Search in sources :

Example 1 with ImportConflict

use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method getTrackedEntityInstance.

public org.hisp.dhis.trackedentity.TrackedEntityInstance getTrackedEntityInstance(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions, ImportSummary importSummary) {
    if (StringUtils.isEmpty(trackedEntityInstance.getOrgUnit())) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "No org unit ID in tracked entity instance object."));
        return null;
    }
    org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
    OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit());
    if (organisationUnit == null) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid org unit ID: " + trackedEntityInstance.getOrgUnit()));
        return null;
    }
    entityInstance.setOrganisationUnit(organisationUnit);
    TrackedEntity trackedEntity = getTrackedEntity(importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity());
    if (trackedEntity == null) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid tracked entity ID: " + trackedEntityInstance.getTrackedEntity()));
        return null;
    }
    entityInstance.setTrackedEntity(trackedEntity);
    entityInstance.setUid(CodeGenerator.isValidUid(trackedEntityInstance.getTrackedEntityInstance()) ? trackedEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateUid());
    return entityInstance;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 2 with ImportConflict

use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method checkRelationships.

private List<ImportConflict> checkRelationships(TrackedEntityInstance trackedEntityInstance) {
    List<ImportConflict> importConflicts = new ArrayList<>();
    for (org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship : trackedEntityInstance.getRelationships()) {
        RelationshipType relationshipType = manager.get(RelationshipType.class, relationship.getRelationship());
        if (relationshipType == null) {
            importConflicts.add(new ImportConflict("Relationship.type", "Invalid type " + relationship.getRelationship()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA());
        if (entityInstanceA == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceA()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB());
        if (entityInstanceB == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceB()));
        }
    }
    return importConflicts;
}
Also used : ArrayList(java.util.ArrayList) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 3 with ImportConflict

use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method updateTrackedEntityInstance.

@Override
public ImportSummary updateTrackedEntityInstance(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(checkRelationships(trackedEntityInstance));
    importConflicts.addAll(checkAttributes(trackedEntityInstance, importOptions));
    org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, trackedEntityInstance.getTrackedEntityInstance());
    if (entityInstance == null) {
        importConflicts.add(new ImportConflict("TrackedEntityInstance", "trackedEntityInstance " + trackedEntityInstance.getTrackedEntityInstance() + " does not point to valid trackedEntityInstance"));
    }
    OrganisationUnit organisationUnit = manager.get(OrganisationUnit.class, trackedEntityInstance.getOrgUnit());
    if (organisationUnit == null) {
        importConflicts.add(new ImportConflict("OrganisationUnit", "orgUnit " + trackedEntityInstance.getOrgUnit() + " does not point to valid organisation unit"));
    }
    importSummary.setConflicts(importConflicts);
    if (!importConflicts.isEmpty()) {
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.getImportCount().incrementIgnored();
        return importSummary;
    }
    entityInstance.setInactive(trackedEntityInstance.isInactive());
    removeRelationships(entityInstance);
    removeAttributeValues(entityInstance);
    teiService.updateTrackedEntityInstance(entityInstance);
    updateRelationships(trackedEntityInstance, entityInstance);
    updateAttributeValues(trackedEntityInstance, entityInstance);
    updateDateFields(trackedEntityInstance, entityInstance);
    teiService.updateTrackedEntityInstance(entityInstance);
    importSummary.setStatus(ImportStatus.SUCCESS);
    importSummary.setReference(entityInstance.getUid());
    importSummary.getImportCount().incrementUpdated();
    importOptions.setStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importSummary.setEnrollments(handleEnrollments(trackedEntityInstance, entityInstance, importOptions));
    return importSummary;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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 4 with ImportConflict

use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.

the class AbstractEventService method validateDataValue.

private boolean validateDataValue(DataElement dataElement, String value, ImportSummary importSummary) {
    String status = ValidationUtils.dataValueIsValid(value, dataElement);
    if (status != null) {
        importSummary.getConflicts().add(new ImportConflict(dataElement.getUid(), status));
        importSummary.getImportCount().incrementIgnored();
        return false;
    }
    return true;
}
Also used : ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 5 with ImportConflict

use of org.hisp.dhis.dxf2.importsummary.ImportConflict in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method checkAttributes.

private List<ImportConflict> checkAttributes(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions) {
    List<ImportConflict> importConflicts = new ArrayList<>();
    for (Attribute attribute : trackedEntityInstance.getAttributes()) {
        TrackedEntityAttribute entityAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
        if (entityAttribute == null) {
            importConflicts.add(new ImportConflict("Attribute.attribute", "Invalid attribute " + attribute.getAttribute()));
            continue;
        }
        if (entityAttribute.isUnique()) {
            OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit());
            org.hisp.dhis.trackedentity.TrackedEntityInstance tei = teiService.getTrackedEntityInstance(trackedEntityInstance.getTrackedEntityInstance());
            importConflicts.addAll(checkScope(tei, entityAttribute, attribute.getValue(), organisationUnit));
        }
        importConflicts.addAll(validateAttributeType(attribute, importOptions));
    }
    return importConflicts;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ArrayList(java.util.ArrayList) 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