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 class
CustomerSegmentMemberImportBatchHandler.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 thePersistenceRequest
for 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 ofPersistenceRequest
for theSegmentMember
.protected SegmentMember
buildSegmentMember(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
Creates instance ofSegmentMember
and populates with properties.boolean
canHandle(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()
String
getDataRouteKey()
protected com.broadleafcommerce.common.dataimport.util.IdResolver
getIdResolver()
protected com.broadleafcommerce.common.dataimport.util.OperationResolver
getOperationResolver()
protected SegmentMemberService<SegmentMember,CustomerSegment>
getSegmentMemberService()
com.broadleafcommerce.common.dataimport.messaging.BatchCompletion
handle(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 theBatchRecords
mapped by email addresses.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 asPersistenceRequest
s and adds persistence result toallCompletions
protected void
processNotFoundCustomers(List<Customer> customersFoundInDataStore, Set<String> emails)
This method OOB does nothing, but can be overridden to process not found customersprotected void
resolveSegmentMemberId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, SegmentMember segmentMember)
Resolves and sets the id forSegmentMember
.protected void
setIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
protected void
setOperationResolver(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 theBatchRecords
mapped by email addresses.For each record, which email address is deemed duplicated in the file, an error
BatchCompletionRecord
will be created and added toerroredCompletions
, and it will not appear in the returned result.- Parameters:
batchRecords
- the list of the givenBatchRecord
from the originalBatchRequest
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 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 theBatchRecord
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 errorBatchCompletionRecord
will be created and added toerroredCompletions
, and it will not appear in the returned result.Any
BatchRecords
with email addresses that reference customers which do not exist incustomersFoundInDataStore
will be considered invalid.Creates and returns a list of pairs of requested
Customer
andBatchRecord
, for records that should be persisted.- Parameters:
batchRecordsByEmail
- the map ofBatchRecord
by 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
Customer
andBatchRecord
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 ofPersistenceRequest
for 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
BatchCompletionRecord
will be created for it and added to thecompletions
list, and a persistence request will not be created for it.- Parameters:
requestedCustomerAndBatchRecordList
- a list of pairs of requestedCustomer
andBatchRecord
customerSegment
- 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
PersistenceRequest
for theSegmentMember
-
buildPersistenceRequest
protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SegmentMember> buildPersistenceRequest(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
Builds thePersistenceRequest
for theSegmentMember
.- Parameters:
customerSegment
- the customer segment for segment membercustomer
- the customer for segment memberbatchRecord
- the record represents segment member from file- Returns:
- the
PersistenceRequest
for theSegmentMember
-
buildSegmentMember
protected SegmentMember buildSegmentMember(CustomerSegment customerSegment, Customer customer, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord)
Creates instance ofSegmentMember
and 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
SegmentMember
with 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 representsSegmentMember
from filesegmentMember
- theSegmentMember
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 asPersistenceRequest
s 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)
-
-