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);
}
}
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations