use of org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState in project thingsboard by thingsboard.
the class AlarmState method updateState.
public void updateState(DeviceProfileAlarm alarm, PersistedAlarmState alarmState) {
this.alarmDefinition = alarm;
this.createRulesSortedBySeverityDesc = new ArrayList<>();
alarmDefinition.getCreateRules().forEach((severity, rule) -> {
PersistedAlarmRuleState ruleState = null;
if (alarmState != null) {
ruleState = alarmState.getCreateRuleStates().get(severity);
if (ruleState == null) {
ruleState = new PersistedAlarmRuleState();
alarmState.getCreateRuleStates().put(severity, ruleState);
}
}
createRulesSortedBySeverityDesc.add(new AlarmRuleState(severity, rule, deviceProfile.getCreateAlarmKeys(alarm.getId(), severity), ruleState, dynamicPredicateValueCtx));
});
createRulesSortedBySeverityDesc.sort(Comparator.comparingInt(state -> state.getSeverity().ordinal()));
PersistedAlarmRuleState ruleState = alarmState == null ? null : alarmState.getClearRuleState();
if (alarmDefinition.getClearRule() != null) {
clearState = new AlarmRuleState(null, alarmDefinition.getClearRule(), deviceProfile.getClearAlarmKeys(alarm.getId()), ruleState, dynamicPredicateValueCtx);
}
}
Aggregations