From 80aae4d70739446b5d39b5e7467ce963c5dddb96 Mon Sep 17 00:00:00 2001 From: d-bernat Date: Tue, 24 Oct 2023 22:50:17 +0200 Subject: [PATCH 1/4] feat: Metadata for user orgunits in analytics CPL response [2.41-DHIS2-16025] --- .../processing/MetadataParamsHandler.java | 37 +++++++++++++++++-- .../data/handler/MetadataHandler.java | 2 +- .../event/data/AbstractAnalyticsService.java | 2 +- .../util/AnalyticsOrganisationUnitUtils.java | 2 +- .../AnalyticsOrganisationUnitUtilsTest.java | 18 ++++----- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java index b45ce476d8af..255f215e8596 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java @@ -35,12 +35,16 @@ import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER; import static org.hisp.dhis.analytics.orgunit.OrgUnitHelper.getActiveOrganisationUnits; +import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems; import static org.hisp.dhis.common.DimensionalObjectUtils.asTypedList; import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap; import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; +import org.hisp.dhis.analytics.AnalyticsMetaDataKey; import org.hisp.dhis.analytics.common.MetadataInfo; import org.hisp.dhis.analytics.common.params.AnalyticsPagingParams; import org.hisp.dhis.analytics.common.params.CommonParams; @@ -73,10 +77,37 @@ public class MetadataParamsHandler { */ public void handle(Grid grid, CommonParams commonParams, User user, long rowsCount) { if (!commonParams.isSkipMeta()) { - MetadataInfo metadataInfo = new MetadataInfo(); - // Dimensions. - metadataInfo.put(ITEMS.getKey(), new MetadataItemsHandler().handle(grid, commonParams)); + List userOrgUnitMetaDataKeys = + commonParams.getDimensionIdentifiers().stream() + .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) + .flatMap( + dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) + .flatMap(item -> item.getValues().stream()) + .filter( + item -> + item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN.getKey())) + .map( + item -> { + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT; + } + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; + } + return AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; + }) + .toList(); + + Map items = + new HashMap<>(new MetadataItemsHandler().handle(grid, commonParams)); + + getUserOrganisationUnitsItems(user, userOrgUnitMetaDataKeys).forEach(items::putAll); + + MetadataInfo metadataInfo = new MetadataInfo(); + metadataInfo.put(ITEMS.getKey(), items); metadataInfo.put( DIMENSIONS.getKey(), new MetadataDimensionsHandler().handle(grid, commonParams)); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java index 68f043c5ac48..b6c2d81b725c 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java @@ -94,7 +94,7 @@ public void addMetaData(DataQueryParams params, Grid grid) { Map items = new HashMap<>(getDimensionMetadataItemMap(params, grid)); - AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsUidList( + AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems( currentUserService.getCurrentUser(), params.getUserOrganisationUnitsCriteria()) .forEach(items::putAll); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java index 33c4ac8a9eef..8584bc20bfab 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java @@ -393,7 +393,7 @@ protected void addMetadata( } Map items = new HashMap<>(); - AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsUidList( + AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems( currentUserService.getCurrentUser(), params.getUserOrganisationUnitsCriteria()) .forEach(items::putAll); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java index e5efe029d2db..037798b7c05b 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java @@ -52,7 +52,7 @@ public class AnalyticsOrganisationUnitUtils { * @param currentUser the {@link org.hisp.dhis.user.CurrentUser}. * @return intersection of requested user organisation units and all units in response grid. */ - public static Collection> getUserOrganisationUnitsUidList( + public static Collection> getUserOrganisationUnitsItems( User currentUser, List userOrganisationUnitsCriteria) { List> userOrganisations = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java index 415daed25dc0..d22176e5ae4f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java @@ -31,7 +31,7 @@ import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; -import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsUidList; +import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; @@ -77,7 +77,7 @@ void testAnalyticsOrganisationUnitUtils_All() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(3, uidMapList.size()); @@ -100,7 +100,7 @@ void testAnalyticsOrganisationUnitUtils_Parent() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -117,7 +117,7 @@ void testAnalyticsOrganisationUnitUtils_Children() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -134,7 +134,7 @@ void testAnalyticsOrganisationUnitUtils_Grandchildren() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -152,7 +152,7 @@ void testAnalyticsOrganisationUnitUtils_All_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(3, uidMapList.size()); @@ -174,7 +174,7 @@ void testAnalyticsOrganisationUnitUtils_Parent_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -190,7 +190,7 @@ void testAnalyticsOrganisationUnitUtils_Children_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -207,7 +207,7 @@ void testAnalyticsOrganisationUnitUtils_Grandchildren_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsUidList(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); From ba6b936b47108477acb870f2d636a26e428bc693 Mon Sep 17 00:00:00 2001 From: d-bernat Date: Tue, 24 Oct 2023 23:02:54 +0200 Subject: [PATCH 2/4] clean coding --- .../processing/MetadataParamsHandler.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java index 255f215e8596..9ff3855d8c67 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java @@ -77,33 +77,11 @@ public class MetadataParamsHandler { */ public void handle(Grid grid, CommonParams commonParams, User user, long rowsCount) { if (!commonParams.isSkipMeta()) { - // Dimensions. - List userOrgUnitMetaDataKeys = - commonParams.getDimensionIdentifiers().stream() - .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) - .flatMap( - dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) - .flatMap(item -> item.getValues().stream()) - .filter( - item -> - item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey()) - || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey()) - || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN.getKey())) - .map( - item -> { - if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey())) { - return AnalyticsMetaDataKey.USER_ORGUNIT; - } - if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey())) { - return AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; - } - return AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; - }) - .toList(); + // Dimensions. + List userOrgUnitMetaDataKeys = getUserOrgUnitsMetadataKeys(commonParams); Map items = new HashMap<>(new MetadataItemsHandler().handle(grid, commonParams)); - getUserOrganisationUnitsItems(user, userOrgUnitMetaDataKeys).forEach(items::putAll); MetadataInfo metadataInfo = new MetadataInfo(); @@ -160,6 +138,35 @@ private List getActiveOrgUnits(Grid grid, CommonParams commonP return getActiveOrganisationUnits(grid, organisationUnits); } + /** + * Retrieve the analytics metadata keys belong to user organisation unit dimension group + * + * @param commonParams the {@link CommonParams}. + * @return list of the {@link AnalyticsMetaDataKey} + */ + private static List getUserOrgUnitsMetadataKeys(CommonParams commonParams){ + return commonParams.getDimensionIdentifiers().stream() + .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) + .flatMap( + dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) + .flatMap(item -> item.getValues().stream()) + .filter( + item -> + item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN.getKey())) + .map( + item -> { + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT; + } + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; + } + return AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; + }) + .toList(); + } /** * Returns the query {@link QueryItem} identifier. It may be prefixed with its program stage * identifier (if one exists). From 21acae6ab202dba4f55b8814566870d2c3141d27 Mon Sep 17 00:00:00 2001 From: d-bernat Date: Tue, 24 Oct 2023 23:03:45 +0200 Subject: [PATCH 3/4] clean coding --- .../processing/MetadataParamsHandler.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java index 9ff3855d8c67..fad501bd403e 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java @@ -79,7 +79,8 @@ public void handle(Grid grid, CommonParams commonParams, User user, long rowsCou if (!commonParams.isSkipMeta()) { // Dimensions. - List userOrgUnitMetaDataKeys = getUserOrgUnitsMetadataKeys(commonParams); + List userOrgUnitMetaDataKeys = + getUserOrgUnitsMetadataKeys(commonParams); Map items = new HashMap<>(new MetadataItemsHandler().handle(grid, commonParams)); getUserOrganisationUnitsItems(user, userOrgUnitMetaDataKeys).forEach(items::putAll); @@ -144,29 +145,29 @@ private List getActiveOrgUnits(Grid grid, CommonParams commonP * @param commonParams the {@link CommonParams}. * @return list of the {@link AnalyticsMetaDataKey} */ - private static List getUserOrgUnitsMetadataKeys(CommonParams commonParams){ + private static List getUserOrgUnitsMetadataKeys(CommonParams commonParams) { return commonParams.getDimensionIdentifiers().stream() - .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) - .flatMap( - dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) - .flatMap(item -> item.getValues().stream()) - .filter( - item -> - item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey()) - || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey()) - || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN.getKey())) - .map( - item -> { - if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey())) { - return AnalyticsMetaDataKey.USER_ORGUNIT; - } - if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey())) { - return AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; - } - return AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; - }) - .toList(); + .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) + .flatMap(dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) + .flatMap(item -> item.getValues().stream()) + .filter( + item -> + item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey()) + || item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN.getKey())) + .map( + item -> { + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT; + } + if (item.equals(AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN.getKey())) { + return AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; + } + return AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; + }) + .toList(); } + /** * Returns the query {@link QueryItem} identifier. It may be prefixed with its program stage * identifier (if one exists). From 39fff5c3c84f3e1fc04e3a922a055ff0416ccf03 Mon Sep 17 00:00:00 2001 From: d-bernat Date: Wed, 25 Oct 2023 07:48:33 +0200 Subject: [PATCH 4/4] clean coding --- .../processing/MetadataParamsHandler.java | 9 +++++---- .../data/handler/MetadataHandler.java | 2 +- .../event/data/AbstractAnalyticsService.java | 2 +- .../util/AnalyticsOrganisationUnitUtils.java | 2 +- .../AnalyticsOrganisationUnitUtilsTest.java | 18 +++++++++--------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java index fad501bd403e..22696c9589f5 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/processing/MetadataParamsHandler.java @@ -35,7 +35,7 @@ import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER; import static org.hisp.dhis.analytics.orgunit.OrgUnitHelper.getActiveOrganisationUnits; -import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems; +import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitItems; import static org.hisp.dhis.common.DimensionalObjectUtils.asTypedList; import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap; import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap; @@ -67,6 +67,7 @@ @Component public class MetadataParamsHandler { private static final String DOT = "."; + private static final String ORG_UNIT_DIM = "ou"; /** * Appends the metadata to the given {@link Grid} based on the given arguments. @@ -83,10 +84,10 @@ public void handle(Grid grid, CommonParams commonParams, User user, long rowsCou getUserOrgUnitsMetadataKeys(commonParams); Map items = new HashMap<>(new MetadataItemsHandler().handle(grid, commonParams)); - getUserOrganisationUnitsItems(user, userOrgUnitMetaDataKeys).forEach(items::putAll); - + getUserOrganisationUnitItems(user, userOrgUnitMetaDataKeys).forEach(items::putAll); MetadataInfo metadataInfo = new MetadataInfo(); metadataInfo.put(ITEMS.getKey(), items); + metadataInfo.put( DIMENSIONS.getKey(), new MetadataDimensionsHandler().handle(grid, commonParams)); @@ -147,7 +148,7 @@ private List getActiveOrgUnits(Grid grid, CommonParams commonP */ private static List getUserOrgUnitsMetadataKeys(CommonParams commonParams) { return commonParams.getDimensionIdentifiers().stream() - .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals("ou")) + .filter(dimensionIdentifier -> dimensionIdentifier.toString().equals(ORG_UNIT_DIM)) .flatMap(dimensionIdentifier -> dimensionIdentifier.getDimension().getItems().stream()) .flatMap(item -> item.getValues().stream()) .filter( diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java index b6c2d81b725c..5e3208c47c52 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/handler/MetadataHandler.java @@ -94,7 +94,7 @@ public void addMetaData(DataQueryParams params, Grid grid) { Map items = new HashMap<>(getDimensionMetadataItemMap(params, grid)); - AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems( + AnalyticsOrganisationUnitUtils.getUserOrganisationUnitItems( currentUserService.getCurrentUser(), params.getUserOrganisationUnitsCriteria()) .forEach(items::putAll); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java index 8584bc20bfab..071e76fc4b69 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/AbstractAnalyticsService.java @@ -393,7 +393,7 @@ protected void addMetadata( } Map items = new HashMap<>(); - AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems( + AnalyticsOrganisationUnitUtils.getUserOrganisationUnitItems( currentUserService.getCurrentUser(), params.getUserOrganisationUnitsCriteria()) .forEach(items::putAll); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java index 037798b7c05b..a85492c0c23f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtils.java @@ -52,7 +52,7 @@ public class AnalyticsOrganisationUnitUtils { * @param currentUser the {@link org.hisp.dhis.user.CurrentUser}. * @return intersection of requested user organisation units and all units in response grid. */ - public static Collection> getUserOrganisationUnitsItems( + public static Collection> getUserOrganisationUnitItems( User currentUser, List userOrganisationUnitsCriteria) { List> userOrganisations = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java index d22176e5ae4f..820f2a9edb6d 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsOrganisationUnitUtilsTest.java @@ -31,7 +31,7 @@ import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT_CHILDREN; import static org.hisp.dhis.analytics.AnalyticsMetaDataKey.USER_ORGUNIT_GRANDCHILDREN; -import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitsItems; +import static org.hisp.dhis.analytics.util.AnalyticsOrganisationUnitUtils.getUserOrganisationUnitItems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; @@ -77,7 +77,7 @@ void testAnalyticsOrganisationUnitUtils_All() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(3, uidMapList.size()); @@ -100,7 +100,7 @@ void testAnalyticsOrganisationUnitUtils_Parent() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -117,7 +117,7 @@ void testAnalyticsOrganisationUnitUtils_Children() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -134,7 +134,7 @@ void testAnalyticsOrganisationUnitUtils_Grandchildren() { // when when(user.getOrganisationUnits()).thenReturn(Set.of(orgA)); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -152,7 +152,7 @@ void testAnalyticsOrganisationUnitUtils_All_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(3, uidMapList.size()); @@ -174,7 +174,7 @@ void testAnalyticsOrganisationUnitUtils_Parent_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -190,7 +190,7 @@ void testAnalyticsOrganisationUnitUtils_Children_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size()); @@ -207,7 +207,7 @@ void testAnalyticsOrganisationUnitUtils_Grandchildren_Empty() { // when when(user.getOrganisationUnits()).thenReturn(Set.of()); List> uidMapList = - getUserOrganisationUnitsItems(user, userOrganisationUnitsCriteria).stream().toList(); + getUserOrganisationUnitItems(user, userOrganisationUnitsCriteria).stream().toList(); // then assertEquals(1, uidMapList.size());