use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class DataValueSetController method postCsvDataValueSet.
@RequestMapping(method = RequestMethod.POST, consumes = "application/csv")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postCsvDataValueSet(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (importOptions.isAsync()) {
startAsyncImport(importOptions, ImportDataValueTask.FORMAT_CSV, request, response);
} else {
ImportSummary summary = dataValueSetService.saveDataValueSetCsv(request.getInputStream(), importOptions);
summary.setImportOptions(importOptions);
response.setContentType(CONTENT_TYPE_XML);
renderService.toXml(response.getOutputStream(), summary);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions 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);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method asyncImport.
private void asyncImport(ImportOptions importOptions, String format, HttpServletRequest request, HttpServletResponse response) throws IOException {
Pair<InputStream, Path> tmpFile = saveTmpFile(request.getInputStream());
TaskId taskId = new TaskId(TaskCategory.COMPLETE_DATA_SET_REGISTRATION_IMPORT, currentUserService.getCurrentUser());
scheduler.executeTask(new ImportCompleteDataSetRegistrationsTask(registrationExchangeService, sessionFactory, tmpFile.getLeft(), tmpFile.getRight(), importOptions, format, taskId));
response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.COMPLETE_DATA_SET_REGISTRATION_IMPORT);
response.setStatus(HttpServletResponse.SC_ACCEPTED);
}
use of org.hisp.dhis.dxf2.common.ImportOptions 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);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions 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;
}
Aggregations