From 4bd1398f0c07bb980b8efd3579f4c1165fc069e3 Mon Sep 17 00:00:00 2001 From: David Mackessy <131455290+david-mackessy@users.noreply.github.com> Date: Sat, 11 Nov 2023 21:12:29 +0000 Subject: [PATCH] fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16138] (#15646) --- .../dxf2/datavalueset/DataValueSetImportValidator.java | 4 +--- .../datavalueset/DataValueSetImportValidatorTest.java | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java index 2e71592e11fb..cccdc7053c59 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java @@ -351,9 +351,7 @@ private void validateDataValueOrgUnitInUserHierarchy( .getOrgUnitInHierarchyMap() .get( valueContext.getOrgUnit().getUid(), - () -> - organisationUnitService.isDescendant( - valueContext.getOrgUnit(), context.getCurrentOrgUnits())); + () -> valueContext.getOrgUnit().isDescendant(context.getCurrentOrgUnits())); if (!inUserHierarchy) { context.addConflict( 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 4db3dd2d5ead..a4c87d0ef9ad 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 @@ -110,11 +110,6 @@ void setUp() { approvalService = mock(DataApprovalService.class); dataValueService = mock(DataValueService.class); organisationUnitService = mock(OrganisationUnitService.class); - when(organisationUnitService.isDescendant(any(OrganisationUnit.class), any(Set.class))) - .thenReturn(true); - when(organisationUnitService.isDescendant( - any(OrganisationUnit.class), any(OrganisationUnit.class))) - .thenReturn(true); i18n = mock(I18n.class); validator = @@ -899,6 +894,9 @@ 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()); builder.orgUnit(ou); } if (coId != null) {