Package com.commercetools.sync.services
Interface ProductService
- 
- All Known Implementing Classes:
 ProductServiceImpl
public interface ProductService 
- 
- 
Method Summary
All Methods Instance Methods Abstract 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> productKeys)Filters out the keys which are already cached and fetches only the not-cached product keys from the CTP project defined in an injectedSphereClientand stores a mapping for every product to id in the cached map of keys -> ids and returns this cached map.java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.products.ProductProjection>>createProduct(io.sphere.sdk.products.ProductDraft productDraft)Given a resource draft of typeProductDraft, this method attempts to create a resourceProductProjectionbased on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.products.ProductProjection>>fetchMatchingProductsByKeys(java.util.Set<java.lang.String> productKeys)Given aSetof product keys, this method fetches a set of all the products, matching this given set of keys in the CTP project, defined in an injectedSphereClient.java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.products.ProductProjection>>fetchProduct(java.lang.String key)Given a product key, this method fetches a product that matches this given key in the CTP project defined in a potentially injectedSphereClient.java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>>getIdFromCacheOrFetch(java.lang.String key)Given akey, if it is blank (null/empty), a completed future with an empty optional is returned.java.util.concurrent.CompletionStage<io.sphere.sdk.products.ProductProjection>updateProduct(io.sphere.sdk.products.ProductProjection product, java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> updateActions)Given aProductProjectionand aList<UpdateAction<Product>>, this method issues an update request with these update actions on thisProductProjectionin the CTP project defined in a potentially injectedSphereClient. 
 - 
 
- 
- 
Method Detail
- 
getIdFromCacheOrFetch
@Nonnull java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> getIdFromCacheOrFetch(@Nullable java.lang.String key)Given akey, if it is blank (null/empty), a completed future with an empty optional is returned. This method then checks if the cached map of product keys -> ids contains the key. If it does, then an optional containing the mapped id is returned. If the cache doesn't contain the key; this method attempts to fetch the id of the key from the CTP project, caches it and returns aCompletionStage<Optional<String>> in which the result of it's completion could contain anOptionalwith the id inside of it or an emptyOptionalif noProductProjectionwas found in the CTP project with this key.- Parameters:
 key- the key by which aProductProjectionid should be fetched from the CTP project.- Returns:
 CompletionStage<Optional<String>> in which the result of it's completion could contain anOptionalwith the id inside of it or an emptyOptionalif noProductProjectionwas found in the CTP project with this key.
 
- 
cacheKeysToIds
@Nonnull java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> cacheKeysToIds(@Nonnull java.util.Set<java.lang.String> productKeys)Filters out the keys which are already cached and fetches only the not-cached product keys from the CTP project defined in an injectedSphereClientand stores a mapping for every product 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.
- Parameters:
 productKeys- the product keys to fetch and cache the ids for.- Returns:
 CompletionStage<Map> in which the result of it's completion contains a map of all product keys -> ids
 
- 
fetchMatchingProductsByKeys
@Nonnull java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.products.ProductProjection>> fetchMatchingProductsByKeys(@Nonnull java.util.Set<java.lang.String> productKeys)Given aSetof product keys, this method fetches a set of all the products, 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 products is persisted in an in-memory map.- Parameters:
 productKeys- set of product keys to fetch matching products by.- Returns:
 CompletionStage<Map> in which the result of it's completion contains aSetof all matching products.
 
- 
fetchProduct
@Nonnull java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.products.ProductProjection>> fetchProduct(@Nullable java.lang.String key)Given a product key, this method fetches a product that matches this given key in the CTP project defined in a potentially injectedSphereClient. If there is no matching product an emptyOptionalwill 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.- Parameters:
 key- the key of the product to fetch.- Returns:
 CompletionStage<Optional> in which the result of it's completion contains anOptionalthat contains the matchingProductProjectionif exists, otherwise empty.
 
- 
createProduct
@Nonnull java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.products.ProductProjection>> createProduct(@Nonnull io.sphere.sdk.products.ProductDraft productDraft)Given a resource draft of typeProductDraft, this method attempts to create a resourceProductProjectionbased 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
CompletionStagein which the result of it's completion contains an instanceOptionalof the resource which was created.- Parameters:
 productDraft- the resource draft to create a resource based off of.- Returns:
 - a 
CompletionStagecontaining an optional with the created resource if successful otherwise an empty optional. 
 
- 
updateProduct
@Nonnull java.util.concurrent.CompletionStage<io.sphere.sdk.products.ProductProjection> updateProduct(@Nonnull io.sphere.sdk.products.ProductProjection product, @Nonnull java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.products.Product>> updateActions)Given aProductProjectionand aList<UpdateAction<Product>>, this method issues an update request with these update actions on thisProductProjectionin the CTP project defined in a potentially injectedSphereClient. This method returnsCompletionStage<ProductProjection> in which the result of it's completion contains an instance of theProductProjectionwhich was updated in the CTP project.- Parameters:
 product- theProductProjectionto update.updateActions- the update actions to update theProductProjectionwith.- Returns:
 CompletionStage<ProductProjection> containing as a result of it's completion an instance of theProductProjectionwhich was updated in the CTP project or aSphereException.
 
 - 
 
 -