Class DefaultSegmentMemberService<P extends SegmentMember,S extends CustomerSegment>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.customer.service.DefaultSegmentMemberService<P,S>
All Implemented Interfaces:
SegmentMemberService<P,S>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultSegmentMemberService<P extends SegmentMember,S extends CustomerSegment> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements SegmentMemberService<P,S>
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultSegmentMemberService(CustomerSegmentService<S> customerSegmentService, int clearSegmentMemberBatchSize, SegmentMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    cannotAddCustomerToSegmentError(P segmentMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Creates and throws an error for use if manually adding customers to this segment is not supported.
    createSegmentMember(P segmentMember, String source, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Creates and adds a customer/segment relationship.
    protected void
    Creates and throws an error for use if the customer already exists in this segment.
    protected org.springframework.data.domain.Page<P>
    findAllBySegmentIdAndNotMatchingSegmentRule(S segment, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    protected int
    The batch size of customers to be included in a ClearCustomerSegmentRequest
     
    protected SegmentMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected void
    notifySegmentClear(String segmentId, List<P> segmentMembers)
     
    readAllByCustomerEmailOrCustomerId(String customerEmail, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the segment members for the specified customer segment id and customer email addresses.
    readAllBySegmentId(String segmentId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the segment members for the specified customer segment id matching the given filters.
    readAllBySegmentIdAndCustomerEmail(String segmentId, Set<String> emailAddresses, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the segment members for the specified customer segment id and customer email addresses.
    readAllBySegmentIdAndCustomerIds(@NonNull String segmentId, @NonNull Set<String> customerIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the segment members for the specified customer segment id and customer ids.
    readMemberInSegment(String segmentId, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Returns a particular customer/segment relationship with the designated customer and segment IDs.
    org.springframework.data.domain.Page<P>
    readMembersInSegment(String segmentId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads a page of customers who are members of a segment.
    void
    removeAllMembersFromSegment(String segmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Removes all customer/segment relationships from a particular segment.
    void
    removeAllMembersNoLongerInSegment(S segment, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Removes all customer/segment relationships for customers that no longer meet the segment's conditions.
    void
    removeMemberFromSegment(String segmentId, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Removes a particular customer/segment relationship with the designated customer and segment IDs.
    protected void
    removeSegmentMembers(@NonNull List<P> segmentMembersToRemove, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    protected void
    sendRemoveAllMembersNotification(String segmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Send a batch or batches of notification containing user and segment IDs to ensure segments are properly cleared in auth.
    protected void
    validateCustomerAddToSegment(P segmentMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Validates that a customer may be added to a segment.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Constructor Details

    • DefaultSegmentMemberService

      public DefaultSegmentMemberService(CustomerSegmentService<S> customerSegmentService, int clearSegmentMemberBatchSize, SegmentMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
  • Method Details

    • readMembersInSegment

      public org.springframework.data.domain.Page<P> readMembersInSegment(String segmentId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Reads a page of customers who are members of a segment.
      Specified by:
      readMembersInSegment in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - The segment ID
      filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
      pageable - The requested page of results from the database
      context - Context information surrounding sandboxing and multitenant state
      Returns:
      A page of customer/segment relationships
    • readMemberInSegment

      public Optional<P> readMemberInSegment(String segmentId, String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Returns a particular customer/segment relationship with the designated customer and segment IDs.
      Specified by:
      readMemberInSegment in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - The segment ID
      customerId - The customer ID
      context - Context information surrounding sandboxing and multitenant state
      Returns:
      The customer/segment relationship.
    • removeMemberFromSegment

      public void removeMemberFromSegment(String segmentId, String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Removes a particular customer/segment relationship with the designated customer and segment IDs.
      Specified by:
      removeMemberFromSegment in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - The segment ID
      customerId - The customer ID
      context - Context information surrounding sandboxing and multitenant state
    • removeAllMembersFromSegment

      @Transactional("customerTransactionManager") public void removeAllMembersFromSegment(String segmentId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Removes all customer/segment relationships from a particular segment.
      Specified by:
      removeAllMembersFromSegment in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - The segment ID
      context - Context information surrounding sandboxing and multitenant state
    • removeAllMembersNoLongerInSegment

      public void removeAllMembersNoLongerInSegment(@NonNull S segment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Removes all customer/segment relationships for customers that no longer meet the segment's conditions.
      Specified by:
      removeAllMembersNoLongerInSegment in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segment - The segment
      context - Context information surrounding sandboxing and multitenant state
    • createSegmentMember

      public P createSegmentMember(P segmentMember, String source, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SegmentMemberService
      Creates and adds a customer/segment relationship.

      This differs from a standard create in that additional validation is performed based on the segment's type. For example, attempting to manually add a customer to a segment with the type RULE_BASED is not allowed and an exception should be thrown.

      For performance critical operations (e.g. a bulk import), use CrudEntityService.create(Object, ContextInfo)

      Specified by:
      createSegmentMember in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentMember - The customer/segment relationship to create.
      source - The source of this segment/customer relationship.
      context - Context information surrounding sandboxing and multitenant state
      Returns:
      The customer/segment relationship if added successfully.
      See Also:
    • readAllBySegmentId

      public Stream<P> readAllBySegmentId(String segmentId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SegmentMemberService
      Reads the segment members for the specified customer segment id matching the given filters.
      Specified by:
      readAllBySegmentId in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - the CustomerSegment id
      filters - additional filters to apply in the query
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      the segment members for the specified customer segment id matching the given filters
    • readAllBySegmentIdAndCustomerEmail

      public List<P> readAllBySegmentIdAndCustomerEmail(String segmentId, Set<String> emailAddresses, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SegmentMemberService
      Reads the segment members for the specified customer segment id and customer email addresses.
      Specified by:
      readAllBySegmentIdAndCustomerEmail in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - the CustomerSegment id
      emailAddresses - the set of Customer email
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      the segment members for the specified customer segment id and customer email addresses
    • readAllByCustomerEmailOrCustomerId

      public List<P> readAllByCustomerEmailOrCustomerId(@Nullable String customerEmail, @Nullable String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SegmentMemberService
      Reads the segment members for the specified customer segment id and customer email addresses.
      Specified by:
      readAllByCustomerEmailOrCustomerId in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      customerEmail - Customer's email
      customerId - Customer's ID
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      the segment members for the specified customer segment id and customer email addresses
    • readAllBySegmentIdAndCustomerIds

      public List<P> readAllBySegmentIdAndCustomerIds(@NonNull @NonNull String segmentId, @NonNull @NonNull Set<String> customerIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SegmentMemberService
      Reads the segment members for the specified customer segment id and customer ids.
      Specified by:
      readAllBySegmentIdAndCustomerIds in interface SegmentMemberService<P extends SegmentMember,S extends CustomerSegment>
      Parameters:
      segmentId - the CustomerSegment id
      customerIds - the set of Customer id
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      the segment members for the specified customer segment id and customer ids
    • validateCustomerAddToSegment

      protected void validateCustomerAddToSegment(P segmentMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Validates that a customer may be added to a segment.
      Parameters:
      segmentMember - The SegmentMember to evaluate
      context - The current context
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - if a customer cannot be added to the specific segment type, or the customer already exists in the segment
    • cannotAddCustomerToSegmentError

      protected void cannotAddCustomerToSegmentError(P segmentMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Creates and throws an error for use if manually adding customers to this segment is not supported.
      Parameters:
      segmentMember - The segment that failed validation
      context - The current context
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - Always thrown
    • customerAlreadyExistsInSegmentError

      protected void customerAlreadyExistsInSegmentError(P segmentMember)
      Creates and throws an error for use if the customer already exists in this segment.
      Parameters:
      segmentMember - The segment that failed validation
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - Always thrown
    • findAllBySegmentIdAndNotMatchingSegmentRule

      @NotNull protected org.springframework.data.domain.Page<P> findAllBySegmentIdAndNotMatchingSegmentRule(@NonNull S segment, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • removeSegmentMembers

      protected void removeSegmentMembers(@NonNull @NonNull List<P> segmentMembersToRemove, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • sendRemoveAllMembersNotification

      protected void sendRemoveAllMembersNotification(String segmentId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Send a batch or batches of notification containing user and segment IDs to ensure segments are properly cleared in auth.
      Parameters:
      segmentId - The segment ID that is to be cleared.
      context - The current context.
    • notifySegmentClear

      protected void notifySegmentClear(String segmentId, List<P> segmentMembers)
    • getCustomerSegmentService

      @NonNull protected CustomerSegmentService<S> getCustomerSegmentService()
    • getRepository

      @NonNull protected SegmentMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SegmentMember>
    • getClearSegmentMemberBatchSize

      protected int getClearSegmentMemberBatchSize()
      The batch size of customers to be included in a ClearCustomerSegmentRequest