From 0b91000d37d783a4471b80f60240b2290d1554be Mon Sep 17 00:00:00 2001 From: Ameen Mohamed Date: Fri, 3 Jan 2025 13:41:26 +0100 Subject: [PATCH 1/4] fix: [DHIS2-18459] Re-use obtained maxTeLimit (2.41) --- .../dhis/trackedentity/DefaultTrackedEntityService.java | 9 +++++---- .../hibernate/HibernateTrackedEntityStore.java | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java index fa21cf0b6c4c..b0e6005fcb7b 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java @@ -679,16 +679,17 @@ public void validateSearchScope(TrackedEntityQueryParams params, boolean isGridS } } - checkIfMaxTeiLimitIsReached(params, maxTeiLimit); params.setMaxTeLimit(maxTeiLimit); + checkIfMaxTeiLimitIsReached(params); + } } - private void checkIfMaxTeiLimitIsReached(TrackedEntityQueryParams params, int maxTeiLimit) { - if (maxTeiLimit > 0) { + private void checkIfMaxTeiLimitIsReached(TrackedEntityQueryParams params) { + if (params.getMaxTeLimit() > 0) { int teCount = trackedEntityStore.getTrackedEntityCountForGridWithMaxTeiLimit(params); - if (teCount > maxTeiLimit) { + if (teCount > params.getMaxTeLimit()) { throw new IllegalQueryException("maxteicountreached"); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java index 49b66cc0b9f0..5f1a07829f61 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java @@ -407,8 +407,6 @@ private String getCountQuery(TrackedEntityQueryParams params) { * @return a count SQL query */ private String getCountQueryWithMaxTeiLimit(TrackedEntityQueryParams params) { - boolean hasMaxTeiCountToReturn = - params.hasProgram() && params.getProgram().hasMaxTeiCountToReturn(); return new StringBuilder() .append(getQueryCountSelect(params)) .append(getQuerySelect(params)) @@ -417,8 +415,8 @@ private String getCountQueryWithMaxTeiLimit(TrackedEntityQueryParams params) { .append(getQueryRelatedTables(params)) .append(getQueryGroupBy(params)) .append( - hasMaxTeiCountToReturn - ? getLimitClause(params.getProgram().getMaxTeiCountToReturn() + 1) + params.getMaxTeLimit() > 0 + ? getLimitClause(params.getMaxTeLimit() + 1) : "") .append(" ) tecount") .toString(); From 6895b4e5f69ec478e7d566995056f0e79fe0b465 Mon Sep 17 00:00:00 2001 From: Ameen Mohamed Date: Fri, 3 Jan 2025 13:47:17 +0100 Subject: [PATCH 2/4] Apply spotless --- .../hisp/dhis/trackedentity/DefaultTrackedEntityService.java | 1 - .../trackedentity/hibernate/HibernateTrackedEntityStore.java | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java index b0e6005fcb7b..1ec8764db057 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java @@ -681,7 +681,6 @@ public void validateSearchScope(TrackedEntityQueryParams params, boolean isGridS params.setMaxTeLimit(maxTeiLimit); checkIfMaxTeiLimitIsReached(params); - } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java index 5f1a07829f61..aff62f4f9b82 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java @@ -414,10 +414,7 @@ private String getCountQueryWithMaxTeiLimit(TrackedEntityQueryParams params) { .append(getFromSubQuery(params, true, true)) .append(getQueryRelatedTables(params)) .append(getQueryGroupBy(params)) - .append( - params.getMaxTeLimit() > 0 - ? getLimitClause(params.getMaxTeLimit() + 1) - : "") + .append(params.getMaxTeLimit() > 0 ? getLimitClause(params.getMaxTeLimit() + 1) : "") .append(" ) tecount") .toString(); } From ef7e0acf4d58082c47d7fa050b54a94734086e02 Mon Sep 17 00:00:00 2001 From: Ameen Mohamed Date: Fri, 3 Jan 2025 14:19:50 +0100 Subject: [PATCH 3/4] Add hasMaxTeLimit convenience method --- .../hisp/dhis/trackedentity/TrackedEntityQueryParams.java | 5 +++++ .../hisp/dhis/trackedentity/DefaultTrackedEntityService.java | 2 +- .../trackedentity/hibernate/HibernateTrackedEntityStore.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java index 0ef00f3c51e6..a458acd31a6b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java @@ -469,6 +469,11 @@ public boolean hasTrackedEntityType() { return trackedEntityType != null; } + /** Indicates whether this parameters specifies a max TE limit. */ + public boolean hasMaxTeLimit() { + return this.maxTeLimit > 0; + } + /** Indicates whether this parameters is of the given organisation unit mode. */ public boolean isOrganisationUnitMode(OrganisationUnitSelectionMode mode) { return orgUnitMode != null && orgUnitMode.equals(mode); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java index 1ec8764db057..cfa8e1a964c8 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java @@ -685,7 +685,7 @@ public void validateSearchScope(TrackedEntityQueryParams params, boolean isGridS } private void checkIfMaxTeiLimitIsReached(TrackedEntityQueryParams params) { - if (params.getMaxTeLimit() > 0) { + if (params.hasMaxTeLimit()) { int teCount = trackedEntityStore.getTrackedEntityCountForGridWithMaxTeiLimit(params); if (teCount > params.getMaxTeLimit()) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java index aff62f4f9b82..2910194dd9b5 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java @@ -414,7 +414,7 @@ private String getCountQueryWithMaxTeiLimit(TrackedEntityQueryParams params) { .append(getFromSubQuery(params, true, true)) .append(getQueryRelatedTables(params)) .append(getQueryGroupBy(params)) - .append(params.getMaxTeLimit() > 0 ? getLimitClause(params.getMaxTeLimit() + 1) : "") + .append(params.hasMaxTeLimit() ? getLimitClause(params.getMaxTeLimit() + 1) : "") .append(" ) tecount") .toString(); } From e872f18146ffbe0ab1fdd7890f7a101fdf5c19b6 Mon Sep 17 00:00:00 2001 From: Ameen Mohamed Date: Fri, 3 Jan 2025 14:20:58 +0100 Subject: [PATCH 4/4] Remove this to make it consistent --- .../org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java index a458acd31a6b..5ebab93624f2 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityQueryParams.java @@ -471,7 +471,7 @@ public boolean hasTrackedEntityType() { /** Indicates whether this parameters specifies a max TE limit. */ public boolean hasMaxTeLimit() { - return this.maxTeLimit > 0; + return maxTeLimit > 0; } /** Indicates whether this parameters is of the given organisation unit mode. */