Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove unnecessary calls to the DB during DataValueSet import [D… #15688

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading