use of org.ambraproject.rhino.view.ResolvedDoiView 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.ResolvedDoiView in project rhino by PLOS.
the class DoiController method resolve.
@Transactional(readOnly = true)
@RequestMapping(value = "/dois/{doi:.+}", method = RequestMethod.GET)
public ResponseEntity<?> resolve(@PathVariable("doi") String escapedDoi) throws IOException {
Doi doi = DoiEscaping.unescape(escapedDoi);
ResolvedDoiView view = findDoiTarget(doi);
return ServiceResponse.serveView(view).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.view.ResolvedDoiView 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