Package org.ametys.runtime.config
Class ConfigManager
- java.lang.Object
-
- org.ametys.runtime.config.ConfigManager
-
- All Implemented Interfaces:
Model
,ModelItemAccessor
,ModelItemContainer
,Initializable
,Contextualizable
,Serviceable
public final class ConfigManager extends Object implements Model, Contextualizable, Serviceable, Initializable
This manager handle the parameters of the application that have to be stored by the plugins.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeatureConfig(String featureId, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers, Collection<String> parameterReferences)
Registers a new parameter or references a globalConfig parameter.void
addPluginConfig(String pluginName, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers)
Registers new available parameters.void
contextualize(Context context)
void
dispose()
Dispose the manager before restarting itboolean
evaluateDisableConditions(DisableConditions disableConditions, Map<String,Object> values)
Recursively evaluate theDisableConditions
against the configuration valuesCollection<ElementDefinition>
getConfigurationParameters()
Retrieves all configuration parametersString
getFamilyId()
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family IdString
getId()
Retrieves the model id (an id must be unique in the familyModel.getFamilyId()
static ConfigManager
getInstance()
Returns the shared instance of the ConfigManagerModelItem
getModelItem(String itemPath)
Retrieves the model item at given pathCollection<ModelItem>
getModelItems()
Retrieves all the model items of this accessorMap<String,DefinitionAndValue>
getOldDefinitionAndValues()
Retrieves old definition and values if the configuration is not well initializedConfigParameterCheckerDescriptor
getParameterChecker(String id)
Gets the parameter checker with its idView
getView(I18nUtils i18nUtils)
Retrieves the view of Configurationvoid
initialize()
boolean
isComplete()
Returns true if the model is initialized and all parameters are valuedboolean
isEmpty()
Returns true if the config file does not existvoid
parseAndValidate()
Ends the initialization of the config parameters, by checking against the already valued parameters.
If at least one parameter has no value, the application won't start.String
resolveValueForParameterChecker(String parameterName, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
Resolve the given value for the parameter checkMap<String,List<I18nizableText>>
save(Map<String,Object> values, String fileName)
Update the configuration file with the given values
Values are untyped (all are of type String) and might be null.void
service(ServiceManager manager)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.runtime.model.ModelItemAccessor
getChild, hasModelItem
-
-
-
-
Method Detail
-
getInstance
public static ConfigManager getInstance()
Returns the shared instance of the ConfigManager- Returns:
- the shared instance of the ConfigManager
-
contextualize
public void contextualize(Context context)
- Specified by:
contextualize
in interfaceContextualizable
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceInitializable
-
addPluginConfig
public void addPluginConfig(String pluginName, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers)
Registers new available parameters. The addFeatureConfig() method allows to select which ones are actually useful.- Parameters:
pluginName
- the name of the plugin defining the parametersparameters
- the configuration parameters definitionparameterCheckers
- the parameters checkers definition
-
addFeatureConfig
public void addFeatureConfig(String featureId, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers, Collection<String> parameterReferences)
Registers a new parameter or references a globalConfig parameter.- Parameters:
featureId
- the id of the feature defining the parametersparameters
- the configuration parameters definitionparameterCheckers
- the parameters checkers definitionparameterReferences
- references to already defined parameters
-
parseAndValidate
public void parseAndValidate()
Ends the initialization of the config parameters, by checking against the already valued parameters.
If at least one parameter has no value, the application won't start.
-
save
public Map<String,List<I18nizableText>> save(Map<String,Object> values, String fileName) throws Exception
Update the configuration file with the given values
Values are untyped (all are of type String) and might be null.- Parameters:
values
- A map (key, value).fileName
- the configuration file absolute path- Returns:
- errors The fields in error
- Throws:
Exception
- If an error occurred while saving values
-
getOldDefinitionAndValues
public Map<String,DefinitionAndValue> getOldDefinitionAndValues()
Retrieves old definition and values if the configuration is not well initialized- Returns:
- the old definition and values pairs
-
resolveValueForParameterChecker
public String resolveValueForParameterChecker(String parameterName, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
Resolve the given value for the parameter check- Parameters:
parameterName
- name of the parameter to resolvevalue
- the value to resolveoldDefinitionAndValues
- the old definition and values if the configuration is not initialized- Returns:
- the resolved value as a String
-
evaluateDisableConditions
public boolean evaluateDisableConditions(DisableConditions disableConditions, Map<String,Object> values)
Recursively evaluate theDisableConditions
against the configuration values- Parameters:
disableConditions
- the disable conditions to evaluatevalues
- the configuration values- Returns:
- true if the disable conditions are true, false otherwise
-
getModelItem
public ModelItem getModelItem(String itemPath) throws UndefinedItemPathException
Description copied from interface:ModelItemAccessor
Retrieves the model item at given path- Specified by:
getModelItem
in interfaceModelItemAccessor
- Parameters:
itemPath
- the item path- Returns:
- the model item.
- Throws:
UndefinedItemPathException
- if there is no item defined at the given path
-
getConfigurationParameters
public Collection<ElementDefinition> getConfigurationParameters()
Retrieves all configuration parameters- Returns:
- all configuration parameters
-
getModelItems
public Collection<ModelItem> getModelItems()
Description copied from interface:ModelItemAccessor
Retrieves all the model items of this accessor- Specified by:
getModelItems
in interfaceModelItemAccessor
- Returns:
- the model items
-
getView
public View getView(I18nUtils i18nUtils)
Retrieves the view of Configuration- Parameters:
i18nUtils
- the i18nUtils to use categories's sorting- Returns:
- the configuration's view
-
getParameterChecker
public ConfigParameterCheckerDescriptor getParameterChecker(String id)
Gets the parameter checker with its id- Parameters:
id
- the id of the parameter checker to get- Returns:
- the associated parameter checker descriptor
-
isComplete
public boolean isComplete()
Returns true if the model is initialized and all parameters are valued- Returns:
- true if the model is initialized and all parameters are valued
-
isEmpty
public boolean isEmpty()
Returns true if the config file does not exist- Returns:
- true if the config file does not exist
-
dispose
public void dispose()
Dispose the manager before restarting it
-
getId
public String getId()
Description copied from interface:Model
Retrieves the model id (an id must be unique in the familyModel.getFamilyId()
-
getFamilyId
public String getFamilyId()
Description copied from interface:Model
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family Id- Specified by:
getFamilyId
in interfaceModel
- Returns:
- content point (for example "org.ametys.cms.contenttype.ContentTypeExtensionPoint" for a content)
-
-