Search in sources :

Example 1 with Volume

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);
}
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 Volume

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());
}
Also used : Volume(org.ambraproject.rhino.model.Volume) VolumeInputView(org.ambraproject.rhino.view.journal.VolumeInputView) Journal(org.ambraproject.rhino.model.Journal) Doi(org.ambraproject.rhino.identity.Doi) Test(org.testng.annotations.Test) BaseRhinoTest(org.ambraproject.rhino.BaseRhinoTest)

Example 3 with Volume

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

Example 4 with Volume

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

Example 5 with 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;
}
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)

Aggregations

Volume (org.ambraproject.rhino.model.Volume)11 RestClientException (org.ambraproject.rhino.rest.RestClientException)5 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)3 Journal (org.ambraproject.rhino.model.Journal)3 VolumeInputView (org.ambraproject.rhino.view.journal.VolumeInputView)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)2 Issue (org.ambraproject.rhino.model.Issue)2 Query (org.hibernate.Query)2 BaseRhinoTest (org.ambraproject.rhino.BaseRhinoTest)1 Doi (org.ambraproject.rhino.identity.Doi)1 IssueIdentifier (org.ambraproject.rhino.identity.IssueIdentifier)1 Comment (org.ambraproject.rhino.model.Comment)1 ResolvedDoiView (org.ambraproject.rhino.view.ResolvedDoiView)1 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)1 IssueOutputView (org.ambraproject.rhino.view.journal.IssueOutputView)1 VolumeOutputView (org.ambraproject.rhino.view.journal.VolumeOutputView)1 Session (org.hibernate.Session)1 Test (org.testng.annotations.Test)1