Class 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.ResourceView>
      java.util.List<io.sphere.sdk.commands.UpdateAction<U>>
      buildCustomUpdateActions​(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 the CustomFields of an old resource T (for example Category, Product, etc..), to the CustomFieldsDraft, of a new resource draft S (for example CategoryDraft, ProductVariantDraft, etc..), and returns a List<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 method buildCustomUpdateActions(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 method buildCustomUpdateActions(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 old Resource which has the custom fields.
        S - the type of the new resource CustomDraft.
        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.ResourceView> java.util.List<io.sphere.sdk.commands.UpdateAction<U>> buildCustomUpdateActions​(@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 the CustomFields of an old resource T (for example Category, Product, etc..), to the CustomFieldsDraft, of a new resource draft S (for example CategoryDraft, ProductVariantDraft, etc..), and returns a List<UpdateAction> as a result. If no update action is needed, for example in the case where both the CustomFields and the CustomFieldsDraft are null, an empty List<UpdateAction> is returned. A BaseSyncOptions 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. The TypeService is injected also for fetching the key of the old resource type from it's cache (see buildNonNullCustomFieldsUpdateActions(CustomFields, CustomFieldsDraft, Custom, GenericCustomActionBuilder, Integer, Function, Function, Function, BaseSyncOptions)).

        An update action will be added to the result list in the following cases:-

        1. 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).
        2. 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.
        3. 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) )})
        4. 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.
        5. 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:-

        1. If both the resources' custom types are not set.
        2. If both the resources' custom type keys are not set.
        3. Custom fields are both empty.
        4. Custom field JSON values have different ordering.
        5. Custom field values are identical.
        Type Parameters:
        D - the type of the new Resource which is the super Resource of the Resource to update.
        T - the type of the old Resource which has the custom fields.
        S - the type of the new resource CustomDraft.
        U - the type of the resource in which the update actions will be applied on.
        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.