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;
}
Aggregations