Search in sources :

Example 1 with PersistedAlarmState

use of org.thingsboard.rule.engine.profile.state.PersistedAlarmState in project thingsboard by thingsboard.

the class DeviceState method getOrInitPersistedAlarmState.

private PersistedAlarmState getOrInitPersistedAlarmState(DeviceProfileAlarm alarm) {
    if (pds != null) {
        PersistedAlarmState alarmState = pds.getAlarmStates().get(alarm.getId());
        if (alarmState == null) {
            alarmState = new PersistedAlarmState();
            alarmState.setCreateRuleStates(new HashMap<>());
            pds.getAlarmStates().put(alarm.getId(), alarmState);
        }
        return alarmState;
    } else {
        return null;
    }
}
Also used : PersistedAlarmState(org.thingsboard.rule.engine.profile.state.PersistedAlarmState)

Example 2 with PersistedAlarmState

use of org.thingsboard.rule.engine.profile.state.PersistedAlarmState 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);
    }
}
Also used : AlarmSeverity(org.thingsboard.server.common.data.alarm.AlarmSeverity) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbMsg(org.thingsboard.server.common.msg.TbMsg) BiFunction(java.util.function.BiFunction) JacksonUtil(org.thingsboard.common.util.JacksonUtil) DonAsynchron(org.thingsboard.common.util.DonAsynchron) TbAlarmResult(org.thingsboard.rule.engine.action.TbAlarmResult) AlarmConditionKeyType(org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType) TbContext(org.thingsboard.rule.engine.api.TbContext) StringUtils(org.apache.commons.lang3.StringUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) ArrayList(java.util.ArrayList) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) EntityId(org.thingsboard.server.common.data.id.EntityId) JsonNode(com.fasterxml.jackson.databind.JsonNode) AlarmStatus(org.thingsboard.server.common.data.alarm.AlarmStatus) PersistedAlarmRuleState(org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState) DashboardId(org.thingsboard.server.common.data.id.DashboardId) DataConstants(org.thingsboard.server.common.data.DataConstants) PersistedAlarmState(org.thingsboard.rule.engine.profile.state.PersistedAlarmState) AlarmOperationResult(org.thingsboard.server.dao.alarm.AlarmOperationResult) Alarm(org.thingsboard.server.common.data.alarm.Alarm) ExecutionException(java.util.concurrent.ExecutionException) Slf4j(lombok.extern.slf4j.Slf4j) ServiceQueue(org.thingsboard.server.common.msg.queue.ServiceQueue) List(java.util.List) Data(lombok.Data) AlarmConditionSpecType(org.thingsboard.server.common.data.device.profile.AlarmConditionSpecType) Comparator(java.util.Comparator) PersistedAlarmRuleState(org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState) PersistedAlarmRuleState(org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState)

Aggregations

PersistedAlarmState (org.thingsboard.rule.engine.profile.state.PersistedAlarmState)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 BiFunction (java.util.function.BiFunction)1 Data (lombok.Data)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DonAsynchron (org.thingsboard.common.util.DonAsynchron)1 JacksonUtil (org.thingsboard.common.util.JacksonUtil)1 TbAlarmResult (org.thingsboard.rule.engine.action.TbAlarmResult)1 TbContext (org.thingsboard.rule.engine.api.TbContext)1 PersistedAlarmRuleState (org.thingsboard.rule.engine.profile.state.PersistedAlarmRuleState)1 DataConstants (org.thingsboard.server.common.data.DataConstants)1 Alarm (org.thingsboard.server.common.data.alarm.Alarm)1 AlarmSeverity (org.thingsboard.server.common.data.alarm.AlarmSeverity)1