Search in sources :

Example 1 with WidgetsBundleUpdateMsg

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

the class WidgetBundleEdgeProcessor method processWidgetsBundleToEdge.

public DownlinkMsg processWidgetsBundleToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    WidgetsBundleId widgetsBundleId = new WidgetsBundleId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            WidgetsBundle widgetsBundle = widgetsBundleService.findWidgetsBundleById(edgeEvent.getTenantId(), widgetsBundleId);
            if (widgetsBundle != null) {
                WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = widgetsBundleMsgConstructor.constructWidgetsBundleUpdateMsg(msgType, widgetsBundle);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetsBundleUpdateMsg(widgetsBundleUpdateMsg).build();
            }
            break;
        case DELETED:
            WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = widgetsBundleMsgConstructor.constructWidgetsBundleDeleteMsg(widgetsBundleId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetsBundleUpdateMsg(widgetsBundleUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) WidgetsBundleId(org.thingsboard.server.common.data.id.WidgetsBundleId) WidgetsBundleUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 2 with WidgetsBundleUpdateMsg

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

the class BaseEdgeTest method testWidgetsBundleAndWidgetType.

@Test
public void testWidgetsBundleAndWidgetType() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("Test Widget Bundle");
    WidgetsBundle savedWidgetsBundle = doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetsBundleUpdateMsg);
    WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = (WidgetsBundleUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetsBundleUpdateMsg.getMsgType());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdMSB(), savedWidgetsBundle.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdLSB(), savedWidgetsBundle.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getAlias(), savedWidgetsBundle.getAlias());
    Assert.assertEquals(widgetsBundleUpdateMsg.getTitle(), savedWidgetsBundle.getTitle());
    testAutoGeneratedCodeByProtobuf(widgetsBundleUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    WidgetType widgetType = new WidgetType();
    widgetType.setName("Test Widget Type");
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    ObjectNode descriptor = mapper.createObjectNode();
    descriptor.put("key", "value");
    widgetType.setDescriptor(descriptor);
    WidgetType savedWidgetType = doPost("/api/widgetType", widgetType, WidgetType.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetTypeUpdateMsg);
    WidgetTypeUpdateMsg widgetTypeUpdateMsg = (WidgetTypeUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getAlias(), savedWidgetType.getAlias());
    Assert.assertEquals(widgetTypeUpdateMsg.getName(), savedWidgetType.getName());
    Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson()), savedWidgetType.getDescriptor());
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/widgetType/" + savedWidgetType.getUuidId()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetTypeUpdateMsg);
    widgetTypeUpdateMsg = (WidgetTypeUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
    // 4
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/widgetsBundle/" + savedWidgetsBundle.getUuidId()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetsBundleUpdateMsg);
    widgetsBundleUpdateMsg = (WidgetsBundleUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, widgetsBundleUpdateMsg.getMsgType());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdMSB(), savedWidgetsBundle.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdLSB(), savedWidgetsBundle.getUuidId().getLeastSignificantBits());
}
Also used : WidgetTypeUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg) AbstractMessage(com.google.protobuf.AbstractMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundleUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)2 WidgetsBundleUpdateMsg (org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1 WidgetsBundleId (org.thingsboard.server.common.data.id.WidgetsBundleId)1 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1 WidgetTypeUpdateMsg (org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg)1