Search in sources :

Example 6 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class ArticleCrudServiceImpl method getArticleItem.

@Override
public ArticleItem getArticleItem(ArticleItemIdentifier id) {
    return hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "FROM ArticleItem " + "WHERE doi = :doi " + "  AND ingestion.ingestionNumber = :ingestionNumber");
        query.setParameter("doi", id.getDoiName());
        query.setParameter("ingestionNumber", id.getIngestionNumber());
        return (ArticleItem) query.uniqueResult();
    });
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) Query(org.hibernate.Query)

Example 7 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem 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;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Article(org.ambraproject.rhino.model.Article)

Example 8 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem 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)

Example 9 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class HibernatePersistenceServiceImpl method persistStrikingImage.

@Override
public Optional<ArticleItem> persistStrikingImage(ArticleIngestion ingestion, List<ArticleItem> items, ManifestXml manifest) {
    Optional<ManifestXml.Asset> strikingImageAsset = manifest.getAssets().stream().filter(ManifestXml.Asset::isStrikingImage).findAny();
    if (!strikingImageAsset.isPresent()) {
        // No striking image declared, so go without setting one.
        return Optional.empty();
    }
    Doi strikingImageDoi = Doi.create(strikingImageAsset.get().getUri());
    Optional<ArticleItem> strikingImageItem = items.stream().filter(item -> Doi.create(item.getDoi()).equals(strikingImageDoi)).findAny();
    if (!strikingImageItem.isPresent()) {
        throw new RuntimeException("Striking image from manifest not found (should have been created by now)");
    }
    ingestion.setStrikingImage(strikingImageItem.get());
    hibernateTemplate.update(ingestion);
    return strikingImageItem;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticlePackage(org.ambraproject.rhino.model.ingest.ArticlePackage) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) JournalCrudService(org.ambraproject.rhino.service.JournalCrudService) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) Collection(java.util.Collection) RestClientException(org.ambraproject.rhino.rest.RestClientException) HibernatePersistenceService(org.ambraproject.rhino.service.HibernatePersistenceService) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ArticleCustomMetadata(org.ambraproject.rhino.model.article.ArticleCustomMetadata) ContentRepoPersistenceService(org.ambraproject.rhino.service.ContentRepoPersistenceService) HttpStatus(org.springframework.http.HttpStatus) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) List(java.util.List) ArticleItemInput(org.ambraproject.rhino.model.ingest.ArticleItemInput) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Query(org.hibernate.Query) Optional(java.util.Optional) Doi(org.ambraproject.rhino.identity.Doi) ArticleFile(org.ambraproject.rhino.model.ArticleFile) ArticleMetadata(org.ambraproject.rhino.model.article.ArticleMetadata) ArticleItem(org.ambraproject.rhino.model.ArticleItem) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Doi(org.ambraproject.rhino.identity.Doi)

Example 10 with ArticleItem

use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.

the class HibernatePersistenceServiceImpl method persistAssets.

@Override
public void persistAssets(ArticlePackage articlePackage, ArticleIngestion ingestion) {
    List<ArticleItem> items = articlePackage.getAllItems().stream().map((ArticleItemInput item) -> contentRepoPersistenceService.createItem(item, ingestion)).collect(Collectors.toList());
    for (ArticleItem item : items) {
        hibernateTemplate.save(item);
    }
    Collection<ArticleFile> files = contentRepoPersistenceService.persistAncillaryFiles(articlePackage, ingestion);
    for (ArticleFile file : files) {
        hibernateTemplate.save(file);
    }
    persistStrikingImage(ingestion, items, articlePackage.getManifest());
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleFile(org.ambraproject.rhino.model.ArticleFile) ArticleItemInput(org.ambraproject.rhino.model.ingest.ArticleItemInput)

Aggregations

ArticleItem (org.ambraproject.rhino.model.ArticleItem)11 ArticleFile (org.ambraproject.rhino.model.ArticleFile)5 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)5 Article (org.ambraproject.rhino.model.Article)4 Query (org.hibernate.Query)4 Collection (java.util.Collection)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)3 RestClientException (org.ambraproject.rhino.rest.RestClientException)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Doi (org.ambraproject.rhino.identity.Doi)2 Journal (org.ambraproject.rhino.model.Journal)2 ArticleItemInput (org.ambraproject.rhino.model.ingest.ArticleItemInput)2 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)2