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 * @param <T> Type of object holding the data to evaluate 028 */ 029public interface DisableConditionsEvaluator<T extends Object> 030{ 031 /** 032 * Recursively evaluate the {@link DisableConditions} of the given model item, against the given values. 033 * @param definition the definition of the evaluated data 034 * @param dataPath the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one 035 * @param values values to check conditions on 036 * @return <code>true</code> if the disable conditions are <code>true</code>, <code>false</code> otherwise 037 * @throws UndefinedItemPathException If no item is found corresponding to one of the conditions 038 * @throws BadItemTypeException If the item referenced by one of the conditions is not an element 039 */ 040 public boolean evaluateDisableConditions(ModelItem definition, String dataPath, Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException; 041 042 /** 043 * Recursively evaluate the {@link DisableConditions} of the given model item, against the values stored in the given object 044 * @param definition the definition of the evaluated data 045 * @param dataPath the path of the evaluated data. Needed to get the value to compare as condition ids are relative to this one 046 * @param object the object holding the data to evaluate and the condition value 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 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 * @return <code>true</code> if the disable conditions are <code>true</code>, <code>false</code> otherwise 063 * @throws UndefinedItemPathException If no item is found corresponding to one of the conditions 064 * @throws BadItemTypeException If the item referenced by one of the conditions is not an element 065 */ 066 public boolean evaluateDisableConditions(ModelItem definition, String dataPath, Optional<String> oldDataPath, Map<String, Object> values, T object, Map<String, Object> contextualParameters) throws UndefinedItemPathException, BadItemTypeException; 067}