use of org.ambraproject.rhino.model.ArticleFile 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.ArticleFile 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.ArticleFile in project rhino by PLOS.
the class ContentRepoPersistenceServiceImpl method persistAncillaryFiles.
// TODO: 12/9/16 merge some of the shared logic between these two methods
@Override
public Collection<ArticleFile> persistAncillaryFiles(ArticlePackage articlePackage, ArticleIngestion ingestion) {
Collection<ArticleFile> files = new ArrayList<>();
for (ArticleFileInput ancillaryFile : articlePackage.getAncillaryFiles()) {
RepoVersion repoVersion = contentRepoService.autoCreateRepoObject(ancillaryFile.getObject()).getVersion();
ArticleFile file = new ArticleFile();
file.setIngestion(ingestion);
file.setFileSize(contentRepoService.getRepoObjectMetadata(repoVersion).getSize());
file.setIngestedFileName(ancillaryFile.getFilename());
RepoId repoId = repoVersion.getId();
file.setBucketName(repoId.getBucketName());
file.setCrepoKey(repoId.getKey());
file.setCrepoUuid(repoVersion.getUuid().toString());
files.add(file);
}
return files;
}
use of org.ambraproject.rhino.model.ArticleFile in project rhino by PLOS.
the class ArticleCrudServiceImpl method repack.
@Override
public Archive repack(ArticleIngestionIdentifier ingestionId) {
ArticleIngestion ingestion = readIngestion(ingestionId);
List<ArticleFile> files = hibernateTemplate.execute(session -> {
Query query = session.createQuery("FROM ArticleFile WHERE ingestion = :ingestion");
query.setParameter("ingestion", ingestion);
return (List<ArticleFile>) query.list();
});
Map<String, ByteSource> archiveMap = files.stream().collect(Collectors.toMap(ArticleFile::getIngestedFileName, (ArticleFile file) -> new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return contentRepoService.getRepoObject(file.getCrepoVersion());
}
}));
return Archive.pack(extractFilenameStub(ingestionId.getDoiName()) + ".zip", archiveMap);
}
use of org.ambraproject.rhino.model.ArticleFile 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