Class AbstractRelativeDisableCondition

java.lang.Object
org.ametys.runtime.model.disableconditions.AbstractRelativeDisableCondition
All Implemented Interfaces:
DisableCondition
Direct Known Subclasses:
AbstractStaticRelativeDisableCondition, DataHolderRelativeDisableCondition, VoidRelativeDisableCondition

public abstract class AbstractRelativeDisableCondition extends Object implements DisableCondition
Abstract implementation for disable condition referencing a relative model item
  • Field Details

  • Constructor Details

  • Method Details

    • getId

      public String getId()
      Description copied from interface: DisableCondition
      Get the id
      Specified by:
      getId in interface DisableCondition
      Returns:
      the condition identifier
    • getName

      public String getName()
      Description copied from interface: DisableCondition
      Get the name
      Specified by:
      getName in interface DisableCondition
      Returns:
      the condition name
    • getOperator

      Description copied from interface: DisableCondition
      Get the operator
      Specified by:
      getOperator in interface DisableCondition
      Returns:
      The comparison operator
    • getValue

      public String getValue()
      Description copied from interface: DisableCondition
      Get the value
      Specified by:
      getValue in interface DisableCondition
      Returns:
      The value to compare to
    • hideIfDisabled

      public boolean hideIfDisabled()
      Description copied from interface: DisableCondition
      Determine if the item must be hidden if the current condition is verified
      Specified by:
      hideIfDisabled in interface DisableCondition
      Returns:
      true if the disabled item must be hidden, false otherwise
    • init

      public void init(Model model, ModelItem definition) throws Exception
      Description copied from interface: DisableCondition
      Used to do more initialization, checks, ... needing model items of distant objects Called by Model parsing when the model items of all models have been initialized.
      Specified by:
      init in interface DisableCondition
      Parameters:
      model - the model containing the definition
      definition - the model item defining this disable condition
      Throws:
      Exception - if an error occurs or if an additional check fails.
    • getAllModelItemsInPath

      Retrieves all model items of the given relative path
      Parameters:
      model - the model containing the definition
      definition - 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 path
      IllegalArgumentException - 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 definition
      definition - the model item defining this disable condition
      segmentModelItem - the model item concerned by the segment
      segmentIndex - the index of the segment in the path
      conditionPathSize - 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,Object> contextualParameters) throws UndefinedItemPathException, BadItemTypeException
      Description copied from interface: DisableCondition
      Evaluate the current DisableCondition against the given values
      Specified by:
      evaluate in interface DisableCondition
      Type Parameters:
      T - Type of object holding the data to evaluate
      Parameters:
      definition - the definition of the evaluated data
      dataPath - the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one
      oldDataPath - the old path of the evaluated data. Needed to get stored value if the data has been moved
      values - values to check conditions on
      object - the object holding the data to evaluate and the condition value
      contextualParameters - the contextual parameters
      Returns:
      true if the disable condition is true, false otherwise
      Throws:
      UndefinedItemPathException
      BadItemTypeException
    • _getConditionDefinitionAndValue

      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 condition
      dataPath - the path of the evaluated data
      oldDataPath - the old path of the evaluated data. Needed to get stored value if the data has been moved
      values - values to check conditions on
      object - the object holding the data to evaluate and the condition value
      contextualParameters - the contextual parameters
      Returns:
      the AbstractRelativeDisableCondition.RelativeDefinitionAndValue corresponding to the condition identifier
      Throws:
      UndefinedItemPathException - If no item is found with the given conditionId
      BadItemTypeException - If the item referenced by the conditionId is not an element
    • getModelItemAccessors

      protected <T> Collection<? extends ModelItemAccessor> getModelItemAccessors(ModelItem definition, Optional<T> object)
      Retrieves the model item accessors relative to the disable condition
      Type Parameters:
      T - Type of object holding the data to evaluate
      Parameters:
      definition - the definition containing the condition
      object - the object holding the data to evaluate and the condition value
      Returns:
      the model item accessors relative to the disable condition
    • getModelItem

      protected ModelItem getModelItem(Collection<? extends ModelItemAccessor> modelItemAccessors, String dataPath, Map<String,Object> contextualParameters) throws UndefinedItemPathException
      Retrieves the model item
      Parameters:
      modelItemAccessors - the relative accessors to the given data path
      dataPath - the data path of the model item to retrieve
      contextualParameters - the contextual parameters
      Returns:
      the model item
      Throws:
      UndefinedItemPathException - If no item is found for the given path
    • containsRelativeValue

      protected boolean containsRelativeValue(Collection<? extends ModelItemAccessor> modelItemAccessors, String conditionDataPath, Map<String,Object> values, Map<String,Object> contextualParameters)
      Check if the values Map contains a value for the relative condition
      Parameters:
      modelItemAccessors - the relative accessors to the given condition path
      conditionDataPath - the absolute data path of the condition
      values - the values Map
      contextualParameters - the contextual parameters
      Returns:
      true if there is a value (even empty) for the condition in the values Map, false otherwise
    • getRelativeValueFromMap

      protected Object getRelativeValueFromMap(Collection<? extends ModelItemAccessor> modelItemAccessors, String conditionDataPath, Map<String,Object> values, Map<String,Object> contextualParameters)
      Retrieves the relative condition value from the values Map
      Parameters:
      modelItemAccessors - the relative accessors to the given condition path
      conditionDataPath - the absolute data path of the condition
      values - the values Map
      contextualParameters - the contextual parameters
      Returns:
      the condition value found in the values Map
    • 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 condition
      oldConditionDataPath - the absolute old data path of the condition
      object - the object holding the data to evaluate and the condition value
      contextualParameters - 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 value
      conditionOperator - the condition operator
      value - the value to check
      Returns:
      true if the condition is true, false otherwise
    • _emptyStringToNull

      protected static Object _emptyStringToNull(Object value)
      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