Class DefaultCustomerSegmentService<P 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.DefaultCustomerSegmentService<P>
Type Parameters:
P - A type or subtype of CustomerSegment
All Implemented Interfaces:
CustomerSegmentService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultCustomerSegmentService<P extends CustomerSegment> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements CustomerSegmentService<P>
Default implementation of CustomerSegmentService
  • Constructor Details

    • DefaultCustomerSegmentService

      public DefaultCustomerSegmentService(CustomerSegmentRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
  • Method Details

    • resolveCustomerSegmentsForRequest

      public ResolveCustomerSegmentResponse resolveCustomerSegmentsForRequest(@NonNull @NonNull ResolveCustomerSegmentsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerSegmentService
      Resolves CustomerSegments that apply to a given request.
      Specified by:
      resolveCustomerSegmentsForRequest in interface CustomerSegmentService<P extends CustomerSegment>
      Parameters:
      request - Request with user details for customer segments to target and be evaluated against.
      context - Additional multitenant and sandbox info.
      Returns:
      The list of matching segments if any.
    • readAllRuleBasedCustomerSegmentsByRuleEvaluationType

      public List<P> readAllRuleBasedCustomerSegmentsByRuleEvaluationType(String evaluationType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerSegmentService
      Specified by:
      readAllRuleBasedCustomerSegmentsByRuleEvaluationType in interface CustomerSegmentService<P extends CustomerSegment>
      Parameters:
      evaluationType - The type of rule evaluation. See DefaultCustomerSegmentRuleEvaluationType.
      context - Additional sandbox and multitenant info.
      Returns:
      The matching CustomerSegments.
    • canManuallyAddCustomerToSegment

      public boolean canManuallyAddCustomerToSegment(String segmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerSegmentService
      Evaluates whether the customer segment with the given ID allows manually adding customers.

      As an example, using the default customer segment types, CUSTOMER_SET and RULE_BASED, only sets support manually adding customers, as rule based segments are derived.

      Specified by:
      canManuallyAddCustomerToSegment in interface CustomerSegmentService<P extends CustomerSegment>
      Parameters:
      segmentId - The ID of the segment to evaluate
      context - Context information regarding sandboxing and multitenant state
      Returns:
      true if customers may be manually added to this segment, else false
    • augmentSegmentResolutionRequest

      protected ResolveCustomerSegmentsRequest augmentSegmentResolutionRequest(@NonNull @NonNull ResolveCustomerSegmentsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Hookpoint to use to augment the data on a ResolveCustomerSegmentsRequest in case additional data needs to be included from related entities like CustomerAddresses that the external caller may not know about or provide. Typically, callers only use the information available on the auth token claims or request attributes like geo- location. Therefore, if there is a desire to have a rule-based segment with a rule targeting information such as home address postal code, then this is the place to hydrate that information onto the request.

      By default, this method does nothing.

      Parameters:
      request - The incoming request to augment.
      context - Additional tenant and sandbox info.
      Returns:
      The augmented request.
    • resolveDirectSegmentsForRequest

      protected List<CustomerSegmentRef> resolveDirectSegmentsForRequest(@NonNull @NonNull ResolveCustomerSegmentsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Finds all of the CustomerSegments that have a SegmentMember that matches the give request.
      Parameters:
      request - The request to resolve customer segments for a given context
      context - Additional sandbox and multitenant info
      Returns:
      The directly related segments matching the context
    • resolveRuleBasedSegmentsForRequest

      protected List<CustomerSegmentRef> resolveRuleBasedSegmentsForRequest(@NonNull @NonNull ResolveCustomerSegmentsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Finds all of the rule-based CustomerSegments that have a CustomerSegment.getRuleEvaluationType() that matches the given request.
      Parameters:
      request - The request to resolve customer segments for a given context
      context - Additional sandbox and multitenant info
      Returns:
      The rule-based segments matching the context
    • resolvePrefetchedSegmentsForRequest

      protected List<CustomerSegmentRef> resolvePrefetchedSegmentsForRequest(@NonNull @NonNull ResolveCustomerSegmentsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Filters the prefetched segments to find those that match the request. This will filter out any DefaultCustomerSegmentRuleEvaluationType.OFFLINE rule-based CustomerSegments as those can't be evaluated in this context and should already be present on the auth token. Additionally, only customer-set segments that the user is a member of will be included.
      Parameters:
      request - The resolution request.
      context - Additional tenant and sandbox info.
      Returns:
      The list of prefetched segments matching the request.
    • buildRefFromSegment

      protected CustomerSegmentRef buildRefFromSegment(@NonNull @NonNull CustomerSegment customerSegment)
    • getRepo

      protected CustomerSegmentRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepo()
    • setSegmentMemberService

      @Autowired @Lazy public void setSegmentMemberService(SegmentMemberService<SegmentMember,CustomerSegment> segmentMemberService)
    • getSegmentMemberService

      protected SegmentMemberService<SegmentMember,CustomerSegment> getSegmentMemberService()
    • setSpelRuleEvaluationService

      @Autowired public void setSpelRuleEvaluationService(com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService spelRuleEvaluationService)
    • getSpelRuleEvaluationService

      protected com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService getSpelRuleEvaluationService()
    • setTypeFactory

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()