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