Search in sources :

Example 1 with AssetMetadata

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;
}
Also used : LinkedListMultimap(com.google.common.collect.LinkedListMultimap) Logger(org.slf4j.Logger) ListMultimap(com.google.common.collect.ListMultimap) Collection(java.util.Collection) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) LoggerFactory(org.slf4j.LoggerFactory) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Strings(com.google.common.base.Strings) List(java.util.List) Lists(com.google.common.collect.Lists) AssetMetadata(org.ambraproject.rhino.model.article.AssetMetadata) ImmutableList(com.google.common.collect.ImmutableList) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) LocalDate(java.time.LocalDate) Map(java.util.Map) Preconditions(com.google.common.base.Preconditions) Doi(org.ambraproject.rhino.identity.Doi) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ArticleMetadata(org.ambraproject.rhino.model.article.ArticleMetadata) Comparator(java.util.Comparator) AssetMetadata(org.ambraproject.rhino.model.article.AssetMetadata) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with AssetMetadata

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);
}
Also used : Node(org.w3c.dom.Node) AssetMetadata(org.ambraproject.rhino.model.article.AssetMetadata)

Aggregations

AssetMetadata (org.ambraproject.rhino.model.article.AssetMetadata)2 Node (org.w3c.dom.Node)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 LocalDate (java.time.LocalDate)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 Doi (org.ambraproject.rhino.identity.Doi)1 ArticleMetadata (org.ambraproject.rhino.model.article.ArticleMetadata)1 RelatedArticleLink (org.ambraproject.rhino.model.article.RelatedArticleLink)1