Class CustomReferenceResolver<ResourceDraftT extends io.vrap.rmf.base.client.Draft<ResourceDraftT>,BuilderT extends io.vrap.rmf.base.client.Builder<ResourceDraftT>,SyncOptionsT extends BaseSyncOptions>
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
-
- com.commercetools.sync.commons.helpers.CustomReferenceResolver<ResourceDraftT,BuilderT,SyncOptionsT>
-
- Type Parameters:
ResourceDraftT
- the resource draft type for which reference resolution has to be done on.BuilderT
- the resource draft builder where resolved values should be set. The builder type should correspond theResourceDraftT
type.SyncOptionsT
- a subclass implementation ofBaseSyncOptions
that is used to allow/deny some specific options, specified by the user, on reference resolution.
- Direct Known Subclasses:
AssetReferenceResolver
,CartDiscountReferenceResolver
,CategoryReferenceResolver
,CustomerReferenceResolver
,InventoryReferenceResolver
,LineItemReferenceResolver
,PriceReferenceResolver
,ShoppingListReferenceResolver
,TextLineItemReferenceResolver
public abstract class CustomReferenceResolver<ResourceDraftT extends io.vrap.rmf.base.client.Draft<ResourceDraftT>,BuilderT extends io.vrap.rmf.base.client.Builder<ResourceDraftT>,SyncOptionsT extends BaseSyncOptions> extends BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
This class is responsible for providing an abstract implementation of reference resolution on Custom CTP resources for example (Categories, inventories and resource with a custom field). For concrete reference resolution implementation of the CTP resources, this class should be extended.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
TYPE_DOES_NOT_EXIST
-
Fields inherited from class com.commercetools.sync.commons.helpers.BaseReferenceResolver
BLANK_ID_VALUE_ON_REFERENCE, BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER, options
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CustomReferenceResolver(SyncOptionsT options, TypeService typeService)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.util.concurrent.CompletionStage<BuilderT>
resolveCustomTypeReference(BuilderT draftBuilder)
Given a draft ofD
(e.g.protected java.util.concurrent.CompletionStage<BuilderT>
resolveCustomTypeReference(BuilderT draftBuilder, java.util.function.Function<BuilderT,com.commercetools.api.models.type.CustomFieldsDraft> customGetter, java.util.function.BiFunction<BuilderT,com.commercetools.api.models.type.CustomFieldsDraft,BuilderT> customSetter, java.lang.String errorMessage)
Given a draft ofD
(e.g.-
Methods inherited from class com.commercetools.sync.commons.helpers.BaseReferenceResolver
getIdFromReference, getKeyFromResourceIdentifier, resolveReferences
-
-
-
-
Field Detail
-
TYPE_DOES_NOT_EXIST
public static final java.lang.String TYPE_DOES_NOT_EXIST
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CustomReferenceResolver
protected CustomReferenceResolver(@Nonnull SyncOptionsT options, @Nonnull TypeService typeService)
-
-
Method Detail
-
resolveCustomTypeReference
protected abstract java.util.concurrent.CompletionStage<BuilderT> resolveCustomTypeReference(@Nonnull BuilderT draftBuilder)
Given a draft ofD
(e.g.CategoryDraft
) this method attempts to resolve it's custom type reference to returnCompletionStage
which contains a new instance of the draft with the resolved custom type reference.The method then tries to fetch the key of the custom type, optimistically from a cache. If the key is is not found, the resultant draft would remain exactly the same as the passed draft (without a custom type reference resolution).
- Parameters:
draftBuilder
- the draft builder to resolve it's references.- Returns:
- a
CompletionStage
that contains as a result a new draft instance with resolved custom type references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveCustomTypeReference
@Nonnull protected java.util.concurrent.CompletionStage<BuilderT> resolveCustomTypeReference(@Nonnull BuilderT draftBuilder, @Nonnull java.util.function.Function<BuilderT,com.commercetools.api.models.type.CustomFieldsDraft> customGetter, @Nonnull java.util.function.BiFunction<BuilderT,com.commercetools.api.models.type.CustomFieldsDraft,BuilderT> customSetter, @Nonnull java.lang.String errorMessage)
Given a draft ofD
(e.g.CategoryDraft
) this method attempts to resolve it's custom type reference to returnCompletionStage
which contains a new instance of the draft with the resolved custom type reference.The method then tries to fetch the key of the custom type, optimistically from a cache. If the key is is not found, the resultant draft would remain exactly the same as the passed draft (without a custom type reference resolution).
Note: If the id field is set, then it is an evidence of resource existence on commercetools, so we can issue an update/create API request right away without reference resolution.
- Parameters:
draftBuilder
- the draft builder to resolve it's references.customGetter
- a function to return the CustomFieldsDraft instance of the draft builder.customSetter
- a function to set the CustomFieldsDraft instance of the builder and return this builder.errorMessage
- the error message to inject in theReferenceResolutionException
if it occurs.- Returns:
- a
CompletionStage
that contains as a result a new draft instance with resolved custom type references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
-