Class CartDiscountServiceImpl
- java.lang.Object
-
- com.commercetools.sync.services.impl.CartDiscountServiceImpl
-
- All Implemented Interfaces:
CartDiscountService
public class CartDiscountServiceImpl extends java.lang.Object implements CartDiscountService
-
-
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 CartDiscountServiceImpl(CartDiscountSyncOptions 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>>
cacheKeysToIdsUsingGraphQl(java.util.Set<java.lang.String> keysToCache, GraphQlQueryResource queryResource)
java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.cart_discount.CartDiscount>>
createCartDiscount(com.commercetools.api.models.cart_discount.CartDiscountDraft cartDiscountDraft)
Given a resource draft of typeCartDiscountDraft
, this method attempts to create a resourceCartDiscount
based on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.cart_discount.CartDiscount>>
fetchCartDiscount(java.lang.String key)
Given a cart discount key, this method fetches a cart discount that matches this given key in the CTP project defined in a potentially injectedProjectApiRoot
.java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.cart_discount.CartDiscount>>
fetchMatchingCartDiscountsByKeys(java.util.Set<java.lang.String> keys)
Given aSet
of CartDiscount keys, this method fetches a set of all the CartDiscounts, matching this given set of keys in the CTP project, defined in an 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.cart_discount.CartDiscount>
updateCartDiscount(com.commercetools.api.models.cart_discount.CartDiscount cartDiscount, java.util.List<com.commercetools.api.models.cart_discount.CartDiscountUpdateAction> updateActions)
Given aCartDiscount
and aList
<CartDiscountUpdateAction
>, this method issues an update request with these update actions on thisCartDiscount
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
-
CartDiscountServiceImpl
public CartDiscountServiceImpl(@Nonnull CartDiscountSyncOptions syncOptions)
-
-
Method Detail
-
fetchMatchingCartDiscountsByKeys
@Nonnull public java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.cart_discount.CartDiscount>> fetchMatchingCartDiscountsByKeys(@Nonnull java.util.Set<java.lang.String> keys)
Description copied from interface:CartDiscountService
Given aSet
of CartDiscount keys, this method fetches a set of all the CartDiscounts, matching this given set of keys in the CTP project, defined in an injectedProjectApiRoot
. A mapping of the key to the id of the fetched CartDiscount is persisted in an in-memory map.- Specified by:
fetchMatchingCartDiscountsByKeys
in interfaceCartDiscountService
- Parameters:
keys
- set of CartDiscounts keys to fetch matching CartDiscount by.- Returns:
CompletionStage
<Set
> in which the result of its completion contains aSet
of all matching CartDiscounts.
-
fetchCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.cart_discount.CartDiscount>> fetchCartDiscount(@Nullable java.lang.String key)
Description copied from interface:CartDiscountService
Given a cart discount key, this method fetches a cart discount that matches this given key in the CTP project defined in a potentially injectedProjectApiRoot
. If there is no matching cart discount an emptyOptional
will be returned in the returned future. A mapping of the key to the id of the fetched cart discount is persisted in an in-memory map.- Specified by:
fetchCartDiscount
in interfaceCartDiscountService
- Parameters:
key
- the key of the product to fetch.- Returns:
CompletionStage
<Optional
> in which the result of it's completion contains anOptional
that contains the matchingCartDiscount
if exists, otherwise empty.
-
createCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.cart_discount.CartDiscount>> createCartDiscount(@Nonnull com.commercetools.api.models.cart_discount.CartDiscountDraft cartDiscountDraft)
Description copied from interface:CartDiscountService
Given a resource draft of typeCartDiscountDraft
, this method attempts to create a resourceCartDiscount
based on it in the CTP project defined by the sync options.A completion stage containing an empty
Optional
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 CartDiscount gets created successfully on CTP, then the created CartDiscount's id and key are cached. The method returns a
CompletionStage
in which the result of it's completion contains an instanceOptional
of the created `CartDiscount`.- Specified by:
createCartDiscount
in interfaceCartDiscountService
- Parameters:
cartDiscountDraft
- the resource draft to create a resource based off of.- Returns:
- a
CompletionStage
containing an optional with the createdCartDiscount
if successful otherwise an empty optional.
-
updateCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<com.commercetools.api.models.cart_discount.CartDiscount> updateCartDiscount(@Nonnull com.commercetools.api.models.cart_discount.CartDiscount cartDiscount, @Nonnull java.util.List<com.commercetools.api.models.cart_discount.CartDiscountUpdateAction> updateActions)
Description copied from interface:CartDiscountService
Given aCartDiscount
and aList
<CartDiscountUpdateAction
>, this method issues an update request with these update actions on thisCartDiscount
in the CTP project defined in a potentially injectedProjectApiRoot
. This method returnsCompletionStage
<CartDiscount
> in which the result of its completion contains an instance of theCartDiscount
which was updated in the CTP project.- Specified by:
updateCartDiscount
in interfaceCartDiscountService
- Parameters:
cartDiscount
- theCartDiscount
to update.updateActions
- the update actions to update theCartDiscount
with.- Returns:
CompletionStage
<CartDiscount
> containing as a result of its completion an instance of theCartDiscount
which was updated in the CTP project or an exception.
-
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)
-
-