From 63c00dec5a668be3ffa14c8df4f25ec02be52221 Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Thu, 21 Dec 2023 12:31:17 +0100 Subject: [PATCH 1/3] fix: programIndicators are now prefixed by programId in tei dimension endpoint [DHIS2-16368] --- .../dhis/webapi/dimension/TeiAnalyticsPrefixStrategy.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/TeiAnalyticsPrefixStrategy.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/TeiAnalyticsPrefixStrategy.java index 2b167db63efd..6e277ee9eb47 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/TeiAnalyticsPrefixStrategy.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/TeiAnalyticsPrefixStrategy.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.common.PrefixedDimension; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.program.ProgramIndicator; import org.hisp.dhis.program.ProgramStageDataElement; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -42,7 +43,8 @@ public class TeiAnalyticsPrefixStrategy implements PrefixStrategy { @Override public String apply(PrefixedDimension pDimension) { if (pDimension.getItem() instanceof DataElement - || pDimension.getItem() instanceof ProgramStageDataElement) { + || pDimension.getItem() instanceof ProgramStageDataElement + || pDimension.getItem() instanceof ProgramIndicator) { return pDimension.getPrefix(); } return StringUtils.EMPTY; From 2abba1f5b6b201cd13daf43a8de035680693f7f2 Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Thu, 21 Dec 2023 13:05:41 +0100 Subject: [PATCH 2/3] fix: programIndicators are now prefixed by programId in tei dimension endpoint [DHIS2-16368] --- .../analytics/AnalyticsDimensionsTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java index c4f22d7960d6..fa25074e1a18 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.analytics; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; @@ -40,6 +41,7 @@ import static org.hamcrest.Matchers.startsWith; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -47,8 +49,10 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.hamcrest.CoreMatchers; +import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Matchers; +import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hisp.dhis.ApiTest; import org.hisp.dhis.Constants; import org.hisp.dhis.actions.analytics.AnalyticsEnrollmentsActions; @@ -322,4 +326,34 @@ public void shouldReturnAllDataElements() { .body("dimensions", hasSize(equalTo(dataElements.size()))) .body("dimensions.uid", everyItem(in(distinctDataElements))); } + + @Test + void ProgramIndicatorsShouldHavePrefix() { + analyticsTeiActions + .query() + .getDimensions( + Constants.TRACKED_ENTITY_TYPE, + new QueryParamsBuilder().add("filter", "dimensionType:eq:PROGRAM_INDICATOR")) + .validate() + .statusCode(200) + .body("dimensions", hasSize(greaterThanOrEqualTo(1))) + .body("dimensions.id", everyItem(containsExactlyOne('.'))); + } + + public static TypeSafeDiagnosingMatcher containsExactlyOne(Character character) { + return new TypeSafeDiagnosingMatcher<>() { + @Override + protected boolean matchesSafely(String item, Description mismatchDescription) { + if (item != null) { + return item.chars().filter(ch -> ch == character).count() == 1; + } + return false; + } + + @Override + public void describeTo(Description description) { + description.appendText("a string that contains exactly one " + character); + } + }; + } } From 1773b0a2f1ab7b8238db76b564429b41917806c3 Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Thu, 21 Dec 2023 13:08:17 +0100 Subject: [PATCH 3/3] fix: programIndicators are now prefixed by programId in tei dimension endpoint [DHIS2-16368] --- .../analytics/AnalyticsDimensionsTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java index fa25074e1a18..9f8e172dd945 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.analytics; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; @@ -41,7 +40,6 @@ import static org.hamcrest.Matchers.startsWith; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -330,14 +328,14 @@ public void shouldReturnAllDataElements() { @Test void ProgramIndicatorsShouldHavePrefix() { analyticsTeiActions - .query() - .getDimensions( - Constants.TRACKED_ENTITY_TYPE, - new QueryParamsBuilder().add("filter", "dimensionType:eq:PROGRAM_INDICATOR")) - .validate() - .statusCode(200) - .body("dimensions", hasSize(greaterThanOrEqualTo(1))) - .body("dimensions.id", everyItem(containsExactlyOne('.'))); + .query() + .getDimensions( + Constants.TRACKED_ENTITY_TYPE, + new QueryParamsBuilder().add("filter", "dimensionType:eq:PROGRAM_INDICATOR")) + .validate() + .statusCode(200) + .body("dimensions", hasSize(greaterThanOrEqualTo(1))) + .body("dimensions.id", everyItem(containsExactlyOne('.'))); } public static TypeSafeDiagnosingMatcher containsExactlyOne(Character character) {