Class TaxCategoryServiceImpl
- java.lang.Object
-
- com.commercetools.sync.services.impl.TaxCategoryServiceImpl
-
- All Implemented Interfaces:
TaxCategoryService
public final class TaxCategoryServiceImpl extends java.lang.Object implements TaxCategoryService
-
-
Field Summary
Fields Modifier and Type Field Description protected com.github.benmanes.caffeine.cache.Cache<java.lang.String,java.lang.String>
keyToIdCache
protected static int
MAXIMUM_ALLOWED_UPDATE_ACTIONS
-
Constructor Summary
Constructors Constructor Description TaxCategoryServiceImpl(TaxCategorySyncOptions syncOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>>
cacheKeysToIds(java.util.Set<java.lang.String> taxCategoryKeys)
Filters out the keys which are already cached and fetches only the not-cached tax category keys from the CTP project defined in an injectedProjectApiRoot
and stores a mapping for every tax category to id in the cached map of keys -> ids and returns this cached map.java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>>
cacheKeysToIdsUsingGraphQl(java.util.Set<java.lang.String> keysToCache, GraphQlQueryResource queryResource)
java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.tax_category.TaxCategory>>
createTaxCategory(com.commercetools.api.models.tax_category.TaxCategoryDraft taxCategoryDraft)
Given a resource draft ofTaxCategoryDraft
, this method attempts to create a resourceTaxCategory
based on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>>
fetchCachedTaxCategoryId(java.lang.String key)
Given akey
, this method first checks if a cached map of TaxCategory keys -> ids is not empty.java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.tax_category.TaxCategory>>
fetchMatchingTaxCategoriesByKeys(java.util.Set<java.lang.String> keys)
Given aSet
of tax category keys, this method fetches a set of all the taxCategories, matching given set of keys in the CTP project, defined in an injectedProjectApiRoot
.java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.tax_category.TaxCategory>>
fetchTaxCategory(java.lang.String key)
Given a tax category key, this method fetches a tax category that matches given key in the CTP project defined in a potentially injectedProjectApiRoot
.protected java.util.Set<java.lang.String>
getKeysNotCached(java.util.Set<java.lang.String> keys)
Given a set of keys this method collects all keys which aren't already contained in the cachekeyToIdCache
java.util.concurrent.CompletionStage<com.commercetools.api.models.tax_category.TaxCategory>
updateTaxCategory(com.commercetools.api.models.tax_category.TaxCategory taxCategory, java.util.List<com.commercetools.api.models.tax_category.TaxCategoryUpdateAction> updateActions)
Given aTaxCategory
and aList
<TaxCategoryUpdateAction
<TaxCategory
>>, this method issues an update request with these update actions on thisTaxCategory
in the CTP project defined in a potentially injectedProjectApiRoot
.
-
-
-
Field Detail
-
keyToIdCache
protected final com.github.benmanes.caffeine.cache.Cache<java.lang.String,java.lang.String> keyToIdCache
-
MAXIMUM_ALLOWED_UPDATE_ACTIONS
protected static final int MAXIMUM_ALLOWED_UPDATE_ACTIONS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TaxCategoryServiceImpl
public TaxCategoryServiceImpl(@Nonnull TaxCategorySyncOptions syncOptions)
-
-
Method Detail
-
cacheKeysToIds
@Nonnull public java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> cacheKeysToIds(@Nonnull java.util.Set<java.lang.String> taxCategoryKeys)
Description copied from interface:TaxCategoryService
Filters out the keys which are already cached and fetches only the not-cached tax category keys from the CTP project defined in an injectedProjectApiRoot
and stores a mapping for every tax category to id in the cached map of keys -> ids and returns this cached map.- Specified by:
cacheKeysToIds
in interfaceTaxCategoryService
- Parameters:
taxCategoryKeys
- - a set of tax category keys to fetch and cache the ids for- Returns:
CompletionStage
<Map
> in which the result of it's completion contains a map of requested tax category keys -> ids
-
fetchCachedTaxCategoryId
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedTaxCategoryId(@Nullable java.lang.String key)
Description copied from interface:TaxCategoryService
Given akey
, this method first checks if a cached map of TaxCategory keys -> ids is not empty. If not, it returns a completed future that contains an optional that contains what this key maps to in the cache. If the cache is empty, the method populates the cache with the mapping of all TaxCategory keys to ids in the CTP project, by querying the CTP project for all Tax categories.After that, the method returns a
CompletionStage
<Optional
<String
>> in which the result of it's completion could contain anOptional
with the id inside of it or an emptyOptional
if noTaxCategory
was found in the CTP project with this key.- Specified by:
fetchCachedTaxCategoryId
in interfaceTaxCategoryService
- Parameters:
key
- the key by which aTaxCategory
id should be fetched from the CTP project.- Returns:
CompletionStage
<Optional
<String
>> in which the result of its completion could contain anOptional
with the id inside of it or an emptyOptional
if noTaxCategory
was found in the CTP project with this key.
-
fetchMatchingTaxCategoriesByKeys
@Nonnull public java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.tax_category.TaxCategory>> fetchMatchingTaxCategoriesByKeys(@Nonnull java.util.Set<java.lang.String> keys)
Description copied from interface:TaxCategoryService
Given aSet
of tax category keys, this method fetches a set of all the taxCategories, matching given set of keys in the CTP project, defined in an injectedProjectApiRoot
. A mapping of the key to the id of the fetched taxCategories is persisted in an in-memory map.
One must remember key is not required to create TaxCategory but is required to synchronize tax categories.- Specified by:
fetchMatchingTaxCategoriesByKeys
in interfaceTaxCategoryService
- Parameters:
keys
- set of tax category keys to fetch matching taxCategories by.- Returns:
CompletionStage
<Map
> in which the result of it's completion contains aSet
of all matching taxCategories.
-
fetchTaxCategory
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.tax_category.TaxCategory>> fetchTaxCategory(@Nullable java.lang.String key)
Description copied from interface:TaxCategoryService
Given a tax category key, this method fetches a tax category that matches given key in the CTP project defined in a potentially injectedProjectApiRoot
. If there is no matching tax category an emptyOptional
will be returned in the returned future. A mapping of the key to the id of the fetched category is persisted in an in-memory map.- Specified by:
fetchTaxCategory
in interfaceTaxCategoryService
- Parameters:
key
- the key of the tax category to fetch.- Returns:
CompletionStage
<Optional
> in which the result of it's completion contains anOptional
that contains the matchingTaxCategory
if exists, otherwise empty.
-
createTaxCategory
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.tax_category.TaxCategory>> createTaxCategory(@Nonnull com.commercetools.api.models.tax_category.TaxCategoryDraft taxCategoryDraft)
Description copied from interface:TaxCategoryService
Given a resource draft ofTaxCategoryDraft
, this method attempts to create a resourceTaxCategory
based on it in the CTP project defined by the sync options.A completion stage containing an empty option and the error callback will be triggered in those cases:
- the draft has a blank key
- the create request fails on CTP
On the other hand, if the resource gets created successfully on CTP, then the created resource's id and key are cached and the method returns a
CompletionStage
in which the result of it's completion contains an instanceOptional
of the resource which was created.- Specified by:
createTaxCategory
in interfaceTaxCategoryService
- Parameters:
taxCategoryDraft
- the resource draft to create a resource based off of.- Returns:
- a
CompletionStage
containing an optional with the created resource if successful otherwise an empty optional.
-
updateTaxCategory
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.tax_category.TaxCategory> updateTaxCategory(@Nonnull com.commercetools.api.models.tax_category.TaxCategory taxCategory, @Nonnull java.util.List<com.commercetools.api.models.tax_category.TaxCategoryUpdateAction> updateActions)
Description copied from interface:TaxCategoryService
Given aTaxCategory
and aList
<TaxCategoryUpdateAction
<TaxCategory
>>, this method issues an update request with these update actions on thisTaxCategory
in the CTP project defined in a potentially injectedProjectApiRoot
. This method returnsCompletionStage
<TaxCategory
> in which the result of it's completion contains an instance of theTaxCategory
which was updated in the CTP project.- Specified by:
updateTaxCategory
in interfaceTaxCategoryService
- Parameters:
taxCategory
- theTaxCategory
to update.updateActions
- the update actions to update theTaxCategory
with.- Returns:
CompletionStage
<TaxCategory
> containing as a result of it's completion an instance of theTaxCategory
which was updated in the CTP project or aCompletionException
.
-
getKeysNotCached
@Nonnull protected java.util.Set<java.lang.String> getKeysNotCached(@Nonnull java.util.Set<java.lang.String> keys)
Given a set of keys this method collects all keys which aren't already contained in the cachekeyToIdCache
- Parameters:
keys
-Set
of keys- Returns:
- a
Set
of keys which aren't already contained in the cache or empty
-
cacheKeysToIdsUsingGraphQl
@Nonnull public java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> cacheKeysToIdsUsingGraphQl(@Nonnull java.util.Set<java.lang.String> keysToCache, @Nonnull GraphQlQueryResource queryResource)
-
-