From de93a14f8ccff03dafb5b37755f50bec55fcdf54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 10 Jan 2025 12:09:59 +0100 Subject: [PATCH 1/2] fix: Update code --- .../organisationunit/OrganisationUnit.java | 36 ++++++++++++++++++- .../data/JdbcRawAnalyticsManager.java | 2 +- .../jdbc/JdbcOrgUnitAssociationsStore.java | 2 +- .../hibernate/HibernateDataValueStore.java | 4 +-- .../function/FunctionOrgUnitAncestor.java | 2 +- .../HibernateOrganisationUnitStore.java | 8 ++--- .../HibernateProgramInstanceStore.java | 5 ++- .../HibernateTrackedEntityInstanceStore.java | 6 +++- ...rnateTrackedEntityDataValueAuditStore.java | 2 +- ...pleteDataSetRegistrationExchangeStore.java | 2 +- .../datavalueset/SpringDataValueSetStore.java | 2 +- .../dxf2/events/event/JdbcEventStore.java | 6 ++-- .../DataValueSetImportValidatorTest.java | 4 +-- .../predictor/PredictionDataValueFetcher.java | 5 +-- .../HibernateMinMaxDataElementStore.java | 2 +- .../util/OutlierDetectionUtils.java | 2 +- .../HibernateValidationResultStore.java | 3 +- .../controller/DataAnalysisController.java | 2 +- .../controller/LockExceptionController.java | 2 +- 19 files changed, 69 insertions(+), 28 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java index 5ae65e907996..73a14024bc44 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java @@ -28,7 +28,9 @@ package org.hisp.dhis.organisationunit; import static org.apache.commons.collections4.CollectionUtils.isEmpty; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; @@ -708,6 +710,13 @@ public void setChildren(Set children) { this.children = children; } + /** + * Note that the {@code path} property is mapped with the "property access" mode. This method will + * calculate and return the path property value based on the org unit ancestors. To access the + * {@code path} property directly, use {@link OrganisationUnit#getStoredPath}. + * + * @return the path. + */ @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) public String getPath() { @@ -734,11 +743,36 @@ public String getPath() { return this.path; } - /** Do not set directly, managed by persistence layer. */ + /** + * Note that the {@code path} property is mapped with the "property access" mode. This method will + * return the persisted {@code path} property value directly. If the path is not defined, + * typically as part of an integration test where the state is not yet flushed to the database, + * the calculated path based on the org unit ancestors is returned. To get the calculated path + * value explicitly, use {@link OrganisationUnit#getPath}. + * + * @return the path. + */ + @JsonIgnore + public String getStoredPath() { + return isNotEmpty(path) ? path : getPath(); + } + + /** + * Note that the {@code path} property is mapped with the "property access" mode. Do not set + * directly, this property is managed by the persistence layer. + */ public void setPath(String path) { this.path = path; } + /** + * Note that the {@code path} property is mapped with the "property access" mode. This method is + * for unit testing purposes only. + */ + public void updatePath() { + setPath(getPath()); + } + /** * Used by persistence layer. Purpose is to have a column for use in database queries. For * application use see {@link OrganisationUnit#getLevel()} which has better performance. diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcRawAnalyticsManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcRawAnalyticsManager.java index 54bb61659ecc..0c0fc2291d0a 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcRawAnalyticsManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcRawAnalyticsManager.java @@ -166,7 +166,7 @@ private String getSelectStatement(DataQueryParams params, List getUserOrgUnitPaths() { Set allUserOrgUnitPaths = currentUserService.getCurrentUserOrganisationUnits().stream() - .map(OrganisationUnit::getPath) + .map(OrganisationUnit::getStoredPath) .collect(Collectors.toSet()); return allUserOrgUnitPaths.stream() diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java index b7eb7e0e8d46..cae08304ee36 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java @@ -315,7 +315,7 @@ private String getDataValuesHql( hql.append( params.getOrganisationUnits().stream() - .map(OrganisationUnit::getPath) + .map(OrganisationUnit::getStoredPath) .map(p -> "ou.path like '" + p + "%'") .collect(joining(" or "))); @@ -546,7 +546,7 @@ private void getDdvOrgUnits( where .append(sqlHelper.or()) .append("ou.path like '") - .append(parent.getPath()) + .append(parent.getStoredPath()) .append("%'"); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/function/FunctionOrgUnitAncestor.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/function/FunctionOrgUnitAncestor.java index 891620983f60..915df6787b65 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/function/FunctionOrgUnitAncestor.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/function/FunctionOrgUnitAncestor.java @@ -65,7 +65,7 @@ public Object evaluate(ExpressionParser.ExprContext ctx, CommonExpressionVisitor if (orgUnit != null) { for (TerminalNode uid : ctx.UID()) { - if (orgUnit.getPath().contains(uid.getText() + "/")) { + if (orgUnit.getStoredPath().contains(uid.getText() + "/")) { return true; } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java index 346bebc58b09..172db6b0ac5e 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java @@ -158,7 +158,7 @@ public Long getOrganisationUnitHierarchyMemberCount( + ")"; Query query = getTypedQuery(hql); - query.setParameter("path", parent.getPath() + "%").setParameter("object", member); + query.setParameter("path", parent.getStoredPath() + "%").setParameter("object", member); return query.getSingleResult(); } @@ -216,7 +216,7 @@ public List getOrganisationUnits(OrganisationUnitQueryParams p if (params.hasParents()) { for (OrganisationUnit parent : params.getParents()) { - query.setParameter(parent.getUid(), parent.getPath() + "%"); + query.setParameter(parent.getUid(), parent.getStoredPath() + "%"); } } @@ -261,7 +261,7 @@ public Map> getOrganisationUnitDataSetAssocationMap( sql += hlp.whereAnd() + " ("; for (OrganisationUnit unit : organisationUnits) { - sql += "ou.path like '" + unit.getPath() + "%' or "; + sql += "ou.path like '" + unit.getStoredPath() + "%' or "; } sql = TextUtils.removeLastOr(sql) + ") "; @@ -385,7 +385,7 @@ private String buildOrganisationUnitDistinctUidsSql(OrganisationUnitQueryParams sql += hlp.whereAnd() + " ("; for (OrganisationUnit parent : params.getParents()) { - sql += "o.path like '" + escapeSql(parent.getPath()) + "%'" + " or "; + sql += "o.path like '" + escapeSql(parent.getStoredPath()) + "%'" + " or "; } sql = TextUtils.removeLastOr(sql) + ") "; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java index 9e4c5aeef6cb..4aa808ec36c0 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java @@ -183,7 +183,10 @@ private QueryWithOrderBy buildProgramInstanceHql(ProgramInstanceQueryParams para for (OrganisationUnit organisationUnit : params.getOrganisationUnits()) { ouClause += - orHlp.or() + "pi.organisationUnit.path LIKE '" + organisationUnit.getPath() + "%'"; + orHlp.or() + + "pi.organisationUnit.path LIKE '" + + organisationUnit.getStoredPath() + + "%'"; } ouClause += ")"; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java index a45565d1c9d3..f098a8253aa2 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java @@ -880,7 +880,11 @@ private String getFromSubQueryJoinOrgUnitConditions(TrackedEntityInstanceQueryPa OrganisationUnit ou = organisationUnitStore.getByUid(organisationUnit.getUid()); if (ou != null) { - orgUnits.append(orHlp.or()).append("OU.path LIKE '").append(ou.getPath()).append("%'"); + orgUnits + .append(orHlp.or()) + .append("OU.path LIKE '") + .append(ou.getStoredPath()) + .append("%'"); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java index 25d7ac0451aa..66d49ce8b38e 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java @@ -159,7 +159,7 @@ private List getTrackedEntityDataValueAuditCriteria( List orgUnitPredicates = new ArrayList<>(); for (OrganisationUnit orgUnit : params.getOrgUnits()) { - orgUnitPredicates.add(builder.like(ou.get("path"), (orgUnit.getPath() + "%"))); + orgUnitPredicates.add(builder.like(ou.get("path"), (orgUnit.getStoredPath() + "%"))); } predicates.add(builder.or(orgUnitPredicates.toArray(Predicate[]::new))); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/JdbcCompleteDataSetRegistrationExchangeStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/JdbcCompleteDataSetRegistrationExchangeStore.java index 2c4abd7dcffb..86e31ee80565 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/JdbcCompleteDataSetRegistrationExchangeStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/dataset/JdbcCompleteDataSetRegistrationExchangeStore.java @@ -272,7 +272,7 @@ private static String createOrgUnitClause( clause += params.getOrganisationUnits().stream() - .map(o -> " ou.path LIKE '" + o.getPath() + "%' OR ") + .map(o -> " ou.path LIKE '" + o.getStoredPath() + "%' OR ") .collect(Collectors.joining()); return TextUtils.removeLastOr(clause) + " ) "; diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java index be486251fa04..3fa3650674d5 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java @@ -290,7 +290,7 @@ private String getDataValueSql(DataExportParams params) { sql += "and ("; for (OrganisationUnit parent : params.getOrganisationUnits()) { - sql += "ou.path like '" + parent.getPath() + "%' or "; + sql += "ou.path like '" + parent.getStoredPath() + "%' or "; } sql = TextUtils.removeLastOr(sql) + ") "; diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java index 7eaa6561a9fc..e30f0042ce89 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java @@ -1401,7 +1401,7 @@ private String createAccessibleSql( private String createDescendantsSql( User user, EventQueryParams params, MapSqlParameterSource mapSqlParameterSource) { - mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getPath()); + mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getStoredPath()); if (isProgramRestricted(params.getProgram())) { return createCaptureScopeQuery( @@ -1414,7 +1414,7 @@ private String createDescendantsSql( private String createChildrenSql( User user, EventQueryParams params, MapSqlParameterSource mapSqlParameterSource) { - mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getPath()); + mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getStoredPath()); String customChildrenQuery = " AND (ou.hierarchylevel = " @@ -1437,7 +1437,7 @@ private String createChildrenSql( private String createSelectedSql( User user, EventQueryParams params, MapSqlParameterSource mapSqlParameterSource) { - mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getPath()); + mapSqlParameterSource.addValue(COLUMN_ORG_UNIT_PATH, params.getOrgUnit().getStoredPath()); String orgUnitPathEqualsMatchQuery = " ou.path = :" diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java index da4b9bdfbceb..b7a21fafa014 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java @@ -880,9 +880,7 @@ private DataValueContextBuilder createDataValueContext(DataValue dataValue) { if (ouId != null) { OrganisationUnit ou = new OrganisationUnit(); ou.setUid(ouId); - // we set the path here just for the tests. This is usually done by the persistence layer - // but there is no interaction with that in these tests. - ou.setPath(ou.getPath()); + ou.updatePath(); builder.orgUnit(ou); } if (coId != null) { diff --git a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionDataValueFetcher.java b/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionDataValueFetcher.java index d69c21e36bc3..88cc2e95cd6b 100644 --- a/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionDataValueFetcher.java +++ b/dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/predictor/PredictionDataValueFetcher.java @@ -207,7 +207,8 @@ public void init( this.outputDataElementOperand = outputDataElementOperand; orgUnitLookup = - orgUnits.stream().collect(Collectors.toMap(OrganisationUnit::getPath, Function.identity())); + orgUnits.stream() + .collect(Collectors.toMap(OrganisationUnit::getStoredPath, Function.identity())); dataElementLookup = dataElements.stream() .collect(toMap(DataElement::getId, Function.identity(), (de1, de2) -> de1)); @@ -359,7 +360,7 @@ private PredictionData getPredictionData( addValueToMap(dv, map); } - if (ddv.getSourcePath().equals(dv.getSource().getPath()) + if (ddv.getSourcePath().equals(dv.getSource().getStoredPath()) && ddv.getDataElementId() == outputDataElementOperand.getDataElement().getId() && (outputDataElementOperand.getCategoryOptionCombo() == null || ddv.getCategoryOptionComboId() diff --git a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java index 64322a7ea8a7..4e80687468b9 100644 --- a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java +++ b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java @@ -177,7 +177,7 @@ public void delete(Collection dataElements, OrganisationUnit parent getQuery(hql) .setParameterList("dataElements", dataElements) - .setParameter("path", parent.getPath() + "%") + .setParameter("path", parent.getStoredPath() + "%") .executeUpdate(); } diff --git a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/outlierdetection/util/OutlierDetectionUtils.java b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/outlierdetection/util/OutlierDetectionUtils.java index a74074da9f17..095702c34055 100644 --- a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/outlierdetection/util/OutlierDetectionUtils.java +++ b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/outlierdetection/util/OutlierDetectionUtils.java @@ -48,7 +48,7 @@ public static String getOrgUnitPathClause(List orgUnits) { String sql = "("; for (OrganisationUnit ou : orgUnits) { - sql += "ou.\"path\" like '" + ou.getPath() + "%' or "; + sql += "ou.\"path\" like '" + ou.getStoredPath() + "%' or "; } return StringUtils.trim(TextUtils.removeLastOr(sql)) + ")"; diff --git a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationResultStore.java b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationResultStore.java index c95bdc2923c5..05bc8f6e447a 100644 --- a/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationResultStore.java +++ b/dhis-2/dhis-services/dhis-service-validation/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationResultStore.java @@ -201,7 +201,8 @@ public List getValidationResults( + "vr.validationRule in :validationRules and vr.period in :periods "); if (orgUnit != null) { - query.setParameter("orgUnitPath", orgUnit.getPath() + (includeOrgUnitDescendants ? "%" : "")); + query.setParameter( + "orgUnitPath", orgUnit.getStoredPath() + (includeOrgUnitDescendants ? "%" : "")); } query.setParameter("validationRules", validationRules); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataAnalysisController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataAnalysisController.java index 97827882ff5f..70abef69435b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataAnalysisController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataAnalysisController.java @@ -671,7 +671,7 @@ private List validationResultsListToResponse( if (organisationUnit != null) { validationResultView.setOrganisationUnitId(organisationUnit.getUid()); validationResultView.setOrganisationUnitDisplayName(organisationUnit.getDisplayName()); - validationResultView.setOrganisationUnitPath(organisationUnit.getPath()); + validationResultView.setOrganisationUnitPath(organisationUnit.getStoredPath()); validationResultView.setOrganisationUnitAncestorNames(organisationUnit.getAncestorNames()); } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/LockExceptionController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/LockExceptionController.java index fae465a91b42..a6509100a340 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/LockExceptionController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/LockExceptionController.java @@ -307,6 +307,6 @@ public void deleteLockException( private boolean canCapture(OrganisationUnit captureTarget) { return currentUserService.currentUserIsSuper() || currentUserService.getCurrentUserOrganisationUnits().stream() - .anyMatch(ou -> captureTarget.getPath().startsWith(ou.getPath())); + .anyMatch(ou -> captureTarget.getPath().startsWith(ou.getStoredPath())); } } From 478f1da44a6fcf89edc0a3dee9fcb5a3ee612094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 10 Jan 2025 14:29:40 +0100 Subject: [PATCH 2/2] fix: Update code --- .../organisationunit/OrganisationUnit.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java index 73a14024bc44..2473f3f291ce 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java @@ -29,16 +29,6 @@ import static org.apache.commons.collections4.CollectionUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isNotEmpty; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -75,6 +65,15 @@ import org.hisp.dhis.schema.annotation.Property; import org.hisp.dhis.user.User; import org.locationtech.jts.geom.Geometry; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; /** * @author Kristian Nordal @@ -738,9 +737,7 @@ public String getPath() { Collections.reverse(pathList); - this.path = PATH_SEP + StringUtils.join(pathList, PATH_SEP); - - return this.path; + return PATH_SEP + StringUtils.join(pathList, PATH_SEP); } /**