-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8aa3d82
commit 6baec89
Showing
19 changed files
with
1,275 additions
and
1 deletion.
There are no files selected for viewing
484 changes: 484 additions & 0 deletions
484
manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
model/src/main/java/org/openremote/model/rules/json/JsonRulesetDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
public class JsonRulesetDefinition { | ||
protected Rule[] rules; | ||
} |
61 changes: 61 additions & 0 deletions
61
model/src/main/java/org/openremote/model/rules/json/Rule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
import org.openremote.model.rules.json.predicate.AssetPredicate; | ||
|
||
/** | ||
* A declarative rule definition (a.k.a. JSON rules); consists of: | ||
* <p> | ||
* <h2>LHS</li> | ||
* <p> | ||
* {@link #when}* - This can be either a {@link RuleTrigger#timer} for time based rules or an {@link AssetPredicate} | ||
* which will be used to filter {@link org.openremote.model.rules.AssetState}s currently available in the rule engine | ||
* that this rule is loaded into. The {@link AssetPredicate} will evaluate to true when one or more | ||
* {@link org.openremote.model.rules.AssetState}s are returned by applying the filter. The returned | ||
* {@link org.openremote.model.rules.AssetState}s are then used as context for the RHS and also the | ||
* {@link RuleTriggerReset} (if specified). | ||
* <p> | ||
* {@link #and} - Optional condition that can be used to further restrict the LHS but without affecting the | ||
* {@link org.openremote.model.rules.AssetState}s that form the context for the RHS. If this is specified then the | ||
* {@link #when} must evaluate to true and this condition must evaluate to true. | ||
* <h2>RHS</h2> | ||
* <p> | ||
* {@link #then}* - Defines a series of {@link RuleAction}s to perform when the rule triggers. | ||
* <h2>Reset</h2> | ||
* <p> | ||
* {@link #reset}* - Optional logic used to reset the rule, this is applied to each | ||
* {@link org.openremote.model.rules.AssetState} that was returned by the {@link #when}. If no reset is specified then | ||
* it is assumed that the rule is fire once per matched {@link org.openremote.model.rules.AssetState}. | ||
* <b>NOTE: Rule trigger history is not persisted so on system restart this information is lost and a rule will be | ||
* able to fire again.</b> | ||
* <p> | ||
* <b>* = Required</b> | ||
*/ | ||
public class Rule { | ||
|
||
public String name; | ||
public String description; | ||
public int priority = Integer.MAX_VALUE-1; | ||
public RuleTrigger when; | ||
public RuleCondition<AssetPredicate> and; | ||
public RuleAction[] then; | ||
public RuleTriggerReset reset; | ||
} |
36 changes: 36 additions & 0 deletions
36
model/src/main/java/org/openremote/model/rules/json/RuleAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = RuleActionWait.class, name = "wait"), | ||
@JsonSubTypes.Type(value = RuleActionWriteAttribute.class, name = "write-attribute"), | ||
@JsonSubTypes.Type(value = RuleActionNotification.class, name = "notification") | ||
}) | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
property = "action" | ||
) | ||
public interface RuleAction { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
model/src/main/java/org/openremote/model/rules/json/RuleActionNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
import org.openremote.model.notification.AbstractNotificationMessage; | ||
|
||
public class RuleActionNotification extends RuleActionWithTarget { | ||
protected AbstractNotificationMessage notification; | ||
} |
24 changes: 24 additions & 0 deletions
24
model/src/main/java/org/openremote/model/rules/json/RuleActionWait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
public class RuleActionWait implements RuleAction { | ||
protected long millis; | ||
} |
34 changes: 34 additions & 0 deletions
34
model/src/main/java/org/openremote/model/rules/json/RuleActionWithTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
import org.openremote.model.query.AssetQuery; | ||
import org.openremote.model.query.UserQuery; | ||
|
||
public abstract class RuleActionWithTarget implements RuleAction { | ||
|
||
public static class Target { | ||
protected boolean useAssetsFromWhen; | ||
protected AssetQuery assets; | ||
protected UserQuery users; | ||
} | ||
|
||
protected Target target; | ||
} |
27 changes: 27 additions & 0 deletions
27
model/src/main/java/org/openremote/model/rules/json/RuleActionWriteAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
import org.openremote.model.value.Value; | ||
|
||
public class RuleActionWriteAttribute extends RuleActionWithTarget { | ||
protected String attributeName; | ||
protected Value value; | ||
} |
38 changes: 38 additions & 0 deletions
38
model/src/main/java/org/openremote/model/rules/json/RuleCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
public class RuleCondition<T> { | ||
|
||
/** | ||
* If not specified then {@link RuleOperator#AND} is assumed. | ||
*/ | ||
public RuleOperator operator; | ||
|
||
/** | ||
* Defines the predicates to apply using the {@link #operator} | ||
*/ | ||
public T[] predicates; | ||
|
||
/** | ||
* Nested conditions allow for more complex logic with a mix of operators | ||
*/ | ||
public RuleCondition<T>[] conditions; | ||
} |
25 changes: 25 additions & 0 deletions
25
model/src/main/java/org/openremote/model/rules/json/RuleOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2018, OpenRemote Inc. | ||
* | ||
* See the CONTRIBUTORS.txt file in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.openremote.model.rules.json; | ||
|
||
public enum RuleOperator { | ||
AND, | ||
OR | ||
} |
Oops, something went wrong.