Search in sources :

Example 16 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException 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 17 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException 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 18 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.

the class ArticlePackageBuilder method findAssetType.

private static AssetType findAssetType(AssetNodesByDoi assetNodeMap, ManifestXml.Asset asset) {
    if (asset.getAssetTagName().equals(ManifestXml.AssetTagName.ARTICLE)) {
        return AssetType.ARTICLE;
    }
    Doi assetIdentity = Doi.create(asset.getUri());
    if (!assetNodeMap.getDois().contains(assetIdentity)) {
        if (asset.isStrikingImage()) {
            return AssetType.STANDALONE_STRIKING_IMAGE;
        } else {
            throw new RestClientException("Asset not mentioned in manuscript: " + asset.getUri(), HttpStatus.BAD_REQUEST);
        }
    }
    List<Node> nodes = assetNodeMap.getNodes(assetIdentity);
    AssetType identifiedType = null;
    for (Node node : nodes) {
        String nodeName = node.getNodeName();
        AssetType assetType = getByXmlNodeName(nodeName);
        if (assetType != null) {
            if (identifiedType == null) {
                identifiedType = assetType;
            } else if (!identifiedType.equals(assetType)) {
                String message = String.format("Ambiguous nodes: %s, %s", identifiedType, assetType);
                throw new RestClientException(message, HttpStatus.BAD_REQUEST);
            }
        }
    }
    if (identifiedType == null) {
        throw new RestClientException("Type not recognized", HttpStatus.BAD_REQUEST);
    }
    return identifiedType;
}
Also used : Node(org.w3c.dom.Node) RestClientException(org.ambraproject.rhino.rest.RestClientException) AssetNodesByDoi(org.ambraproject.rhino.content.xml.AssetNodesByDoi) Doi(org.ambraproject.rhino.identity.Doi)

Example 19 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException in project rhino by PLOS.

the class ArticleListCrudController method create.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/lists", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "ListInputView", value = "example: {\"journal\": \"PLoSONE\", \"type\": \"admin\", \"key\": \"plosone_news\", " + "\"title\": \"test\", \"articleDois\": [\"10.1371/journal.pone.0095668\"]}")
public ResponseEntity<?> create(HttpServletRequest request) throws IOException {
    final ListInputView inputView;
    try {
        inputView = readJsonFromRequest(request, ListInputView.class);
    } catch (ListInputView.PartialIdentityException e) {
        throw complainAboutRequiredListIdentity(e);
    }
    Optional<ArticleListIdentity> identity = inputView.getIdentity();
    if (!identity.isPresent()) {
        throw complainAboutRequiredListIdentity(null);
    }
    Optional<String> title = inputView.getTitle();
    if (!title.isPresent()) {
        throw new RestClientException("title required", HttpStatus.BAD_REQUEST);
    }
    Optional<ImmutableSet<ArticleIdentifier>> articleDois = inputView.getArticleIds();
    if (!articleDois.isPresent()) {
        throw new RestClientException("articleDois required", HttpStatus.BAD_REQUEST);
    }
    ArticleListView listView = articleListCrudService.create(identity.get(), title.get(), articleDois.get());
    return ServiceResponse.reportCreated(listView).asJsonResponse(entityGson);
}
Also used : ArticleListIdentity(org.ambraproject.rhino.identity.ArticleListIdentity) ImmutableSet(com.google.common.collect.ImmutableSet) ListInputView(org.ambraproject.rhino.view.article.ListInputView) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleListView(org.ambraproject.rhino.view.journal.ArticleListView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with RestClientException

use of org.ambraproject.rhino.rest.RestClientException 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)

Aggregations

RestClientException (org.ambraproject.rhino.rest.RestClientException)21 Transactional (org.springframework.transaction.annotation.Transactional)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Volume (org.ambraproject.rhino.model.Volume)5 Issue (org.ambraproject.rhino.model.Issue)4 Journal (org.ambraproject.rhino.model.Journal)4 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)3 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Article (org.ambraproject.rhino.model.Article)3 Comment (org.ambraproject.rhino.model.Comment)3 Query (org.hibernate.Query)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Doi (org.ambraproject.rhino.identity.Doi)2 VolumeIdentifier (org.ambraproject.rhino.identity.VolumeIdentifier)2 ArticleList (org.ambraproject.rhino.model.ArticleList)2 Session (org.hibernate.Session)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1