Class ProductVariantUpdateActionUtils


  • public final class ProductVariantUpdateActionUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<com.commercetools.api.models.product.ProductMoveImageToPositionAction> buildMoveImageToPositionUpdateActions​(long variantId, java.util.List<com.commercetools.api.models.common.Image> oldImages, java.util.List<com.commercetools.api.models.common.Image> newImages)
      Compares an old List of Images and a new one and returns a List of ProductMoveImageToPositionAction with the given variantId.
      static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantAssetsUpdateActions​(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, com.commercetools.api.models.product.ProductVariant oldProductVariant, com.commercetools.api.models.product.ProductVariantDraft newProductVariant, ProductSyncOptions syncOptions)
      Compares the List of AssetDrafts of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<Product>.
      static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantAttributesUpdateActions​(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, com.commercetools.api.models.product.ProductVariant oldProductVariant, com.commercetools.api.models.product.ProductVariantDraft newProductVariant, java.util.Map<java.lang.String,​AttributeMetaData> attributesMetaData, ProductSyncOptions syncOptions)
      Compares the attributes of a ProductVariantDraft and a ProductVariant to build either ProductSetAttributeAction or ProductSetAttributeInAllVariantsAction update actions.
      static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantImagesUpdateActions​(com.commercetools.api.models.product.ProductVariant oldProductVariant, com.commercetools.api.models.product.ProductVariantDraft newProductVariant)
      Compares the List of Images of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<Product>.
      static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantPricesUpdateActions​(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, com.commercetools.api.models.product.ProductVariant oldProductVariant, com.commercetools.api.models.product.ProductVariantDraft newProductVariant, ProductSyncOptions syncOptions)
      Compares the List of Prices of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<Product>.
      static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantSkuUpdateAction​(com.commercetools.api.models.product.ProductVariant oldProductVariant, com.commercetools.api.models.product.ProductVariantDraft newProductVariant)
      Compares the SKUs of a ProductVariantDraft and a ProductVariant.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FAILED_TO_BUILD_ATTRIBUTE_UPDATE_ACTION

        public static final java.lang.String FAILED_TO_BUILD_ATTRIBUTE_UPDATE_ACTION
        See Also:
        Constant Field Values
      • NULL_PRODUCT_VARIANT_ATTRIBUTE

        public static final java.lang.String NULL_PRODUCT_VARIANT_ATTRIBUTE
        See Also:
        Constant Field Values
    • Method Detail

      • buildProductVariantSkuUpdateAction

        @Nonnull
        public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantSkuUpdateAction​(@Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariant oldProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariantDraft newProductVariant)
        Compares the SKUs of a ProductVariantDraft and a ProductVariant. It returns a ProductSetSkuAction 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.
        Parameters:
        oldProductVariant - the variant which should be updated.
        newProductVariant - the variant draft where we get the new SKU.
        Returns:
        A filled optional with the update action or an empty optional if the SKUs are identical.
      • buildProductVariantPricesUpdateActions

        @Nonnull
        public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantPricesUpdateActions​(@Nullable
                                                                                                                                      com.commercetools.api.models.product.ProductProjection oldProduct,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductDraft newProduct,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariant oldProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariantDraft newProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      ProductSyncOptions syncOptions)
        Compares the List of Prices of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<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.
        Parameters:
        oldProduct - the product which should be updated.
        newProduct - the product draft.
        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).
        Returns:
        a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
      • buildProductVariantImagesUpdateActions

        @Nonnull
        public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantImagesUpdateActions​(@Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariant oldProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariantDraft newProductVariant)
        Compares the List of Images of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<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.
        Parameters:
        oldProductVariant - the ProductVariant which should be updated.
        newProductVariant - the ProductVariantDraft where we get the new list of images.
        Returns:
        a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
      • buildMoveImageToPositionUpdateActions

        public static java.util.List<com.commercetools.api.models.product.ProductMoveImageToPositionAction> buildMoveImageToPositionUpdateActions​(long variantId,
                                                                                                                                                  @Nonnull
                                                                                                                                                  java.util.List<com.commercetools.api.models.common.Image> oldImages,
                                                                                                                                                  @Nonnull
                                                                                                                                                  java.util.List<com.commercetools.api.models.common.Image> newImages)
        Compares an old List of Images and a new one and returns a List of ProductMoveImageToPositionAction 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 ProductMoveImageToPositionAction actions for items which are already on desired positions (after previous moves in the sequence). This will be re-optimized in the next releases.

        Parameters:
        variantId - the variantId for the ProductMoveImageToPositionAction update actions.
        oldImages - the old list of images.
        newImages - the new list of images.
        Returns:
        a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
      • buildProductVariantAssetsUpdateActions

        @Nonnull
        public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantAssetsUpdateActions​(@Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductProjection oldProduct,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductDraft newProduct,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariant oldProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      com.commercetools.api.models.product.ProductVariantDraft newProductVariant,
                                                                                                                                      @Nonnull
                                                                                                                                      ProductSyncOptions syncOptions)
        Compares the List of AssetDrafts of a ProductVariantDraft and a ProductVariant and returns a List of ProductUpdateAction<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.
        Parameters:
        oldProduct - old Product, whose variant assets should be updated.
        newProduct - new product draft, which provides the assets to update.
        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.
        Returns:
        a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
      • buildProductVariantAttributesUpdateActions

        @Nonnull
        public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantAttributesUpdateActions​(@Nonnull
                                                                                                                                          com.commercetools.api.models.product.ProductProjection oldProduct,
                                                                                                                                          @Nonnull
                                                                                                                                          com.commercetools.api.models.product.ProductDraft newProduct,
                                                                                                                                          @Nonnull
                                                                                                                                          com.commercetools.api.models.product.ProductVariant oldProductVariant,
                                                                                                                                          @Nonnull
                                                                                                                                          com.commercetools.api.models.product.ProductVariantDraft newProductVariant,
                                                                                                                                          @Nonnull
                                                                                                                                          java.util.Map<java.lang.String,​AttributeMetaData> attributesMetaData,
                                                                                                                                          @Nonnull
                                                                                                                                          ProductSyncOptions syncOptions)
        Compares the attributes of a ProductVariantDraft and a ProductVariant to build either ProductSetAttributeAction or ProductSetAttributeInAllVariantsAction 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.
        Parameters:
        oldProduct - the product that the variants belong to. It is used only in the error messages if any.
        newProduct - the new product draft.
        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).
        Returns:
        a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.