Class ConditionEqualJsonPathMetadataContributor

java.lang.Object
org.dspace.importer.external.metadatamapping.contributor.SimpleJsonPathMetadataContributor
org.dspace.importer.external.metadatamapping.contributor.ConditionEqualJsonPathMetadataContributor
All Implemented Interfaces:
MetadataContributor<String>

public class ConditionEqualJsonPathMetadataContributor extends SimpleJsonPathMetadataContributor
A metadata contributor that extracts a value from JSON using a JsonPathMetadataProcessor and compares it against a predefined right operand. If the extracted value matches the right operand, the specified SimpleJsonPathMetadataContributor is used to extract additional metadata. Otherwise, an empty collection is returned. This class extends SimpleJsonPathMetadataContributor and allows conditional metadata extraction based on JSON path processing.
Author:
Adamo Fapohunda (adamo.fapohunda at 4science.com)
  • Constructor Details

    • ConditionEqualJsonPathMetadataContributor

      public ConditionEqualJsonPathMetadataContributor()
  • Method Details

    • contributeMetadata

      public Collection<MetadatumDTO> contributeMetadata(String json)
      Extracts metadata from the provided JSON string. The extraction process follows these steps:
      1. Uses JsonPathMetadataProcessor to extract a value from the JSON.
      2. Compares the extracted value with the predefined right operand.
      3. If they match, the SimpleJsonPathMetadataContributor is used to extract and return metadata.
      4. If they do not match, an empty collection is returned.
      Specified by:
      contributeMetadata in interface MetadataContributor<String>
      Overrides:
      contributeMetadata in class SimpleJsonPathMetadataContributor
      Parameters:
      json - The JSON string to process.
      Returns:
      A collection of MetadatumDTO if the condition is met; otherwise, an empty collection.
    • setLeftOperandProcessor

      public void setLeftOperandProcessor(JsonPathMetadataProcessor leftOperandProcessor)
      Sets the JsonPathMetadataProcessor responsible for extracting the left operand value from the JSON.
      Parameters:
      leftOperandProcessor - The JSON path processor used for extraction.
    • setRightOperand

      public void setRightOperand(String rightOperand)
      Sets the right operand value that the extracted JSON value must match for metadata extraction to proceed.
      Parameters:
      rightOperand - The expected value to compare against.
    • setMetadatumContributor

      public void setMetadatumContributor(SimpleJsonPathMetadataContributor metadatumContributor)
      Sets the SimpleJsonPathMetadataContributor responsible for extracting metadata if the condition is met.
      Parameters:
      metadatumContributor - The metadata contributor to use upon a successful match.