Search in sources :

Example 6 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 7 with 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);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) Journal(org.ambraproject.rhino.model.Journal)

Example 8 with Comment

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);
}
Also used : CompetingInterestPolicy(org.ambraproject.rhino.view.comment.CompetingInterestPolicy) Flag(org.ambraproject.rhino.model.Flag) ServiceResponse(org.ambraproject.rhino.rest.response.ServiceResponse) CommentCrudService(org.ambraproject.rhino.service.CommentCrudService) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) CommentFlagInputView(org.ambraproject.rhino.view.comment.CommentFlagInputView) JournalCrudService(org.ambraproject.rhino.service.JournalCrudService) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) Strings(com.google.common.base.Strings) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) CommentNodeView(org.ambraproject.rhino.view.comment.CommentNodeView) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) CommentFlagOutputView(org.ambraproject.rhino.view.comment.CommentFlagOutputView) CommentOutputView(org.ambraproject.rhino.view.comment.CommentOutputView) Query(org.hibernate.Query) Doi(org.ambraproject.rhino.identity.Doi) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) CommentCountView(org.ambraproject.rhino.view.comment.CommentCountView) Collection(java.util.Collection) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) FlagReasonCode(org.ambraproject.rhino.model.FlagReasonCode) Pattern(java.util.regex.Pattern) Comment(org.ambraproject.rhino.model.Comment) 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)

Example 9 with Comment

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);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) Query(org.hibernate.Query) CommentNodeView(org.ambraproject.rhino.view.comment.CommentNodeView)

Example 10 with Comment

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

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