use of org.ambraproject.rhino.identity.VolumeIdentifier in project rhino by PLOS.
the class VolumeCrudController method update.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "VolumeInputView", value = "example #1: {\"doi\": \"10.1371/volume.pmed.v01\"}<br>" + "example #2: {\"displayName\": \"2004\"}")
public ResponseEntity<?> update(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
// TODO: Validate journalKey
VolumeIdentifier volumeId = getVolumeId(volumeDoi);
VolumeInputView input = readJsonFromRequest(request, VolumeInputView.class);
Volume updated = volumeCrudService.update(volumeId, input);
VolumeOutputView view = volumeOutputViewFactory.getView(updated);
return ServiceResponse.serveView(view).asJsonResponse(entityGson);
}
use of org.ambraproject.rhino.identity.VolumeIdentifier in project rhino by PLOS.
the class VolumeCrudController method delete.
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi:.+}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
// TODO: Validate journalKey
VolumeIdentifier volumeId = getVolumeId(volumeDoi);
volumeCrudService.delete(volumeId);
return reportDeleted(volumeId.getDoi().getName());
}
use of org.ambraproject.rhino.identity.VolumeIdentifier in project rhino by PLOS.
the class VolumeCrudServiceImpl method create.
@Override
public Volume create(String journalKey, VolumeInputView input) {
Preconditions.checkNotNull(journalKey);
VolumeIdentifier volumeId = VolumeIdentifier.create(input.getDoi());
if (getVolume(volumeId).isPresent()) {
throw new RestClientException("Volume already exists with DOI: " + volumeId.getDoi(), HttpStatus.BAD_REQUEST);
}
Volume volume = new Volume();
volume.setIssues(new ArrayList<>(0));
volume = applyInput(volume, input);
Journal journal = journalCrudService.readJournal(journalKey);
journal.getVolumes().add(volume);
hibernateTemplate.save(journal);
return volume;
}
use of org.ambraproject.rhino.identity.VolumeIdentifier in project rhino by PLOS.
the class VolumeCrudServiceImpl method applyInput.
private Volume applyInput(Volume volume, VolumeInputView input) {
String doi = input.getDoi();
if (doi != null) {
VolumeIdentifier volumeId = VolumeIdentifier.create(doi);
volume.setDoi(volumeId.getDoi().getName());
}
String displayName = input.getDisplayName();
if (displayName != null) {
volume.setDisplayName(displayName);
} else if (volume.getDisplayName() == null) {
volume.setDisplayName("");
}
return volume;
}
use of org.ambraproject.rhino.identity.VolumeIdentifier 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);
}
Aggregations