Class RegexReplacingJsonPathMetadataProcessor

java.lang.Object
org.dspace.importer.external.metadatamapping.contributor.AbstractJsonPathMetadataProcessor
org.dspace.importer.external.metadatamapping.contributor.RegexReplacingJsonPathMetadataProcessor
All Implemented Interfaces:
JsonPathMetadataProcessor

public class RegexReplacingJsonPathMetadataProcessor extends AbstractJsonPathMetadataProcessor
A generic JSON metadata processor that extracts a string value from a JSON node using a specified JSONPath and applies a regex-based replacement. This class extends AbstractJsonPathMetadataProcessor and provides functionality to replace a matching regex pattern in the extracted text with a given replacement value.
Author:
Adamo Fapohunda (adamo.fapohunda at 4science.com)
See Also:
  • Constructor Details

    • RegexReplacingJsonPathMetadataProcessor

      public RegexReplacingJsonPathMetadataProcessor()
  • Method Details

    • getStringValue

      protected String getStringValue(com.fasterxml.jackson.databind.JsonNode node)
      Extracts the string value from the given JSON node and applies regex-based replacement.
      Specified by:
      getStringValue in class AbstractJsonPathMetadataProcessor
      Parameters:
      node - The JSON node from which to extract the value.
      Returns:
      The transformed string after applying the regex replacement.
      Throws:
      IllegalArgumentException - if the node is null or does not contain a text value.
    • getLogger

      protected org.apache.logging.log4j.Logger getLogger()
      Provides the logger instance for error handling.
      Specified by:
      getLogger in class AbstractJsonPathMetadataProcessor
      Returns:
      A Logger instance.
    • getPath

      protected String getPath()
      Returns the JSONPath expression used to locate the value in the JSON structure.
      Specified by:
      getPath in class AbstractJsonPathMetadataProcessor
      Returns:
      The JSONPath string.
    • setPath

      public void setPath(String path)
      Sets the JSONPath expression used for extraction.
      Parameters:
      path - The JSONPath string.
    • setRegexPattern

      public void setRegexPattern(String regexPattern)
      Sets the regex pattern to be replaced in the extracted string.
      Parameters:
      regexPattern - The regular expression pattern.
    • setReplacement

      public void setReplacement(String replacement)
      Sets the replacement string that will replace occurrences of the regex pattern.
      Parameters:
      replacement - The replacement string.