use of org.ambraproject.rhino.model.article.AssetMetadata in project rhino by PLOS.
the class ArticleXml method disambiguateAssetNodes.
/**
* @param assetNodesMetadata metadata for at least two asset nodes with the same DOI and unequal content
* @return the metadata with the most non-empty fields
* @throws XmlContentException if two or more asset nodes have non-empty, inconsistent title or description
*/
@VisibleForTesting
static AssetMetadata disambiguateAssetNodes(Collection<AssetMetadata> assetNodesMetadata) {
// Find the node with the most substantial content
AssetMetadata bestNode = assetNodesMetadata.stream().min(ASSET_NODE_PREFERENCE).orElseThrow(() -> new IllegalArgumentException("Argument list must not be empty"));
// If any other nodes have non-empty fields that are inconsistent with bestNode, complain about ambiguity
Collection<AssetMetadata> ambiguous = assetNodesMetadata.stream().filter(node -> {
String title = node.getTitle();
boolean ambiguousTitle = !title.isEmpty() && !title.equals(bestNode.getTitle());
String description = node.getDescription();
boolean ambiguousDescription = !description.isEmpty() && !description.equals(bestNode.getDescription());
return ambiguousTitle || ambiguousDescription;
}).collect(Collectors.toList());
if (!ambiguous.isEmpty()) {
throw new XmlContentException(String.format("Ambiguous asset nodes: %s, %s", bestNode, ambiguous));
}
return bestNode;
}
use of org.ambraproject.rhino.model.article.AssetMetadata in project rhino by PLOS.
the class AssetXml method build.
@Override
public AssetMetadata build() throws XmlContentException {
String doi = assetId.getName();
String title = Strings.nullToEmpty(readString("child::label"));
Node captionNode = readNode("child::caption");
String description = Strings.nullToEmpty(getXmlFromNode(captionNode));
return new AssetMetadata(doi, title, description);
}
Aggregations