From 476cb6efdd95f7f35ae456c7cdef9f07f93fc7c5 Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Wed, 18 Dec 2024 20:50:22 +0100 Subject: [PATCH] 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 --- .../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 7478bef21c40..4b8d7d6c3b3c 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 @@ -121,6 +121,15 @@ @JacksonXmlRootElement(localName = "analyticalObject", namespace = DxfNamespaces.DXF_2_0) public abstract class BaseAnalyticalObject extends BaseNameableObject implements AnalyticalObject { + 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"; /** Line and axis labels. */ @@ -320,6 +329,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(); @@ -700,15 +722,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()) {