use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method addTrackedEntityInstance.
@Override
public ImportSummary addTrackedEntityInstance(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions) {
if (importOptions == null) {
importOptions = new ImportOptions();
}
ImportSummary importSummary = new ImportSummary(trackedEntityInstance.getTrackedEntityInstance());
trackedEntityInstance.trimValuesToNull();
Set<ImportConflict> importConflicts = new HashSet<>();
importConflicts.addAll(checkTrackedEntity(trackedEntityInstance, importOptions));
importConflicts.addAll(checkAttributes(trackedEntityInstance, importOptions));
importSummary.setConflicts(importConflicts);
if (!importConflicts.isEmpty()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance(trackedEntityInstance, importOptions, importSummary);
if (entityInstance == null) {
return importSummary;
}
teiService.addTrackedEntityInstance(entityInstance);
updateRelationships(trackedEntityInstance, entityInstance);
updateAttributeValues(trackedEntityInstance, entityInstance);
updateDateFields(trackedEntityInstance, entityInstance);
teiService.updateTrackedEntityInstance(entityInstance);
importSummary.setReference(entityInstance.getUid());
importSummary.getImportCount().incrementImported();
importOptions.setStrategy(ImportStrategy.CREATE_AND_UPDATE);
importSummary.setEnrollments(handleEnrollments(trackedEntityInstance, entityInstance, importOptions));
return importSummary;
}
use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validateHasMatchingPeriodTypes.
private static void validateHasMatchingPeriodTypes(MetaDataProperties props) throws ImportConflictException {
// TODO MdCache?
PeriodType dsPeType = props.dataSet.getPeriodType();
PeriodType peType = props.period.getPeriodType();
if (!dsPeType.equals(peType)) {
throw new ImportConflictException(new ImportConflict(props.period.getUid(), String.format("Period type of period: %s is not equal to the period type of data set: %s", props.period.getIsoDate(), props.dataSet.getPeriodType())));
}
}
use of org.hisp.dhis.dxf2.importsummary.ImportConflict 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.requireAttrOptionCombos) {
throw new ImportConflictException(new ImportConflict("Attribute option combo", "Attribute option combo is required but is not specified"));
} else {
mdProps.attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
}
final DataElementCategoryOptionCombo aoc = mdProps.attrOptCombo;
DateRange range = aoc.getDateRange();
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.attrOptComboOrgUnitMap.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.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.
the class AbstractEnrollmentService method checkScope.
private List<ImportConflict> checkScope(org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute, String value, OrganisationUnit organisationUnit, Program program) {
List<ImportConflict> importConflicts = new ArrayList<>();
if (trackedEntityAttribute == null || value == null) {
return importConflicts;
}
String errorMessage = trackedEntityAttributeService.validateScope(trackedEntityAttribute, value, trackedEntityInstance, organisationUnit, program);
if (errorMessage != null) {
importConflicts.add(new ImportConflict("Attribute.value", errorMessage));
}
return importConflicts;
}
use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.
the class AbstractEnrollmentService method validateAttributeType.
private List<ImportConflict> validateAttributeType(Attribute attribute, ImportOptions importOptions) {
List<ImportConflict> importConflicts = Lists.newArrayList();
TrackedEntityAttribute teAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
if (teAttribute == null) {
importConflicts.add(new ImportConflict("Attribute.attribute", "Does not point to a valid attribute."));
return importConflicts;
}
String errorMessage = trackedEntityAttributeService.validateValueType(teAttribute, attribute.getValue());
if (errorMessage != null) {
importConflicts.add(new ImportConflict("Attribute.value", errorMessage));
}
return importConflicts;
}
Aggregations