Search in sources :

Example 1 with ArticleCommentFlag

use of org.ambraproject.wombat.model.ArticleCommentFlag in project wombat by PLOS.

the class ArticleController method receiveCommentFlag.

@RequestMapping(name = "postCommentFlag", method = RequestMethod.POST, value = "/article/comments/flag")
@ResponseBody
public Object receiveCommentFlag(HttpServletRequest request, @RequestParam("reasonCode") String reasonCode, @RequestParam("comment") String flagCommentBody, @RequestParam("target") String targetCommentDoi) throws IOException {
    checkCommentsAreEnabled();
    Map<String, Object> validationErrors = commentValidationService.validateFlag(flagCommentBody);
    if (!validationErrors.isEmpty()) {
        return ImmutableMap.of("validationErrors", validationErrors);
    }
    String authId = request.getRemoteUser();
    final String creatorUserId = authId == null ? null : userApi.getUserIdFromAuthId(authId);
    ArticleCommentFlag flag = new ArticleCommentFlag(creatorUserId, flagCommentBody, reasonCode);
    Map<String, Object> comment = getComment(targetCommentDoi);
    String parentArticleDoi = getParentArticleDoiFromComment(comment);
    ApiAddress address = ApiAddress.builder("articles").embedDoi(parentArticleDoi).addToken("comments").embedDoi(targetCommentDoi).addToken("flags").build();
    articleApi.postObject(address, flag);
    // the "201 CREATED" status is all the AJAX client needs
    return ImmutableMap.of();
}
Also used : ArticleCommentFlag(org.ambraproject.wombat.model.ArticleCommentFlag) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ArticleCommentFlag (org.ambraproject.wombat.model.ArticleCommentFlag)1 ApiAddress (org.ambraproject.wombat.service.remote.ApiAddress)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1