public final class ProductTypeServiceImpl extends java.lang.Object implements ProductTypeService
Modifier and Type | Field and Description |
---|---|
protected com.github.benmanes.caffeine.cache.Cache<java.lang.String,java.lang.String> |
keyToIdCache |
protected static int |
MAXIMUM_ALLOWED_UPDATE_ACTIONS |
Constructor and Description |
---|
ProductTypeServiceImpl(BaseSyncOptions syncOptions) |
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> |
cacheKeysToIds(java.util.Set<java.lang.String> keys)
Filters out the keys which are already cached and fetches only the not-cached product type keys
from the CTP project defined in an injected
SphereClient and stores a mapping for every
productType to id in the cached map of keys -> ids and returns this cached map. |
java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.producttypes.ProductType>> |
createProductType(io.sphere.sdk.producttypes.ProductTypeDraft productTypeDraft)
Given a resource draft of type
ProductTypeDraft , this method attempts to create a
resource ProductType based on it in the CTP project defined by the sync options. |
java.util.concurrent.CompletionStage<java.util.Optional<java.util.Map<java.lang.String,AttributeMetaData>>> |
fetchCachedProductAttributeMetaDataMap(java.lang.String productTypeId)
Given a
productType , this method first checks if a cached map of ProductType ids ->
map of AttributeMetaData is not empty. |
java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> |
fetchCachedProductTypeId(java.lang.String key)
Given a
key , this method first checks if a cached map of ProductType keys -> ids
contains the key. |
java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.producttypes.ProductType>> |
fetchMatchingProductTypesByKeys(java.util.Set<java.lang.String> keys)
Given a
Set of ProductType keys, this method fetches a set of all the ProductTypes,
matching this given set of keys in the CTP project, defined in an injected SphereClient . |
java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.producttypes.ProductType>> |
fetchProductType(java.lang.String key)
Given a productType key, this method fetches a productType that matches this given key in the
CTP project defined in an injected
SphereClient . |
java.util.concurrent.CompletionStage<io.sphere.sdk.producttypes.ProductType> |
updateProductType(io.sphere.sdk.producttypes.ProductType productType,
java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.producttypes.ProductType>> updateActions)
Updates existing product type with
updateActions . |
protected final com.github.benmanes.caffeine.cache.Cache<java.lang.String,java.lang.String> keyToIdCache
protected static final int MAXIMUM_ALLOWED_UPDATE_ACTIONS
public ProductTypeServiceImpl(@Nonnull BaseSyncOptions syncOptions)
@Nonnull public java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> cacheKeysToIds(@Nonnull java.util.Set<java.lang.String> keys)
ProductTypeService
SphereClient
and stores a mapping for every
productType 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.
cacheKeysToIds
in interface ProductTypeService
keys
- the productType keys to fetch and cache the ids for.CompletionStage
<Map
> in which the result of it's completion
contains a map of all productType keys -> ids@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedProductTypeId(@Nonnull java.lang.String key)
ProductTypeService
key
, this method first checks if a cached map of ProductType keys -> ids
contains the key. If not, it returns a completed future that contains an Optional
that
contains what this key maps to in the cache. 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 a CompletionStage
<Optional
<String
>> in which the result of it's
completion could contain an Optional
with the id inside of it or an empty Optional
if no ProductType
was found in the CTP project with this key.fetchCachedProductTypeId
in interface ProductTypeService
key
- the key by which a ProductType
id should be fetched from the CTP project.CompletionStage
<Optional
<String
>> in which the
result of its completion could contain an Optional
with the id inside of it or an
empty Optional
if no ProductType
was found in the CTP project with this
key.@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<java.util.Map<java.lang.String,AttributeMetaData>>> fetchCachedProductAttributeMetaDataMap(@Nonnull java.lang.String productTypeId)
ProductTypeService
productType
, this method first checks if a cached map of ProductType ids ->
map of AttributeMetaData
is not empty. If not, it returns a completed future that
contains an optional that contains what this productType id maps to in the cache. If the cache
is empty, the method populates the cache with the mapping of all ProductType ids to maps of
each product type's attributes' AttributeMetaData
in the CTP project, by querying the
CTP project for all ProductTypes.
After that, the method returns a CompletionStage
<Optional
<String
>> in which the result of it's completion could contain an Optional
with a
map of the attributes names -> AttributeMetaData
inside of it or an empty Optional
if no ProductType
was found in the CTP project with this id.
fetchCachedProductAttributeMetaDataMap
in interface ProductTypeService
productTypeId
- the id by which a a map of the attributes names -> AttributeMetaData
corresponding to the product type should be fetched from the CTP
project.CompletionStage
<Optional
<String
>> in which the
result of its completion could contain an Optional
with the id inside of it or an
empty Optional
if no ProductType
was found in the CTP project with this
key.@Nonnull public java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.producttypes.ProductType>> fetchMatchingProductTypesByKeys(@Nonnull java.util.Set<java.lang.String> keys)
ProductTypeService
Set
of ProductType keys, this method fetches a set of all the ProductTypes,
matching this given set of keys in the CTP project, defined in an injected SphereClient
. A mapping of the key to the id of the fetched ProductType
is persisted in an in-memory map.fetchMatchingProductTypesByKeys
in interface ProductTypeService
keys
- set of ProductType keys to fetch matching ProductTypes by.CompletionStage
<Map
> in which the result of it's completion
contains a Set
of all matching ProductType.@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.producttypes.ProductType>> createProductType(@Nonnull io.sphere.sdk.producttypes.ProductTypeDraft productTypeDraft)
ProductTypeService
ProductTypeDraft
, this method attempts to create a
resource ProductType
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:
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 instance Optional
of the resource which was
created.
createProductType
in interface ProductTypeService
productTypeDraft
- the resource draft to create a resource based off of.CompletionStage
containing an optional with the created resource if
successful otherwise an empty optional.@Nonnull public java.util.concurrent.CompletionStage<io.sphere.sdk.producttypes.ProductType> updateProductType(@Nonnull io.sphere.sdk.producttypes.ProductType productType, @Nonnull java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.producttypes.ProductType>> updateActions)
ProductTypeService
updateActions
.updateProductType
in interface ProductTypeService
productType
- product type that should be updatedupdateActions
- List
of actions that should be applied to productType
CompletionStage
with updated ProductType
.@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.producttypes.ProductType>> fetchProductType(@Nullable java.lang.String key)
ProductTypeService
SphereClient
. If there is no matching productType an
empty Optional
will be returned in the returned future.fetchProductType
in interface ProductTypeService
key
- the key of the product type to fetch.CompletionStage
<Optional
> in which the result of it's completion
contains an Optional
that contains the matching ProductType
if exists,
otherwise empty.