Class AbstractRelativeDisableCondition
java.lang.Object
org.ametys.runtime.model.disableconditions.AbstractRelativeDisableCondition
- All Implemented Interfaces:
DisableCondition
- Direct Known Subclasses:
AbstractStaticRelativeDisableCondition
,DataHolderRelativeDisableCondition
,VoidRelativeDisableCondition
Abstract implementation for disable condition referencing a relative model item
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Definition and value corresponding to a relativeDisableCondition
Nested classes/interfaces inherited from interface org.ametys.runtime.model.disableconditions.DisableCondition
DisableCondition.OPERATOR
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
the condition identifierprotected String
the condition name - path to the relative model itemprotected DisableCondition.OPERATOR
The condition operatorprotected String
The condition valueFields inherited from interface org.ametys.runtime.model.disableconditions.DisableCondition
EXTERNAL_CONDITION_ID_PREFIX
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static Object
_emptyStringToNull
(Object value) Convert empty string to null object, or retrieve the given value_getConditionDefinitionAndValue
(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, Optional<T> object, Map<String, Object> contextualParameters) Retrieve the value corresponding to the identifier of the condition, and its typeprotected void
checkModelItemPathSegment
(Model model, ModelItem definition, ModelItem segmentModelItem, int segmentIndex, int conditionPathSize) Check a segment of the condition pathprotected boolean
containsRelativeValue
(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Check if the valuesMap
contains a value for the relative condition<T> boolean
evaluate
(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, Optional<T> object, Map<String, Object> contextualParameters) Evaluate the currentDisableCondition
against the given valuesprotected boolean
evaluateDisableConditionValue
(Object conditionValue, DisableCondition.OPERATOR conditionOperator, Object value) Evaluate the given condition value against the given valuegetAllModelItemsInPath
(Model model, ModelItem definition) Retrieves all model items of the given relative pathgetId()
Get the idprotected ModelItem
getModelItem
(ModelItemAccessor modelItemAccessor, String dataPath, Map<String, Object> contextualParameters) Retrieves the model itemgetName()
Get the nameGet the operatorprotected Object
getRelativeValueFromMap
(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Retrieves the relative condition value from the valuesMap
protected abstract <T> Object
getStoredRelativeValue
(String conditionDataPath, Optional<String> oldConditionDataPath, T object, Map<String, Object> contextualParameters) Retrieves the condition value from data stored in the given objectgetValue()
Get the valuevoid
Used to do more initialization, checks, ...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.disableconditions.DisableCondition
isExternal
-
Field Details
-
_id
the condition identifier -
_name
the condition name - path to the relative model item -
_operator
The condition operator -
_value
The condition value
-
-
Constructor Details
-
AbstractRelativeDisableCondition
public AbstractRelativeDisableCondition()
-
-
Method Details
-
getId
Description copied from interface:DisableCondition
Get the id- Specified by:
getId
in interfaceDisableCondition
- Returns:
- the condition identifier
-
getName
Description copied from interface:DisableCondition
Get the name- Specified by:
getName
in interfaceDisableCondition
- Returns:
- the condition name
-
getOperator
Description copied from interface:DisableCondition
Get the operator- Specified by:
getOperator
in interfaceDisableCondition
- Returns:
- The comparison operator
-
getValue
Description copied from interface:DisableCondition
Get the value- Specified by:
getValue
in interfaceDisableCondition
- Returns:
- The value to compare to
-
init
Description copied from interface:DisableCondition
Used to do more initialization, checks, ... needing model items of distant objects Called byModel
parsing when the model items of all models have been initialized.- Specified by:
init
in interfaceDisableCondition
- Parameters:
model
- the model containing the definitiondefinition
- the model item defining this disable condition- Throws:
Exception
- if an error occurs or if an additional check fails.
-
getAllModelItemsInPath
protected List<ModelItem> getAllModelItemsInPath(Model model, ModelItem definition) throws UndefinedItemPathException, IllegalArgumentException Retrieves all model items of the given relative path- Parameters:
model
- the model containing the definitiondefinition
- the model item defining this disable condition- Returns:
- all model items of the given relative path
- Throws:
UndefinedItemPathException
- if there is no item defined at the given pathIllegalArgumentException
- if the given path is null or empty
-
checkModelItemPathSegment
protected void checkModelItemPathSegment(Model model, ModelItem definition, ModelItem segmentModelItem, int segmentIndex, int conditionPathSize) throws ConfigurationException Check a segment of the condition path- Parameters:
model
- the model containing the definitiondefinition
- the model item defining this disable conditionsegmentModelItem
- the model item concerned by the segmentsegmentIndex
- the index of the segment in the pathconditionPathSize
- the number of segments in the condition path- Throws:
ConfigurationException
- if the segment can not be used in the condition path
-
evaluate
public <T> boolean evaluate(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, Optional<T> object, Map<String, throws UndefinedItemPathException, BadItemTypeExceptionObject> contextualParameters) Description copied from interface:DisableCondition
Evaluate the currentDisableCondition
against the given values- Specified by:
evaluate
in interfaceDisableCondition
- Type Parameters:
T
- Type of object holding the data to evaluate- Parameters:
definition
- the definition of the evaluated datadataPath
- the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this oneoldDataPath
- the old path of the evaluated data. Needed to get stored value if the data has been movedvalues
- values to check conditions onobject
- the object holding the data to evaluate and the condition valuecontextualParameters
- the contextual parameters- Returns:
true
if the disable condition istrue
,false
otherwise- Throws:
UndefinedItemPathException
BadItemTypeException
-
_getConditionDefinitionAndValue
protected <T> AbstractRelativeDisableCondition.RelativeDefinitionAndValue _getConditionDefinitionAndValue(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, Optional<T> object, Map<String, throws UndefinedItemPathException, BadItemTypeExceptionObject> contextualParameters) Retrieve the value corresponding to the identifier of the condition, and its type- Type Parameters:
T
- Type of object holding the data to evaluate- Parameters:
definition
- the definition containing the conditiondataPath
- the path of the evaluated dataoldDataPath
- the old path of the evaluated data. Needed to get stored value if the data has been movedvalues
- values to check conditions onobject
- the object holding the data to evaluate and the condition valuecontextualParameters
- the contextual parameters- Returns:
- the
AbstractRelativeDisableCondition.RelativeDefinitionAndValue
corresponding to the condition identifier - Throws:
UndefinedItemPathException
- If no item is found with the given conditionIdBadItemTypeException
- If the item referenced by the conditionId is not an element
-
getModelItem
protected ModelItem getModelItem(ModelItemAccessor modelItemAccessor, String dataPath, Map<String, Object> contextualParameters) throws UndefinedItemPathExceptionRetrieves the model item- Parameters:
modelItemAccessor
- the relative accessor to the given data pathdataPath
- the data path of the model item to retrievecontextualParameters
- the contextual parameters- Returns:
- the model item
- Throws:
UndefinedItemPathException
- If no item is found for the given path
-
containsRelativeValue
protected boolean containsRelativeValue(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Check if the valuesMap
contains a value for the relative condition- Parameters:
modelItemAccessor
- the relative accessor to the given condition pathconditionDataPath
- the absolute data path of the conditionvalues
- the valuesMap
contextualParameters
- the contextual parameters- Returns:
true
if there is a value (even empty) for the condition in the valuesMap
,false
otherwise
-
getRelativeValueFromMap
protected Object getRelativeValueFromMap(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Retrieves the relative condition value from the valuesMap
-
getStoredRelativeValue
protected abstract <T> Object getStoredRelativeValue(String conditionDataPath, Optional<String> oldConditionDataPath, T object, Map<String, Object> contextualParameters) Retrieves the condition value from data stored in the given object- Type Parameters:
T
- Type of object holding the data to evaluate- Parameters:
conditionDataPath
- the absolute data path of the conditionoldConditionDataPath
- the absolute old data path of the conditionobject
- the object holding the data to evaluate and the condition valuecontextualParameters
- the contextual parameters- Returns:
- the condition value from data stored in the object
-
evaluateDisableConditionValue
protected boolean evaluateDisableConditionValue(Object conditionValue, DisableCondition.OPERATOR conditionOperator, Object value) Evaluate the given condition value against the given value- Parameters:
conditionValue
- the condition valueconditionOperator
- the condition operatorvalue
- the value to check- Returns:
true
if the condition istrue
,false
otherwise
-
_emptyStringToNull
Convert empty string to null object, or retrieve the given value- Parameters:
value
- the value- Returns:
- null if the given value is an empty string, the value itself otherwise
-