Search in sources :

Example 1 with ManifestXml

use of org.ambraproject.rhino.content.xml.ManifestXml in project rhino by PLOS.

the class IngestionService method createIngestPackage.

private IngestPackage createIngestPackage(Archive archive, Optional<String> bucketName) throws IOException {
    ManifestXml manifestXml = getManifestXml(archive);
    ImmutableSet<String> entryNames = archive.getEntryNames();
    manifestXml.validateManifestCompleteness(entryNames);
    String manuscriptEntry = getManuscriptEntry(entryNames, manifestXml);
    Document document = getDocument(archive, manuscriptEntry);
    ArticleXml parsedArticle = new ArticleXml(document);
    ArticleCustomMetadata customMetadata = customMetadataExtractorFactory.parse(document).build();
    ArticlePackage articlePackage = new ArticlePackageBuilder(resolveBucketName(bucketName), archive, parsedArticle, manifestXml).build();
    articlePackage.validateAssetCompleteness(parsedArticle.findAllAssetNodes().getDois());
    ArticleMetadata articleMetadata = parsedArticle.build();
    return new IngestPackage(articlePackage, articleMetadata, customMetadata);
}
Also used : ArticlePackageBuilder(org.ambraproject.rhino.model.ingest.ArticlePackageBuilder) IngestPackage(org.ambraproject.rhino.model.ingest.IngestPackage) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) ArticleCustomMetadata(org.ambraproject.rhino.model.article.ArticleCustomMetadata) Document(org.w3c.dom.Document) ArticlePackage(org.ambraproject.rhino.model.ingest.ArticlePackage) ArticleMetadata(org.ambraproject.rhino.model.article.ArticleMetadata)

Example 2 with ManifestXml

use of org.ambraproject.rhino.content.xml.ManifestXml in project rhino by PLOS.

the class IngestionService method getManuscriptEntry.

private String getManuscriptEntry(ImmutableSet<String> entryNames, ManifestXml manifestXml) {
    ManifestXml.Representation manuscriptRepr = manifestXml.getArticleAsset().getRepresentation("manuscript").orElseThrow(() -> new RestClientException("Manuscript entry not found in manifest", HttpStatus.BAD_REQUEST));
    String manuscriptEntry = manuscriptRepr.getFile().getEntry();
    if (!entryNames.contains(manuscriptEntry)) {
        throw new RestClientException("Manuscript file not found in archive: " + manuscriptEntry, HttpStatus.BAD_REQUEST);
    }
    return manuscriptEntry;
}
Also used : RestClientException(org.ambraproject.rhino.rest.RestClientException) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml)

Example 3 with ManifestXml

use of org.ambraproject.rhino.content.xml.ManifestXml 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;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticlePackage(org.ambraproject.rhino.model.ingest.ArticlePackage) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) JournalCrudService(org.ambraproject.rhino.service.JournalCrudService) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) Collection(java.util.Collection) RestClientException(org.ambraproject.rhino.rest.RestClientException) HibernatePersistenceService(org.ambraproject.rhino.service.HibernatePersistenceService) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ArticleCustomMetadata(org.ambraproject.rhino.model.article.ArticleCustomMetadata) ContentRepoPersistenceService(org.ambraproject.rhino.service.ContentRepoPersistenceService) HttpStatus(org.springframework.http.HttpStatus) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) List(java.util.List) ArticleItemInput(org.ambraproject.rhino.model.ingest.ArticleItemInput) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Query(org.hibernate.Query) Optional(java.util.Optional) Doi(org.ambraproject.rhino.identity.Doi) ArticleFile(org.ambraproject.rhino.model.ArticleFile) ArticleMetadata(org.ambraproject.rhino.model.article.ArticleMetadata) ArticleItem(org.ambraproject.rhino.model.ArticleItem) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Doi(org.ambraproject.rhino.identity.Doi)

Example 4 with ManifestXml

use of org.ambraproject.rhino.content.xml.ManifestXml in project rhino by PLOS.

the class IngestionService method getManifestXml.

@VisibleForTesting
ManifestXml getManifestXml(Archive archive) throws IOException {
    String manifestEntry = null;
    for (String entryName : archive.getEntryNames()) {
        if (entryName.equalsIgnoreCase("manifest.xml")) {
            manifestEntry = entryName;
        }
    }
    if (manifestEntry == null) {
        throw new RestClientException("Archive has no manifest file", HttpStatus.BAD_REQUEST);
    }
    ManifestXml manifestXml;
    try (InputStream manifestStream = new BufferedInputStream(archive.openFile(manifestEntry))) {
        manifestXml = new ManifestXml(AmbraService.parseXml(manifestStream));
    }
    return manifestXml;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) RestClientException(org.ambraproject.rhino.rest.RestClientException) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)4 RestClientException (org.ambraproject.rhino.rest.RestClientException)3 ArticleCustomMetadata (org.ambraproject.rhino.model.article.ArticleCustomMetadata)2 ArticleMetadata (org.ambraproject.rhino.model.article.ArticleMetadata)2 ArticlePackage (org.ambraproject.rhino.model.ingest.ArticlePackage)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ArticleXml (org.ambraproject.rhino.content.xml.ArticleXml)1 Doi (org.ambraproject.rhino.identity.Doi)1 Article (org.ambraproject.rhino.model.Article)1 ArticleFile (org.ambraproject.rhino.model.ArticleFile)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 ArticleItem (org.ambraproject.rhino.model.ArticleItem)1 Journal (org.ambraproject.rhino.model.Journal)1 ArticleItemInput (org.ambraproject.rhino.model.ingest.ArticleItemInput)1