Class BaseReferenceResolver<T,S extends BaseSyncOptions>
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<T,S>
-
- Type Parameters:
S
- a subclass implementation ofBaseSyncOptions
that is used to allow/deny some specific options, specified by the user, on reference resolution.
- Direct Known Subclasses:
AttributeDefinitionReferenceResolver
,CustomReferenceResolver
,ProductReferenceResolver
,ProductTypeReferenceResolver
,StateReferenceResolver
,VariantReferenceResolver
public abstract class BaseReferenceResolver<T,S extends BaseSyncOptions> extends java.lang.Object
This class is responsible for providing an abstract implementation of reference resolution on different CTP resources. 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
BLANK_ID_VALUE_ON_REFERENCE
static java.lang.String
BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER
protected S
options
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseReferenceResolver(S options)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static <T> java.lang.String
getIdFromReference(io.sphere.sdk.models.Reference<T> reference)
This method gets the key value on the passedReference
from the id field, if valid.protected static <T> java.lang.String
getKeyFromResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier<T> resourceIdentifier)
This method gets the key value on the passedResourceIdentifier
, if valid.abstract java.util.concurrent.CompletionStage<T>
resolveReferences(T draft)
Given a draft this method attempts to resolve the all the references on the draft to return aCompletionStage
which contains a new instance of the draft with the resolved references.
-
-
-
Field Detail
-
BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER
public static final java.lang.String BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER
- See Also:
- Constant Field Values
-
BLANK_ID_VALUE_ON_REFERENCE
public static final java.lang.String BLANK_ID_VALUE_ON_REFERENCE
- See Also:
- Constant Field Values
-
options
protected S extends BaseSyncOptions options
-
-
Constructor Detail
-
BaseReferenceResolver
protected BaseReferenceResolver(@Nonnull S options)
-
-
Method Detail
-
resolveReferences
public abstract java.util.concurrent.CompletionStage<T> resolveReferences(@Nonnull T draft)
Given a draft this method attempts to resolve the all the references on the draft to return aCompletionStage
which contains a new instance of the draft with the resolved references.- Parameters:
draft
- the productDraft to resolve it's references.- Returns:
- a
CompletionStage
that contains as a result a new draft instance with resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
getIdFromReference
@Nonnull protected static <T> java.lang.String getIdFromReference(@Nonnull io.sphere.sdk.models.Reference<T> reference) throws ReferenceResolutionException
This method gets the key value on the passedReference
from the id field, if valid. If it is not valid, aReferenceResolutionException
will be thrown. The validity checks are:- Checks if the id value is not null or not empty.
ReferenceResolutionException
is thrown.- Type Parameters:
T
- the type of the reference.- Parameters:
reference
- the reference from which the key value is validated and returned.- Returns:
- the Id value on the
ResourceIdentifier
- Throws:
ReferenceResolutionException
- if any of the validation checks fail.
-
getKeyFromResourceIdentifier
@Nonnull protected static <T> java.lang.String getKeyFromResourceIdentifier(@Nonnull io.sphere.sdk.models.ResourceIdentifier<T> resourceIdentifier) throws ReferenceResolutionException
This method gets the key value on the passedResourceIdentifier
, if valid. If it is not valid, aReferenceResolutionException
will be thrown. The validity checks are:- Checks if the key value is not null or not empty.
- Checks if the key value is not equal to KEY_IS_NOT_SET(fetched from cache).
ReferenceResolutionException
is thrown.- Type Parameters:
T
- the type of the reference.- Parameters:
resourceIdentifier
- the resource identifier from which the key value is validated and returned.- Returns:
- the key value on the
ResourceIdentifier
- Throws:
ReferenceResolutionException
- if any of the validation checks fail.
-
-