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 <D,T extends io.sphere.sdk.types.Custom,S extends io.sphere.sdk.types.CustomDraft,U extends io.sphere.sdk.models.Resource<U>>
java.util.List<io.sphere.sdk.commands.UpdateAction<U>>buildCustomUpdateActions(io.sphere.sdk.models.Resource oldMainResource, D newMainResourceDraft, T oldResource, S newResourceDraft, GenericCustomActionBuilder<U> customActionBuilder, java.lang.Integer variantId, java.util.function.Function<T,java.lang.String> resourceIdGetter, java.util.function.Function<T,java.lang.String> resourceTypeIdGetter, java.util.function.Function<T,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
<UpdateAction
> as a result.static <T extends io.sphere.sdk.types.Custom & io.sphere.sdk.models.Resource<T>,S extends io.sphere.sdk.types.CustomDraft>
java.util.List<io.sphere.sdk.commands.UpdateAction<T>>buildPrimaryResourceCustomUpdateActions(T oldResource, S newResource, GenericCustomActionBuilder<T> customActionBuilder, BaseSyncOptions syncOptions)
This method is a syntactic sugar for the methodbuildCustomUpdateActions(Resource, Object, Custom, CustomDraft, GenericCustomActionBuilder, Integer, Function, Function, Function, 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 <T extends io.sphere.sdk.types.Custom & io.sphere.sdk.models.Resource<T>,S extends io.sphere.sdk.types.CustomDraft> java.util.List<io.sphere.sdk.commands.UpdateAction<T>> buildPrimaryResourceCustomUpdateActions(@Nonnull T oldResource, @Nonnull S newResource, @Nonnull GenericCustomActionBuilder<T> customActionBuilder, @Nonnull BaseSyncOptions syncOptions)
This method is a syntactic sugar for the methodbuildCustomUpdateActions(Resource, Object, Custom, CustomDraft, GenericCustomActionBuilder, Integer, Function, Function, Function, 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:
T
- the type of the oldResource
which has the custom fields.S
- the type of the new resourceCustomDraft
.- 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 <D,T extends io.sphere.sdk.types.Custom,S extends io.sphere.sdk.types.CustomDraft,U extends io.sphere.sdk.models.Resource<U>> java.util.List<io.sphere.sdk.commands.UpdateAction<U>> buildCustomUpdateActions(@Nullable io.sphere.sdk.models.Resource oldMainResource, @Nullable D newMainResourceDraft, @Nonnull T oldResource, @Nonnull S newResourceDraft, @Nonnull GenericCustomActionBuilder<U> customActionBuilder, @Nullable java.lang.Integer variantId, @Nonnull java.util.function.Function<T,java.lang.String> resourceIdGetter, @Nonnull java.util.function.Function<T,java.lang.String> resourceTypeIdGetter, @Nonnull java.util.function.Function<T,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
<UpdateAction
> as a result. If no update action is needed, for example in the case where both theCustomFields
and theCustomFieldsDraft
are null, an emptyList
<UpdateAction
> 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, Integer, 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, Integer, 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:
D
- the type of the newResource
which is the superResource
of the Resource to update.T
- the type of the oldResource
which has the custom fields.S
- the type of the new resourceCustomDraft
.U
- the type of the resource in which the update actions will be applied on.- Parameters:
oldMainResource
- the main resource of the resource which should be updated.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.
-
-