Class CustomerSegmentContextInfoCustomizer<P extends CustomerSegment>

java.lang.Object
com.broadleafcommerce.customer.client.context.CustomerSegmentContextInfoCustomizer<P>
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.context.ContextInfoCustomizer, org.springframework.core.Ordered

public class CustomerSegmentContextInfoCustomizer<P extends CustomerSegment> extends Object implements com.broadleafcommerce.data.tracking.core.context.ContextInfoCustomizer
Customizer responsible for hydrating ContextInfo.getCustomerSegmentIds(). This will reach out to the configured CustomerSegmentProvider to retrieve any dynamic segments, cache them, then evaluate their rules against the current incoming web request and auth context.
Author:
Nathan Moore (nathandmoore)
  • Field Details

  • Constructor Details

    • CustomerSegmentContextInfoCustomizer

      public CustomerSegmentContextInfoCustomizer(com.broadleafcommerce.common.extension.data.DataRouteSupporting route, CustomerSegmentProvider<P> customerSegmentProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authUtils, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, CustomerSegmentResolutionProperties customerSegmentResolutionProperties)
  • Method Details

    • customize

      public void customize(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable String routeKey, @Nullable org.springframework.core.MethodParameter endpoint, @Nullable org.springframework.web.context.request.NativeWebRequest webRequest)
      Specified by:
      customize in interface com.broadleafcommerce.data.tracking.core.context.ContextInfoCustomizer
    • shouldHandle

      protected boolean shouldHandle(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable String routeKey, @Nullable org.springframework.core.MethodParameter endpoint, @Nullable org.springframework.web.context.request.NativeWebRequest webRequest)
    • readSegments

      protected List<P> readSegments(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable String routeKey, @Nullable org.springframework.web.context.request.NativeWebRequest webRequest)
      Reads the dynamic CustomerSegments and caches them by default.
      Parameters:
      contextInfo - The context info being customized.
      routeKey - The key for the data route, e.g., customer, catalog, cart.
      webRequest - The incoming web request.
      Returns:
      List of the dynamic CustomerSegments and caches them by default.
    • buildResolutionRequest

      protected ResolveCustomerSegmentsRequest buildResolutionRequest(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable String routeKey, @Nullable org.springframework.web.context.request.NativeWebRequest webRequest)
      Builds the ResolveCustomerSegmentsRequest against which the resolved CustomerSegments are evaluated to determine if they match the current context.
      Parameters:
      contextInfo - The context info being customized.
      routeKey - The key for the data route, e.g., customer, catalog, cart.
      webRequest - The incoming web request.
      Returns:
      The ResolveCustomerSegmentsRequest against which the resolved CustomerSegments are evaluated to determine if they match the current context.
    • getAdditionalClaims

      protected Map<String,Object> getAdditionalClaims()
      Retrieves the additional auth claims that should be placed on the ResolveCustomerSegmentsRequest that the CustomerSegments are evaluated against.
      Returns:
      The additional auth claims that should be placed on the ResolveCustomerSegmentsRequest that the CustomerSegments are evaluated against.
    • getRequestAttributes

      protected Map<String,Object> getRequestAttributes(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable String routeKey, @Nullable org.springframework.web.context.request.NativeWebRequest webRequest)
      Retrieves the request attributes that should be placed on the ResolveCustomerSegmentsRequest that the CustomerSegments are evaluated against.
      Parameters:
      contextInfo - The context info being customized.
      routeKey - The key for the data route, e.g., customer, catalog, cart.
      webRequest - The incoming web request.
      Returns:
      The request attributes that should be placed on the ResolveCustomerSegmentsRequest that the CustomerSegments are evaluated against.
    • handleSegmentsRequiringExternalEvaluation

      protected List<String> handleSegmentsRequiringExternalEvaluation(@NonNull @NonNull Collection<P> prefetchedSegments, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull @NonNull ResolveCustomerSegmentsRequest request)
      Handles CustomerSegments where CustomerSegment.isInternalEvaluationRequired(). These segments require additional data only available in the Customer Service such as a customer's home zipcode.

      This will only send a request if the prefetchedSegments contains any rule-based segments that require external evaluation and the property. CustomerSegmentResolutionProperties.isEvaluatingRuleBasedSegmentsExternallyAllowed().

      Parameters:
      prefetchedSegments - Rule-based segments that have already been fetched.
      contextInfo - The context info being customized.
      request - The ResolveCustomerSegmentsRequest.
      Returns:
      The list of segment IDs that match the context according to the customer service.
    • getRoute

      protected com.broadleafcommerce.common.extension.data.DataRouteSupporting getRoute()
    • getCustomerSegmentProvider

      protected CustomerSegmentProvider<P> getCustomerSegmentProvider()
    • getTypeFactory

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

      protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthUtils()
    • getRuleEvaluationService

      protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService getRuleEvaluationService()
    • getCacheStateManager

      @Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager()
    • setDynamicCustomerSegmentCacheKeyGen

      @Autowired @Qualifier("dynamicCustomerSegmentCache") public void setDynamicCustomerSegmentCacheKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen dynamicCustomerSegmentCacheKeyGen)
    • getDynamicCustomerSegmentCacheKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getDynamicCustomerSegmentCacheKeyGen()
    • getCustomerSegmentResolutionProperties

      protected CustomerSegmentResolutionProperties getCustomerSegmentResolutionProperties()