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 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<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 typeV
this method applies thebeforeCreateCallback
function which is set tothis
instance of theBaseSyncOptions
and 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 aList
ofUpdateAction
, a new resource draft of typeV
and the old existing resource of the typeU
, this method applies thebeforeUpdateCallback
function which is set tothis
instance of theBaseSyncOptions
and returns the result.void
applyErrorCallback(SyncException syncException)
void
applyErrorCallback(SyncException exception, U oldResource, V newResourceDraft, java.util.List<io.sphere.sdk.commands.UpdateAction<A>> updateActions)
Given anerrorMessage
and anexception
, this method calls theerrorCallback
function which is set tothis
instance of theBaseSyncOptions
.void
applyErrorCallback(java.lang.String errorMessage)
void
applyWarningCallback(SyncException exception, U oldResource, V newResourceDraft)
Given anexception
,oldResource
andnewResourceDraft
this method calls thewarningCallback
function which is set tothis
instance of theBaseSyncOptions
.int
getBatchSize()
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 thebeforeUpdateCallback
TriFunction
<List
<UpdateAction
<U
>>,V
,U
,List
<UpdateAction
<U
>>> function set tothis
BaseSyncOptions
.long
getCacheSize()
Gets the cache size used in the sync process.io.sphere.sdk.client.SphereClient
getCtpClient()
Returns theSphereClient
responsible 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 theerrorCallback
QuadConsumer
<SyncException
,Optional
<V
>,Optional
<U
>,List
<UpdateAction
<U
>>> function set tothis
BaseSyncOptions
.TriConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>>
getWarningCallback()
Returns thewarningCallback
TriConsumer
<SyncException
,Optional
<V
>,Optional
<U
>> function set tothis
BaseSyncOptions
.
-
-
-
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 theSphereClient
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<A>>> getErrorCallback()
Returns theerrorCallback
QuadConsumer
<SyncException
,Optional
<V
>,Optional
<U
>,List
<UpdateAction
<U
>>> function set tothis
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 tothis
BaseSyncOptions
-
getWarningCallback
@Nullable public TriConsumer<SyncException,java.util.Optional<V>,java.util.Optional<U>> getWarningCallback()
Returns thewarningCallback
TriConsumer
<SyncException
,Optional
<V
>,Optional
<U
>> function set tothis
BaseSyncOptions
. It represents the callback that is called whenever an event occurs during the sync process that represents a warning.- Returns:
- the
warningCallback
TriConsumer
<SyncException
,Optional
<V
>,Optional
<U
>> function set tothis
BaseSyncOptions
-
applyWarningCallback
public void applyWarningCallback(@Nonnull SyncException exception, @Nullable U oldResource, @Nullable V newResourceDraft)
Given anexception
,oldResource
andnewResourceDraft
this method calls thewarningCallback
function which is set tothis
instance of theBaseSyncOptions
. If therewarningCallback
is null, this method does nothing.- Parameters:
exception
- the exception to supply to thewarningCallback
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<A>> updateActions)
Given anerrorMessage
and anexception
, this method calls theerrorCallback
function which is set tothis
instance of theBaseSyncOptions
. If thereerrorCallback
is null, this method does nothing.- Parameters:
exception
-Throwable
instance to supply as first param to theerrorCallback
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.
-
applyErrorCallback
public void applyErrorCallback(@Nonnull SyncException syncException)
- Parameters:
syncException
-Throwable
instance to supply as first param to theerrorCallback
function.- 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 theerrorCallback
function.- 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 thebeforeUpdateCallback
TriFunction
<List
<UpdateAction
<U
>>,V
,U
,List
<UpdateAction
<U
>>> function set tothis
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 tothis
BaseSyncOptions
.
-
getBeforeCreateCallback
@Nullable public java.util.function.Function<V,V> getBeforeCreateCallback()
Returns thebeforeCreateCallback
Function
<V
,Optional
<V
>> function set tothis
BaseSyncOptions
. It represents a callback function which is applied (if set) on the resource draft of typeV
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 tothis
BaseSyncOptions
.
-
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 aList
ofUpdateAction
, a new resource draft of typeV
and the old existing resource of the typeU
, this method applies thebeforeUpdateCallback
function which is set tothis
instance of theBaseSyncOptions
and returns the result. If thebeforeUpdateCallback
is null orupdateActions
is empty, this method does nothing to the supplied list ofupdateActions
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 thebeforeUpdateCallback
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 thebeforeUpdateCallback
function is null orupdateActions
is empty, the supplied list ofupdateActions
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 typeV
this method applies thebeforeCreateCallback
function which is set tothis
instance of theBaseSyncOptions
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 thebeforeCreateCallback
function is null, the supplied resource draft is returned as is, wrapped in an optional.
- If the
-
-