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 a SegmentMember
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultRuleBasedSegmentBulkProcessor
(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
Modifier and TypeMethodDescriptionprotected 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
protected com.broadleafcommerce.bulk.service.BulkUpdateService<com.broadleafcommerce.bulk.domain.BulkUpdate>
protected CustomerSegmentService<CustomerSegment>
protected CustomerService<P>
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
protected com.broadleafcommerce.common.messaging.notification.NotificationManager
protected String
getSegmentId
(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate) Returns the targeted customer segment ID.protected SegmentMemberService<SegmentMember,
CustomerSegment> protected CustomerSegment
getTargetSegment
(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate) Returns the targeted customer segment.protected com.broadleafcommerce.common.extension.TypeFactory
com.broadleafcommerce.bulk.service.BatchProcessResponse
modifyAndPersist
(List<P> customerBatch, com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate) protected void
persistSegmentMemberBatch
(List<SegmentMember> segmentMemberBatch, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Persists the batch of segment customersreadCustomerStream
(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.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 Details
-
CUSTOMER_SEGMENT_CLAIM_ATTR_KEY
- See Also:
-
-
Constructor Details
-
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 Details
-
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
-
updateStatusIfLastBatch
-
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> segmentMemberBatch, List<com.broadleafcommerce.bulk.domain.BulkUpdateError> errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Persists the batch of segment customers- Parameters:
segmentMemberBatch
- 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
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
Returns the targeted customer segment.- Parameters:
bulkUpdate
- The BulkUpdate request- Returns:
- The targeted segment
-
getSegmentId
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
-
getCustomerSegmentService
-
getSegmentMemberService
-
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
-
getNotificationManager
protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()
-