Command resolvedCommand = commandResolver.resolve(command);
//doing so we bypass messaging system gaining better performances
BehaviorManager.parseCommand(resolvedCommand);
} else {
//if the event has a target object we include also object info
EnvObjectLogic targetObject =
EnvObjectPersistence.getObjectByName(event.getProperty("object.name"));
if (targetObject != null) {
commandResolver.addContext("current.",
targetObject.getExposedProperties());
commandResolver.addContext("current.",
targetObject.getExposedBehaviors());
}
final Command resolvedCommand = commandResolver.resolve(command);
//it's not a user level command for objects (eg: turn it on), it is for another kind of actuator
Command reply = busService.send(resolvedCommand); //blocking wait until executed
if (reply == null) {
LOG.log(Level.WARNING,
"Unreceived reply within given time ({0}ms) for command {1}",
new Object[]{command.getReplyTimeout(), command.getName()});
} else {
if (reply.isExecuted()) {
LOG.log(Level.FINE, "Executed succesfully {0}", command.getName());
} else {
LOG.log(Level.WARNING, "Unable to execute command{0}", command.getName());
}
}
}
}
} catch (Exception e) {
LOG.severe("Exception while merging event parameters into reaction.\n");
LOG.severe(Freedomotic.getStackTraceInfo(e));
return;
}
String info =
"Executing automation '" + reaction.toString() + "' takes "
+ (System.currentTimeMillis() - event.getCreation()) + "ms.";
LOG.info(info);
MessageEvent message = new MessageEvent(null, info);
message.setType("callout"); //display as callout on frontends
busService.send(message);
}
}
if (!found) {
LOG.log(Level.CONFIG, "No valid reaction bound to trigger ''{0}''", trigger.getName());
}
}
/**
* Resolves the additional conditions of the reaction in input. Now
* it just takes the statement attribute and value and check if they
* are equal to the target behavior name and value respectively.
* This should be improved to allow also REGEX and other statement
* resolution.
*/
private boolean checkAdditionalConditions(Reaction rea) {
boolean result = true;
for (Condition condition : rea.getConditions()) {
//System.out.println("DEBUG: check condition " + condition.getTarget());
EnvObjectLogic object = EnvObjectPersistence.getObjectByName(condition.getTarget());
Statement statement = condition.getStatement();
if (object != null) {
BehaviorLogic behavior = object.getBehavior(statement.getAttribute());
//System.out.println("DEBUG: " + object.getPojo().getName() + " "
//+ " behavior: " + behavior.getName() + " " + behavior.getValueAsString());
boolean eval = behavior.getValueAsString().equalsIgnoreCase(statement.getValue());
if (statement.getLogical().equalsIgnoreCase("AND")) {
result = result && eval;