Search in sources :

Example 1 with DashboardUpdateMsg

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

the class DashboardEdgeProcessor method processDashboardToEdge.

public DownlinkMsg processDashboardToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            Dashboard dashboard = dashboardService.findDashboardById(edgeEvent.getTenantId(), dashboardId);
            if (dashboard != null) {
                CustomerId customerId = null;
                if (!edge.getCustomerId().isNullUid() && dashboard.isAssignedToCustomer(edge.getCustomerId())) {
                    customerId = edge.getCustomerId();
                }
                DashboardUpdateMsg dashboardUpdateMsg = dashboardMsgConstructor.constructDashboardUpdatedMsg(msgType, dashboard, customerId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDashboardUpdateMsg(dashboardUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            DashboardUpdateMsg dashboardUpdateMsg = dashboardMsgConstructor.constructDashboardDeleteMsg(dashboardId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDashboardUpdateMsg(dashboardUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardId(org.thingsboard.server.common.data.id.DashboardId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardUpdateMsg(org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg)

Example 2 with DashboardUpdateMsg

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

the class BaseEdgeTest method testDashboards.

@Test
public void testDashboards() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("Edge Test Dashboard");
    Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
    doPost("/api/edge/" + edge.getUuidId() + "/dashboard/" + savedDashboard.getUuidId(), Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    DashboardUpdateMsg dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getIdMSB(), savedDashboard.getUuidId().getMostSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
    testAutoGeneratedCodeByProtobuf(dashboardUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    savedDashboard.setTitle("Updated Edge Test Dashboard");
    doPost("/api/dashboard", savedDashboard, Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/edge/" + edge.getUuidId() + "/dashboard/" + savedDashboard.getUuidId(), Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getIdMSB(), savedDashboard.getUuidId().getMostSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
    // 4
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/dashboard/" + savedDashboard.getUuidId()).andExpect(status().isOk());
    Assert.assertFalse(edgeImitator.waitForMessages(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardUpdateMsg(org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

Dashboard (org.thingsboard.server.common.data.Dashboard)2 DashboardUpdateMsg (org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg)2 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 DashboardId (org.thingsboard.server.common.data.id.DashboardId)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1