use of org.ambraproject.rhino.model.Article 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.Article 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.Article 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.Article in project rhino by PLOS.
the class ArticleCrudServiceImpl method fromRelatedArticleLink.
private ArticleRelationship fromRelatedArticleLink(Article article, RelatedArticleLink ral) {
ArticleRelationship ar = new ArticleRelationship();
ar.setSourceArticle(Objects.requireNonNull(article));
Article targetArticle = getArticle(ral.getArticleId()).orElse(null);
ar.setTargetArticle(Objects.requireNonNull(targetArticle));
ar.setType(Objects.requireNonNull(ral.getType()));
return ar;
}
use of org.ambraproject.rhino.model.Article 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);
}
Aggregations