Create Alarm Node add originator and status when using message data (#1503)

This commit is contained in:
Valerii Sosliuk 2019-02-21 17:56:35 +02:00 committed by GitHub
parent a9e55caedc
commit 1706fcbec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -103,6 +103,7 @@ public class AlarmController extends BaseController {
checkParameter(ALARM_ID, strAlarmId); checkParameter(ALARM_ID, strAlarmId);
try { try {
AlarmId alarmId = new AlarmId(toUUID(strAlarmId)); AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
checkAlarmId(alarmId, Operation.WRITE);
return alarmService.deleteAlarm(getTenantId(), alarmId); return alarmService.deleteAlarm(getTenantId(), alarmId);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);

View File

@ -69,8 +69,7 @@ public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConf
msgAlarm = null; msgAlarm = null;
} else { } else {
try { try {
msgAlarm = mapper.readValue(msg.getData(), Alarm.class); msgAlarm = getAlarmFromMessage(ctx, msg);
msgAlarm.setTenantId(ctx.getTenantId());
alarmType = msgAlarm.getType(); alarmType = msgAlarm.getType();
} catch (IOException e) { } catch (IOException e) {
ctx.tellFailure(msg, e); ctx.tellFailure(msg, e);
@ -89,6 +88,19 @@ public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConf
} }
private Alarm getAlarmFromMessage(TbContext ctx, TbMsg msg) throws IOException {
Alarm msgAlarm;
msgAlarm = mapper.readValue(msg.getData(), Alarm.class);
msgAlarm.setTenantId(ctx.getTenantId());
if (msgAlarm.getOriginator() == null) {
msgAlarm.setOriginator(msg.getOriginator());
}
if (msgAlarm.getStatus() == null) {
msgAlarm.setStatus(AlarmStatus.ACTIVE_UNACK);
}
return msgAlarm;
}
private ListenableFuture<AlarmResult> createNewAlarm(TbContext ctx, TbMsg msg, Alarm msgAlarm) { private ListenableFuture<AlarmResult> createNewAlarm(TbContext ctx, TbMsg msg, Alarm msgAlarm) {
ListenableFuture<Alarm> asyncAlarm; ListenableFuture<Alarm> asyncAlarm;
if (msgAlarm != null ) { if (msgAlarm != null ) {