Search in sources :

Example 1 with CustomerUpdateMsg

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

the class CustomerEdgeProcessor method processCustomerToEdge.

public DownlinkMsg processCustomerToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    CustomerId customerId = new CustomerId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
            Customer customer = customerService.findCustomerById(edgeEvent.getTenantId(), customerId);
            if (customer != null) {
                CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerUpdatedMsg(msgType, customer);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            }
            break;
        case DELETED:
            CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerDeleteMsg(customerId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Customer(org.thingsboard.server.common.data.Customer) CustomerId(org.thingsboard.server.common.data.id.CustomerId) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg)

Example 2 with CustomerUpdateMsg

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

the class BaseEdgeTest method testCustomerAndNewUser.

@Test
public void testCustomerAndNewUser() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Customer customer = new Customer();
    customer.setTitle("Edge Customer 1");
    Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
    doPost("/api/customer/" + savedCustomer.getUuidId() + "/edge/" + edge.getUuidId(), Edge.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof CustomerUpdateMsg);
    CustomerUpdateMsg customerUpdateMsg = (CustomerUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, customerUpdateMsg.getMsgType());
    Assert.assertEquals(customerUpdateMsg.getIdMSB(), savedCustomer.getUuidId().getMostSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getTitle(), savedCustomer.getTitle());
    testAutoGeneratedCodeByProtobuf(customerUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    User customerUser = new User();
    customerUser.setAuthority(Authority.CUSTOMER_USER);
    customerUser.setTenantId(savedTenant.getId());
    customerUser.setCustomerId(savedCustomer.getId());
    customerUser.setEmail("customerUser@thingsboard.org");
    customerUser.setFirstName("John");
    customerUser.setLastName("Edwards");
    User savedUser = doPost("/api/user", customerUser, User.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof UserUpdateMsg);
    UserUpdateMsg userUpdateMsg = (UserUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, userUpdateMsg.getMsgType());
    Assert.assertEquals(userUpdateMsg.getIdMSB(), savedUser.getUuidId().getMostSignificantBits());
    Assert.assertEquals(userUpdateMsg.getIdLSB(), savedUser.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(userUpdateMsg.getEmail(), savedUser.getEmail());
    testAutoGeneratedCodeByProtobuf(userUpdateMsg);
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/customer/edge/" + edge.getUuidId(), Edge.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof CustomerUpdateMsg);
    customerUpdateMsg = (CustomerUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, customerUpdateMsg.getMsgType());
    Assert.assertEquals(customerUpdateMsg.getIdMSB(), savedCustomer.getUuidId().getMostSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/customer/" + savedCustomer.getUuidId()).andExpect(status().isOk());
    Assert.assertFalse(edgeImitator.waitForMessages(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) User(org.thingsboard.server.common.data.User) Customer(org.thingsboard.server.common.data.Customer) UserUpdateMsg(org.thingsboard.server.gen.edge.v1.UserUpdateMsg) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

Customer (org.thingsboard.server.common.data.Customer)2 CustomerUpdateMsg (org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg)2 AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1 User (org.thingsboard.server.common.data.User)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1 UserUpdateMsg (org.thingsboard.server.gen.edge.v1.UserUpdateMsg)1