fix/AlarmActionEvents
This commit is contained in:
parent
8bd617e3b5
commit
702a091329
@ -252,26 +252,26 @@ class DefaultTbContext implements TbContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg customerCreatedMsg(Customer customer, RuleNodeId ruleNodeId) {
|
public TbMsg customerCreatedMsg(Customer customer, RuleNodeId ruleNodeId) {
|
||||||
return entityCreatedMsg(customer, customer.getId(), ruleNodeId);
|
return entityActionMsg(customer, customer.getId(), ruleNodeId, DataConstants.ENTITY_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) {
|
public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) {
|
||||||
return entityCreatedMsg(device, device.getId(), ruleNodeId);
|
return entityActionMsg(device, device.getId(), ruleNodeId, DataConstants.ENTITY_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId) {
|
public TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId) {
|
||||||
return entityCreatedMsg(asset, asset.getId(), ruleNodeId);
|
return entityActionMsg(asset, asset.getId(), ruleNodeId, DataConstants.ENTITY_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId) {
|
public TbMsg alarmActionMsg(Alarm alarm, RuleNodeId ruleNodeId, String action) {
|
||||||
return entityCreatedMsg(alarm, alarm.getId(), ruleNodeId);
|
return entityActionMsg(alarm, alarm.getId(), ruleNodeId, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E, I extends EntityId> TbMsg entityCreatedMsg(E entity, I id, RuleNodeId ruleNodeId) {
|
public <E, I extends EntityId> TbMsg entityActionMsg(E entity, I id, RuleNodeId ruleNodeId, String action) {
|
||||||
try {
|
try {
|
||||||
return TbMsg.newMsg(DataConstants.ENTITY_CREATED, id, getActionMetaData(ruleNodeId), mapper.writeValueAsString(mapper.valueToTree(entity)));
|
return TbMsg.newMsg(action, id, getActionMetaData(ruleNodeId), mapper.writeValueAsString(mapper.valueToTree(entity)));
|
||||||
} catch (JsonProcessingException | IllegalArgumentException e) {
|
} catch (JsonProcessingException | IllegalArgumentException e) {
|
||||||
throw new RuntimeException("Failed to process " + id.getEntityType().name().toLowerCase() + " created msg: " + e);
|
throw new RuntimeException("Failed to process " + id.getEntityType().name().toLowerCase() + " " + action + " msg: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -124,6 +124,7 @@ public class AlarmController extends BaseController {
|
|||||||
long ackTs = System.currentTimeMillis();
|
long ackTs = System.currentTimeMillis();
|
||||||
alarmService.ackAlarm(getCurrentUser().getTenantId(), alarmId, ackTs).get();
|
alarmService.ackAlarm(getCurrentUser().getTenantId(), alarmId, ackTs).get();
|
||||||
alarm.setAckTs(ackTs);
|
alarm.setAckTs(ackTs);
|
||||||
|
alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
|
||||||
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
|
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
@ -141,6 +142,7 @@ public class AlarmController extends BaseController {
|
|||||||
long clearTs = System.currentTimeMillis();
|
long clearTs = System.currentTimeMillis();
|
||||||
alarmService.clearAlarm(getCurrentUser().getTenantId(), alarmId, null, clearTs).get();
|
alarmService.clearAlarm(getCurrentUser().getTenantId(), alarmId, null, clearTs).get();
|
||||||
alarm.setClearTs(clearTs);
|
alarm.setClearTs(clearTs);
|
||||||
|
alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
|
||||||
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
|
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
|
|||||||
@ -141,7 +141,7 @@ public interface TbContext {
|
|||||||
TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId);
|
TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId);
|
||||||
|
|
||||||
// TODO: Does this changes the message?
|
// TODO: Does this changes the message?
|
||||||
TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId);
|
TbMsg alarmActionMsg(Alarm alarm, RuleNodeId ruleNodeId, String action);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.thingsboard.rule.engine.api.TbContext;
|
|||||||
import org.thingsboard.rule.engine.api.TbNode;
|
import org.thingsboard.rule.engine.api.TbNode;
|
||||||
import org.thingsboard.rule.engine.api.TbNodeConfiguration;
|
import org.thingsboard.rule.engine.api.TbNodeConfiguration;
|
||||||
import org.thingsboard.rule.engine.api.TbNodeException;
|
import org.thingsboard.rule.engine.api.TbNodeException;
|
||||||
|
import org.thingsboard.server.common.data.DataConstants;
|
||||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||||
import org.thingsboard.server.common.msg.TbMsg;
|
import org.thingsboard.server.common.msg.TbMsg;
|
||||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||||
@ -61,13 +62,11 @@ public abstract class TbAbstractAlarmNode<C extends TbAbstractAlarmNodeConfigura
|
|||||||
if (alarmResult.alarm == null) {
|
if (alarmResult.alarm == null) {
|
||||||
ctx.tellNext(msg, "False");
|
ctx.tellNext(msg, "False");
|
||||||
} else if (alarmResult.isCreated) {
|
} else if (alarmResult.isCreated) {
|
||||||
ctx.enqueue(ctx.alarmCreatedMsg(alarmResult.alarm, ctx.getSelfId()),
|
tellNext(ctx, msg, alarmResult, DataConstants.ENTITY_CREATED, "Created");
|
||||||
() -> ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Created"),
|
|
||||||
throwable -> ctx.tellFailure(toAlarmMsg(ctx, alarmResult, msg), throwable));
|
|
||||||
} else if (alarmResult.isUpdated) {
|
} else if (alarmResult.isUpdated) {
|
||||||
ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Updated");
|
tellNext(ctx, msg, alarmResult, DataConstants.ENTITY_UPDATED, "Updated");
|
||||||
} else if (alarmResult.isCleared) {
|
} else if (alarmResult.isCleared) {
|
||||||
ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Cleared");
|
tellNext(ctx, msg, alarmResult, DataConstants.ALARM_CLEAR, "Cleared");
|
||||||
} else {
|
} else {
|
||||||
ctx.tellSuccess(msg);
|
ctx.tellSuccess(msg);
|
||||||
}
|
}
|
||||||
@ -126,4 +125,10 @@ public abstract class TbAbstractAlarmNode<C extends TbAbstractAlarmNodeConfigura
|
|||||||
this.alarm = alarm;
|
this.alarm = alarm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tellNext(TbContext ctx, TbMsg msg, AlarmResult alarmResult, String alarmAction, String alarmResultMsgType) {
|
||||||
|
ctx.enqueue(ctx.alarmActionMsg(alarmResult.alarm, ctx.getSelfId(), alarmAction),
|
||||||
|
() -> ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), alarmResultMsgType),
|
||||||
|
throwable -> ctx.tellFailure(toAlarmMsg(ctx, alarmResult, msg), throwable));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user