Search in sources :

Example 6 with ImportConflict

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;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) HashSet(java.util.HashSet) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 7 with ImportConflict

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())));
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 8 with ImportConflict

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())));
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DateRange(org.hisp.dhis.common.DateRange) Period(org.hisp.dhis.period.Period) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 9 with ImportConflict

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;
}
Also used : ArrayList(java.util.ArrayList) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 10 with ImportConflict

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;
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Aggregations

ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)23 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)9 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)8 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 DataElement (org.hisp.dhis.dataelement.DataElement)4 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)4 Program (org.hisp.dhis.program.Program)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 Date (java.util.Date)3 IdScheme (org.hisp.dhis.common.IdScheme)3 CachingMap (org.hisp.dhis.commons.collection.CachingMap)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Period (org.hisp.dhis.period.Period)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 IdentifiableObjectCallable (org.hisp.dhis.system.callable.IdentifiableObjectCallable)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)2