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();
}
Aggregations