Class CustomerImportBatchHandler
- java.lang.Object
-
- com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
-
- com.broadleafcommerce.customer.dataimport.CustomerImportBatchHandler
-
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("customer") public class CustomerImportBatchHandler extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
- Author:
- Vitalii Voronkov (vvoronkov)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CustomerImportBatchHandler.ImportTypes
-
Constructor Summary
Constructors Constructor Description CustomerImportBatchHandler(CustomerConverter customerConverter, CustomerService<Customer> customerService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer>
buildPersistenceRequest(String requestedCustomerEmail, org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord> requestedCustomerAndBatchRecord, Map<String,Customer> existingCustomersByEmailAddress)
Determines id, operation type and builds thePersistenceRequest
for theCustomer
.protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer>>
buildPersistenceRequests(Map<String,org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedCustomersByEmailAddress, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Builds the list ofPersistenceRequests
for the givenCustomers
.boolean
canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
protected Map<String,org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>>
convertBatchRecords(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions)
Converts all of the batch records in the batch request to customer.protected Optional<Customer>
convertToCustomer(com.broadleafcommerce.common.dataimport.messaging.BatchRecord customerRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
protected CustomerAddressColumnConverter
getCustomerAddressColumnConverter()
protected CustomerAddressService<CustomerAddress>
getCustomerAddressService()
protected CustomerConverter
getCustomerConverter()
protected CustomerService<Customer>
getCustomerService()
String
getDataRouteKey()
protected Map<String,Customer>
getExistingCustomers(Set<String> customerEmails, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected com.broadleafcommerce.common.dataimport.util.IdResolver
getIdResolver()
protected com.broadleafcommerce.common.dataimport.util.OperationResolver
getOperationResolver()
com.broadleafcommerce.common.dataimport.messaging.BatchCompletion
handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
protected void
persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer>> customerRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
Perform a persist of the parsed out domain specified asPersistenceRequest
s and adds persistence result toallCompletions
protected void
preFetchCustomerAddresses(Set<String> customerIdsToGetAddressesFor, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo, com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest)
To satisfy requirements ofCustomerAddressColumnConverter
, this method will identify and pre-fetch existing customer addresses for the specified customers and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCustomerAddressColumnConverter.BATCH_CONTEXT_PREFETCHED_CUSTOMER_ADDRESSES_BY_CUSTOMER_ID_MAP
.protected void
processAddressesForSuccessfullyProcessedCustomers(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
Once customer records are successfully created/updated, we will process any requested addresses for them.void
setCustomerAddressColumnConverter(CustomerAddressColumnConverter customerAddressColumnConverter)
void
setCustomerAddressService(CustomerAddressService<CustomerAddress> customerAddressService)
protected void
setIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
protected void
setOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)
-
Methods inherited from class com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
addFailedConversionCompletions, buildAndAddCompletionRecords, buildContextInfo, buildCreateContextInfo, buildNonValidationErrorCompletions, buildReadContextInfo, buildSuccessfulCompletionsForRequest, buildUpdateContextInfo, buildValidationErrorCompletions, failRecordAndDependentsEarly, generateAndAddCompletions, generateAndAddCompletions, generateAndAddValidationErrorCompletions, getCompletionError, getFormattedEmbeddedValidationErrorString, getFormattedValidationErrorString, getHydrator, persist, persist, removeAndReturnFieldErrorsUnderPath
-
-
-
-
Constructor Detail
-
CustomerImportBatchHandler
public CustomerImportBatchHandler(CustomerConverter customerConverter, CustomerService<Customer> customerService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
Method Detail
-
canHandle
public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
-
handle
@SuppressNotification("SINGLE_INDEX_REQUEST") public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
-
convertBatchRecords
protected Map<String,org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> convertBatchRecords(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions)
Converts all of the batch records in the batch request to customer.If conversion fails for a record, a
BatchCompletionRecord
will be created for it and added toerroredCompletions
, and it will not appear in the converted result.If multiple batch records are attempting to import the same customer email address, all but the first will be considered errored. A
BatchCompletionRecord
will be created for the duplicates and added toerroredCompletions
, and they will not appear in the converted result.- Parameters:
batch
- the original record batcherroredCompletions
- the list to which any errored completion records should be added- Returns:
- a map of the converted
Customer
and originalBatchRecord
pairs grouped by email address value
-
buildPersistenceRequests
protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer>> buildPersistenceRequests(Map<String,org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedCustomersByEmailAddress, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Builds the list ofPersistenceRequests
for the givenCustomers
.This method will query the data-store for existing customers to determine whether each item should be an update or a create.
-
buildPersistenceRequest
protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer> buildPersistenceRequest(String requestedCustomerEmail, org.apache.commons.lang3.tuple.Pair<Customer,com.broadleafcommerce.common.dataimport.messaging.BatchRecord> requestedCustomerAndBatchRecord, Map<String,Customer> existingCustomersByEmailAddress)
Determines id, operation type and builds thePersistenceRequest
for theCustomer
.
-
persistPersistenceRequests
protected void persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Customer>> customerRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
Perform a persist of the parsed out domain specified asPersistenceRequest
s and adds persistence result toallCompletions
- Parameters:
batch
- the original record batchcustomerRequests
- a list of the customer persistence requestsallCompletions
- the list to which the completion records should be added
-
processAddressesForSuccessfullyProcessedCustomers
protected void processAddressesForSuccessfullyProcessedCustomers(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
Once customer records are successfully created/updated, we will process any requested addresses for them.It is important that this processing happens after customer persistence for a few reasons:
- Managing an address for a failed customer would be invalid for obvious reasons, so confirming success before proceeding is important
- Certain address fields are sourced directly from the Customer itself, such as Full Name, Primary Phone Number, etc. However, since this specification allows for 'updates', it's possible the row in the import file is sparse and does not directly supply those values. Thus, we must wait until _after_ persistence to see the final state of the Customer and source values from it.
- Parameters:
request
- the original batch requestallCompletions
- these are assumed to exclusively contain customer records after all customer conversion/persistence is completed. The list may be mutated.
-
preFetchCustomerAddresses
protected void preFetchCustomerAddresses(Set<String> customerIdsToGetAddressesFor, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo, com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest)
To satisfy requirements ofCustomerAddressColumnConverter
, this method will identify and pre-fetch existing customer addresses for the specified customers and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCustomerAddressColumnConverter.BATCH_CONTEXT_PREFETCHED_CUSTOMER_ADDRESSES_BY_CUSTOMER_ID_MAP
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.- Parameters:
customerIdsToGetAddressesFor
- all customer ids to fetch addresses forreadContextInfo
- context info that can be used to fetch addressesbatchRequest
- the original batch request
-
getDataRouteKey
public String getDataRouteKey()
-
convertToCustomer
protected Optional<Customer> convertToCustomer(com.broadleafcommerce.common.dataimport.messaging.BatchRecord customerRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
-
getExistingCustomers
protected Map<String,Customer> getExistingCustomers(Set<String> customerEmails, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
getCustomerConverter
protected CustomerConverter getCustomerConverter()
-
getCustomerAddressColumnConverter
protected CustomerAddressColumnConverter getCustomerAddressColumnConverter()
-
setCustomerAddressColumnConverter
@Autowired public void setCustomerAddressColumnConverter(CustomerAddressColumnConverter customerAddressColumnConverter)
-
getCustomerService
protected CustomerService<Customer> getCustomerService()
-
getCustomerAddressService
protected CustomerAddressService<CustomerAddress> getCustomerAddressService()
-
setCustomerAddressService
@Autowired public void setCustomerAddressService(CustomerAddressService<CustomerAddress> customerAddressService)
-
getIdResolver
protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()
-
setIdResolver
protected void setIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
-
getOperationResolver
protected com.broadleafcommerce.common.dataimport.util.OperationResolver getOperationResolver()
-
setOperationResolver
protected void setOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)
-
-