Search in sources :

Example 6 with ArticleRevision

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);
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ArticleRevision

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));
            });
        });
    });
}
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 8 with ArticleRevision

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
    }
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article)

Example 9 with ArticleRevision

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);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Example 10 with ArticleRevision

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;
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision)

Aggregations

ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)20 Article (org.ambraproject.rhino.model.Article)9 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)9 Query (org.hibernate.Query)7 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 ArticleItem (org.ambraproject.rhino.model.ArticleItem)4 IOException (java.io.IOException)3 LocalDate (java.time.LocalDate)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 ArticleIngestionIdentifier (org.ambraproject.rhino.identity.ArticleIngestionIdentifier)3 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)3 ArticleRevisionView (org.ambraproject.rhino.view.article.ArticleRevisionView)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Document (org.w3c.dom.Document)3