From ec3b4ff1413706180293350177df95c1a22fc41a Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Wed, 18 Dec 2024 20:50:22 +0100 Subject: [PATCH] Signed-off-by: Giuseppe Nespolino fix: ou item names in visualization [DHIS2-18337] (#19523) * fix: ou item names in visualization [DHIS2-18337] Signed-off-by: Giuseppe Nespolino * fix: formatting [DHIS2-18337] Signed-off-by: Giuseppe Nespolino --------- Signed-off-by: Giuseppe Nespolino (cherry picked from commit 476cb6efdd95f7f35ae456c7cdef9f07f93fc7c5) Signed-off-by: Giuseppe Nespolino --- .../dhis/common/BaseAnalyticalObject.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java index 146c58cac563..f5d2b7d0ae8c 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java @@ -120,6 +120,15 @@ public abstract class BaseAnalyticalObject extends BaseNameableObject implements public static final int NONE = 0; + private static final BaseDimensionalItemObject USER_OU_ITEM_OBJ = + buildDimItemObj(KEY_USER_ORGUNIT, "User organisation unit"); + + private static final BaseDimensionalItemObject USER_OU_CHILDREN_ITEM_OBJ = + buildDimItemObj(KEY_USER_ORGUNIT_CHILDREN, "User organisation unit children"); + + private static final BaseDimensionalItemObject USER_OU_GRANDCHILDREN_ITEM_OBJ = + buildDimItemObj(KEY_USER_ORGUNIT_GRANDCHILDREN, "User organisation unit grand children"); + public static final String NOT_A_VALID_DIMENSION = "Not a valid dimension: %s"; // ------------------------------------------------------------------------- @@ -240,6 +249,19 @@ public abstract void init( List organisationUnitsInGroups, I18nFormat format); + /** + * Returns the dimensional item object for the given dimension and name. + * + * @param uid the dimension uid. + * @param name the dimension name. + * @return the DimensionalObject. + */ + private static BaseDimensionalItemObject buildDimItemObj(String uid, String name) { + BaseDimensionalItemObject itemObj = new BaseDimensionalItemObject(uid); + itemObj.setName(name); + return itemObj; + } + @Override public abstract void populateAnalyticalProperties(); @@ -636,15 +658,15 @@ protected Optional getDimensionalObject(String dimension) { ouList.addAll(transientOrganisationUnits); if (userOrganisationUnit) { - ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT)); + ouList.add(USER_OU_ITEM_OBJ); } if (userOrganisationUnitChildren) { - ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_CHILDREN)); + ouList.add(USER_OU_CHILDREN_ITEM_OBJ); } if (userOrganisationUnitGrandChildren) { - ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_GRANDCHILDREN)); + ouList.add(USER_OU_GRANDCHILDREN_ITEM_OBJ); } if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {