Search in sources :

Example 6 with ApiImplicitParam

use of com.wordnik.swagger.annotations.ApiImplicitParam in project rhino by PLOS.

the class IssueCrudController method create.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example: {\"doi\": \"10.1371/issue.pbio.v02.i07\", " + "\"displayName\": \"July\", " + "\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\", " + "\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
    // TODO: Validate journalKey
    VolumeIdentifier volumeId = VolumeIdentifier.create(DoiEscaping.unescape(volumeDoi));
    IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
    if (StringUtils.isBlank(input.getDoi())) {
        throw new RestClientException("issueUri required", HttpStatus.BAD_REQUEST);
    }
    Issue issue = issueCrudService.create(volumeId, input);
    return ServiceResponse.reportCreated(issueOutputViewFactory.getView(issue)).asJsonResponse(entityGson);
}
Also used : Issue(org.ambraproject.rhino.model.Issue) RestClientException(org.ambraproject.rhino.rest.RestClientException) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ApiImplicitParam

use of com.wordnik.swagger.annotations.ApiImplicitParam in project rhino by PLOS.

the class JournalCrudController method update.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "JournalInputView", value = "example: {\"currentIssueDoi\": \"10.1371/issue.pmed.v13.i09\"}")
public ResponseEntity<?> update(@RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince, HttpServletRequest request, @PathVariable String journalKey) throws IOException {
    JournalInputView input = readJsonFromRequest(request, JournalInputView.class);
    journalCrudService.update(journalKey, input);
    return journalCrudService.serve(journalKey).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}
Also used : JournalInputView(org.ambraproject.rhino.view.journal.JournalInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ApiImplicitParam

use of com.wordnik.swagger.annotations.ApiImplicitParam in project rhino by PLOS.

the class VolumeCrudController method create.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "VolumeInputView", value = "example: {\"doi\": \"10.1371/volume.pmed.v01\", \"displayName\": \"2004\"}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable String journalKey) throws IOException {
    VolumeInputView input = readJsonFromRequest(request, VolumeInputView.class);
    if (StringUtils.isBlank(input.getDoi())) {
        throw new RestClientException("Volume DOI required", HttpStatus.BAD_REQUEST);
    }
    Volume volume = volumeCrudService.create(journalKey, input);
    return ServiceResponse.reportCreated(volumeOutputViewFactory.getView(volume)).asJsonResponse(entityGson);
}
Also used : Volume(org.ambraproject.rhino.model.Volume) VolumeInputView(org.ambraproject.rhino.view.journal.VolumeInputView) RestClientException(org.ambraproject.rhino.rest.RestClientException) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ApiImplicitParam

use of com.wordnik.swagger.annotations.ApiImplicitParam in project rhino by PLOS.

the class ArticleListCrudController method create.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/lists", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "ListInputView", value = "example: {\"journal\": \"PLoSONE\", \"type\": \"admin\", \"key\": \"plosone_news\", " + "\"title\": \"test\", \"articleDois\": [\"10.1371/journal.pone.0095668\"]}")
public ResponseEntity<?> create(HttpServletRequest request) throws IOException {
    final ListInputView inputView;
    try {
        inputView = readJsonFromRequest(request, ListInputView.class);
    } catch (ListInputView.PartialIdentityException e) {
        throw complainAboutRequiredListIdentity(e);
    }
    Optional<ArticleListIdentity> identity = inputView.getIdentity();
    if (!identity.isPresent()) {
        throw complainAboutRequiredListIdentity(null);
    }
    Optional<String> title = inputView.getTitle();
    if (!title.isPresent()) {
        throw new RestClientException("title required", HttpStatus.BAD_REQUEST);
    }
    Optional<ImmutableSet<ArticleIdentifier>> articleDois = inputView.getArticleIds();
    if (!articleDois.isPresent()) {
        throw new RestClientException("articleDois required", HttpStatus.BAD_REQUEST);
    }
    ArticleListView listView = articleListCrudService.create(identity.get(), title.get(), articleDois.get());
    return ServiceResponse.reportCreated(listView).asJsonResponse(entityGson);
}
Also used : ArticleListIdentity(org.ambraproject.rhino.identity.ArticleListIdentity) ImmutableSet(com.google.common.collect.ImmutableSet) ListInputView(org.ambraproject.rhino.view.article.ListInputView) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleListView(org.ambraproject.rhino.view.journal.ArticleListView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ApiImplicitParam

use of com.wordnik.swagger.annotations.ApiImplicitParam in project rhino by PLOS.

the class CommentCrudController method patch.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentInputView", value = "example #1: {\"title\": \"new title\"}<br>" + "example #2: {\"body\": \"comment body replacement text\"}<br>" + "example #3: {\"isRemoved\": \"true\"}")
public ResponseEntity<?> patch(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    CommentInputView input = readJsonFromRequest(request, CommentInputView.class);
    return commentCrudService.patchComment(commentId, input).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 Transactional (org.springframework.transaction.annotation.Transactional)7 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 ArticleRevisionIdentifier (org.ambraproject.rhino.identity.ArticleRevisionIdentifier)3 Syndication (org.ambraproject.rhino.model.Syndication)3 RestClientException (org.ambraproject.rhino.rest.RestClientException)3 SyndicationInputView (org.ambraproject.rhino.view.article.SyndicationInputView)3 SyndicationView (org.ambraproject.rhino.view.article.SyndicationView)3 ArticleListIdentity (org.ambraproject.rhino.identity.ArticleListIdentity)2 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)2 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)2 Volume (org.ambraproject.rhino.model.Volume)2 ListInputView (org.ambraproject.rhino.view.article.ListInputView)2 CommentInputView (org.ambraproject.rhino.view.comment.CommentInputView)2 IssueInputView (org.ambraproject.rhino.view.journal.IssueInputView)2 VolumeInputView (org.ambraproject.rhino.view.journal.VolumeInputView)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 IssueIdentifier (org.ambraproject.rhino.identity.IssueIdentifier)1