use of org.ambraproject.rhino.model.Volume 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.model.Volume in project rhino by PLOS.
the class VolumeCrudServiceTest method testCreate.
@Test(enabled = false)
public void testCreate() {
Doi volumeId = Doi.create("10.1371/volume.pmed.v05");
String displayName = "volumeDisplay";
String json = String.format("{\"volumeUri\": \"%s\", \"displayName\": \"%s\"}", volumeId.getName(), displayName);
VolumeInputView input = entityGson.fromJson(json, VolumeInputView.class);
Journal testJournal = createTestJournal();
volumeCrudService.create(testJournal.getJournalKey(), input);
testJournal = getTestJournal();
List<Volume> testJournalVolumes = testJournal.getVolumes();
assertFalse(testJournalVolumes.isEmpty());
}
use of org.ambraproject.rhino.model.Volume 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.model.Volume in project rhino by PLOS.
the class VolumeCrudServiceImpl method update.
@Override
public Volume update(VolumeIdentifier volumeId, VolumeInputView input) {
Preconditions.checkNotNull(input);
Volume volume = readVolume(volumeId);
volume = applyInput(volume, input);
hibernateTemplate.update(volume);
return volume;
}
use of org.ambraproject.rhino.model.Volume 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;
}
Aggregations