Search in sources :

Example 1 with ArticleRevisionIdentifier

use of org.ambraproject.rhino.identity.ArticleRevisionIdentifier in project rhino by PLOS.

the class ArticleCrudController method deleteRevision.

@Transactional(readOnly = false)
@RequestMapping(value = "/articles/{doi}/revisions/{revision}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteRevision(@PathVariable("doi") String doi, @PathVariable("revision") int revisionNumber) {
    ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    articleRevisionWriteService.deleteRevision(revisionId);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ArticleRevisionIdentifier

use of org.ambraproject.rhino.identity.ArticleRevisionIdentifier in project rhino by PLOS.

the class ArticleCrudController method readSyndications.

@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", method = RequestMethod.GET)
public ResponseEntity<?> readSyndications(@PathVariable("doi") String doi, @PathVariable("number") int revisionNumber) throws IOException {
    ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    List<Syndication> syndications = syndicationCrudService.getSyndications(revisionId);
    // TODO: If revision does not exist, need to respond with 404 instead of empty list?
    List<SyndicationView> views = syndications.stream().map(SyndicationView::new).collect(Collectors.toList());
    return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
Also used : SyndicationView(org.ambraproject.rhino.view.article.SyndicationView) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Syndication(org.ambraproject.rhino.model.Syndication) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ArticleRevisionIdentifier

use of org.ambraproject.rhino.identity.ArticleRevisionIdentifier 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 4 with ArticleRevisionIdentifier

use of org.ambraproject.rhino.identity.ArticleRevisionIdentifier in project rhino by PLOS.

the class ArticleCrudController method createSyndication.

@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "SyndicationInputView", value = "example: {\"targetQueue\": \"activemq:plos.pmc\"}")
public ResponseEntity<?> createSyndication(HttpServletRequest request, @PathVariable("doi") String doi, @PathVariable("number") int revisionNumber) throws IOException {
    ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    SyndicationInputView input = readJsonFromRequest(request, SyndicationInputView.class);
    Syndication syndication = syndicationCrudService.createSyndication(revisionId, input.getTargetQueue());
    return ServiceResponse.reportCreated(new SyndicationView(syndication)).asJsonResponse(entityGson);
}
Also used : SyndicationView(org.ambraproject.rhino.view.article.SyndicationView) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) SyndicationInputView(org.ambraproject.rhino.view.article.SyndicationInputView) Syndication(org.ambraproject.rhino.model.Syndication) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ArticleRevisionIdentifier

use of org.ambraproject.rhino.identity.ArticleRevisionIdentifier in project rhino by PLOS.

the class ArticleCrudController method syndicate.

@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", // Fold into PATCH operation so we can get rid of "?syndicate"?
method = RequestMethod.POST, params = "syndicate")
@ApiOperation(value = "syndicate", notes = "Send a syndication message to the queue for processing. " + "Will create and add a syndication to the database if none exist for current article and target.")
@ApiImplicitParam(name = "body", paramType = "body", dataType = "SyndicationInputView", value = "example: {\"targetQueue\": \"activemq:plos.pmc\"}")
public ResponseEntity<?> syndicate(HttpServletRequest request, @PathVariable("doi") String doi, @PathVariable("number") int revisionNumber) throws IOException {
    ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    SyndicationInputView input = readJsonFromRequest(request, SyndicationInputView.class);
    Syndication created = syndicationCrudService.syndicate(revisionId, input.getTargetQueue());
    return ServiceResponse.reportCreated(new SyndicationView(created)).asJsonResponse(entityGson);
}
Also used : SyndicationView(org.ambraproject.rhino.view.article.SyndicationView) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) SyndicationInputView(org.ambraproject.rhino.view.article.SyndicationInputView) Syndication(org.ambraproject.rhino.model.Syndication) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArticleRevisionIdentifier (org.ambraproject.rhino.identity.ArticleRevisionIdentifier)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Syndication (org.ambraproject.rhino.model.Syndication)4 SyndicationView (org.ambraproject.rhino.view.article.SyndicationView)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 SyndicationInputView (org.ambraproject.rhino.view.article.SyndicationInputView)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 ArticleIngestionIdentifier (org.ambraproject.rhino.identity.ArticleIngestionIdentifier)1 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)1 ResponseEntity (org.springframework.http.ResponseEntity)1