T - the resource draft type for which reference resolution has to be done on.S - a subclass implementation of BaseSyncOptions that is used to allow/deny some specific options,
specified by the user, on reference resolution.public abstract class BaseReferenceResolver<T extends io.sphere.sdk.types.CustomDraft,S extends BaseSyncOptions>
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
protected |
BaseReferenceResolver(S options,
TypeService typeService) |
| Modifier and Type | Method and Description |
|---|---|
protected java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> |
getCustomTypeId(io.sphere.sdk.types.CustomFieldsDraft custom,
java.lang.String referenceResolutionErrorMessage)
Given a custom fields object this method fetches the custom type reference id.
|
protected static java.lang.String |
getKeyFromExpansionOrReference(boolean shouldAllowUuidKeys,
java.lang.String keyFromExpansion,
io.sphere.sdk.models.Reference reference)
Given a key value (
keyFromExpansion) which is potentially fetched from the expansion of a reference. |
protected S |
getOptions()
|
protected static boolean |
isReferenceExpanded(io.sphere.sdk.models.Reference reference)
Helper method to check if passed
Reference instance is expanded. |
protected abstract java.util.concurrent.CompletionStage<T> |
resolveCustomTypeReference(T draft)
Given a draft of
T (e.g. |
protected BaseReferenceResolver(@Nonnull
S options,
@Nonnull
TypeService typeService)
protected S getOptions()
S, which is a subclass of BaseSyncOptions, instance of this instance.protected abstract java.util.concurrent.CompletionStage<T> resolveCustomTypeReference(@Nonnull T draft)
T (e.g. CategoryDraft) this method attempts to resolve it's custom type
reference to return CompletionStage which contains a new instance of the draft with the resolved
custom type reference. The key of the custom type is taken from the from the id field of the 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).
draft - the draft to resolve it's references.CompletionStage that contains as a result a new draft instance with resolved custom
type references or, in case an error occurs during reference resolution,
a ReferenceResolutionException.protected java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> getCustomTypeId(@Nonnull
io.sphere.sdk.types.CustomFieldsDraft custom,
@Nonnull
java.lang.String referenceResolutionErrorMessage)
custom - the custom fields object.referenceResolutionErrorMessage - the message containing the information about the draft to attach to the
ReferenceResolutionException in case it occurs.CompletionStage that contains as a result an optional which either contains the custom type id
if it exists or empty if it doesn't.@Nonnull
protected static java.lang.String getKeyFromExpansionOrReference(boolean shouldAllowUuidKeys,
@Nullable
java.lang.String keyFromExpansion,
@Nonnull
io.sphere.sdk.models.Reference reference)
throws ReferenceResolutionException
keyFromExpansion) which is potentially fetched from the expansion of a reference. This
method checks if this value is not blank (empty string/null), if it is, it tries to fetch the key value from the
id field on the reference. If it's not blank it returns it. Whether the value is fetched from the expansion or
from the reference's id field, this method makes sure the key is valid:
options instance of this class.ReferenceResolutionException will be thrown.shouldAllowUuidKeys - flag that signals whether the key could be UUID format or not.keyFromExpansion - the key value fetched after expansion of the reference.reference - the reference object to get the key from.ReferenceResolutionException - thrown if the key is not valid.protected static boolean isReferenceExpanded(@Nonnull
io.sphere.sdk.models.Reference reference)
Reference instance is expanded.reference - the reference to check.Reference is expanded.