Class DefaultRuleBasedSegmentBulkProcessor<P extends Customer>
- java.lang.Object
-
- com.broadleafcommerce.customer.service.bulk.DefaultRuleBasedSegmentBulkProcessor<P>
-
- Type Parameters:
P
-Customer
or a subclass of Customer
- All Implemented Interfaces:
com.broadleafcommerce.bulk.service.BulkUpdateProcessor<P>
public class DefaultRuleBasedSegmentBulkProcessor<P extends Customer> extends Object implements com.broadleafcommerce.bulk.service.BulkUpdateProcessor<P>
Bulk processor for evaluating customers against a rule based customer segment.Evaluates all customers against a segment's
CustomerSegment.segmentMatchRule
and, if they match, persists the relationship as aSegmentMember
- See Also:
SegmentMember
,Customer
,CustomerSegment
-
-
Field Summary
Fields Modifier and Type Field Description static String
CUSTOMER_SEGMENT_CLAIM_ATTR_KEY
-
Constructor Summary
Constructors Constructor Description DefaultRuleBasedSegmentBulkProcessor(CustomerService<P> customerService, CustomerSegmentService<CustomerSegment> customerSegmentService, SegmentMemberService<SegmentMember,CustomerSegment> segmentMemberService, SegmentProcessHistoryService<SegmentProcessHistory> segmentProcessHistoryService, com.broadleafcommerce.bulk.service.BulkUpdateService<com.broadleafcommerce.bulk.domain.BulkUpdate> bulkUpdateService, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> filterParser, com.broadleafcommerce.common.extension.TypeFactory typeFactory, BulkProcessUtil bulkProcessUtil, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SegmentMember
buildSegmentMember(P customer, String segmentId)
Builds the segment/customer relationshipboolean
canHandle(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
protected void
clearSegmentMembers(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, CustomerSegment segment)
Clears all existing customers who are members of the segment.protected com.broadleafcommerce.bulk.service.BatchProcessResponse
createProcessResponse(@NonNull List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors)
Creates a BatchProcessResponse with errors, if applicable.protected BulkProcessUtil
getBulkProcessUtil()
protected com.broadleafcommerce.bulk.service.BulkUpdateService<com.broadleafcommerce.bulk.domain.BulkUpdate>
getBulkUpdateService()
protected CustomerSegmentService<CustomerSegment>
getCustomerSegmentService()
protected CustomerService<P>
getCustomerService()
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
getFilterParser()
protected com.broadleafcommerce.common.messaging.notification.NotificationManager
getNotificationManager()
protected String
getSegmentId(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
Returns the targeted customer segment ID.protected SegmentMemberService<SegmentMember,CustomerSegment>
getSegmentMemberService()
protected SegmentProcessHistoryService<SegmentProcessHistory>
getSegmentProcessHistoryService()
protected CustomerSegment
getTargetSegment(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
Returns the targeted customer segment.protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
com.broadleafcommerce.bulk.service.BatchProcessResponse
modifyAndPersist(List<P> customerBatch, com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
protected void
persistSegmentMemberBatch(List<SegmentMember> segmentMemberBatches, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Persists the batch of segment customersprotected Stream<P>
readCustomerStream(CustomerSegment segment, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Returns a Stream of customers to be processed that match the Customer Segment match rule.protected Stream<P>
readRecordsInternal(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors)
Reads a stream of customers matching the customer segment's rules.com.broadleafcommerce.bulk.service.ReadRecordsResponse<P>
readRecordsToProcess(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
protected void
updateSegmentState(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, CustomerSegment segment, String segmentProcessingState)
protected void
updateStatusIfLastBatch(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, List<P> customerBatch)
-
-
-
Field Detail
-
CUSTOMER_SEGMENT_CLAIM_ATTR_KEY
public static final String CUSTOMER_SEGMENT_CLAIM_ATTR_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultRuleBasedSegmentBulkProcessor
public DefaultRuleBasedSegmentBulkProcessor(CustomerService<P> customerService, CustomerSegmentService<CustomerSegment> customerSegmentService, SegmentMemberService<SegmentMember,CustomerSegment> segmentMemberService, SegmentProcessHistoryService<SegmentProcessHistory> segmentProcessHistoryService, com.broadleafcommerce.bulk.service.BulkUpdateService<com.broadleafcommerce.bulk.domain.BulkUpdate> bulkUpdateService, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> filterParser, com.broadleafcommerce.common.extension.TypeFactory typeFactory, BulkProcessUtil bulkProcessUtil, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager)
-
-
Method Detail
-
canHandle
public boolean canHandle(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
-
readRecordsToProcess
public com.broadleafcommerce.bulk.service.ReadRecordsResponse<P> readRecordsToProcess(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
-
modifyAndPersist
public com.broadleafcommerce.bulk.service.BatchProcessResponse modifyAndPersist(List<P> customerBatch, com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
-
updateStatusIfLastBatch
protected void updateStatusIfLastBatch(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, List<P> customerBatch)
-
readRecordsInternal
protected Stream<P> readRecordsInternal(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors)
Reads a stream of customers matching the customer segment's rules.- Parameters:
bulkUpdate
- The bulk update objecterrors
- List to add errors to if an error occurs.- Returns:
- A stream of customers, or null if an error occurred.
-
updateSegmentState
protected void updateSegmentState(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, CustomerSegment segment, String segmentProcessingState)
-
persistSegmentMemberBatch
protected void persistSegmentMemberBatch(List<SegmentMember> segmentMemberBatches, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Persists the batch of segment customers- Parameters:
segmentMemberBatches
- A list of segment/customer relationships.errors
- List to add errors to if an error occurs.context
- context information surrounding sandboxing and multitenant state
-
clearSegmentMembers
protected void clearSegmentMembers(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate, CustomerSegment segment)
Clears all existing customers who are members of the segment.- Parameters:
bulkUpdate
-BulkUpdate
being representing the processsegment
- The segment to clear
-
buildSegmentMember
protected SegmentMember buildSegmentMember(P customer, String segmentId)
Builds the segment/customer relationship- Parameters:
customer
- The target customersegmentId
- The segment ID- Returns:
- The SegmentMember relationship object
-
readCustomerStream
protected Stream<P> readCustomerStream(CustomerSegment segment, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Returns a Stream of customers to be processed that match the Customer Segment match rule.- Parameters:
segment
- The rule based customer segment.context
- context information surrounding sandboxing and multitenant state- Returns:
- A stream of customers to be processed
-
getTargetSegment
protected CustomerSegment getTargetSegment(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
Returns the targeted customer segment.- Parameters:
bulkUpdate
- The BulkUpdate request- Returns:
- The targeted segment
-
getSegmentId
protected String getSegmentId(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
Returns the targeted customer segment ID.- Parameters:
bulkUpdate
- The BulkUpdate request- Returns:
- The segment ID
-
createProcessResponse
protected com.broadleafcommerce.bulk.service.BatchProcessResponse createProcessResponse(@NonNull @NonNull List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors)
Creates a BatchProcessResponse with errors, if applicable. Success is set to true or false depending on if there are any errors in the supplied list.- Parameters:
errors
- A list of errors (Non-null, may be empty)- Returns:
- The batch process response.
-
getCustomerService
protected CustomerService<P> getCustomerService()
-
getCustomerSegmentService
protected CustomerSegmentService<CustomerSegment> getCustomerSegmentService()
-
getSegmentMemberService
protected SegmentMemberService<SegmentMember,CustomerSegment> getSegmentMemberService()
-
getSegmentProcessHistoryService
protected SegmentProcessHistoryService<SegmentProcessHistory> getSegmentProcessHistoryService()
-
getBulkUpdateService
protected com.broadleafcommerce.bulk.service.BulkUpdateService<com.broadleafcommerce.bulk.domain.BulkUpdate> getBulkUpdateService()
-
getFilterParser
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getFilterParser()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getBulkProcessUtil
protected BulkProcessUtil getBulkProcessUtil()
-
getNotificationManager
protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()
-
-