Class CustomUpdateActionUtils
- java.lang.Object
-
- com.commercetools.sync.commons.utils.CustomUpdateActionUtils
-
public final class CustomUpdateActionUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <ResourceDraftT,CustomT extends Custom,CustomDraftT extends CustomDraft,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>
java.util.List<ResourceUpdateActionT>buildCustomUpdateActions(ResourceDraftT newMainResourceDraft, CustomT oldResource, CustomDraftT newResourceDraft, GenericCustomActionBuilder<ResourceUpdateActionT> customActionBuilder, java.lang.Long variantId, java.util.function.Function<CustomT,java.lang.String> resourceIdGetter, java.util.function.Function<CustomT,java.lang.String> resourceTypeIdGetter, java.util.function.Function<CustomT,java.lang.String> updateIdGetter, BaseSyncOptions syncOptions)
Compares theCustomFields
of an old resourceT
(for exampleCategory
,Product
, etc..), to theCustomFieldsDraft
, of a new resource draftS
(for exampleCategoryDraft
,ProductVariantDraft
, etc..), and returns aList
<ResourceUpdateAction
> as a result.static <CustomT extends Custom,CustomDraftT extends CustomDraft,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>
java.util.List<ResourceUpdateActionT>buildPrimaryResourceCustomUpdateActions(CustomT oldResource, CustomDraftT newResource, GenericCustomActionBuilder<ResourceUpdateActionT> customActionBuilder, BaseSyncOptions syncOptions)
This method is a syntactic sugar for the methodbuildCustomUpdateActions(com.commercetools.sync.commons.models.Custom, com.commercetools.sync.commons.models.CustomDraft, com.commercetools.sync.commons.helpers.GenericCustomActionBuilder, Long, Function, Function, Function, com.commercetools.sync.commons.BaseSyncOptions)
but this one is only for primary resources (i.e resources which have their own endpoints for example channels, categories, inventory entries.
-
-
-
Method Detail
-
buildPrimaryResourceCustomUpdateActions
@Nonnull public static <CustomT extends Custom,CustomDraftT extends CustomDraft,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>> java.util.List<ResourceUpdateActionT> buildPrimaryResourceCustomUpdateActions(@Nonnull CustomT oldResource, @Nonnull CustomDraftT newResource, @Nonnull GenericCustomActionBuilder<ResourceUpdateActionT> customActionBuilder, @Nonnull BaseSyncOptions syncOptions)
This method is a syntactic sugar for the methodbuildCustomUpdateActions(com.commercetools.sync.commons.models.Custom, com.commercetools.sync.commons.models.CustomDraft, com.commercetools.sync.commons.helpers.GenericCustomActionBuilder, Long, Function, Function, Function, com.commercetools.sync.commons.BaseSyncOptions)
but this one is only for primary resources (i.e resources which have their own endpoints for example channels, categories, inventory entries. For more details of the inner logic and different scenarios, check the Javadoc of the other method.- Type Parameters:
CustomT
- the type of the oldCustom
which has the custom fields.CustomDraftT
- the type of the new resourceCustomDraft
.ResourceUpdateActionT
- extends ResourceUpdateAction (e.gCustomerChangeEmailAction
- Parameters:
oldResource
- the resource which should be updated.newResource
- the resource draft where we get the new custom fields.customActionBuilder
- the builder instance responsible for building the custom update actions.syncOptions
- responsible for supplying the sync options to the sync utility method.- Returns:
- a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
- See Also:
)
-
buildCustomUpdateActions
@Nonnull public static <ResourceDraftT,CustomT extends Custom,CustomDraftT extends CustomDraft,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>> java.util.List<ResourceUpdateActionT> buildCustomUpdateActions(@Nullable ResourceDraftT newMainResourceDraft, @Nonnull CustomT oldResource, @Nonnull CustomDraftT newResourceDraft, @Nonnull GenericCustomActionBuilder<ResourceUpdateActionT> customActionBuilder, @Nullable java.lang.Long variantId, @Nonnull java.util.function.Function<CustomT,java.lang.String> resourceIdGetter, @Nonnull java.util.function.Function<CustomT,java.lang.String> resourceTypeIdGetter, @Nonnull java.util.function.Function<CustomT,java.lang.String> updateIdGetter, @Nonnull BaseSyncOptions syncOptions)
Compares theCustomFields
of an old resourceT
(for exampleCategory
,Product
, etc..), to theCustomFieldsDraft
, of a new resource draftS
(for exampleCategoryDraft
,ProductVariantDraft
, etc..), and returns aList
<ResourceUpdateAction
> as a result. If no update action is needed, for example in the case where both theCustomFields
and theCustomFieldsDraft
are null, an emptyList
<ResourceUpdateAction
> is returned. ABaseSyncOptions
instance is injected into the method which is responsible for supplying the sync options to the sync utility method. For example, custom error callbacks for errors. TheTypeService
is injected also for fetching the key of the old resource type from it's cache (seebuildNonNullCustomFieldsUpdateActions(CustomFields, CustomFieldsDraft, Custom, GenericCustomActionBuilder, Long, Function, Function, Function, BaseSyncOptions)
).An update action will be added to the result list in the following cases:-
- If the new resources's custom type is set, but old resources's custom type is not. A "setCustomType" update actions is added, which sets the custom type (and all it's fields to the old resource).
- If the new resource's custom type is not set, but the old resource's custom type is set. A "setCustomType" update action is added, which removes the type set on the old resource.
- If both the resources custom types are the same and the custom fields are both set. The
custom field values of both resources are then calculated. (see
buildSetCustomFieldsUpdateActions(Map, Map, Custom, GenericCustomActionBuilder, Long, Function)
)}) - If the keys of both custom types are different, then a "setCustomType" update action is added, where the old resource's custom type is set to be as the new one's.
- If both resources custom type keys are identical but the custom fields of the new resource's custom type is not set.
An update action will not be added to the result list in the following cases:-
- If both the resources' custom types are not set.
- If both the resources' custom type keys are not set.
- Custom fields are both empty.
- Custom field JSON values have different ordering.
- Custom field values are identical.
- Type Parameters:
ResourceDraftT
- the type of the newBaseResource
which is the superBaseResource
of the Resource to update.CustomT
- the type of the oldCustom
which has the custom fields.CustomDraftT
- the type of the new resourceCustomDraft
.ResourceUpdateActionT
- extends ResourceUpdateAction (e.gCustomerChangeEmailAction
- Parameters:
newMainResourceDraft
- the main resource of the resource draft where we get the new custom fields.oldResource
- the resource which should be updated.newResourceDraft
- the resource draft where we get the new custom fields.customActionBuilder
- the builder instance responsible for building the custom update actions.variantId
- optional field representing the variant id in case the oldResource is an asset.resourceIdGetter
- a function used to get the id of the resource being updated.resourceTypeIdGetter
- a function used to get the Type id of the resource being updated.updateIdGetter
- a function used to get the id/key needed for updating the resource that has the custom fields.syncOptions
- responsible for supplying the sync options to the sync utility method.- Returns:
- a list that contains all the update actions needed, otherwise an empty list if no update actions are needed.
-
-