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 Details

  • Constructor Details

  • Method Details

    • canHandle

      public boolean canHandle(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
      Specified by:
      canHandle in interface com.broadleafcommerce.bulk.service.BulkUpdateProcessor<P extends Customer>
    • readRecordsToProcess

      public com.broadleafcommerce.bulk.service.ReadRecordsResponse<P> readRecordsToProcess(com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
      Specified by:
      readRecordsToProcess in interface com.broadleafcommerce.bulk.service.BulkUpdateProcessor<P extends Customer>
    • modifyAndPersist

      public com.broadleafcommerce.bulk.service.BatchProcessResponse modifyAndPersist(List<P> customerBatch, com.broadleafcommerce.bulk.domain.BulkUpdate bulkUpdate)
      Specified by:
      modifyAndPersist in interface com.broadleafcommerce.bulk.service.BulkUpdateProcessor<P extends Customer>
    • 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 object
      errors - 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 process
      segment - The segment to clear
    • buildSegmentMember

      protected SegmentMember buildSegmentMember(P customer, String segmentId)
      Builds the segment/customer relationship
      Parameters:
      customer - The target customer
      segmentId - 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()