Search in sources :

Example 6 with ActionType

use of org.eclipse.smarthome.automation.type.ActionType 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)

Example 7 with ActionType

use of org.eclipse.smarthome.automation.type.ActionType in project smarthome by eclipse.

the class ConnectionValidator method checkConnection.

/**
 * The method validates the connection between outputs of list of triggers and actions to the action's input. It
 * checks if the input is unconnected and compatibility of data types of the input and connected output. Throws
 * exception if they are incompatible.
 *
 * @param connection that should be validated
 * @param input that should 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 checkConnection(Connection connection, Input input, List<Trigger> triggers, List<Action> actions) {
    Map<String, Action> actionsMap = new HashMap<String, Action>();
    for (Action a : actions) {
        actionsMap.put(a.getId(), a);
    }
    String moduleId = connection.getOuputModuleId();
    Action action = actionsMap.get(moduleId);
    String msg = " Invalid Connection \"" + connection.getInputName() + "\" : ";
    if (moduleId != null && action != null) {
        String typeUID = action.getTypeUID();
        ActionType actionType = (ActionType) mtRegistry.get(typeUID);
        if (actionType == null) {
            throw new IllegalArgumentException(msg + " Action Type with UID \"" + typeUID + "\" does not exist!");
        }
        checkCompatibility(msg, connection, input, actionType.getOutputs());
    } else {
        checkConnection(connection, input, triggers);
    }
}
Also used : RuntimeAction(org.eclipse.smarthome.automation.core.internal.RuntimeAction) Action(org.eclipse.smarthome.automation.Action) ActionType(org.eclipse.smarthome.automation.type.ActionType) HashMap(java.util.HashMap)

Example 8 with ActionType

use of org.eclipse.smarthome.automation.type.ActionType in project smarthome by eclipse.

the class ModuleTypeResourceBundleProvider method createLocalizedActionType.

/**
 * Utility method for localization of ActionTypes.
 *
 * @param at is an ActionType for localization.
 * @param bundle the bundle providing localization resources.
 * @param moduleTypeUID is an ActionType uid.
 * @param locale represents a specific geographical, political, or cultural region.
 * @param lconfigDescriptions are ActionType localized config descriptions.
 * @param llabel is an ActionType localized label.
 * @param ldescription is an ActionType localized description.
 * @return localized ActionType.
 */
private ActionType createLocalizedActionType(ActionType at, Bundle bundle, String moduleTypeUID, Locale locale, List<ConfigDescriptionParameter> lconfigDescriptions, String llabel, String ldescription) {
    List<Input> inputs = ModuleTypeI18nUtil.getLocalizedInputs(i18nProvider, at.getInputs(), bundle, moduleTypeUID, locale);
    List<Output> outputs = ModuleTypeI18nUtil.getLocalizedOutputs(i18nProvider, at.getOutputs(), bundle, moduleTypeUID, locale);
    ActionType lat = null;
    if (at instanceof CompositeActionType) {
        List<Action> modules = ModuleI18nUtil.getLocalizedModules(i18nProvider, ((CompositeActionType) at).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
        lat = new CompositeActionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, at.getTags(), at.getVisibility(), inputs, outputs, modules);
    } else {
        lat = new ActionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, at.getTags(), at.getVisibility(), inputs, outputs);
    }
    return lat;
}
Also used : Input(org.eclipse.smarthome.automation.type.Input) Action(org.eclipse.smarthome.automation.Action) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ActionType(org.eclipse.smarthome.automation.type.ActionType) Output(org.eclipse.smarthome.automation.type.Output) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType)

Example 9 with ActionType

use of org.eclipse.smarthome.automation.type.ActionType in project smarthome by eclipse.

the class ModuleTypeResourceBundleProvider method getPerLocale.

/**
 * This method is used to localize the {@link ModuleType}s.
 *
 * @param element is the {@link ModuleType} that must be localized.
 * @param locale represents a specific geographical, political, or cultural region.
 * @return the localized {@link ModuleType}.
 */
private ModuleType getPerLocale(ModuleType defModuleType, Locale locale) {
    if (locale == null || defModuleType == null || i18nProvider == null) {
        return defModuleType;
    }
    String uid = defModuleType.getUID();
    Bundle bundle = getBundle(uid);
    String llabel = ModuleTypeI18nUtil.getLocalizedModuleTypeLabel(i18nProvider, bundle, uid, defModuleType.getLabel(), locale);
    String ldescription = ModuleTypeI18nUtil.getLocalizedModuleTypeDescription(i18nProvider, bundle, uid, defModuleType.getDescription(), locale);
    List<ConfigDescriptionParameter> lconfigDescriptions = getLocalizedConfigurationDescription(i18nProvider, defModuleType.getConfigurationDescriptions(), bundle, uid, ModuleTypeI18nUtil.MODULE_TYPE, locale);
    if (defModuleType instanceof ActionType) {
        return createLocalizedActionType((ActionType) defModuleType, bundle, uid, locale, lconfigDescriptions, llabel, ldescription);
    }
    if (defModuleType instanceof ConditionType) {
        return createLocalizedConditionType((ConditionType) defModuleType, bundle, uid, locale, lconfigDescriptions, llabel, ldescription);
    }
    if (defModuleType instanceof TriggerType) {
        return createLocalizedTriggerType((TriggerType) defModuleType, bundle, uid, locale, lconfigDescriptions, llabel, ldescription);
    }
    return null;
}
Also used : CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) TriggerType(org.eclipse.smarthome.automation.type.TriggerType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ActionType(org.eclipse.smarthome.automation.type.ActionType) Bundle(org.osgi.framework.Bundle) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Example 10 with ActionType

use of org.eclipse.smarthome.automation.type.ActionType in project smarthome by eclipse.

the class ModuleTypeGSONParser method createMapByType.

private Map<String, List<? extends ModuleType>> createMapByType(Set<ModuleType> dataObjects) {
    Map<String, List<? extends ModuleType>> map = new HashMap<String, List<? extends ModuleType>>();
    List<TriggerType> triggers = new ArrayList<TriggerType>();
    List<ConditionType> conditions = new ArrayList<ConditionType>();
    List<ActionType> actions = new ArrayList<ActionType>();
    for (ModuleType moduleType : dataObjects) {
        if (moduleType instanceof TriggerType) {
            triggers.add((TriggerType) moduleType);
        } else if (moduleType instanceof ConditionType) {
            conditions.add((ConditionType) moduleType);
        } else if (moduleType instanceof ActionType) {
            actions.add((ActionType) moduleType);
        }
    }
    map.put("triggers", triggers);
    map.put("conditions", conditions);
    map.put("actions", actions);
    return map;
}
Also used : CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) TriggerType(org.eclipse.smarthome.automation.type.TriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ActionType(org.eclipse.smarthome.automation.type.ActionType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Aggregations

ActionType (org.eclipse.smarthome.automation.type.ActionType)10 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)4 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)4 ConditionType (org.eclipse.smarthome.automation.type.ConditionType)4 Input (org.eclipse.smarthome.automation.type.Input)4 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)4 TriggerType (org.eclipse.smarthome.automation.type.TriggerType)4 Action (org.eclipse.smarthome.automation.Action)3 Output (org.eclipse.smarthome.automation.type.Output)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 Condition (org.eclipse.smarthome.automation.Condition)1 Trigger (org.eclipse.smarthome.automation.Trigger)1 Connection (org.eclipse.smarthome.automation.core.internal.Connection)1 RuntimeAction (org.eclipse.smarthome.automation.core.internal.RuntimeAction)1