public final class ProductVariantUpdateActionUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FAILED_TO_BUILD_ATTRIBUTE_UPDATE_ACTION |
static java.lang.String |
NULL_PRODUCT_VARIANT_ATTRIBUTE |
Modifier and Type | Method and Description |
---|---|
static java.util.List<io.sphere.sdk.products.commands.updateactions.MoveImageToPosition> |
buildMoveImageToPositionUpdateActions(int variantId,
java.util.List<io.sphere.sdk.products.Image> oldImages,
java.util.List<io.sphere.sdk.products.Image> newImages)
Compares an old
List of Image s and a new one and returns a List of
MoveImageToPosition with the given variantId . |
static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> |
buildProductVariantAssetsUpdateActions(io.sphere.sdk.products.ProductVariant oldProductVariant,
io.sphere.sdk.products.ProductVariantDraft newProductVariant,
ProductSyncOptions syncOptions)
Compares the
List of AssetDraft s of a ProductVariantDraft and a
ProductVariant and returns a List of UpdateAction <Product >. |
static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> |
buildProductVariantAttributesUpdateActions(java.lang.String productKey,
io.sphere.sdk.products.ProductVariant oldProductVariant,
io.sphere.sdk.products.ProductVariantDraft newProductVariant,
java.util.Map<java.lang.String,AttributeMetaData> attributesMetaData,
ProductSyncOptions syncOptions)
Compares the attributes of a
ProductVariantDraft and a ProductVariant to build either
SetAttribute or
SetAttributeInAllVariants update actions. |
static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> |
buildProductVariantImagesUpdateActions(io.sphere.sdk.products.ProductVariant oldProductVariant,
io.sphere.sdk.products.ProductVariantDraft newProductVariant)
Compares the
List of Image s of a ProductVariantDraft and a ProductVariant and
returns a List of UpdateAction <Product >. |
static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> |
buildProductVariantPricesUpdateActions(io.sphere.sdk.products.ProductVariant oldProductVariant,
io.sphere.sdk.products.ProductVariantDraft newProductVariant,
ProductSyncOptions syncOptions)
Compares the
List of Price s of a ProductVariantDraft and a
ProductVariant and returns a List of UpdateAction <Product >. |
static java.util.Optional<io.sphere.sdk.products.commands.updateactions.SetSku> |
buildProductVariantSkuUpdateAction(io.sphere.sdk.products.ProductVariant oldProductVariant,
io.sphere.sdk.products.ProductVariantDraft newProductVariant)
Compares the SKUs of a
ProductVariantDraft and a ProductVariant . |
public static final java.lang.String FAILED_TO_BUILD_ATTRIBUTE_UPDATE_ACTION
public static final java.lang.String NULL_PRODUCT_VARIANT_ATTRIBUTE
@Nonnull public static java.util.Optional<io.sphere.sdk.products.commands.updateactions.SetSku> buildProductVariantSkuUpdateAction(@Nonnull io.sphere.sdk.products.ProductVariant oldProductVariant, @Nonnull io.sphere.sdk.products.ProductVariantDraft newProductVariant)
ProductVariantDraft
and a ProductVariant
. It returns a SetSku
update action as a result in an Optional
. If both the ProductVariantDraft
and the ProductVariant
have identical identical SKUs, then no update action is needed and hence an
empty Optional
is returned.oldProductVariant
- the variant which should be updated.newProductVariant
- the variant draft where we get the new SKU.@Nonnull public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> buildProductVariantPricesUpdateActions(@Nonnull io.sphere.sdk.products.ProductVariant oldProductVariant, @Nonnull io.sphere.sdk.products.ProductVariantDraft newProductVariant, @Nonnull ProductSyncOptions syncOptions)
List
of Price
s of a ProductVariantDraft
and a
ProductVariant
and returns a List
of UpdateAction
<Product
>. If both the
ProductVariantDraft
and the ProductVariant
have identical list of prices, then no update action
is needed and hence an empty List
is returned.oldProductVariant
- the ProductVariant
which should be updated.newProductVariant
- the ProductVariantDraft
where we get the new list of prices.syncOptions
- the sync options wrapper which contains options related to the sync process supplied by
the user. For example, custom callbacks to call in case of warnings or errors occurring
on the build update action process. And other options (See ProductSyncOptions
for more info).@Nonnull public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> buildProductVariantImagesUpdateActions(@Nonnull io.sphere.sdk.products.ProductVariant oldProductVariant, @Nonnull io.sphere.sdk.products.ProductVariantDraft newProductVariant)
List
of Image
s of a ProductVariantDraft
and a ProductVariant
and
returns a List
of UpdateAction
<Product
>. If both the ProductVariantDraft
and the ProductVariant
have identical list of images, then no update action is needed and hence an
empty List
is returned.oldProductVariant
- the ProductVariant
which should be updated.newProductVariant
- the ProductVariantDraft
where we get the new list of images.public static java.util.List<io.sphere.sdk.products.commands.updateactions.MoveImageToPosition> buildMoveImageToPositionUpdateActions(int variantId, @Nonnull java.util.List<io.sphere.sdk.products.Image> oldImages, @Nonnull java.util.List<io.sphere.sdk.products.Image> newImages)
List
of Image
s and a new one and returns a List
of
MoveImageToPosition
with the given variantId
. If both the lists are identical, then no update
action is needed and hence an empty List
is returned.
This method expects the two lists two contain the same images only in different order. Otherwise, an
IllegalArgumentException
would be thrown.
Note: the solution is still not optimized and may contain MoveImageToPosition
actions
for items which are already on desired positions (after previous moves in the sequence). This will be
re-optimized in the next releases. TODO: GITHUB ISSUE#133
variantId
- the variantId for the MoveImageToPosition
update actions.oldImages
- the old list of images.newImages
- the new list of images.@Nonnull public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> buildProductVariantAssetsUpdateActions(@Nonnull io.sphere.sdk.products.ProductVariant oldProductVariant, @Nonnull io.sphere.sdk.products.ProductVariantDraft newProductVariant, @Nonnull ProductSyncOptions syncOptions)
List
of AssetDraft
s of a ProductVariantDraft
and a
ProductVariant
and returns a List
of UpdateAction
<Product
>. If both the
ProductVariantDraft
and the ProductVariant
have identical list of assets, then no update action
is needed and hence an empty List
is returned. In case, the new product variant draft has a list of
assets in which a duplicate key exists, the error callback is triggered and an empty list is returned.oldProductVariant
- the ProductVariant
which should be updated.newProductVariant
- the ProductVariantDraft
where we get the new list of assets.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.@Nonnull public static java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> buildProductVariantAttributesUpdateActions(@Nullable java.lang.String productKey, @Nonnull io.sphere.sdk.products.ProductVariant oldProductVariant, @Nonnull io.sphere.sdk.products.ProductVariantDraft newProductVariant, @Nonnull java.util.Map<java.lang.String,AttributeMetaData> attributesMetaData, @Nonnull ProductSyncOptions syncOptions)
ProductVariantDraft
and a ProductVariant
to build either
SetAttribute
or
SetAttributeInAllVariants
update actions.
If both the ProductVariantDraft
and the ProductVariant
have identical list of attributes, then
no update action is needed and hence an empty List
is returned.productKey
- the key of the product that the variants belong to. It is used only in the error
messages if any.oldProductVariant
- the ProductVariant
which should be updated.newProductVariant
- the ProductVariantDraft
where we get the new list of attributes.attributesMetaData
- a map of attribute name -> AttributeMetaData
; which defines attribute
information: its name, whether a value is required or not and whether it has the
constraint "SameForAll" or not.syncOptions
- the sync options wrapper which contains options related to the sync process supplied by
the user. For example, custom callbacks to call in case of warnings or errors occurring
on the build update action process. And other options (See ProductSyncOptions
for more info).