Search in sources :

Example 76 with ImportSummary

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

the class DefaultDataValueSetService method saveDataValueSet.

@Override
public ImportSummary saveDataValueSet(InputStream in, ImportOptions importOptions, TaskId id) {
    try {
        in = StreamUtils.wrapAndCheckCompressionFormat(in);
        DataValueSet dataValueSet = new StreamingXmlDataValueSet(XMLFactory.getXMLReader(in));
        return saveDataValueSet(importOptions, id, dataValueSet);
    } catch (Exception ex) {
        log.error(DebugUtils.getStackTrace(ex));
        notifier.notify(id, ERROR, "Process failed: " + ex.getMessage(), true);
        return new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage());
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 77 with ImportSummary

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

the class DefaultDataValueSetService method handleComplete.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void handleComplete(DataSet dataSet, Date completeDate, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, ImportSummary summary) {
    if (orgUnit == null) {
        summary.getConflicts().add(new ImportConflict(OrganisationUnit.class.getSimpleName(), ERROR_OBJECT_NEEDED_TO_COMPLETE));
        return;
    }
    if (period == null) {
        summary.getConflicts().add(new ImportConflict(Period.class.getSimpleName(), ERROR_OBJECT_NEEDED_TO_COMPLETE));
        return;
    }
    period = periodService.reloadPeriod(period);
    CompleteDataSetRegistration completeAlready = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
    String username = currentUserService.getCurrentUsername();
    if (completeAlready != null) {
        completeAlready.setStoredBy(username);
        completeAlready.setDate(completeDate);
        registrationService.updateCompleteDataSetRegistration(completeAlready);
    } else {
        CompleteDataSetRegistration registration = new CompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo, completeDate, username);
        registrationService.saveCompleteDataSetRegistration(registration);
    }
    summary.setDataSetComplete(DateUtils.getMediumDateString(completeDate));
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 78 with ImportSummary

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

the class DefaultCompleteDataSetRegistrationExchangeService method saveCompleteDataSetRegistrationsJson.

@Override
public ImportSummary saveCompleteDataSetRegistrationsJson(InputStream in, ImportOptions importOptions, TaskId taskId) {
    try {
        in = StreamUtils.wrapAndCheckCompressionFormat(in);
        CompleteDataSetRegistrations completeDataSetRegistrations = DefaultRenderService.getJsonMapper().readValue(in, CompleteDataSetRegistrations.class);
        return saveCompleteDataSetRegistrations(importOptions, taskId, completeDataSetRegistrations);
    } catch (Exception ex) {
        return handleImportError(taskId, ex);
    }
}
Also used : StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 79 with ImportSummary

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

the class DefaultCompleteDataSetRegistrationExchangeService method saveCompleteDataSetRegistrationsXml.

@Override
public ImportSummary saveCompleteDataSetRegistrationsXml(InputStream in, ImportOptions importOptions, TaskId taskId) {
    try {
        in = StreamUtils.wrapAndCheckCompressionFormat(in);
        CompleteDataSetRegistrations completeDataSetRegistrations = new StreamingXmlCompleteDataSetRegistrations(XMLFactory.getXMLReader(in));
        return saveCompleteDataSetRegistrations(importOptions, taskId, completeDataSetRegistrations);
    } catch (Exception ex) {
        return handleImportError(taskId, ex);
    }
}
Also used : StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations) StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 80 with ImportSummary

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

the class DefaultCompleteDataSetRegistrationExchangeService method finalizeSummary.

private static void finalizeSummary(ImportSummary summary, int totalCount, int importCount, int updateCount, int deleteCount) {
    int ignores = totalCount - importCount - updateCount - deleteCount;
    summary.setImportCount(new ImportCount(importCount, updateCount, ignores, deleteCount));
    summary.setStatus(ImportStatus.SUCCESS);
    summary.setDescription("Import process completed successfully");
}
Also used : ImportCount(org.hisp.dhis.dxf2.importsummary.ImportCount)

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