java.lang.Object
com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartItemValidationActivity
All Implemented Interfaces:
CheckoutWorkflowActivity

public class CartItemValidationActivity extends Object implements CheckoutWorkflowActivity
This CheckoutWorkflowActivity is responsible for validating that the cart's CartItems include all necessary selections and data so that we can clearly understand what is being purchased and must later be fulfilled.
Author:
Chad Harchar (charchar), Chris Kittrell (ckittrell)
  • Constructor Details

  • Method Details

    • execute

      public CheckoutProcessDto execute(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CheckoutWorkflowActivity
      Method responsible for executing some work against the cart that is required for checkout. This may include, but is not limited to, cart validation checks, inventory reservations, or payment authorizations.
      Specified by:
      execute in interface CheckoutWorkflowActivity
      Parameters:
      processDto - The CheckoutProcessDto that we're attempting to checkout with.
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The final state of the CheckoutProcessDto following the execution of the activity.
    • validateUserIsAuthenticatedIfApplicable

      protected void validateUserIsAuthenticatedIfApplicable(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateCartItems

      protected void validateCartItems(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that each of the cart's CartItems include all necessary selections and data
      Parameters:
      processDto - the CheckoutProcessDto being used for checkout
      contextInfo - Context information around sandbox and multitenant state.
      Throws:
      CheckoutWorkflowActivityException - thrown if an unrecoverable error is encountered during the execution of the activity
    • validateCancellationFeeProductIsPresentInTheCartIfApplicable

      protected <C extends com.broadleafcommerce.cart.client.domain.CartItem> void validateCancellationFeeProductIsPresentInTheCartIfApplicable(@NonNull @NonNull CheckoutProcessDto processDto, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<C> cartItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the CancellationFeeProduct is present as a cartItem in the cart if applicable. This is executed only when the cart is in the DefaultSubscriptionActionFlow.CANCEL flow.
      Parameters:
      processDto - the CheckoutProcessDto being processed for checkout
      cart - the Cart being processed for checkout
      cartItems - the Collection of cartItems present in the cart
      contextInfo - additional info around sandboxing and multi-tenancy
      Throws:
      CheckoutWorkflowActivityException - if the CancellationFeeProduct is not present in the cart despite being applicable, or the getSubscriptionOpsProvider() is null.
      Since:
      Cart Operation Service 2.3.0, Release Train 2.3.0
    • isCancelSubscriptionAction

      protected boolean isCancelSubscriptionAction(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Whether the current cart belongs to a DefaultSubscriptionActionFlow.CANCEL flow.
      Parameters:
      cart - the cart whose status is to be determined
      Returns:
      true if the cart is in a Cancel flow
      Since:
      Cart Operation Service 2.3.0, Release Train 2.3.0
    • getCancellationFeeProductId

      protected String getCancellationFeeProductId(@NonNull @NonNull CancellationPolicyDetail cancellationPolicyDetail)
      Retrieves the cancellationFeeProductId from the CancellationPolicyDetail considering the grace period duration.
      Parameters:
      cancellationPolicyDetail - The CancellationPolicyDetail from which to extract the feeProductId
      Returns:
      The cancellationFeeProductId
      Since:
      Cart Operation Service 2.3.0, Release Train 2.3.0
    • buildCheckoutWorkflowActivityException

      protected CheckoutWorkflowActivityException buildCheckoutWorkflowActivityException(DefaultCheckoutFailureTypes failureType, CheckoutProcessDto processDto)
      Builds an instance of CheckoutWorkflowActivityException from the failureType
      Parameters:
      failureType - the failure type from DefaultCheckoutFailureTypes
      processDto - the CheckoutProcessDto being used for checkout
      Returns:
      the CheckoutWorkflowActivityException with its custom failure message
      Since:
      Cart Operation Service 2.3.0, Release Train 2.3.0
    • gatherCartItemConfigErrors

      protected Map<String,String> gatherCartItemConfigErrors(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Gathers all of the config error messages for the CartItem into a map.
      Parameters:
      cartItem -
      Returns:
      the map of CartItem config error messages
    • buildCatalogItemRequests

      protected Collection<CatalogItemRequest> buildCatalogItemRequests(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • isDuplicateCatalogItemRequest

      @Deprecated(forRemoval=true, since="Cart Operation Service 2.3.0, Release Train 2.3.0") protected boolean isDuplicateCatalogItemRequest(@NonNull @NonNull Set<CatalogItemRequest> catalogItemRequests, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of CartItemConfigurationService#catalogItemRequestAlreadyExists(Set, String, String)
      Hook point to prevent duplicate CatalogItemRequests from being built based on the CartItem.

      By default, we filter on the product ID.

      Parameters:
      catalogItemRequests - the list of requests to pass to the CatalogProvider
      cartItem - the CartItem to build the CatalogItemRequest
      contextInfo - context information around sandbox and multitenant state
      Returns:
      true if building a new CatalogItemRequest would be a duplicate of an existing request in catalogItemRequests
    • buildCatalogItemRequest

      protected CatalogItemRequest buildCatalogItemRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Hook point to create the CatalogItemRequest and populate any additional attributes that should be passed to the CatalogProvider when fetching the catalog representation for the cart item.
      Parameters:
      cartItem - the CartItem to build the CatalogItemRequest
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the populated CatalogItemRequest for the CartItem
    • identifyKeysForCatalogItems

      protected Set<String> identifyKeysForCatalogItems(CatalogItemList<? extends CatalogItem> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Hook point to collect the keys that will identify the CatalogItems.
      Parameters:
      catalogItemList - the list of CatalogItems
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the set of identifying keys for the catalog items
    • isCartItemMissingCatalogItems

      protected boolean isCartItemMissingCatalogItems(Set<String> catalogItemKeys, com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Hook point to determine if the CartItem does not have a backing CatalogItem.

      By default, the keys are checked against the cart item's product ID.

      Parameters:
      catalogItemKeys - the set of identifying keys for the catalog items
      cartItem - the cart item to check
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      true if the cartItem does not have a backing CatalogItem
    • getPriceContext

      @Nullable protected com.broadleafcommerce.pricing.client.domain.context.PriceContext getPriceContext(@Nullable Locale locale, @Nullable javax.money.CurrencyUnit currency)
    • getCatalogProvider

      protected CatalogProvider<? extends CatalogItem> getCatalogProvider()
    • getCartItemConfigurationService

      protected CartItemConfigurationService<? extends CatalogItem> getCartItemConfigurationService()
    • getMessageSource

      protected org.springframework.context.MessageSource getMessageSource()
    • setStaleCartItemsService

      @Autowired public void setStaleCartItemsService(StaleCartItemsService staleCartItemsService)
    • getStaleCartItemsService

      protected StaleCartItemsService getStaleCartItemsService()
    • setTypeFactory

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • getTypeFactory

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

      @Autowired(required=false) public void setSubscriptionOpsProvider(@Nullable SubscriptionOpsProvider subscriptionOpsProvider)
    • getSubscriptionOpsProvider

      @Nullable protected SubscriptionOpsProvider getSubscriptionOpsProvider()
    • setCartSubscriptionUtils

      @Autowired public void setCartSubscriptionUtils(CartSubscriptionUtils cartSubscriptionUtils)
    • getCartSubscriptionUtils

      protected CartSubscriptionUtils getCartSubscriptionUtils()
    • setAuthenticationUtils

      @Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
    • getAuthenticationUtils

      protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()