use of org.hisp.dhis.interpretation.InterpretationComment in project dhis2-core by dhis2.
the class InterpretationController method postComment.
// -------------------------------------------------------------------------
// Comment
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/comments", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void postComment(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
}
InterpretationComment comment = interpretationService.addInterpretationComment(uid, text);
String builder = InterpretationSchemaDescriptor.API_ENDPOINT + "/" + uid + "/comments/" + comment.getUid();
response.addHeader("Location", builder);
webMessageService.send(WebMessageUtils.created("Commented created"), response, request);
}
use of org.hisp.dhis.interpretation.InterpretationComment in project dhis2-core by dhis2.
the class DefaultInterpretationService method addInterpretationComment.
@Override
public InterpretationComment addInterpretationComment(String uid, String text) {
Interpretation interpretation = getInterpretation(uid);
User user = currentUserService.getCurrentUser();
InterpretationComment comment = new InterpretationComment(text);
comment.setLastUpdated(new Date());
comment.setUid(CodeGenerator.generateUid());
if (user != null) {
comment.setUser(user);
}
interpretation.addComment(comment);
interpretationStore.update(interpretation);
return comment;
}
use of org.hisp.dhis.interpretation.InterpretationComment in project dhis2-core by dhis2.
the class InterpretationController method deleteComment.
@DeleteMapping("/{uid}/comments/{cuid}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage deleteComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, HttpServletResponse response) {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
return conflict("Interpretation does not exist: " + uid);
}
Iterator<InterpretationComment> iterator = interpretation.getComments().iterator();
while (iterator.hasNext()) {
InterpretationComment comment = iterator.next();
if (comment.getUid().equals(cuid)) {
if (!currentUserService.getCurrentUser().equals(comment.getCreatedBy()) && !currentUserService.currentUserIsSuper()) {
throw new AccessDeniedException("You are not allowed to delete this comment.");
}
iterator.remove();
}
}
interpretationService.updateInterpretation(interpretation);
return null;
}
use of org.hisp.dhis.interpretation.InterpretationComment 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);
}
use of org.hisp.dhis.interpretation.InterpretationComment in project dhis2-core by dhis2.
the class InterpretationController method postComment.
// -------------------------------------------------------------------------
// Comment
// -------------------------------------------------------------------------
@PostMapping(value = "/{uid}/comments", consumes = { "text/html", "text/plain" })
@ResponseBody
public WebMessage postComment(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response) {
Interpretation interpretation = interpretationService.getInterpretation(uid);
if (interpretation == null) {
return conflict("Interpretation does not exist: " + uid);
}
InterpretationComment comment = interpretationService.addInterpretationComment(uid, text);
return created("Commented created").setLocation(InterpretationSchemaDescriptor.API_ENDPOINT + "/" + uid + "/comments/" + comment.getUid());
}
Aggregations