use of org.ambraproject.rhino.view.article.ListInputView 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);
}
use of org.ambraproject.rhino.view.article.ListInputView 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);
}
Aggregations