Search in sources :

Example 1 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidator method skipDataValue.

/*
     * DataValue validation
     */
public boolean skipDataValue(DataValueEntry dataValue, ImportContext context, DataSetContext dataSetContext, DataValueContext valueContext) {
    ImportSummary summary = context.getSummary();
    int skippedBefore = summary.skippedValueCount();
    int totalConflictsBefore = summary.getTotalConflictOccurrenceCount();
    for (DataValueValidation validation : dataValueValidations) {
        validation.validate(dataValue, context, dataSetContext, valueContext);
        if (summary.skippedValueCount() > skippedBefore || summary.getTotalConflictOccurrenceCount() > totalConflictsBefore) {
            return true;
        }
    }
    return false;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 2 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testValidateDataValueOrgUnitInUserHierarchy.

@Test
void testValidateDataValueOrgUnitInUserHierarchy() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).currentOrgUnits(emptySet()).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    String currentUserId = context.getCurrentUser().getUid();
    assertConflict(ErrorCode.E7617, "Organisation unit: `<object1>` not in hierarchy of current user: `" + currentUserId + "`", context, dataValue.getOrgUnit(), currentUserId);
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 3 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValueNotAfterLatestOpenFuturePeriod.

@Test
void testCheckDataValueNotAfterLatestOpenFuturePeriod() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).isIso8601(true).build();
    context.getDataElementLatestFuturePeriodMap().put(valueContext.getDataElement().getUid(), PeriodType.getPeriodFromIsoString("2020-01"));
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7641, "Period: `<object1>` is after latest open future period: `202001` for data element: `<object2>`", context, dataValue.getPeriod(), dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 4 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValuePeriodIsOpenNow.

@Test
void testCheckDataValuePeriodIsOpenNow() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
    DataInputPeriod inputPeriod = new DataInputPeriod();
    inputPeriod.setPeriod(PeriodType.getPeriodFromIsoString("2019"));
    dataSetContext.getDataSet().setDataInputPeriods(singleton(inputPeriod));
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7643, "Period: `<object1>` is not open for this data set at this time: `<object2>`", context, dataValue.getPeriod(), dataSetContext.getDataSet().getUid());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataInputPeriod(org.hisp.dhis.dataset.DataInputPeriod) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 5 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method createMinimalImportContext.

private ImportContextBuilder createMinimalImportContext(DataValueContext valueContext) {
    User currentUser = new User();
    currentUser.setUsername("Guest");
    currentUser.setUid(CodeGenerator.generateUid());
    return ImportContext.builder().summary(new ImportSummary()).strategy(ImportStrategy.CREATE).importOptions(new ImportOptions()).currentUser(currentUser).i18n(i18n).currentOrgUnits(valueContext == null ? null : singleton(valueContext.getOrgUnit())).singularNameForType(DataValueSetImportValidatorTest::getSingularNameForType);
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Aggregations

DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)28 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)28 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 Test (org.junit.jupiter.api.Test)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 Date (java.util.Date)1 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DateRange (org.hisp.dhis.common.DateRange)1 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 User (org.hisp.dhis.user.User)1