Class TranslationDynamicHeaderFieldMapping
java.lang.Object
com.broadleafcommerce.dataimport.processor.specification.translation.TranslationDynamicHeaderFieldMapping
- All Implemented Interfaces:
DynamicHeaderFieldMapping
public class TranslationDynamicHeaderFieldMapping
extends Object
implements DynamicHeaderFieldMapping
A dynamic header field mapping that supports mapping headers and fields matching a translation
pattern.
In order to successfully perform a mapping, this component requires the 'base' field/header being
mapped to be present in ImportSpecification.getHeaderFieldConfigsByRowType()
in
getParentSpecification()
. For example, to map the header 'Name TN:es', the specification
must contain a direct mapping for 'Name'.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
For reverse-mapping cases as are needed inmapFromFieldToHeader(String, String)
, we want the reverse mappings fromImportSpecification.getHeaderFieldConfigsByRowType()
to be computed exactly once and in a thread-safe way. -
Constructor Summary
ConstructorDescriptionTranslationDynamicHeaderFieldMapping
(ImportSpecification parentSpecification) -
Method Summary
Modifier and TypeMethodDescriptionprotected Pattern
By default this expects fields of the format 'translation::{some field}::{locale}'.protected Pattern
By default, this expects headers of the format '{some header} TN:{locale}'.protected ImportSpecification
Typically, the specification will be one instantiating and holding references to theDynamicHeaderFieldMapping
it needs.protected Pattern
protected Pattern
mapFromFieldToHeader
(String field, String rowType) Map the given field back to its corresponding header.mapFromHeaderToField
(String header, String rowType) Map the given header to its corresponding field.boolean
supportsMappingFieldToHeader
(String field, String rowType) Consumers should use this method to test whether this component supports mapping the given field back to a header.boolean
supportsMappingHeaderToField
(String header, String rowType) Consumers should use this method to test whether this component supports mapping the given header to a field.
-
Constructor Details
-
TranslationDynamicHeaderFieldMapping
-
-
Method Details
-
buildSupportedHeaderPattern
By default, this expects headers of the format '{some header} TN:{locale}'.- Returns:
- the pattern that should be used to identify translation headers
-
buildSupportedFieldPattern
By default this expects fields of the format 'translation::{some field}::{locale}'.- Returns:
- the pattern that should be used to identify translation fields
-
supportsMappingHeaderToField
Description copied from interface:DynamicHeaderFieldMapping
Consumers should use this method to test whether this component supports mapping the given header to a field.- Specified by:
supportsMappingHeaderToField
in interfaceDynamicHeaderFieldMapping
- Parameters:
header
- the header value to test mapping support forrowType
- the row type the mapping is being performed for- Returns:
- true if this component can support mapping the given header, false otherwise
-
supportsMappingFieldToHeader
Description copied from interface:DynamicHeaderFieldMapping
Consumers should use this method to test whether this component supports mapping the given field back to a header.- Specified by:
supportsMappingFieldToHeader
in interfaceDynamicHeaderFieldMapping
- Parameters:
field
- the field to test mapping support forrowType
- the row type the mapping is being performed for- Returns:
- true if this component can support mapping the given field, false otherwise
-
mapFromHeaderToField
Description copied from interface:DynamicHeaderFieldMapping
Map the given header to its corresponding field.Consumers should only invoke this method on a header which has been pre-validated via
DynamicHeaderFieldMapping.supportsMappingHeaderToField(String, String)
.- Specified by:
mapFromHeaderToField
in interfaceDynamicHeaderFieldMapping
- Parameters:
header
- the header value to map to a fieldrowType
- the row type the mapping is being performed for- Returns:
- the mapped field for the given header, or
null
if mapping could not successfully be completed
-
mapFromFieldToHeader
Description copied from interface:DynamicHeaderFieldMapping
Map the given field back to its corresponding header.Consumers should only invoke this method on a header which has been pre-validated via
DynamicHeaderFieldMapping.supportsMappingFieldToHeader(String, String)
.- Specified by:
mapFromFieldToHeader
in interfaceDynamicHeaderFieldMapping
- Parameters:
field
- the field to map back to a header. In most cases, this will likely just be a value that this component itself created inDynamicHeaderFieldMapping.mapFromHeaderToField(String, String)
.rowType
- the row type the mapping is being performed for- Returns:
- the mapped header for the given field, or
null
if mapping could not successfully be completed
-
getParentSpecification
Typically, the specification will be one instantiating and holding references to theDynamicHeaderFieldMapping
it needs. However, in this case, this component needs a back-reference to the parent so it can leverage other information from the specification. -
getSupportedHeaderPattern
-
getSupportedFieldPattern
-