Package org.ametys.runtime.model
Class ModelHelper
java.lang.Object
org.ametys.runtime.model.ModelHelper
Helper class for models
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Stores a configuration and the name of the plugin in which is declared the configuration -
Method Summary
Modifier and TypeMethodDescriptionfindModelItemsByType
(ModelItemAccessor container, String type) Find all model items of the given typegetAllModelItemsInPath
(String path, Collection<? extends ModelItemAccessor> itemAccessors) Retrieve the list of successive model items represented by the given path.getAllModelItemsInPaths
(Set<String> paths, Collection<? extends ModelItemAccessor> itemAccessors) Retrieve the list of successive model items represented by the given paths, indexed by path.static String
getDefinitionPathFromDataPath
(String dataPath) Retrieves the given dataPath as a definition path (without the repeaterEntry positions)static String
getDisableConditionAbsolutePath
(DisableCondition condition, String relativePath) Retrieves the absolute path of the conditionstatic ModelItem
getModelItem
(String path, Collection<? extends ModelItemAccessor> itemAccessors) Retrieves the model item at the given relative pathstatic Collection<? extends ModelItem>
getModelItems
(Collection<? extends ModelItemAccessor> itemAccessors) Retrieves all model items of given accessors.static boolean
hasDisableConditions
(DisableConditions disableConditions) Check if there is a non empty condition in the given conditionsstatic boolean
hasDisableConditions
(ModelItem modelItem) Check if the given model item contains non empty disable conditionsstatic boolean
hasModelItem
(String path, Collection<? extends ModelItemAccessor> itemAccessors) Checks if there is a model item at the given relative pathstatic boolean
hasModelItemOfType
(ModelItemAccessor container, String type) Determines if a container of model items contains a model item of the given typestatic boolean
isGroupSwitchOn
(ModelItem modelItem, Map<String, Object> values) Checks if this item is in a group with a switch onstatic I18nizableText
parseI18nizableText
(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name) Parse an i18n text.static I18nizableText
parseI18nizableText
(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name, String defaultValue) Parse an i18n text.static I18nizableText
parseI18nizableText
(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name, I18nizableText defaultValue) Parse an i18n text.static ValidationResult
validateValue
(ElementDefinition definition, Object value) Validates the given valuestatic ValidationResult
validateValue
(ElementDefinition definition, Object value, boolean checkEnumerated) Validates the given value
-
Method Details
-
hasModelItem
public static boolean hasModelItem(String path, Collection<? extends ModelItemAccessor> itemAccessors) throws IllegalArgumentException Checks if there is a model item at the given relative path- Parameters:
path
- path of the model item. This path is relative to the given accessors. No matter if it is a definition or data path (with repeater entry positions)itemAccessors
- model item accessors where to search if there is a model item- Returns:
true
if there is model item at this path,false
otherwise- Throws:
IllegalArgumentException
- if the given path is null or empty
-
getModelItem
public static ModelItem getModelItem(String path, Collection<? extends ModelItemAccessor> itemAccessors) throws IllegalArgumentException, UndefinedItemPathException Retrieves the model item at the given relative path- Parameters:
path
- path of the model item to retrieve. This path is relative to the given accessors. No matter if it is a definition or data path (with repeater entry positions)itemAccessors
- model item accessors where to search the model item- Returns:
- the model item
- Throws:
IllegalArgumentException
- if the given path is null or emptyUndefinedItemPathException
- if there is no item defined at the given path in given item accessors
-
getModelItems
public static Collection<? extends ModelItem> getModelItems(Collection<? extends ModelItemAccessor> itemAccessors) Retrieves all model items of given accessors.- Parameters:
itemAccessors
- The model items accessors- Returns:
- the model items
- Throws:
IllegalArgumentException
- if some models define a model item with the same name and this model item does not come from a common ancestor
-
getAllModelItemsInPaths
public static Map<String,List<ModelItem>> getAllModelItemsInPaths(Set<String> paths, Collection<? extends ModelItemAccessor> itemAccessors) throws IllegalArgumentException, UndefinedItemPathException Retrieve the list of successive model items represented by the given paths, indexed by path.- Parameters:
paths
- paths of the model items to retrieve. These paths are relative to the given accessors. No matter if they are definition or data paths (with repeater entry positions)itemAccessors
- model item accessors where to search the model items- Returns:
- the list of successive model items, indexed by path
- Throws:
IllegalArgumentException
- if one of the given paths is null or emptyUndefinedItemPathException
- if there is no item defined at one of the given paths in given item accessors
-
getAllModelItemsInPath
public static List<ModelItem> getAllModelItemsInPath(String path, Collection<? extends ModelItemAccessor> itemAccessors) throws IllegalArgumentException, UndefinedItemPathException Retrieve the list of successive model items represented by the given path.- Parameters:
path
- path of the model items to retrieve. This path is relative to the given accessors. No matter if it is a definition or data path (with repeater entry positions)itemAccessors
- model item accessors where to search the model items- Returns:
- the list of successive model items
- Throws:
IllegalArgumentException
- if the given path is null or emptyUndefinedItemPathException
- if there is no item defined at the given path in given item accessors
-
hasModelItemOfType
Determines if a container of model items contains a model item of the given type- Parameters:
container
- the model item containertype
- the type identifier to find.- Returns:
- true if a model item of the given type is found
-
findModelItemsByType
Find all model items of the given type- Parameters:
container
- the model item containertype
- the type identifier to find.- Returns:
- the list of
ModelItem
s of this type
-
getDefinitionPathFromDataPath
Retrieves the given dataPath as a definition path (without the repeaterEntry positions)- Parameters:
dataPath
- the data path- Returns:
- the definition path
-
isGroupSwitchOn
Checks if this item is in a group with a switch on- Parameters:
modelItem
- the item to checkvalues
- all items' values to get switchers' values- Returns:
- false if this item is part of a group with a switch to off, true otherwise
-
getDisableConditionAbsolutePath
public static String getDisableConditionAbsolutePath(DisableCondition condition, String relativePath) throws IllegalArgumentException Retrieves the absolute path of the condition- Parameters:
condition
- the conditionrelativePath
- the relative path for computing condition absolute path (path of the model item defining the condition, or path of an evaluated data)- Returns:
- the absolute path of the condition
- Throws:
IllegalArgumentException
- if the path of the condition can not be computed from the given relative path
-
hasDisableConditions
Check if the given model item contains non empty disable conditions- Parameters:
modelItem
- the model item to check- Returns:
true
if a non empty condition has been found,false
otherwise
-
hasDisableConditions
Check if there is a non empty condition in the given conditions- Parameters:
disableConditions
- the disable conditions to check- Returns:
true
if a non empty condition has been found,false
otherwise
-
validateValue
Validates the given value- Parameters:
definition
- The definition to use to validate the valuevalue
- the value to validate- Returns:
- the structure with errors information if the validation failed.
-
validateValue
public static ValidationResult validateValue(ElementDefinition definition, Object value, boolean checkEnumerated) Validates the given value- Parameters:
definition
- The definition to use to validate the valuevalue
- the value to validatecheckEnumerated
-true
true to make sure that the item with an enumerator has its value in the enumerated values- Returns:
- the structure with errors information if the validation failed. TODO NEWATTRIBUTEAPI RUNTIME-2897: remove this method to always check enumerator when validating a value
-
parseI18nizableText
public static I18nizableText parseI18nizableText(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name) throws ConfigurationException Parse an i18n text.- Parameters:
configurationAndPluginName
- the configuration to use.name
- the child name.- Returns:
- the i18n text.
- Throws:
ConfigurationException
- if the configuration is not valid.
-
parseI18nizableText
public static I18nizableText parseI18nizableText(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name, String defaultValue) throws ConfigurationException Parse an i18n text.- Parameters:
configurationAndPluginName
- the configuration to use.name
- the child name.defaultValue
- the default value if no present- Returns:
- the i18n text.
- Throws:
ConfigurationException
- if the configuration is not valid.
-
parseI18nizableText
public static I18nizableText parseI18nizableText(ModelHelper.ConfigurationAndPluginName configurationAndPluginName, String name, I18nizableText defaultValue) throws ConfigurationException Parse an i18n text.- Parameters:
configurationAndPluginName
- the configuration to use.name
- the child name.defaultValue
- the default value if no present- Returns:
- the i18n text.
- Throws:
ConfigurationException
- if the configuration is not valid.
-