Search in sources :

Example 1 with ArticleOverview

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);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Example 2 with ArticleOverview

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));
    });
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Example 3 with 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);
}
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)

Aggregations

ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)3 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)2 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)2 ResolvedDoiView (org.ambraproject.rhino.view.ResolvedDoiView)2 Query (org.hibernate.Query)2 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 ArticleItem (org.ambraproject.rhino.model.ArticleItem)1 Comment (org.ambraproject.rhino.model.Comment)1 Issue (org.ambraproject.rhino.model.Issue)1 Journal (org.ambraproject.rhino.model.Journal)1 Volume (org.ambraproject.rhino.model.Volume)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1