Commit 076f5483587d5ea1a7e0cd1d79f16a70e0fd6c84
Committed by
Andrew Shvayka
1 parent
150b1bb8
refactored AlarmState
Showing
1 changed file
with
4 additions
and
3 deletions
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/profile/AlarmState.java
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | +import org.apache.commons.lang3.StringUtils; | ||
22 | import org.thingsboard.rule.engine.action.TbAlarmResult; | 23 | import org.thingsboard.rule.engine.action.TbAlarmResult; |
23 | import org.thingsboard.rule.engine.api.TbContext; | 24 | import org.thingsboard.rule.engine.api.TbContext; |
24 | import org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState; | 25 | import org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState; |
@@ -239,18 +240,18 @@ class AlarmState { | @@ -239,18 +240,18 @@ class AlarmState { | ||
239 | JsonNode alarmDetails; | 240 | JsonNode alarmDetails; |
240 | String alarmDetailsStr = ruleState.getAlarmRule().getAlarmDetails(); | 241 | String alarmDetailsStr = ruleState.getAlarmRule().getAlarmDetails(); |
241 | 242 | ||
242 | - if (alarmDetailsStr != null) { | 243 | + if (StringUtils.isNotEmpty(alarmDetailsStr)) { |
243 | for (KeyFilter keyFilter : ruleState.getAlarmRule().getCondition().getCondition()) { | 244 | for (KeyFilter keyFilter : ruleState.getAlarmRule().getCondition().getCondition()) { |
244 | EntityKeyValue entityKeyValue = dataSnapshot.getValue(keyFilter.getKey()); | 245 | EntityKeyValue entityKeyValue = dataSnapshot.getValue(keyFilter.getKey()); |
245 | alarmDetailsStr = alarmDetailsStr.replaceAll(String.format("\\$\\{%s}", keyFilter.getKey().getKey()), getValueAsString(entityKeyValue)); | 246 | alarmDetailsStr = alarmDetailsStr.replaceAll(String.format("\\$\\{%s}", keyFilter.getKey().getKey()), getValueAsString(entityKeyValue)); |
246 | } | 247 | } |
247 | - ObjectNode newDetails = JacksonUtil.OBJECT_MAPPER.createObjectNode(); | 248 | + ObjectNode newDetails = JacksonUtil.newObjectNode(); |
248 | newDetails.put("data", alarmDetailsStr); | 249 | newDetails.put("data", alarmDetailsStr); |
249 | alarmDetails = newDetails; | 250 | alarmDetails = newDetails; |
250 | } else if (currentAlarm != null) { | 251 | } else if (currentAlarm != null) { |
251 | alarmDetails = currentAlarm.getDetails(); | 252 | alarmDetails = currentAlarm.getDetails(); |
252 | } else { | 253 | } else { |
253 | - alarmDetails = JacksonUtil.OBJECT_MAPPER.createObjectNode(); | 254 | + alarmDetails = JacksonUtil.newObjectNode(); |
254 | } | 255 | } |
255 | 256 | ||
256 | return alarmDetails; | 257 | return alarmDetails; |