Class CustomerImportBatchHandler

  • All Implemented Interfaces:
    com.broadleafcommerce.common.dataimport.ImportBatchHandler

    @DataRouteByKey("customer")
    public class CustomerImportBatchHandler
    extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
    Author:
    Vitalii Voronkov (vvoronkov)
    • 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 the PersistenceRequest for the Customer.
      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 of PersistenceRequests for the given Customers.
      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 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 as PersistenceRequests and adds persistence result to allCompletions
      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, generateAndAddCompletions, generateAndAddCompletions, generateAndAddValidationErrorCompletions, getCompletionError, getFormattedEmbeddedValidationErrorString, getFormattedValidationErrorString, getHydrator, 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 to erroredCompletions, 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 to erroredCompletions, and they will not appear in the converted result.

        Parameters:
        batch - the original record batch
        erroredCompletions - the list to which any errored completion records should be added
        Returns:
        a map of the converted Customer and original BatchRecord 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 of PersistenceRequests for the given Customers.

        This method will query the data-store for existing customers to determine whether each item should be an update or a create.

        Parameters:
        requestedCustomersByEmailAddress - the map of Customer and BatchRecord pairs grouped customer email address
        context - request context information around sandbox and multitenant state
        Returns:
        the list of PersistenceRequest for the Customer
      • 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 the PersistenceRequest for the Customer.
        Parameters:
        requestedCustomerEmail - the email address of requested customer
        requestedCustomerAndBatchRecord - the pair of requested Customer and BatchRecord
        existingCustomersByEmailAddress - the map of Customer grouped by email address
        Returns:
        the PersistenceRequest for the Customer
      • 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 as PersistenceRequests and adds persistence result to allCompletions
        Parameters:
        batch - the original record batch
        customerRequests - a list of the customer persistence requests
        allCompletions - the list to which the completion records should be added
      • 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)
      • 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)