use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleCrudController method writeRevision.
@Transactional(readOnly = false)
@RequestMapping(value = "/articles/{doi}/revisions", method = RequestMethod.POST)
public ResponseEntity<?> writeRevision(@PathVariable("doi") String doi, @RequestParam(value = "revision", required = false) Integer revisionNumber, @RequestParam(value = "ingestion", required = true) Integer ingestionNumber) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(doi));
ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(articleId, ingestionNumber);
final ArticleRevision revision;
if (revisionNumber == null) {
revision = articleRevisionWriteService.createRevision(ingestionId);
} else {
ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(articleId, revisionNumber);
revision = articleRevisionWriteService.writeRevision(revisionId, ingestionId);
}
return ServiceResponse.reportCreated(ArticleRevisionView.getView(revision)).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.model.ArticleRevision 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.ArticleRevision in project rhino by PLOS.
the class ArticleRevisionWriteServiceImpl method deleteRevision.
@Override
public void deleteRevision(ArticleRevisionIdentifier revisionId) {
ArticleRevision revision = articleCrudService.readRevision(revisionId);
Article article = revision.getIngestion().getArticle();
ArticleRevision latestRevision = articleCrudService.getLatestRevision(article).orElseThrow(// should be guaranteed to exist because at least one revision exists
RuntimeException::new);
boolean deletingLatest = latestRevision.equals(revision);
hibernateTemplate.delete(revision);
if (deletingLatest) {
articleCrudService.getLatestRevision(article).ifPresent(this::refreshForLatestRevision);
// else, we deleted the only revision
}
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleCrudServiceImpl method serveOverview.
@Override
public ServiceResponse<ArticleOverview> serveOverview(ArticleIdentifier id) {
ArticleOverview view = hibernateTemplate.execute(session -> {
Query ingestionQuery = session.createQuery("FROM ArticleIngestion WHERE article.doi = :doi");
ingestionQuery.setParameter("doi", id.getDoiName());
List<ArticleIngestion> ingestions = ingestionQuery.list();
Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + " (FROM ArticleIngestion WHERE article.doi = :doi)");
revisionQuery.setParameter("doi", id.getDoiName());
List<ArticleRevision> revisions = revisionQuery.list();
return ArticleOverview.build(id, ingestions, revisions);
});
return ServiceResponse.serveView(view);
}
use of org.ambraproject.rhino.model.ArticleRevision in project rhino by PLOS.
the class ArticleRevisionWriteServiceImpl method createRevision.
@Override
public ArticleRevision createRevision(ArticleIngestionIdentifier ingestionId) {
ArticleIngestion ingestion = articleCrudService.readIngestion(ingestionId);
Optional<ArticleRevision> previousLatest = articleCrudService.getLatestRevision(ingestion.getArticle());
int newRevisionNumber = 1 + previousLatest.map(ArticleRevision::getRevisionNumber).orElse(0);
ArticleRevision revision = new ArticleRevision();
revision.setIngestion(ingestion);
revision.setRevisionNumber(newRevisionNumber);
hibernateTemplate.save(revision);
refreshForLatestRevision(revision);
return revision;
}
Aggregations