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 DoiController method findDoiTarget.
private ResolvedDoiView findDoiTarget(Doi doi) throws IOException {
// Look for the DOI in the corpus of articles
Optional<ResolvedDoiView> itemOverview = articleCrudService.getItemOverview(doi);
if (itemOverview.isPresent()) {
return itemOverview.get();
}
// Not found as an Article or ArticleItem. Check other object types that use DOIs.
Optional<Comment> comment = commentCrudService.getComment(CommentIdentifier.create(doi));
if (comment.isPresent()) {
ArticleOverview article = articleCrudService.buildOverview(comment.get().getArticle());
return ResolvedDoiView.createForArticle(doi, ResolvedDoiView.DoiWorkType.COMMENT, article);
}
Optional<Issue> issue = issueCrudService.getIssue(IssueIdentifier.create(doi));
if (issue.isPresent()) {
Journal journal = issueCrudService.getJournalOf(issue.get());
return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.ISSUE, journal);
}
Optional<Volume> volume = volumeCrudService.getVolume(VolumeIdentifier.create(doi));
if (volume.isPresent()) {
Journal journal = volumeCrudService.getJournalOf(volume.get());
return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.VOLUME, journal);
}
throw new RestClientException("DOI not found: " + doi.getName(), HttpStatus.NOT_FOUND);
}
use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.
the class CommentCrudServiceImpl method serveComments.
@Override
public ServiceResponse<List<CommentOutputView>> serveComments(ArticleIdentifier articleId) throws IOException {
Article article = articleCrudService.readArticle(articleId);
Collection<Comment> comments = fetchAllComments(article);
CommentOutputView.Factory factory = new CommentOutputView.Factory(new CompetingInterestPolicy(runtimeConfiguration), comments, article);
List<CommentOutputView> views = comments.stream().filter(comment -> comment.getParent() == null).sorted(CommentOutputView.BY_DATE).map(factory::buildView).collect(Collectors.toList());
return ServiceResponse.serveView(views);
}
use of org.ambraproject.rhino.model.Comment in project rhino by PLOS.
the class CommentCrudServiceImpl method getCommentsCreatedOn.
@Override
public ServiceResponse<Collection<CommentNodeView>> getCommentsCreatedOn(LocalDate date) {
Collection<CommentNodeView> views = hibernateTemplate.execute(session -> {
Query query = session.createQuery("FROM Comment WHERE DATE(created) = :date");
query.setParameter("date", java.sql.Date.valueOf(date));
Collection<Comment> comments = query.list();
return comments.stream().map(commentNodeViewFactory::create).collect(Collectors.toList());
});
return ServiceResponse.serveView(views);
}
use of org.ambraproject.rhino.model.Comment 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();
}
Aggregations