Search in sources :

Example 1 with ArticleFile

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);
    }
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) RestClientException(org.ambraproject.rhino.rest.RestClientException) NotFoundException(org.plos.crepo.exceptions.NotFoundException) ArticleFile(org.ambraproject.rhino.model.ArticleFile)

Example 2 with ArticleFile

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;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleFileInput(org.ambraproject.rhino.model.ingest.ArticleFileInput) ArrayList(java.util.ArrayList) ArticleFile(org.ambraproject.rhino.model.ArticleFile) RepoId(org.plos.crepo.model.identity.RepoId) Map(java.util.Map) RepoVersion(org.plos.crepo.model.identity.RepoVersion)

Example 3 with ArticleFile

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;
}
Also used : ArticleFileInput(org.ambraproject.rhino.model.ingest.ArticleFileInput) ArrayList(java.util.ArrayList) ArticleFile(org.ambraproject.rhino.model.ArticleFile) RepoId(org.plos.crepo.model.identity.RepoId) RepoVersion(org.plos.crepo.model.identity.RepoVersion)

Example 4 with ArticleFile

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);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Query(org.hibernate.Query) ByteSource(com.google.common.io.ByteSource) List(java.util.List) ArrayList(java.util.ArrayList) ArticleFile(org.ambraproject.rhino.model.ArticleFile)

Example 5 with ArticleFile

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());
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleFile(org.ambraproject.rhino.model.ArticleFile) ArticleItemInput(org.ambraproject.rhino.model.ingest.ArticleItemInput)

Aggregations

ArticleFile (org.ambraproject.rhino.model.ArticleFile)5 ArrayList (java.util.ArrayList)3 ArticleItem (org.ambraproject.rhino.model.ArticleItem)3 ArticleFileInput (org.ambraproject.rhino.model.ingest.ArticleFileInput)2 RepoId (org.plos.crepo.model.identity.RepoId)2 RepoVersion (org.plos.crepo.model.identity.RepoVersion)2 ByteSource (com.google.common.io.ByteSource)1 List (java.util.List)1 Map (java.util.Map)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 ArticleItemInput (org.ambraproject.rhino.model.ingest.ArticleItemInput)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 Query (org.hibernate.Query)1 NotFoundException (org.plos.crepo.exceptions.NotFoundException)1