use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class ReportController method getReportDesign.
@RequestMapping(value = "/{uid}/design", method = RequestMethod.GET)
public void getReportDesign(@PathVariable("uid") String uid, HttpServletResponse response) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
if (report.getDesignContent() == null) {
throw new WebMessageException(WebMessageUtils.conflict("Report has no design content: " + uid));
}
if (report.isTypeHtml()) {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".html", true);
} else {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".jrxml", true);
}
response.getWriter().write(report.getDesignContent());
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class EventController method getEvent.
@RequestMapping(value = "/{uid}", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Event getEvent(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request) throws Exception {
Event event = eventService.getEvent(uid);
if (event == null) {
throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
}
event.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + uid);
return event;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class EventController method putJsonEventForEventDate.
@RequestMapping(value = "/{uid}/eventDate", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEventForEventDate(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);
eventService.updateEventForEventDate(updatedEvent);
webMessageService.send(WebMessageUtils.ok("Event updated " + uid), response, request);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class EventController method getCsvEvents.
@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/csv", "application/csv+gzip", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
public void getCsvEvents(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false, defaultValue = "false") boolean skipHeader, IdSchemes idSchemes, HttpServletResponse response, HttpServletRequest request) throws IOException, WebMessageException {
boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, null, null, null, includeDeleted);
Events events = eventService.getEvents(params);
OutputStream outputStream = response.getOutputStream();
response.setContentType("application/csv");
if (ContextUtils.isAcceptCsvGzip(request)) {
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
outputStream = new GZIPOutputStream(outputStream);
response.setContentType("application/csv+gzip");
}
if (!StringUtils.isEmpty(attachment)) {
response.addHeader("Content-Disposition", "attachment; filename=" + attachment);
}
csvEventService.writeEvents(outputStream, events, !skipHeader);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class UserKeyJsonValueController method updateUserKeyJsonValue.
/**
* Update a key.
*/
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.PUT, produces = "application/json", consumes = "application/json")
public void updateUserKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String body, HttpServletResponse response) throws WebMessageException, IOException {
UserKeyJsonValue userKeyJsonValue = userKeyJsonValueService.getUserKeyJsonValue(currentUserService.getCurrentUser(), namespace, key);
if (userKeyJsonValue == null) {
throw new WebMessageException(WebMessageUtils.notFound("The key '" + key + "' was not found in the namespace '" + namespace + "'."));
}
if (!renderService.isValidJson(body)) {
throw new WebMessageException(WebMessageUtils.badRequest("The data is not valid JSON."));
}
userKeyJsonValue.setValue(body);
userKeyJsonValueService.updateUserKeyJsonValue(userKeyJsonValue);
response.setStatus(HttpServletResponse.SC_OK);
messageService.sendJson(WebMessageUtils.created("Key '" + key + "' in namespace '" + namespace + "' updated."), response);
}
Aggregations