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 Details

  • 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: CancellationPolicyService
      Reads a CancellationPolicy by its id.
      Specified by:
      readCancellationPolicyById in interface CancellationPolicyService<C extends CancellationPolicy>
      Parameters:
      id - the id of the CancellationPolicy
      contextInfo - context information around multi-tenant state
      Returns:
      the CancellationPolicy with the provided id
    • identifyCancellationPolicy

      public IdentifyCancellationPolicyResponse identifyCancellationPolicy(@NonNull @NonNull IdentifyCancellationPolicyRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CancellationPolicyService
      Specified by:
      identifyCancellationPolicy in interface CancellationPolicyService<C extends CancellationPolicy>
      Parameters:
      request - the request to identify the cancellation policy
      context - context information surrounding sandboxing and multitenant state
      Returns:
      the IdentifyCancellationPolicyResponse containing the result
    • buildFirstPageable

      protected org.springframework.data.domain.Pageable buildFirstPageable()
      Builds the initial Pageable to be used in the readAll request.

      By default, it sorts by priority in ascending order with Sort.NullHandling.NULLS_LAST strategy.

    • getPageSize

      protected int getPageSize()
    • buildNodeFilters

      protected cz.jirutka.rsql.parser.ast.Node buildNodeFilters()
      Builds the Node filters for the CancellationPolicyProvider.readAll(Node, Pageable, ContextInfo) requests.

      By default, it filters out policies that require direct reference.

      Returns:
      the Node filters
    • 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 evaluate
      cartItem - the cart item to evaluate against
      Returns:
      the Optional of 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 given CancellationPolicy is a match for the given CartItem based on the CancellationPolicy.getPolicyRules().
      Parameters:
      policy - the CancellationPolicy to evaluate
      cartItem - the CartItem to evaluate against
      Returns:
      true if the policy matches the item, otherwise false
    • buildPolicyRef

      protected com.broadleafcommerce.order.common.domain.subscription.CancellationPolicyRef buildPolicyRef(@NonNull C cancellationPolicy)
      Builds the CancellationPolicyRef based on the given CancellationPolicy.
      Parameters:
      cancellationPolicy - the CancellationPolicy to build the reference from
      Returns:
      the CancellationPolicyRef
    • getCancellationPolicyProvider

      protected CancellationPolicyProvider<C> getCancellationPolicyProvider()
    • getRuleEvaluationService

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

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