Class ShoppingListReferenceResolver
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
-
- com.commercetools.sync.commons.helpers.CustomReferenceResolver<com.commercetools.api.models.shopping_list.ShoppingListDraft,com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder,ShoppingListSyncOptions>
-
- com.commercetools.sync.shoppinglists.helpers.ShoppingListReferenceResolver
-
public final class ShoppingListReferenceResolver extends CustomReferenceResolver<com.commercetools.api.models.shopping_list.ShoppingListDraft,com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder,ShoppingListSyncOptions>
-
-
Field Summary
-
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
-
-
Constructor Summary
Constructors Constructor Description ShoppingListReferenceResolver(ShoppingListSyncOptions shoppingListSyncOptions, CustomerService customerService, TypeService typeService)
Takes aShoppingListSyncOptions
instance, aCustomerService
andTypeService
to instantiate aShoppingListReferenceResolver
instance that could be used to resolve the shopping list drafts in the CTP project specified in the injectedShoppingListSyncOptions
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(ShoppingListBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e custom type, customer) from the CTP to populate caches for the reference resolution.protected java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder>
resolveCustomerReference(com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder draftBuilder)
protected java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder>
resolveCustomTypeReference(com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder draftBuilder)
Given a draft ofD
(e.g.java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraft>
resolveReferences(com.commercetools.api.models.shopping_list.ShoppingListDraft shoppingListDraft)
Given aShoppingListDraft
this method attempts to resolve the customer and custom type references to return aCompletionStage
which contains a new instance of the draft 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
-
-
-
-
Constructor Detail
-
ShoppingListReferenceResolver
public ShoppingListReferenceResolver(@Nonnull ShoppingListSyncOptions shoppingListSyncOptions, @Nonnull CustomerService customerService, @Nonnull TypeService typeService)
Takes aShoppingListSyncOptions
instance, aCustomerService
andTypeService
to instantiate aShoppingListReferenceResolver
instance that could be used to resolve the shopping list drafts in the CTP project specified in the injectedShoppingListSyncOptions
instance.- Parameters:
shoppingListSyncOptions
- the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.customerService
- the service to fetch the customers for reference resolution.typeService
- the service to fetch the types for reference resolution.
-
-
Method Detail
-
resolveReferences
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraft> resolveReferences(@Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft shoppingListDraft)
Given aShoppingListDraft
this method attempts to resolve the customer and custom type references to return aCompletionStage
which contains a new instance of the draft with the resolved references.- Specified by:
resolveReferences
in classBaseReferenceResolver<com.commercetools.api.models.shopping_list.ShoppingListDraft,ShoppingListSyncOptions>
- Parameters:
shoppingListDraft
- the shoppingListDraft to resolve its references.- Returns:
- a
CompletionStage
that contains as a result a new shoppingListDraft instance with resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveCustomerReference
@Nonnull protected java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder> resolveCustomerReference(@Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder draftBuilder)
-
resolveCustomTypeReference
@Nonnull protected java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder> resolveCustomTypeReference(@Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder 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.shopping_list.ShoppingListDraft,com.commercetools.api.models.shopping_list.ShoppingListDraftBuilder,ShoppingListSyncOptions>
- 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
.
-
populateKeyToIdCachesForReferencedKeys
@Nonnull public java.util.concurrent.CompletableFuture<java.util.List<java.util.Map<java.lang.String,java.lang.String>>> populateKeyToIdCachesForReferencedKeys(@Nonnull ShoppingListBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e custom type, customer) from the CTP to populate caches for the reference resolution.Note: This method is only to be used internally by the library to improve performance.
- Parameters:
referencedKeys
- a wrapper for the custom type and customer references to fetch the keys, and store the corresponding keys -> ids into cached maps.- Returns:
CompletionStage
<Map
<String
>String
>> in which the results of its completions contains a map of requested references keys -> ids of customer references.
-
-