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>keyToIdCacheprotected static intMAXIMUM_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.Optional<io.sphere.sdk.cartdiscounts.CartDiscount>>createCartDiscount(io.sphere.sdk.cartdiscounts.CartDiscountDraft cartDiscountDraft)Given a resource draft of typeCartDiscountDraft, this method attempts to create a resourceCartDiscountbased on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.cartdiscounts.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 injectedSphereClient.java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.cartdiscounts.CartDiscount>>fetchMatchingCartDiscountsByKeys(java.util.Set<java.lang.String> keys)Given aSetof CartDiscount keys, this method fetches a set of all the CartDiscounts, matching this given set of keys in the CTP project, defined in an injectedSphereClient.java.util.concurrent.CompletionStage<io.sphere.sdk.cartdiscounts.CartDiscount>updateCartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount cartDiscount, java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.cartdiscounts.CartDiscount>> updateActions)Given aCartDiscountand aList<UpdateAction<CartDiscount>>, this method issues an update request with these update actions on thisCartDiscountin the CTP project defined in a potentially injectedSphereClient.
-
-
-
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<io.sphere.sdk.cartdiscounts.CartDiscount>> fetchMatchingCartDiscountsByKeys(@Nonnull java.util.Set<java.lang.String> keys)Description copied from interface:CartDiscountServiceGiven aSetof CartDiscount keys, this method fetches a set of all the CartDiscounts, matching this given set of keys in the CTP project, defined in an injectedSphereClient. A mapping of the key to the id of the fetched CartDiscount is persisted in an in-memory map.- Specified by:
fetchMatchingCartDiscountsByKeysin interfaceCartDiscountService- Parameters:
keys- set of CartDiscounts keys to fetch matching CartDiscount by.- Returns:
CompletionStage<Set> in which the result of its completion contains aSetof all matching CartDiscounts.
-
fetchCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.cartdiscounts.CartDiscount>> fetchCartDiscount(@Nullable java.lang.String key)Description copied from interface:CartDiscountServiceGiven a cart discount key, this method fetches a cart discount that matches this given key in the CTP project defined in a potentially injectedSphereClient. If there is no matching cart discount an emptyOptionalwill 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:
fetchCartDiscountin interfaceCartDiscountService- Parameters:
key- the key of the product to fetch.- Returns:
CompletionStage<Optional> in which the result of it's completion contains anOptionalthat contains the matchingCartDiscountif exists, otherwise empty.
-
createCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.cartdiscounts.CartDiscount>> createCartDiscount(@Nonnull io.sphere.sdk.cartdiscounts.CartDiscountDraft cartDiscountDraft)Description copied from interface:CartDiscountServiceGiven a resource draft of typeCartDiscountDraft, this method attempts to create a resourceCartDiscountbased on it in the CTP project defined by the sync options.A completion stage containing an empty
Optionaland 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
CompletionStagein which the result of it's completion contains an instanceOptionalof the created `CartDiscount`.- Specified by:
createCartDiscountin interfaceCartDiscountService- Parameters:
cartDiscountDraft- the resource draft to create a resource based off of.- Returns:
- a
CompletionStagecontaining an optional with the createdCartDiscountif successful otherwise an empty optional.
-
updateCartDiscount
@Nonnull public java.util.concurrent.CompletionStage<io.sphere.sdk.cartdiscounts.CartDiscount> updateCartDiscount(@Nonnull io.sphere.sdk.cartdiscounts.CartDiscount cartDiscount, @Nonnull java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.cartdiscounts.CartDiscount>> updateActions)Description copied from interface:CartDiscountServiceGiven aCartDiscountand aList<UpdateAction<CartDiscount>>, this method issues an update request with these update actions on thisCartDiscountin the CTP project defined in a potentially injectedSphereClient. This method returnsCompletionStage<CartDiscount> in which the result of its completion contains an instance of theCartDiscountwhich was updated in the CTP project.- Specified by:
updateCartDiscountin interfaceCartDiscountService- Parameters:
cartDiscount- theCartDiscountto update.updateActions- the update actions to update theCartDiscountwith.- Returns:
CompletionStage<CartDiscount> containing as a result of its completion an instance of theCartDiscountwhich was updated in the CTP project or aSphereException.
-
-