Class ProductReferenceResolver
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseReferenceResolver<com.commercetools.api.models.product.ProductDraft,ProductSyncOptions>
-
- com.commercetools.sync.products.helpers.ProductReferenceResolver
-
public final class ProductReferenceResolver extends BaseReferenceResolver<com.commercetools.api.models.product.ProductDraft,ProductSyncOptions>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CATEGORIES_DO_NOT_EXIST
static java.lang.String
FAILED_TO_RESOLVE_REFERENCE
static java.lang.String
PRODUCT_TYPE_DOES_NOT_EXIST
static java.lang.String
STATE_DOES_NOT_EXIST
static java.lang.String
TAX_CATEGORY_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 ProductReferenceResolver(ProductSyncOptions productSyncOptions, ProductTypeService productTypeService, CategoryService categoryService, TypeService typeService, ChannelService channelService, CustomerGroupService customerGroupService, TaxCategoryService taxCategoryService, StateService stateService, ProductService productService, CustomObjectService customObjectService, CustomerService customerService)
Takes aProductSyncOptions
instance, aProductTypeService
, aCategoryService
, aTypeService
, aChannelService
, aCustomerGroupService
, aTaxCategoryService
, aStateService
and aProductService
to instantiate aProductReferenceResolver
instance that could be used to resolve the product type, categories, variants, tax category and product state references of product drafts in the CTP project specified in the injectedProductSyncOptions
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,java.lang.String>>
populateKeyToIdCachesForReferencedKeys(ProductBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e product type, product attribute) from the commercetools to populate caches for the reference resolution.java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder>
resolveCategoryReferences(com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the categories and categoryOrderHints to return aCompletionStage
which contains a new instance of the builder with the resolved references.java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder>
resolveProductTypeReference(com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the product type to return aCompletionStage
which contains a new instance of the builder with the resolved product type reference.java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraft>
resolveReferences(com.commercetools.api.models.product.ProductDraft productDraft)
Given aProductDraft
this method attempts to resolve the product type, categories, variants, tax category and product state references to return aCompletionStage
which contains a new instance of the draft with the resolved references.java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder>
resolveStateReference(com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the state to return aCompletionStage
which contains a new instance of the builder with the resolved state reference.java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder>
resolveTaxCategoryReference(com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the tax category to return aCompletionStage
which contains a new instance of the builder with the resolved tax category reference.-
Methods inherited from class com.commercetools.sync.commons.helpers.BaseReferenceResolver
getIdFromReference, getKeyFromResourceIdentifier
-
-
-
-
Field Detail
-
FAILED_TO_RESOLVE_REFERENCE
public static final java.lang.String FAILED_TO_RESOLVE_REFERENCE
- See Also:
- Constant Field Values
-
PRODUCT_TYPE_DOES_NOT_EXIST
public static final java.lang.String PRODUCT_TYPE_DOES_NOT_EXIST
- See Also:
- Constant Field Values
-
TAX_CATEGORY_DOES_NOT_EXIST
public static final java.lang.String TAX_CATEGORY_DOES_NOT_EXIST
- See Also:
- Constant Field Values
-
CATEGORIES_DO_NOT_EXIST
public static final java.lang.String CATEGORIES_DO_NOT_EXIST
- See Also:
- Constant Field Values
-
STATE_DOES_NOT_EXIST
public static final java.lang.String STATE_DOES_NOT_EXIST
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ProductReferenceResolver
public ProductReferenceResolver(@Nonnull ProductSyncOptions productSyncOptions, @Nonnull ProductTypeService productTypeService, @Nonnull CategoryService categoryService, @Nonnull TypeService typeService, @Nonnull ChannelService channelService, @Nonnull CustomerGroupService customerGroupService, @Nonnull TaxCategoryService taxCategoryService, @Nonnull StateService stateService, @Nonnull ProductService productService, @Nonnull CustomObjectService customObjectService, @Nonnull CustomerService customerService)
Takes aProductSyncOptions
instance, aProductTypeService
, aCategoryService
, aTypeService
, aChannelService
, aCustomerGroupService
, aTaxCategoryService
, aStateService
and aProductService
to instantiate aProductReferenceResolver
instance that could be used to resolve the product type, categories, variants, tax category and product state references of product drafts in the CTP project specified in the injectedProductSyncOptions
instance.- Parameters:
productSyncOptions
- the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.productTypeService
- the service to fetch the product type for reference resolution.categoryService
- the service to fetch the categories for reference resolution.typeService
- the service to fetch the custom types for reference resolution.channelService
- the service to fetch the channels for reference resolution.customerGroupService
- the service to fetch the customer groups for reference resolution.taxCategoryService
- the service to fetch tax categories for reference resolution.stateService
- the service to fetch product states for reference resolution.productService
- the service to fetch products for product reference resolution on reference attributes.customObjectService
- the service to fetch custom objects for reference resolution.customerService
- the service to fetch customers for reference resolution.
-
-
Method Detail
-
resolveReferences
public java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraft> resolveReferences(@Nonnull com.commercetools.api.models.product.ProductDraft productDraft)
Given aProductDraft
this method attempts to resolve the product type, categories, variants, tax category and product state 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.product.ProductDraft,ProductSyncOptions>
- Parameters:
productDraft
- the productDraft to resolve it's references.- Returns:
- a
CompletionStage
that contains as a result a new productDraft instance with resolved references or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveProductTypeReference
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder> resolveProductTypeReference(@Nonnull com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the product type to return aCompletionStage
which contains a new instance of the builder with the resolved product type reference.- Parameters:
draftBuilder
- the productDraft to resolve its product type reference.- Returns:
- a
CompletionStage
that contains as a result a new builder instance with resolved product type reference or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveCategoryReferences
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder> resolveCategoryReferences(@Nonnull com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the categories and categoryOrderHints to return aCompletionStage
which contains a new instance of the builder with the resolved references.- Parameters:
draftBuilder
- the productDraft to resolve its category and categoryOrderHints 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
.
-
resolveTaxCategoryReference
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder> resolveTaxCategoryReference(@Nonnull com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the tax category to return aCompletionStage
which contains a new instance of the builder with the resolved tax category reference.- Parameters:
draftBuilder
- the productDraft to resolve its tax category reference.- Returns:
- a
CompletionStage
that contains as a result a new builder instance with resolved tax category reference or, in case an error occurs during reference resolution, aReferenceResolutionException
.
-
resolveStateReference
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.product.ProductDraftBuilder> resolveStateReference(@Nonnull com.commercetools.api.models.product.ProductDraftBuilder draftBuilder)
Given aProductDraftBuilder
this method attempts to resolve the state to return aCompletionStage
which contains a new instance of the builder with the resolved state reference.Note: The key of the state reference taken from the value of the id field of the reference.
- Parameters:
draftBuilder
- the productDraft to resolve its state reference.- Returns:
- a
CompletionStage
that contains as a result a new builder instance with resolved state reference or, in case an error occurs during reference resolution, the future is completed exceptionally with aReferenceResolutionException
.
-
populateKeyToIdCachesForReferencedKeys
@Nonnull public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,java.lang.String>> populateKeyToIdCachesForReferencedKeys(@Nonnull ProductBatchValidator.ReferencedKeys referencedKeys)
Calls thecacheKeysToIds
service methods to fetch all the referenced keys (i.e product type, product attribute) 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 product references.
-
-