Class CustomerAddressColumnConverter

java.lang.Object
com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>>
com.broadleafcommerce.customer.dataimport.converter.CustomerAddressColumnConverter

public class CustomerAddressColumnConverter extends com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>>
Component to parse and convert customer address related columns from a customer row in CustomerImportBatchHandler.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched customer addresses by customer ID.

    Fields inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter

    COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomerAddressColumnConverter(com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>
    convert(Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    protected com.broadleafcommerce.data.tracking.core.type.OperationType
    determineOperationType(@NonNull CustomerAddress customerAddress, boolean addressAlreadyExistsInDatastore, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord customerRecord)
    Determine the effective operation type for the given customer address instance and customer record.
    protected void
    forceInitializeFields(@NonNull CustomerAddress customerAddress, @NonNull Map<String,String> addressColumns, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull Customer parent, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    Certain fields should never be honored from what is provided in the row and instead should be auto-set by the system.
    protected List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>
    generateConversionResponsesForUnsettingExistingDefaultAddresses(CustomerAddress newDefault, String existingDefaultShippingAddressId, String existingDefaultBillingAddressId, List<CustomerAddress> prefetchedCustomerAddresses)
    For this import, the provided address is always set as the new default shipping and billing address.
    protected String
     
    protected Map<String,String>
     
    getExistingCustomerAddressesForCustomer(String customerId, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    We expect the CustomerImportBatchHandler to have pre-fetched customer addresses for the given customer and placed them into the BatchRequest.BatchContext.getAdditionalContextMap().
    protected com.broadleafcommerce.common.dataimport.util.IdResolver
     
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>
    initializeData(@NonNull CustomerAddress customerAddress, @NonNull Map<String,String> addressColumns, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull Customer parent, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    Initialize the data from the address columns onto the address instance and set additional data as needed.
    protected org.springframework.data.util.Pair<Boolean,CustomerAddress>
    instantiateOrGetPrefetchedAddress(Map<String,String> addressColumns, Customer parent, List<CustomerAddress> prefetchedCustomerAddresses)
    By default, address name is used as the unique identifier for determining whether the provided address information should result in the creation of a new address, or if an existing address should be updated.
    protected String
    Validates the given address columns and returns an error if validation failed.

    Methods inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter

    extractSpecialColumns

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BATCH_CONTEXT_PREFETCHED_CUSTOMER_ADDRESSES_BY_CUSTOMER_ID_MAP

      public static final String BATCH_CONTEXT_PREFETCHED_CUSTOMER_ADDRESSES_BY_CUSTOMER_ID_MAP
      In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched customer addresses by customer ID.
      See Also:
  • Constructor Details

    • CustomerAddressColumnConverter

      public CustomerAddressColumnConverter(com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
  • Method Details

    • canConvert

      public boolean canConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Specified by:
      canConvert in class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>>
    • getAddressColumnPrefix

      protected String getAddressColumnPrefix()
    • convert

      public List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>> convert(@Nullable Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Specified by:
      convert in class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>>>
      Parameters:
      parent - this is expected to be the parent Customer instance in its final state (with all fields present and updated, since they will be used to source values for the address)
      record - the record which should be converted
      context - the batch context, which may provide supporting information
      Returns:
      one or more conversion responses describing the result of the conversion. Typically, multiple responses are only returned if the 'default' address was changed and the previous default needs to be unset. In such cases, there will be additional conversion response(s) returned
    • getExistingCustomerAddressesForCustomer

      protected List<CustomerAddress> getExistingCustomerAddressesForCustomer(String customerId, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      We expect the CustomerImportBatchHandler to have pre-fetched customer addresses for the given customer and placed them into the BatchRequest.BatchContext.getAdditionalContextMap(). This obtains the pre-fetched addresses for the specified customer.
      Parameters:
      customerId - the customer to get the pre-fetched addresses for
      context - the batch context containing pre-fetched data
      Returns:
      the pre-fetched addresses for the specified customer
    • getAddressColumnsStrippedOfPrefix

      protected Map<String,String> getAddressColumnsStrippedOfPrefix(Map<String,String> customerRow)
    • validateGivenAddressColumnsAndReturnError

      @Nullable protected String validateGivenAddressColumnsAndReturnError(Map<String,String> addressColumns)
      Validates the given address columns and returns an error if validation failed.
      Parameters:
      addressColumns - the address-specific columns from the row, already stripped of any address-specific prefix (ex: getAddressColumnPrefix())
      Returns:
      an error if validation failed, null if validation passed
    • instantiateOrGetPrefetchedAddress

      protected org.springframework.data.util.Pair<Boolean,CustomerAddress> instantiateOrGetPrefetchedAddress(Map<String,String> addressColumns, Customer parent, List<CustomerAddress> prefetchedCustomerAddresses)
      By default, address name is used as the unique identifier for determining whether the provided address information should result in the creation of a new address, or if an existing address should be updated.

      If an address with a matching name is present in prefetchedCustomerAddresses, it will be used as-is.

      If an address is not present by name in prefetchedCustomerAddresses, it will be newly instantiated.

      Parameters:
      addressColumns - the provided address columns in the customer row, already stripped of any special prefix
      parent - the customer for which this address is being resolved
      prefetchedCustomerAddresses - the existing addresses in the datastore for the provided parent customer
      Returns:
      a Pair containing a boolean describing whether the address was found in the pre-fetched instances, as well as the address instance itself
    • determineOperationType

      protected com.broadleafcommerce.data.tracking.core.type.OperationType determineOperationType(@NonNull @NonNull CustomerAddress customerAddress, boolean addressAlreadyExistsInDatastore, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord customerRecord)
      Determine the effective operation type for the given customer address instance and customer record. This can help inform decisions on how to instantiate/map fields.

      By default, this is entirely determined by whether the address was found to already exist in the datastore.

      Parameters:
      customerAddress - the resolved customer address instance
      addressAlreadyExistsInDatastore - whether the address was determined to already exist in the datastore. See instantiateOrGetPrefetchedAddress(Map, Customer, List)
      customerRecord - the original customer batch record
      Returns:
      the effective operation type for the given address instance
    • initializeData

      protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress> initializeData(@NonNull @NonNull CustomerAddress customerAddress, @NonNull @NonNull Map<String,String> addressColumns, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull @NonNull Customer parent, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Initialize the data from the address columns onto the address instance and set additional data as needed.
      Parameters:
      customerAddress - the target instance on which to initialize data
      addressColumns - the address columns from the row, already stripped of any special prefix
      operationType - the determined operation type that needs to be performed for this address
      parent - the pre-converted parent customer instance for this address
      context - the batch context
      Returns:
      a ConversionUtils.ConversionResponse containing the updated instance
    • forceInitializeFields

      protected void forceInitializeFields(@NonNull @NonNull CustomerAddress customerAddress, @NonNull @NonNull Map<String,String> addressColumns, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull @NonNull Customer parent, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Certain fields should never be honored from what is provided in the row and instead should be auto-set by the system. This method sets such values.
      Parameters:
      customerAddress - the address to set fields on
      addressColumns - the address columns from the row, already stripped of any special prefix
      operationType - the operation type that should be performed for this address
      parent - the parent customer for the address
      context - the original batch context
    • generateConversionResponsesForUnsettingExistingDefaultAddresses

      protected List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CustomerAddress>> generateConversionResponsesForUnsettingExistingDefaultAddresses(CustomerAddress newDefault, @Nullable String existingDefaultShippingAddressId, @Nullable String existingDefaultBillingAddressId, List<CustomerAddress> prefetchedCustomerAddresses)
      For this import, the provided address is always set as the new default shipping and billing address. This means any existing address(es) set as the default need to be unset as default.

      This method produces conversion responses to unset those defaults as needed.

      Parameters:
      newDefault - the 'new' default address which was provided in the import
      existingDefaultShippingAddressId - the ID of the existing default shipping address (if it exists)
      existingDefaultBillingAddressId - the ID of the existing default billing address (if it exists)
      prefetchedCustomerAddresses - the list of all existing customer addresses, which should contain the existing defaults matching the given IDs
      Returns:
      a list of conversion responses containing updated instances to 'unset' as default. If it was determined that there is no need to unset any existing defaults, this list will be empty.
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
    • getIdResolver

      protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()