use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EventController method putXmlEvent.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putXmlEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, 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 updatedEvent = renderService.fromXml(inputStream, Event.class);
updatedEvent.setEvent(uid);
ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EventController method putJsonEvent.
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, 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 updatedEvent = renderService.fromJson(inputStream, Event.class);
updatedEvent.setEvent(uid);
ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void postEnrollmentJson(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
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 (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", getResourcePath(request, importSummary));
}
}
response.setStatus(HttpServletResponse.SC_CREATED);
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class AdxController method postXMLDataValueSet.
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postXMLDataValueSet(ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model) throws IOException {
ImportSummary importSummary = adxService.saveDataValueSet(in, importOptions, null);
importSummary.setImportOptions(importOptions);
log.debug("Data values set saved");
response.setContentType(CONTENT_TYPE_XML);
DefaultRenderService.getXmlMapper().writeValue(response.getOutputStream(), importSummary);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithStrictAttributeOptionCombos.
@Test
public void testImportDataValuesWithStrictAttributeOptionCombos() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
ImportOptions options = new ImportOptions().setStrictAttributeOptionCombos(true);
ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
assertEquals(summary.getConflicts().toString(), 1, summary.getConflicts().size());
assertEquals(2, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(1, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.WARNING, summary.getStatus());
}
Aggregations