use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class DataSetController method getFormXml.
@RequestMapping(value = "/{uid}/form", method = RequestMethod.GET, produces = { "application/xml", "text/xml" })
public void getFormXml(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "catOpts", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
OrganisationUnit ou = manager.get(OrganisationUnit.class, orgUnit);
if (ou == null) {
throw new WebMessageException(WebMessageUtils.notFound("Organisation unit does not exist: " + orgUnit));
}
Period pe = PeriodType.getPeriodFromIsoString(period);
Form form = getForm(dataSets, ou, pe, categoryOptions, metaData);
renderService.toXml(response.getOutputStream(), form);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class DataSetController method getFormJson.
@RequestMapping(value = "/{uid}/form", method = RequestMethod.GET, produces = "application/json")
public void getFormJson(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "categoryOptions", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
OrganisationUnit ou = manager.get(OrganisationUnit.class, orgUnit);
if (ou == null) {
throw new WebMessageException(WebMessageUtils.notFound("Organisation unit does not exist: " + orgUnit));
}
Period pe = PeriodType.getPeriodFromIsoString(period);
Form form = getForm(dataSets, ou, pe, categoryOptions, metaData);
renderService.toJson(response.getOutputStream(), form);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class InterpretationController method writeChartInterpretation.
@RequestMapping(value = "/chart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeChartInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
Chart chart = idObjectManager.get(Chart.class, uid);
if (chart == null) {
throw new WebMessageException(WebMessageUtils.conflict("Chart does not exist or is not accessible: " + uid));
}
OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, chart, currentUserService.getCurrentUser());
createIntepretation(new Interpretation(chart, orgUnit, text), request, response);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class InterpretationController method updateInterpretation.
// -------------------------------------------------------------------------
// Interpretation update
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateInterpretation(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.notFound("Interpretation does not exist: " + uid));
}
if (!currentUserService.getCurrentUser().equals(interpretation.getUser()) && !currentUserService.currentUserIsSuper()) {
throw new AccessDeniedException("You are not allowed to update this interpretation.");
}
interpretation.setText(text);
interpretationService.updateInterpretation(interpretation);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.
the class InterpretationController method like.
// -------------------------------------------------------------------------
// Likes
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/like", method = RequestMethod.POST)
public void like(@PathVariable("uid") String uid, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
}
boolean like = interpretationService.likeInterpretation(interpretation.getId());
if (like) {
webMessageService.send(WebMessageUtils.created("Like added to interpretation"), response, request);
} else {
webMessageService.send(WebMessageUtils.conflict("Could not add like, user had already liked interpretation"), response, request);
}
}
Aggregations