Search in sources :

Example 1 with ArticleListIdentity

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

the class ArticleListCrudController method update.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/lists/{type}/journals/{journal}/keys/{key}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "ListInputView", value = "example #1: {\"title\": \"New Title\"}<br>" + "example #2: {\"articleDois\": [\"10.1371/journal.pone.0012345\", \"10.1371/journal.pone.0054321\"]}")
public ResponseEntity<?> update(HttpServletRequest request, @PathVariable("type") String type, @PathVariable("journal") String journalKey, @PathVariable("key") String key) throws IOException {
    final ListInputView inputView;
    try {
        inputView = readJsonFromRequest(request, ListInputView.class);
    } catch (ListInputView.PartialIdentityException e) {
        throw complainAboutListIdentityOnPatch(e);
    }
    if (inputView.getIdentity().isPresent()) {
        throw complainAboutListIdentityOnPatch(null);
    }
    ArticleListIdentity identity = new ArticleListIdentity(type, journalKey, key);
    articleListCrudService.update(identity, inputView.getTitle(), inputView.getArticleIds());
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ArticleListIdentity(org.ambraproject.rhino.identity.ArticleListIdentity) ResponseEntity(org.springframework.http.ResponseEntity) ListInputView(org.ambraproject.rhino.view.article.ListInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ArticleListIdentity

use of org.ambraproject.rhino.identity.ArticleListIdentity 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)

Aggregations

ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)2 ArticleListIdentity (org.ambraproject.rhino.identity.ArticleListIdentity)2 ListInputView (org.ambraproject.rhino.view.article.ListInputView)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 ArticleListView (org.ambraproject.rhino.view.journal.ArticleListView)1 ResponseEntity (org.springframework.http.ResponseEntity)1