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 thequantityvalues of aShoppingListLineItemand aShoppingListLineItemDraftand returns anOptionalof 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 aShoppingListLineItemand aShoppingListLineItemDraftand returns a list ofShoppingListUpdateActionas 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 ofShoppingListLineItems with a list ofShoppingListLineItemDrafts.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 aShoppingListLineItemand aShoppingListLineItemDraftand returns a list ofShoppingListUpdateActionas 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 ofShoppingListLineItems with a list ofShoppingListLineItemDrafts. 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
ShoppingListLineItemDrafts 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 aShoppingListLineItemand aShoppingListLineItemDraftand returns a list ofShoppingListUpdateActionas a result. If both theShoppingListLineItemand theShoppingListLineItemDrafthave identical fields, then no update action is needed and hence an emptyListis 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 thequantityvalues of aShoppingListLineItemand aShoppingListLineItemDraftand returns anOptionalof update action, which would contain the"changeLineItemQuantity"ShoppingListUpdateAction. If bothShoppingListLineItemandShoppingListLineItemDrafthave the samequantityvalues, then no update action is needed and empty optional will be returned.Note: If
quantityfrom thenewLineItemisnull, the newquantitywill be set to default value1L. Ifquantityfrom thenewLineItemis0, 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 aShoppingListLineItemand aShoppingListLineItemDraftand returns a list ofShoppingListUpdateActionas a result. If both theShoppingListLineItemand theShoppingListLineItemDrafthave identical custom fields and types, then no update action is needed and hence an emptyListis 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.
-
-