Search in sources :

Example 1 with RelatedArticleLink

use of org.ambraproject.rhino.model.article.RelatedArticleLink 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)

Example 2 with RelatedArticleLink

use of org.ambraproject.rhino.model.article.RelatedArticleLink in project rhino by PLOS.

the class IngestionTest method compareRelationshipLists.

private void compareRelationshipLists(AssertionCollector results, List<RelatedArticleLink> actual, List<RelatedArticleLink> expected) {
    Map<ArticleIdentifier, RelatedArticleLink> actualMap = Maps.uniqueIndex(actual, RelatedArticleLink::getArticleId);
    Set<ArticleIdentifier> actualDois = actualMap.keySet();
    Map<ArticleIdentifier, RelatedArticleLink> expectedMap = Maps.uniqueIndex(expected, RelatedArticleLink::getArticleId);
    Set<ArticleIdentifier> expectedDois = expectedMap.keySet();
    for (ArticleIdentifier missingDoi : Sets.difference(expectedDois, actualDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", null, missingDoi);
    }
    for (ArticleIdentifier extraDoi : Sets.difference(actualDois, expectedDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", extraDoi, null);
    }
    for (ArticleIdentifier doi : Sets.intersection(actualDois, expectedDois)) {
        compare(results, ArticleRelationship.class, "otherArticleDoi", doi, doi);
        compare(results, ArticleRelationship.class, "type", actualMap.get(doi).getType(), expectedMap.get(doi).getType());
    }
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink)

Example 3 with RelatedArticleLink

use of org.ambraproject.rhino.model.article.RelatedArticleLink in project rhino by PLOS.

the class ArticleXml method parseRelatedArticles.

/**
   * Parse {@link RelatedArticleLink} objects from XML.
   * <p/>
   * These are returned from here, rather than set in the {@link ArticleMetadata} object during normal parsing, so they
   * can get special handling.
   *
   * @return the article relationships defined by the XML
   */
public List<RelatedArticleLink> parseRelatedArticles() {
    List<Node> relatedArticleNodes = readNodeList("//related-article");
    List<RelatedArticleLink> relatedArticles = Lists.newArrayListWithCapacity(relatedArticleNodes.size());
    for (Node relatedArticleNode : relatedArticleNodes) {
        String type = readString("attribute::related-article-type", relatedArticleNode);
        String doi = readHrefAttribute(relatedArticleNode);
        if (doi != null) {
            RelatedArticleLink relatedArticle = new RelatedArticleLink(type, ArticleIdentifier.create(doi));
            relatedArticles.add(relatedArticle);
        } else {
            throw new XmlContentException("Related article has no doi. node " + relatedArticleNode.getAttributes().getNamedItem("id"));
        }
    }
    return relatedArticles;
}
Also used : Node(org.w3c.dom.Node) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink)

Aggregations

RelatedArticleLink (org.ambraproject.rhino.model.article.RelatedArticleLink)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)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