Search in sources :

Example 1 with DeviceUpdateMsg

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

the class BaseEdgeTest method verifyEdgeConnectionAndInitialData.

private void verifyEdgeConnectionAndInitialData() throws Exception {
    Assert.assertTrue(edgeImitator.waitForMessages());
    EdgeConfiguration configuration = edgeImitator.getConfiguration();
    Assert.assertNotNull(configuration);
    testAutoGeneratedCodeByProtobuf(configuration);
    Optional<DeviceUpdateMsg> deviceUpdateMsgOpt = edgeImitator.findMessageByType(DeviceUpdateMsg.class);
    Assert.assertTrue(deviceUpdateMsgOpt.isPresent());
    DeviceUpdateMsg deviceUpdateMsg = deviceUpdateMsgOpt.get();
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType());
    UUID deviceUUID = new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB());
    Device device = doGet("/api/device/" + deviceUUID.toString(), Device.class);
    Assert.assertNotNull(device);
    List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getUuidId() + "/devices?", new TypeReference<PageData<Device>>() {
    }, new PageLink(100)).getData();
    Assert.assertTrue(edgeDevices.contains(device));
    List<DeviceProfileUpdateMsg> deviceProfileUpdateMsgList = edgeImitator.findAllMessagesByType(DeviceProfileUpdateMsg.class);
    Assert.assertEquals(3, deviceProfileUpdateMsgList.size());
    Optional<DeviceProfileUpdateMsg> deviceProfileUpdateMsgOpt = deviceProfileUpdateMsgList.stream().filter(dfum -> CUSTOM_DEVICE_PROFILE_NAME.equals(dfum.getName())).findAny();
    Assert.assertTrue(deviceProfileUpdateMsgOpt.isPresent());
    DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileUpdateMsgOpt.get();
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType());
    UUID deviceProfileUUID = new UUID(deviceProfileUpdateMsg.getIdMSB(), deviceProfileUpdateMsg.getIdLSB());
    DeviceProfile deviceProfile = doGet("/api/deviceProfile/" + deviceProfileUUID.toString(), DeviceProfile.class);
    Assert.assertNotNull(deviceProfile);
    Assert.assertNotNull(deviceProfile.getProfileData());
    Assert.assertNotNull(deviceProfile.getProfileData().getAlarms());
    Assert.assertNotNull(deviceProfile.getProfileData().getAlarms().get(0).getClearRule());
    testAutoGeneratedCodeByProtobuf(deviceProfileUpdateMsg);
    Optional<AssetUpdateMsg> assetUpdateMsgOpt = edgeImitator.findMessageByType(AssetUpdateMsg.class);
    Assert.assertTrue(assetUpdateMsgOpt.isPresent());
    AssetUpdateMsg assetUpdateMsg = assetUpdateMsgOpt.get();
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, assetUpdateMsg.getMsgType());
    UUID assetUUID = new UUID(assetUpdateMsg.getIdMSB(), assetUpdateMsg.getIdLSB());
    Asset asset = doGet("/api/asset/" + assetUUID.toString(), Asset.class);
    Assert.assertNotNull(asset);
    List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getUuidId() + "/assets?", new TypeReference<PageData<Asset>>() {
    }, new PageLink(100)).getData();
    Assert.assertTrue(edgeAssets.contains(asset));
    testAutoGeneratedCodeByProtobuf(assetUpdateMsg);
    Optional<RuleChainUpdateMsg> ruleChainUpdateMsgOpt = edgeImitator.findMessageByType(RuleChainUpdateMsg.class);
    Assert.assertTrue(ruleChainUpdateMsgOpt.isPresent());
    RuleChainUpdateMsg ruleChainUpdateMsg = ruleChainUpdateMsgOpt.get();
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, ruleChainUpdateMsg.getMsgType());
    UUID ruleChainUUID = new UUID(ruleChainUpdateMsg.getIdMSB(), ruleChainUpdateMsg.getIdLSB());
    RuleChain ruleChain = doGet("/api/ruleChain/" + ruleChainUUID.toString(), RuleChain.class);
    Assert.assertNotNull(ruleChain);
    List<RuleChain> edgeRuleChains = doGetTypedWithPageLink("/api/edge/" + edge.getUuidId() + "/ruleChains?", new TypeReference<PageData<RuleChain>>() {
    }, new PageLink(100)).getData();
    Assert.assertTrue(edgeRuleChains.contains(ruleChain));
    testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg);
    validateAdminSettings();
}
Also used : AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Edge(org.thingsboard.server.common.data.edge.Edge) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) AlarmConditionKeyType(org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType) Autowired(org.springframework.beans.factory.annotation.Autowired) TenantId(org.thingsboard.server.common.data.id.TenantId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) UplinkResponseMsg(org.thingsboard.server.gen.edge.v1.UplinkResponseMsg) Map(java.util.Map) JsonConverter(org.thingsboard.server.common.transport.adaptor.JsonConverter) JsonNode(com.fasterxml.jackson.databind.JsonNode) AlarmStatus(org.thingsboard.server.common.data.alarm.AlarmStatus) EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) PageLink(org.thingsboard.server.common.data.page.PageLink) Authority(org.thingsboard.server.common.data.security.Authority) Alarm(org.thingsboard.server.common.data.alarm.Alarm) EdgeEventActionType(org.thingsboard.server.common.data.edge.EdgeEventActionType) EntityView(org.thingsboard.server.common.data.EntityView) AdminSettingsUpdateMsg(org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) UserCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg) Awaitility(org.awaitility.Awaitility) EntityKeyValueType(org.thingsboard.server.common.data.query.EntityKeyValueType) DeviceCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg) AlarmSeverity(org.thingsboard.server.common.data.alarm.AlarmSeverity) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) Device(org.thingsboard.server.common.data.Device) AlarmUpdateMsg(org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) ArrayList(java.util.ArrayList) User(org.thingsboard.server.common.data.User) EntityIdFactory(org.thingsboard.server.common.data.id.EntityIdFactory) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) WidgetsBundleUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg) DashboardUpdateMsg(org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg) Before(org.junit.Before) RpcResponseMsg(org.thingsboard.server.gen.edge.v1.RpcResponseMsg) DataConstants(org.thingsboard.server.common.data.DataConstants) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) RuleChainType(org.thingsboard.server.common.data.rule.RuleChainType) RuleNode(org.thingsboard.server.common.data.rule.RuleNode) RuleChainMetadataRequestMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataRequestMsg) UserCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) AttributesRequestMsg(org.thingsboard.server.gen.edge.v1.AttributesRequestMsg) Test(org.junit.Test) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg) TreeMap(java.util.TreeMap) PageData(org.thingsboard.server.common.data.page.PageData) DeviceCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) Assert(org.junit.Assert) JsonObject(com.google.gson.JsonObject) DeviceProfileUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg) EdgeImitator(org.thingsboard.server.edge.imitator.EdgeImitator) DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg) Customer(org.thingsboard.server.common.data.Customer) RuleChainMetaData(org.thingsboard.server.common.data.rule.RuleChainMetaData) AssetUpdateMsg(org.thingsboard.server.gen.edge.v1.AssetUpdateMsg) Random(java.util.Random) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) WidgetTypeUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg) After(org.junit.After) AttributeDeleteMsg(org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg) EntityType(org.thingsboard.server.common.data.EntityType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) EdgeId(org.thingsboard.server.common.data.id.EdgeId) Dashboard(org.thingsboard.server.common.data.Dashboard) EdgeEventService(org.thingsboard.server.dao.edge.EdgeEventService) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) UUID(java.util.UUID) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) UserUpdateMsg(org.thingsboard.server.gen.edge.v1.UserUpdateMsg) RuleChainUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg) List(java.util.List) TbClusterService(org.thingsboard.server.cluster.TbClusterService) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) UpdateMsgType(org.thingsboard.server.gen.edge.v1.UpdateMsgType) EntityViewsRequestMsg(org.thingsboard.server.gen.edge.v1.EntityViewsRequestMsg) RelationRequestMsg(org.thingsboard.server.gen.edge.v1.RelationRequestMsg) JacksonUtil(org.thingsboard.common.util.JacksonUtil) Tenant(org.thingsboard.server.common.data.Tenant) RuleChainMetadataUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TenantProfile(org.thingsboard.server.common.data.TenantProfile) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) SimpleAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.SimpleAlarmConditionSpec) EntityId(org.thingsboard.server.common.data.id.EntityId) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg) AlarmInfo(org.thingsboard.server.common.data.alarm.AlarmInfo) AbstractMessage(com.google.protobuf.AbstractMessage) DeviceCredentialsType(org.thingsboard.server.common.data.security.DeviceCredentialsType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EdgeConfiguration(org.thingsboard.server.gen.edge.v1.EdgeConfiguration) TimeUnit(java.util.concurrent.TimeUnit) MessageLite(com.google.protobuf.MessageLite) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) EdgeEventType(org.thingsboard.server.common.data.edge.EdgeEventType) Asset(org.thingsboard.server.common.data.asset.Asset) DeviceProfileUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg) Device(org.thingsboard.server.common.data.Device) EdgeConfiguration(org.thingsboard.server.gen.edge.v1.EdgeConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) AssetUpdateMsg(org.thingsboard.server.gen.edge.v1.AssetUpdateMsg) PageLink(org.thingsboard.server.common.data.page.PageLink) Asset(org.thingsboard.server.common.data.asset.Asset) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) TypeReference(com.fasterxml.jackson.core.type.TypeReference) UUID(java.util.UUID) RuleChainUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg)

Example 2 with DeviceUpdateMsg

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

the class BaseEdgeTest method testSendDeviceToCloudWithNameThatAlreadyExistsOnCloud.

@Test
public void testSendDeviceToCloudWithNameThatAlreadyExistsOnCloud() throws Exception {
    String deviceOnCloudName = RandomStringUtils.randomAlphanumeric(15);
    Device deviceOnCloud = saveDevice(deviceOnCloudName, "Default");
    UUID uuid = Uuids.timeBased();
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
    deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
    deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
    deviceUpdateMsgBuilder.setName(deviceOnCloudName);
    deviceUpdateMsgBuilder.setType("test");
    deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
    testAutoGeneratedCodeByProtobuf(deviceUpdateMsgBuilder);
    uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(2);
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getMessageFromTail(2);
    Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
    DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
    Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName());
    Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName());
    UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
    Assert.assertNotEquals(deviceOnCloud.getId().getId(), newDeviceId);
    Device device = doGet("/api/device/" + newDeviceId, Device.class);
    Assert.assertNotNull(device);
    Assert.assertNotEquals(deviceOnCloudName, device.getName());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceCredentialsRequestMsg);
    DeviceCredentialsRequestMsg latestDeviceCredentialsRequestMsg = (DeviceCredentialsRequestMsg) latestMessage;
    Assert.assertEquals(uuid.getMostSignificantBits(), latestDeviceCredentialsRequestMsg.getDeviceIdMSB());
    Assert.assertEquals(uuid.getLeastSignificantBits(), latestDeviceCredentialsRequestMsg.getDeviceIdLSB());
    newDeviceId = new UUID(latestDeviceCredentialsRequestMsg.getDeviceIdMSB(), latestDeviceCredentialsRequestMsg.getDeviceIdLSB());
    device = doGet("/api/device/" + newDeviceId, Device.class);
    Assert.assertNotNull(device);
    Assert.assertNotEquals(deviceOnCloudName, device.getName());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) DeviceCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg) Device(org.thingsboard.server.common.data.Device) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) UUID(java.util.UUID) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 3 with DeviceUpdateMsg

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

the class BaseEdgeTest method saveDeviceOnCloudAndVerifyDeliveryToEdge.

// Utility methods
private Device saveDeviceOnCloudAndVerifyDeliveryToEdge() throws Exception {
    edgeImitator.expectMessageAmount(1);
    Device savedDevice = saveDevice(RandomStringUtils.randomAlphanumeric(15), "Default");
    doPost("/api/edge/" + edge.getUuidId() + "/device/" + savedDevice.getUuidId(), Device.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
    DeviceUpdateMsg deviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType());
    Assert.assertEquals(deviceUpdateMsg.getIdMSB(), savedDevice.getUuidId().getMostSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getIdLSB(), savedDevice.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getName(), savedDevice.getName());
    Assert.assertEquals(deviceUpdateMsg.getType(), savedDevice.getType());
    return savedDevice;
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)

Example 4 with DeviceUpdateMsg

use of org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg 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 5 with DeviceUpdateMsg

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

the class EntityEdgeProcessor method processEntityMergeRequestMessageToEdge.

public DownlinkMsg processEntityMergeRequestMessageToEdge(Edge edge, EdgeEvent edgeEvent) {
    DownlinkMsg downlinkMsg = null;
    if (EdgeEventType.DEVICE.equals(edgeEvent.getType())) {
        DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
        Device device = deviceService.findDeviceById(edge.getTenantId(), deviceId);
        CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device, edge);
        String conflictName = null;
        if (edgeEvent.getBody() != null) {
            conflictName = edgeEvent.getBody().get("conflictName").asText();
        }
        DeviceUpdateMsg deviceUpdateMsg = deviceMsgConstructor.constructDeviceUpdatedMsg(UpdateMsgType.ENTITY_MERGE_RPC_MESSAGE, device, customerId, conflictName);
        downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceUpdateMsg(deviceUpdateMsg).build();
    }
    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)

Aggregations

Device (org.thingsboard.server.common.data.Device)6 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)6 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)3 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)3 UUID (java.util.UUID)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 DeviceCredentialsRequestMsg (org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg)2 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)2 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)2 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonObject (com.google.gson.JsonObject)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 MessageLite (com.google.protobuf.MessageLite)1