Search in sources :

Example 1 with ArticleXml

use of org.ambraproject.rhino.content.xml.ArticleXml 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 ArticleXml

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

the class ArticleCrudServiceImpl method refreshArticleRelationships.

@Override
public void refreshArticleRelationships(ArticleRevision sourceArticleRev) {
    ArticleXml sourceArticleXml = new ArticleXml(getManuscriptXml(sourceArticleRev.getIngestion()));
    Article sourceArticle = sourceArticleRev.getIngestion().getArticle();
    List<RelatedArticleLink> xmlRelationships = sourceArticleXml.parseRelatedArticles();
    List<ArticleRelationship> dbRelationships = getRelationshipsFrom(ArticleIdentifier.create(sourceArticle.getDoi()));
    dbRelationships.forEach(ar -> hibernateTemplate.delete(ar));
    xmlRelationships.forEach(ar -> {
        getArticle(ar.getArticleId()).ifPresent((Article relatedArticle) -> {
            hibernateTemplate.save(fromRelatedArticleLink(sourceArticle, ar));
            getLatestRevision(relatedArticle).ifPresent((ArticleRevision relatedArticleRev) -> {
                ArticleXml relatedArticleXml = new ArticleXml(getManuscriptXml(relatedArticleRev.getIngestion()));
                Set<ArticleRelationship> inboundDbRelationships = getRelationshipsTo(ArticleIdentifier.create(sourceArticle.getDoi())).stream().filter(dbAr -> dbAr.getSourceArticle().equals(relatedArticle)).collect(Collectors.toSet());
                relatedArticleXml.parseRelatedArticles().stream().filter(ral -> ral.getArticleId().getDoiName().equals(sourceArticle.getDoi())).map(ral -> fromRelatedArticleLink(relatedArticle, ral)).filter(relatedAr -> !inboundDbRelationships.contains(relatedAr)).forEach(relatedAr -> hibernateTemplate.save(relatedAr));
            });
        });
    });
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) ServiceResponse(org.ambraproject.rhino.rest.response.ServiceResponse) ArticleFileIdentifier(org.ambraproject.rhino.identity.ArticleFileIdentifier) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Collections2(com.google.common.collect.Collections2) Archive(org.ambraproject.rhino.util.Archive) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Matcher(java.util.regex.Matcher) Document(org.w3c.dom.Document) Map(java.util.Map) Query(org.hibernate.Query) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) ArticleAllAuthorsView(org.ambraproject.rhino.view.article.author.ArticleAllAuthorsView) ArticleItem(org.ambraproject.rhino.model.ArticleItem) RepoObjectMetadata(org.plos.crepo.model.metadata.RepoObjectMetadata) Collection(java.util.Collection) Set(java.util.Set) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) AssetCrudService(org.ambraproject.rhino.service.AssetCrudService) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Objects(java.util.Objects) List(java.util.List) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ArticleFile(org.ambraproject.rhino.model.ArticleFile) Pattern(java.util.regex.Pattern) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship) Iterables(com.google.common.collect.Iterables) Article(org.ambraproject.rhino.model.Article) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) ArticleItemIdentifier(org.ambraproject.rhino.identity.ArticleItemIdentifier) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TaxonomyService(org.ambraproject.rhino.service.taxonomy.TaxonomyService) XpathReader(org.ambraproject.rhino.content.xml.XpathReader) Doi(org.ambraproject.rhino.identity.Doi) ByteSource(com.google.common.io.ByteSource) XPathException(javax.xml.xpath.XPathException) ArticleIngestionView(org.ambraproject.rhino.view.article.ArticleIngestionView) Logger(org.slf4j.Logger) XmlContentException(org.ambraproject.rhino.content.xml.XmlContentException) IOException(java.io.IOException) ArticleCategoryAssignment(org.ambraproject.rhino.model.ArticleCategoryAssignment) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) AuthorView(org.ambraproject.rhino.view.article.author.AuthorView) CategoryAssignmentView(org.ambraproject.rhino.view.article.CategoryAssignmentView) ItemSetView(org.ambraproject.rhino.view.article.ItemSetView) InputStream(java.io.InputStream) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) Article(org.ambraproject.rhino.model.Article) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship)

Aggregations

ArticleXml (org.ambraproject.rhino.content.xml.ArticleXml)2 Document (org.w3c.dom.Document)2 Strings (com.google.common.base.Strings)1 Collections2 (com.google.common.collect.Collections2)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 ByteSource (com.google.common.io.ByteSource)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1