Class BaseSyncOptions<ResourceT,​ResourceDraftT,​ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>

    • Method Detail

      • getCtpClient

        public com.commercetools.api.client.ProjectApiRoot getCtpClient()
        Returns the ProjectApiRoot responsible for interaction with the target CTP project.
        Returns:
        the ProjectApiRoot responsible for interaction with the target CTP project.
      • applyWarningCallback

        public void applyWarningCallback​(@Nonnull
                                         SyncException exception,
                                         @Nullable
                                         ResourceT oldResource,
                                         @Nullable
                                         ResourceDraftT 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
                                       ResourceT oldResource,
                                       @Nullable
                                       ResourceDraftT newResourceDraft,
                                       @Nullable
                                       java.util.List<ResourceUpdateActionT> 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<ResourceUpdateActionT>,​ResourceDraftT,​ResourceT,​java.util.List<ResourceUpdateActionT>> getBeforeUpdateCallback()
        Returns the beforeUpdateCallback TriFunction<List<ResourceUpdateAction< U>>, V, U, List<ResourceUpdateAction<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<ResourceUpdateAction< U>>, V, U, List<ResourceUpdateAction<U>>> function set to this BaseSyncOptions.
      • getBeforeCreateCallback

        @Nullable
        public java.util.function.Function<ResourceDraftT,​ResourceDraftT> 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<ResourceUpdateActionT> applyBeforeUpdateCallback​(@Nonnull
                                                                               java.util.List<ResourceUpdateActionT> updateActions,
                                                                               @Nonnull
                                                                               ResourceDraftT newResourceDraft,
                                                                               @Nonnull
                                                                               ResourceT oldResource)
        Given a List of ResourceUpdateAction, 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<ResourceDraftT> applyBeforeCreateCallback​(@Nonnull
                                                                            ResourceDraftT 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.