Class ChannelServiceImpl

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.github.benmanes.caffeine.cache.Cache<java.lang.String,​java.lang.String> keyToIdCache  
      protected static int MAXIMUM_ALLOWED_UPDATE_ACTIONS  
    • Constructor Summary

      Constructors 
      Constructor Description
      ChannelServiceImpl​(BaseSyncOptions syncOptions, java.util.Set<com.commercetools.api.models.channel.ChannelRoleEnum> channelRoles)  
    • 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> channelKeys)
      Filters out the keys which are already cached and fetches only the not-cached channel keys from the CTP project defined in an injected ProjectApiRoot and stores a mapping for every channel to id in the cached map of keys -> ids and returns this cached map.
      java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​java.lang.String>> cacheKeysToIdsUsingGraphQl​(java.util.Set<java.lang.String> keysToCache, GraphQlQueryResource queryResource)  
      java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.channel.Channel>> createAndCacheChannel​(java.lang.String key)
      Creates a new channel with the supplied key and puts a new mapping of it's key to id in a cache map.
      java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.channel.Channel>> createChannel​(java.lang.String key)
      Creates a new channel with the supplied key.
      java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedChannelId​(java.lang.String key)
      Given a key, this method first checks if a cached map of channel keys -> ids is not empty.
      protected java.util.Set<java.lang.String> getKeysNotCached​(java.util.Set<java.lang.String> keys)
      Given a set of keys this method collects all keys which aren't already contained in the cache keyToIdCache
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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

      • ChannelServiceImpl

        public ChannelServiceImpl​(@Nonnull
                                  BaseSyncOptions syncOptions,
                                  @Nonnull
                                  java.util.Set<com.commercetools.api.models.channel.ChannelRoleEnum> channelRoles)
    • 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> channelKeys)
        Description copied from interface: ChannelService
        Filters out the keys which are already cached and fetches only the not-cached channel keys from the CTP project defined in an injected ProjectApiRoot and stores a mapping for every channel to id in the cached map of keys -> ids and returns this cached map.
        Specified by:
        cacheKeysToIds in interface ChannelService
        Parameters:
        channelKeys - - a set of channel keys to fetch and cache the ids for
        Returns:
        CompletionStage<Map> in which the result of it's completion contains a map of requested tax channel -> ids
      • fetchCachedChannelId

        @Nonnull
        public java.util.concurrent.CompletionStage<java.util.Optional<java.lang.String>> fetchCachedChannelId​(@Nonnull
                                                                                                               java.lang.String key)
        Description copied from interface: ChannelService
        Given a key, this method first checks if a cached map of channel keys -> ids is not empty. If not, it returns a completed future that contains an optional that contains what this key maps to in the cache. If the cache is empty, the method populates the cache with the mapping of all channels' keys to ids in the CTP project, by querying the CTP project channels.

        After that, the method 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 Channel was found in the CTP project with this key.

        Specified by:
        fetchCachedChannelId in interface ChannelService
        Parameters:
        key - the key by which a Channel id should be fetched from the CTP project.
        Returns:
        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 Channel was found in the CTP project with this external id.
      • createChannel

        @Nonnull
        public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.channel.Channel>> createChannel​(@Nonnull
                                                                                                                                    java.lang.String key)
        Description copied from interface: ChannelService
        Creates a new channel with the supplied key.
        Specified by:
        createChannel in interface ChannelService
        Parameters:
        key - key of supply channel.
        Returns:
        a future containing as a result the created Channel or empty optional.
      • createAndCacheChannel

        @Nonnull
        public java.util.concurrent.CompletionStage<java.util.Optional<com.commercetools.api.models.channel.Channel>> createAndCacheChannel​(@Nonnull
                                                                                                                                            java.lang.String key)
        Description copied from interface: ChannelService
        Creates a new channel with the supplied key and puts a new mapping of it's key to id in a cache map.
        Specified by:
        createAndCacheChannel in interface ChannelService
        Parameters:
        key - key of supply channel.
        Returns:
        a future containing as a result the created Channel or empty optional.
      • getKeysNotCached

        @Nonnull
        protected java.util.Set<java.lang.String> getKeysNotCached​(@Nonnull
                                                                   java.util.Set<java.lang.String> keys)
        Given a set of keys this method collects all keys which aren't already contained in the cache keyToIdCache
        Parameters:
        keys - Set of keys
        Returns:
        a Set of keys which aren't already contained in the cache or empty
      • cacheKeysToIdsUsingGraphQl

        @Nonnull
        public java.util.concurrent.CompletionStage<java.util.Map<java.lang.String,​java.lang.String>> cacheKeysToIdsUsingGraphQl​(@Nonnull
                                                                                                                                       java.util.Set<java.lang.String> keysToCache,
                                                                                                                                       @Nonnull
                                                                                                                                       GraphQlQueryResource queryResource)