Skip to content

Commit

Permalink
fix: Remove unnecessary calls to the DB during DataValueSet import [D… (
Browse files Browse the repository at this point in the history
#15688)

* fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16159]

* fix: Remove unused dep and clean up test [DHIS2-16159]

* fix format
  • Loading branch information
david-mackessy authored Nov 14, 2023
1 parent 520136b commit ebae39f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -645,8 +642,7 @@ private void checkDataValueOrgUnitValidForAttrOptionCombo(

private boolean isOrgUnitValidForAttrOptionCombo(DataValueContext valueContext) {
Set<OrganisationUnit> aocOrgUnits = valueContext.getAttrOptionCombo().getOrganisationUnits();
return aocOrgUnits == null
|| organisationUnitService.isDescendant(valueContext.getOrgUnit(), aocOrgUnits);
return aocOrgUnits == null || valueContext.getOrgUnit().isDescendant(aocOrgUnits);
}

private static void checkDataValueTargetDataSets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -99,8 +98,6 @@ class DataValueSetImportValidatorTest {

private DataValueSetImportValidator validator;

private OrganisationUnitService organisationUnitService;

private final CategoryCombo defaultCombo = new CategoryCombo();

@BeforeEach
Expand All @@ -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()))
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ebae39f

Please sign in to comment.