use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.
the class ArticleIngestionView method serialize.
@Override
public JsonElement serialize(JsonSerializationContext context) {
JsonObject serialized = new JsonObject();
serialized.addProperty("doi", ingestion.getArticle().getDoi());
serialized.addProperty("ingestionNumber", ingestion.getIngestionNumber());
serialized.add("journal", context.serialize(journal));
serialized.addProperty("bucketName", bucketName);
ArticleItem strikingImage = ingestion.getStrikingImage();
if (strikingImage != null) {
serialized.add("strikingImage", context.serialize(ItemSetView.getItemView(strikingImage)));
}
JsonAdapterUtil.copyWithoutOverwriting(context.serialize(metadata).getAsJsonObject(), serialized);
JsonAdapterUtil.copyWithoutOverwriting(context.serialize(customMetadata).getAsJsonObject(), serialized);
serialized.remove("assets");
List<AssetMetadataView> assetViews = metadata.getAssets().stream().map(AssetMetadataView::new).collect(Collectors.toList());
serialized.add("assetsLinkedFromManuscript", context.serialize(assetViews));
return serialized;
}
use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.
the class ContentRepoPersistenceServiceImpl method createItem.
@Override
public ArticleItem createItem(ArticleItemInput itemInput, ArticleIngestion ingestion) {
ArticleItem item = new ArticleItem();
item.setIngestion(ingestion);
item.setDoi(itemInput.getDoi().getName());
item.setItemType(itemInput.getType());
Collection<ArticleFile> files = new ArrayList<>(itemInput.getFiles().entrySet().size());
for (Map.Entry<String, ArticleFileInput> entry : itemInput.getFiles().entrySet()) {
ArticleFileInput fileInput = entry.getValue();
RepoVersion repoVersion = contentRepoService.autoCreateRepoObject(fileInput.getObject()).getVersion();
ArticleFile file = new ArticleFile();
file.setIngestion(ingestion);
file.setItem(item);
file.setFileType(entry.getKey());
RepoId repoId = repoVersion.getId();
file.setBucketName(repoId.getBucketName());
file.setCrepoKey(repoId.getKey());
file.setCrepoUuid(repoVersion.getUuid().toString());
file.setFileSize(contentRepoService.getRepoObjectMetadata(repoVersion).getSize());
file.setIngestedFileName(fileInput.getFilename());
files.add(file);
}
item.setFiles(files);
return item;
}
use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.
the class AssetCrudServiceImpl method getArticleItemFile.
@Override
public RepoObjectMetadata getArticleItemFile(ArticleFileIdentifier fileId) {
ArticleItem work = articleCrudService.getArticleItem(fileId.getItemIdentifier());
String fileType = fileId.getFileType();
ArticleFile articleFile = work.getFile(fileType).orElseThrow(() -> new RestClientException("Unrecognized type: " + fileType, HttpStatus.NOT_FOUND));
try {
return contentRepoService.getRepoObjectMetadata(articleFile.getCrepoVersion());
} catch (NotFoundException e) {
throw new RestClientException("Object not found: " + fileId + ". File info: " + articleFile, HttpStatus.NOT_FOUND);
}
}
use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.
the class ArticleCrudServiceImpl method getItemOverview.
@Override
public Optional<ResolvedDoiView> getItemOverview(Doi doi) {
return hibernateTemplate.execute(session -> {
Query ingestionQuery = session.createQuery("FROM ArticleItem WHERE doi = :doi");
ingestionQuery.setParameter("doi", doi.getName());
List<ArticleItem> items = ingestionQuery.list();
if (items.isEmpty())
return Optional.empty();
ResolvedDoiView.DoiWorkType type = items.stream().allMatch(ArticleCrudServiceImpl::isMainArticleItem) ? ResolvedDoiView.DoiWorkType.ARTICLE : ResolvedDoiView.DoiWorkType.ASSET;
ArticleIdentifier articleId = Iterables.getOnlyElement(items.stream().map(item -> ArticleIdentifier.create(item.getIngestion().getArticle().getDoi())).collect(Collectors.toSet()));
Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + " (SELECT ingestion FROM ArticleItem WHERE doi = :doi)");
revisionQuery.setParameter("doi", doi.getName());
List<ArticleRevision> revisions = revisionQuery.list();
Collection<ArticleIngestion> ingestions = Collections2.transform(items, ArticleItem::getIngestion);
ArticleOverview articleOverview = ArticleOverview.build(articleId, ingestions, revisions);
return Optional.of(ResolvedDoiView.createForArticle(doi, type, articleOverview));
});
}
use of org.ambraproject.rhino.model.ArticleItem in project rhino by PLOS.
the class ArticleCrudServiceImpl method getLatestRevision.
@Override
public Optional<ArticleRevision> getLatestRevision(Article article) {
Integer maxRevisionNumber = hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "SELECT MAX(rev.revisionNumber) " + "FROM ArticleRevision rev, ArticleItem item " + "WHERE item.doi = :doi " + " AND rev.ingestion = item.ingestion");
query.setParameter("doi", Doi.create(article.getDoi()).getName());
return (Integer) query.uniqueResult();
});
if (maxRevisionNumber == null)
return Optional.empty();
return Optional.ofNullable(hibernateTemplate.execute(session -> {
Query query = session.createQuery("" + "FROM ArticleRevision as av " + "WHERE av.ingestion.article = :article " + "AND av.revisionNumber = :latestRevision");
query.setParameter("article", article);
query.setParameter("latestRevision", maxRevisionNumber);
return (ArticleRevision) query.uniqueResult();
}));
}
Aggregations