From 744704f7f0a943b02a22b793dab15e7a4b036c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Sun, 15 Dec 2024 15:53:44 +0100 Subject: [PATCH] fix: Update code --- .../AbstractJdbcEventAnalyticsManager.java | 18 ++++------- .../query/context/sql/SqlQueryBuilders.java | 32 +++++++++---------- .../dhis/analytics/util/DisplayNameUtils.java | 12 +++---- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManager.java index 9f53bfd51add..55a58883bd63 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractJdbcEventAnalyticsManager.java @@ -49,8 +49,8 @@ import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getHeaderColumns; import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getOrgUnitLevelColumns; import static org.hisp.dhis.analytics.event.data.EnrollmentQueryHelper.getPeriodColumns; -import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.OU_GEOMETRY_COL_SUFFIX; -import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.OU_NAME_COL_SUFFIX; +import static org.hisp.dhis.analytics.table.AbstractEventJdbcTableManager.OU_GEOMETRY_COL_SUFFIX; +import static org.hisp.dhis.analytics.table.AbstractEventJdbcTableManager.OU_NAME_COL_SUFFIX; import static org.hisp.dhis.analytics.util.AnalyticsUtils.replaceStringBetween; import static org.hisp.dhis.analytics.util.AnalyticsUtils.throwIllegalQueryEx; import static org.hisp.dhis.analytics.util.AnalyticsUtils.withExceptionHandling; @@ -375,8 +375,9 @@ private void addDimensionSelectColumns( singleQuote(period.getIsoDate()) + " as " + period.getPeriodType().getName()); } else { throw new IllegalStateException( - "Program indicator non-default boundary query must have " - + "exactly one period, or no periods and a period filter"); + """ + Program indicator non-default boundary query must have \" + exactly one period, or no periods and a period filter"""); } }); } @@ -455,7 +456,6 @@ private ColumnAndAlias getColumnAndAlias( } else if (queryItem.getValueType() == ValueType.NUMBER && !isGroupByClause) { ColumnAndAlias columnAndAlias = getColumnAndAlias(queryItem, isAggregated, queryItem.getItemName()); - return ColumnAndAlias.ofColumnAndAlias( columnAndAlias.getColumn(), defaultIfNull(columnAndAlias.getAlias(), queryItem.getItemName())); @@ -532,14 +532,10 @@ protected Optional getAlias(QueryItem queryItem) { @Transactional(readOnly = true, propagation = REQUIRES_NEW) public Grid getAggregatedEventData(EventQueryParams params, Grid grid, int maxLimit) { String aggregateClause = getAggregateClause(params); + String columns = StringUtils.join(getSelectColumns(params, true), ","); String sql = - TextUtils.removeLastComma( - "select " - + aggregateClause - + " as value," - + StringUtils.join(getSelectColumns(params, true), ",") - + " "); + TextUtils.removeLastComma("select " + aggregateClause + " as value," + columns + " "); // --------------------------------------------------------------------- // Criteria diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/trackedentity/query/context/sql/SqlQueryBuilders.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/trackedentity/query/context/sql/SqlQueryBuilders.java index e9768189d49c..23ae04e3abd6 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/trackedentity/query/context/sql/SqlQueryBuilders.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/trackedentity/query/context/sql/SqlQueryBuilders.java @@ -61,22 +61,22 @@ select json_agg(json_build_object( // incidentDate is kept to support a deprecated field, will be removed when FE will only // use occurreddate """ - select json_agg( - json_build_object( - 'programUid', en.program, - 'enrollmentUid', en.enrollment, - 'enrollmentDate', en.enrollmentdate, - 'incidentDate', en.occurreddate, - 'occurredDate', en.occurreddate, - 'completedDate', en.completeddate, - 'orgUnitUid', en.ou, - 'orgUnitName', en.ouname, - 'orgUnitCode', en.oucode, - 'orgUnitNameHierarchy', en.ounamehierarchy, - 'enrollmentStatus', en.enrollmentstatus, - 'events', ${eventQuery})) - from analytics_te_enrollment_${trackedEntityType} en - where en.trackedentity = t_1.trackedentity""", + select json_agg( + json_build_object( + 'programUid', en.program, + 'enrollmentUid', en.enrollment, + 'enrollmentDate', en.enrollmentdate, + 'incidentDate', en.occurreddate, + 'occurredDate', en.occurreddate, + 'completedDate', en.completeddate, + 'orgUnitUid', en.ou, + 'orgUnitName', en.ouname, + 'orgUnitCode', en.oucode, + 'orgUnitNameHierarchy', en.ounamehierarchy, + 'enrollmentStatus', en.enrollmentstatus, + 'events', ${eventQuery})) + from analytics_te_enrollment_${trackedEntityType} en + where en.trackedentity = t_1.trackedentity""", Map.of("eventQuery", coalesceToEmptyArray(EVENT_QUERY))); private static final String JSON_AGGREGATION_QUERY = coalesceToEmptyArray(ENROLLMENT_QUERY); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/DisplayNameUtils.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/DisplayNameUtils.java index 5377f0807253..b7f47fbce85d 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/DisplayNameUtils.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/DisplayNameUtils.java @@ -124,22 +124,22 @@ public static String getDisplayName( isNotEmpty.apply(surname), isNotEmpty.apply(firstName), isEmpty.apply(username), - formatNames(sqlBuilder, surname, "', '", firstName), + sqlBuilder.concat(surname, "', '", firstName), // FirstName and Username isEmpty.apply(surname), isNotEmpty.apply(firstName), isNotEmpty.apply(username), - formatNames(sqlBuilder, firstName, "' ('", username, "')'"), + sqlBuilder.concat(firstName, "' ('", username, "')'"), // Surname and Username isNotEmpty.apply(surname), isEmpty.apply(firstName), isNotEmpty.apply(username), - formatNames(sqlBuilder, surname, "' ('", username, "')'"), + sqlBuilder.concat(surname, "' ('", username, "')'"), // All fields - formatNames(sqlBuilder, surname, "', '", firstName, "' ('", username, "')'"), + sqlBuilder.concat(surname, "', '", firstName, "' ('", username, "')'"), columnAlias); } @@ -149,8 +149,4 @@ private static String extractJsonValue( String jsonExtracted = sqlBuilder.jsonExtract(json, path); return sqlBuilder.trim(jsonExtracted); } - - private static String formatNames(SqlBuilder sqlBuilder, String... elements) { - return sqlBuilder.concat(elements); - } }