Search in sources :

Example 1 with Comment

use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.

the class CommentCrudServiceImpl method patchComment.

@Override
public ServiceResponse<CommentOutputView> patchComment(CommentIdentifier commentId, CommentInputView input) {
    Comment comment = readComment(commentId);
    String declaredUri = input.getAnnotationUri();
    if (declaredUri != null && !CommentIdentifier.create(declaredUri).equals(commentId)) {
        throw new RestClientException("Mismatched commentUri in body", HttpStatus.BAD_REQUEST);
    }
    String creatorUserId = input.getCreatorUserId();
    if (creatorUserId != null) {
        comment.setUserProfileID(Long.valueOf(creatorUserId));
    }
    String title = input.getTitle();
    if (title != null) {
        comment.setTitle(title);
    }
    String body = input.getBody();
    if (body != null) {
        comment.setBody(body);
    }
    String highlightedText = input.getHighlightedText();
    if (highlightedText != null) {
        comment.setHighlightedText(highlightedText);
    }
    String competingInterestStatement = input.getCompetingInterestStatement();
    if (competingInterestStatement != null) {
        comment.setCompetingInterestBody(competingInterestStatement);
    }
    String isRemoved = input.getIsRemoved();
    if (isRemoved != null) {
        comment.setIsRemoved(Boolean.valueOf(isRemoved));
    }
    hibernateTemplate.update(comment);
    return ServiceResponse.serveView(createView(comment));
}
Also used : Comment(org.ambraproject.rhino.model.Comment) RestClientException(org.ambraproject.rhino.rest.RestClientException)

Example 2 with Comment

use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.

the class CommentOutputViewTest method createStubComment.

private Comment createStubComment() {
    Comment comment = new Comment();
    Article article = new Article();
    article.setDoi("test");
    comment.setArticle(article);
    comment.setBody("test body");
    comment.setCommentId(0L);
    comment.setCreated(Date.from(Instant.now()));
    return comment;
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Article(org.ambraproject.rhino.model.Article)

Example 3 with Comment

use of org.ambraproject.rhino.model.Comment 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 4 with Comment

use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.

the class CommentCrudServiceImpl method deleteComment.

@Override
public String deleteComment(CommentIdentifier commentId) {
    Comment comment = readComment(commentId);
    hibernateTemplate.delete(comment);
    return commentId.getDoiName();
}
Also used : Comment(org.ambraproject.rhino.model.Comment)

Example 5 with Comment

use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.

the class CommentCrudServiceImpl method createView.

private CommentOutputView createView(Comment comment) {
    Article article = comment.getArticle();
    Collection<Comment> articleComments = fetchAllComments(article);
    return new CommentOutputView.Factory(new CompetingInterestPolicy(runtimeConfiguration), articleComments, article).buildView(comment);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Article(org.ambraproject.rhino.model.Article) CommentOutputView(org.ambraproject.rhino.view.comment.CommentOutputView) CompetingInterestPolicy(org.ambraproject.rhino.view.comment.CompetingInterestPolicy)

Aggregations

Comment (org.ambraproject.rhino.model.Comment)11 Article (org.ambraproject.rhino.model.Article)4 RestClientException (org.ambraproject.rhino.rest.RestClientException)4 Flag (org.ambraproject.rhino.model.Flag)3 CommentOutputView (org.ambraproject.rhino.view.comment.CommentOutputView)3 CompetingInterestPolicy (org.ambraproject.rhino.view.comment.CompetingInterestPolicy)3 UUID (java.util.UUID)2 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)2 Doi (org.ambraproject.rhino.identity.Doi)2 Journal (org.ambraproject.rhino.model.Journal)2 CommentNodeView (org.ambraproject.rhino.view.comment.CommentNodeView)2 Query (org.hibernate.Query)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1