Create Alarm Node add originator and status when using message data (#1503)
This commit is contained in:
parent
a9e55caedc
commit
1706fcbec7
@ -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);
|
||||||
|
|||||||
@ -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 ) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user