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 ofCustomerSegment
- 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 Summary
ConstructorDescriptionDefaultCustomerSegmentService
(CustomerSegmentRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper) -
Method Summary
Modifier and TypeMethodDescriptionprotected ResolveCustomerSegmentsRequest
augmentSegmentResolutionRequest
(@NonNull ResolveCustomerSegmentsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hookpoint to use to augment the data on aResolveCustomerSegmentsRequest
in case additional data needs to be included from related entities likeCustomerAddresses
that the external caller may not know about or provide.protected CustomerSegmentRef
buildRefFromSegment
(@NonNull CustomerSegment customerSegment) boolean
canManuallyAddCustomerToSegment
(String segmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Evaluates whether the customer segment with the given ID allows manually adding customers.protected CustomerSegmentRepository<com.broadleafcommerce.data.tracking.core.Trackable>
getRepo()
protected SegmentMemberService<SegmentMember,
CustomerSegment> protected com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService
protected com.broadleafcommerce.common.extension.TypeFactory
readAllRuleBasedCustomerSegmentsByRuleEvaluationType
(String evaluationType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads all the matchingCustomerSegments
byCustomerSegment.getCustomerSegmentType()
andCustomerSegment.getRuleEvaluationType()
.resolveCustomerSegmentsForRequest
(@NonNull ResolveCustomerSegmentsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) ResolvesCustomerSegments
that apply to a given request.protected List<CustomerSegmentRef>
resolveDirectSegmentsForRequest
(@NonNull ResolveCustomerSegmentsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected List<CustomerSegmentRef>
resolvePrefetchedSegmentsForRequest
(@NonNull ResolveCustomerSegmentsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Filters theprefetched segments
to find those that match the request.protected List<CustomerSegmentRef>
resolveRuleBasedSegmentsForRequest
(@NonNull ResolveCustomerSegmentsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds all of therule-based
CustomerSegments
that have aCustomerSegment.getRuleEvaluationType()
that matches the givenrequest
.void
setSegmentMemberService
(SegmentMemberService<SegmentMember, CustomerSegment> segmentMemberService) void
setSpelRuleEvaluationService
(com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService spelRuleEvaluationService) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) 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, getRepository, 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
-
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
ResolvesCustomerSegments
that apply to a given request.- Specified by:
resolveCustomerSegmentsForRequest
in interfaceCustomerSegmentService<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
Reads all the matchingCustomerSegments
byCustomerSegment.getCustomerSegmentType()
andCustomerSegment.getRuleEvaluationType()
.- Specified by:
readAllRuleBasedCustomerSegmentsByRuleEvaluationType
in interfaceCustomerSegmentService<P extends CustomerSegment>
- Parameters:
evaluationType
- The type of rule evaluation. SeeDefaultCustomerSegmentRuleEvaluationType
.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
andRULE_BASED
, only sets support manually adding customers, as rule based segments are derived.- Specified by:
canManuallyAddCustomerToSegment
in interfaceCustomerSegmentService<P extends CustomerSegment>
- Parameters:
segmentId
- The ID of the segment to evaluatecontext
- Context information regarding sandboxing and multitenant state- Returns:
true
if customers may be manually added to this segment, elsefalse
-
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 aResolveCustomerSegmentsRequest
in case additional data needs to be included from related entities likeCustomerAddresses
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 ashome 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) - Parameters:
request
- The request to resolve customer segments for a given contextcontext
- 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 therule-based
CustomerSegments
that have aCustomerSegment.getRuleEvaluationType()
that matches the givenrequest
.- Parameters:
request
- The request to resolve customer segments for a given contextcontext
- 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 theprefetched segments
to find those that match the request. This will filter out anyDefaultCustomerSegmentRuleEvaluationType.OFFLINE
rule-based
CustomerSegments
as those can't be evaluated in this context and should already be present on the auth token. Additionally, onlycustomer-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
-
getRepo
-
setSegmentMemberService
@Autowired @Lazy public void setSegmentMemberService(SegmentMemberService<SegmentMember, CustomerSegment> segmentMemberService) -
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()
-