Package com.commercetools.sync.commons
Class BaseSyncOptions<U,V,A>
- java.lang.Object
-
- com.commercetools.sync.commons.BaseSyncOptions<U,V,A>
-
- Type Parameters:
U- Resource (e.g.ProductProjection,Category, etc..V- Resource Draft (e.g.ProductDraft,CategoryDraft, etcA- Resource to update (e.g.Product,Category, etc..
- Direct Known Subclasses:
CartDiscountSyncOptions,CategorySyncOptions,CustomerSyncOptions,CustomObjectSyncOptions,InventorySyncOptions,ProductSyncOptions,ProductTypeSyncOptions,ShoppingListSyncOptions,StateSyncOptions,TaxCategorySyncOptions,TypeSyncOptions
public class BaseSyncOptions<U,V,A> extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseSyncOptions(io.sphere.sdk.client.SphereClient ctpClient, QuadConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>> errorCallback, TriConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>> warningCallback, int batchSize, TriFunction<java.util.List<io.sphere.sdk.commands.UpdateAction<A>>,V,U,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>> beforeUpdateCallback, java.util.function.Function<V,V> beforeCreateCallback, long cacheSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<V>applyBeforeCreateCallback(V newResourceDraft)Given a new resource draft of typeVthis method applies thebeforeCreateCallbackfunction which is set tothisinstance of theBaseSyncOptionsand returns the result.java.util.List<io.sphere.sdk.commands.UpdateAction<A>>applyBeforeUpdateCallback(java.util.List<io.sphere.sdk.commands.UpdateAction<A>> updateActions, V newResourceDraft, U oldResource)Given aListofUpdateAction, a new resource draft of typeVand the old existing resource of the typeU, this method applies thebeforeUpdateCallbackfunction which is set tothisinstance of theBaseSyncOptionsand returns the result.voidapplyErrorCallback(SyncException syncException)voidapplyErrorCallback(SyncException exception, U oldResource, V newResourceDraft, java.util.List<io.sphere.sdk.commands.UpdateAction<A>> updateActions)Given anerrorMessageand anexception, this method calls theerrorCallbackfunction which is set tothisinstance of theBaseSyncOptions.voidapplyErrorCallback(java.lang.String errorMessage)voidapplyWarningCallback(SyncException exception, U oldResource, V newResourceDraft)Given anexception,oldResourceandnewResourceDraftthis method calls thewarningCallbackfunction which is set tothisinstance of theBaseSyncOptions.intgetBatchSize()Gets the batch size used in the sync process.java.util.function.Function<V,V>getBeforeCreateCallback()TriFunction<java.util.List<io.sphere.sdk.commands.UpdateAction<A>>,V,U,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>>getBeforeUpdateCallback()Returns thebeforeUpdateCallbackTriFunction<List<UpdateAction<U>>,V,U,List<UpdateAction<U>>> function set tothisBaseSyncOptions.longgetCacheSize()Gets the cache size used in the sync process.io.sphere.sdk.client.SphereClientgetCtpClient()Returns theSphereClientresponsible for interaction with the target CTP project.QuadConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>>getErrorCallback()Returns theerrorCallbackQuadConsumer<SyncException,Optional<V>,Optional<U>,List<UpdateAction<U>>> function set tothisBaseSyncOptions.TriConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>>getWarningCallback()Returns thewarningCallbackTriConsumer<SyncException,Optional<V>,Optional<U>> function set tothisBaseSyncOptions.
-
-
-
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<A>>> 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<A>>,V,U,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>> beforeUpdateCallback, @Nullable java.util.function.Function<V,V> beforeCreateCallback, long cacheSize)
-
-
Method Detail
-
getCtpClient
public io.sphere.sdk.client.SphereClient getCtpClient()
Returns theSphereClientresponsible for interaction with the target CTP project.- Returns:
- the
SphereClientresponsible 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<A>>> getErrorCallback()
Returns theerrorCallbackQuadConsumer<SyncException,Optional<V>,Optional<U>,List<UpdateAction<U>>> function set tothisBaseSyncOptions. It represents the callback that is called whenever an event occurs during the sync process that represents an error.- Returns:
- the
errorCallbackQuadConsumer<SyncException,Optional<V>,Optional<U>,List<UpdateAction<U>> function set tothisBaseSyncOptions
-
getWarningCallback
@Nullable public TriConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>> getWarningCallback()
Returns thewarningCallbackTriConsumer<SyncException,Optional<V>,Optional<U>> function set tothisBaseSyncOptions. It represents the callback that is called whenever an event occurs during the sync process that represents a warning.- Returns:
- the
warningCallbackTriConsumer<SyncException,Optional<V>,Optional<U>> function set tothisBaseSyncOptions
-
applyWarningCallback
public void applyWarningCallback(@Nonnull SyncException exception, @Nullable U oldResource, @Nullable V newResourceDraft)Given anexception,oldResourceandnewResourceDraftthis method calls thewarningCallbackfunction which is set tothisinstance of theBaseSyncOptions. If therewarningCallbackis null, this method does nothing.- Parameters:
exception- the exception to supply to thewarningCallbackfunction.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<A>> updateActions)Given anerrorMessageand anexception, this method calls theerrorCallbackfunction which is set tothisinstance of theBaseSyncOptions. If thereerrorCallbackis null, this method does nothing.- Parameters:
exception-Throwableinstance to supply as first param to theerrorCallbackfunction.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.
-
applyErrorCallback
public void applyErrorCallback(@Nonnull SyncException syncException)- Parameters:
syncException-Throwableinstance to supply as first param to theerrorCallbackfunction.- See Also:
applyErrorCallback(SyncException exception, Object oldResource, Object newResource, List updateActions)
-
applyErrorCallback
public void applyErrorCallback(@Nonnull java.lang.String errorMessage)- Parameters:
errorMessage- the error message to supply as part of first param to theerrorCallbackfunction.- See Also:
applyErrorCallback(SyncException exception, Object oldResource, Object newResource, List updateActions)
-
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<A>>,V,U,java.util.List<io.sphere.sdk.commands.UpdateAction<A>>> getBeforeUpdateCallback()
Returns thebeforeUpdateCallbackTriFunction<List<UpdateAction<U>>,V,U,List<UpdateAction<U>>> function set tothisBaseSyncOptions. 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
beforeUpdateCallbackTriFunction<List<UpdateAction<U>>,V,U,List<UpdateAction<U>>> function set tothisBaseSyncOptions.
-
getBeforeCreateCallback
@Nullable public java.util.function.Function<V,V> getBeforeCreateCallback()
Returns thebeforeCreateCallbackFunction<V,Optional<V>> function set tothisBaseSyncOptions. It represents a callback function which is applied (if set) on the resource draft of typeVbefore it is created to produce a resultant draft after the filter function has been applied.- Returns:
- the
beforeUpdateCallbackFunction<V,Optional<V>> function set tothisBaseSyncOptions.
-
applyBeforeUpdateCallback
@Nonnull public java.util.List<io.sphere.sdk.commands.UpdateAction<A>> applyBeforeUpdateCallback(@Nonnull java.util.List<io.sphere.sdk.commands.UpdateAction<A>> updateActions, @Nonnull V newResourceDraft, @Nonnull U oldResource)
Given aListofUpdateAction, a new resource draft of typeVand the old existing resource of the typeU, this method applies thebeforeUpdateCallbackfunction which is set tothisinstance of theBaseSyncOptionsand returns the result. If thebeforeUpdateCallbackis null orupdateActionsis empty, this method does nothing to the supplied list ofupdateActionsand 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 thebeforeUpdateCallbackfunction 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
beforeUpdateCallbackfunction on. If thebeforeUpdateCallbackfunction is null orupdateActionsis empty, the supplied list ofupdateActionsis 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 typeVthis method applies thebeforeCreateCallbackfunction which is set tothisinstance of theBaseSyncOptionsand returns the result.- If the
beforeCreateCallbackis null, this method does nothing to the supplied resource draft and returns it as is, wrapped in an optional. - If the return of
beforeCreateCallbackis null, an empty optional is returned. - Otherwise, the result of the
beforeCreateCallbackis 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
beforeCreateCallbackfunction on. If thebeforeCreateCallbackfunction is null, the supplied resource draft is returned as is, wrapped in an optional.
- If the
-
-