Search in sources :

Example 16 with ArticleIngestion

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

Aggregations

ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)16 Article (org.ambraproject.rhino.model.Article)7 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)7 Query (org.hibernate.Query)6 ArticleItem (org.ambraproject.rhino.model.ArticleItem)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Journal (org.ambraproject.rhino.model.Journal)3 Document (org.w3c.dom.Document)3 InputStream (java.io.InputStream)2 Optional (java.util.Optional)2 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)2 ArticleFile (org.ambraproject.rhino.model.ArticleFile)2 RestClientException (org.ambraproject.rhino.rest.RestClientException)2 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ImmutableList (com.google.common.collect.ImmutableList)1