use of org.ambraproject.rhino.model.Volume in project rhino by PLOS.
the class IssueCrudController method readIssuesForVolume.
@Transactional(readOnly = true)
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues", method = RequestMethod.GET)
public ResponseEntity<?> readIssuesForVolume(@PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
// TODO: Validate journalKey
VolumeIdentifier volumeId = VolumeIdentifier.create(DoiEscaping.unescape(volumeDoi));
Volume volume = volumeCrudService.readVolume(volumeId);
List<IssueOutputView> views = volume.getIssues().stream().map(issueOutputViewFactory::getView).collect(Collectors.toList());
return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.model.Volume in project rhino by PLOS.
the class DoiController method findDoiTarget.
private ResolvedDoiView findDoiTarget(Doi doi) throws IOException {
// Look for the DOI in the corpus of articles
Optional<ResolvedDoiView> itemOverview = articleCrudService.getItemOverview(doi);
if (itemOverview.isPresent()) {
return itemOverview.get();
}
// Not found as an Article or ArticleItem. Check other object types that use DOIs.
Optional<Comment> comment = commentCrudService.getComment(CommentIdentifier.create(doi));
if (comment.isPresent()) {
ArticleOverview article = articleCrudService.buildOverview(comment.get().getArticle());
return ResolvedDoiView.createForArticle(doi, ResolvedDoiView.DoiWorkType.COMMENT, article);
}
Optional<Issue> issue = issueCrudService.getIssue(IssueIdentifier.create(doi));
if (issue.isPresent()) {
Journal journal = issueCrudService.getJournalOf(issue.get());
return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.ISSUE, journal);
}
Optional<Volume> volume = volumeCrudService.getVolume(VolumeIdentifier.create(doi));
if (volume.isPresent()) {
Journal journal = volumeCrudService.getJournalOf(volume.get());
return ResolvedDoiView.create(doi, ResolvedDoiView.DoiWorkType.VOLUME, journal);
}
throw new RestClientException("DOI not found: " + doi.getName(), HttpStatus.NOT_FOUND);
}
use of org.ambraproject.rhino.model.Volume 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);
}
use of org.ambraproject.rhino.model.Volume in project rhino by PLOS.
the class VolumeCrudServiceImpl method delete.
@Override
public void delete(VolumeIdentifier id) throws IOException {
Volume volume = readVolume(id);
if (volume.getIssues().size() > 0) {
throw new RestClientException("Volume has issues and cannot be deleted until all issues have " + "been deleted.", HttpStatus.BAD_REQUEST);
}
hibernateTemplate.delete(volume);
}
use of org.ambraproject.rhino.model.Volume in project rhino by PLOS.
the class IssueCrudServiceImpl method getParentVolume.
@Override
public Volume getParentVolume(Issue issue) {
Volume parentVolume = hibernateTemplate.execute((Session session) -> {
Query query = session.createQuery("from Volume where :issue in elements(issues)");
query.setParameter("issue", issue);
return (Volume) query.uniqueResult();
});
if (parentVolume == null) {
throw new RuntimeException("Data integrity error; issue has no parent volume: " + issue.getDoi());
}
return parentVolume;
}
Aggregations