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