From ba9f6db44b7d73cb9165102dc88778fe966374fe Mon Sep 17 00:00:00 2001 From: David Mackessy Date: Wed, 15 Nov 2023 08:07:48 +0000 Subject: [PATCH] fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16159 --- .../DataValueSetImportValidator.java | 6 +----- .../DataValueSetImportValidatorTest.java | 16 +--------------- 2 files changed, 2 insertions(+), 20 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 cccdc7053c59..d2c9ec0c6cc7 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 @@ -54,7 +54,6 @@ import org.hisp.dhis.dxf2.importsummary.ImportStatus; import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.security.acl.AclService; @@ -78,8 +77,6 @@ public class DataValueSetImportValidator { private final DataValueService dataValueService; - private final OrganisationUnitService organisationUnitService; - /** Validation on the {@link DataSet} level */ interface DataSetValidation { void validate(DataValueSet dataValueSet, ImportContext context, DataSetContext dataSetContext); @@ -645,8 +642,7 @@ private void checkDataValueOrgUnitValidForAttrOptionCombo( private boolean isOrgUnitValidForAttrOptionCombo(DataValueContext valueContext) { Set aocOrgUnits = valueContext.getAttrOptionCombo().getOrganisationUnits(); - return aocOrgUnits == null - || organisationUnitService.isDescendant(valueContext.getOrgUnit(), aocOrgUnits); + return aocOrgUnits == null || valueContext.getOrgUnit().isDescendant(aocOrgUnits); } private static void checkDataValueTargetDataSets( 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 a4c87d0ef9ad..da4b9bdfbceb 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 @@ -72,7 +72,6 @@ import org.hisp.dhis.importexport.ImportStrategy; import org.hisp.dhis.option.OptionSet; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.period.PeriodTypeEnum; @@ -99,8 +98,6 @@ class DataValueSetImportValidatorTest { private DataValueSetImportValidator validator; - private OrganisationUnitService organisationUnitService; - private final CategoryCombo defaultCombo = new CategoryCombo(); @BeforeEach @@ -109,16 +106,11 @@ void setUp() { lockExceptionStore = mock(LockExceptionStore.class); approvalService = mock(DataApprovalService.class); dataValueService = mock(DataValueService.class); - organisationUnitService = mock(OrganisationUnitService.class); i18n = mock(I18n.class); validator = new DataValueSetImportValidator( - aclService, - lockExceptionStore, - approvalService, - dataValueService, - organisationUnitService); + aclService, lockExceptionStore, approvalService, dataValueService); validator.init(); setupUserCanWriteCategoryOptions(true); when(i18n.getString(anyString())) @@ -298,12 +290,6 @@ void testValidateDataValueAttrOptionComboAccess() { @Test void testValidateDataValueOrgUnitInUserHierarchy() { - when(organisationUnitService.isDescendant(any(OrganisationUnit.class), any(Set.class))) - .thenReturn(false); - when(organisationUnitService.isDescendant( - any(OrganisationUnit.class), any(OrganisationUnit.class))) - .thenReturn(false); - DataValue dataValue = createRandomDataValue(); DataValueContext valueContext = createDataValueContext(dataValue).build(); DataSetContext dataSetContext = createMinimalDataSetContext().build();