Search in sources :

Example 1 with EntityViewUpdateMsg

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

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

the class EntityViewMsgConstructor method constructEntityViewUpdatedMsg.

public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView, CustomerId customerId) {
    EdgeEntityType entityType;
    switch(entityView.getEntityId().getEntityType()) {
        case DEVICE:
            entityType = EdgeEntityType.DEVICE;
            break;
        case ASSET:
            entityType = EdgeEntityType.ASSET;
            break;
        default:
            throw new RuntimeException("Unsupported entity type [" + entityView.getEntityId().getEntityType() + "]");
    }
    EntityViewUpdateMsg.Builder builder = EntityViewUpdateMsg.newBuilder().setMsgType(msgType).setIdMSB(entityView.getId().getId().getMostSignificantBits()).setIdLSB(entityView.getId().getId().getLeastSignificantBits()).setName(entityView.getName()).setType(entityView.getType()).setEntityIdMSB(entityView.getEntityId().getId().getMostSignificantBits()).setEntityIdLSB(entityView.getEntityId().getId().getLeastSignificantBits()).setEntityType(entityType);
    if (customerId != null) {
        builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
        builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
    }
    if (entityView.getAdditionalInfo() != null) {
        builder.setAdditionalInfo(JacksonUtil.toString(entityView.getAdditionalInfo()));
    }
    return builder.build();
}
Also used : EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg) EdgeEntityType(org.thingsboard.server.gen.edge.v1.EdgeEntityType)

Example 3 with EntityViewUpdateMsg

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

the class BaseEdgeTest method verifyEntityViewUpdateMsg.

private void verifyEntityViewUpdateMsg(EntityView entityView, Device device) {
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityViewUpdateMsg);
    EntityViewUpdateMsg entityViewUpdateMsg = (EntityViewUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, entityViewUpdateMsg.getMsgType());
    Assert.assertEquals(entityViewUpdateMsg.getType(), entityView.getType());
    Assert.assertEquals(entityViewUpdateMsg.getName(), entityView.getName());
    Assert.assertEquals(entityViewUpdateMsg.getIdMSB(), entityView.getUuidId().getMostSignificantBits());
    Assert.assertEquals(entityViewUpdateMsg.getIdLSB(), entityView.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(entityViewUpdateMsg.getEntityIdMSB(), device.getUuidId().getMostSignificantBits());
    Assert.assertEquals(entityViewUpdateMsg.getEntityIdLSB(), device.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(entityViewUpdateMsg.getEntityType().name(), device.getId().getEntityType().name());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)

Example 4 with EntityViewUpdateMsg

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

the class BaseEdgeTest method testEntityView.

@Test
public void testEntityView() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Device device = findDeviceByName("Edge Device 1");
    EntityView entityView = new EntityView();
    entityView.setName("Edge EntityView 1");
    entityView.setType("test");
    entityView.setEntityId(device.getId());
    EntityView savedEntityView = doPost("/api/entityView", entityView, EntityView.class);
    doPost("/api/edge/" + edge.getUuidId() + "/entityView/" + savedEntityView.getUuidId(), EntityView.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    verifyEntityViewUpdateMsg(savedEntityView, device);
    // 2
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    EntityViewsRequestMsg.Builder entityViewsRequestBuilder = EntityViewsRequestMsg.newBuilder();
    entityViewsRequestBuilder.setEntityIdMSB(device.getUuidId().getMostSignificantBits());
    entityViewsRequestBuilder.setEntityIdLSB(device.getUuidId().getLeastSignificantBits());
    entityViewsRequestBuilder.setEntityType(device.getId().getEntityType().name());
    testAutoGeneratedCodeByProtobuf(entityViewsRequestBuilder);
    uplinkMsgBuilder.addEntityViewsRequestMsg(entityViewsRequestBuilder.build());
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(1);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    verifyEntityViewUpdateMsg(savedEntityView, device);
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/edge/" + edge.getUuidId() + "/entityView/" + savedEntityView.getUuidId(), EntityView.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityViewUpdateMsg);
    EntityViewUpdateMsg entityViewUpdateMsg = (EntityViewUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, entityViewUpdateMsg.getMsgType());
    Assert.assertEquals(entityViewUpdateMsg.getIdMSB(), savedEntityView.getUuidId().getMostSignificantBits());
    Assert.assertEquals(entityViewUpdateMsg.getIdLSB(), savedEntityView.getUuidId().getLeastSignificantBits());
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/entityView/" + savedEntityView.getUuidId()).andExpect(status().isOk());
    Assert.assertFalse(edgeImitator.waitForMessages(1));
}
Also used : EntityViewsRequestMsg(org.thingsboard.server.gen.edge.v1.EntityViewsRequestMsg) AbstractMessage(com.google.protobuf.AbstractMessage) EntityView(org.thingsboard.server.common.data.EntityView) Device(org.thingsboard.server.common.data.Device) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

EntityViewUpdateMsg (org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)4 AbstractMessage (com.google.protobuf.AbstractMessage)2 EntityView (org.thingsboard.server.common.data.EntityView)2 Test (org.junit.Test)1 Device (org.thingsboard.server.common.data.Device)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1 EdgeEntityType (org.thingsboard.server.gen.edge.v1.EdgeEntityType)1 EntityViewsRequestMsg (org.thingsboard.server.gen.edge.v1.EntityViewsRequestMsg)1 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)1