Search in sources :

Example 1 with SyndicationView

use of org.ambraproject.rhino.view.article.SyndicationView 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 2 with SyndicationView

use of org.ambraproject.rhino.view.article.SyndicationView 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 3 with SyndicationView

use of org.ambraproject.rhino.view.article.SyndicationView 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)

Example 4 with SyndicationView

use of org.ambraproject.rhino.view.article.SyndicationView in project rhino by PLOS.

the class ArticleCrudController method patchSyndication.

@RequestMapping(value = "/articles/{doi}/revisions/{number}/syndications", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "SyndicationInputView", value = "example: {\"targetQueue\": \"activemq:plos.pmc\", \"status\": \"FAILURE\", \"errorMessage\": \"failed\"}")
public ResponseEntity<?> patchSyndication(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 patched = syndicationCrudService.updateSyndication(revisionId, input.getTargetQueue(), input.getStatus(), input.getErrorMessage());
    return ServiceResponse.serveView(new SyndicationView(patched)).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)

Aggregations

ArticleRevisionIdentifier (org.ambraproject.rhino.identity.ArticleRevisionIdentifier)4 Syndication (org.ambraproject.rhino.model.Syndication)4 SyndicationView (org.ambraproject.rhino.view.article.SyndicationView)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 SyndicationInputView (org.ambraproject.rhino.view.article.SyndicationInputView)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1