use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class AbstractEnrollmentService method updateEnrollments.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries updateEnrollments(List<Enrollment> enrollments, ImportOptions importOptions) {
if (importOptions == null) {
importOptions = new ImportOptions();
}
ImportSummaries importSummaries = new ImportSummaries();
int counter = 0;
for (Enrollment enrollment : enrollments) {
importSummaries.addImportSummary(updateEnrollment(enrollment, importOptions));
if (counter % FLUSH_FREQUENCY == 0) {
clearSession();
}
counter++;
}
return importSummaries;
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class JacksonEnrollmentService method addEnrollmentList.
private ImportSummaries addEnrollmentList(List<Enrollment> enrollments, ImportOptions importOptions) {
ImportSummaries importSummaries = new ImportSummaries();
List<Enrollment> create = new ArrayList<>();
List<Enrollment> update = new ArrayList<>();
List<String> delete = new ArrayList<>();
if (importOptions.getImportStrategy().isCreate()) {
create.addAll(enrollments);
} else if (importOptions.getImportStrategy().isCreateAndUpdate()) {
for (Enrollment enrollment : enrollments) {
if (StringUtils.isEmpty(enrollment.getEnrollment())) {
create.add(enrollment);
} else {
if (!programInstanceService.programInstanceExists(enrollment.getEnrollment())) {
create.add(enrollment);
} else {
update.add(enrollment);
}
}
}
} else if (importOptions.getImportStrategy().isUpdate()) {
update.addAll(enrollments);
} else if (importOptions.getImportStrategy().isDelete()) {
delete.addAll(enrollments.stream().map(Enrollment::getEnrollment).collect(Collectors.toList()));
}
importSummaries.addImportSummaries(addEnrollments(create, importOptions));
importSummaries.addImportSummaries(updateEnrollments(update, importOptions));
importSummaries.addImportSummaries(deleteEnrollments(delete));
return importSummaries;
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class AbstractEnrollmentService method handleEvents.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private ImportSummaries handleEvents(Enrollment enrollment, ProgramInstance programInstance, ImportOptions importOptions) {
List<Event> create = new ArrayList<>();
List<Event> update = new ArrayList<>();
for (Event event : enrollment.getEvents()) {
event.setEnrollment(enrollment.getEnrollment());
event.setProgram(programInstance.getProgram().getUid());
if (!programStageInstanceService.programStageInstanceExists(event.getEvent())) {
create.add(event);
} else {
update.add(event);
}
}
ImportSummaries importSummaries = new ImportSummaries();
importSummaries.addImportSummaries(eventService.addEvents(create, importOptions));
importSummaries.addImportSummaries(eventService.updateEvents(update, false));
return importSummaries;
}
use of org.hisp.dhis.dxf2.common.ImportOptions 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;
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class AbstractEnrollmentService method addEnrollments.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries addEnrollments(List<Enrollment> enrollments, ImportOptions importOptions) {
if (importOptions == null) {
importOptions = new ImportOptions();
}
ImportSummaries importSummaries = new ImportSummaries();
int counter = 0;
for (Enrollment enrollment : enrollments) {
importSummaries.addImportSummary(addEnrollment(enrollment, importOptions));
if (counter % FLUSH_FREQUENCY == 0) {
clearSession();
}
counter++;
}
return importSummaries;
}
Aggregations