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