Search in sources :

Example 11 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision 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 12 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.

the class ArticleCrudServiceImpl method populateCategories.

@Override
public void populateCategories(ArticleIdentifier articleId) throws IOException {
    Article article = readArticle(articleId);
    ArticleRevision revision = readLatestRevision(article);
    taxonomyService.populateCategories(revision);
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article)

Example 13 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.

the class ArticleRevisionWriteServiceImpl method writeRevision.

@Override
public ArticleRevision writeRevision(ArticleRevisionIdentifier revisionId, ArticleIngestionIdentifier ingestionId) {
    Preconditions.checkArgument(revisionId.getArticleIdentifier().equals(ingestionId.getArticleIdentifier()));
    ArticleIngestion ingestion = articleCrudService.readIngestion(ingestionId);
    Article article = ingestion.getArticle();
    Optional<ArticleRevision> previousLatest = articleCrudService.getLatestRevision(article);
    ArticleRevision newRevision = articleCrudService.getRevision(revisionId).orElseGet(() -> {
        ArticleRevision revision = new ArticleRevision();
        revision.setRevisionNumber(revisionId.getRevision());
        return revision;
    });
    newRevision.setIngestion(ingestion);
    hibernateTemplate.saveOrUpdate(newRevision);
    if (!previousLatest.isPresent() || previousLatest.get().getRevisionNumber() <= newRevision.getRevisionNumber()) {
        refreshForLatestRevision(newRevision);
    }
    return newRevision;
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article)

Example 14 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.

the class ArticleCrudServiceImpl method getRawCategoriesAndText.

/**
   * {@inheritDoc}
   *
   * @param articleId
   */
@Override
public String getRawCategoriesAndText(final ArticleIdentifier articleId) throws IOException {
    Article article = readArticle(articleId);
    ArticleRevision revision = readLatestRevision(article);
    Document manuscriptXml = getManuscriptXml(revision.getIngestion());
    List<String> rawTermsAndText = taxonomyService.getRawTerms(manuscriptXml, article, true);
    StringBuilder cleanedTermsAndText = new StringBuilder();
    cleanedTermsAndText.append("<pre>");
    // HTML-escape the text, which is in the first element of the result array
    cleanedTermsAndText.append(StringEscapeUtils.escapeHtml4(rawTermsAndText.get(0)));
    cleanedTermsAndText.append("\n");
    for (int i = 1; i < rawTermsAndText.size(); i++) {
        String term = rawTermsAndText.get(i).replaceAll("<TERM>", "").replaceAll("</TERM>", "");
        cleanedTermsAndText.append("\n");
        cleanedTermsAndText.append(term);
    }
    cleanedTermsAndText.append("</pre>");
    return cleanedTermsAndText.toString();
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article) Document(org.w3c.dom.Document)

Example 15 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision 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)

Aggregations

ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)20 Article (org.ambraproject.rhino.model.Article)9 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)9 Query (org.hibernate.Query)7 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 ArticleItem (org.ambraproject.rhino.model.ArticleItem)4 IOException (java.io.IOException)3 LocalDate (java.time.LocalDate)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 ArticleIngestionIdentifier (org.ambraproject.rhino.identity.ArticleIngestionIdentifier)3 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)3 ArticleRevisionView (org.ambraproject.rhino.view.article.ArticleRevisionView)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Document (org.w3c.dom.Document)3