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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected static final Patternprotected static final PatternFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCustomerSegmentContextInfoCustomizer(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 Summary
Modifier and TypeMethodDescriptionprotected ResolveCustomerSegmentsRequestbuildResolutionRequest(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.web.context.request.NativeWebRequest webRequest) Builds theResolveCustomerSegmentsRequestagainst which the resolvedCustomerSegmentsare evaluated to determine if they match the current context.voidcustomize(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.core.MethodParameter endpoint, org.springframework.web.context.request.NativeWebRequest webRequest) Retrieves the additional auth claims that should be placed on theResolveCustomerSegmentsRequestthat theCustomerSegmentsare evaluated against.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsprotected com.broadleafcommerce.common.extension.cache.CacheStateManagerprotected CustomerSegmentProvider<P>protected CustomerSegmentResolutionPropertiesprotected com.broadleafcommerce.common.extension.cache.key.ContextKeyGenprotected static StringgetFormattedClaimKey(String augClaimKey) Removes the augmentation prefix from the augmentation claim key and transforms it to camel case.getRequestAttributes(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.web.context.request.NativeWebRequest webRequest) Retrieves the request attributes that should be placed on theResolveCustomerSegmentsRequestthat theCustomerSegmentsare evaluated against.protected com.broadleafcommerce.common.extension.data.DataRouteSupportinggetRoute()protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationServiceprotected com.broadleafcommerce.common.extension.TypeFactoryhandleSegmentsRequiringExternalEvaluation(@NonNull Collection<P> prefetchedSegments, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull ResolveCustomerSegmentsRequest request) HandlesCustomerSegmentswhereCustomerSegment.isInternalEvaluationRequired().readSegments(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.web.context.request.NativeWebRequest webRequest) Reads the dynamicCustomerSegmentsand caches them by default.voidsetDynamicCustomerSegmentCacheKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen dynamicCustomerSegmentCacheKeyGen) protected booleanshouldHandle(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.core.MethodParameter endpoint, org.springframework.web.context.request.NativeWebRequest webRequest) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.context.ContextInfoCustomizer
getOrder
-
Field Details
-
DYNAMIC_CUSTOMER_SEGMENT_CACHE
- See Also:
-
AUGMENTATION_PREFIX
- See Also:
-
PREFIX_PATTERN
-
SNAKE_TO_CAMEL_PATTERN
-
-
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:
customizein interfacecom.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 dynamicCustomerSegmentsand 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
CustomerSegmentsand 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 theResolveCustomerSegmentsRequestagainst which the resolvedCustomerSegmentsare 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
ResolveCustomerSegmentsRequestagainst which the resolvedCustomerSegmentsare evaluated to determine if they match the current context.
-
getAdditionalClaims
Retrieves the additional auth claims that should be placed on theResolveCustomerSegmentsRequestthat theCustomerSegmentsare evaluated against.- Returns:
- The additional auth claims that should be placed on the
ResolveCustomerSegmentsRequestthat theCustomerSegmentsare 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 theResolveCustomerSegmentsRequestthat theCustomerSegmentsare 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
ResolveCustomerSegmentsRequestthat theCustomerSegmentsare 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) HandlesCustomerSegmentswhereCustomerSegment.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
prefetchedSegmentscontains 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- TheResolveCustomerSegmentsRequest.- Returns:
- The list of segment IDs that match the context according to the customer service.
-
getFormattedClaimKey
Removes the augmentation prefix from the augmentation claim key and transforms it to camel case. This method expects a claim key in snake case.- Parameters:
augClaimKey- the claim key to format- Returns:
- the formatted claim key
-
getRoute
protected com.broadleafcommerce.common.extension.data.DataRouteSupporting getRoute() -
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() -
getCustomerSegmentResolutionProperties
-
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()
-