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