Browse Source

Merge branch 'fix/lastActivityTime' of https://github.com/zbeacon/thingsboard into zbeacon-fix/lastActivityTime

pull/3985/head
Andrii Shvaika 6 years ago
parent
commit
5a5f29610f
  1. 1
      common/queue/src/main/proto/queue.proto
  2. 26
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java
  3. 17
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java
  4. 12
      ui-ngx/src/app/modules/home/pages/device/device.component.html
  5. 10
      ui-ngx/src/app/modules/home/pages/device/device.component.ts
  6. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json

1
common/queue/src/main/proto/queue.proto

@ -53,6 +53,7 @@ message SessionInfoProto {
int64 gwSessionIdLSB = 11;
int64 deviceProfileIdMSB = 12;
int64 deviceProfileIdLSB = 13;
bool activityTimeFromGatewayDevice = 14;
}
enum SessionEvent {

26
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/auth/SessionInfoCreator.java

@ -15,16 +15,20 @@
*/
package org.thingsboard.server.common.transport.auth;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.thingsboard.server.common.transport.TransportContext;
import org.thingsboard.server.gen.transport.TransportProtos;
import java.io.IOException;
import java.util.UUID;
@Slf4j
public class SessionInfoCreator {
public static TransportProtos.SessionInfoProto create(ValidateDeviceCredentialsResponse msg, TransportContext context, UUID sessionId) {
return TransportProtos.SessionInfoProto.newBuilder()
.setNodeId(context.getNodeId())
TransportProtos.SessionInfoProto.Builder builder = TransportProtos.SessionInfoProto.newBuilder();
builder.setNodeId(context.getNodeId())
.setSessionIdMSB(sessionId.getMostSignificantBits())
.setSessionIdLSB(sessionId.getLeastSignificantBits())
.setDeviceIdMSB(msg.getDeviceInfo().getDeviceId().getId().getMostSignificantBits())
@ -34,8 +38,22 @@ public class SessionInfoCreator {
.setDeviceName(msg.getDeviceInfo().getDeviceName())
.setDeviceType(msg.getDeviceInfo().getDeviceType())
.setDeviceProfileIdMSB(msg.getDeviceInfo().getDeviceProfileId().getId().getMostSignificantBits())
.setDeviceProfileIdLSB(msg.getDeviceInfo().getDeviceProfileId().getId().getLeastSignificantBits())
.build();
.setDeviceProfileIdLSB(msg.getDeviceInfo().getDeviceProfileId().getId().getLeastSignificantBits());
if (!"null".equals(msg.getDeviceInfo().getAdditionalInfo())) {
try {
JsonNode infoNode = context.getMapper().readTree(msg.getDeviceInfo().getAdditionalInfo());
if (infoNode.get("gateway").asBoolean()) {
boolean activityTimeFromGatewayDevice = false;
if (infoNode.has("activityTimeFromGatewayDevice")) {
activityTimeFromGatewayDevice = infoNode.get("activityTimeFromGatewayDevice").asBoolean();
}
builder.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice);
}
} catch (IOException e) {
log.trace("[{}][{}] Failed to fetch device additional info", sessionId, msg.getDeviceInfo().getDeviceName(), e);
}
}
return builder.build();
}
}

17
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

@ -61,6 +61,7 @@ import org.thingsboard.server.common.transport.util.JsonUtils;
import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceRequestMsg;
import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsg;
import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg;
import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg;
import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg;
@ -512,7 +513,7 @@ public class DefaultTransportService implements TransportService {
if (sessionInfo.getGwSessionIdMSB() != 0 &&
sessionInfo.getGwSessionIdLSB() != 0) {
SessionMetaData gwMetaData = sessions.get(new UUID(sessionInfo.getGwSessionIdMSB(), sessionInfo.getGwSessionIdLSB()));
if (gwMetaData != null) {
if (gwMetaData != null && gwMetaData.getSessionInfo().getActivityTimeFromGatewayDevice()) {
lastActivityTime = Math.max(gwMetaData.getLastActivityTime(), lastActivityTime);
}
}
@ -702,13 +703,21 @@ public class DefaultTransportService implements TransportService {
} else {
newDeviceProfile = null;
}
TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder()
TransportProtos.SessionInfoProto.Builder newSessionInfoBuilder = TransportProtos.SessionInfoProto.newBuilder()
.mergeFrom(md.getSessionInfo())
.setDeviceProfileIdMSB(deviceProfileIdMSB)
.setDeviceProfileIdLSB(deviceProfileIdLSB)
.setDeviceName(device.getName())
.setDeviceType(device.getType())
.build();
.setDeviceType(device.getType());
if (device.getAdditionalInfo().has("gateway")
&& device.getAdditionalInfo().get("gateway").asBoolean()
&& device.getAdditionalInfo().has("activityTimeFromGatewayDevice")) {
boolean activityTimeFromGatewayDevice = device.getAdditionalInfo().get("activityTimeFromGatewayDevice").asBoolean();
if (md.getSessionInfo().getActivityTimeFromGatewayDevice() != activityTimeFromGatewayDevice) {
newSessionInfoBuilder.setActivityTimeFromGatewayDevice(activityTimeFromGatewayDevice);
}
}
TransportProtos.SessionInfoProto newSessionInfo = newSessionInfoBuilder.build();
md.setSessionInfo(newSessionInfo);
transportCallbackExecutor.submit(() -> md.getListener().onDeviceUpdate(newSessionInfo, device, Optional.ofNullable(newDeviceProfile)));
}

12
ui-ngx/src/app/modules/home/pages/device/device.component.html

@ -100,9 +100,15 @@
required>
</tb-device-data>
<div formGroupName="additionalInfo" fxLayout="column">
<mat-checkbox fxFlex formControlName="gateway" style="padding-bottom: 16px;">
{{ 'device.is-gateway' | translate }}
</mat-checkbox>
<div fxLayout="row" fxLayout.xs="column" style="padding-bottom: 16px;">
<mat-checkbox fxFlex.gt-sm="30" fxFlex formControlName="gateway">
{{ 'device.is-gateway' | translate }}
</mat-checkbox>
<mat-checkbox fxFlex *ngIf="entityForm.get('additionalInfo.gateway').value"
formControlName="activityTimeFromGatewayDevice">
{{ 'device.activity-time-from-gateway-device' | translate }}
</mat-checkbox>
</div>
<mat-form-field class="mat-block">
<mat-label translate>device.description</mat-label>
<textarea matInput formControlName="description" rows="2"></textarea>

10
ui-ngx/src/app/modules/home/pages/device/device.component.ts

@ -84,6 +84,7 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> {
additionalInfo: this.fb.group(
{
gateway: [entity && entity.additionalInfo ? entity.additionalInfo.gateway : false],
activityTimeFromGatewayDevice: [entity && entity.additionalInfo ? entity.additionalInfo.activityTimeFromGatewayDevice: false],
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
}
)
@ -96,8 +97,13 @@ export class DeviceComponent extends EntityComponent<DeviceInfo> {
this.entityForm.patchValue({deviceProfileId: entity.deviceProfileId});
this.entityForm.patchValue({label: entity.label});
this.entityForm.patchValue({deviceData: entity.deviceData});
this.entityForm.patchValue({additionalInfo:
{gateway: entity.additionalInfo ? entity.additionalInfo.gateway : false}});
this.entityForm.patchValue({
additionalInfo:
{
gateway: entity.additionalInfo ? entity.additionalInfo.gateway : false,
activityTimeFromGatewayDevice: entity.additionalInfo ? entity.additionalInfo.activityTimeFromGatewayDevice : false
}
});
this.entityForm.patchValue({additionalInfo: {description: entity.additionalInfo ? entity.additionalInfo.description : ''}});
}

2
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -906,6 +906,7 @@
"unable-delete-device-alias-title": "Unable to delete device alias",
"unable-delete-device-alias-text": "Device alias '{{deviceAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}",
"is-gateway": "Is gateway",
"activity-time-from-gateway-device": "Activity time from gateway device",
"public": "Public",
"device-public": "Device is public",
"select-device": "Select device",
@ -1721,6 +1722,7 @@
"entity-field": "Entity field",
"access-token": "Access token",
"isgateway": "Is Gateway",
"activity-time-from-gateway-device": "Activity time from gateway device",
"description": "Description"
},
"stepper-text":{

Loading…
Cancel
Save