001/*
002 *  Copyright 2024 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.runtime.model.disableconditions;
017
018import java.util.Map;
019import java.util.Optional;
020
021import org.ametys.runtime.model.ModelItem;
022import org.ametys.runtime.model.exception.BadItemTypeException;
023import org.ametys.runtime.model.exception.UndefinedItemPathException;
024
025/**
026 * Evaluator for {@link DisableConditions}
027 */
028public interface DisableConditionsEvaluator
029{
030    /**
031     * Recursively evaluate the {@link DisableConditions} of the given model item, against the given values.
032     * @param definition the definition of the evaluated data
033     * @param dataPath the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one
034     * @param values values to check conditions on 
035     * @return <code>true</code> if the disable conditions are <code>true</code>, <code>false</code> otherwise
036     * @throws UndefinedItemPathException If no item is found corresponding to one of the conditions
037     * @throws BadItemTypeException If the item referenced by one of the conditions is not an element
038     */
039    public boolean evaluateDisableConditions(ModelItem definition, String dataPath, Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException;
040    
041    /**
042     * Recursively evaluate the {@link DisableConditions} of the given model item, against the values stored in the given object
043     * @param definition the definition of the evaluated data
044     * @param dataPath the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one
045     * @param object the object holding the data to evaluate and the condition value
046     * @param <T> Type of object holding the data to evaluate
047     * @return <code>true</code> if the disable conditions are <code>true</code>, <code>false</code> otherwise
048     * @throws UndefinedItemPathException If no item is found corresponding to one of the conditions
049     * @throws BadItemTypeException If the item referenced by one of the conditions is not an element
050     */
051    public <T> boolean evaluateDisableConditions(ModelItem definition, String dataPath, T object) throws UndefinedItemPathException, BadItemTypeException;
052    
053    /**
054     * Recursively evaluate the {@link DisableConditions} of the given model item, against the given values.
055     * If the value of the condition is not present in the given {@link Map}, search in the stored values in the given object  
056     * @param definition the definition of the evaluated data
057     * @param dataPath the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one
058     * @param oldDataPath the old path of the evaluated data. Needed to get stored value if the data has been moved
059     * @param values values to check conditions on 
060     * @param object the object holding the data to evaluate and the condition value
061     * @param contextualParameters the contextual parameters
062     * @param <T> Type of object holding the data to evaluate
063     * @return <code>true</code> if the disable conditions are <code>true</code>, <code>false</code> otherwise
064     * @throws UndefinedItemPathException If no item is found corresponding to one of the conditions
065     * @throws BadItemTypeException If the item referenced by one of the conditions is not an element
066     */
067    public <T> boolean evaluateDisableConditions(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, T object, Map<String, Object> contextualParameters) throws UndefinedItemPathException, BadItemTypeException;
068}