Package org.ametys.runtime.model
Class ModelHelper
- java.lang.Object
-
- org.ametys.runtime.model.ModelHelper
-
public final class ModelHelper extends Object
Helper class for models
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
__LOGGER
-
Constructor Summary
Constructors Modifier Constructor Description private
ModelHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static boolean
_checkValueEnumeration(Object value)
private static Object
_emptyStringToNull(Object compareValue)
private static boolean
_evaluateCondition(DisableCondition condition, Map<String,DefinitionAndValue> definitionAndValues, org.slf4j.Logger logger)
private static boolean
_evaluateConditionValue(Object value, DisableCondition.OPERATOR operator, Object compareValue)
private static List<ModelItem>
_getAllModelItemsInPath(String definitionPath, ModelItemContainer itemContainer)
private static boolean
_hasDisableConditions(DisableConditions disableConditions)
private static Pair<Boolean,ElementDefinition>
_isModelItemGroupActive(ModelItemGroup group, Map<String,Object> values)
static boolean
evaluateDisableConditions(DisableConditions disableConditions, Map<String,DefinitionAndValue> definitionAndValues, org.slf4j.Logger logger)
Recursively evaluate theDisableConditions
against the given valuesstatic List<ModelItem>
findModelItemsByType(ModelItemContainer container, String type)
Find all model items of the given typestatic List<ModelItem>
getAllModelItemsInPath(String path, Collection<? extends ModelItemContainer> itemContainers)
Retrieve the list of successive model items represented by the given path.static Map<String,List<ModelItem>>
getAllModelItemsInPaths(Set<String> paths, Collection<? extends ModelItemContainer> itemContainers)
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 ModelItem
getModelItem(String path, Collection<? extends ModelItemContainer> itemContainers)
Retrieves the model item at the given relative pathstatic boolean
hasModelItem(String path, Collection<? extends ModelItemContainer> itemContainers)
Checks if there is a model item at the given relative pathstatic boolean
hasModelItemOfType(ModelItemContainer 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 List<I18nizableText>
validateValue(ElementDefinition definition, Object value)
Validates the given valuestatic List<I18nizableText>
validateValue(ElementDefinition definition, Object value, boolean checkEnumerated)
Validates the given value
-
-
-
Field Detail
-
__LOGGER
private static final org.slf4j.Logger __LOGGER
-
-
Constructor Detail
-
ModelHelper
private ModelHelper()
-
-
Method Detail
-
hasModelItem
public static boolean hasModelItem(String path, Collection<? extends ModelItemContainer> itemContainers)
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 containers. No matter if it is a definition or data path (with repeater entry positions)itemContainers
- model item containers where to search if there is a model item- Returns:
true
if there is model item at this path,false
otherwise
-
getModelItem
public static ModelItem getModelItem(String path, Collection<? extends ModelItemContainer> itemContainers) 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 containers. No matter if it is a definition or data path (with repeater entry positions)itemContainers
- model item containers 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 containers
-
getAllModelItemsInPaths
public static Map<String,List<ModelItem>> getAllModelItemsInPaths(Set<String> paths, Collection<? extends ModelItemContainer> itemContainers) 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 containers. No matter if they are definition or data paths (with repeater entry positions)itemContainers
- model item containers 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 containers
-
getAllModelItemsInPath
public static List<ModelItem> getAllModelItemsInPath(String path, Collection<? extends ModelItemContainer> itemContainers) 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 containers. No matter if it is a definition or data path (with repeater entry positions)itemContainers
- model item containers 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 containers
-
_getAllModelItemsInPath
private static List<ModelItem> _getAllModelItemsInPath(String definitionPath, ModelItemContainer itemContainer)
-
hasModelItemOfType
public static boolean hasModelItemOfType(ModelItemContainer container, String type)
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
public static List<ModelItem> findModelItemsByType(ModelItemContainer container, String type)
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
public static String getDefinitionPathFromDataPath(String dataPath)
Retrieves the given dataPath as a definition path (without the repeaterEntry positions)- Parameters:
dataPath
- the data path- Returns:
- the definition path
-
isGroupSwitchOn
public static boolean isGroupSwitchOn(ModelItem modelItem, Map<String,Object> values)
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
-
_isModelItemGroupActive
private static Pair<Boolean,ElementDefinition> _isModelItemGroupActive(ModelItemGroup group, Map<String,Object> values)
-
evaluateDisableConditions
public static boolean evaluateDisableConditions(DisableConditions disableConditions, Map<String,DefinitionAndValue> definitionAndValues, org.slf4j.Logger logger)
Recursively evaluate theDisableConditions
against the given values- Parameters:
disableConditions
- the disable conditions to evaluatedefinitionAndValues
- the values to evaluatelogger
- the logger for disable conditions evaluation logs- Returns:
- true if the disable conditions are true, false otherwise
-
_hasDisableConditions
private static boolean _hasDisableConditions(DisableConditions disableConditions)
-
_evaluateCondition
private static boolean _evaluateCondition(DisableCondition condition, Map<String,DefinitionAndValue> definitionAndValues, org.slf4j.Logger logger)
-
_evaluateConditionValue
private static boolean _evaluateConditionValue(Object value, DisableCondition.OPERATOR operator, Object compareValue)
-
_emptyStringToNull
private static Object _emptyStringToNull(Object compareValue)
-
validateValue
public static List<I18nizableText> validateValue(ElementDefinition definition, Object value)
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 List<I18nizableText> 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
-
_checkValueEnumeration
private static boolean _checkValueEnumeration(Object value)
-
-