Class ProductVariantAttributeUpdateActionUtils


  • public final class ProductVariantAttributeUpdateActionUtils
    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.product.ProductUpdateAction> buildProductVariantAttributeUpdateAction​(long variantId, com.commercetools.api.models.product.Attribute oldProductVariantAttribute, com.commercetools.api.models.product.Attribute newProductVariantAttribute, java.util.Map<java.lang.String,​AttributeMetaData> attributesMetaData)
      Compares the attributes of a Attribute and a Attribute to build either a ProductSetAttributeAction or a ProductSetAttributeInAllVariantsAction.
      • Methods inherited from class java.lang.Object

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

      • ATTRIBUTE_NOT_IN_ATTRIBUTE_METADATA

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

      • buildProductVariantAttributeUpdateAction

        @Nonnull
        public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildProductVariantAttributeUpdateAction​(long variantId,
                                                                                                                                            @Nullable
                                                                                                                                            com.commercetools.api.models.product.Attribute oldProductVariantAttribute,
                                                                                                                                            @Nonnull
                                                                                                                                            com.commercetools.api.models.product.Attribute newProductVariantAttribute,
                                                                                                                                            @Nonnull
                                                                                                                                            java.util.Map<java.lang.String,​AttributeMetaData> attributesMetaData)
                                                                                                                                     throws BuildUpdateActionException
        Compares the attributes of a Attribute and a Attribute to build either a ProductSetAttributeAction or a ProductSetAttributeInAllVariantsAction.

        If the attribute is sameForAll a ProductSetAttributeInAllVariantsAction is built. Otherwise, a ProductSetAttributeAction is built.

        If both the Attribute and the Attribute have identical values, then no update action is needed and hence an empty List is returned.

        Parameters:
        variantId - the id of the variant of that the attribute belong to. It is used only in the error messages if any.
        oldProductVariantAttribute - the Attribute which should be updated.
        newProductVariantAttribute - the Attribute where we get the new value.
        attributesMetaData - a map of attribute name -> AttributeMetaData; which defines attribute information: its name and whether it has the constraint "SameForAll" or not.
        Returns:
        A filled optional with the update action or an empty optional if the attributes are identical.
        Throws:
        BuildUpdateActionException - thrown if attribute as not found in the attributeMetaData or if the attribute is required and the new value is null.