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
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionCustomerSegmentContextInfoCustomizer
(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 ResolveCustomerSegmentsRequest
buildResolutionRequest
(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.web.context.request.NativeWebRequest webRequest) Builds theResolveCustomerSegmentsRequest
against which the resolvedCustomerSegments
are evaluated to determine if they match the current context.void
customize
(@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 theResolveCustomerSegmentsRequest
that theCustomerSegments
are evaluated against.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected com.broadleafcommerce.common.extension.cache.CacheStateManager
protected CustomerSegmentProvider<P>
protected CustomerSegmentResolutionProperties
protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
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 theResolveCustomerSegmentsRequest
that theCustomerSegments
are evaluated against.protected com.broadleafcommerce.common.extension.data.DataRouteSupporting
getRoute()
protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService
protected com.broadleafcommerce.common.extension.TypeFactory
handleSegmentsRequiringExternalEvaluation
(@NonNull Collection<P> prefetchedSegments, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @NonNull ResolveCustomerSegmentsRequest request) HandlesCustomerSegments
whereCustomerSegment.isInternalEvaluationRequired()
.readSegments
(@NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, String routeKey, org.springframework.web.context.request.NativeWebRequest webRequest) Reads the dynamicCustomerSegments
and caches them by default.void
setDynamicCustomerSegmentCacheKeyGen
(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen dynamicCustomerSegmentCacheKeyGen) protected boolean
shouldHandle
(@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, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.context.ContextInfoCustomizer
getOrder
-
Field Details
-
DYNAMIC_CUSTOMER_SEGMENT_CACHE
- See Also:
-
-
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 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 dynamicCustomerSegments
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 theResolveCustomerSegmentsRequest
against which the resolvedCustomerSegments
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 resolvedCustomerSegments
are evaluated to determine if they match the current context.
-
getAdditionalClaims
Retrieves the additional auth claims that should be placed on theResolveCustomerSegmentsRequest
that theCustomerSegments
are evaluated against.- Returns:
- The additional auth claims that should be placed on the
ResolveCustomerSegmentsRequest
that theCustomerSegments
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 theResolveCustomerSegmentsRequest
that theCustomerSegments
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 theCustomerSegments
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) HandlesCustomerSegments
whereCustomerSegment.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
- TheResolveCustomerSegmentsRequest
.- 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
-
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
-