Interface MediaStorageConfigService

  • All Known Implementing Classes:
    DefaultMediaStorageConfigService, TestMediaStorageConfig

    public interface MediaStorageConfigService

    Manages media storage configuration. Whole media storage configuration is based on properties and special naming convention to keep it consistent. Configuration is divided to three groups of properties: default settings, specific strategy global settings and folder settings.

    Default settings section is strict and follows naming convention:

     media.default.{subKey}
     

    All predefined default settings are listed below:

    • media.default.storage.strategy - Used for default storage strategy for all folders without specific configuration. Value is spring bean id of strategy. Default is localFileMediaStorageStrategy.
    • media.default.url.strategy - Used for default URL strategy for all folders without specific configuration. Value is spring bean id of strategy. Default is localFileMediaStorageStrategy.
    • media.default.local.cache - Specifies whether data from non-local strategies is cached. Value is "true" or "false". Default is "true".
    • media.default.local.cache.rootCacheFolder - Specifies root cache folder for all cached files which will be created in media data directory. Default is "cache".
    • media.default.hashing.depth - Specifies depth of sub-directories when media have to be stored in hierarchical way. Allowed values are 0 up-to 4, 0 means no sub-directories. Default is 2.
    • media.default.storage.location.hash.salt - Specifies unique per installation salt which will be used for computing hashes for media locations. It is highly recommended to set it up individually for each installation.

    Global settings section depends on media storage implementation and can contain any keys which follow naming convention:

     media.globalSetting.{strategyBeanId}.{subKey}
     

    valid global setting key example is:

     media.globalSettings.localFileMediaStorageStrategy.cleanOnInit = true
     

    where mandatory part is media.globalSettings plus spring bean Id of strategy which is localFileMediaStorageStrategy. Variable part of the key in this case is cleanOnInit.

    Folder specific settings must also follow naming convention as follows:

     media.folder.{folderQualifier}.{subKey}
     

    valid folder specific key example is:

     media.folder.foo.storage.strategy = fooBar
     

    where mandatory part is media.folder plus folder qualifier which is foo. Variable part of the key in this case is storage.strategy.

    Please keep in mind that all maps returned by configuration as global settings, custom strategy specific settings keeps keys as subKeys, thus to obtain value user have to call it like this:

     // configService injected by Spring
     final MediaFolderConfig config = configService.getConfigForFolder("foo");
     Optional<Map<String, Object>> settings = config.getCustomSettings();
     if (settings.isPresent())
     {
            final Map<String, Object> mySettings = settings.get();
            // storage.strategy is a subKey
            final String storageStrategy = (String) mySettings.get("storage.strategy");
     }
     

    Media storage configuration stores all values for predefined keys as valid java types. Conversion from String is done by converters which are registered for following predefined subKeys: url.strategy, local.cache, secured, hashing.depth, cleanOnInit. System by default provides three converters:

    • IntegerValueConverter - Spring bean ID: integerConfigValueConverter. Converts string representation of integer into Integer object.
    • BooleanValueConverter - Spring bean ID: booleanConfigValueConverter. Converts string representation of boolean into Boolean object.
    • IterableValueConverter - Spring bean ID: iterableConfigValueConverter. Converts comma separated string of values into Iterable object containing all values as strings.

    By default all custom settings are stored without conversion, however user may want to use converters. It is just matter of registering bean of class ConfigValueMappingRegistrar as follows:

    <bean id="someCustomSubKeyConversionMapping" class="de.hybris.platform.media.storage.impl.ConfigValueMappingRegistrar" p:key="my.fancy.subKey" p:value-ref="integerConfigValueConverter" />

    Assuming that my.fancy.subKey points to Integer value this mapping will register it to use IntegerValueConverter. It is also possible to write own converters by implementing ConfigValueConverter interface and registering it to any subKey as was shown in example above. All registered mappings are scanned and used automatically by MediaStorageConfigService.

    • Method Detail

      • getConfigForFolder

        MediaStorageConfigService.MediaFolderConfig getConfigForFolder​(java.lang.String folderQualifier)
        Gets folder configuration for any media folder (not only directly configured in properties) which contains mandatory data like folder qualifier, media storage strategy ID as well information whether folder is secured, is local caching enabled and what is hashing depth. Additionally any configured URL strategies and any attached to folder custom settings are available.

        Method will return also configuration for folders which are not configured directly in properties. In this case service will try to collect required configuration from default settings as well from storage strategy global settings. Keep in mind that this method does not execute any validation against database whether media folder identified by folderQualifier exists.

        Parameters:
        folderQualifier - the folder qualifier
        Returns:
        configuration for folder
      • getFolderConfigsForStrategy

        java.lang.Iterable<MediaStorageConfigService.MediaFolderConfig> getFolderConfigsForStrategy​(java.lang.String strategyId)
        Gets all folder configurations for strategy identified by strategyId (Spring based). If no folders have been configured directly empty set will be returned.
        Parameters:
        strategyId - the strategy Spring Bean id
        Returns:
        set of MediaFolderConfig objects containing folder configuration or empty set when storage strategy does not have any directly configured folders.
      • getGlobalSettingsForStrategy

        MediaStorageConfigService.GlobalMediaStorageConfig getGlobalSettingsForStrategy​(java.lang.String strategyId)
        Gets the global settings for strategy identified by strategyId.
        Parameters:
        strategyId - the strategy id
        Returns:
        the global settings for strategy
      • getDefaultStrategyId

        java.lang.String getDefaultStrategyId()
        Returns default storage strategy ID. Default storage strategy is mandatory in configuration.
      • isStorageStrategyConfigured

        boolean isStorageStrategyConfigured​(java.lang.String strategyId)
        Checks if particular media storage strategy with strategyId is configured in properties. Storage strategy is considered as configured when it is either set as global strategy or one of media folders has it configured directly.
        Parameters:
        strategyId - the strategy id
        Returns:
        true, if storage strategy is configured
      • getSecuredFolders

        java.util.Collection<java.lang.String> getSecuredFolders()
        Returns a collection of all secured folders (configured with media.folder.FOLDER_NAME.secured property).
        Returns:
        all secured folders defined in properties
      • getDefaultCacheFolderName

        java.lang.String getDefaultCacheFolderName()
        Gets the default folder name under which all cached files will be stored.