Class ProductUpdateActionUtils
- java.lang.Object
-
- com.commercetools.sync.products.utils.ProductUpdateActionUtils
-
public final class ProductUpdateActionUtils 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.ProductUpdateAction>
buildAddToCategoryUpdateActions(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theList
ofCategoryReference
s of aProductDraft
and aProductProjection
.static java.util.List<com.commercetools.api.models.product.ProductUpdateAction>
buildChangeMasterVariantUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, ProductSyncOptions syncOptions)
Create update action, ifnewProduct
has#masterVariant#key
different thanoldProduct
staged#masterVariant#key
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildChangeNameUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
names of aProductDraft
and aProductProjection
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildChangeSlugUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
slugs of aProductDraft
and aProductProjection
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildPublishOrUnpublishUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, boolean hasNewUpdateActions)
Compares the 'published' field of aProductDraft
and aProductProjection
with the new update actions and hasStagedChanges of the old product.static java.util.List<com.commercetools.api.models.product.ProductUpdateAction>
buildRemoveFromCategoryUpdateActions(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theList
ofCategoryResourceIdentifier
CategoryReference
s of aProductDraft
and aProductProjection
.static java.util.List<com.commercetools.api.models.product.ProductUpdateAction>
buildSetCategoryOrderHintUpdateActions(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theCategoryOrderHints
of aProductDraft
and aProductProjection
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetDescriptionUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
descriptions of aProductDraft
and aProductProjection
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetMetaDescriptionUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta descriptions of aProductDraft
and aProduct
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetMetaKeywordsUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta keywordss of aProductDraft
and aProduct
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetMetaTitleUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta titles of aProductDraft
and aProduct
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetSearchKeywordsUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theSearchKeywords
of aProductDraft
and aProductProjection
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildSetTaxCategoryUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theTaxCategory
references of an oldProduct
and newProductDraft
.static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction>
buildTransitionStateUpdateAction(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct)
Compares theState
references of an oldProductProjection
and newProductDraft
.static java.util.List<com.commercetools.api.models.product.ProductUpdateAction>
buildVariantsUpdateActions(com.commercetools.api.models.product.ProductProjection oldProduct, com.commercetools.api.models.product.ProductDraft newProduct, ProductSyncOptions syncOptions, java.util.Map<java.lang.String,AttributeMetaData> attributesMetaData)
Compares the variants (including the master variants) of aProductDraft
and aProduct
.static java.util.List<com.commercetools.api.models.product.ProductVariantDraft>
getAllVariants(com.commercetools.api.models.product.ProductDraft productDraft)
Returns a list containing all the variants (including the master variant) of the suppliedProductDraft
.
-
-
-
Method Detail
-
buildChangeNameUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildChangeNameUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
names of aProductDraft
and aProductProjection
. It returns anProductChangeNameAction
as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same name, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new name.- Returns:
- A filled optional with the update action or an empty optional if the names are identical.
-
buildSetDescriptionUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetDescriptionUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
descriptions of aProductDraft
and aProductProjection
. It returns anProductSetDescriptionAction
as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same description, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new description.- Returns:
- A filled optional with the update action or an empty optional if the descriptions are identical.
-
buildChangeSlugUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildChangeSlugUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
slugs of aProductDraft
and aProductProjection
. It returns aProductChangeSlugAction
update action as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same slug, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new slug.- Returns:
- A filled optional with the update action or an empty optional if the slugs are identical.
-
buildAddToCategoryUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildAddToCategoryUpdateActions(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theList
ofCategoryReference
s of aProductDraft
and aProductProjection
. It returns aList
ofProductAddToCategoryAction
update actions as a result, if the old product needs to be added to a category to have the same set of categories as the new product. If both theProductProjection
and theProductDraft
have the same set of categories, then no update actions are needed and hence an emptyList
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new slug.- Returns:
- A list containing the update actions or an empty list if the category sets are identical.
-
buildSetCategoryOrderHintUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildSetCategoryOrderHintUpdateActions(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theCategoryOrderHints
of aProductDraft
and aProductProjection
. It returns aProductSetCategoryOrderHintAction
update action as a result in anList
. If both theProductProjection
and theProductDraft
have the same categoryOrderHints, then no update actions are needed and hence an emptyList
is returned.NOTE: Comparison is done against the staged projection of the old product.
ProductProjection
which should be updated.- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new categoryOrderHints.- Returns:
- A list containing the update actions or an empty list if the categoryOrderHints are identical.
-
buildRemoveFromCategoryUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildRemoveFromCategoryUpdateActions(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theList
ofCategoryResourceIdentifier
CategoryReference
s of aProductDraft
and aProductProjection
. It returns aList
ofProductRemoveFromCategoryAction
update actions as a result, if the old product needs to be removed from a category to have the same set of categories as the new product. If both theProductProjection
and theProductDraft
have the same set of categories, then no update actions are needed and hence an emptyList
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new slug.- Returns:
- A list containing the update actions or an empty list if the category sets are identical.
-
buildSetSearchKeywordsUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetSearchKeywordsUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theSearchKeywords
of aProductDraft
and aProductProjection
. It returns aProductSetSearchKeywordsAction
update action as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same search keywords, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new search keywords.- Returns:
- A filled optional with the update action or an empty optional if the search keywords are identical.
-
buildSetMetaDescriptionUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetMetaDescriptionUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta descriptions of aProductDraft
and aProduct
. It returns aProductSetMetaDescriptionAction
update action as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same meta description, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new meta description.- Returns:
- A filled optional with the update action or an empty optional if the meta descriptions are identical.
-
buildSetMetaKeywordsUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetMetaKeywordsUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta keywordss of aProductDraft
and aProduct
. It returns aProductSetMetaKeywordsAction
update action as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same meta keywords, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productProjection which should be updated.newProduct
- the product draft where we get the new meta keywords.- Returns:
- A filled optional with the update action or an empty optional if the meta keywords are identical.
-
buildSetMetaTitleUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetMetaTitleUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theLocalizedString
meta titles of aProductDraft
and aProduct
. It returns aProductSetMetaTitleAction
update action as a result in anOptional
. If both theProductProjection
and theProductDraft
have the same meta title, then no update action is needed and hence an emptyOptional
is returned.NOTE: Comparison is done against the staged projection of the old product.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new meta title.- Returns:
- A filled optional with the update action or an empty optional if the meta titles are identical.
-
buildVariantsUpdateActions
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildVariantsUpdateActions(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct, @Nonnull ProductSyncOptions syncOptions, @Nonnull java.util.Map<java.lang.String,AttributeMetaData> attributesMetaData)
Compares the variants (including the master variants) of aProductDraft
and aProduct
. It returns aList
of variant related update actions. For example:ProductAddVariantAction
ProductRemoveVariantAction
ProductChangeMasterVariantAction
ProductSetAttributeAction
ProductSetAttributeInAllVariantsAction
ProductSetSkuAction
ProductAddExternalImageAction
ProductRemoveImageAction
ProductAddPriceAction
- ... and more variant level update actions.
ProductProjection
and theProductDraft
have identical variants, then no update actions are needed and hence an emptyList
is returned.NOTE: Comparison is done against the staged projection of the old product.
ProductProjection
which should be updated.- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new meta title.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 (SeeProductSyncOptions
for more info).attributesMetaData
- a map of attribute name ->AttributeMetaData
; which defines attribute information: its name and whether it has the constraint "SameForAll" or not.- Returns:
- A list of product variant-specific update actions.
-
getAllVariants
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductVariantDraft> getAllVariants(@Nonnull com.commercetools.api.models.product.ProductDraft productDraft)
Returns a list containing all the variants (including the master variant) of the suppliedProductDraft
.- Parameters:
productDraft
- the product draft that has the variants and master variant that should be returned.- Returns:
- a list containing all the variants (including the master variant) of the supplied
ProductDraft
.
-
buildPublishOrUnpublishUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildPublishOrUnpublishUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct, boolean hasNewUpdateActions)
Compares the 'published' field of aProductDraft
and aProductProjection
with the new update actions and hasStagedChanges of the old product. Accordingly it returns aProductPublishAction
orProductUnpublishAction
update action as a result in anOptional
. Check the calculation table below for all different combinations named as states.Mapping of product publish/unpublish update action calculation State New draft publish Old product publish New update actions Old product hasStagedChanges Action State 1 false false false false - State 2 false false false true - State 3 false false true false - State 4 false false true true - State 5 false true false false unpublish State 6 false true false true unpublish State 7 false true true false unpublish State 8 false true true true unpublish State 9 true false false false publish State 10 true false false true publish State 11 true false true false publish State 12 true false true true publish State 13 true true false false - State 14 true true false true publish State 15 true true true false publish State 16 true true true true publish NOTE: Comparison is done against the staged projection of the old product. If the new product's 'published' field is null, then the default false value is assumed.
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft where we get the new published field value.hasNewUpdateActions
- the product draft has other update actions set.- Returns:
- A filled optional with the update action or an empty optional if the flag values are identical.
-
buildChangeMasterVariantUpdateAction
@Nonnull public static java.util.List<com.commercetools.api.models.product.ProductUpdateAction> buildChangeMasterVariantUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct, @Nonnull ProductSyncOptions syncOptions)
Create update action, ifnewProduct
has#masterVariant#key
different thanoldProduct
staged#masterVariant#key
.If update action is created - it is created of
newProduct.getMasterVariant().getSku()
If old master variant is missing in the new variants list - add
ProductRemoveVariantAction
action at the end.- Parameters:
oldProduct
- old productprojections with variantsnewProduct
- new product draft with variants with resolved references prices referencessyncOptions
- the sync options wrapper which contains options related to the sync process- Returns:
- a list of maximum two elements:
ProductChangeMasterVariantAction
if the keys are different, optionally followed byProductRemoveVariantAction
if the changed variant does not exist in the new variants list.
-
buildSetTaxCategoryUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildSetTaxCategoryUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theTaxCategory
references of an oldProduct
and newProductDraft
. If they are different - returnProductSetTaxCategoryAction
update action.If the old value is set, but the new one is empty - the command will unset the tax category.
ProductProjection
which should be updated.- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft with newTaxCategory
reference.- Returns:
- An optional with
ProductUpdateAction
update action.
-
buildTransitionStateUpdateAction
@Nonnull public static java.util.Optional<com.commercetools.api.models.product.ProductUpdateAction> buildTransitionStateUpdateAction(@Nonnull com.commercetools.api.models.product.ProductProjection oldProduct, @Nonnull com.commercetools.api.models.product.ProductDraft newProduct)
Compares theState
references of an oldProductProjection
and newProductDraft
. If they are different - returnProductTransitionStateAction
update action.If the old value is set, but the new one is empty - return empty object, because unset transition state is not possible.
Note: the transition state action is called with force == true, i.e. the platform won't verify transition
- Parameters:
oldProduct
- the productprojection which should be updated.newProduct
- the product draft with newState
reference.- Returns:
- An optional with
ProductTransitionStateAction
update action.
-
-