use of org.ambraproject.rhino.model.Article in project rhino by PLOS.
the class CommentCrudServiceImpl method serveComments.
@Override
public ServiceResponse<List<CommentOutputView>> serveComments(ArticleIdentifier articleId) throws IOException {
Article article = articleCrudService.readArticle(articleId);
Collection<Comment> comments = fetchAllComments(article);
CommentOutputView.Factory factory = new CommentOutputView.Factory(new CompetingInterestPolicy(runtimeConfiguration), comments, article);
List<CommentOutputView> views = comments.stream().filter(comment -> comment.getParent() == null).sorted(CommentOutputView.BY_DATE).map(factory::buildView).collect(Collectors.toList());
return ServiceResponse.serveView(views);
}
use of org.ambraproject.rhino.model.Article 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.Article in project rhino by PLOS.
the class TaxonomyClassificationServiceImpl method populateCategories.
/**
* {@inheritDoc}
*/
@Override
public void populateCategories(ArticleRevision revision) {
ArticleIngestion ingestion = revision.getIngestion();
Article article = ingestion.getArticle();
Document xml = articleCrudService.getManuscriptXml(ingestion);
List<WeightedTerm> terms;
String doi = article.getDoi();
//todo: fix or remove this when we find a home for article types
boolean isAmendment = false;
if (!isAmendment) {
terms = classifyArticle(article, xml);
if (terms != null && terms.size() > 0) {
List<WeightedTerm> leafNodes = getDistinctLeafNodes(CATEGORY_COUNT, terms);
persistCategories(leafNodes, article);
} else {
log.error("Taxonomy server returned 0 terms. Cannot populate Categories. " + doi);
}
}
}
use of org.ambraproject.rhino.model.Article in project rhino by PLOS.
the class HibernatePersistenceServiceImpl method persistArticle.
@Override
public Article persistArticle(Doi doi) {
String articleDoi = doi.getName();
Article article = hibernateTemplate.execute(session -> {
Query selectQuery = session.createQuery("FROM Article WHERE doi = :doi");
selectQuery.setParameter("doi", articleDoi);
return (Article) selectQuery.uniqueResult();
});
if (article == null) {
article = new Article();
article.setDoi(articleDoi);
hibernateTemplate.save(article);
}
return article;
}
use of org.ambraproject.rhino.model.Article in project rhino by PLOS.
the class IngestionServiceTest method createStubArticleItem.
private static ArticleItem createStubArticleItem() {
ArticleItem articleItem = new ArticleItem();
ArticleIngestion articleIngestion = new ArticleIngestion();
Article article = new Article();
article.setDoi("test");
articleItem.setIngestion(articleIngestion);
articleIngestion.setArticle(article);
return articleItem;
}
Aggregations