use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleCrudServiceImpl method getLatestRevision.
@Override
public Optional<ArticleRevision> getLatestRevision(Article article) {
Integer maxRevisionNumber = hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "SELECT MAX(rev.revisionNumber) " + "FROM ArticleRevision rev, ArticleItem item " + "WHERE item.doi = :doi " + " AND rev.ingestion = item.ingestion");
query.setParameter("doi", Doi.create(article.getDoi()).getName());
return (Integer) query.uniqueResult();
});
if (maxRevisionNumber == null)
return Optional.empty();
return Optional.ofNullable(hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "FROM ArticleRevision as av " + "WHERE av.ingestion.article = :article " + "AND av.revisionNumber = :latestRevision");
query.setParameter("article", article);
query.setParameter("latestRevision", maxRevisionNumber);
return (ArticleRevision) query.uniqueResult();
}));
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleCrudServiceImpl method serveRawCategories.
/**
* {@inheritDoc}
*/
@Override
public ServiceResponse<List<String>> serveRawCategories(final ArticleIdentifier articleId) throws IOException {
Article article = readArticle(articleId);
ArticleRevision revision = readLatestRevision(article);
Document manuscriptXml = getManuscriptXml(revision.getIngestion());
List<String> rawTerms = taxonomyService.getRawTerms(manuscriptXml, article, false);
List<String> cleanedTerms = new ArrayList<>();
for (String term : rawTerms) {
term = term.replaceAll("<TERM>", "").replaceAll("</TERM>", "");
cleanedTerms.add(term);
}
return ServiceResponse.serveView(cleanedTerms);
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleCrudServiceImpl method serveRevisions.
@Override
public ServiceResponse<List<ArticleRevisionView>> serveRevisions(ArticleIdentifier id) {
Article article = readArticle(id);
List<ArticleRevision> revisions = (List<ArticleRevision>) hibernateTemplate.find("FROM ArticleRevision WHERE ingestion.article = ? ORDER BY revisionNumber", article);
List<ArticleRevisionView> views = Lists.transform(revisions, ArticleRevisionView::getView);
return ServiceResponse.serveView(views);
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class IssueOutputView method getIssueImageFigureDoi.
private static String getIssueImageFigureDoi(ArticleCrudService articleCrudService, Article imageArticle) {
ArticleRevision latestArticleRevision = articleCrudService.getLatestRevision(imageArticle).orElseThrow(() -> new RuntimeException("Image article has no published revisions. " + imageArticle.getDoi()));
ArticleIngestion ingestion = latestArticleRevision.getIngestion();
Collection<ArticleItem> allArticleItems = articleCrudService.getAllArticleItems(ingestion);
List<ArticleItem> figureImageItems = allArticleItems.stream().filter(item -> FIGURE_IMAGE_TYPES.contains(item.getItemType())).collect(Collectors.toList());
if (figureImageItems.size() != 1) {
throw new RuntimeException("Image article does not contain exactly one image file. " + imageArticle.getDoi());
}
return figureImageItems.get(0).getDoi();
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class SyndicationCrudServiceImpl method getSyndication.
@Override
@SuppressWarnings("unchecked")
public Syndication getSyndication(final ArticleRevisionIdentifier revisionId, final String syndicationTargetQueue) {
ArticleRevision articleRevision = articleCrudService.readRevision(revisionId);
return hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "FROM Syndication s " + "WHERE s.targetQueue = :targetQueue " + "AND s.articleRevision = :articleRevision");
query.setParameter(ArticleJsonNames.SYNDICATION_TARGET, syndicationTargetQueue);
query.setParameter("articleRevision", articleRevision);
return (Syndication) query.uniqueResult();
});
}
Aggregations