Class DefaultCartResolverService

java.lang.Object
com.broadleafcommerce.cartoperation.service.DefaultCartResolverService
All Implemented Interfaces:
CartResolverService

public class DefaultCartResolverService extends Object implements CartResolverService
Author:
Nick Crum (ncrum)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultCartResolverService(CartOperationService cartOperationService, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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 given Cart.getCustomerRef() matches with the given CustomerRef.
    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 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 given CustomerRef is an account approver for the given Cart with the DefaultCartStatuses.REQUIRES_APPROVAL status.
    protected boolean
    Returns whether a cart with the given status is allowed to viewed by a customer.
    protected boolean
     
    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 a Cart given the ResolveCartRequest 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 a Cart 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 the Cart 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 to CartResolverService.resolveCartForUpdate(String, Integer, CustomerRef, ContextInfo) except it will allow carts with status DefaultCartStatuses.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 the Cart.getVersion(), Cart.getStatus(), and sometimes the ResolveCartRequest.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 the Cart.getVersion() and Cart.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 given CustomerRef's implicit/default cart, which out of the box means an DefaultCartStatuses.IN_PROCESS cart with null name.
    void
     
    void
     
    void
     
    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 given CustomerRef has access to the given DefaultCartTypes.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

  • 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 a Cart 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 interface CartResolverService
      Parameters:
      cartId - the cart ID
      customer - the customer
      contextInfo - 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 a Cart given the ResolveCartRequest 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 interface CartResolverService
      Parameters:
      resolveCartRequest - the cart ID
      customer - the customer
      contextInfo - 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 the Cart 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 interface CartResolverService
      Parameters:
      statuses - the statuses to check
      customer - the customer
      contextInfo - 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 given CustomerRef's implicit/default cart, which out of the box means an DefaultCartStatuses.IN_PROCESS cart with null 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 as false
      Specified by:
      resolveImplicitCart in interface CartResolverService
      Parameters:
      customer - the CustomerRef representing the currently authenticated user
      contextInfo - the context info
      allowRepriceDueToStaleCartPrices - 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 to CartResolverService.resolveCartForUpdate(String, Integer, CustomerRef, ContextInfo) except it will allow carts with status DefaultCartStatuses.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 interface CartResolverService
      Parameters:
      cartId - Id of the cart to resolve
      cartVersion - Cart version expected
      customer - Customer who owns the cart
      contextInfo - 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 the Cart.getVersion() and Cart.getStatus().
      Specified by:
      resolveCartForUpdate in interface CartResolverService
      Parameters:
      cartId - Id of the cart to resolve
      cartVersion - Cart version expected
      customer - Customer who owns the cart
      contextInfo - 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 the Cart.getVersion(), Cart.getStatus(), and sometimes the ResolveCartRequest.getWorkflow().
      Specified by:
      resolveCartForUpdate in interface CartResolverService
      Parameters:
      resolveCartRequest - the ResolveCartRequest containing the details for the cart resolution
      contextInfo - Additional sandbox and multitenant info
      Returns:
      The matching cart if it's updatable
    • getCartNotFoundMessage

      public String getCartNotFoundMessage(String cartId)
      Specified by:
      getCartNotFoundMessage in interface CartResolverService
    • 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 given Cart.getCustomerRef() matches with the given CustomerRef.
      Parameters:
      cart - the Cart to check the ownership
      customerRef - the CustomerRef 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 resolved
      customer - 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 resolved
      customer - 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 resolved
      customer - The customer requested the cart
      Returns:
      Whether the customer's account is in the cart owner's account hierarchy.
    • isVisibleToCustomer

      protected boolean isVisibleToCustomer(String cartStatus)
      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 given CustomerRef is an account approver for the given Cart with the DefaultCartStatuses.REQUIRES_APPROVAL status.
      Parameters:
      cart - the Cart that requires approval
      customerRef - the CustomerRef to check
      Returns:
      true if the given CustomerRef is an account approver for the given Cart, 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 given CustomerRef has access to the given DefaultCartTypes.QUOTE-typed cart.
      Parameters:
      cart - the DefaultCartTypes.QUOTE-typed cart to validate
      customerRef - the CustomerRef representing the currently authenticated user
      contextInfo - 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

      protected CartOperationService getCartOperationService()
    • getAuthenticationUtils

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

      protected CartApprovalValidationService getCartApprovalValidationService()
    • setCartApprovalValidationService

      @Autowired public void setCartApprovalValidationService(CartApprovalValidationService cartApprovalValidationService)
    • getCartVersionValidationService

      protected CartVersionValidationService 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

      protected CartStatusManager getCartStatusManager()
    • setCartStatusManager

      @Autowired public void setCartStatusManager(CartStatusManager cartStatusManager)
    • getTypeFactory

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

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