Class AbstractRowConverter<P>
java.lang.Object
com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<P>
- Type Parameters:
P
- the expected result of the conversion process
Simple starting point for a 'converter' that can convert a
BatchRecord.getRow()
into a
meaningful entity instance.- Author:
- Kelly Tisdell (ktisdell)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
This arbitrarily indicates that a particular column requires special treatment or processing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
canConvert
(BatchRecord record, BatchRequest.BatchContext context) Indicates if this converter can parse the provided record into an entity.abstract P
convert
(Object parent, BatchRecord record, BatchRequest.BatchContext context) Converts the provided record into the required result(s).extractSpecialColumns
(@NonNull Map<String, String> mutableRow, BatchRequest.BatchContext context) Used to remove columns that require special processing, or that cannot be set using reflection.
-
Field Details
-
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.
-
-
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 aRuntimeException
. Typically, implementors will evaluate theBatchRecord.getRow()
headers and data to determine support.- Parameters:
record
- the record for which this component's conversion support should be checkedcontext
- 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 convertercontext
- the batch context, which may provide supporting information- Returns:
- the conversion result. In most cases, this should either be a
ConversionUtils.ConversionResponse
or aList
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 containCOMPLEX_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 outputcontext
- the batch context- Returns:
- a non-null map containing zero or more columns that require special processing
-