Commit a4ae57eb86a329a3afe97c7658968ca2e450022d
Committed by
Andrew Shvayka
1 parent
b3aaf66f
improvements
Showing
2 changed files
with
21 additions
and
12 deletions
@@ -27,11 +27,14 @@ import org.thingsboard.rule.engine.api.TbNodeConfiguration; | @@ -27,11 +27,14 @@ import org.thingsboard.rule.engine.api.TbNodeConfiguration; | ||
27 | import org.thingsboard.rule.engine.api.TbNodeException; | 27 | import org.thingsboard.rule.engine.api.TbNodeException; |
28 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; | 28 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
29 | import org.thingsboard.server.common.data.alarm.Alarm; | 29 | import org.thingsboard.server.common.data.alarm.Alarm; |
30 | +import org.thingsboard.server.common.data.alarm.AlarmId; | ||
31 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
30 | import org.thingsboard.server.common.data.plugin.ComponentType; | 32 | import org.thingsboard.server.common.data.plugin.ComponentType; |
31 | import org.thingsboard.server.common.msg.TbMsg; | 33 | import org.thingsboard.server.common.msg.TbMsg; |
32 | 34 | ||
33 | import javax.annotation.Nullable; | 35 | import javax.annotation.Nullable; |
34 | import java.io.IOException; | 36 | import java.io.IOException; |
37 | +import java.util.UUID; | ||
35 | 38 | ||
36 | import static org.thingsboard.rule.engine.api.TbRelationTypes.FAILURE; | 39 | import static org.thingsboard.rule.engine.api.TbRelationTypes.FAILURE; |
37 | import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; | 40 | import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; |
@@ -41,6 +44,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; | @@ -41,6 +44,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; | ||
41 | type = ComponentType.FILTER, | 44 | type = ComponentType.FILTER, |
42 | name = "checks alarm status", | 45 | name = "checks alarm status", |
43 | configClazz = TbCheckAlarmStatusNodeConfig.class, | 46 | configClazz = TbCheckAlarmStatusNodeConfig.class, |
47 | + relationTypes = {"True", "False"}, | ||
44 | nodeDescription = "Checks alarm status.", | 48 | nodeDescription = "Checks alarm status.", |
45 | nodeDetails = "If the alarm status matches the specified one - msg is success if does not match - msg is failure.", | 49 | nodeDetails = "If the alarm status matches the specified one - msg is success if does not match - msg is failure.", |
46 | uiResources = {"static/rulenode/rulenode-core-config.js"}, | 50 | uiResources = {"static/rulenode/rulenode-core-config.js"}, |
@@ -64,18 +68,22 @@ public class TbCheckAlarmStatusNode implements TbNode { | @@ -64,18 +68,22 @@ public class TbCheckAlarmStatusNode implements TbNode { | ||
64 | Futures.addCallback(latest, new FutureCallback<Alarm>() { | 68 | Futures.addCallback(latest, new FutureCallback<Alarm>() { |
65 | @Override | 69 | @Override |
66 | public void onSuccess(@Nullable Alarm result) { | 70 | public void onSuccess(@Nullable Alarm result) { |
67 | - boolean isPresent = false; | ||
68 | - for (String alarmStatus : config.getAlarmStatusList()) { | ||
69 | - if (alarm.getStatus().name().equals(alarmStatus)) { | ||
70 | - isPresent = true; | ||
71 | - break; | 71 | + if (result != null) { |
72 | + boolean isPresent = false; | ||
73 | + for (AlarmStatus alarmStatus : config.getAlarmStatusList()) { | ||
74 | + if (alarm.getStatus() == alarmStatus) { | ||
75 | + isPresent = true; | ||
76 | + break; | ||
77 | + } | ||
72 | } | 78 | } |
73 | - } | ||
74 | 79 | ||
75 | - if (isPresent) { | ||
76 | - ctx.tellNext(msg, SUCCESS); | 80 | + if (isPresent) { |
81 | + ctx.tellNext(msg, "True"); | ||
82 | + } else { | ||
83 | + ctx.tellNext(msg, "False"); | ||
84 | + } | ||
77 | } else { | 85 | } else { |
78 | - ctx.tellNext(msg, FAILURE); | 86 | + ctx.tellFailure(msg, new TbNodeException("No such Alarm found.")); |
79 | } | 87 | } |
80 | } | 88 | } |
81 | 89 |
@@ -17,18 +17,19 @@ package org.thingsboard.rule.engine.filter; | @@ -17,18 +17,19 @@ package org.thingsboard.rule.engine.filter; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.rule.engine.api.NodeConfiguration; | 19 | import org.thingsboard.rule.engine.api.NodeConfiguration; |
20 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
20 | 21 | ||
21 | -import java.util.Collections; | 22 | +import java.util.Arrays; |
22 | import java.util.List; | 23 | import java.util.List; |
23 | 24 | ||
24 | @Data | 25 | @Data |
25 | public class TbCheckAlarmStatusNodeConfig implements NodeConfiguration<TbCheckAlarmStatusNodeConfig> { | 26 | public class TbCheckAlarmStatusNodeConfig implements NodeConfiguration<TbCheckAlarmStatusNodeConfig> { |
26 | - private List<String> alarmStatusList; | 27 | + private List<AlarmStatus> alarmStatusList; |
27 | 28 | ||
28 | @Override | 29 | @Override |
29 | public TbCheckAlarmStatusNodeConfig defaultConfiguration() { | 30 | public TbCheckAlarmStatusNodeConfig defaultConfiguration() { |
30 | TbCheckAlarmStatusNodeConfig config = new TbCheckAlarmStatusNodeConfig(); | 31 | TbCheckAlarmStatusNodeConfig config = new TbCheckAlarmStatusNodeConfig(); |
31 | - config.setAlarmStatusList(Collections.emptyList()); | 32 | + config.setAlarmStatusList(Arrays.asList(AlarmStatus.ACTIVE_ACK, AlarmStatus.ACTIVE_UNACK)); |
32 | return config; | 33 | return config; |
33 | } | 34 | } |
34 | } | 35 | } |