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