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'.

  • Constructor Details

    • TranslationDynamicHeaderFieldMapping

      public TranslationDynamicHeaderFieldMapping(ImportSpecification parentSpecification)
  • Method Details

    • buildSupportedHeaderPattern

      protected Pattern 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

      protected Pattern 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

      public boolean supportsMappingHeaderToField(String header, String rowType)
      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 interface DynamicHeaderFieldMapping
      Parameters:
      header - the header value to test mapping support for
      rowType - the row type the mapping is being performed for
      Returns:
      true if this component can support mapping the given header, false otherwise
    • supportsMappingFieldToHeader

      public boolean supportsMappingFieldToHeader(String field, String rowType)
      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 interface DynamicHeaderFieldMapping
      Parameters:
      field - the field to test mapping support for
      rowType - the row type the mapping is being performed for
      Returns:
      true if this component can support mapping the given field, false otherwise
    • mapFromHeaderToField

      @Nullable public String mapFromHeaderToField(String header, String rowType)
      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 interface DynamicHeaderFieldMapping
      Parameters:
      header - the header value to map to a field
      rowType - 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

      @Nullable public String mapFromFieldToHeader(String field, String rowType)
      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 interface DynamicHeaderFieldMapping
      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 in DynamicHeaderFieldMapping.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

      protected ImportSpecification getParentSpecification()
      Typically, the specification will be one instantiating and holding references to the DynamicHeaderFieldMapping 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

      protected Pattern getSupportedHeaderPattern()
    • getSupportedFieldPattern

      protected Pattern getSupportedFieldPattern()