Class CustomerSegmentMemberImportBatchHandler
- java.lang.Object
-
- com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
-
- com.broadleafcommerce.customer.dataimport.CustomerSegmentMemberImportBatchHandler
-
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("customer") public class CustomerSegmentMemberImportBatchHandler extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler- Author:
- Vitalii Voronkov (vvoronkov)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCustomerSegmentMemberImportBatchHandler.ImportTypes
-
Constructor Summary
Constructors Constructor Description CustomerSegmentMemberImportBatchHandler(CustomerService<Customer> customerService, CustomerSegmentService<CustomerSegment> customerSegmentService, SegmentMemberService<SegmentMember,CustomerSegment> segmentMemberService, 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<SegmentMember>buildPersistenceRequest(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)Builds thePersistenceRequestfor theSegmentMember.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 ofPersistenceRequestfor theSegmentMember.protected SegmentMemberbuildSegmentMember(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)Creates instance ofSegmentMemberand populates with properties.booleancanHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)protected Set<String>determineNotFoundCustomerEmails(Set<String> batchRecordEmails, List<Customer> customersFoundInDataStore)Determines the set of emails for which customers do not exist.protected Set<String>findEmailsWithExistingSegmentMembers(com.broadleafcommerce.data.tracking.core.context.ContextInfo readContextInfo, String customerSegmentId, Set<String> requestedCustomerEmails)Finds emails with existing segment members.protected CustomerSegmentService<CustomerSegment>getCustomerSegmentService()protected CustomerService<Customer>getCustomerService()StringgetDataRouteKey()protected com.broadleafcommerce.common.dataimport.util.IdResolvergetIdResolver()protected com.broadleafcommerce.common.dataimport.util.OperationResolvergetOperationResolver()protected SegmentMemberService<SegmentMember,CustomerSegment>getSegmentMemberService()com.broadleafcommerce.common.dataimport.messaging.BatchCompletionhandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)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 theBatchRecordsmapped by email addresses.protected voidpersistPersistenceRequests(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 asPersistenceRequests and adds persistence result toallCompletionsprotected voidprocessNotFoundCustomers(List<Customer> customersFoundInDataStore, Set<String> emails)This method OOB does nothing, but can be overridden to process not found customersprotected voidresolveSegmentMemberId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, SegmentMember segmentMember)Resolves and sets the id forSegmentMember.protected voidsetIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)protected voidsetOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)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.-
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
-
CustomerSegmentMemberImportBatchHandler
public CustomerSegmentMemberImportBatchHandler(CustomerService<Customer> customerService, CustomerSegmentService<CustomerSegment> customerSegmentService, SegmentMemberService<SegmentMember,CustomerSegment> segmentMemberService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
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 theBatchRecordsmapped by email addresses.For each record, which email address is deemed duplicated in the file, an error
BatchCompletionRecordwill be created and added toerroredCompletions, and it will not appear in the returned result.- Parameters:
batchRecords- the list of the givenBatchRecordfrom the originalBatchRequesterroredCompletions- the list to which any errored completion records should be added- Returns:
- the map of
BatchRecordby 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 statecustomerSegmentId- the id of the parent customer segment for which members are being importedrequestedCustomerEmails- 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 theBatchRecordcustomersFoundInDataStore- 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 errorBatchCompletionRecordwill be created and added toerroredCompletions, and it will not appear in the returned result.Any
BatchRecordswith email addresses that reference customers which do not exist incustomersFoundInDataStorewill be considered invalid.Creates and returns a list of pairs of requested
CustomerandBatchRecord, for records that should be persisted.- Parameters:
batchRecordsByEmail- the map ofBatchRecordby email addresscustomersFoundInDataStore- the list of customers existing in the data storeerroredCompletions- the list to which any errored completion records should be added- Returns:
- a list of pairs of requested
CustomerandBatchRecordthat 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 ofPersistenceRequestfor theSegmentMember.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
BatchCompletionRecordwill be created for it and added to thecompletionslist, and a persistence request will not be created for it.- Parameters:
requestedCustomerAndBatchRecordList- a list of pairs of requestedCustomerandBatchRecordcustomerSegment- the parent customer segment for which members are being importedcompletions- the list of batch record completions to add any early-completions toreadContextInfo- request context information around sandbox and multitenant state- Returns:
- the list of
PersistenceRequestfor theSegmentMember
-
buildPersistenceRequest
protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SegmentMember> buildPersistenceRequest(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
Builds thePersistenceRequestfor theSegmentMember.- Parameters:
customerSegment- the customer segment for segment membercustomer- the customer for segment memberbatchRecord- the record represents segment member from file- Returns:
- the
PersistenceRequestfor theSegmentMember
-
buildSegmentMember
protected SegmentMember buildSegmentMember(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
Creates instance ofSegmentMemberand populates with properties.- Parameters:
customerSegment- the customer segment for segment membercustomer- the customer for segment memberbatchRecord- the record represents segment member from file- Returns:
- instance of
SegmentMemberwith populated properties
-
resolveSegmentMemberId
protected void resolveSegmentMemberId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, SegmentMember segmentMember)Resolves and sets the id forSegmentMember.- Parameters:
batchRecord- the record representsSegmentMemberfrom filesegmentMember- theSegmentMemberfor 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 asPersistenceRequests and adds persistence result toallCompletions- Parameters:
batch- the original record batchsegmentMembers- a list of the segment member persistence requestsallCompletions- 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 storeemails- the set of email addresses for which customers were not found
-
getCustomerService
protected CustomerService<Customer> getCustomerService()
-
getCustomerSegmentService
protected CustomerSegmentService<CustomerSegment> getCustomerSegmentService()
-
getSegmentMemberService
protected SegmentMemberService<SegmentMember,CustomerSegment> getSegmentMemberService()
-
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)
-
-