From 63fe07b4574ee4dc877ab057052802bb54e48b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 8 Jan 2025 19:20:27 +0100 Subject: [PATCH] fix: Update code --- .../organisationunit/OrganisationUnit.java | 13 ++++++++++- ...lyticsZscoreSqlStatementProcessorTest.java | 4 ++-- .../acl/DefaultTrackerAccessManagerTest.java | 23 ++++++++++++------- .../export/OperationsParamsValidatorTest.java | 2 ++ 4 files changed, 31 insertions(+), 11 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 0f288eca1098..9812e2f9b1d0 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 @@ -801,11 +801,22 @@ public String getStoredPath() { return path; } - /** Do not set directly, managed by persistence layer. */ + /** + * Note that the {@code path} 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} 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/test/java/org/hisp/dhis/analytics/outlier/service/AnalyticsZscoreSqlStatementProcessorTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/outlier/service/AnalyticsZscoreSqlStatementProcessorTest.java index 9171716f6182..5c1c716a90eb 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/outlier/service/AnalyticsZscoreSqlStatementProcessorTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/outlier/service/AnalyticsZscoreSqlStatementProcessorTest.java @@ -83,8 +83,8 @@ public void setUp() { ouA = createOrganisationUnit('A'); ouB = createOrganisationUnit('B'); - ouA.getPath(); - ouB.getPath(); + ouA.updatePath(); + ouB.updatePath(); } @Test diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/acl/DefaultTrackerAccessManagerTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/acl/DefaultTrackerAccessManagerTest.java index 1f63f94d30fb..ef7c4945f7c7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/acl/DefaultTrackerAccessManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/acl/DefaultTrackerAccessManagerTest.java @@ -53,7 +53,7 @@ void shouldHaveAccessWhenProgramOpenAndSearchAccessAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(OPEN); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); user.setTeiSearchOrganisationUnits(Set.of(orgUnit)); @@ -67,7 +67,7 @@ void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(OPEN); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); assertFalse( trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit), @@ -77,7 +77,7 @@ void shouldNotHaveAccessWhenProgramOpenAndSearchAccessNotAvailable() { @Test void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() { User user = new User(); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); user.setTeiSearchOrganisationUnits(Set.of(orgUnit)); @@ -89,7 +89,7 @@ void shouldHaveAccessWhenProgramNullAndSearchAccessAvailable() { @Test void shouldNotHaveAccessWhenProgramNullAndSearchAccessNotAvailable() { User user = new User(); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); assertFalse( trackerAccessManager.canAccess(UserDetails.fromUser(user), null, orgUnit), @@ -101,7 +101,7 @@ void shouldHaveAccessWhenProgramClosedAndCaptureAccessAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(CLOSED); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); user.setOrganisationUnits(Set.of(orgUnit)); @@ -115,7 +115,7 @@ void shouldNotHaveAccessWhenProgramClosedAndCaptureAccessNotAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(CLOSED); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); assertFalse( trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit), @@ -127,7 +127,7 @@ void shouldHaveAccessWhenProgramProtectedAndCaptureAccessAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(PROTECTED); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); user.setOrganisationUnits(Set.of(orgUnit)); @@ -141,10 +141,17 @@ void shouldNotHaveAccessWhenProgramProtectedAndCaptureAccessNotAvailable() { User user = new User(); Program program = new Program(); program.setAccessLevel(PROTECTED); - OrganisationUnit orgUnit = new OrganisationUnit(); + OrganisationUnit orgUnit = createOrgUnit(); assertFalse( trackerAccessManager.canAccess(UserDetails.fromUser(user), program, orgUnit), "User should not have access to protected program"); } + + private OrganisationUnit createOrgUnit() { + OrganisationUnit ou = new OrganisationUnit(); + ou.setAutoFields(); + ou.updatePath(); + return ou; + } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/OperationsParamsValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/OperationsParamsValidatorTest.java index 5ab7b641dbcb..cf22cd6f4b34 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/OperationsParamsValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/OperationsParamsValidatorTest.java @@ -108,6 +108,7 @@ class OperationsParamsValidatorTest { public void setUp() { OrganisationUnit organisationUnit = createOrgUnit("orgUnit", PARENT_ORG_UNIT_UID); organisationUnit.setChildren(Set.of(captureScopeOrgUnit, searchScopeOrgUnit)); + organisationUnit.updatePath(); } @Test @@ -389,6 +390,7 @@ void shouldReturnOrgUnitsWhenUserIsSuperButHasNoAccessToOrgUnit() private OrganisationUnit createOrgUnit(String name, String uid) { OrganisationUnit orgUnit = new OrganisationUnit(name); orgUnit.setUid(uid); + orgUnit.updatePath(); return orgUnit; } }