Refactoring

This commit is contained in:
zbeacon 2021-01-20 12:41:35 +02:00
parent 5338d8e094
commit c24db73a37
2 changed files with 4 additions and 4 deletions

View File

@ -42,9 +42,9 @@ public class SessionInfoCreator {
if (!"null".equals(msg.getDeviceInfo().getAdditionalInfo())) { if (!"null".equals(msg.getDeviceInfo().getAdditionalInfo())) {
try { try {
JsonNode infoNode = context.getMapper().readTree(msg.getDeviceInfo().getAdditionalInfo()); JsonNode infoNode = context.getMapper().readTree(msg.getDeviceInfo().getAdditionalInfo());
if (infoNode.get("gateway").asBoolean(false)) { if (infoNode.get("gateway").asBoolean()) {
boolean activityTimeFromGatewayDevice = false; boolean activityTimeFromGatewayDevice = false;
if (infoNode.get("activityTimeFromGatewayDevice") != null) { if (infoNode.has("activityTimeFromGatewayDevice")) {
activityTimeFromGatewayDevice = infoNode.get("activityTimeFromGatewayDevice").asBoolean(); activityTimeFromGatewayDevice = infoNode.get("activityTimeFromGatewayDevice").asBoolean();
} }
builder.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice); builder.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice);

View File

@ -649,10 +649,10 @@ public class DefaultTransportService implements TransportService {
Optional<Device> deviceOpt = dataDecodingEncodingService.decode(msg.getData().toByteArray()); Optional<Device> deviceOpt = dataDecodingEncodingService.decode(msg.getData().toByteArray());
if (deviceOpt.isPresent()) { if (deviceOpt.isPresent()) {
Device device = deviceOpt.get(); Device device = deviceOpt.get();
if (device.getAdditionalInfo().get("gateway") != null && device.getAdditionalInfo().get("gateway").asBoolean()) { if (device.getAdditionalInfo().has("gateway") && device.getAdditionalInfo().get("gateway").asBoolean()) {
sessions.forEach((uuid, currentMD) -> { sessions.forEach((uuid, currentMD) -> {
if (device.getId().equals(new DeviceId(new UUID(currentMD.getSessionInfo().getDeviceIdMSB(), currentMD.getSessionInfo().getDeviceIdLSB())))) { if (device.getId().equals(new DeviceId(new UUID(currentMD.getSessionInfo().getDeviceIdMSB(), currentMD.getSessionInfo().getDeviceIdLSB())))) {
boolean newActivityTimeFromGatewayDevice = device.getAdditionalInfo().get("activityTimeFromGatewayDevice").asBoolean(false); boolean newActivityTimeFromGatewayDevice = device.getAdditionalInfo().get("activityTimeFromGatewayDevice").asBoolean();
if (currentMD.getSessionInfo().getActivityTimeFromGatewayDevice() != newActivityTimeFromGatewayDevice) { if (currentMD.getSessionInfo().getActivityTimeFromGatewayDevice() != newActivityTimeFromGatewayDevice) {
SessionInfoProto currentSessionInfo = currentMD.getSessionInfo(); SessionInfoProto currentSessionInfo = currentMD.getSessionInfo();
SessionInfoProto newSessionInfo = SessionInfoProto.newBuilder() SessionInfoProto newSessionInfo = SessionInfoProto.newBuilder()