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());
}
}
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());
}
}
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()));
}
}
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()));
}
}
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;
}
Aggregations