Search in sources :

Example 1 with UPDATE

use of org.hisp.dhis.importexport.ImportStrategy.UPDATE in project dhis2-core by dhis2.

the class EventManager method updateEvents.

public ImportSummaries updateEvents(final List<Event> events, final WorkContext workContext) {
    final ImportSummaries importSummaries = new ImportSummaries();
    // pre-process events
    executorsByPhase.get(EventProcessorPhase.UPDATE_PRE).execute(workContext, events);
    if (ImportStrategyUtils.isUpdate(workContext.getImportOptions().getImportStrategy())) {
        importSummaries.addImportSummaries(run(workContext, events, checkersRunOnUpdate));
    }
    // collect the UIDs of events that did not pass validation
    final List<String> eventValidationFailedUids = importSummaries.getImportSummaries().stream().filter(i -> i.isStatus(ERROR)).map(ImportSummary::getReference).collect(toList());
    if (eventValidationFailedUids.size() == events.size()) {
        return importSummaries;
    }
    if (!workContext.getImportOptions().isDryRun()) {
        try {
            eventPersistenceService.update(workContext, eventValidationFailedUids.isEmpty() ? events : events.stream().filter(e -> !eventValidationFailedUids.contains(e.getEvent())).collect(toList()));
        } catch (Exception e) {
            handleFailure(workContext, importSummaries, events, IMPORT_ERROR_STRING, UPDATE);
        }
        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.UPDATE_POST).execute(workContext, savedEvents);
        incrementSummaryTotals(events, importSummaries, UPDATE);
    }
    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

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 CollectionUtils.isNotEmpty (org.apache.commons.collections4.CollectionUtils.isNotEmpty)1 IdScheme (org.hisp.dhis.common.IdScheme)1 Event (org.hisp.dhis.dxf2.events.event.Event)1 EventPersistenceService (org.hisp.dhis.dxf2.events.event.persistence.EventPersistenceService)1 WorkContext (org.hisp.dhis.dxf2.events.importer.context.WorkContext)1 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)1 ERROR (org.hisp.dhis.dxf2.importsummary.ImportStatus.ERROR)1 SUCCESS (org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS)1