Search in sources :

Example 1 with RelationUpdateMsg

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

the class RelationEdgeProcessor method processRelationToEdge.

public DownlinkMsg processRelationToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType) {
    EntityRelation entityRelation = mapper.convertValue(edgeEvent.getBody(), EntityRelation.class);
    RelationUpdateMsg relationUpdateMsg = relationMsgConstructor.constructRelationUpdatedMsg(msgType, entityRelation);
    return DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRelationUpdateMsg(relationUpdateMsg).build();
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg)

Example 2 with RelationUpdateMsg

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

the class BaseEdgeTest method testRelations.

@Test
public void testRelations() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Device device = findDeviceByName("Edge Device 1");
    Asset asset = findAssetByName("Edge Asset 1");
    EntityRelation relation = new EntityRelation();
    relation.setType("test");
    relation.setFrom(device.getId());
    relation.setTo(asset.getId());
    relation.setTypeGroup(RelationTypeGroup.COMMON);
    doPost("/api/relation", relation);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
    RelationUpdateMsg relationUpdateMsg = (RelationUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
    Assert.assertEquals(relationUpdateMsg.getType(), relation.getType());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
    // 2
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/relation?" + "fromId=" + relation.getFrom().getId().toString() + "&fromType=" + relation.getFrom().getEntityType().name() + "&relationType=" + relation.getType() + "&relationTypeGroup=" + relation.getTypeGroup().name() + "&toId=" + relation.getTo().getId().toString() + "&toType=" + relation.getTo().getEntityType().name()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
    relationUpdateMsg = (RelationUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
    Assert.assertEquals(relationUpdateMsg.getType(), relation.getType());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) Asset(org.thingsboard.server.common.data.asset.Asset) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 3 with RelationUpdateMsg

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

the class BaseEdgeTest method testSendRelationRequestToCloud.

@Test
public void testSendRelationRequestToCloud() throws Exception {
    Device device = findDeviceByName("Edge Device 1");
    Asset asset = findAssetByName("Edge Asset 1");
    EntityRelation relation = new EntityRelation();
    relation.setType("test");
    relation.setFrom(device.getId());
    relation.setTo(asset.getId());
    relation.setTypeGroup(RelationTypeGroup.COMMON);
    edgeImitator.expectMessageAmount(1);
    doPost("/api/relation", relation);
    Assert.assertTrue(edgeImitator.waitForMessages());
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    RelationRequestMsg.Builder relationRequestMsgBuilder = RelationRequestMsg.newBuilder();
    relationRequestMsgBuilder.setEntityIdMSB(device.getId().getId().getMostSignificantBits());
    relationRequestMsgBuilder.setEntityIdLSB(device.getId().getId().getLeastSignificantBits());
    relationRequestMsgBuilder.setEntityType(device.getId().getEntityType().name());
    testAutoGeneratedCodeByProtobuf(relationRequestMsgBuilder);
    uplinkMsgBuilder.addRelationRequestMsg(relationRequestMsgBuilder.build());
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(1);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
    RelationUpdateMsg relationUpdateMsg = (RelationUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
    Assert.assertEquals(relation.getType(), relationUpdateMsg.getType());
    UUID fromUUID = new UUID(relationUpdateMsg.getFromIdMSB(), relationUpdateMsg.getFromIdLSB());
    EntityId fromEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getFromEntityType(), fromUUID);
    Assert.assertEquals(relation.getFrom(), fromEntityId);
    UUID toUUID = new UUID(relationUpdateMsg.getToIdMSB(), relationUpdateMsg.getToIdLSB());
    EntityId toEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getToEntityType(), toUUID);
    Assert.assertEquals(relation.getTo(), toEntityId);
    Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup());
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) RelationRequestMsg(org.thingsboard.server.gen.edge.v1.RelationRequestMsg) AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) Asset(org.thingsboard.server.common.data.asset.Asset) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg) UUID(java.util.UUID) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)3 RelationUpdateMsg (org.thingsboard.server.gen.edge.v1.RelationUpdateMsg)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 Device (org.thingsboard.server.common.data.Device)2 Asset (org.thingsboard.server.common.data.asset.Asset)2 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)2 UUID (java.util.UUID)1 EntityId (org.thingsboard.server.common.data.id.EntityId)1 RelationRequestMsg (org.thingsboard.server.gen.edge.v1.RelationRequestMsg)1 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)1