use of org.hisp.dhis.dxf2.importsummary.ImportSummaries in project dhis2-core by dhis2.
the class AbstractEnrollmentService method deleteEnrollments.
@Override
public ImportSummaries deleteEnrollments(List<String> uids) {
ImportSummaries importSummaries = new ImportSummaries();
int counter = 0;
for (String uid : uids) {
importSummaries.addImportSummary(deleteEnrollment(uid));
if (counter % FLUSH_FREQUENCY == 0) {
clearSession();
}
counter++;
}
return importSummaries;
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummaries 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.importsummary.ImportSummaries 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.importsummary.ImportSummaries 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;
}
use of org.hisp.dhis.dxf2.importsummary.ImportSummaries in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleEventDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful.
@Test
public void testHandleEventDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful() throws Exception {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
ImportSummaries expectedSummary = new ImportSummaries();
ImportSummary summary = new ImportSummary();
summary.setStatus(ImportStatus.SUCCESS);
expectedSummary.addImportSummary(summary);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
when(metadataSyncPreProcessor.handleEventDataPush(mockRetryContext)).thenReturn(expectedSummary);
ImportSummaries actualSummary = metadataSyncPreProcessor.handleEventDataPush(mockRetryContext);
assertEquals(expectedSummary.getImportSummaries().get(0).getStatus(), actualSummary.getImportSummaries().get(0).getStatus());
}
Aggregations