Class ShoppingListServiceImpl
- java.lang.Object
-
- com.commercetools.sync.services.impl.ShoppingListServiceImpl
-
- All Implemented Interfaces:
ShoppingListService
public final class ShoppingListServiceImpl extends java.lang.Object implements ShoppingListService
Implementation of ShoppingListService interface.
-
-
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 ShoppingListServiceImpl(ShoppingListSyncOptions 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> shoppingListKeys)
Filters out the keys which are already cached and fetches only the not-cached shopping list keys from the CTP project defined in an injectedProjectApiRoot
and stores a mapping for every shopping list 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.shopping_list.ShoppingList>>
createShoppingList(com.commercetools.api.models.shopping_list.ShoppingListDraft shoppingListDraft)
Given a resource draft of typeShoppingListDraft
, this method attempts to create a resourceShoppingList
based on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.shopping_list.ShoppingList>>
fetchMatchingShoppingListsByKeys(java.util.Set<java.lang.String> keys)
Given aSet
of shopping list keys, this method fetches a set of all the shopping lists, matching given set of keys in the CTP project, defined in an injectedProjectApiRoot
.java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingList>>
fetchShoppingList(java.lang.String key)
Given a shopping list key, this method fetches a shopping list 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.shopping_list.ShoppingList>
updateShoppingList(com.commercetools.api.models.shopping_list.ShoppingList shoppingList, java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> updateActions)
Given aShoppingList
and aList
<ShoppingListUpdateAction
>, this method issues an update request with these update actions on thisShoppingList
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
-
ShoppingListServiceImpl
public ShoppingListServiceImpl(@Nonnull ShoppingListSyncOptions 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> shoppingListKeys)
Description copied from interface:ShoppingListService
Filters out the keys which are already cached and fetches only the not-cached shopping list keys from the CTP project defined in an injectedProjectApiRoot
and stores a mapping for every shopping list to id in the cached map of keys -> ids and returns this cached map.Note: If all the supplied keys are already cached, the cached map is returned right away with no request to CTP.
- Specified by:
cacheKeysToIds
in interfaceShoppingListService
- Parameters:
shoppingListKeys
- the shopping list keys to fetch and cache the ids for.- Returns:
CompletionStage
<Map
> in which the result of it's completion contains a map of all shopping list keys -> ids
-
fetchMatchingShoppingListsByKeys
@Nonnull public java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.shopping_list.ShoppingList>> fetchMatchingShoppingListsByKeys(@Nonnull java.util.Set<java.lang.String> keys)
Description copied from interface:ShoppingListService
Given aSet
of shopping list keys, this method fetches a set of all the shopping lists, matching given set of keys in the CTP project, defined in an injectedProjectApiRoot
. A mapping of the key to the id of the fetched shopping lists is persisted in an in-memory map.- Specified by:
fetchMatchingShoppingListsByKeys
in interfaceShoppingListService
- Parameters:
keys
- set of shopping list keys to fetch matching shopping lists by.- Returns:
CompletionStage
<Map
> in which the result of it's completion contains aSet
of all matching shopping lists.
-
fetchShoppingList
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingList>> fetchShoppingList(@Nullable java.lang.String key)
Description copied from interface:ShoppingListService
Given a shopping list key, this method fetches a shopping list that matches given key in the CTP project defined in a potentially injectedProjectApiRoot
. If there is no matching shopping list, an emptyOptional
will be returned in the returned future. A mapping of the key to the id of the fetched shopping list is persisted in an in-memory map.- Specified by:
fetchShoppingList
in interfaceShoppingListService
- Parameters:
key
- the key of the shopping list to fetch.- Returns:
CompletionStage
<Optional
> in which the result of its completion contains anOptional
that contains the matchingShoppingList
if exists, otherwise empty.
-
createShoppingList
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.shopping_list.ShoppingList>> createShoppingList(@Nonnull com.commercetools.api.models.shopping_list.ShoppingListDraft shoppingListDraft)
Description copied from interface:ShoppingListService
Given a resource draft of typeShoppingListDraft
, this method attempts to create a resourceShoppingList
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:
createShoppingList
in interfaceShoppingListService
- Parameters:
shoppingListDraft
- 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.
-
updateShoppingList
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.shopping_list.ShoppingList> updateShoppingList(@Nonnull com.commercetools.api.models.shopping_list.ShoppingList shoppingList, @Nonnull java.util.List<com.commercetools.api.models.shopping_list.ShoppingListUpdateAction> updateActions)
Description copied from interface:ShoppingListService
Given aShoppingList
and aList
<ShoppingListUpdateAction
>, this method issues an update request with these update actions on thisShoppingList
in the CTP project defined in a potentially injectedProjectApiRoot
. This method returnsCompletionStage
<ShoppingList
> in which the result of it's completion contains an instance of theShoppingList
which was updated in the CTP project.- Specified by:
updateShoppingList
in interfaceShoppingListService
- Parameters:
shoppingList
- theShoppingList
to update.updateActions
- the update actions to update theShoppingList
with.- Returns:
CompletionStage
<ShoppingList
> containing as a result of it's completion an instance of theShoppingList
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)
-
-