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<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildChangeLineItemQuantityUpdateAction(com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem)
Compares thequantity
values of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns anOptional
of update action, which would contain the"changeLineItemQuantity"
ShoppingListUpdateAction
.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildLineItemCustomUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem, ShoppingListSyncOptions syncOptions)
Compares the custom fields and custom types of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildLineItemsUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, ShoppingListSyncOptions syncOptions)
Compares a list ofShoppingListLineItem
s with a list ofShoppingListLineItemDraft
s.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildLineItemUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem, ShoppingListSyncOptions syncOptions)
Compares all the fields of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result.
-
-
-
Method Detail
-
buildLineItemsUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildLineItemsUpdateActions(@Nonnull com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, @Nonnull ShoppingListSyncOptions syncOptions)
Compares a list ofShoppingListLineItem
s with a list ofShoppingListLineItemDraft
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
ShoppingListLineItemDraft
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<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildLineItemUpdateActions(@Nonnull com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem, @Nonnull ShoppingListSyncOptions syncOptions)
Compares all the fields of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result. If both theShoppingListLineItem
and theShoppingListLineItemDraft
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<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildChangeLineItemQuantityUpdateAction(@Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem)
Compares thequantity
values of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns anOptional
of update action, which would contain the"changeLineItemQuantity"
ShoppingListUpdateAction
. If bothShoppingListLineItem
andShoppingListLineItemDraft
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<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildLineItemCustomUpdateActions(@Nonnull com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItem oldLineItem, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListLineItemDraft newLineItem, @Nonnull ShoppingListSyncOptions syncOptions)
Compares the custom fields and custom types of aShoppingListLineItem
and aShoppingListLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result. If both theShoppingListLineItem
and theShoppingListLineItemDraft
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.
-
-