diff --git a/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java b/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java index cf07f65010..793afa97d7 100644 --- a/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java +++ b/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java @@ -42,8 +42,12 @@ public class SessionInfoCreator { if (!"null".equals(msg.getDeviceInfo().getAdditionalInfo())) { try { JsonNode infoNode = context.getMapper().readTree(msg.getDeviceInfo().getAdditionalInfo()); - if (infoNode.get("gateway").asBoolean()) { - builder.setActivityTimeFromGatewayDevice(infoNode.get("activityTimeFromGatewayDevice").asBoolean()); + if (infoNode.get("gateway").asBoolean(false)) { + boolean activityTimeFromGatewayDevice = false; + if (infoNode.get("activityTimeFromGatewayDevice") != null) { + activityTimeFromGatewayDevice = infoNode.get("activityTimeFromGatewayDevice").asBoolean(); + } + builder.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice); } } catch (IOException e) { log.trace("[{}][{}] Failed to fetch device additional info", sessionId, msg.getDeviceInfo().getDeviceName(), e); diff --git a/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java b/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java index df1807cc0d..4b41313b7e 100644 --- a/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java +++ b/common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java @@ -649,35 +649,32 @@ public class DefaultTransportService implements TransportService { Optional deviceOpt = dataDecodingEncodingService.decode(msg.getData().toByteArray()); if (deviceOpt.isPresent()) { Device device = deviceOpt.get(); - if (device.getAdditionalInfo() != null) { - if (device.getAdditionalInfo().get("gateway") != null - && device.getAdditionalInfo().get("gateway").asBoolean()) { - sessions.forEach((uuid, currentMD) -> { - if (device.getId().equals(new DeviceId(new UUID(currentMD.getSessionInfo().getDeviceIdMSB(), currentMD.getSessionInfo().getDeviceIdLSB())))) { - boolean newActivityTimeFromGatewayDevice = device.getAdditionalInfo().get("activityTimeFromGatewayDevice").asBoolean(); - if (currentMD.getSessionInfo().getActivityTimeFromGatewayDevice() != newActivityTimeFromGatewayDevice) { - SessionInfoProto currentSessionInfo = currentMD.getSessionInfo(); - SessionInfoProto newSessionInfo = SessionInfoProto.newBuilder() - .setNodeId(currentSessionInfo.getNodeId()) - .setSessionIdMSB(currentSessionInfo.getSessionIdMSB()) - .setSessionIdLSB(currentSessionInfo.getSessionIdLSB()) - .setDeviceIdMSB(currentSessionInfo.getDeviceIdMSB()) - .setDeviceIdLSB(currentSessionInfo.getDeviceIdLSB()) - .setTenantIdMSB(currentSessionInfo.getTenantIdMSB()) - .setTenantIdLSB(currentSessionInfo.getTenantIdLSB()) - .setDeviceName(currentSessionInfo.getDeviceName()) - .setDeviceType(currentSessionInfo.getDeviceType()) - .setGwSessionIdMSB(currentSessionInfo.getGwSessionIdMSB()) - .setGwSessionIdLSB(currentSessionInfo.getGwSessionIdLSB()) - .setDeviceProfileIdMSB(currentSessionInfo.getDeviceProfileIdMSB()) - .setDeviceProfileIdLSB(currentSessionInfo.getDeviceProfileIdLSB()) - .setActivityTimeFromGatewayDevice(newActivityTimeFromGatewayDevice) - .build(); - currentMD.setSessionInfo(newSessionInfo); - } + if (device.getAdditionalInfo().get("gateway") != null && device.getAdditionalInfo().get("gateway").asBoolean()) { + sessions.forEach((uuid, currentMD) -> { + if (device.getId().equals(new DeviceId(new UUID(currentMD.getSessionInfo().getDeviceIdMSB(), currentMD.getSessionInfo().getDeviceIdLSB())))) { + boolean newActivityTimeFromGatewayDevice = device.getAdditionalInfo().get("activityTimeFromGatewayDevice").asBoolean(false); + if (currentMD.getSessionInfo().getActivityTimeFromGatewayDevice() != newActivityTimeFromGatewayDevice) { + SessionInfoProto currentSessionInfo = currentMD.getSessionInfo(); + SessionInfoProto newSessionInfo = SessionInfoProto.newBuilder() + .setNodeId(currentSessionInfo.getNodeId()) + .setSessionIdMSB(currentSessionInfo.getSessionIdMSB()) + .setSessionIdLSB(currentSessionInfo.getSessionIdLSB()) + .setDeviceIdMSB(currentSessionInfo.getDeviceIdMSB()) + .setDeviceIdLSB(currentSessionInfo.getDeviceIdLSB()) + .setTenantIdMSB(currentSessionInfo.getTenantIdMSB()) + .setTenantIdLSB(currentSessionInfo.getTenantIdLSB()) + .setDeviceName(currentSessionInfo.getDeviceName()) + .setDeviceType(currentSessionInfo.getDeviceType()) + .setGwSessionIdMSB(currentSessionInfo.getGwSessionIdMSB()) + .setGwSessionIdLSB(currentSessionInfo.getGwSessionIdLSB()) + .setDeviceProfileIdMSB(currentSessionInfo.getDeviceProfileIdMSB()) + .setDeviceProfileIdLSB(currentSessionInfo.getDeviceProfileIdLSB()) + .setActivityTimeFromGatewayDevice(newActivityTimeFromGatewayDevice) + .build(); + currentMD.setSessionInfo(newSessionInfo); } - }); - } + } + }); } onDeviceUpdate(device); }