Skip to content

Commit

Permalink
fix: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Dec 15, 2024
1 parent 1687966 commit 744704f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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""");
}
});
}
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -532,14 +532,10 @@ protected Optional<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}

0 comments on commit 744704f

Please sign in to comment.