Class TextLineItemUpdateActionUtils
- java.lang.Object
-
- com.commercetools.sync.shoppinglists.utils.TextLineItemUpdateActionUtils
-
public final class TextLineItemUpdateActionUtils 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>
buildChangeTextLineItemNameUpdateAction(com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares theLocalizedString
names ofTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"changeTextLineItemName"
ShoppingListUpdateAction
.static java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildChangeTextLineItemQuantityUpdateAction(com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares thequantity
values of aTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"changeTextLineItemQuantity"
ShoppingListUpdateAction
.static java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildSetTextLineItemDescriptionUpdateAction(com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares theLocalizedString
descriptions ofTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"setTextLineItemDescription"
ShoppingListUpdateAction
.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildTextLineItemCustomUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem, ShoppingListSyncOptions syncOptions)
Compares the custom fields and custom types of aTextLineItem
and aTextLineItemDraft
and returns a list ofShoppingListUpdateAction
<ShoppingList
> as a result.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildTextLineItemsUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, ShoppingListSyncOptions syncOptions)
Compares a list ofTextLineItem
s with a list ofTextLineItemDraft
s.static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction>
buildTextLineItemUpdateActions(com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem, ShoppingListSyncOptions syncOptions)
Compares all the fields of aTextLineItem
and aTextLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result.
-
-
-
Method Detail
-
buildTextLineItemsUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildTextLineItemsUpdateActions(@Nonnull com.commercetools.api.models.shopping_list.ShoppingList oldShoppingList, @Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft newShoppingList, @Nonnull ShoppingListSyncOptions syncOptions)
Compares a list ofTextLineItem
s with a list ofTextLineItemDraft
s. The method takes in functions for building the required update actions (AddTextLineItem, RemoveTextLineItem and 1-1 update actions on text line items (e.g. changeTextLineItemQuantity, setTextLineItemCustomType, etc..).If the list of new
TextLineItemDraft
s isnull
, then remove actions are built for every existing text line item.- Parameters:
oldShoppingList
- shopping list resource, whose text line items should be updated.newShoppingList
- new shopping list draft, which contains the text line items 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 text line item update actions on the resource of shopping lists, if the list of text line items are not identical. Otherwise, if the text line items are identical, an empty list is returned.
-
buildTextLineItemUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildTextLineItemUpdateActions(@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.TextLineItem oldTextLineItem, @Nonnull com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem, @Nonnull ShoppingListSyncOptions syncOptions)
Compares all the fields of aTextLineItem
and aTextLineItemDraft
and returns a list ofShoppingListUpdateAction
as a result. If both theTextLineItem
and theTextLineItemDraft
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.oldTextLineItem
- the text line item which should be updated.newTextLineItem
- the text line item draft where we get the new fields (i.e. quantity, custom fields).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 text line item fields are identical.
-
buildChangeTextLineItemNameUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildChangeTextLineItemNameUpdateAction(@Nonnull com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, @Nonnull com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares theLocalizedString
names ofTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"changeTextLineItemName"
ShoppingListUpdateAction
. If both theTextLineItem
and theTextLineItemDraft
have the samedescription
values, then no update action is needed and hence an empty optional will be returned.- Parameters:
oldTextLineItem
- the text line item which should be updated.newTextLineItem
- the text line item draft where we get the new name.- Returns:
- A filled optional with the update action or an empty optional if the names are identical.
-
buildSetTextLineItemDescriptionUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildSetTextLineItemDescriptionUpdateAction(@Nonnull com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, @Nonnull com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares theLocalizedString
descriptions ofTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"setTextLineItemDescription"
ShoppingListUpdateAction
. If both theTextLineItem
and theTextLineItemDraft
have the samedescription
values, then no update action is needed and hence an empty optional will be returned.- Parameters:
oldTextLineItem
- the text line item which should be updated.newTextLineItem
- the text line item draft where we get the new description.- Returns:
- A filled optional with the update action or an empty optional if the descriptions are identical.
-
buildChangeTextLineItemQuantityUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildChangeTextLineItemQuantityUpdateAction(@Nonnull com.commercetools.api.models.shopping_list.TextLineItem oldTextLineItem, @Nonnull com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem)
Compares thequantity
values of aTextLineItem
and aTextLineItemDraft
and returns anOptional
of update action, which would contain the"changeTextLineItemQuantity"
ShoppingListUpdateAction
. If bothTextLineItem
andTextLineItemDraft
have the samequantity
values, then no update action is needed and empty optional will be returned.Note: If
quantity
from thenewTextLineItem
isnull
, the newquantity
will be set to default value1L
. Ifquantity
from thenewTextLineItem
is0
, then it means removing the text line item.- Parameters:
oldTextLineItem
- the text line item which should be updated.newTextLineItem
- the text 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.
-
buildTextLineItemCustomUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> buildTextLineItemCustomUpdateActions(@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.TextLineItem oldTextLineItem, @Nonnull com.commercetools.api.models.shopping_list.TextLineItemDraft newTextLineItem, @Nonnull ShoppingListSyncOptions syncOptions)
Compares the custom fields and custom types of aTextLineItem
and aTextLineItemDraft
and returns a list ofShoppingListUpdateAction
<ShoppingList
> as a result. If both theTextLineItem
and theTextLineItemDraft
have identical custom fields and types, then no update action is needed and hence an emptyList
is returned.- Parameters:
oldShoppingList
- shopping list resource, whose text line item should be updated.newShoppingList
- new shopping list draft, which contains the text line item to update.oldTextLineItem
- the text line item which should be updated.newTextLineItem
- the text 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.
-
-