Class BaseReferenceResolver<ResourceDraftT extends io.vrap.rmf.base.client.Draft<ResourceDraftT>,SyncOptionsT extends BaseSyncOptions>
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
-
- Type Parameters:
SyncOptionsT
- 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<ResourceDraftT extends io.vrap.rmf.base.client.Draft<ResourceDraftT>,SyncOptionsT 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 SyncOptionsT
options
static java.lang.String
SELF_REFERENCING_ID_PLACE_HOLDER
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseReferenceResolver(SyncOptionsT 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(com.commercetools.api.models.common.Reference reference)
This method gets the key value on the passedReference
from the id field, if valid.protected static java.lang.String
getKeyFromResourceIdentifier(com.commercetools.api.models.common.ResourceIdentifier resourceIdentifier)
This method gets the key value on the passedResourceIdentifier
, if valid.abstract java.util.concurrent.CompletionStage<ResourceDraftT>
resolveReferences(ResourceDraftT 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
-
SELF_REFERENCING_ID_PLACE_HOLDER
public static final java.lang.String SELF_REFERENCING_ID_PLACE_HOLDER
- See Also:
- Constant Field Values
-
options
protected SyncOptionsT extends BaseSyncOptions options
-
-
Constructor Detail
-
BaseReferenceResolver
protected BaseReferenceResolver(@Nonnull SyncOptionsT options)
-
-
Method Detail
-
resolveReferences
public abstract java.util.concurrent.CompletionStage<ResourceDraftT> resolveReferences(@Nonnull ResourceDraftT 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 com.commercetools.api.models.common.Reference 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 java.lang.String getKeyFromResourceIdentifier(@Nonnull com.commercetools.api.models.common.ResourceIdentifier 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.- 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.
-
-