use of org.hisp.dhis.interpretation.Interpretation in project dhis2-core by dhis2.
the class PostInterpretation method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Chart c = chartService.getChart(id);
Interpretation i = new Interpretation(c, null, interpretation);
i.setUser(currentUserService.getCurrentUser());
interpretationService.saveInterpretation(i);
return SUCCESS;
}
use of org.hisp.dhis.interpretation.Interpretation 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.interpretation.Interpretation 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.interpretation.Interpretation 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);
}
}
use of org.hisp.dhis.interpretation.Interpretation in project dhis2-core by dhis2.
the class InterpretationController method updateComment.
@RequestMapping(value = "/{uid}/comments/{cuid}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, HttpServletResponse response, @RequestBody String content) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
}
for (InterpretationComment comment : interpretation.getComments()) {
if (comment.getUid().equals(cuid)) {
if (!currentUserService.getCurrentUser().equals(comment.getUser()) && !currentUserService.currentUserIsSuper()) {
throw new AccessDeniedException("You are not allowed to update this comment.");
}
comment.setText(content);
}
}
interpretationService.updateInterpretation(interpretation);
}
Aggregations