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 recordDefinition and value corresponding to a relativeDisableConditionNested classes/interfaces inherited from interface org.ametys.runtime.model.disableconditions.DisableCondition
DisableCondition.OPERATOR -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringthe condition identifierprotected Stringthe condition name - path to the relative model itemprotected DisableCondition.OPERATORThe condition operatorprotected StringThe 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 voidcheckModelItemPathSegment(Model model, ModelItem definition, ModelItem segmentModelItem, int segmentIndex, int conditionPathSize) Check a segment of the condition pathprotected booleancontainsRelativeValue(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Check if the valuesMapcontains a value for the relative condition<T> booleanevaluate(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, Optional<T> object, Map<String, Object> contextualParameters) Evaluate the currentDisableConditionagainst the given valuesprotected booleanevaluateDisableConditionValue(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 ModelItemgetModelItem(ModelItemAccessor modelItemAccessor, String dataPath, Map<String, Object> contextualParameters) Retrieves the model itemgetName()Get the nameGet the operatorprotected ObjectgetRelativeValueFromMap(ModelItemAccessor modelItemAccessor, String conditionDataPath, Map<String, Object> values, Map<String, Object> contextualParameters) Retrieves the relative condition value from the valuesMapprotected abstract <T> ObjectgetStoredRelativeValue(String conditionDataPath, Optional<String> oldConditionDataPath, T object, Map<String, Object> contextualParameters) Retrieves the condition value from data stored in the given objectgetValue()Get the valuevoidUsed to do more initialization, checks, ...Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:DisableConditionGet the id- Specified by:
getIdin interfaceDisableCondition- Returns:
- the condition identifier
-
getName
Description copied from interface:DisableConditionGet the name- Specified by:
getNamein interfaceDisableCondition- Returns:
- the condition name
-
getOperator
Description copied from interface:DisableConditionGet the operator- Specified by:
getOperatorin interfaceDisableCondition- Returns:
- The comparison operator
-
getValue
Description copied from interface:DisableConditionGet the value- Specified by:
getValuein interfaceDisableCondition- Returns:
- The value to compare to
-
init
Description copied from interface:DisableConditionUsed to do more initialization, checks, ... needing model items of distant objects Called byModelparsing when the model items of all models have been initialized.- Specified by:
initin 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:DisableConditionEvaluate the currentDisableConditionagainst the given values- Specified by:
evaluatein 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:
trueif the disable condition istrue,falseotherwise- Throws:
UndefinedItemPathExceptionBadItemTypeException
-
_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.RelativeDefinitionAndValuecorresponding 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 valuesMapcontains a value for the relative condition- Parameters:
modelItemAccessor- the relative accessor to the given condition pathconditionDataPath- the absolute data path of the conditionvalues- the valuesMapcontextualParameters- the contextual parameters- Returns:
trueif there is a value (even empty) for the condition in the valuesMap,falseotherwise
-
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:
trueif the condition istrue,falseotherwise
-
_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
-