Class LineItemUpdateActionUtils
- java.lang.Object
-
- com.commercetools.sync.shoppinglists.utils.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 thequantity
values of aLineItem
and aLineItemDraft
and returns anOptional
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 aLineItem
and aLineItemDraft
and returns a list ofUpdateAction
<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 ofLineItem
s with a list ofLineItemDraft
s.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 aLineItem
and aLineItemDraft
and returns a list ofUpdateAction
<ShoppingList
> as a result.
-
-
-
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 ofLineItem
s with a list ofLineItemDraft
s. 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
LineItemDraft
s isnull
, 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 aLineItem
and aLineItemDraft
and returns a list ofUpdateAction
<ShoppingList
> as a result. If both theLineItem
and theLineItemDraft
have identical fields, then no update action is needed and hence an emptyList
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 thequantity
values of aLineItem
and aLineItemDraft
and returns anOptional
of update action, which would contain the"changeLineItemQuantity"
UpdateAction
. If bothLineItem
andLineItemDraft
have the samequantity
values, then no update action is needed and empty optional will be returned.Note: If
quantity
from thenewLineItem
isnull
, the newquantity
will be set to default value1L
. Ifquantity
from thenewLineItem
is0
, 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 aLineItem
and aLineItemDraft
and returns a list ofUpdateAction
<ShoppingList
> as a result. If both theLineItem
and theLineItemDraft
have identical custom fields and types, then no update action is needed and hence an emptyList
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.
-
-