/** * The method calls handlers of child modules and return true only when they all are satisfied. * * @see org.openhab.core.automation.handler.ConditionHandler#isSatisfied(java.util.Map) */ @Override public boolean isSatisfied(Map<String, Object> context) { List<Condition> children = getChildren(); Map<String, Object> compositeContext = getCompositeContext(context); for (Condition child : children) { Map<String, Object> childContext = Collections.unmodifiableMap(getChildContext(child, compositeContext)); ConditionHandler childHandler = moduleHandlerMap.get(child); boolean isSatisfied = childHandler.isSatisfied(childContext); if (!isSatisfied) { return false; } } return true; }
/** * This method checks if all rule's condition are satisfied or not. * * @param rule the checked rule * @return true when all conditions of the rule are satisfied, false otherwise. */ private boolean calculateConditions(WrappedRule rule) { List<WrappedCondition> conditions = rule.getConditions(); if (conditions.size() == 0) { return true; } final String ruleUID = rule.getUID(); RuleStatus ruleStatus = null; for (Iterator<WrappedCondition> it = conditions.iterator(); it.hasNext();) { ruleStatus = getRuleStatus(ruleUID); if (ruleStatus != RuleStatus.RUNNING) { return false; } final WrappedCondition managedCondition = it.next(); final Condition condition = managedCondition.unwrap(); ConditionHandler tHandler = managedCondition.getModuleHandler(); Map<String, Object> context = getContext(ruleUID, managedCondition.getConnections()); if (tHandler != null && !tHandler.isSatisfied(Collections.unmodifiableMap(context))) { logger.debug("The condition '{}' of rule '{}' is unsatisfied.", new Object[] { condition.getId(), ruleUID }); return false; } } return true; }