Search in sources :

Example 1 with Flag

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;
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Flag(org.ambraproject.rhino.model.Flag)

Example 2 with 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;
}
Also used : Query(org.hibernate.Query) RestClientException(org.ambraproject.rhino.rest.RestClientException) Flag(org.ambraproject.rhino.model.Flag)

Example 3 with 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;
}
Also used : Flag(org.ambraproject.rhino.model.Flag)

Example 4 with Flag

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();
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Flag(org.ambraproject.rhino.model.Flag)

Example 5 with Flag

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);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) Flag(org.ambraproject.rhino.model.Flag) CommentFlagInputView(org.ambraproject.rhino.view.comment.CommentFlagInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Flag (org.ambraproject.rhino.model.Flag)5 Comment (org.ambraproject.rhino.model.Comment)2 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)1 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 CommentFlagInputView (org.ambraproject.rhino.view.comment.CommentFlagInputView)1 Query (org.hibernate.Query)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1