Class DefaultCartResolverService
- All Implemented Interfaces:
CartResolverService
- Author:
- Nick Crum (ncrum)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultCartResolverService
(CartOperationService cartOperationService, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
accountMatches
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer's account matches the cart owner's.protected boolean
accountMatchesHierarchy
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer's account is in the cart owner's account hierarchy.protected boolean
applicationMatches
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, String applicationId) protected boolean
cartOwnershipMatchWithCustomerRef
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.order.common.domain.CustomerRef customerRef) protected boolean
cartOwnershipMatchWithCustomerRef
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.order.common.domain.CustomerRef customerRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCart.getCustomerRef()
matches with the givenCustomerRef
.protected boolean
contextMatches
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
customerHasAccessToCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
customerMatches
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer matches the cart's owner.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected CartApprovalValidationService
getCartNotFoundMessage
(String cartId) protected CartOperationService
protected CartStatusManager
protected CartVersionValidationService
protected org.springframework.context.MessageSource
protected com.broadleafcommerce.common.extension.TypeFactory
protected boolean
isUserAnApprover
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.order.common.domain.CustomerRef customerRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is an account approver for the givenCart
with theDefaultCartStatuses.REQUIRES_APPROVAL
status.protected boolean
isVisibleToCustomer
(String cartStatus) Returns whether a cart with the given status is allowed to viewed by a customer.protected boolean
requestWorkflowHandlesAwaitingPaymentFinalizationStatus
(@NonNull ResolveCartRequest resolveCartRequest) Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCartById
(ResolveCartRequest resolveCartRequest, com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves aCart
given theResolveCartRequest
with the given cart id and data.Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCartById
(String cartId, com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves aCart
given the cart ID, customer, and context.Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveCartByStatus
(@NonNull Collection<String> statuses, @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves theCart
with the first matching status for the given customer and context.com.broadleafcommerce.cart.client.domain.Cart
resolveCartForStatusChange
(String cartId, Integer cartVersion, com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Similar toCartResolverService.resolveCartForUpdate(String, Integer, CustomerRef, ContextInfo)
except it will allow carts with statusDefaultCartStatuses.REQUIRES_APPROVAL
to have their statuses updated.com.broadleafcommerce.cart.client.domain.Cart
resolveCartForUpdate
(ResolveCartRequest resolveCartRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves the cart with additional validation that it can be updated by checking theCart.getVersion()
,Cart.getStatus()
, and sometimes theResolveCartRequest.getWorkflow()
.com.broadleafcommerce.cart.client.domain.Cart
resolveCartForUpdate
(String cartId, Integer cartVersion, com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves the cart with additional validation that it can be updated by checking theCart.getVersion()
andCart.getStatus()
.Optional<com.broadleafcommerce.cart.client.domain.Cart>
resolveImplicitCart
(@NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, boolean allowRepriceDueToStaleCartPrices) Resolves the givenCustomerRef
's implicit/default cart, which out of the box means anDefaultCartStatuses.IN_PROCESS
cart withnull
name.void
setCartApprovalValidationService
(CartApprovalValidationService cartApprovalValidationService) void
setCartStatusManager
(CartStatusManager cartStatusManager) void
setCartVersionValidationService
(CartVersionValidationService cartVersionValidationService) void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected boolean
userCanReadQuote
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.order.common.domain.CustomerRef customerRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
has access to the givenDefaultCartTypes.QUOTE
-typed cart.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.cartoperation.service.CartResolverService
resolveCartByStatus, resolveImplicitCart, resolveInProcessCart
-
Field Details
-
CART_NOT_FOUND_MESSAGE_FORMAT
- See Also:
-
-
Constructor Details
-
DefaultCartResolverService
public DefaultCartResolverService(CartOperationService cartOperationService, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
-
-
Method Details
-
resolveCartById
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCartById(String cartId, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Resolves aCart
given the cart ID, customer, and context.If the provided
CustomerRef
is not registered, this will resolve a guest cart for the given ID and context. If the cart is found to be a customer cart, this will return as empty, because an anonymous customer can only access guest carts.If the provided
CustomerRef
is registered, this will resolve a customer cart for the given customer, ID, and context. If the cart is found to be a guest cart, this will return as empty.If no cart is found, this will return an empty optional.
- Specified by:
resolveCartById
in interfaceCartResolverService
- Parameters:
cartId
- the cart IDcustomer
- the customercontextInfo
- the context info- Returns:
- an optional with a cart, or empty
-
resolveCartById
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCartById(ResolveCartRequest resolveCartRequest, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Resolves aCart
given theResolveCartRequest
with the given cart id and data.If the provided
CustomerRef
is not registered, this will resolve a guest cart for the given ID and context. If the cart is found to be a customer cart, this will return as empty, because an anonymous customer can only access guest carts.If the provided
CustomerRef
is registered, this will resolve a customer cart for the given customer, ID, and context. If the cart is found to be a guest cart, this will return as empty.If no cart is found, this will return an empty optional.
- Specified by:
resolveCartById
in interfaceCartResolverService
- Parameters:
resolveCartRequest
- the cart IDcustomer
- the customercontextInfo
- the context info- Returns:
- an optional with a cart, or empty
-
resolveCartByStatus
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveCartByStatus(@NonNull @NonNull Collection<String> statuses, @NonNull @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Resolves theCart
with the first matching status for the given customer and context.This method will iterate through each status, in given order, and attempt to retrieve a cart for that status. The first accessible cart retrieved for a status will be returned.
If no cart is found, this will return an empty optional.
- Specified by:
resolveCartByStatus
in interfaceCartResolverService
- Parameters:
statuses
- the statuses to checkcustomer
- the customercontextInfo
- the context info- Returns:
- an optional with a cart, or empty
-
resolveImplicitCart
public Optional<com.broadleafcommerce.cart.client.domain.Cart> resolveImplicitCart(@NonNull @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, boolean allowRepriceDueToStaleCartPrices) Description copied from interface:CartResolverService
Resolves the givenCustomerRef
's implicit/default cart, which out of the box means anDefaultCartStatuses.IN_PROCESS
cart withnull
name. By default,shouldReprice
is true since we want to reprice the cart. Only for the creation of a net new cart, it is set asfalse
- Specified by:
resolveImplicitCart
in interfaceCartResolverService
- Parameters:
customer
- theCustomerRef
representing the currently authenticated usercontextInfo
- the context infoallowRepriceDueToStaleCartPrices
- declares if repricing due to stale cart prices should be considered or skipped entirely- Returns:
- an optional with a cart, or empty
-
resolveCartForStatusChange
public com.broadleafcommerce.cart.client.domain.Cart resolveCartForStatusChange(String cartId, @Nullable Integer cartVersion, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Similar toCartResolverService.resolveCartForUpdate(String, Integer, CustomerRef, ContextInfo)
except it will allow carts with statusDefaultCartStatuses.REQUIRES_APPROVAL
to have their statuses updated. This enables the original requester of the approval to reclaim their cart to make changes.- Specified by:
resolveCartForStatusChange
in interfaceCartResolverService
- Parameters:
cartId
- Id of the cart to resolvecartVersion
- Cart version expectedcustomer
- Customer who owns the cartcontextInfo
- Additional sandbox and multitenant info- Returns:
- The matching cart if it's updatable
-
resolveCartForUpdate
public com.broadleafcommerce.cart.client.domain.Cart resolveCartForUpdate(String cartId, @Nullable Integer cartVersion, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Resolves the cart with additional validation that it can be updated by checking theCart.getVersion()
andCart.getStatus()
.- Specified by:
resolveCartForUpdate
in interfaceCartResolverService
- Parameters:
cartId
- Id of the cart to resolvecartVersion
- Cart version expectedcustomer
- Customer who owns the cartcontextInfo
- Additional sandbox and multitenant info- Returns:
- The matching cart if it's updatable
-
resolveCartForUpdate
public com.broadleafcommerce.cart.client.domain.Cart resolveCartForUpdate(ResolveCartRequest resolveCartRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartResolverService
Resolves the cart with additional validation that it can be updated by checking theCart.getVersion()
,Cart.getStatus()
, and sometimes theResolveCartRequest.getWorkflow()
.- Specified by:
resolveCartForUpdate
in interfaceCartResolverService
- Parameters:
resolveCartRequest
- theResolveCartRequest
containing the details for the cart resolutioncontextInfo
- Additional sandbox and multitenant info- Returns:
- The matching cart if it's updatable
-
getCartNotFoundMessage
- Specified by:
getCartNotFoundMessage
in interfaceCartResolverService
-
contextMatches
protected boolean contextMatches(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
applicationMatches
protected boolean applicationMatches(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable String applicationId) -
customerHasAccessToCart
protected boolean customerHasAccessToCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
cartOwnershipMatchWithCustomerRef
protected boolean cartOwnershipMatchWithCustomerRef(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customerRef) -
cartOwnershipMatchWithCustomerRef
protected boolean cartOwnershipMatchWithCustomerRef(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCart.getCustomerRef()
matches with the givenCustomerRef
.- Parameters:
cart
- theCart
to check the ownershipcustomerRef
- theCustomerRef
to check against- Returns:
- true if the cart ownership matches with the given
CustomerRef
, otherwise false
-
customerMatches
protected boolean customerMatches(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer matches the cart's owner.- Parameters:
cart
- The cart being resolvedcustomer
- The customer requested the cart- Returns:
- Whether the customer matches the cart's owner.
-
accountMatches
protected boolean accountMatches(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer's account matches the cart owner's.- Parameters:
cart
- The cart being resolvedcustomer
- The customer requested the cart- Returns:
- Whether the customer matches the cart owner's.
-
accountMatchesHierarchy
protected boolean accountMatchesHierarchy(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.order.common.domain.CustomerRef customer) Whether the customer's account is in the cart owner's account hierarchy.- Parameters:
cart
- The cart being resolvedcustomer
- The customer requested the cart- Returns:
- Whether the customer's account is in the cart owner's account hierarchy.
-
isVisibleToCustomer
Returns whether a cart with the given status is allowed to viewed by a customer.- Parameters:
cartStatus
- The status of the cart in question.- Returns:
- Whether a cart with the given status is allowed to viewed by a customer.
-
isUserAnApprover
protected boolean isUserAnApprover(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is an account approver for the givenCart
with theDefaultCartStatuses.REQUIRES_APPROVAL
status.- Parameters:
cart
- theCart
that requires approvalcustomerRef
- theCustomerRef
to check- Returns:
- true if the given
CustomerRef
is an account approver for the givenCart
, otherwise false
-
userCanReadQuote
protected boolean userCanReadQuote(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.order.common.domain.CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
has access to the givenDefaultCartTypes.QUOTE
-typed cart.- Parameters:
cart
- theDefaultCartTypes.QUOTE
-typed cart to validatecustomerRef
- theCustomerRef
representing the currently authenticated usercontextInfo
- the contextInfo for the request- Returns:
- true if the given
CustomerRef
can access the quote, otherwise false
-
requestWorkflowHandlesAwaitingPaymentFinalizationStatus
protected boolean requestWorkflowHandlesAwaitingPaymentFinalizationStatus(@NonNull @NonNull ResolveCartRequest resolveCartRequest) -
getCartOperationService
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils() -
getCartApprovalValidationService
-
setCartApprovalValidationService
@Autowired public void setCartApprovalValidationService(CartApprovalValidationService cartApprovalValidationService) -
getCartVersionValidationService
-
setCartVersionValidationService
@Autowired public void setCartVersionValidationService(CartVersionValidationService cartVersionValidationService) -
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
setMessageSource
@Autowired public void setMessageSource(org.springframework.context.MessageSource messageSource) -
getCartStatusManager
-
setCartStatusManager
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-