Class TypeServiceImpl
- java.lang.Object
-
- com.commercetools.sync.services.impl.TypeServiceImpl
-
- All Implemented Interfaces:
TypeService
public final class TypeServiceImpl extends java.lang.Object implements TypeService
-
-
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 TypeServiceImpl(BaseSyncOptions 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> typeKeys)Filters out the keys which are already cached and fetches only the not-cached type keys from the CTP project defined in an injectedSphereClientand stores a mapping for every type to id in the cached map of keys -> ids and returns this cached map.java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.types.Type>>createType(io.sphere.sdk.types.TypeDraft typeDraft)Given a resource draft of typeTypeDraft, this method attempts to create a resourceTypebased on it in the CTP project defined by the sync options.java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>>fetchCachedTypeId(java.lang.String key)Given akey, this method first checks if a cached map of Type keys -> ids contains the key.java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.types.Type>>fetchMatchingTypesByKeys(java.util.Set<java.lang.String> keys)Given aSetof Type keys, this method fetches a set of all the Types, matching this given set of keys in the CTP project, defined in an injectedSphereClient.java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.types.Type>>fetchType(java.lang.String key)Given a type key, this method fetches a type that matches this given key in the CTP project defined in an injectedSphereClient.java.util.concurrent.CompletionStage<io.sphere.sdk.types.Type>updateType(io.sphere.sdk.types.Type type, java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.types.Type>> updateActions)Given aTypeand aList<UpdateAction<Type>>, this method issues an update request with these update actions on thisTypein the CTP project defined in an 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
-
TypeServiceImpl
public TypeServiceImpl(@Nonnull BaseSyncOptions 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> typeKeys)Description copied from interface:TypeServiceFilters out the keys which are already cached and fetches only the not-cached type keys from the CTP project defined in an injectedSphereClientand stores a mapping for every type to id in the cached map of keys -> ids and returns this cached map.- Specified by:
cacheKeysToIdsin interfaceTypeService- Parameters:
typeKeys- - a set type keys to fetch and cache the ids for- Returns:
CompletionStage<Map> in which the result of it's completion contains a map of requested type keys -> ids
-
fetchCachedTypeId
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedTypeId(@Nonnull java.lang.String key)Description copied from interface:TypeServiceGiven akey, this method first checks if a cached map of Type keys -> ids contains the key. If not, it returns a completed future that contains anOptionalthat 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 aCompletionStage<Optional<String>> in which the result of it's completion could contain anOptionalwith the id inside of it or an emptyOptionalif noTypewas found in the CTP project with this key.- Specified by:
fetchCachedTypeIdin interfaceTypeService- Parameters:
key- the key by which aTypeid should be fetched from the CTP project.- Returns:
CompletionStage<Optional<String>> in which the result of its completion could contain anOptionalwith the id inside of it or an emptyOptionalif noTypewas found in the CTP project with this key.
-
fetchMatchingTypesByKeys
@Nonnull public java.util.concurrent.CompletionStage<java.util.Set<io.sphere.sdk.types.Type>> fetchMatchingTypesByKeys(@Nonnull java.util.Set<java.lang.String> keys)Description copied from interface:TypeServiceGiven aSetof Type keys, this method fetches a set of all the Types, 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 Type is persisted in an in-memory map.- Specified by:
fetchMatchingTypesByKeysin interfaceTypeService- Parameters:
keys- set of Type keys to fetch matching Type by.- Returns:
CompletionStage<Map> in which the result of its completion contains aSetof all matching Types.
-
fetchType
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.types.Type>> fetchType(@Nullable java.lang.String key)Description copied from interface:TypeServiceGiven a type key, this method fetches a type that matches this given key in the CTP project defined in an injectedSphereClient. If there is no matching type an emptyOptionalwill be returned in the returned future.- Specified by:
fetchTypein interfaceTypeService- Parameters:
key- the key of the type to fetch.- Returns:
CompletionStage<Optional> in which the result of its completion contains anOptionalthat contains the matchingTypeif exists, otherwise empty.
-
createType
@Nonnull public java.util.concurrent.CompletionStage<java.util.Optional<io.sphere.sdk.types.Type>> createType(@Nonnull io.sphere.sdk.types.TypeDraft typeDraft)Description copied from interface:TypeServiceGiven a resource draft of typeTypeDraft, this method attempts to create a resourceTypebased 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 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 its completion contains an instanceOptionalof the resource which was created.- Specified by:
createTypein interfaceTypeService- Parameters:
typeDraft- 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.
-
updateType
@Nonnull public java.util.concurrent.CompletionStage<io.sphere.sdk.types.Type> updateType(@Nonnull io.sphere.sdk.types.Type type, @Nonnull java.util.List<io.sphere.sdk.commands.UpdateAction<io.sphere.sdk.types.Type>> updateActions)Description copied from interface:TypeServiceGiven aTypeand aList<UpdateAction<Type>>, this method issues an update request with these update actions on thisTypein the CTP project defined in an injectedSphereClient. This method returnsCompletionStage<Type> in which the result of its completion contains an instance of theTypewhich was updated in the CTP project.- Specified by:
updateTypein interfaceTypeService- Parameters:
type- theTypeto update.updateActions- the update actions to update theTypewith.- Returns:
CompletionStage<Type> containing as a result of it's completion an instance of theTypewhich was updated in the CTP project or aSphereException.
-
-