Search in sources :

Example 1 with IssueInputView

use of org.ambraproject.rhino.view.journal.IssueInputView in project rhino by PLOS.

the class IssueCrudController method update.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example #1: {\"displayName\": \"July\"}<br>" + "example #2: {\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\"}<br>" + "example #3: {\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> update(HttpServletRequest request, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi, @PathVariable("issueDoi") String issueDoi) throws IOException {
    // TODO: Validate journalKey and volumeDoiObj
    IssueIdentifier issueId = getIssueId(issueDoi);
    IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
    issueCrudService.update(issueId, input);
    return issueCrudService.serveIssue(issueId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}
Also used : IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IssueInputView

use of org.ambraproject.rhino.view.journal.IssueInputView in project rhino by PLOS.

the class IssueCrudServiceImpl method applyInput.

private Issue applyInput(Issue issue, IssueInputView input) {
    String issueDoi = input.getDoi();
    if (issueDoi != null) {
        IssueIdentifier issueId = IssueIdentifier.create(issueDoi);
        issue.setDoi(issueId.getDoi().getName());
    }
    String displayName = input.getDisplayName();
    if (displayName != null) {
        issue.setDisplayName(displayName);
    } else if (issue.getDisplayName() == null) {
        issue.setDisplayName("");
    }
    String imageDoi = input.getImageArticleDoi();
    if (imageDoi != null) {
        ArticleIdentifier imageArticleId = ArticleIdentifier.create(imageDoi);
        Article imageArticle = articleCrudService.readArticle(imageArticleId);
        issue.setImageArticle(imageArticle);
    } else {
        issue.setImageArticle(null);
    }
    List<String> inputArticleDois = input.getArticleOrder();
    if (inputArticleDois != null) {
        List<Article> inputArticles = inputArticleDois.stream().map(doi -> articleCrudService.readArticle(ArticleIdentifier.create(doi))).collect(Collectors.toList());
        issue.setArticles(inputArticles);
    }
    return issue;
}
Also used : Article(org.ambraproject.rhino.model.Article) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) Journal(org.ambraproject.rhino.model.Journal) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) IssueOutputView(org.ambraproject.rhino.view.journal.IssueOutputView) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) Issue(org.ambraproject.rhino.model.Issue) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) Volume(org.ambraproject.rhino.model.Volume) VolumeCrudService(org.ambraproject.rhino.service.VolumeCrudService) Query(org.hibernate.Query) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) IssueCrudService(org.ambraproject.rhino.service.IssueCrudService) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) Article(org.ambraproject.rhino.model.Article)

Example 3 with IssueInputView

use of org.ambraproject.rhino.view.journal.IssueInputView in project rhino by PLOS.

the class IssueCrudController method create.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "IssueInputView", value = "example: {\"doi\": \"10.1371/issue.pbio.v02.i07\", " + "\"displayName\": \"July\", " + "\"imageArticleDoi\": \"10.1371/image.pbio.v02.i07\", " + "\"articleOrder\": [\"10.1371/journal.pbio.0020213\", \"10.1371/journal.pbio.0020214\", " + "\"10.1371/journal.pbio.0020228\"]}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi) throws IOException {
    // TODO: Validate journalKey
    VolumeIdentifier volumeId = VolumeIdentifier.create(DoiEscaping.unescape(volumeDoi));
    IssueInputView input = readJsonFromRequest(request, IssueInputView.class);
    if (StringUtils.isBlank(input.getDoi())) {
        throw new RestClientException("issueUri required", HttpStatus.BAD_REQUEST);
    }
    Issue issue = issueCrudService.create(volumeId, input);
    return ServiceResponse.reportCreated(issueOutputViewFactory.getView(issue)).asJsonResponse(entityGson);
}
Also used : Issue(org.ambraproject.rhino.model.Issue) RestClientException(org.ambraproject.rhino.rest.RestClientException) VolumeIdentifier(org.ambraproject.rhino.identity.VolumeIdentifier) IssueInputView(org.ambraproject.rhino.view.journal.IssueInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IssueInputView (org.ambraproject.rhino.view.journal.IssueInputView)3 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)2 IssueIdentifier (org.ambraproject.rhino.identity.IssueIdentifier)2 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)2 Issue (org.ambraproject.rhino.model.Issue)2 RestClientException (org.ambraproject.rhino.rest.RestClientException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Preconditions (com.google.common.base.Preconditions)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 Article (org.ambraproject.rhino.model.Article)1 Journal (org.ambraproject.rhino.model.Journal)1 Volume (org.ambraproject.rhino.model.Volume)1 CacheableResponse (org.ambraproject.rhino.rest.response.CacheableResponse)1 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)1 IssueCrudService (org.ambraproject.rhino.service.IssueCrudService)1