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