Class CustomerSegmentMemberImportBatchHandler

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

    @DataRouteByKey("customer")
    public class CustomerSegmentMemberImportBatchHandler
    extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
    Author:
    Vitalii Voronkov (vvoronkov)
    • Method Detail

      • canHandle

        public boolean canHandle​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
      • handle

        public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
      • mapBatchRecordsByEmail

        protected Map<String,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord> mapBatchRecordsByEmail​(List<com.broadleafcommerce.common.dataimport.messaging.BatchRecord> batchRecords,
                                                                                                                         List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions)
        Returns the BatchRecords mapped by email addresses.

        For each record, which email address is deemed duplicated in the file, an error BatchCompletionRecord will be created and added to erroredCompletions, and it will not appear in the returned result.

        Parameters:
        batchRecords - the list of the given BatchRecord from the original BatchRequest
        erroredCompletions - the list to which any errored completion records should be added
        Returns:
        the map of BatchRecord by email address
      • findEmailsWithExistingSegmentMembers

        protected Set<String> findEmailsWithExistingSegmentMembers​(com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo,
                                                                   String customerSegmentId,
                                                                   Set<String> requestedCustomerEmails)
        Finds emails with existing segment members.
        Parameters:
        readContextInfo - request context information around sandbox and multitenant state
        customerSegmentId - the id of the parent customer segment for which members are being imported
        requestedCustomerEmails - the set of customer email addresses requested for import
        Returns:
        the set of email addresses for which there is an existing segment member
      • determineNotFoundCustomerEmails

        protected Set<String> determineNotFoundCustomerEmails​(Set<String> batchRecordEmails,
                                                              List<Customer> customersFoundInDataStore)
        Determines the set of emails for which customers do not exist.
        Parameters:
        batchRecordEmails - the set of requested emails form the BatchRecord
        customersFoundInDataStore - the list of customers existing in data store
        Returns:
        the list of emails for which customers do not exist
      • validate

        protected List<org.apache.commons.lang3.tuple.Pair<Customer,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> validate​(Map<String,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord> batchRecordsByEmail,
                                                                                                                                                   List<Customer> customersFoundInDataStore,
                                                                                                                                                   List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions)
        This methods validates the given batch records, returning only those that are considered valid. For each record that is deemed invalid, an error BatchCompletionRecord will be created and added to erroredCompletions, and it will not appear in the returned result.

        Any BatchRecords with email addresses that reference customers which do not exist in customersFoundInDataStore will be considered invalid.

        Creates and returns a list of pairs of requested Customer and BatchRecord, for records that should be persisted.

        Parameters:
        batchRecordsByEmail - the map of BatchRecord by email address
        customersFoundInDataStore - the list of customers existing in the data store
        erroredCompletions - the list to which any errored completion records should be added
        Returns:
        a list of pairs of requested Customer and BatchRecord that passed validation
      • buildPersistenceRequests

        protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SegmentMember>> buildPersistenceRequests​(List<org.apache.commons.lang3.tuple.Pair<Customer,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedCustomerAndBatchRecordList,
                                                                                                                                CustomerSegment customerSegment,
                                                                                                                                List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> completions,
                                                                                                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo)
        Builds the list of PersistenceRequest for the SegmentMember.

        By default, this method will check if the parent segment already has a segment member in the data store for each requested email. If a segment member already exists, the corresponding batch record will eagerly be marked as completed successfully. A successful BatchCompletionRecord will be created for it and added to the completions list, and a persistence request will not be created for it.

        Parameters:
        requestedCustomerAndBatchRecordList - a list of pairs of requested Customer and BatchRecord
        customerSegment - the parent customer segment for which members are being imported
        completions - the list of batch record completions to add any early-completions to
        readContextInfo - request context information around sandbox and multitenant state
        Returns:
        the list of PersistenceRequest for the SegmentMember
      • buildPersistenceRequest

        protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SegmentMember> buildPersistenceRequest​(CustomerSegment customerSegment,
                                                                                                                         Customer customer,
                                                                                                                         com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
        Builds the PersistenceRequest for the SegmentMember.
        Parameters:
        customerSegment - the customer segment for segment member
        customer - the customer for segment member
        batchRecord - the record represents segment member from file
        Returns:
        the PersistenceRequest for the SegmentMember
      • buildSegmentMember

        protected SegmentMember buildSegmentMember​(CustomerSegment customerSegment,
                                                   Customer customer,
                                                   com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
        Creates instance of SegmentMember and populates with properties.
        Parameters:
        customerSegment - the customer segment for segment member
        customer - the customer for segment member
        batchRecord - the record represents segment member from file
        Returns:
        instance of SegmentMember with populated properties
      • resolveSegmentMemberId

        protected void resolveSegmentMemberId​(com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord,
                                              SegmentMember segmentMember)
        Resolves and sets the id for SegmentMember.
        Parameters:
        batchRecord - the record represents SegmentMember from file
        segmentMember - the SegmentMember for which the id should be resolved
      • persistPersistenceRequests

        protected void persistPersistenceRequests​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch,
                                                  List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SegmentMember>> segmentMembers,
                                                  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
        segmentMembers - a list of the segment member persistence requests
        allCompletions - the list to which the completion records should be added
      • getDataRouteKey

        public String getDataRouteKey()
      • processNotFoundCustomers

        protected void processNotFoundCustomers​(List<Customer> customersFoundInDataStore,
                                                Set<String> emails)
        This method OOB does nothing, but can be overridden to process not found customers
        Parameters:
        customersFoundInDataStore - the list of customers existing in the data store
        emails - the set of email addresses for which customers were not found
      • 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)