Class InventoryReferenceResolver
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<ResourceDraftT,SyncOptionsT>
-
- com.commercetools.sync.commons.helpers.CustomReferenceResolver<com.commercetools.api.models.inventory.InventoryEntryDraft,com.commercetools.api.models.inventory.InventoryEntryDraftBuilder,InventorySyncOptions>
-
- com.commercetools.sync.inventories.helpers.InventoryReferenceResolver
-
public final class InventoryReferenceResolver extends CustomReferenceResolver<com.commercetools.api.models.inventory.InventoryEntryDraft,com.commercetools.api.models.inventory.InventoryEntryDraftBuilder,InventorySyncOptions>
-
-
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 InventoryReferenceResolver(InventorySyncOptions options, TypeService typeService, ChannelService channelService)
Takes aInventorySyncOptions
instance, aTypeService
and aChannelService
to instantiate aInventoryReferenceResolver
instance that could be used to resolve the type and supply channel references of inventory drafts.
-
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(InventoryBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (supply channel and type) from the commercetools to populate caches for the reference resolution.protected java.util.concurrent.CompletionStage<com.commercetools.api.models.inventory.InventoryEntryDraftBuilder>
resolveCustomTypeReference(com.commercetools.api.models.inventory.InventoryEntryDraftBuilder draftBuilder)
Given a draft ofD
(e.g.java.util.concurrent.CompletionStage<com.commercetools.api.models.inventory.InventoryEntryDraft>
resolveReferences(com.commercetools.api.models.inventory.InventoryEntryDraft draft)
Given aInventoryEntryDraft
this method attempts to resolve the custom type and supply channel resource identifiers to return aCompletionStage
which contains a new instance of the draft with the resolved resource identifiers.-
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
-
InventoryReferenceResolver
public InventoryReferenceResolver(@Nonnull InventorySyncOptions options, @Nonnull TypeService typeService, @Nonnull ChannelService channelService)
Takes aInventorySyncOptions
instance, aTypeService
and aChannelService
to instantiate aInventoryReferenceResolver
instance that could be used to resolve the type and supply channel references of inventory drafts.- 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.channelService
- the service to fetch the supply channels for reference resolution.
-
-
Method Detail
-
resolveReferences
public java.util.concurrent.CompletionStage<com.commercetools.api.models.inventory.InventoryEntryDraft> resolveReferences(@Nonnull com.commercetools.api.models.inventory.InventoryEntryDraft draft)
Given aInventoryEntryDraft
this method attempts to resolve the custom type and supply channel resource identifiers to return aCompletionStage
which contains a new instance of the draft with the resolved resource identifiers.- Specified by:
resolveReferences
in classBaseReferenceResolver<com.commercetools.api.models.inventory.InventoryEntryDraft,InventorySyncOptions>
- Parameters:
draft
- the inventoryEntryDraft to resolve its resource identifiers.- Returns:
- a
CompletionStage
that contains as a result a new inventoryEntryDraft instance with resolved resource identifiers or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveCustomTypeReference
@Nonnull protected java.util.concurrent.CompletionStage<com.commercetools.api.models.inventory.InventoryEntryDraftBuilder> resolveCustomTypeReference(@Nonnull com.commercetools.api.models.inventory.InventoryEntryDraftBuilder 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.inventory.InventoryEntryDraft,com.commercetools.api.models.inventory.InventoryEntryDraftBuilder,InventorySyncOptions>
- 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 InventoryBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (supply channel and type) 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 inventory references to fetch and cache the id's for.- Returns:
CompletionStage
<List
<Map
<String
>String
>>> in which the results of it's completions contains a map of requested references keys -> ids of it's references.
-
-