Class ArrayJsonPathMetadataContributor

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

public class ArrayJsonPathMetadataContributor extends Object implements MetadataContributor<String>
A metadata contributor that applies a given MetadataContributor to each object within a JSON array at a specified path. This enables extracting metadata from multiple objects within a JSON structure.

This class is useful for processing JSON arrays where each element represents an entity that requires metadata extraction.

Example JSON structure:

 {
   "authors": [
     { "name": "John Doe", "id": "123" },
     { "name": "Jane Smith", "id": "456" }
   ]
 }
 

If the pathToArray is set to "/authors", the contributor will be applied to each author object in the array.

Author:
Adamo Fapohunda (adamo.fapohunda at 4science.com)
  • Constructor Details

    • ArrayJsonPathMetadataContributor

      public ArrayJsonPathMetadataContributor()
  • Method Details

    • setMetadataFieldMapping

      public void setMetadataFieldMapping(MetadataFieldMapping<String,MetadataContributor<String>> rt)
      Unused by this implementation. This method is required by the MetadataContributor interface.
      Specified by:
      setMetadataFieldMapping in interface MetadataContributor<String>
      Parameters:
      rt - The metadata field mapping (not used in this implementation).
    • contributeMetadata

      public Collection<MetadatumDTO> contributeMetadata(String fullJson)
      Extracts metadata from each object in a JSON array located at pathToArray. The configured contributor is applied to each element of the array.
      Specified by:
      contributeMetadata in interface MetadataContributor<String>
      Parameters:
      fullJson - The JSON string containing the array.
      Returns:
      A collection of MetadatumDTO objects extracted from the array elements.
    • setContributor

      public void setContributor(MetadataContributor<String> contributor)
      Sets the metadata contributor that will be applied to each element of the JSON array.
      Parameters:
      contributor - The MetadataContributor responsible for processing each array element.
    • setPathToArray

      public void setPathToArray(String pathToArray)
      Sets the JSONPath to the array in the JSON structure.
      Parameters:
      pathToArray - A JSONPath expression indicating the location of the array.