Search in sources :

Example 1 with IssueIdentifier

use of org.ambraproject.rhino.identity.IssueIdentifier 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 2 with IssueIdentifier

use of org.ambraproject.rhino.identity.IssueIdentifier 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 3 with IssueIdentifier

use of org.ambraproject.rhino.identity.IssueIdentifier 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 4 with IssueIdentifier

use of org.ambraproject.rhino.identity.IssueIdentifier in project rhino by PLOS.

the class IssueCrudController method delete.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.DELETE)
public ResponseEntity<Object> delete(HttpServletRequest request, @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi, @PathVariable("issueDoi") String issueDoi) throws IOException {
    // TODO: Validate journalKey and volumeDoiObj
    IssueIdentifier issueId = getIssueId(issueDoi);
    issueCrudService.delete(issueId);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with IssueIdentifier

use of org.ambraproject.rhino.identity.IssueIdentifier in project rhino by PLOS.

the class IssueCrudController method readArticlesInIssue.

@Transactional(readOnly = true)
@RequestMapping(value = "/issues/{issueDoi:.+}/contents", method = RequestMethod.GET)
public ResponseEntity<?> readArticlesInIssue(@PathVariable("issueDoi") String issueDoi) throws IOException {
    IssueIdentifier issueId = getIssueId(issueDoi);
    Issue issue = issueCrudService.readIssue(issueId);
    List<ArticleRevisionView> views = issueOutputViewFactory.getIssueArticlesView(issue);
    return ServiceResponse.serveView(views).asJsonResponse(entityGson);
}
Also used : ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView) Issue(org.ambraproject.rhino.model.Issue) IssueIdentifier(org.ambraproject.rhino.identity.IssueIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IssueIdentifier (org.ambraproject.rhino.identity.IssueIdentifier)5 Issue (org.ambraproject.rhino.model.Issue)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Volume (org.ambraproject.rhino.model.Volume)2 RestClientException (org.ambraproject.rhino.rest.RestClientException)2 IssueInputView (org.ambraproject.rhino.view.journal.IssueInputView)2 Preconditions (com.google.common.base.Preconditions)1 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)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 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)1 Article (org.ambraproject.rhino.model.Article)1 Journal (org.ambraproject.rhino.model.Journal)1 CacheableResponse (org.ambraproject.rhino.rest.response.CacheableResponse)1 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)1 IssueCrudService (org.ambraproject.rhino.service.IssueCrudService)1