Search in sources :

Example 11 with ImportSummaries

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

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

Example 13 with 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;
}
Also used : ArrayList(java.util.ArrayList) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Example 14 with 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;
}
Also used : ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 15 with 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());
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)26 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)10 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)9 InputStream (java.io.InputStream)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 Date (java.util.Date)6 Lists (com.google.common.collect.Lists)5 IOException (java.io.IOException)5 List (java.util.List)5 Set (java.util.Set)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)5 OrganisationUnitSelectionMode (org.hisp.dhis.common.OrganisationUnitSelectionMode)5 StreamUtils (org.hisp.dhis.commons.util.StreamUtils)5 TextUtils (org.hisp.dhis.commons.util.TextUtils)5 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 StringUtils (org.apache.commons.lang3.StringUtils)4