Search in sources :

Example 31 with ERROR

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

the class DefaultDataValueSetService method saveDataValueSetJson.

@Override
public ImportSummary saveDataValueSetJson(InputStream in, ImportOptions importOptions, TaskId id) {
    try {
        in = StreamUtils.wrapAndCheckCompressionFormat(in);
        DataValueSet dataValueSet = DefaultRenderService.getJsonMapper().readValue(in, DataValueSet.class);
        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 32 with ERROR

use of org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR 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 33 with ERROR

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

the class AbstractEnrollmentService method addEnrollments.

@Override
public ImportSummaries addEnrollments(List<Enrollment> enrollments, ImportOptions importOptions, JobConfiguration jobId) {
    notifier.clear(jobId).notify(jobId, "Importing enrollments");
    importOptions = updateImportOptions(importOptions);
    try {
        ImportSummaries importSummaries = addEnrollments(enrollments, importOptions, true);
        if (jobId != null) {
            notifier.notify(jobId, NotificationLevel.INFO, "Import done", true).addJobSummary(jobId, importSummaries, ImportSummaries.class);
        }
        return importSummaries;
    } catch (RuntimeException ex) {
        log.error(DebugUtils.getStackTrace(ex));
        notifier.notify(jobId, ERROR, "Process failed: " + ex.getMessage(), true);
        return new ImportSummaries().addImportSummary(new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage()));
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Example 34 with ERROR

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

the class AbstractEventService method addEvents.

@Transactional
@Override
public ImportSummaries addEvents(final List<Event> events, ImportOptions importOptions, final JobConfiguration jobConfiguration) {
    notifier.clear(jobConfiguration).notify(jobConfiguration, "Importing events");
    importOptions = updateImportOptions(importOptions);
    try {
        final WorkContext workContext = workContextLoader.load(importOptions, events);
        final ImportSummaries importSummaries = eventManager.addEvents(events, workContext);
        if (jobConfiguration != null) {
            notifier.notify(jobConfiguration, NotificationLevel.INFO, "Import done", true).addJobSummary(jobConfiguration, importSummaries, ImportSummaries.class);
        }
        return importSummaries;
    } catch (RuntimeException ex) {
        log.error(DebugUtils.getStackTrace(ex));
        notifier.notify(jobConfiguration, ERROR, "Process failed: " + ex.getMessage(), true);
        return new ImportSummaries().addImportSummary(new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage()));
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with ERROR

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

the class EventManager method addEvents.

public ImportSummaries addEvents(final List<Event> events, final WorkContext workContext) {
    final ImportSummaries importSummaries = new ImportSummaries();
    if (CollectionUtils.isEmpty(events)) {
        return importSummaries;
    }
    // filter out events which are already in the database as well as
    // duplicates in the payload (if stage is not repeatable)
    List<Event> validEvents = resolveImportableEvents(events, importSummaries, workContext);
    if (validEvents.isEmpty()) {
        return importSummaries;
    }
    // pre-process events
    executorsByPhase.get(EventProcessorPhase.INSERT_PRE).execute(workContext, validEvents);
    if (ImportStrategyUtils.isInsert(workContext.getImportOptions().getImportStrategy())) {
        importSummaries.addImportSummaries(run(workContext, validEvents, checkersRunOnInsert));
    }
    // collect the UIDs of events that did not pass validation
    final List<String> invalidEvents = importSummaries.getImportSummaries().stream().filter(i -> i.isStatus(ERROR)).map(ImportSummary::getReference).collect(toList());
    if (invalidEvents.size() == events.size()) {
        return importSummaries;
    }
    if (!workContext.getImportOptions().isDryRun()) {
        // fetch persistable events //
        List<Event> eventsToInsert = invalidEvents.isEmpty() ? validEvents : validEvents.stream().filter(e -> !invalidEvents.contains(e.getEvent())).collect(toList());
        if (isNotEmpty(eventsToInsert)) {
            try {
                // save the entire batch in one transaction
                eventPersistenceService.save(workContext, eventsToInsert);
            } catch (Exception e) {
                handleFailure(workContext, importSummaries, events, IMPORT_ERROR_STRING, CREATE);
            }
        }
        final List<String> eventPersistenceFailedUids = importSummaries.getImportSummaries().stream().filter(i -> i.isStatus(ERROR)).map(ImportSummary::getReference).collect(toList());
        // Post processing only the events that passed validation and were
        // persisted
        // correctly.
        List<Event> savedEvents = events.stream().filter(e -> !eventPersistenceFailedUids.contains(e.getEvent())).collect(toList());
        executorsByPhase.get(EventProcessorPhase.INSERT_POST).execute(workContext, savedEvents);
        incrementSummaryTotals(events, importSummaries, CREATE);
    }
    return importSummaries;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) DELETE(org.hisp.dhis.importexport.ImportStrategy.DELETE) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Program(org.hisp.dhis.program.Program) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ERROR(org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR) ImmutableList(com.google.common.collect.ImmutableList) CREATE(org.hisp.dhis.importexport.ImportStrategy.CREATE) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) EventPersistenceService(org.hisp.dhis.dxf2.events.event.persistence.EventPersistenceService) WARNING(org.hisp.dhis.dxf2.importsummary.ImportStatus.WARNING) ImportSummary.error(org.hisp.dhis.dxf2.importsummary.ImportSummary.error) NonNull(lombok.NonNull) Set(java.util.Set) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStage(org.hisp.dhis.program.ProgramStage) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) UPDATE(org.hisp.dhis.importexport.ImportStrategy.UPDATE) SUCCESS(org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS) IdScheme(org.hisp.dhis.common.IdScheme) Event(org.hisp.dhis.dxf2.events.event.Event) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 Test (org.junit.jupiter.api.Test)25 User (org.hisp.dhis.user.User)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 IOException (java.io.IOException)15 Event (org.hisp.dhis.dxf2.events.event.Event)14 List (java.util.List)12 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ArrayList (java.util.ArrayList)6 FileResource (org.hisp.dhis.fileresource.FileResource)6 SchemaService (org.hisp.dhis.schema.SchemaService)6 UserService (org.hisp.dhis.user.UserService)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 InputStream (java.io.InputStream)4