Search in sources :

Example 1 with AssetNodesByDoi

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

Aggregations

AssetNodesByDoi (org.ambraproject.rhino.content.xml.AssetNodesByDoi)1 Doi (org.ambraproject.rhino.identity.Doi)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 Node (org.w3c.dom.Node)1