Class BaseSyncOptions<U,​V>

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BaseSyncOptions​(io.sphere.sdk.client.SphereClient ctpClient, QuadConsumer<SyncException,​java.util.Optional<V>,​java.util.Optional<U>,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> errorCallback, TriConsumer<SyncException,​java.util.Optional<V>,​java.util.Optional<U>> warningCallback, int batchSize, TriFunction<java.util.List<io.sphere.sdk.commands.UpdateAction<U>>,​V,​U,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> beforeUpdateCallback, java.util.function.Function<V,​V> beforeCreateCallback, long cacheSize)  
    • Constructor Detail

      • BaseSyncOptions

        protected BaseSyncOptions​(@Nonnull
                                  io.sphere.sdk.client.SphereClient ctpClient,
                                  @Nullable
                                  QuadConsumer<SyncException,​java.util.Optional<V>,​java.util.Optional<U>,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> errorCallback,
                                  @Nullable
                                  TriConsumer<SyncException,​java.util.Optional<V>,​java.util.Optional<U>> warningCallback,
                                  int batchSize,
                                  @Nullable
                                  TriFunction<java.util.List<io.sphere.sdk.commands.UpdateAction<U>>,​V,​U,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> beforeUpdateCallback,
                                  @Nullable
                                  java.util.function.Function<V,​V> beforeCreateCallback,
                                  long cacheSize)
    • Method Detail

      • getCtpClient

        public io.sphere.sdk.client.SphereClient getCtpClient()
        Returns the SphereClient responsible for interaction with the target CTP project.
        Returns:
        the SphereClient responsible for interaction with the target CTP project.
      • getErrorCallback

        @Nullable
        public QuadConsumer<SyncException,​java.util.Optional<V>,​java.util.Optional<U>,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> getErrorCallback()
        Returns the errorCallback QuadConsumer<SyncException, Optional<V>, Optional<U>, List<UpdateAction<U>>> function set to this BaseSyncOptions. It represents the callback that is called whenever an event occurs during the sync process that represents an error.
        Returns:
        the errorCallback QuadConsumer<SyncException, Optional<V>, Optional<U>, List<UpdateAction<U>> function set to this BaseSyncOptions
      • applyWarningCallback

        public void applyWarningCallback​(@Nonnull
                                         SyncException exception,
                                         @Nullable
                                         U oldResource,
                                         @Nullable
                                         V newResourceDraft)
        Given an exception, oldResource and newResourceDraft this method calls the warningCallback function which is set to this instance of the BaseSyncOptions. If there warningCallback is null, this method does nothing.
        Parameters:
        exception - the exception to supply to the warningCallback function.
        oldResource - the old resource that is being compared to the new draft.
        newResourceDraft - the new resource draft that is being compared to the old resource.
      • applyErrorCallback

        public void applyErrorCallback​(@Nonnull
                                       SyncException exception,
                                       @Nullable
                                       U oldResource,
                                       @Nullable
                                       V newResourceDraft,
                                       @Nullable
                                       java.util.List<io.sphere.sdk.commands.UpdateAction<U>> updateActions)
        Given an errorMessage and an exception, this method calls the errorCallback function which is set to this instance of the BaseSyncOptions. If there errorCallback is null, this method does nothing.
        Parameters:
        exception - Throwable instance to supply as first param to the errorCallback function.
        oldResource - the old resource that is being compared to the new draft.
        newResourceDraft - the new resource draft that is being compared to the old resource.
        updateActions - the list of update actions.
      • getBatchSize

        public int getBatchSize()
        Gets the batch size used in the sync process. During the sync there is a need for fetching existing resources so that they can be compared with the new resource drafts. That's why the input is sliced into batches and then processed. It allows to reduce the query size for fetching all resources processed in one batch. E.g. value of 30 means that 30 entries from input list would be accumulated and one API call will be performed for fetching entries responding to them. Then comparison and sync are performed.

        This batch size is set to 30 by default.

        Returns:
        option that indicates capacity of batch of resources to process.
      • getCacheSize

        public long getCacheSize()
        Gets the cache size used in the sync process. To increase performance during the sync some resource keys / ids are cached which are required for resolving references. To keep the cache performant old entries are evicted when a certain size is reached.

        This cache size is set to 100.000 by default.

        Returns:
        option that indicates capacity of cache of resource keys
      • getBeforeUpdateCallback

        @Nullable
        public TriFunction<java.util.List<io.sphere.sdk.commands.UpdateAction<U>>,​V,​U,​java.util.List<io.sphere.sdk.commands.UpdateAction<U>>> getBeforeUpdateCallback()
        Returns the beforeUpdateCallback TriFunction<List<UpdateAction< U>>, V, U, List<UpdateAction<U>>> function set to this BaseSyncOptions. It represents a callback function which is applied (if set) on the generated list of update actions to produce a resultant list after the filter function has been applied.
        Returns:
        the beforeUpdateCallback TriFunction<List<UpdateAction< U>>, V, U, List<UpdateAction<U>>> function set to this BaseSyncOptions.
      • getBeforeCreateCallback

        @Nullable
        public java.util.function.Function<V,​V> getBeforeCreateCallback()
        Returns the beforeCreateCallback Function<V, Optional<V>> function set to this BaseSyncOptions. It represents a callback function which is applied (if set) on the resource draft of type V before it is created to produce a resultant draft after the filter function has been applied.
        Returns:
        the beforeUpdateCallback Function<V, Optional<V>> function set to this BaseSyncOptions.
      • applyBeforeUpdateCallback

        @Nonnull
        public java.util.List<io.sphere.sdk.commands.UpdateAction<U>> applyBeforeUpdateCallback​(@Nonnull
                                                                                                java.util.List<io.sphere.sdk.commands.UpdateAction<U>> updateActions,
                                                                                                @Nonnull
                                                                                                V newResourceDraft,
                                                                                                @Nonnull
                                                                                                U oldResource)
        Given a List of UpdateAction, a new resource draft of type V and the old existing resource of the type U, this method applies the beforeUpdateCallback function which is set to this instance of the BaseSyncOptions and returns the result. If the beforeUpdateCallback is null or updateActions is empty, this method does nothing to the supplied list of updateActions and returns the same list. If the result of the callback is null, an empty list is returned.
        Parameters:
        updateActions - the list of update actions to apply the beforeUpdateCallback function on.
        newResourceDraft - the new resource draft that is being compared to the old resource.
        oldResource - the old resource that is being compared to the new draft.
        Returns:
        a list of update actions after applying the beforeUpdateCallback function on. If the beforeUpdateCallback function is null or updateActions is empty, the supplied list of updateActions is returned as is. If the return of the callback is null, an empty list is returned.
      • applyBeforeCreateCallback

        @Nonnull
        public java.util.Optional<V> applyBeforeCreateCallback​(@Nonnull
                                                               V newResourceDraft)
        Given a new resource draft of type V this method applies the beforeCreateCallback function which is set to this instance of the BaseSyncOptions and returns the result.
        • If the beforeCreateCallback is null, this method does nothing to the supplied resource draft and returns it as is, wrapped in an optional.
        • If the return of beforeCreateCallback is null, an empty optional is returned.
        • Otherwise, the result of the beforeCreateCallback is returned in the optional.
        Parameters:
        newResourceDraft - the new resource draft that should be created.
        Returns:
        an optional containing the resultant resource draft after applying the beforeCreateCallback function on. If the beforeCreateCallback function is null, the supplied resource draft is returned as is, wrapped in an optional.