use of org.hisp.dhis.common.DateRange in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validateAttrOptCombo.
private void validateAttrOptCombo(MetadataProperties mdProps, MetadataCaches mdCaches, ImportConfig config) throws ImportConflictException {
final Period pe = mdProps.period;
if (mdProps.attrOptCombo == null) {
if (config.isRequireAttrOptionCombos()) {
throw new ImportConflictException(new ImportConflict("Attribute option combo", "Attribute option combo is required but is not specified"));
} else {
mdProps.attrOptCombo = categoryService.getDefaultCategoryOptionCombo();
}
}
final CategoryOptionCombo aoc = mdProps.attrOptCombo;
DateRange range = aoc.getDateRange(mdProps.dataSet);
if ((range.getStartDate() != null && range.getStartDate().compareTo(pe.getStartDate()) > 0) || (range.getEndDate() != null && range.getEndDate().compareTo(pe.getEndDate()) < 0)) {
throw new ImportConflictException(new ImportConflict(mdProps.orgUnit.getUid(), String.format("Period: %s is not within range of attribute option combo: %s", pe.getIsoDate(), aoc.getUid())));
}
final String aocOrgUnitKey = aoc.getUid() + mdProps.orgUnit.getUid();
boolean isOrgUnitValidForAoc = mdCaches.getAttrOptComboOrgUnitMap().get(aocOrgUnitKey, () -> {
Set<OrganisationUnit> aocOrgUnits = aoc.getOrganisationUnits();
return aocOrgUnits == null || mdProps.orgUnit.isDescendant(aocOrgUnits);
});
if (!isOrgUnitValidForAoc) {
throw new ImportConflictException(new ImportConflict(mdProps.orgUnit.getUid(), String.format("Organisation unit: %s is not valid for attribute option combo %s", mdProps.orgUnit.getUid(), aoc.getUid())));
}
}
use of org.hisp.dhis.common.DateRange in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValuePeriodWithinAttrOptionComboRange.
@Test
void testCheckDataValuePeriodWithinAttrOptionComboRange() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
String key = valueContext.getAttrOptionCombo().getUid() + valueContext.getDataElement().getUid();
context.getAttrOptionComboDateRangeMap().put(key, new DateRange(new Date(), null));
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7638, "Period: `<object1>` is not within date range of attribute option combo: `<object2>`", context, dataValue.getPeriod(), dataValue.getAttributeOptionCombo());
}
use of org.hisp.dhis.common.DateRange in project dhis2-core by dhis2.
the class CategoryOptionComboTest method testGetDateRangeProgram.
@Test
void testGetDateRangeProgram() {
DateRange dateRange;
dateRange = optionComboA.getDateRange(program);
assertNull(dateRange.getStartDate());
assertNull(dateRange.getEndDate());
dateRange = optionComboB.getDateRange(program);
assertEquals(jan1, dateRange.getStartDate());
assertEquals(jan4, dateRange.getEndDate());
dateRange = optionComboC.getDateRange(program);
assertEquals(jan2, dateRange.getStartDate());
assertEquals(jan4, dateRange.getEndDate());
program.setOpenDaysAfterCoEndDate(2);
dateRange = optionComboA.getDateRange(program);
assertNull(dateRange.getStartDate());
assertNull(dateRange.getEndDate());
dateRange = optionComboB.getDateRange(program);
assertEquals(jan1, dateRange.getStartDate());
assertEquals(jan6, dateRange.getEndDate());
dateRange = optionComboC.getDateRange(program);
assertEquals(jan2, dateRange.getStartDate());
assertEquals(jan6, dateRange.getEndDate());
}
Aggregations