Class AbstractRowConverter<P>

java.lang.Object
com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<P>
Type Parameters:
P - the expected result of the conversion process

public abstract class AbstractRowConverter<P> extends Object
Simple starting point for a 'converter' that can convert a BatchRecord.getRow() into a meaningful entity instance.
Author:
Kelly Tisdell (ktisdell)
  • Field Details

    • COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER

      public static final String COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER
      This arbitrarily indicates that a particular column requires special treatment or processing. For example, category::1 might indicate that a product row contains a column with a category identifier.

      Implementations aren't required to use this - it's just a sensible default.

      See Also:
  • Constructor Details

    • AbstractRowConverter

      public AbstractRowConverter()
  • Method Details

    • canConvert

      public abstract boolean canConvert(@NonNull BatchRecord record, @Nullable BatchRequest.BatchContext context)
      Indicates if this converter can parse the provided record into an entity. This should not normally throw a RuntimeException. Typically, implementors will evaluate the BatchRecord.getRow() headers and data to determine support.
      Parameters:
      record - the record for which this component's conversion support should be checked
      context - the batch context, which may provide supporting information
      Returns:
      whether this component can properly parse the provided record.
    • convert

      @NonNull public abstract P convert(@Nullable Object parent, @NonNull BatchRecord record, @Nullable BatchRequest.BatchContext context)
      Converts the provided record into the required result(s).
      Parameters:
      parent - (optional) in some cases, the conversion may be for a 'dependent' record. Conversion of such records can require access to a pre-converted instance of a parent record, which is expected to be supplied here.
      record - the record which should be converter
      context - the batch context, which may provide supporting information
      Returns:
      the conversion result. In most cases, this should either be a ConversionUtils.ConversionResponse or a List of them, but there is no hard constraint imposed by this component
    • extractSpecialColumns

      protected Map<String,String> extractSpecialColumns(@NonNull @NonNull Map<String,String> mutableRow, @Nullable BatchRequest.BatchContext context)
      Used to remove columns that require special processing, or that cannot be set using reflection. By default, this method only removes headers that contain COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER (i.e. "::"). Subclasses may wish to use and/or override this method to augment this functionality for other fields that don't contain "::", for example.
      Parameters:
      mutableRow - the existing row from which special fields will be removed and copied to the output
      context - the batch context
      Returns:
      a non-null map containing zero or more columns that require special processing