Search in sources :

Example 1 with InterpretationComment

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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with InterpretationComment

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;
}
Also used : User(org.hisp.dhis.user.User) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) Date(java.util.Date)

Example 3 with InterpretationComment

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;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with InterpretationComment

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);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with InterpretationComment

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());
}
Also used : InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Interpretation (org.hisp.dhis.interpretation.Interpretation)6 InterpretationComment (org.hisp.dhis.interpretation.InterpretationComment)6 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Date (java.util.Date)1 User (org.hisp.dhis.user.User)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1