use of org.ambraproject.rhino.content.xml.AssetNodesByDoi 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;
}
Aggregations