use of org.ambraproject.rhino.identity.IssueIdentifier 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.identity.IssueIdentifier in project rhino by PLOS.
the class IssueCrudServiceImpl method create.
@Override
public Issue create(VolumeIdentifier volumeId, IssueInputView input) {
Preconditions.checkNotNull(volumeId);
IssueIdentifier issueId = IssueIdentifier.create(input.getDoi());
if (getIssue(issueId).isPresent()) {
throw new RestClientException("Issue already exists with DOI: " + issueId, HttpStatus.BAD_REQUEST);
}
Issue issue = applyInput(new Issue(), input);
Volume volume = volumeCrudService.readVolume(volumeId);
volume.getIssues().add(issue);
hibernateTemplate.save(volume);
return issue;
}
use of org.ambraproject.rhino.identity.IssueIdentifier 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.identity.IssueIdentifier in project rhino by PLOS.
the class IssueCrudController method delete.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.DELETE)
public ResponseEntity<Object> delete(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi, @PathVariable("issueDoi") String issueDoi) throws IOException {
// TODO: Validate journalKey and volumeDoiObj
IssueIdentifier issueId = getIssueId(issueDoi);
issueCrudService.delete(issueId);
return new ResponseEntity<>(HttpStatus.OK);
}
use of org.ambraproject.rhino.identity.IssueIdentifier in project rhino by PLOS.
the class IssueCrudController method readArticlesInIssue.
@Transactional(readOnly = true)
@RequestMapping(value = "/issues/{issueDoi:.+}/contents", method = RequestMethod.GET)
public ResponseEntity<?> readArticlesInIssue(@PathVariable("issueDoi") String issueDoi) throws IOException {
IssueIdentifier issueId = getIssueId(issueDoi);
Issue issue = issueCrudService.readIssue(issueId);
List<ArticleRevisionView> views = issueOutputViewFactory.getIssueArticlesView(issue);
return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
Aggregations