use of org.ambraproject.rhino.view.article.ArticleOverview in project rhino by PLOS.
the class ArticleCrudServiceImpl method serveOverview.
@Override
public ServiceResponse<ArticleOverview> serveOverview(ArticleIdentifier id) {
ArticleOverview view = hibernateTemplate.execute(session -> {
Query ingestionQuery = session.createQuery("FROM ArticleIngestion WHERE article.doi = :doi");
ingestionQuery.setParameter("doi", id.getDoiName());
List<ArticleIngestion> ingestions = ingestionQuery.list();
Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + " (FROM ArticleIngestion WHERE article.doi = :doi)");
revisionQuery.setParameter("doi", id.getDoiName());
List<ArticleRevision> revisions = revisionQuery.list();
return ArticleOverview.build(id, ingestions, revisions);
});
return ServiceResponse.serveView(view);
}
use of org.ambraproject.rhino.view.article.ArticleOverview in project rhino by PLOS.
the class ArticleCrudServiceImpl method getItemOverview.
@Override
public Optional<ResolvedDoiView> getItemOverview(Doi doi) {
return hibernateTemplate.execute(session -> {
Query ingestionQuery = session.createQuery("FROM ArticleItem WHERE doi = :doi");
ingestionQuery.setParameter("doi", doi.getName());
List<ArticleItem> items = ingestionQuery.list();
if (items.isEmpty())
return Optional.empty();
ResolvedDoiView.DoiWorkType type = items.stream().allMatch(ArticleCrudServiceImpl::isMainArticleItem) ? ResolvedDoiView.DoiWorkType.ARTICLE : ResolvedDoiView.DoiWorkType.ASSET;
ArticleIdentifier articleId = Iterables.getOnlyElement(items.stream().map(item -> ArticleIdentifier.create(item.getIngestion().getArticle().getDoi())).collect(Collectors.toSet()));
Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + " (SELECT ingestion FROM ArticleItem WHERE doi = :doi)");
revisionQuery.setParameter("doi", doi.getName());
List<ArticleRevision> revisions = revisionQuery.list();
Collection<ArticleIngestion> ingestions = Collections2.transform(items, ArticleItem::getIngestion);
ArticleOverview articleOverview = ArticleOverview.build(articleId, ingestions, revisions);
return Optional.of(ResolvedDoiView.createForArticle(doi, type, articleOverview));
});
}
use of org.ambraproject.rhino.view.article.ArticleOverview 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);
}
Aggregations