Search in sources :

Example 1 with Connection

use of org.eclipse.smarthome.automation.core.internal.Connection in project smarthome by eclipse.

the class ConnectionValidator method validateConditionConnections.

/**
 * The method validates connections between trigger's outputs and condition's inputs. It checks is there unconnected
 * required inputs and compatibility of data types of connected inputs and outputs. Throws exception if they are
 * incompatible.
 *
 * @param condition is a Condition module whose connections have to be validated
 * @param triggers is a list with triggers of the rule on which the condition belongs
 * @throws IllegalArgumentException when validation fails.
 */
private static void validateConditionConnections(RuntimeCondition condition, List<Trigger> triggers) {
    // get module type of the condition
    ConditionType type = (ConditionType) mtRegistry.get(condition.getTypeUID());
    if (type == null) {
        // if module type not exists in the system - throws exception
        throw new IllegalArgumentException("Condition Type \"" + condition.getTypeUID() + "\" does not exist!");
    }
    // get inputs of the condition according to module type definition
    List<Input> inputs = type.getInputs();
    // gets connected inputs from the condition module and put them into map
    Set<Connection> cons = condition.getConnections();
    Map<String, Connection> connectionsMap = new HashMap<String, Connection>();
    Iterator<Connection> connectionsI = cons.iterator();
    while (connectionsI.hasNext()) {
        Connection connection = connectionsI.next();
        String inputName = connection.getInputName();
        connectionsMap.put(inputName, connection);
    }
    // checks is there unconnected required inputs
    if (inputs != null && !inputs.isEmpty()) {
        for (Input input : inputs) {
            String name = input.getName();
            Connection connection = connectionsMap.get(name);
            if (connection != null) {
                checkConnection(connection, input, triggers);
            } else if (input.isRequired()) {
                throw new IllegalArgumentException("Required input \"" + name + "\" of the condition \"" + condition.getId() + "\" not connected");
            }
        }
    }
}
Also used : Input(org.eclipse.smarthome.automation.type.Input) HashMap(java.util.HashMap) Connection(org.eclipse.smarthome.automation.core.internal.Connection) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Example 2 with Connection

use of org.eclipse.smarthome.automation.core.internal.Connection in project smarthome by eclipse.

the class ConnectionValidator method validateActionConnections.

/**
 * The method validates connections between outputs of triggers and actions and action's inputs. It checks is there
 * unconnected required inputs and compatibility of data types of connected inputs and outputs. Throws exception if
 * they are incompatible.
 *
 * @param action is an Action module whose connections have to be validated
 * @param triggers is a list with triggers of the rule on which the action belongs
 * @param actions is a list with actions of the rule on which the action belongs
 * @throws IllegalArgumentException when validation fails.
 */
private static void validateActionConnections(RuntimeAction action, List<Trigger> triggers, List<Action> actions) {
    // get module type of the condition
    ActionType type = (ActionType) mtRegistry.get(action.getTypeUID());
    if (type == null) {
        // if module type not exists in the system - throws exception
        throw new IllegalArgumentException("Action Type \"" + action.getTypeUID() + "\" does not exist!");
    }
    // get inputs of the condition according to module type definition
    List<Input> inputs = type.getInputs();
    // gets connected inputs from the condition module and put them into map
    Set<Connection> cons = action.getConnections();
    Map<String, Connection> connectionsMap = new HashMap<String, Connection>();
    Iterator<Connection> connectionsI = cons.iterator();
    while (connectionsI.hasNext()) {
        Connection connection = connectionsI.next();
        String inputName = connection.getInputName();
        connectionsMap.put(inputName, connection);
    }
    // checks is there unconnected required inputs
    if (inputs != null && !inputs.isEmpty()) {
        for (Input input : inputs) {
            String name = input.getName();
            Connection connection = connectionsMap.get(name);
            if (connection == null && input.isRequired()) {
                throw new IllegalArgumentException("Required input \"" + name + "\" of the condition \"" + action.getId() + "\" not connected");
            } else if (connection != null) {
                checkConnection(connection, input, triggers, actions);
            }
        }
    }
}
Also used : Input(org.eclipse.smarthome.automation.type.Input) ActionType(org.eclipse.smarthome.automation.type.ActionType) HashMap(java.util.HashMap) Connection(org.eclipse.smarthome.automation.core.internal.Connection)

Aggregations

HashMap (java.util.HashMap)2 Connection (org.eclipse.smarthome.automation.core.internal.Connection)2 Input (org.eclipse.smarthome.automation.type.Input)2 ActionType (org.eclipse.smarthome.automation.type.ActionType)1 ConditionType (org.eclipse.smarthome.automation.type.ConditionType)1