Class DefaultCartResolverService

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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 getAuthenticationUtils()  
      protected CartApprovalValidationService getCartApprovalValidationService()  
      String getCartNotFoundMessage​(String cartId)  
      protected CartOperationService getCartOperationService()  
      protected CartVersionValidationService getCartVersionValidationService()  
      protected org.springframework.context.MessageSource getMessageSource()  
      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 isVisibleToCustomer​(String cartStatus)
      Returns whether a cart with the given status is allowed to viewed by a customer.
      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​(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)
      Resolves the given CustomerRef's implicit/default cart, which out of the box means an DefaultCartStatuses.IN_PROCESS cart with null name.
      void setCartApprovalValidationService​(CartApprovalValidationService cartApprovalValidationService)  
      void setCartVersionValidationService​(CartVersionValidationService cartVersionValidationService)  
      void setMessageSource​(org.springframework.context.MessageSource messageSource)  
    • Constructor Detail

      • DefaultCartResolverService

        public DefaultCartResolverService​(CartOperationService cartOperationService,
                                          com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
    • Method Detail

      • 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
      • 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)
        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.
        Specified by:
        resolveImplicitCart in interface CartResolverService
        Parameters:
        customer - the CustomerRef representing the currently authenticated user
        contextInfo - the context info
        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
      • 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
      • getAuthenticationUtils

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

        @Autowired
        public void setCartApprovalValidationService​(CartApprovalValidationService cartApprovalValidationService)
      • setCartVersionValidationService

        @Autowired
        public void setCartVersionValidationService​(CartVersionValidationService cartVersionValidationService)
      • getMessageSource

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

        @Autowired
        public void setMessageSource​(org.springframework.context.MessageSource messageSource)