Search in sources :

Example 56 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbCreateRelationNodeTest method testDeleteCurrentRelationsCreateNewRelation.

@Test
public void testDeleteCurrentRelationsCreateNewRelation() throws TbNodeException {
    init(createRelationNodeConfigWithRemoveCurrentRelations());
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    AssetId assetId = new AssetId(Uuids.timeBased());
    Asset asset = new Asset();
    asset.setId(assetId);
    when(assetService.findAssetByTenantIdAndName(any(), eq("AssetName"))).thenReturn(asset);
    when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset));
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("name", "AssetName");
    metaData.putValue("type", "AssetType");
    msg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    EntityRelation relation = new EntityRelation();
    when(ctx.getRelationService().findByToAndTypeAsync(any(), eq(msg.getOriginator()), eq(RELATION_TYPE_CONTAINS), eq(RelationTypeGroup.COMMON))).thenReturn(Futures.immediateFuture(Collections.singletonList(relation)));
    when(ctx.getRelationService().deleteRelationAsync(any(), eq(relation))).thenReturn(Futures.immediateFuture(true));
    when(ctx.getRelationService().checkRelation(any(), eq(assetId), eq(deviceId), eq(RELATION_TYPE_CONTAINS), eq(RelationTypeGroup.COMMON))).thenReturn(Futures.immediateFuture(false));
    when(ctx.getRelationService().saveRelationAsync(any(), eq(new EntityRelation(assetId, deviceId, RELATION_TYPE_CONTAINS, RelationTypeGroup.COMMON)))).thenReturn(Futures.immediateFuture(true));
    node.onMsg(ctx, msg);
    verify(ctx).tellNext(msg, TbRelationTypes.SUCCESS);
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Asset(org.thingsboard.server.common.data.asset.Asset) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 57 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.PostTelemetryMsg msg, TransportServiceCallback<Void> callback) {
    int dataPoints = 0;
    for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) {
        dataPoints += tsKv.getKvCount();
    }
    if (checkLimits(sessionInfo, msg, callback, dataPoints)) {
        reportActivityInternal(sessionInfo);
        TenantId tenantId = getTenantId(sessionInfo);
        DeviceId deviceId = new DeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
        CustomerId customerId = getCustomerId(sessionInfo);
        MsgPackCallback packCallback = new MsgPackCallback(msg.getTsKvListCount(), new ApiStatsProxyCallback<>(tenantId, customerId, dataPoints, callback));
        for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) {
            TbMsgMetaData metaData = new TbMsgMetaData();
            metaData.putValue("deviceName", sessionInfo.getDeviceName());
            metaData.putValue("deviceType", sessionInfo.getDeviceType());
            metaData.putValue("ts", tsKv.getTs() + "");
            JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList());
            sendToRuleEngine(tenantId, deviceId, customerId, sessionInfo, json, metaData, SessionMsgType.POST_TELEMETRY_REQUEST, packCallback);
        }
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) JsonObject(com.google.gson.JsonObject) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) UUID(java.util.UUID)

Example 58 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToServerRpcRequestMsg msg, TransportServiceCallback<Void> callback) {
    if (checkLimits(sessionInfo, msg, callback)) {
        reportActivityInternal(sessionInfo);
        UUID sessionId = toSessionId(sessionInfo);
        TenantId tenantId = getTenantId(sessionInfo);
        DeviceId deviceId = getDeviceId(sessionInfo);
        JsonObject json = new JsonObject();
        json.addProperty("method", msg.getMethodName());
        json.add("params", JsonUtils.parse(msg.getParams()));
        TbMsgMetaData metaData = new TbMsgMetaData();
        metaData.putValue("deviceName", sessionInfo.getDeviceName());
        metaData.putValue("deviceType", sessionInfo.getDeviceType());
        metaData.putValue("requestId", Integer.toString(msg.getRequestId()));
        metaData.putValue("serviceId", serviceInfoProvider.getServiceId());
        metaData.putValue("sessionId", sessionId.toString());
        sendToRuleEngine(tenantId, deviceId, getCustomerId(sessionInfo), sessionInfo, json, metaData, SessionMsgType.TO_SERVER_RPC_REQUEST, new TransportTbQueueCallback(callback));
        String requestId = sessionId + "-" + msg.getRequestId();
        toServerRpcPendingMap.put(requestId, new RpcRequestMetadata(sessionId, msg.getRequestId()));
        scheduler.schedule(() -> processTimeout(requestId), clientSideRpcTimeout, TimeUnit.MILLISECONDS);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) JsonObject(com.google.gson.JsonObject) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) ByteString(com.google.protobuf.ByteString) UUID(java.util.UUID)

Example 59 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.PostAttributeMsg msg, TransportServiceCallback<Void> callback) {
    if (checkLimits(sessionInfo, msg, callback, msg.getKvCount())) {
        reportActivityInternal(sessionInfo);
        TenantId tenantId = getTenantId(sessionInfo);
        DeviceId deviceId = new DeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
        JsonObject json = JsonUtils.getJsonObject(msg.getKvList());
        TbMsgMetaData metaData = new TbMsgMetaData();
        metaData.putValue("deviceName", sessionInfo.getDeviceName());
        metaData.putValue("deviceType", sessionInfo.getDeviceType());
        metaData.putValue("notifyDevice", "false");
        CustomerId customerId = getCustomerId(sessionInfo);
        sendToRuleEngine(tenantId, deviceId, customerId, sessionInfo, json, metaData, SessionMsgType.POST_ATTRIBUTES_REQUEST, new TransportTbQueueCallback(new ApiStatsProxyCallback<>(tenantId, customerId, msg.getKvList().size(), callback)));
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) JsonObject(com.google.gson.JsonObject) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) CustomerId(org.thingsboard.server.common.data.id.CustomerId) UUID(java.util.UUID)

Example 60 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbSnsNode method processPublishResult.

private TbMsg processPublishResult(TbContext ctx, TbMsg origMsg, PublishResult result) {
    TbMsgMetaData metaData = origMsg.getMetaData().copy();
    metaData.putValue(MESSAGE_ID, result.getMessageId());
    metaData.putValue(REQUEST_ID, result.getSdkResponseMetadata().getRequestId());
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Aggregations

TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)89 TbMsg (org.thingsboard.server.common.msg.TbMsg)56 Test (org.junit.Test)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 Device (org.thingsboard.server.common.data.Device)17 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 List (java.util.List)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 DeviceId (org.thingsboard.server.common.data.id.DeviceId)15 EntityId (org.thingsboard.server.common.data.id.EntityId)15 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)14 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)14 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)14 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)14 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)14 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)14 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13