Browse Source

Merge branch 'master' of https://github.com/thingsboard/thingsboard into feature/device-provision-3.2-onlyProfileVersion

pull/3518/head
zbeacon 6 years ago
parent
commit
6e4c404929
  1. 5
      application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/profile/DefaultTbDeviceProfileCache.java
  3. 3
      application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java
  4. 4
      application/src/main/java/org/thingsboard/server/service/state/DeviceStateData.java
  5. 27
      ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts
  6. 1
      ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html
  7. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

5
application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java

@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.channel.EventLoopGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.thingsboard.common.util.ListeningExecutor;
import org.thingsboard.rule.engine.api.MailService;
import org.thingsboard.rule.engine.api.RuleEngineAlarmService;
@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.rule.RuleNodeState;
import org.thingsboard.server.common.msg.TbActorMsg;
import org.thingsboard.server.common.msg.TbMsg;
import org.thingsboard.server.common.msg.TbMsgMetaData;
import org.thingsboard.server.common.msg.queue.ServiceQueue;
import org.thingsboard.server.common.msg.queue.ServiceType;
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
import org.thingsboard.server.dao.asset.AssetService;
@ -183,6 +185,9 @@ class DefaultTbContext implements TbContext {
}
private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) {
if (StringUtils.isEmpty(queueName)) {
queueName = ServiceQueue.MAIN;
}
return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator());
}

2
application/src/main/java/org/thingsboard/server/service/profile/DefaultTbDeviceProfileCache.java

@ -74,6 +74,8 @@ public class DefaultTbDeviceProfileCache implements TbDeviceProfileCache {
if (device != null) {
profileId = device.getDeviceProfileId();
devicesMap.put(deviceId, profileId);
} else {
return null;
}
}
return get(tenantId, profileId);

3
application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java

@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
if (stateData != null) {
DeviceState state = stateData.getState();
state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout());
if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime())) {
if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime()) && stateData.getDeviceCreationTime() + state.getInactivityTimeout() < ts) {
state.setLastInactivityAlarmTime(ts);
pushRuleEngineMessage(stateData, INACTIVITY_EVENT);
save(deviceId, INACTIVITY_ALARM_TIME, ts);
@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
return DeviceStateData.builder()
.tenantId(device.getTenantId())
.deviceId(device.getId())
.deviceCreationTime(device.getCreatedTime())
.metaData(md)
.state(deviceState).build();
} catch (Exception e) {

4
application/src/main/java/org/thingsboard/server/service/state/DeviceStateData.java

@ -30,8 +30,8 @@ class DeviceStateData {
private final TenantId tenantId;
private final DeviceId deviceId;
private final long deviceCreationTime;
private TbMsgMetaData metaData;
private final DeviceState state;
}

27
ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts

@ -64,6 +64,9 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor,
@Input()
selectDefaultProfile = false;
@Input()
selectFirstProfile = false;
@Input()
displayAllOnEmpty = false;
@ -183,12 +186,34 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor,
if (this.selectDefaultProfile && !this.modelValue) {
this.deviceProfileService.getDefaultDeviceProfileInfo().subscribe(
(profile) => {
if (profile && !this.transportType || (profile.transportType === this.transportType)) {
if (profile && (!this.transportType || (profile.transportType === this.transportType))) {
this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(profile, {emitEvent: false});
this.updateView(profile);
} else {
this.selectFirstDeviceProfileIfNeeded();
}
}
);
} else {
this.selectFirstDeviceProfileIfNeeded();
}
}
selectFirstDeviceProfileIfNeeded(): void {
if (this.selectFirstProfile && !this.modelValue) {
const pageLink = new PageLink(1, 0, null, {
property: 'createdTime',
direction: Direction.DESC
});
this.deviceProfileService.getDeviceProfileInfos(pageLink, this.transportType, {ignoreLoading: true}).subscribe(
(pageData => {
const data = pageData.data;
if (data.length) {
this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(data[0], {emitEvent: false});
this.updateView(data[0]);
}
})
);
}
}

1
ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html

@ -79,6 +79,7 @@
(deviceProfileChanged)="$event?.transportType ? deviceWizardFormGroup.get('transportType').patchValue($event?.transportType) : {}"
[addNewProfile]="false"
[selectDefaultProfile]="true"
[selectFirstProfile]="true"
[editProfileEnabled]="false">
</tb-device-profile-autocomplete>
<mat-form-field fxFlex class="mat-block">

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

@ -794,9 +794,9 @@
"transport-type": "Transport type",
"transport-type-required": "Transport type is required.",
"transport-type-default": "Default",
"transport-type-default-hint": "Default transport type",
"transport-type-default-hint": "Refers to already existing transport configuration or basic MQTT, HTTP, CoAP settings",
"transport-type-mqtt": "MQTT",
"transport-type-mqtt-hint": "MQTT transport type",
"transport-type-mqtt-hint": "Advanced MQTT topic filters and Device profile settings",
"transport-type-lwm2m": "LWM2M",
"transport-type-lwm2m-hint": "LWM2M transport type",
"description": "Description",

Loading…
Cancel
Save