use of org.hisp.dhis.dxf2.common.ImportOptions 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);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions 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);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class DefaultAdxDataService method parseAdxGroupToDxf.
// -------------------------------------------------------------------------
// Utility methods
// -------------------------------------------------------------------------
private List<ImportConflict> parseAdxGroupToDxf(XMLReader adxReader, XMLStreamWriter dxfWriter, ImportOptions importOptions, CachingMap<String, DataSet> dataSetMap, IdentifiableObjectCallable<DataSet> dataSetCallable, CachingMap<String, DataElement> dataElementMap, IdentifiableObjectCallable<DataElement> dataElementCallable) throws XMLStreamException, AdxException {
List<ImportConflict> adxConflicts = new LinkedList<>();
IdentifiableProperty dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme().getIdentifiableProperty();
Map<String, String> groupAttributes = adxReader.readAttributes();
if (!groupAttributes.containsKey(AdxDataService.PERIOD)) {
throw new AdxException(AdxDataService.PERIOD + " attribute is required on 'group'");
}
if (!groupAttributes.containsKey(AdxDataService.ORGUNIT)) {
throw new AdxException(AdxDataService.ORGUNIT + " attribute is required on 'group'");
}
// translate ADX period to DXF
String periodStr = groupAttributes.get(AdxDataService.PERIOD);
groupAttributes.remove(AdxDataService.PERIOD);
Period period = AdxPeriod.parse(periodStr);
groupAttributes.put(AdxDataService.PERIOD, period.getIsoDate());
// process ADX group attributes
if (!groupAttributes.containsKey(AdxDataService.ATTOPTCOMBO) && groupAttributes.containsKey(AdxDataService.DATASET)) {
log.debug("No attribute option combo present, check data set for attribute category combo");
String dataSetStr = trimToNull(groupAttributes.get(AdxDataService.DATASET));
final DataSet dataSet = dataSetMap.get(dataSetStr, dataSetCallable.setId(dataSetStr));
if (dataSet == null) {
throw new AdxException("No data set matching identifier: " + groupAttributes.get(AdxDataService.DATASET));
}
groupAttributes.put(AdxDataService.DATASET, dataSet.getUid());
DataElementCategoryCombo attributeCombo = dataSet.getCategoryCombo();
convertAttributesToDxf(groupAttributes, AdxDataService.ATTOPTCOMBO, attributeCombo, dataElementIdScheme);
}
// process the dataValues
while (adxReader.moveToStartElement(AdxDataService.DATAVALUE, AdxDataService.GROUP)) {
try {
parseADXDataValueToDxf(adxReader, dxfWriter, groupAttributes, importOptions, dataElementMap, dataElementCallable);
} catch (AdxException ex) {
adxConflicts.add(ex.getImportConflict());
log.info("ADX data value conflict: " + ex.getImportConflict());
}
}
return adxConflicts;
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EventController method postXmlEvent.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postXmlEvent(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws Exception {
importOptions.setImportStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
importOptions.setIdSchemes(getIdSchemesFromParameters(importOptions.getIdSchemes(), contextService.getParameterValuesMap()));
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventService.addEventsXml(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importOptions.isDryRun()) {
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference());
}
}
}
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
} else {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
List<Event> events = eventService.getEventsXml(inputStream);
scheduler.executeTask(new ImportEventTask(events, eventService, importOptions, taskId));
response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.EVENT_IMPORT);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EventController method postJsonEventForNote.
@RequestMapping(value = "/{uid}/note", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postJsonEventForNote(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException, WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Event event = renderService.fromJson(inputStream, Event.class);
event.setEvent(uid);
eventService.updateEventForNote(event);
webMessageService.send(WebMessageUtils.ok("Event updated: " + uid), response, request);
}
Aggregations