use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary 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.webmessage.WebMessageUtils.importSummary 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.webmessage.WebMessageUtils.importSummary in project dhis2-core by dhis2.
the class EventController method putJsonEventSingleValue.
@RequestMapping(value = "/{uid}/{dataElementUid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEventSingleValue(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, @PathVariable("dataElementUid") String dataElementUid) throws IOException, WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
DataElement dataElement = dataElementService.getDataElement(dataElementUid);
if (dataElement == null) {
throw new WebMessageException(WebMessageUtils.notFound("DataElement not found for ID " + dataElementUid));
}
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Event updatedEvent = renderService.fromJson(inputStream, Event.class);
updatedEvent.setEvent(uid);
ImportSummary importSummary = eventService.updateEvent(updatedEvent, true);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary in project dhis2-core by dhis2.
the class EventController method deleteEvent.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_DELETE')")
public void deleteEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid) throws WebMessageException {
if (!programStageInstanceService.programStageInstanceExists(uid)) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
response.setStatus(HttpServletResponse.SC_OK);
try {
ImportSummary importSummary = eventService.deleteEvent(uid);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
} catch (Exception ex) {
webMessageService.send(WebMessageUtils.conflict("Unable to delete event " + uid, ex.getMessage()), response, request);
}
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method updateTrackedEntityInstanceJson.
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_ADD')")
public void updateTrackedEntityInstanceJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceJson(id, inputStream, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Aggregations