Search in sources :

Example 6 with Volume

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

Example 7 with Volume

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);
}
Also used : Comment(org.ambraproject.rhino.model.Comment) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) Journal(org.ambraproject.rhino.model.Journal)

Example 8 with Volume

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

Example 9 with Volume

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

Example 10 with 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;
}
Also used : Query(org.hibernate.Query) Volume(org.ambraproject.rhino.model.Volume) Session(org.hibernate.Session)

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