diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteDefinition.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteDefinition.java index 6101234baee..69686a3c966 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteDefinition.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteDefinition.java @@ -46,7 +46,7 @@ public class CteDefinition { @Getter private final List offsets = new ArrayList<>(); // The alias of the CTE private final String alias; - // Whether the CTE is a row context (TODO this need a better explanation) + // Whether the CTE is a row context @Getter private boolean rowContext; // Whether the CTE is a program indicator @Getter private boolean programIndicator = false; @@ -61,9 +61,6 @@ public class CteDefinition { @Getter private String aggregateWhereClause; - private static final String PS_PREFIX = "ps"; - private static final String PI_PREFIX = "pi"; - public CteDefinition setExists(boolean exists) { this.isExists = exists; return this; @@ -109,7 +106,6 @@ public CteDefinition(String cteDefinition, String aggregateWhereClause) { this(null, null, cteDefinition, 0, false); this.rowContext = false; this.aggregationBase = true; - assert aggregateWhereClause != null; this.aggregateWhereClause = aggregateWhereClause; } @@ -137,24 +133,6 @@ public CteDefinition( this.filter = isFilter; } - /** - * @param uid the uid of an dimension item or ProgramIndicator - * @return the name of the CTE - */ - public String asCteName(String uid) { - if (isExists) { - return uid.toLowerCase(); - } - if (programIndicator) { - return "%s_%s".formatted(PI_PREFIX, programIndicatorUid.toLowerCase()); - } - if (filter) { - return uid.toLowerCase(); - } - - return "%s_%s_%s".formatted(PS_PREFIX, programStageUid.toLowerCase(), uid.toLowerCase()); - } - public boolean isProgramStage() { return !filter && !programIndicator && !isExists; } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteUtils.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteUtils.java index 43c9625db3f..3cb12b3e2c8 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteUtils.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/CteUtils.java @@ -40,8 +40,6 @@ public static String computeKey(QueryItem queryItem) { } else if (queryItem.isProgramIndicator()) { return queryItem.getItemId(); } - - // TODO continue with the rest of the method return ""; } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EnrollmentQueryHelper.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EnrollmentQueryHelper.java index 3e9805f669e..de1b9b2e5c7 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EnrollmentQueryHelper.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/EnrollmentQueryHelper.java @@ -114,10 +114,9 @@ public static Set getHeaderColumns(List headers, EventQueryP if (!headerName.equalsIgnoreCase(COL_VALUE) && !headerName.equalsIgnoreCase(PERIOD_DIM_ID) - && !headerName.equalsIgnoreCase(ORGUNIT_DIM_ID)) { - if (!itemsToSkip.contains(headerName)) { - headerColumns.add(headerName); - } + && !headerName.equalsIgnoreCase(ORGUNIT_DIM_ID) + && !itemsToSkip.contains(headerName)) { + headerColumns.add(headerName); } } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java index 2add8cd0def..8561618a548 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java @@ -1101,7 +1101,7 @@ private void buildProgramStageCte( String colName = quote(item.getItemName()); if (params.isAggregatedEnrollments()) { - handleAggregatedEnrollments(cteContext, item, params, eventTableName, colName); + handleAggregatedEnrollments(cteContext, item, eventTableName, colName); return; } @@ -1170,11 +1170,7 @@ private String buildMainCteSql( * @param colName the quoted column name for the item */ private void handleAggregatedEnrollments( - CteContext cteContext, - QueryItem item, - EventQueryParams params, - String eventTableName, - String colName) { + CteContext cteContext, QueryItem item, String eventTableName, String colName) { CteDefinition baseAggregatedCte = cteContext.getBaseAggregatedCte(); assert baseAggregatedCte != null; @@ -1225,7 +1221,7 @@ private String buildAggregatedCteSql( values.put("enrollmentAggrBase", ENROLLMENT_AGGR_BASE); values.put("programStageUid", item.getProgramStage().getUid()); values.put( - "aggregateWhereClause", baseAggregatedCte.getAggregateWhereClause().replaceAll("%s", "eb")); + "aggregateWhereClause", baseAggregatedCte.getAggregateWhereClause().replace("%s", "eb")); return new StringSubstitutor(values).replace(template); } @@ -1531,6 +1527,7 @@ private void addSortingAndPaging(SelectBuilder builder, EventQueryParams params) } } + @Override protected String getSortClause(EventQueryParams params) { if (params.isSorting()) { return super.getSortClause(params); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/programindicator/DefaultProgramIndicatorSubqueryBuilder.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/programindicator/DefaultProgramIndicatorSubqueryBuilder.java index e751ef4b73f..bfd2cb06050 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/programindicator/DefaultProgramIndicatorSubqueryBuilder.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/programindicator/DefaultProgramIndicatorSubqueryBuilder.java @@ -116,7 +116,7 @@ public void contributeCte( earliestStartDate, latestDate) // FIXME this is a bit of an hack - .replaceAll("subax\\.", ""); + .replace("subax\\.", ""); filter = "where " + piResolvedSqlFilter; } @@ -128,7 +128,7 @@ public void contributeCte( earliestStartDate, latestDate) // FIXME this is a bit of an hack - .replaceAll("subax\\.", ""); + .replace("subax\\.", ""); String cteSql = "select enrollment, %s(%s) as value from %s %s group by enrollment" diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SelectBuilder.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SelectBuilder.java index d04dba266a6..eab082a3d1b 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SelectBuilder.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SelectBuilder.java @@ -239,7 +239,7 @@ public SelectBuilder addColumn(String expression, String tablePrefix) { } public List getColumnNames() { - return columns.stream().map(Column::expression).collect(Collectors.toList()); + return columns.stream().map(Column::expression).toList(); } /** diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlAliasReplacer.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlAliasReplacer.java index 8be7ce9a3c5..5069f06cbbe 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlAliasReplacer.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlAliasReplacer.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import lombok.experimental.UtilityClass; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitorAdapter; import net.sf.jsqlparser.expression.Function; @@ -40,6 +41,7 @@ import net.sf.jsqlparser.statement.select.SelectExpressionItem; import net.sf.jsqlparser.statement.select.SubSelect; +@UtilityClass public class SqlAliasReplacer { public static String replaceTableAliases(String whereClause, List columns) { diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlColumnParser.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlColumnParser.java index f0241f0fea6..b96b9f78b69 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlColumnParser.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/sql/SqlColumnParser.java @@ -27,10 +27,12 @@ */ package org.hisp.dhis.analytics.util.sql; +import lombok.experimental.UtilityClass; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.schema.Column; +@UtilityClass public class SqlColumnParser { /**