Class ExternalCartProvider

    • Constructor Summary

      Constructors 
      Constructor Description
      ExternalCartProvider​(org.springframework.web.reactive.function.client.WebClient webClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExternalCartProperties properties, CartHolder<com.broadleafcommerce.cart.client.domain.Cart> requestCartHolder)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected StaleCartException cartConflict​(Integer requestCartVersion, String cartId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, org.springframework.web.reactive.function.client.WebClientResponseException.Conflict conflictException)
      Builds an exception when a CONFLICT exception is thrown from the Cart Service, indicating that an optimistic lock failure occurred.
      com.broadleafcommerce.cart.client.domain.Cart createCart​(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Create a new cart.
      com.broadleafcommerce.cart.client.domain.Cart createNonRequestCart​(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Create a new cart, without updating the original request cart.
      void deleteCartItem​(String cartId, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Delete the cart item.
      protected int findCartItemIndex​(com.broadleafcommerce.cart.client.domain.Cart cart, String itemId)
      Finds the index at which the cart item with the given ID is at.
      protected String getServiceClient()  
      com.broadleafcommerce.cart.client.domain.Cart patchCart​(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Patch the cart.
      protected com.broadleafcommerce.cart.client.domain.Cart populateCurrency​(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)  
      protected com.broadleafcommerce.cart.client.domain.Cart resolveCartFromConflict​(org.springframework.web.reactive.function.client.WebClientResponseException.Conflict conflict)
      Attempts to extract a fresh version of the cart from the CONFLICT error's response body.
      protected Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCart​(String retrieveCartUrl, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Method for retrieving a single, optional cart.
      protected com.broadleafcommerce.cart.client.domain.Cart retrieveCartAfterConflict​(String cartId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Retrieves the latest version of the cart following a conflict error if possible.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCartById​(String cartId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Retrieve the cart.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCartByOrderNumber​(String customerId, String orderNumber, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Find the cart (if it exists) for the provided customer id and order number.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCsrOwnedCart​(String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Retrieve the DefaultCartStatuses.CSR_OWNED cart for the provided customer.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCustomerCartByStatus​(String customerId, String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds a cart with the given status belonging to the provided customer.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveHistoricalCartForAnonymousCustomer​(String emailAddress, String orderNumber, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds a single, historical cart for an anonymous customer.
      SimplePage<com.broadleafcommerce.cart.client.domain.Cart> retrieveHistoricalCartsForCustomer​(String customerId, Date startDate, Date endDate, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Find all carts not DefaultCartStatuses.IN_PROCESS, DefaultCartStatuses.CSR_OWNED, or DefaultCartStatuses.NAMED for the provided customer and dates.
      Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveInProcessCart​(String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Retrieve the DefaultCartStatuses.IN_PROCESS cart for the provided customer.
      protected void syncItemToCart​(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Takes changes made from an update to a single item and applies them to the cart and items in it.
      com.broadleafcommerce.cart.client.domain.Cart updateCart​(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Update the cart.
      com.broadleafcommerce.cart.client.domain.CartItem updateCartItem​(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Update the cart item.
      protected com.broadleafcommerce.cart.client.domain.Cart updateRequestCart​(com.broadleafcommerce.cart.client.domain.Cart cart)
      This updates the cart for the current request with a recently received version from the cart service.
    • Constructor Detail

      • ExternalCartProvider

        public ExternalCartProvider​(org.springframework.web.reactive.function.client.WebClient webClient,
                                    com.fasterxml.jackson.databind.ObjectMapper objectMapper,
                                    com.broadleafcommerce.common.extension.TypeFactory typeFactory,
                                    ExternalCartProperties properties,
                                    CartHolder<com.broadleafcommerce.cart.client.domain.Cart> requestCartHolder)
    • Method Detail

      • retrieveInProcessCart

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveInProcessCart​(String customerId,
                                                                                             @Nullable
                                                                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Retrieve the DefaultCartStatuses.IN_PROCESS cart for the provided customer.
        Specified by:
        retrieveInProcessCart in interface CartProvider
        Parameters:
        customerId - The id of the customer for which we are attempting to find an DefaultCartStatuses.IN_PROCESS cart.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        Retrieve the DefaultCartStatuses.IN_PROCESS cart for the provided customer.
      • retrieveCsrOwnedCart

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCsrOwnedCart​(String customerId,
                                                                                            @Nullable
                                                                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Retrieve the DefaultCartStatuses.CSR_OWNED cart for the provided customer.
        Specified by:
        retrieveCsrOwnedCart in interface CartProvider
        Parameters:
        customerId - The id of the customer for which we are attempting to find an DefaultCartStatuses.CSR_OWNED cart.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        Retrieve the DefaultCartStatuses.CSR_OWNED cart for the provided customer.
      • retrieveCustomerCartByStatus

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCustomerCartByStatus​(String customerId,
                                                                                                    String status,
                                                                                                    @Nullable
                                                                                                    com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Finds a cart with the given status belonging to the provided customer.
        Specified by:
        retrieveCustomerCartByStatus in interface CartProvider
        Parameters:
        customerId - the customer ID
        status - the status
        contextInfo - the context info
        Returns:
        a cart if it exists
      • retrieveCartByOrderNumber

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCartByOrderNumber​(String customerId,
                                                                                                 String orderNumber,
                                                                                                 @Nullable
                                                                                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Find the cart (if it exists) for the provided customer id and order number.
        Specified by:
        retrieveCartByOrderNumber in interface CartProvider
        Parameters:
        customerId - the id of the customer who owns the cart
        orderNumber - the order number for the cart
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        a cart (if it exists) with the given order number that belongs to the provided customer
      • retrieveHistoricalCartsForCustomer

        public SimplePage<com.broadleafcommerce.cart.client.domain.Cart> retrieveHistoricalCartsForCustomer​(String customerId,
                                                                                                            @Nullable
                                                                                                            Date startDate,
                                                                                                            @Nullable
                                                                                                            Date endDate,
                                                                                                            @Nullable
                                                                                                            org.springframework.data.domain.Pageable page,
                                                                                                            @Nullable
                                                                                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Find all carts not DefaultCartStatuses.IN_PROCESS, DefaultCartStatuses.CSR_OWNED, or DefaultCartStatuses.NAMED for the provided customer and dates.
        Specified by:
        retrieveHistoricalCartsForCustomer in interface CartProvider
        Parameters:
        customerId - the id of the customer who owns the carts
        startDate - the starting date to filter carts by
        endDate - the ending date to filter carts by
        page - the requested page of results from the database
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        all carts not DefaultCartStatuses.IN_PROCESS or DefaultCartStatuses.NAMED for the provided customer and dates.
      • retrieveHistoricalCartForAnonymousCustomer

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveHistoricalCartForAnonymousCustomer​(String emailAddress,
                                                                                                                  String orderNumber,
                                                                                                                  @Nullable
                                                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Finds a single, historical cart for an anonymous customer.
        Specified by:
        retrieveHistoricalCartForAnonymousCustomer in interface CartProvider
        Parameters:
        emailAddress - The email address associated with the cart
        orderNumber - The historical cart's order number
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The single, historical cart for an anonymous customer
      • retrieveCartById

        public Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCartById​(String cartId,
                                                                                        @Nullable
                                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Retrieve the cart.
        Specified by:
        retrieveCartById in interface CartProvider
        Parameters:
        cartId - The id of the cart on which to perform the operation.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The cart for the provided id.
      • createNonRequestCart

        public com.broadleafcommerce.cart.client.domain.Cart createNonRequestCart​(@NonNull
                                                                                  @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                  @Nullable
                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Create a new cart, without updating the original request cart.
        Specified by:
        createNonRequestCart in interface CartProvider
        Parameters:
        cart - The cart to create
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The created cart.
      • createCart

        public com.broadleafcommerce.cart.client.domain.Cart createCart​(@NonNull
                                                                        @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                        @Nullable
                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Create a new cart.
        Specified by:
        createCart in interface CartProvider
        Parameters:
        cart - The cart to create
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The created cart.
      • updateCart

        public com.broadleafcommerce.cart.client.domain.Cart updateCart​(@NonNull
                                                                        @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                        @Nullable
                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Update the cart.
        Specified by:
        updateCart in interface CartProvider
        Parameters:
        cart - The cart on which to perform the operation.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The updated cart.
      • patchCart

        public com.broadleafcommerce.cart.client.domain.Cart patchCart​(@NonNull
                                                                       @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                       @Nullable
                                                                       com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Patch the cart. A patch does not replace the cart, but partially updates it using any non-null fields.
        Specified by:
        patchCart in interface CartProvider
        Parameters:
        cart - The cart on which to perform the operation.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The patched cart.
      • updateCartItem

        public com.broadleafcommerce.cart.client.domain.CartItem updateCartItem​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                                                @Nullable
                                                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Update the cart item.
        Specified by:
        updateCartItem in interface CartProvider
        Parameters:
        cart - the cart the item belongs to
        cartItem - The cart item on which to perform the operation.
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        The updated cart item.
      • deleteCartItem

        public void deleteCartItem​(String cartId,
                                   com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                   @Nullable
                                   com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: CartProvider
        Delete the cart item.
        Specified by:
        deleteCartItem in interface CartProvider
        Parameters:
        cartId - the ID of the card the item belongs to
        cartItem - The cart item on which to perform the operation.
        contextInfo - Context information around sandbox and multitenant state.
      • retrieveCart

        protected Optional<com.broadleafcommerce.cart.client.domain.Cart> retrieveCart​(String retrieveCartUrl,
                                                                                       @Nullable
                                                                                       com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Method for retrieving a single, optional cart. This will handle adding headers and attributes and handle errors in a common way. 404 results in returning Optional.empty().
        Parameters:
        retrieveCartUrl - Fully built URL specifying the endpoint to hit and including query params
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        a single, optional cart.
        Throws:
        ProviderApiException - if an error occurs during or from the request such as a 500 response
      • populateCurrency

        protected com.broadleafcommerce.cart.client.domain.Cart populateCurrency​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                                                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • findCartItemIndex

        protected int findCartItemIndex​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                        String itemId)
        Finds the index at which the cart item with the given ID is at.
        Parameters:
        cart - the cart to search through
        itemId - the ID of the item to find the index of
        Returns:
        the index of the cart item
        Throws:
        com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - when no item with the given ID exists
      • syncItemToCart

        protected void syncItemToCart​(com.broadleafcommerce.cart.client.domain.Cart cart,
                                      com.broadleafcommerce.cart.client.domain.CartItem cartItem)
        Takes changes made from an update to a single item and applies them to the cart and items in it.
        Parameters:
        cart - the cart to apply updates to
        cartItem - the updated version of the item that was just update
      • updateRequestCart

        protected com.broadleafcommerce.cart.client.domain.Cart updateRequestCart​(com.broadleafcommerce.cart.client.domain.Cart cart)
        This updates the cart for the current request with a recently received version from the cart service. This should be called after calling any endpoint which leaves the cart in an out of date state. For example, an update on the cart will result in a completely new cart instance being returned from the cart service. That new instance should be run through this method. This will ignore carts that have a different ID than the one associated to the request.
        Parameters:
        cart - the cart to update the request context with
        Returns:
        the same cart provided for chaining purposes
      • cartConflict

        protected StaleCartException cartConflict​(Integer requestCartVersion,
                                                  @Nullable
                                                  String cartId,
                                                  @Nullable
                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo,
                                                  org.springframework.web.reactive.function.client.WebClientResponseException.Conflict conflictException)
        Builds an exception when a CONFLICT exception is thrown from the Cart Service, indicating that an optimistic lock failure occurred. This exception contains a freshly retrieved instance of the cart, allowing the client to update it's version of the cart to match.
        Parameters:
        requestCartVersion - the requested version of the cart
        cartId - the ID of the requested cart, or null if not known (in which case, fresh cart retrieval will be skipped)
        contextInfo - Context information around sandbox and multitenant state.
        conflictException - an exception representing the HTTP 409 (CONFLICT) error
        Returns:
        a stale cart exception with the freshly retrieved cart if able
      • resolveCartFromConflict

        @Nullable
        protected com.broadleafcommerce.cart.client.domain.Cart resolveCartFromConflict​(org.springframework.web.reactive.function.client.WebClientResponseException.Conflict conflict)
        Attempts to extract a fresh version of the cart from the CONFLICT error's response body.
        Parameters:
        conflict - the conflict exception that occurred while saving a cart
        Returns:
        the cart from the response body, or null if unavailable
      • retrieveCartAfterConflict

        @Nullable
        protected com.broadleafcommerce.cart.client.domain.Cart retrieveCartAfterConflict​(@Nullable
                                                                                          String cartId,
                                                                                          @Nullable
                                                                                          com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Retrieves the latest version of the cart following a conflict error if possible. See cartConflict(Integer, String, ContextInfo, WebClientResponseException.Conflict).
        Parameters:
        cartId - the ID of the relevant cart
        contextInfo - Context information around sandbox and multitenant state.
        Returns:
        the retrieved cart, or null if unable to retrieve
      • getServiceClient

        protected String getServiceClient()