Search in sources :

Example 6 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class AlarmEdgeProcessor method processAlarmToEdge.

public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ALARM_ACK:
        case ALARM_CLEAR:
            try {
                Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
                if (alarm != null) {
                    downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm)).build();
                }
            } catch (Exception e) {
                log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
            }
            break;
        case DELETED:
            Alarm alarm = mapper.convertValue(edgeEvent.getBody(), Alarm.class);
            AlarmUpdateMsg alarmUpdateMsg = alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAlarmUpdateMsg(alarmUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : AlarmId(org.thingsboard.server.common.data.id.AlarmId) AlarmUpdateMsg(org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Alarm(org.thingsboard.server.common.data.alarm.Alarm) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method processDeviceToEdge.

public DownlinkMsg processDeviceToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            Device device = deviceService.findDeviceById(edgeEvent.getTenantId(), deviceId);
            if (device != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device, edge);
                DeviceUpdateMsg deviceUpdateMsg = deviceMsgConstructor.constructDeviceUpdatedMsg(msgType, device, customerId, null);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceUpdateMsg(deviceUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            DeviceUpdateMsg deviceUpdateMsg = deviceMsgConstructor.constructDeviceDeleteMsg(deviceId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceUpdateMsg(deviceUpdateMsg).build();
            break;
        case CREDENTIALS_UPDATED:
            DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(edge.getTenantId(), deviceId);
            if (deviceCredentials != null) {
                DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = deviceMsgConstructor.constructDeviceCredentialsUpdatedMsg(deviceCredentials);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceCredentialsUpdateMsg(deviceCredentialsUpdateMsg).build();
            }
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) CustomerId(org.thingsboard.server.common.data.id.CustomerId) DeviceCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 8 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class EntityViewEdgeProcessor method processEntityViewToEdge.

public DownlinkMsg processEntityViewToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            EntityView entityView = entityViewService.findEntityViewById(edgeEvent.getTenantId(), entityViewId);
            if (entityView != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(entityView, edge);
                EntityViewUpdateMsg entityViewUpdateMsg = entityViewMsgConstructor.constructEntityViewUpdatedMsg(msgType, entityView, customerId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addEntityViewUpdateMsg(entityViewUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            EntityViewUpdateMsg entityViewUpdateMsg = entityViewMsgConstructor.constructEntityViewDeleteMsg(entityViewId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addEntityViewUpdateMsg(entityViewUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) EntityView(org.thingsboard.server.common.data.EntityView) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)

Example 9 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class RuleChainEdgeProcessor method processRuleChainToEdge.

public DownlinkMsg processRuleChainToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
            RuleChain ruleChain = ruleChainService.findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
            if (ruleChain != null) {
                RuleChainUpdateMsg ruleChainUpdateMsg = ruleChainMsgConstructor.constructRuleChainUpdatedMsg(edge.getRootRuleChainId(), msgType, ruleChain);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainUpdateMsg(ruleChainUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainUpdateMsg(ruleChainMsgConstructor.constructRuleChainDeleteMsg(ruleChainId)).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) RuleChainUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg)

Example 10 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class UserEdgeProcessor method processUserToEdge.

public DownlinkMsg processUserToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    UserId userId = new UserId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            User user = userService.findUserById(edgeEvent.getTenantId(), userId);
            if (user != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(user, edge);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserUpdatedMsg(msgType, user, customerId)).build();
            }
            break;
        case DELETED:
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserDeleteMsg(userId)).build();
            break;
        case CREDENTIALS_UPDATED:
            UserCredentials userCredentialsByUserId = userService.findUserCredentialsByUserId(edge.getTenantId(), userId);
            if (userCredentialsByUserId != null && userCredentialsByUserId.isEnabled()) {
                UserCredentialsUpdateMsg userCredentialsUpdateMsg = userMsgConstructor.constructUserCredentialsUpdatedMsg(userCredentialsByUserId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserCredentialsUpdateMsg(userCredentialsUpdateMsg).build();
            }
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) User(org.thingsboard.server.common.data.User) UserId(org.thingsboard.server.common.data.id.UserId) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials) UserCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Aggregations

DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)12 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 AssetId (org.thingsboard.server.common.data.id.AssetId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)2 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)2 RuleChain (org.thingsboard.server.common.data.rule.RuleChain)2 AlarmUpdateMsg (org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg)2 EntityViewUpdateMsg (org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Customer (org.thingsboard.server.common.data.Customer)1 Dashboard (org.thingsboard.server.common.data.Dashboard)1 Device (org.thingsboard.server.common.data.Device)1 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)1 EntityView (org.thingsboard.server.common.data.EntityView)1 User (org.thingsboard.server.common.data.User)1 Alarm (org.thingsboard.server.common.data.alarm.Alarm)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 AlarmId (org.thingsboard.server.common.data.id.AlarmId)1 DashboardId (org.thingsboard.server.common.data.id.DashboardId)1