Class CartItemValidationActivity
java.lang.Object
com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartItemValidationActivity
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCartItemValidationActivity(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected CatalogItemRequestbuildCatalogItemRequest(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to create theCatalogItemRequestand populate any additional attributes that should be passed to theCatalogProviderwhen fetching the catalog representation for the cart item.protected Collection<CatalogItemRequest>buildCatalogItemRequests(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CheckoutWorkflowActivityExceptionbuildCheckoutWorkflowActivityException(DefaultCheckoutFailureTypes failureType, CheckoutProcessDto processDto) Builds an instance ofCheckoutWorkflowActivityExceptionfrom thefailureTypeexecute(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Method responsible for executing some work against the cart that is required for checkout.gatherCartItemConfigErrors(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gathers all of the config error messages for theCartIteminto a map.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsprotected StringgetCancellationFeeProductId(@NonNull CancellationPolicyDetail cancellationPolicyDetail) Retrieves the cancellationFeeProductId from theCancellationPolicyDetailconsidering the grace period duration.protected CartItemConfigurationService<? extends CatalogItem>protected CartSubscriptionUtilsprotected CatalogProvider<? extends CatalogItem>protected org.springframework.context.MessageSourceprotected com.broadleafcommerce.pricing.client.domain.context.PriceContextgetPriceContext(Locale locale, javax.money.CurrencyUnit currency) protected StaleCartItemsServiceprotected SubscriptionOpsProviderprotected com.broadleafcommerce.common.extension.TypeFactoryidentifyKeysForCatalogItems(CatalogItemList<? extends CatalogItem> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to collect the keys that will identify theCatalogItems.protected booleanisCancelSubscriptionAction(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Whether the current cart belongs to aDefaultSubscriptionActionFlow.CANCELflow.protected booleanisCartItemMissingCatalogItems(Set<String> catalogItemKeys, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if theCartItemdoes not have a backingCatalogItem.protected booleanisDuplicateCatalogItemRequest(@NonNull Set<CatalogItemRequest> catalogItemRequests, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.voidsetAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) voidsetCartSubscriptionUtils(CartSubscriptionUtils cartSubscriptionUtils) voidsetStaleCartItemsService(StaleCartItemsService staleCartItemsService) voidsetSubscriptionOpsProvider(SubscriptionOpsProvider subscriptionOpsProvider) voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected <C extends com.broadleafcommerce.cart.client.domain.CartItem>
voidvalidateCancellationFeeProductIsPresentInTheCartIfApplicable(@NonNull CheckoutProcessDto processDto, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<C> cartItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that theCancellationFeeProductis present as a cartItem in the cart if applicable.protected voidvalidateCartItems(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that each of the cart'sCartItemsinclude all necessary selections and dataprotected voidvalidateUserIsAuthenticatedIfApplicable(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CheckoutWorkflowActivity
rollback
-
Constructor Details
-
CartItemValidationActivity
public CartItemValidationActivity(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource)
-
-
Method Details
-
execute
public CheckoutProcessDto execute(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CheckoutWorkflowActivityMethod 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:
executein interfaceCheckoutWorkflowActivity- Parameters:
processDto- TheCheckoutProcessDtothat we're attempting to checkout with.contextInfo- Context information around sandbox and multitenant state.- Returns:
- The final state of the
CheckoutProcessDtofollowing 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'sCartItemsinclude all necessary selections and data- Parameters:
processDto- theCheckoutProcessDtobeing used for checkoutcontextInfo- 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 theCancellationFeeProductis present as a cartItem in the cart if applicable. This is executed only when the cart is in theDefaultSubscriptionActionFlow.CANCELflow.- Parameters:
processDto- theCheckoutProcessDtobeing processed for checkoutcart- theCartbeing processed for checkoutcartItems- theCollectionofcartItemspresent in the cartcontextInfo- additional info around sandboxing and multi-tenancy- Throws:
CheckoutWorkflowActivityException- if theCancellationFeeProductis not present in the cart despite being applicable, or thegetSubscriptionOpsProvider()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 aDefaultSubscriptionActionFlow.CANCELflow.- 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 theCancellationPolicyDetailconsidering the grace period duration.- Parameters:
cancellationPolicyDetail- TheCancellationPolicyDetailfrom 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 ofCheckoutWorkflowActivityExceptionfrom thefailureType- Parameters:
failureType- the failure type fromDefaultCheckoutFailureTypesprocessDto- theCheckoutProcessDtobeing used for checkout- Returns:
- the
CheckoutWorkflowActivityExceptionwith 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 theCartIteminto 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 ofCartItemConfigurationService#catalogItemRequestAlreadyExists(Set, String, String)Hook point to prevent duplicateCatalogItemRequestsfrom being built based on theCartItem.By default, we filter on the product ID.
- Parameters:
catalogItemRequests- the list of requests to pass to theCatalogProvidercartItem- theCartItemto build theCatalogItemRequestcontextInfo- context information around sandbox and multitenant state- Returns:
- true if building a new
CatalogItemRequestwould be a duplicate of an existing request incatalogItemRequests
-
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 theCatalogItemRequestand populate any additional attributes that should be passed to theCatalogProviderwhen fetching the catalog representation for the cart item.- Parameters:
cartItem- theCartItemto build theCatalogItemRequestcontextInfo- context information around sandbox and multitenant state- Returns:
- the populated
CatalogItemRequestfor theCartItem
-
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 theCatalogItems.- Parameters:
catalogItemList- the list ofCatalogItemscontextInfo- 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 theCartItemdoes not have a backingCatalogItem.By default, the keys are checked against the cart item's product ID.
- Parameters:
catalogItemKeys- the set of identifying keys for the catalog itemscartItem- the cart item to checkcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- true if the
cartItemdoes not have a backingCatalogItem
-
getPriceContext
@Nullable protected com.broadleafcommerce.pricing.client.domain.context.PriceContext getPriceContext(@Nullable Locale locale, @Nullable javax.money.CurrencyUnit currency) -
getCatalogProvider
-
getCartItemConfigurationService
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
setStaleCartItemsService
-
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
-
setCartSubscriptionUtils
-
getCartSubscriptionUtils
-
setAuthenticationUtils
@Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) -
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
-
CartItemConfigurationService#catalogItemRequestAlreadyExists(Set, String, String)