Search in sources :

Example 1 with UserCredentialsUpdateMsg

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

the class UserEdgeProcessor method processUserToEdge.

public DownlinkMsg processUserToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    UserId userId = new UserId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            User user = userService.findUserById(edgeEvent.getTenantId(), userId);
            if (user != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(user, edge);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserUpdatedMsg(msgType, user, customerId)).build();
            }
            break;
        case DELETED:
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserDeleteMsg(userId)).build();
            break;
        case CREDENTIALS_UPDATED:
            UserCredentials userCredentialsByUserId = userService.findUserCredentialsByUserId(edge.getTenantId(), userId);
            if (userCredentialsByUserId != null && userCredentialsByUserId.isEnabled()) {
                UserCredentialsUpdateMsg userCredentialsUpdateMsg = userMsgConstructor.constructUserCredentialsUpdatedMsg(userCredentialsByUserId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserCredentialsUpdateMsg(userCredentialsUpdateMsg).build();
            }
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) User(org.thingsboard.server.common.data.User) UserId(org.thingsboard.server.common.data.id.UserId) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials) UserCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Example 2 with UserCredentialsUpdateMsg

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

the class BaseEdgeTest method testSendUserCredentialsRequestToCloud.

@Test
public void testSendUserCredentialsRequestToCloud() throws Exception {
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    UserCredentialsRequestMsg.Builder userCredentialsRequestMsgBuilder = UserCredentialsRequestMsg.newBuilder();
    userCredentialsRequestMsgBuilder.setUserIdMSB(tenantAdmin.getId().getId().getMostSignificantBits());
    userCredentialsRequestMsgBuilder.setUserIdLSB(tenantAdmin.getId().getId().getLeastSignificantBits());
    testAutoGeneratedCodeByProtobuf(userCredentialsRequestMsgBuilder);
    uplinkMsgBuilder.addUserCredentialsRequestMsg(userCredentialsRequestMsgBuilder.build());
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(1);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof UserCredentialsUpdateMsg);
    UserCredentialsUpdateMsg userCredentialsUpdateMsg = (UserCredentialsUpdateMsg) latestMessage;
    Assert.assertEquals(userCredentialsUpdateMsg.getUserIdMSB(), tenantAdmin.getId().getId().getMostSignificantBits());
    Assert.assertEquals(userCredentialsUpdateMsg.getUserIdLSB(), tenantAdmin.getId().getId().getLeastSignificantBits());
    testAutoGeneratedCodeByProtobuf(userCredentialsUpdateMsg);
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) UserCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg) UserCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

UserCredentialsUpdateMsg (org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg)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 UserId (org.thingsboard.server.common.data.id.UserId)1 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)1 UserCredentialsRequestMsg (org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg)1