Class CustomerReferenceResolver
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
-
- com.commercetools.sync.commons.helpers.CustomReferenceResolver<com.commercetools.api.models.customer.CustomerDraft,com.commercetools.api.models.customer.CustomerDraftBuilder,CustomerSyncOptions>
-
- com.commercetools.sync.customers.helpers.CustomerReferenceResolver
-
public final class CustomerReferenceResolver extends CustomReferenceResolver<com.commercetools.api.models.customer.CustomerDraft,com.commercetools.api.models.customer.CustomerDraftBuilder,CustomerSyncOptions>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CUSTOMER_GROUP_DOES_NOT_EXIST
static java.lang.String
FAILED_TO_RESOLVE_CUSTOM_TYPE
static java.lang.String
FAILED_TO_RESOLVE_CUSTOMER_GROUP_REFERENCE
static java.lang.String
FAILED_TO_RESOLVE_STORE_REFERENCE
-
Fields inherited from class com.commercetools.sync.commons.helpers.CustomReferenceResolver
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, SELF_REFERENCING_ID_PLACE_HOLDER
-
-
Constructor Summary
Constructors Constructor Description CustomerReferenceResolver(CustomerSyncOptions options, TypeService typeService, CustomerGroupService customerGroupService)
Takes aCustomerSyncOptions
instance, aTypeService
and aCustomerGroupService
to instantiate aCustomerReferenceResolver
instance that could be used to resolve the customer drafts in the CTP project specified in the injectedCustomerSyncOptions
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.util.List<java.util.Map<java.lang.String,java.lang.String>>>
populateKeyToIdCachesForReferencedKeys(CustomerBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e custom type, customer group) from the commercetools to populate caches for the reference resolution.java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder>
resolveCustomerGroupReference(com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Given aCustomerDraftBuilder
this method attempts to resolve the customer group to return aCompletionStage
which contains a new instance of the builder with the resolved customer group reference.protected java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder>
resolveCustomTypeReference(com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Given a draft ofD
(e.g.java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraft>
resolveReferences(com.commercetools.api.models.customer.CustomerDraft customerDraft)
Given aCustomerDraft
this method attempts to resolve the stores, customer group and custom type references to return aCompletionStage
which contains a new instance of the draft with the resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder>
resolveStoreReferences(com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Given aCustomerDraftBuilder
this method attempts to resolve the stores and return aCompletionStage
which contains a new instance of the builder with the resolved references.-
Methods inherited from class com.commercetools.sync.commons.helpers.CustomReferenceResolver
resolveCustomTypeReference
-
Methods inherited from class com.commercetools.sync.commons.helpers.BaseReferenceResolver
getIdFromReference, getKeyFromResourceIdentifier
-
-
-
-
Field Detail
-
FAILED_TO_RESOLVE_CUSTOMER_GROUP_REFERENCE
public static final java.lang.String FAILED_TO_RESOLVE_CUSTOMER_GROUP_REFERENCE
- See Also:
- Constant Field Values
-
FAILED_TO_RESOLVE_STORE_REFERENCE
public static final java.lang.String FAILED_TO_RESOLVE_STORE_REFERENCE
- See Also:
- Constant Field Values
-
FAILED_TO_RESOLVE_CUSTOM_TYPE
public static final java.lang.String FAILED_TO_RESOLVE_CUSTOM_TYPE
- See Also:
- Constant Field Values
-
CUSTOMER_GROUP_DOES_NOT_EXIST
public static final java.lang.String CUSTOMER_GROUP_DOES_NOT_EXIST
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CustomerReferenceResolver
public CustomerReferenceResolver(@Nonnull CustomerSyncOptions options, @Nonnull TypeService typeService, @Nonnull CustomerGroupService customerGroupService)
Takes aCustomerSyncOptions
instance, aTypeService
and aCustomerGroupService
to instantiate aCustomerReferenceResolver
instance that could be used to resolve the customer drafts in the CTP project specified in the injectedCustomerSyncOptions
instance.- Parameters:
options
- the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.typeService
- the service to fetch the custom types for reference resolution.customerGroupService
- the service to fetch the customer groups for reference resolution.
-
-
Method Detail
-
resolveReferences
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraft> resolveReferences(@Nonnull com.commercetools.api.models.customer.CustomerDraft customerDraft)
Given aCustomerDraft
this method attempts to resolve the stores, customer group and custom type references to return aCompletionStage
which contains a new instance of the draft with the resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.- Specified by:
resolveReferences
in classBaseReferenceResolver<com.commercetools.api.models.customer.CustomerDraft,CustomerSyncOptions>
- Parameters:
customerDraft
- the draft to resolve its references.- Returns:
- a
CompletionStage
that contains as a result a new CustomerDraft instance with resolved custom type reference or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveCustomTypeReference
protected java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder> resolveCustomTypeReference(@Nonnull com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Description copied from class:CustomReferenceResolver
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).
- Specified by:
resolveCustomTypeReference
in classCustomReferenceResolver<com.commercetools.api.models.customer.CustomerDraft,com.commercetools.api.models.customer.CustomerDraftBuilder,CustomerSyncOptions>
- 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
.
-
resolveCustomerGroupReference
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder> resolveCustomerGroupReference(@Nonnull com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Given aCustomerDraftBuilder
this method attempts to resolve the customer group to return aCompletionStage
which contains a new instance of the builder with the resolved customer group reference.- Parameters:
draftBuilder
- the customerDraft to resolve its customer group reference.- Returns:
- a
CompletionStage
that contains as a result a new builder instance with resolved customer group reference or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveStoreReferences
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.customer.CustomerDraftBuilder> resolveStoreReferences(@Nonnull com.commercetools.api.models.customer.CustomerDraftBuilder draftBuilder)
Given aCustomerDraftBuilder
this method attempts to resolve the stores and return aCompletionStage
which contains a new instance of the builder with the resolved references.- Parameters:
draftBuilder
- the customer draft to resolve its store references.- Returns:
- a
CompletionStage
that contains as a result a new builder instance with resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
populateKeyToIdCachesForReferencedKeys
@Nonnull public java.util.concurrent.CompletableFuture<java.util.List<java.util.Map<java.lang.String,java.lang.String>>> populateKeyToIdCachesForReferencedKeys(@Nonnull CustomerBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e custom type, customer group) from the commercetools to populate caches for the reference resolution.Note: This method is meant be only used internally by the library to improve performance.
- Parameters:
referencedKeys
- a wrapper for the product references to fetch and cache the id's for.- Returns:
CompletionStage
<Map
<String
>String
>> in which the results of it's completions contains a map of requested references keys -> ids of customer references.
-
-