Class CartItemValidationActivity
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartItemValidationActivity
-
- All Implemented Interfaces:
CheckoutWorkflowActivity
public class CartItemValidationActivity extends Object implements CheckoutWorkflowActivity
ThisCheckoutWorkflowActivityis responsible for validating that the cart'sCartItemsinclude 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
Constructors Constructor Description CartItemValidationActivity(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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)CheckoutProcessDtoexecute(@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.protected Map<String,String>gatherCartItemConfigErrors(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)Gathers all of the config error messages for theCartIteminto a map.protected CartItemConfigurationService<? extends CatalogItem>getCartItemConfigurationService()protected CatalogProvider<? extends CatalogItem>getCatalogProvider()protected org.springframework.context.MessageSourcegetMessageSource()protected StaleCartItemsServicegetStaleCartItemsService()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected CatalogItemidentifyCatalogItemForCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList)protected Set<String>identifyKeysForCatalogItems(CatalogItemList<? extends CatalogItem> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Hook point to collect the keys that will identify theCatalogItems.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)Hook point to prevent duplicateCatalogItemRequestsfrom being built based on theCartItem.CheckoutProcessDtorollback(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Method responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)method.voidsetStaleCartItemsService(StaleCartItemsService staleCartItemsService)voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)protected voidvalidateCartItems(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Validates that each of the cart'sCartItemsinclude all necessary selections and data
-
-
-
Constructor Detail
-
CartItemValidationActivity
public CartItemValidationActivity(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource)
-
-
Method Detail
-
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.
-
rollback
public CheckoutProcessDto rollback(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CheckoutWorkflowActivityMethod responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)method.- Specified by:
rollbackin interfaceCheckoutWorkflowActivity- Parameters:
processDto- TheCheckoutProcessDtothat we were attempting to checkout with, but ran into an exception/error.contextInfo- Context information around sandbox and multitenant state.- Returns:
- The final state of the
CheckoutProcessDtofollowing the rollback of the activity.
-
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
-
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
-
identifyCatalogItemForCartItem
protected CatalogItem identifyCatalogItemForCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<? extends CatalogItem> catalogItemList)
-
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
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)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
-
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()
-
-