@Test public void testCheckAdditionalConditions() { System.out.println("Check additional conditions in reaction"); }
private boolean checkAdditionalConditions(Reaction rea) { boolean result = true; for (Condition condition : rea.getConditions()) { EnvObjectLogic object = thingsRepository.findByName(condition.getTarget()).get(0); Statement statement = condition.getStatement(); if (object != null) { String attributeValue = object.getBehavior(statement.getAttribute()).getValueAsString(); String operand = statement.getOperand(); String value = statement.getValue(); boolean isAndCondition = "AND".equalsIgnoreCase(statement.getLogical()); if(StringUtils.isBlank(value)) value = ""; try { value = this.getCurrentValueFromBehavior(value, object); } catch (FreedomoticException e) { LOG.warn(e.getMessage()); return false; } if ((isDecimalNumber(attributeValue) || isDecimalNumber(value)) && !("EQUALS".equalsIgnoreCase(operand))) { attributeValue = this.increaseStringValue(attributeValue); value = this.increaseStringValue(value); } boolean eval = (boolean) new ExpressionFactory<>().createExpression(attributeValue, operand, value).evaluate(); result = executeBooleanExpression(isAndCondition, result, eval); } } return result; }
TriggerCheck { private boolean checkAdditionalConditions(Reaction rea) { boolean result = true; for (Condition condition : rea.getConditions()) { EnvObjectLogic object = thingsRepository.findByName(condition.getTarget()).get(0); Statement statement = condition.getStatement(); if (object != null) { String attributeValue = object.getBehavior(statement.getAttribute()).getValueAsString(); String operand = statement.getOperand(); String value = statement.getValue(); boolean isAndCondition = "AND".equalsIgnoreCase(statement.getLogical()); if(StringUtils.isBlank(value)) value = ""; try { value = this.getCurrentValueFromBehavior(value, object); } catch (FreedomoticException e) { LOG.warn(e.getMessage()); return false; } if ((isDecimalNumber(attributeValue) || isDecimalNumber(value)) && !("EQUALS".equalsIgnoreCase(operand))) { attributeValue = this.increaseStringValue(attributeValue); value = this.increaseStringValue(value); } boolean eval = (boolean) new ExpressionFactory<>().createExpression(attributeValue, operand, value).evaluate(); result = executeBooleanExpression(isAndCondition, result, eval); } } return result; } }
TriggerCheck { private boolean checkAdditionalConditions(Reaction rea) { boolean result = true; for (Condition condition : rea.getConditions()) { EnvObjectLogic object = thingsRepository.findByName(condition.getTarget()).get(0); Statement statement = condition.getStatement(); if (object != null) { String attributeValue = object.getBehavior(statement.getAttribute()).getValueAsString(); String operand = statement.getOperand(); String value = statement.getValue(); boolean isAndCondition = "AND".equalsIgnoreCase(statement.getLogical()); if(StringUtils.isBlank(value)) value = ""; try { value = this.getCurrentValueFromBehavior(value, object); } catch (FreedomoticException e) { LOG.warn(e.getMessage()); return false; } if ((isDecimalNumber(attributeValue) || isDecimalNumber(value)) && !("EQUALS".equalsIgnoreCase(operand))) { attributeValue = this.increaseStringValue(attributeValue); value = this.increaseStringValue(value); } boolean eval = (boolean) new ExpressionFactory<>().createExpression(attributeValue, operand, value).evaluate(); result = executeBooleanExpression(isAndCondition, result, eval); } } return result; } @Inject  TriggerCheck(
            Autodiscovery autodiscovery,
            ThingRepository thingsRepository,
            BusService busService,
            BehaviorManager behaviorManager,
            ReactionRepository reactionRepository); }
TriggerCheck { private boolean checkAdditionalConditions(Reaction rea) { boolean result = true; for (Condition condition : rea.getConditions()) { EnvObjectLogic object = thingsRepository.findByName(condition.getTarget()).get(0); Statement statement = condition.getStatement(); if (object != null) { String attributeValue = object.getBehavior(statement.getAttribute()).getValueAsString(); String operand = statement.getOperand(); String value = statement.getValue(); boolean isAndCondition = "AND".equalsIgnoreCase(statement.getLogical()); if(StringUtils.isBlank(value)) value = ""; try { value = this.getCurrentValueFromBehavior(value, object); } catch (FreedomoticException e) { LOG.warn(e.getMessage()); return false; } if ((isDecimalNumber(attributeValue) || isDecimalNumber(value)) && !("EQUALS".equalsIgnoreCase(operand))) { attributeValue = this.increaseStringValue(attributeValue); value = this.increaseStringValue(value); } boolean eval = (boolean) new ExpressionFactory<>().createExpression(attributeValue, operand, value).evaluate(); result = executeBooleanExpression(isAndCondition, result, eval); } } return result; } @Inject  TriggerCheck(
            Autodiscovery autodiscovery,
            ThingRepository thingsRepository,
            BusService busService,
            BehaviorManager behaviorManager,
            ReactionRepository reactionRepository); boolean check(final EventTemplate event, final Trigger trigger); }
TriggerCheck { private boolean checkAdditionalConditions(Reaction rea) { boolean result = true; for (Condition condition : rea.getConditions()) { EnvObjectLogic object = thingsRepository.findByName(condition.getTarget()).get(0); Statement statement = condition.getStatement(); if (object != null) { String attributeValue = object.getBehavior(statement.getAttribute()).getValueAsString(); String operand = statement.getOperand(); String value = statement.getValue(); boolean isAndCondition = "AND".equalsIgnoreCase(statement.getLogical()); if(StringUtils.isBlank(value)) value = ""; try { value = this.getCurrentValueFromBehavior(value, object); } catch (FreedomoticException e) { LOG.warn(e.getMessage()); return false; } if ((isDecimalNumber(attributeValue) || isDecimalNumber(value)) && !("EQUALS".equalsIgnoreCase(operand))) { attributeValue = this.increaseStringValue(attributeValue); value = this.increaseStringValue(value); } boolean eval = (boolean) new ExpressionFactory<>().createExpression(attributeValue, operand, value).evaluate(); result = executeBooleanExpression(isAndCondition, result, eval); } } return result; } @Inject  TriggerCheck(
            Autodiscovery autodiscovery,
            ThingRepository thingsRepository,
            BusService busService,
            BehaviorManager behaviorManager,
            ReactionRepository reactionRepository); boolean check(final EventTemplate event, final Trigger trigger);  }