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