use of org.ambraproject.rhino.model.ArticleRelationship 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.ArticleRelationship in project rhino by PLOS.
the class ArticleCrudServiceImpl method fromRelatedArticleLink.
private ArticleRelationship fromRelatedArticleLink(Article article, RelatedArticleLink ral) {
ArticleRelationship ar = new ArticleRelationship();
ar.setSourceArticle(Objects.requireNonNull(article));
Article targetArticle = getArticle(ral.getArticleId()).orElse(null);
ar.setTargetArticle(Objects.requireNonNull(targetArticle));
ar.setType(Objects.requireNonNull(ral.getType()));
return ar;
}
Aggregations