Class LineItemUpdateActionUtils


  • public final class LineItemUpdateActionUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildChangeLineItemQuantityUpdateAction​(io.sphere.sdk.shoppinglists.LineItem oldLineItem, io.sphere.sdk.shoppinglists.LineItemDraft newLineItem)
      Compares the quantity values of a LineItem and a LineItemDraft and returns an Optional of update action, which would contain the "changeLineItemQuantity" UpdateAction.
      static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemCustomUpdateActions​(io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList, io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList, io.sphere.sdk.shoppinglists.LineItem oldLineItem, io.sphere.sdk.shoppinglists.LineItemDraft newLineItem, ShoppingListSyncOptions syncOptions)
      Compares the custom fields and custom types of a LineItem and a LineItemDraft and returns a list of UpdateAction<ShoppingList> as a result.
      static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemsUpdateActions​(io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList, io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList, ShoppingListSyncOptions syncOptions)
      Compares a list of LineItems with a list of LineItemDrafts.
      static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemUpdateActions​(io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList, io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList, io.sphere.sdk.shoppinglists.LineItem oldLineItem, io.sphere.sdk.shoppinglists.LineItemDraft newLineItem, ShoppingListSyncOptions syncOptions)
      Compares all the fields of a LineItem and a LineItemDraft and returns a list of UpdateAction<ShoppingList> as a result.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • buildLineItemsUpdateActions

        @Nonnull
        public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemsUpdateActions​(@Nonnull
                                                                                                                                                io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList,
                                                                                                                                                @Nonnull
                                                                                                                                                io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList,
                                                                                                                                                @Nonnull
                                                                                                                                                ShoppingListSyncOptions syncOptions)
        Compares a list of LineItems with a list of LineItemDrafts. The method takes in functions for building the required update actions (AddLineItem, RemoveLineItem and 1-1 update actions on line items (e.g. changeLineItemQuantity, setLineItemCustomType, etc..).

        If the list of new LineItemDrafts is null, then remove actions are built for every existing line item.

        Parameters:
        oldShoppingList - shopping list resource, whose line item should be updated.
        newShoppingList - new shopping list draft, which contains the line item to update.
        syncOptions - responsible for supplying the sync options to the sync utility method. It is used for triggering the error callback within the utility, in case of errors.
        Returns:
        a list of line item update actions on the resource of shopping lists, if the list of line items are not identical. Otherwise, if the line items are identical, an empty list is returned.
      • buildLineItemUpdateActions

        @Nonnull
        public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemUpdateActions​(@Nonnull
                                                                                                                                               io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList,
                                                                                                                                               @Nonnull
                                                                                                                                               io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList,
                                                                                                                                               @Nonnull
                                                                                                                                               io.sphere.sdk.shoppinglists.LineItem oldLineItem,
                                                                                                                                               @Nonnull
                                                                                                                                               io.sphere.sdk.shoppinglists.LineItemDraft newLineItem,
                                                                                                                                               @Nonnull
                                                                                                                                               ShoppingListSyncOptions syncOptions)
        Compares all the fields of a LineItem and a LineItemDraft and returns a list of UpdateAction<ShoppingList> as a result. If both the LineItem and the LineItemDraft have identical fields, then no update action is needed and hence an empty List is returned.
        Parameters:
        oldShoppingList - shopping list resource, whose line item should be updated.
        newShoppingList - new shopping list draft, which contains the line item to update.
        oldLineItem - the line item which should be updated.
        newLineItem - the line item draft where we get the new fields (i.e. quantity, custom fields and types).
        syncOptions - responsible for supplying the sync options to the sync utility method. It is used for triggering the error callback within the utility, in case of errors.
        Returns:
        A list with the update actions or an empty list if the line item fields are identical.
      • buildChangeLineItemQuantityUpdateAction

        @Nonnull
        public static java.util.Optional<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildChangeLineItemQuantityUpdateAction​(@Nonnull
                                                                                                                                                                io.sphere.sdk.shoppinglists.LineItem oldLineItem,
                                                                                                                                                                @Nonnull
                                                                                                                                                                io.sphere.sdk.shoppinglists.LineItemDraft newLineItem)
        Compares the quantity values of a LineItem and a LineItemDraft and returns an Optional of update action, which would contain the "changeLineItemQuantity" UpdateAction. If both LineItem and LineItemDraft have the same quantity values, then no update action is needed and empty optional will be returned.

        Note: If quantity from the newLineItem is null, the new quantity will be set to default value 1L. If quantity from the newLineItem is 0, then it means removing the line item.

        Parameters:
        oldLineItem - the line item which should be updated.
        newLineItem - the line item draft where we get the new quantity.
        Returns:
        A filled optional with the update action or an empty optional if the quantities are identical.
      • buildLineItemCustomUpdateActions

        @Nonnull
        public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.shoppinglists.ShoppingList>> buildLineItemCustomUpdateActions​(@Nonnull
                                                                                                                                                     io.sphere.sdk.shoppinglists.ShoppingList oldShoppingList,
                                                                                                                                                     @Nonnull
                                                                                                                                                     io.sphere.sdk.shoppinglists.ShoppingListDraft newShoppingList,
                                                                                                                                                     @Nonnull
                                                                                                                                                     io.sphere.sdk.shoppinglists.LineItem oldLineItem,
                                                                                                                                                     @Nonnull
                                                                                                                                                     io.sphere.sdk.shoppinglists.LineItemDraft newLineItem,
                                                                                                                                                     @Nonnull
                                                                                                                                                     ShoppingListSyncOptions syncOptions)
        Compares the custom fields and custom types of a LineItem and a LineItemDraft and returns a list of UpdateAction<ShoppingList> as a result. If both the LineItem and the LineItemDraft have identical custom fields and types, then no update action is needed and hence an empty List is returned.
        Parameters:
        oldShoppingList - shopping list resource, whose line item should be updated.
        newShoppingList - new shopping list draft, which contains the line item to update.
        oldLineItem - the line item which should be updated.
        newLineItem - the line item draft where we get the new custom fields and types.
        syncOptions - responsible for supplying the sync options to the sync utility method. It is used for triggering the error callback within the utility, in case of errors.
        Returns:
        A list with the custom field/type update actions or an empty list if the custom fields/types are identical.