use of org.ambraproject.rhino.view.journal.IssueInputView in project rhino by PLOS.
the class IssueCrudController method update.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example #1: {\"displayName\": \"July\"}<br>" + "example #2: {\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\"}<br>" + "example #3: {\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> update(HttpServletRequest request, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi, @PathVariable("issueDoi") String issueDoi) throws IOException {
// TODO: Validate journalKey and volumeDoiObj
IssueIdentifier issueId = getIssueId(issueDoi);
IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
issueCrudService.update(issueId, input);
return issueCrudService.serveIssue(issueId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.view.journal.IssueInputView in project rhino by PLOS.
the class IssueCrudServiceImpl method applyInput.
private Issue applyInput(Issue issue, IssueInputView input) {
String issueDoi = input.getDoi();
if (issueDoi != null) {
IssueIdentifier issueId = IssueIdentifier.create(issueDoi);
issue.setDoi(issueId.getDoi().getName());
}
String displayName = input.getDisplayName();
if (displayName != null) {
issue.setDisplayName(displayName);
} else if (issue.getDisplayName() == null) {
issue.setDisplayName("");
}
String imageDoi = input.getImageArticleDoi();
if (imageDoi != null) {
ArticleIdentifier imageArticleId = ArticleIdentifier.create(imageDoi);
Article imageArticle = articleCrudService.readArticle(imageArticleId);
issue.setImageArticle(imageArticle);
} else {
issue.setImageArticle(null);
}
List<String> inputArticleDois = input.getArticleOrder();
if (inputArticleDois != null) {
List<Article> inputArticles = inputArticleDois.stream().map(doi -> articleCrudService.readArticle(ArticleIdentifier.create(doi))).collect(Collectors.toList());
issue.setArticles(inputArticles);
}
return issue;
}
use of org.ambraproject.rhino.view.journal.IssueInputView 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);
}
Aggregations