Search in sources :

Example 16 with UpdateMsgType

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

the class AssetEdgeProcessor method processAssetToEdge.

public DownlinkMsg processAssetToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    AssetId assetId = new AssetId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            Asset asset = assetService.findAssetById(edgeEvent.getTenantId(), assetId);
            if (asset != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(asset, edge);
                AssetUpdateMsg assetUpdateMsg = assetMsgConstructor.constructAssetUpdatedMsg(msgType, asset, customerId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAssetUpdateMsg(assetUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            AssetUpdateMsg assetUpdateMsg = assetMsgConstructor.constructAssetDeleteMsg(assetId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAssetUpdateMsg(assetUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) AssetUpdateMsg(org.thingsboard.server.gen.edge.v1.AssetUpdateMsg) Asset(org.thingsboard.server.common.data.asset.Asset) CustomerId(org.thingsboard.server.common.data.id.CustomerId) AssetId(org.thingsboard.server.common.data.id.AssetId)

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