Search in sources :

Example 16 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class CommentCrudController method readFlagsOnComment.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags", method = RequestMethod.GET)
public void readFlagsOnComment(HttpServletRequest request, HttpServletResponse response, @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
    commentCrudService.readCommentFlagsOn(commentId).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleListCrudServiceImpl method fetchArticles.

/**
   * Fetch all articles with the given IDs, in the same iteration error.
   *
   * @param articleIds a set of article IDs
   * @return the articles in the same order, if all exist
   * @throws RestClientException if not every article ID belongs to an existing article
   */
private List<Article> fetchArticles(Set<ArticleIdentifier> articleIds) {
    if (articleIds.isEmpty())
        return ImmutableList.of();
    final Map<String, Integer> articleKeys = new HashMap<>();
    int i = 0;
    for (ArticleIdentifier articleId : articleIds) {
        articleKeys.put(articleId.getDoiName(), i++);
    }
    List<Article> articles = (List<Article>) hibernateTemplate.findByNamedParam("from Article where doi in :articleKeys", "articleKeys", articleKeys.keySet());
    if (articles.size() < articleKeys.size()) {
        throw new RestClientException(buildMissingArticleMessage(articles, articleKeys.keySet()), HttpStatus.NOT_FOUND);
    }
    Collections.sort(articles, (a1, a2) -> {
        // We expect the error check above to guarantee that both values will be found in the map
        int i1 = articleKeys.get(a1.getDoi());
        int i2 = articleKeys.get(a2.getDoi());
        return i1 - i2;
    });
    return articles;
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) HashMap(java.util.HashMap) Article(org.ambraproject.rhino.model.Article) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ArticleList(org.ambraproject.rhino.model.ArticleList) List(java.util.List)

Example 18 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class ArticleCrudServiceImpl method buildOverview.

@Override
public ArticleOverview buildOverview(Article article) {
    return hibernateTemplate.execute(session -> {
        Query ingestionQuery = session.createQuery("FROM ArticleIngestion WHERE article = :article");
        ingestionQuery.setParameter("article", article);
        List<ArticleIngestion> ingestions = ingestionQuery.list();
        Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + "  (FROM ArticleIngestion WHERE article = :article)");
        revisionQuery.setParameter("article", article);
        List<ArticleRevision> revisions = revisionQuery.list();
        ArticleIdentifier id = ArticleIdentifier.create(article.getDoi());
        return ArticleOverview.build(id, ingestions, revisions);
    });
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Query(org.hibernate.Query)

Example 19 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier 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 20 with ArticleIdentifier

use of org.ambraproject.rhino.identity.ArticleIdentifier in project rhino by PLOS.

the class CommentCrudController method removeFlag.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags/{flagId}", method = RequestMethod.DELETE)
public ResponseEntity<Object> removeFlag(@PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi, @PathVariable("flagId") long flagId) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId and commentId
    commentCrudService.deleteCommentFlag(flagId);
    return reportDeleted(Long.toString(flagId));
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)9 Article (org.ambraproject.rhino.model.Article)7 RestClientException (org.ambraproject.rhino.rest.RestClientException)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)4 Query (org.hibernate.Query)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2