Class DefaultCancellationPolicyService

java.lang.Object
com.broadleafcommerce.cartoperation.service.subscription.DefaultCancellationPolicyService
All Implemented Interfaces:
CancellationPolicyService

public class DefaultCancellationPolicyService extends Object implements CancellationPolicyService
Default implementation of CancellationPolicyService.
Since:
Cart Operation Service 2.3.0, Release Train 2.3.0
Author:
Sunny Yu
  • Constructor Details

    • DefaultCancellationPolicyService

      public DefaultCancellationPolicyService(SubscriptionOpsProvider subscriptionOpsProvider, CartSubscriptionUtils cartSubscriptionUtils, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • populateCancellationPolicies

      public com.broadleafcommerce.cart.client.domain.Cart populateCancellationPolicies(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CancellationPolicyService
      Populates the CartItem.getCancellationPolicyRef() for the given Cart.getCartItems().
      Specified by:
      populateCancellationPolicies in interface CancellationPolicyService
      Parameters:
      cart - the Cart containing the items to populate the cancellation policy for
      contextInfo - the current context
      Returns:
      the updated Cart
    • requiresCancellationPolicy

      protected boolean requiresCancellationPolicy(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Checks if the given CartItem requires a cancellation policy.

      By default, it checks whether the item is a Broadleaf subscription item

      Parameters:
      cartItem - the CartItem to check
      Returns:
      true if the given CartItem requires a cancellation policy, otherwise false
    • identifyCancellationPolicyFromCandidates

      protected List<com.broadleafcommerce.cart.client.domain.CartItem> identifyCancellationPolicyFromCandidates(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> itemsRequiresPolicy)
      Identifies and sets the cancellation policy for the given CartItems from the CartItem.getCandidateCancellationPolicies().

      For any items that could not have a cancellation policy identified, they will be returned in the result.

      Parameters:
      cart - the Cart that the given CartItems belong to
      itemsRequiresPolicy - the CartItems to identify the cancellation policy for
      Returns:
      the CartItems that still require a cancellation policy
    • findCancellationPolicy

      protected Optional<com.broadleafcommerce.order.common.domain.subscription.CancellationPolicyRef> findCancellationPolicy(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Finds the cancellation policy for the given cart item from CartItem.getCandidateCancellationPolicies().

      The method first looks for a CancellationPolicyRef with a DefaultCancellationPolicySourceTypes.BLC_PRICE_DATA, then DefaultCancellationPolicySourceTypes.BLC_PRODUCT.

      Parameters:
      cart - the Cart that the given CartItem belongs to
      cartItem - the CartItem to find the cancellation policy for
      Returns:
      an Optional containing the CancellationPolicyRef if found, otherwise empty
    • buildIdentifyCancellationPolicyRequest

      protected <T extends com.broadleafcommerce.cart.client.domain.CartItem> IdentifyCancellationPolicyRequest buildIdentifyCancellationPolicyRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<T> cartItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • populateCancellationPolicyForItem

      protected <T extends com.broadleafcommerce.order.common.domain.subscription.CancellationPolicyRef> void populateCancellationPolicyForItem(@NonNull @NonNull Map<String,T> policyByCartItemId, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem item)
      Populates the cancellation policy for the given CartItem.
      Parameters:
      policyByCartItemId - the map of CartItem.getId() to the matching CancellationPolicyRef
      item - the CartItem to populate the cancellation policy for
      Throws:
      com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if the cancellation policy for the given CartItem is not found
    • getSubscriptionOpsProvider

      protected SubscriptionOpsProvider getSubscriptionOpsProvider()
    • getCartSubscriptionUtils

      protected CartSubscriptionUtils getCartSubscriptionUtils()
    • getTypeFactory

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