Search in sources :

Example 1 with ArticleCrudService

use of org.ambraproject.rhino.service.ArticleCrudService 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();
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleItem(org.ambraproject.rhino.model.ArticleItem) JsonObject(com.google.gson.JsonObject) ArticleItem(org.ambraproject.rhino.model.ArticleItem) ImmutableSet(com.google.common.collect.ImmutableSet) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) JsonOutputView(org.ambraproject.rhino.view.JsonOutputView) JsonElement(com.google.gson.JsonElement) Objects(java.util.Objects) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) JsonSerializationContext(com.google.gson.JsonSerializationContext) Optional(java.util.Optional) IssueCrudService(org.ambraproject.rhino.service.IssueCrudService) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonSerializationContext (com.google.gson.JsonSerializationContext)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Article (org.ambraproject.rhino.model.Article)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 ArticleItem (org.ambraproject.rhino.model.ArticleItem)1 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)1 Issue (org.ambraproject.rhino.model.Issue)1 Journal (org.ambraproject.rhino.model.Journal)1 Volume (org.ambraproject.rhino.model.Volume)1 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)1 IssueCrudService (org.ambraproject.rhino.service.IssueCrudService)1 JsonOutputView (org.ambraproject.rhino.view.JsonOutputView)1