Showing
1 changed file
with
15 additions
and
6 deletions
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * | |
3 | + * <p> | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
7 | + * <p> | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * <p> | |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
... | ... | @@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j; |
23 | 23 | import org.apache.velocity.Template; |
24 | 24 | import org.apache.velocity.VelocityContext; |
25 | 25 | import org.apache.velocity.runtime.parser.ParseException; |
26 | +import org.springframework.util.StringUtils; | |
26 | 27 | import org.thingsboard.server.common.data.alarm.Alarm; |
27 | 28 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
28 | 29 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
... | ... | @@ -107,6 +108,11 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration |
107 | 108 | boolean isActiveAlarm; |
108 | 109 | boolean isClearedAlarm; |
109 | 110 | |
111 | + VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg); | |
112 | + for (Object key : context.getKeys()) { | |
113 | + md.put(key.toString(), context.get(key.toString())); | |
114 | + } | |
115 | + | |
110 | 116 | try { |
111 | 117 | isActiveAlarm = newAlarmEvaluator.execute(bindings); |
112 | 118 | isClearedAlarm = clearAlarmEvaluator.execute(bindings); |
... | ... | @@ -132,7 +138,6 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration |
132 | 138 | md.put(IS_EXISTING_ALARM, Boolean.TRUE); |
133 | 139 | } |
134 | 140 | } else if (isClearedAlarm) { |
135 | - VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg); | |
136 | 141 | String alarmType = VelocityUtils.merge(alarmTypeTemplate, context); |
137 | 142 | Optional<Alarm> alarm = ctx.findLatestAlarm(ctx.getDeviceMetaData().getDeviceId(), alarmType); |
138 | 143 | if (alarm.isPresent()) { |
... | ... | @@ -149,7 +154,11 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration |
149 | 154 | md.put("alarmType", existing.getType()); |
150 | 155 | md.put("alarmSeverity", existing.getSeverity()); |
151 | 156 | try { |
152 | - md.put("alarmDetails", mapper.writeValueAsString(existing.getDetails())); | |
157 | + if (!StringUtils.isEmpty(existing.getDetails())) { | |
158 | + md.put("alarmDetails", mapper.writeValueAsString(existing.getDetails())); | |
159 | + } else { | |
160 | + md.put("alarmDetails", "{}"); | |
161 | + } | |
153 | 162 | } catch (JsonProcessingException e) { |
154 | 163 | throw new RuleException("Failed to serialize alarm details", e); |
155 | 164 | } | ... | ... |