Package com.commercetools.sync.commons
Class BaseSyncOptionsBuilder<SyncOptionsBuilderT extends BaseSyncOptionsBuilder<SyncOptionsBuilderT,SyncOptionsT,ResourceT,ResourceDraftT,ResourceUpdateActionT>,SyncOptionsT extends BaseSyncOptions<ResourceT,ResourceDraftT,ResourceUpdateActionT>,ResourceT,ResourceDraftT,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>
- java.lang.Object
-
- com.commercetools.sync.commons.BaseSyncOptionsBuilder<SyncOptionsBuilderT,SyncOptionsT,ResourceT,ResourceDraftT,ResourceUpdateActionT>
-
- Direct Known Subclasses:
CartDiscountSyncOptionsBuilder
,CategorySyncOptionsBuilder
,CustomerSyncOptionsBuilder
,CustomObjectSyncOptionsBuilder
,InventorySyncOptionsBuilder
,ProductSyncOptionsBuilder
,ProductTypeSyncOptionsBuilder
,ShoppingListSyncOptionsBuilder
,StateSyncOptionsBuilder
,TaxCategorySyncOptionsBuilder
,TypeSyncOptionsBuilder
public abstract class BaseSyncOptionsBuilder<SyncOptionsBuilderT extends BaseSyncOptionsBuilder<SyncOptionsBuilderT,SyncOptionsT,ResourceT,ResourceDraftT,ResourceUpdateActionT>,SyncOptionsT extends BaseSyncOptions<ResourceT,ResourceDraftT,ResourceUpdateActionT>,ResourceT,ResourceDraftT,ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>> extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected int
batchSize
protected java.util.function.Function<ResourceDraftT,ResourceDraftT>
beforeCreateCallback
protected TriFunction<java.util.List<ResourceUpdateActionT>,ResourceDraftT,ResourceT,java.util.List<ResourceUpdateActionT>>
beforeUpdateCallback
protected long
cacheSize
protected com.commercetools.api.client.ProjectApiRoot
ctpClient
protected QuadConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>,java.util.List<ResourceUpdateActionT>>
errorCallback
protected TriConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>>
warningCallback
-
Constructor Summary
Constructors Constructor Description BaseSyncOptionsBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SyncOptionsBuilderT
batchSize(int batchSize)
Set option that indicates batch size for sync process.SyncOptionsBuilderT
beforeCreateCallback(java.util.function.Function<ResourceDraftT,ResourceDraftT> beforeCreateCallback)
Sets the beforeCreateCallbackFunction
which can be applied on a new resource draft of typeV
(e.g.SyncOptionsBuilderT
beforeUpdateCallback(TriFunction<java.util.List<ResourceUpdateActionT>,ResourceDraftT,ResourceT,java.util.List<ResourceUpdateActionT>> beforeUpdateCallback)
Sets the beforeUpdateCallbackTriFunction
which can be applied on the supplied list of update actions generated from comparing an old resource of typeU
(e.g.protected abstract SyncOptionsT
build()
Creates new instance ofS
which extendsBaseSyncOptions
enriched with all attributes provided tothis
builder.SyncOptionsBuilderT
cacheSize(long cacheSize)
Sets the cache size that indicates the key to id cache size of the sync process.SyncOptionsBuilderT
errorCallback(QuadConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>,java.util.List<ResourceUpdateActionT>> errorCallback)
Sets theerrorCallback
function of the sync module.protected abstract SyncOptionsBuilderT
getThis()
SyncOptionsBuilderT
warningCallback(TriConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>> warningCallback)
Sets thewarningCallback
function of the sync module.
-
-
-
Field Detail
-
ctpClient
protected com.commercetools.api.client.ProjectApiRoot ctpClient
-
errorCallback
protected QuadConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>,java.util.List<ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>> errorCallback
-
warningCallback
protected TriConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>> warningCallback
-
batchSize
protected int batchSize
-
beforeUpdateCallback
protected TriFunction<java.util.List<ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>,ResourceDraftT,ResourceT,java.util.List<ResourceUpdateActionT extends com.commercetools.api.models.ResourceUpdateAction<ResourceUpdateActionT>>> beforeUpdateCallback
-
beforeCreateCallback
protected java.util.function.Function<ResourceDraftT,ResourceDraftT> beforeCreateCallback
-
cacheSize
protected long cacheSize
-
-
Method Detail
-
errorCallback
public SyncOptionsBuilderT errorCallback(@Nonnull QuadConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>,java.util.List<ResourceUpdateActionT>> errorCallback)
Sets theerrorCallback
function of the sync module. This callback will be called whenever an event occurs that leads to an error alert from the sync process.- Parameters:
errorCallback
- the new value to set to the error callback.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
warningCallback
public SyncOptionsBuilderT warningCallback(@Nonnull TriConsumer<SyncException,java.util.Optional<ResourceDraftT>,java.util.Optional<ResourceT>> warningCallback)
Sets thewarningCallback
function of the sync module. This callback will be called whenever an event occurs that leads to a warning alert from the sync process.- Parameters:
warningCallback
- the new value to set to the warning callback.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
batchSize
public SyncOptionsBuilderT batchSize(int batchSize)
Set option that indicates batch size for 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 comparision and sync are performed.This batch size is set to 30 by default.
- Parameters:
batchSize
- int that indicates batch size of resources to process. Has to be positive or else will be ignored and default value of 30 would be used.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
cacheSize
public SyncOptionsBuilderT cacheSize(long cacheSize)
Sets the cache size that indicates the key to id cache size of the sync process. To increase performance during the sync some resource keys mapped to ids are cached which are required for resolving references. To keep the cache performant outdated entries are evicted when a certain size is reached.Note: This cache size is set to 10.000 by default.
- Parameters:
cacheSize
- a long number value that indicates cache size of the key to id cache used for reference resolution. Has to be positive or else will be ignored and default value of 10.000 would be used.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
beforeUpdateCallback
public SyncOptionsBuilderT beforeUpdateCallback(@Nonnull TriFunction<java.util.List<ResourceUpdateActionT>,ResourceDraftT,ResourceT,java.util.List<ResourceUpdateActionT>> beforeUpdateCallback)
Sets the beforeUpdateCallbackTriFunction
which can be applied on the supplied list of update actions generated from comparing an old resource of typeU
(e.g.Product
) to a new draft of typeV
(e.g.ProductDraft
). It results in a resultant list after the specifiedTriFunction
beforeUpdateCallback
function has been applied. This can be used to intercept the sync process before issuing an update request and to be able to manipulate the update actions. Note: Specifying a callback that returns anull
value or empty list will skip issuing the update request.- Parameters:
beforeUpdateCallback
- function which can be applied on generated list of update actions.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
beforeCreateCallback
public SyncOptionsBuilderT beforeCreateCallback(@Nonnull java.util.function.Function<ResourceDraftT,ResourceDraftT> beforeCreateCallback)
Sets the beforeCreateCallbackFunction
which can be applied on a new resource draft of typeV
(e.g.ProductDraft
) before it's created by the sync. It results in a resource draft of the same type which is the result of the application of the specifiedFunction
beforeCreateCallback
function. This can be used to intercept the sync process before creating the resource draft and to be able to manipulate it. Note: Specifying a callback that returns anull
value will skip draft creation.- Parameters:
beforeCreateCallback
- function which can be applied on a new draft before it's created by the sync.- Returns:
this
instance ofBaseSyncOptionsBuilder
-
build
protected abstract SyncOptionsT build()
Creates new instance ofS
which extendsBaseSyncOptions
enriched with all attributes provided tothis
builder.- Returns:
- new instance of S which extends
BaseSyncOptions
-
getThis
protected abstract SyncOptionsBuilderT getThis()
Returnsthis
instance ofT
, which extendsBaseSyncOptionsBuilder
. The purpose of this method is to make sure thatthis
is an instance of a class which extendsBaseSyncOptionsBuilder
in order to be used in the generic methods of the class. Otherwise, without this method, the methods above would need to castthis to T
which could lead to a runtime error of the class was extended in a wrong way.- Returns:
- an instance of the class that overrides this method.
-
-