Skip to content
Permalink
Browse files

Added check for validity of Json rule

  • Loading branch information...
Miggets7 committed Jul 8, 2019
1 parent 682c5bf commit ce94d52f7f33afb2b525d86a98d310eac1c46de3
Showing with 33 additions and 0 deletions.
  1. +33 −0 manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java
@@ -177,6 +177,39 @@ void update() {
return;
}

//Check if rule is still valid
if (ruleCondition.datetime != null) {
long currentMillis = timerService.getCurrentTimeMillis();

Pair<Long, Long> fromAndTo = AssetQueryPredicate.asFromAndTo(currentMillis, ruleCondition.datetime);
boolean isValid = false;
switch (ruleCondition.datetime.operator) {
case BETWEEN:
isValid = currentMillis >= fromAndTo.key && currentMillis < fromAndTo.value;
break;
case EQUALS:
isValid = currentMillis == fromAndTo.key;
break;
case LESS_THAN:
isValid = currentMillis < fromAndTo.key;
break;
case LESS_EQUALS:
isValid = currentMillis <= fromAndTo.key;
break;
case GREATER_THAN:
isValid = currentMillis > fromAndTo.key;
break;
case GREATER_EQUALS:
isValid = currentMillis >= fromAndTo.key;
break;
}
if (!isValid) {
log(Level.FINEST, "Rule trigger is no longer valid so no match");
lastTriggerResult = new RuleTriggerResult(false, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
return;
}
}

if (!TextUtil.isNullOrEmpty(ruleCondition.timer)) {
lastTriggerResult = null;

0 comments on commit ce94d52

Please sign in to comment.
You can’t perform that action at this time.