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
Nested ClassesModifier and TypeClassDescriptionstatic classFor 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
ConstructorsConstructorDescriptionTranslationDynamicHeaderFieldMapping(ImportSpecification parentSpecification) -
Method Summary
Modifier and TypeMethodDescriptionprotected PatternBy default this expects fields of the format 'translation::{some field}::{locale}'.protected PatternBy default, this expects headers of the format '{some header} TN:{locale}'.protected ImportSpecificationTypically, the specification will be one instantiating and holding references to theDynamicHeaderFieldMappingit needs.protected Patternprotected PatternmapFromFieldToHeader(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.booleansupportsMappingFieldToHeader(String field, String rowType) Consumers should use this method to test whether this component supports mapping the given field back to a header.booleansupportsMappingHeaderToField(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:DynamicHeaderFieldMappingConsumers should use this method to test whether this component supports mapping the given header to a field.- Specified by:
supportsMappingHeaderToFieldin 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:DynamicHeaderFieldMappingConsumers should use this method to test whether this component supports mapping the given field back to a header.- Specified by:
supportsMappingFieldToHeaderin 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:DynamicHeaderFieldMappingMap 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:
mapFromHeaderToFieldin 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
nullif mapping could not successfully be completed
-
mapFromFieldToHeader
Description copied from interface:DynamicHeaderFieldMappingMap 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:
mapFromFieldToHeaderin 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
nullif mapping could not successfully be completed
-
getParentSpecification
Typically, the specification will be one instantiating and holding references to theDynamicHeaderFieldMappingit 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
-