use of org.ambraproject.rhino.model.Flag in project rhino by PLOS.
the class CommentCrudServiceImpl method createCommentFlag.
@Override
public Flag createCommentFlag(CommentIdentifier commentId, CommentFlagInputView input) {
Comment comment = readComment(commentId);
Long flagCreator = Long.valueOf(input.getCreatorUserId());
Flag flag = new Flag();
flag.setFlaggedComment(comment);
flag.setUserProfileId(flagCreator);
flag.setComment(input.getBody());
flag.setReason(FlagReasonCode.fromString(input.getReasonCode()));
hibernateTemplate.save(flag);
return flag;
}
use of org.ambraproject.rhino.model.Flag in project rhino by PLOS.
the class CommentCrudServiceImpl method getFlag.
private Flag getFlag(Long commentFlagId) {
Flag flag = hibernateTemplate.execute(session -> {
Query query = session.createQuery("FROM Flag WHERE commentFlagId = :commentFlagId");
query.setParameter("commentFlagId", commentFlagId);
return (Flag) query.uniqueResult();
});
if (flag == null) {
String message = "Comment flag not found at the provided ID: " + commentFlagId;
throw new RestClientException(message, HttpStatus.NOT_FOUND);
}
return flag;
}
use of org.ambraproject.rhino.model.Flag in project rhino by PLOS.
the class CommentCrudServiceImpl method deleteCommentFlag.
@Override
public Long deleteCommentFlag(Long flagId) {
Flag flag = getFlag(flagId);
hibernateTemplate.delete(flag);
return flagId;
}
use of org.ambraproject.rhino.model.Flag in project rhino by PLOS.
the class CommentCrudServiceImpl method removeFlagsFromComment.
@Override
public String removeFlagsFromComment(CommentIdentifier commentId) {
Comment comment = readComment(commentId);
Collection<Flag> flags = getCommentFlagsOn(comment);
hibernateTemplate.deleteAll(flags);
return commentId.getDoiName();
}
use of org.ambraproject.rhino.model.Flag in project rhino by PLOS.
the class CommentCrudController method createFlag.
@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentFlagInputView", value = "example: {\"creatorUserId\": 10365, \"body\": \"oops\", \"reasonCode\": \"spam\"}")
public ResponseEntity<?> createFlag(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
// TODO: Validate articleId
CommentFlagInputView input = readJsonFromRequest(request, CommentFlagInputView.class);
Flag commentFlag = commentCrudService.createCommentFlag(commentId, input);
return ServiceResponse.reportCreated(commentNodeViewFactory.createFlagView(commentFlag)).asJsonResponse(entityGson);
}
Aggregations