Browse Source

Refactoring

pull/3958/head
zbeacon 6 years ago
parent
commit
5338d8e094
  1. 8
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java
  2. 53
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

8
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);

53
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<Device> 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);
}

Loading…
Cancel
Save