Search in sources :

Example 1 with WidgetTypeUpdateMsg

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

the class WidgetTypeEdgeProcessor method processWidgetTypeToEdge.

public DownlinkMsg processWidgetTypeToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    WidgetTypeId widgetTypeId = new WidgetTypeId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            WidgetTypeDetails widgetTypeDetails = widgetTypeService.findWidgetTypeDetailsById(edgeEvent.getTenantId(), widgetTypeId);
            if (widgetTypeDetails != null) {
                WidgetTypeUpdateMsg widgetTypeUpdateMsg = widgetTypeMsgConstructor.constructWidgetTypeUpdateMsg(msgType, widgetTypeDetails);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetTypeUpdateMsg(widgetTypeUpdateMsg).build();
            }
            break;
        case DELETED:
            WidgetTypeUpdateMsg widgetTypeUpdateMsg = widgetTypeMsgConstructor.constructWidgetTypeDeleteMsg(widgetTypeId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetTypeUpdateMsg(widgetTypeUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : WidgetTypeUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) WidgetTypeId(org.thingsboard.server.common.data.id.WidgetTypeId) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails)

Example 2 with WidgetTypeUpdateMsg

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

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