Class DefaultCancellationPolicyService<C extends CancellationPolicy>
java.lang.Object
com.broadleafcommerce.subscriptionoperation.service.DefaultCancellationPolicyService<C>
- All Implemented Interfaces:
CancellationPolicyService<C>
public class DefaultCancellationPolicyService<C extends CancellationPolicy>
extends Object
implements CancellationPolicyService<C>
Default implementation of
CancellationPolicyService.- Author:
- Sunny Yu
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCancellationPolicyService(CancellationPolicyProvider<C> cancellationPolicyProvider, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.data.domain.PageableBuilds the initialPageableto be used in the readAll request.protected cz.jirutka.rsql.parser.ast.NodeBuilds theNodefilters for theCancellationPolicyProvider.readAll(Node, Pageable, ContextInfo)requests.protected com.broadleafcommerce.order.common.domain.subscription.CancellationPolicyRefbuildPolicyRef(C cancellationPolicy) Builds theCancellationPolicyRefbased on the givenCancellationPolicy.protected CancellationPolicyProvider<C>protected intprotected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationServiceprotected com.broadleafcommerce.common.extension.TypeFactoryidentifyCancellationPolicy(@NonNull IdentifyCancellationPolicyRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Identifies theCancellationPolicyfor the givenIdentifyCancellationPolicyRequest.identifyCancellationPolicy(@NonNull List<C> cancellationPolicies, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies the matching cancellation policy for the given cart item.protected booleanpolicyMatchesForItem(C policy, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Determines whether the givenCancellationPolicyis a match for the givenCartItembased on theCancellationPolicy.getPolicyRules().readCancellationPolicyById(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads aCancellationPolicyby its id.
-
Field Details
-
DEFAULT_PAGE_SIZE
protected static final int DEFAULT_PAGE_SIZE- See Also:
-
REQUIRES_DIRECT_REFERENCE
- See Also:
-
-
Constructor Details
-
DefaultCancellationPolicyService
public DefaultCancellationPolicyService(CancellationPolicyProvider<C> cancellationPolicyProvider, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
readCancellationPolicyById
public C readCancellationPolicyById(@NonNull @NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CancellationPolicyServiceReads aCancellationPolicyby its id.- Specified by:
readCancellationPolicyByIdin interfaceCancellationPolicyService<C extends CancellationPolicy>- Parameters:
id- the id of theCancellationPolicycontextInfo- context information around multi-tenant state- Returns:
- the
CancellationPolicywith the provided id
-
identifyCancellationPolicy
public IdentifyCancellationPolicyResponse identifyCancellationPolicy(@NonNull @NonNull IdentifyCancellationPolicyRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:CancellationPolicyServiceIdentifies theCancellationPolicyfor the givenIdentifyCancellationPolicyRequest.- Specified by:
identifyCancellationPolicyin interfaceCancellationPolicyService<C extends CancellationPolicy>- Parameters:
request- the request to identify the cancellation policycontext- context information surrounding sandboxing and multitenant state- Returns:
- the
IdentifyCancellationPolicyResponsecontaining the result
-
buildFirstPageable
protected org.springframework.data.domain.Pageable buildFirstPageable()Builds the initialPageableto be used in the readAll request.By default, it sorts by priority in ascending order with
Sort.NullHandling.NULLS_LASTstrategy. -
getPageSize
protected int getPageSize() -
buildNodeFilters
protected cz.jirutka.rsql.parser.ast.Node buildNodeFilters()Builds theNodefilters for theCancellationPolicyProvider.readAll(Node, Pageable, ContextInfo)requests.By default, it filters out policies that require direct reference.
- Returns:
- the
Nodefilters
-
identifyCancellationPolicy
protected Optional<C> identifyCancellationPolicy(@NonNull @NonNull List<C> cancellationPolicies, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Identifies the matching cancellation policy for the given cart item.There should be a default policy in the system that has no policy rules defined to serve as a fallback.
- Parameters:
cancellationPolicies- the list of cancellation policies to evaluatecartItem- the cart item to evaluate against- Returns:
- the
Optionalof cancellation policy,Optional.empty()if not found.
-
policyMatchesForItem
protected boolean policyMatchesForItem(@NonNull C policy, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Determines whether the givenCancellationPolicyis a match for the givenCartItembased on theCancellationPolicy.getPolicyRules().- Parameters:
policy- theCancellationPolicyto evaluatecartItem- theCartItemto evaluate against- Returns:
trueif the policy matches the item, otherwisefalse
-
buildPolicyRef
protected com.broadleafcommerce.order.common.domain.subscription.CancellationPolicyRef buildPolicyRef(@NonNull C cancellationPolicy) Builds theCancellationPolicyRefbased on the givenCancellationPolicy.- Parameters:
cancellationPolicy- theCancellationPolicyto build the reference from- Returns:
- the
CancellationPolicyRef
-
getCancellationPolicyProvider
-
getRuleEvaluationService
protected com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService getRuleEvaluationService() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-