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