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;
}
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);
}
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());
}
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());
}
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);
}
Aggregations