Class FieldTransformer

java.lang.Object
com.northconcepts.datapipeline.transform.Transformer
com.northconcepts.datapipeline.transform.FieldTransformer
Direct Known Subclasses:
BasicFieldTransformer

public abstract class FieldTransformer extends Transformer
See FieldPath for supported field name expressions.
  • Constructor Details

    • FieldTransformer

      public FieldTransformer(String... names)
    • FieldTransformer

      public FieldTransformer(String name)
    • FieldTransformer

      public FieldTransformer(Collection<String> names)
  • Method Details

    • getName

      public String getName()
      Returns the name of the field this transformer applies to if only one field was specified, otherwise null if multiple fields.
      See Also:
    • getNames

      public FieldPath[] getNames()
    • getNamesAsStrings

      public String[] getNamesAsStrings()
    • isThrowExceptionOnMissingField

      public boolean isThrowExceptionOnMissingField()
      Indicates if an exception should be thrown if the source field is missing (default to true).
    • setThrowExceptionOnMissingField

      public FieldTransformer setThrowExceptionOnMissingField(boolean throwExceptionOnMissingField)
      Indicates if an exception should be thrown if the source field is missing (default to true).
    • getCurrentRecord

      public Record getCurrentRecord()
      Returns the record being transformed, for use in transformField(Field).
    • getCurrentField

      public Field getCurrentField()
      Returns the field being transformed or null if the field last looked up is missing from the record.
    • setValueOnException

      public FieldTransformer setValueOnException(Object valueOnException)
      Sets the value a field receives when transforming it throws, instead of failing; null is a valid value.
    • getValueOnException

      public Object getValueOnException()
      Returns the value a field receives when transforming it throws, or null if none was set.
    • hasValueOnException

      public boolean hasValueOnException()
      Returns true if setValueOnException(Object) was called, even with null.
    • transform

      public boolean transform(Record record) throws Throwable
      Description copied from class: Transformer
      Applies this transformer to a record on its way through a TransformingReader or TransformingWriter.

      Contract for subclasses (see also docs/authoring/Transformer.md):

      • Mutate record in place as needed.
      • Return true to keep the record in the pipeline.
      • Return false to drop the record (the host routes it to a discard writer if one is configured, otherwise it disappears).
      • Throw to fail (or route to a discard writer, depending on host configuration).
      • Do not call incrementRecordCount() on the host endpoint; the host handles it.
      Specified by:
      transform in class Transformer
      Throws:
      Throwable
    • transformField

      protected abstract void transformField(Field field) throws Throwable
      Transforms the given field in place; called for each named field found in the record.
      Throws:
      Throwable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Transformer
      Adds this transformer's details to an exception raised by its host reader or writer; returns the same exception.
      Overrides:
      addExceptionProperties in class Transformer