Search in sources :

Example 1 with VolumeIdentifier

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);
}
Also used : Volume(org.ambraproject.rhino.model.Volume) VolumeInputView(org.ambraproject.rhino.view.journal.VolumeInputView) VolumeOutputView(org.ambraproject.rhino.view.journal.VolumeOutputView) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with VolumeIdentifier

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());
}
Also used : VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with VolumeIdentifier

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;
}
Also used : Volume(org.ambraproject.rhino.model.Volume) RestClientException(org.ambraproject.rhino.rest.RestClientException) Journal(org.ambraproject.rhino.model.Journal) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier)

Example 4 with VolumeIdentifier

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;
}
Also used : VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier)

Example 5 with VolumeIdentifier

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);
}
Also used : IssueOutputView(org.ambraproject.rhino.view.journal.IssueOutputView) Volume(org.ambraproject.rhino.model.Volume) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Volume (org.ambraproject.rhino.model.Volume)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)2 RestClientException (org.ambraproject.rhino.rest.RestClientException)2 Issue (org.ambraproject.rhino.model.Issue)1 Journal (org.ambraproject.rhino.model.Journal)1 IssueInputView (org.ambraproject.rhino.view.journal.IssueInputView)1 IssueOutputView (org.ambraproject.rhino.view.journal.IssueOutputView)1 VolumeInputView (org.ambraproject.rhino.view.journal.VolumeInputView)1 VolumeOutputView (org.ambraproject.rhino.view.journal.VolumeOutputView)1