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:
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:
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.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
MediaStorageConfigService.AbstractStorageConfig |
static interface |
MediaStorageConfigService.GlobalMediaStorageConfig
Keeps global settings for global media storage strategy.
|
static interface |
MediaStorageConfigService.MediaFolderConfig
Keeps full media storage configuration for media folder.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
java.lang.String |
getDefaultCacheFolderName()
Gets the default folder name under which all cached files will be stored.
|
java.lang.String |
getDefaultStrategyId()
Returns default storage strategy ID.
|
java.lang.Iterable<MediaStorageConfigService.MediaFolderConfig> |
getFolderConfigsForStrategy(java.lang.String strategyId)
Gets all folder configurations for strategy identified by
strategyId (Spring based). |
MediaStorageConfigService.GlobalMediaStorageConfig |
getGlobalSettingsForStrategy(java.lang.String strategyId)
Gets the global settings for strategy identified by
strategyId. |
java.util.Collection<java.lang.String> |
getSecuredFolders()
Returns a collection of all secured folders (configured with media.folder.FOLDER_NAME.secured property).
|
boolean |
isStorageStrategyConfigured(java.lang.String strategyId)
Checks if particular media storage strategy with
strategyId is configured in properties. |
MediaStorageConfigService.MediaFolderConfig getConfigForFolder(java.lang.String folderQualifier)
folderQualifier exists.folderQualifier - the folder qualifierjava.lang.Iterable<MediaStorageConfigService.MediaFolderConfig> getFolderConfigsForStrategy(java.lang.String strategyId)
strategyId (Spring based). If no folders
have been configured directly empty set will be returned.strategyId - the strategy Spring Bean idMediaFolderConfig objects containing folder configuration or empty set when storage
strategy does not have any directly configured folders.MediaStorageConfigService.GlobalMediaStorageConfig getGlobalSettingsForStrategy(java.lang.String strategyId)
strategyId.strategyId - the strategy idjava.lang.String getDefaultStrategyId()
boolean isStorageStrategyConfigured(java.lang.String strategyId)
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.strategyId - the strategy idjava.util.Collection<java.lang.String> getSecuredFolders()
java.lang.String getDefaultCacheFolderName()
Copyright © 2018 SAP SE. All Rights Reserved.