Package com.commercetools.sync.services
Interface TypeService
-
- All Known Implementing Classes:
TypeServiceImpl
public interface TypeService
-
-
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> typeKeys)
Filters out the keys which are already cached and fetches only the not-cached type keys from the CTP project defined in an injectedProjectApiRoot
and 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<com.commercetools.api.models.type.Type>>
createType(com.commercetools.api.models.type.TypeDraft typeDraft)
Given a resource draft of typeTypeDraft
, this method attempts to create a resourceType
based 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<com.commercetools.api.models.type.Type>>
fetchMatchingTypesByKeys(java.util.Set<java.lang.String> keys)
java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.type.Type>>
fetchTypeByKey(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 injectedProjectApiRoot
.java.util.concurrent.CompletionStage<com.commercetools.api.models.type.Type>
updateType(com.commercetools.api.models.type.Type type, java.util.List<com.commercetools.api.models.type.TypeUpdateAction> updateActions)
Given aType
and aList
<TypeUpdateAction
<Type
>>, this method issues an update request with these update actions on thisType
in the CTP project defined in an injectedProjectApiRoot
.
-
-
-
Method Detail
-
cacheKeysToIds
@Nonnull java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,java.lang.String>> cacheKeysToIds(@Nonnull 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 injectedProjectApiRoot
and stores a mapping for every type to id in the cached map of keys -> ids and returns this cached map.- 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 java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedTypeId(@Nonnull java.lang.String key)
Given 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 anOptional
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 aCompletionStage
<Optional
<String
>> in which the result of it's completion could contain anOptional
with the id inside of it or an emptyOptional
if noType
was found in the CTP project with this key.- Parameters:
key
- the key by which aType
id should be fetched from the CTP project.- Returns:
CompletionStage
<Optional
<String
>> in which the result of its completion could contain anOptional
with the id inside of it or an emptyOptional
if noType
was found in the CTP project with this key.
-
fetchMatchingTypesByKeys
@Nonnull java.util.concurrent.CompletionStage<java.util.Set<com.commercetools.api.models.type.Type>> fetchMatchingTypesByKeys(@Nonnull java.util.Set<java.lang.String> keys)
-
fetchTypeByKey
@Nonnull java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.type.Type>> fetchTypeByKey(@Nullable 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 injectedProjectApiRoot
. If there is no matching type an emptyOptional
will be returned in the returned future.- Parameters:
key
- the key of the type to fetch.- Returns:
CompletionStage
<Optional
> in which the result of its completion contains anOptional
that contains the matchingType
if exists, otherwise empty.
-
createType
@Nonnull java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.type.Type>> createType(@Nonnull com.commercetools.api.models.type.TypeDraft typeDraft)
Given a resource draft of typeTypeDraft
, this method attempts to create a resourceType
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 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 its completion contains an instanceOptional
of the resource which was created.- Parameters:
typeDraft
- the resource draft to create a resource based off of.- Returns:
- a
CompletionStage
containing an optional with the created resource if successful otherwise an empty optional.
-
updateType
@Nonnull java.util.concurrent.CompletionStage<com.commercetools.api.models.type.Type> updateType(@Nonnull com.commercetools.api.models.type.Type type, @Nonnull java.util.List<com.commercetools.api.models.type.TypeUpdateAction> updateActions)
Given aType
and aList
<TypeUpdateAction
<Type
>>, this method issues an update request with these update actions on thisType
in the CTP project defined in an injectedProjectApiRoot
. This method returnsCompletionStage
<Type
> in which the result of its completion contains an instance of theType
which was updated in the CTP project.- Parameters:
type
- theType
to update.updateActions
- the update actions to update theType
with.- Returns:
CompletionStage
<Type
> containing as a result of it's completion an instance of theType
which was updated in the CTP project.
-
-