Search in sources :

Example 41 with ImportSummary

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

the class CompleteDataSetRegistrationController method postCompleteRegistrationsXml.

// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_XML)
public void postCompleteRegistrationsXml(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_XML, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_XML);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsXml(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toXml(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with ImportSummary

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

the class CompleteDataSetRegistrationController method postCompleteRegistrationsJson.

@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_JSON)
public void postCompleteRegistrationsJson(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_JSON, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_JSON);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsJson(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toJson(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with ImportSummary

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

the class DefaultCompleteDataSetRegistrationExchangeService method saveCompleteDataSetRegistrations.

private ImportSummary saveCompleteDataSetRegistrations(ImportOptions importOptions, TaskId id, CompleteDataSetRegistrations completeRegistrations) {
    Clock clock = new Clock(log).startClock().logTime("Starting complete data set registration import, options: " + importOptions);
    notifier.clear(id).notify(id, "Process started");
    // Start here so we can access any outer attributes for the configuration
    completeRegistrations.open();
    ImportSummary importSummary = new ImportSummary();
    // ---------------------------------------------------------------------
    // Set up import configuration
    // ---------------------------------------------------------------------
    importOptions = importOptions != null ? importOptions : ImportOptions.getDefaultImportOptions();
    log.info("Import options: " + importOptions);
    ImportConfig cfg = new ImportConfig(completeRegistrations, importOptions);
    // ---------------------------------------------------------------------
    // Set up meta-data
    // ---------------------------------------------------------------------
    MetaDataCaches caches = new MetaDataCaches();
    MetaDataCallables metaDataCallables = new MetaDataCallables(cfg);
    if (importOptions.isPreheatCacheDefaultFalse()) {
        caches.preheat(idObjManager, cfg);
    }
    // ---------------------------------------------------------------------
    // Perform import
    // ---------------------------------------------------------------------
    notifier.notify(id, "Importing complete data set registrations");
    int totalCount = batchImport(completeRegistrations, cfg, importSummary, metaDataCallables, caches);
    notifier.notify(id, NotificationLevel.INFO, "Import done", true).addTaskSummary(id, importSummary);
    ImportCount count = importSummary.getImportCount();
    clock.logTime(String.format("Complete data set registration import done, total: %d, imported: %d, updated: %d, deleted: %d", totalCount, count.getImported(), count.getUpdated(), count.getDeleted()));
    completeRegistrations.close();
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount) Clock(org.hisp.dhis.system.util.Clock)

Example 44 with ImportSummary

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

the class AbstractEnrollmentService method updateEnrollmentForNote.

@Override
public ImportSummary updateEnrollmentForNote(Enrollment enrollment) {
    if (enrollment == null || enrollment.getEnrollment() == null) {
        return new ImportSummary(ImportStatus.ERROR, "No enrollment or enrollment ID was supplied").incrementIgnored();
    }
    ImportSummary importSummary = new ImportSummary(enrollment.getEnrollment());
    ProgramInstance programInstance = programInstanceService.getProgramInstance(enrollment.getEnrollment());
    if (programInstance == null) {
        return new ImportSummary(ImportStatus.ERROR, "Enrollment ID was not valid.").incrementIgnored();
    }
    saveTrackedEntityComment(programInstance, enrollment);
    importSummary.setReference(enrollment.getEnrollment());
    importSummary.getImportCount().incrementUpdated();
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Example 45 with ImportSummary

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

the class SynchronizationController method execute.

@PreAuthorize("hasRole('ALL') or hasRole('F_EXPORT_DATA')")
@RequestMapping(value = "/dataPush", method = RequestMethod.POST)
public void execute(HttpServletResponse response) throws IOException {
    ImportSummary summary = synchronizationManager.executeDataPush();
    response.setContentType(CONTENT_TYPE_JSON);
    renderService.toJson(response.getOutputStream(), summary);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)102 Test (org.junit.Test)58 DhisSpringTest (org.hisp.dhis.DhisSpringTest)49 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 DataValue (org.hisp.dhis.datavalue.DataValue)18 Event (org.hisp.dhis.dxf2.events.event.Event)17 InputStream (java.io.InputStream)14 Date (java.util.Date)11 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)11 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 IOException (java.io.IOException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 DhisTest (org.hisp.dhis.DhisTest)9 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7