Commit 6e4c4049290cad539f648589a565f704866d8d40
Merge branch 'master' of https://github.com/thingsboard/thingsboard into feature…
…/device-provision-3.2-onlyProfileVersion
Showing
7 changed files
with
40 additions
and
6 deletions
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ||
20 | import io.netty.channel.EventLoopGroup; | 20 | import io.netty.channel.EventLoopGroup; |
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.data.redis.core.RedisTemplate; | 22 | import org.springframework.data.redis.core.RedisTemplate; |
23 | +import org.springframework.util.StringUtils; | ||
23 | import org.thingsboard.common.util.ListeningExecutor; | 24 | import org.thingsboard.common.util.ListeningExecutor; |
24 | import org.thingsboard.rule.engine.api.MailService; | 25 | import org.thingsboard.rule.engine.api.MailService; |
25 | import org.thingsboard.rule.engine.api.RuleEngineAlarmService; | 26 | import org.thingsboard.rule.engine.api.RuleEngineAlarmService; |
@@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.rule.RuleNodeState; | @@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.rule.RuleNodeState; | ||
47 | import org.thingsboard.server.common.msg.TbActorMsg; | 48 | import org.thingsboard.server.common.msg.TbActorMsg; |
48 | import org.thingsboard.server.common.msg.TbMsg; | 49 | import org.thingsboard.server.common.msg.TbMsg; |
49 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 50 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
51 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; | ||
50 | import org.thingsboard.server.common.msg.queue.ServiceType; | 52 | import org.thingsboard.server.common.msg.queue.ServiceType; |
51 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 53 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
52 | import org.thingsboard.server.dao.asset.AssetService; | 54 | import org.thingsboard.server.dao.asset.AssetService; |
@@ -183,6 +185,9 @@ class DefaultTbContext implements TbContext { | @@ -183,6 +185,9 @@ class DefaultTbContext implements TbContext { | ||
183 | } | 185 | } |
184 | 186 | ||
185 | private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) { | 187 | private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) { |
188 | + if (StringUtils.isEmpty(queueName)) { | ||
189 | + queueName = ServiceQueue.MAIN; | ||
190 | + } | ||
186 | return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); | 191 | return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); |
187 | } | 192 | } |
188 | 193 |
@@ -74,6 +74,8 @@ public class DefaultTbDeviceProfileCache implements TbDeviceProfileCache { | @@ -74,6 +74,8 @@ public class DefaultTbDeviceProfileCache implements TbDeviceProfileCache { | ||
74 | if (device != null) { | 74 | if (device != null) { |
75 | profileId = device.getDeviceProfileId(); | 75 | profileId = device.getDeviceProfileId(); |
76 | devicesMap.put(deviceId, profileId); | 76 | devicesMap.put(deviceId, profileId); |
77 | + } else { | ||
78 | + return null; | ||
77 | } | 79 | } |
78 | } | 80 | } |
79 | return get(tenantId, profileId); | 81 | return get(tenantId, profileId); |
@@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | @@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | ||
392 | if (stateData != null) { | 392 | if (stateData != null) { |
393 | DeviceState state = stateData.getState(); | 393 | DeviceState state = stateData.getState(); |
394 | state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout()); | 394 | state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout()); |
395 | - if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime())) { | 395 | + if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime()) && stateData.getDeviceCreationTime() + state.getInactivityTimeout() < ts) { |
396 | state.setLastInactivityAlarmTime(ts); | 396 | state.setLastInactivityAlarmTime(ts); |
397 | pushRuleEngineMessage(stateData, INACTIVITY_EVENT); | 397 | pushRuleEngineMessage(stateData, INACTIVITY_EVENT); |
398 | save(deviceId, INACTIVITY_ALARM_TIME, ts); | 398 | save(deviceId, INACTIVITY_ALARM_TIME, ts); |
@@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | @@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | ||
479 | return DeviceStateData.builder() | 479 | return DeviceStateData.builder() |
480 | .tenantId(device.getTenantId()) | 480 | .tenantId(device.getTenantId()) |
481 | .deviceId(device.getId()) | 481 | .deviceId(device.getId()) |
482 | + .deviceCreationTime(device.getCreatedTime()) | ||
482 | .metaData(md) | 483 | .metaData(md) |
483 | .state(deviceState).build(); | 484 | .state(deviceState).build(); |
484 | } catch (Exception e) { | 485 | } catch (Exception e) { |
@@ -30,8 +30,8 @@ class DeviceStateData { | @@ -30,8 +30,8 @@ class DeviceStateData { | ||
30 | 30 | ||
31 | private final TenantId tenantId; | 31 | private final TenantId tenantId; |
32 | private final DeviceId deviceId; | 32 | private final DeviceId deviceId; |
33 | - | 33 | + private final long deviceCreationTime; |
34 | private TbMsgMetaData metaData; | 34 | private TbMsgMetaData metaData; |
35 | private final DeviceState state; | 35 | private final DeviceState state; |
36 | - | 36 | + |
37 | } | 37 | } |
@@ -65,6 +65,9 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, | @@ -65,6 +65,9 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, | ||
65 | selectDefaultProfile = false; | 65 | selectDefaultProfile = false; |
66 | 66 | ||
67 | @Input() | 67 | @Input() |
68 | + selectFirstProfile = false; | ||
69 | + | ||
70 | + @Input() | ||
68 | displayAllOnEmpty = false; | 71 | displayAllOnEmpty = false; |
69 | 72 | ||
70 | @Input() | 73 | @Input() |
@@ -183,12 +186,34 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, | @@ -183,12 +186,34 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, | ||
183 | if (this.selectDefaultProfile && !this.modelValue) { | 186 | if (this.selectDefaultProfile && !this.modelValue) { |
184 | this.deviceProfileService.getDefaultDeviceProfileInfo().subscribe( | 187 | this.deviceProfileService.getDefaultDeviceProfileInfo().subscribe( |
185 | (profile) => { | 188 | (profile) => { |
186 | - if (profile && !this.transportType || (profile.transportType === this.transportType)) { | 189 | + if (profile && (!this.transportType || (profile.transportType === this.transportType))) { |
187 | this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(profile, {emitEvent: false}); | 190 | this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(profile, {emitEvent: false}); |
188 | this.updateView(profile); | 191 | this.updateView(profile); |
192 | + } else { | ||
193 | + this.selectFirstDeviceProfileIfNeeded(); | ||
189 | } | 194 | } |
190 | } | 195 | } |
191 | ); | 196 | ); |
197 | + } else { | ||
198 | + this.selectFirstDeviceProfileIfNeeded(); | ||
199 | + } | ||
200 | + } | ||
201 | + | ||
202 | + selectFirstDeviceProfileIfNeeded(): void { | ||
203 | + if (this.selectFirstProfile && !this.modelValue) { | ||
204 | + const pageLink = new PageLink(1, 0, null, { | ||
205 | + property: 'createdTime', | ||
206 | + direction: Direction.DESC | ||
207 | + }); | ||
208 | + this.deviceProfileService.getDeviceProfileInfos(pageLink, this.transportType, {ignoreLoading: true}).subscribe( | ||
209 | + (pageData => { | ||
210 | + const data = pageData.data; | ||
211 | + if (data.length) { | ||
212 | + this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(data[0], {emitEvent: false}); | ||
213 | + this.updateView(data[0]); | ||
214 | + } | ||
215 | + }) | ||
216 | + ); | ||
192 | } | 217 | } |
193 | } | 218 | } |
194 | 219 |
@@ -79,6 +79,7 @@ | @@ -79,6 +79,7 @@ | ||
79 | (deviceProfileChanged)="$event?.transportType ? deviceWizardFormGroup.get('transportType').patchValue($event?.transportType) : {}" | 79 | (deviceProfileChanged)="$event?.transportType ? deviceWizardFormGroup.get('transportType').patchValue($event?.transportType) : {}" |
80 | [addNewProfile]="false" | 80 | [addNewProfile]="false" |
81 | [selectDefaultProfile]="true" | 81 | [selectDefaultProfile]="true" |
82 | + [selectFirstProfile]="true" | ||
82 | [editProfileEnabled]="false"> | 83 | [editProfileEnabled]="false"> |
83 | </tb-device-profile-autocomplete> | 84 | </tb-device-profile-autocomplete> |
84 | <mat-form-field fxFlex class="mat-block"> | 85 | <mat-form-field fxFlex class="mat-block"> |
@@ -794,9 +794,9 @@ | @@ -794,9 +794,9 @@ | ||
794 | "transport-type": "Transport type", | 794 | "transport-type": "Transport type", |
795 | "transport-type-required": "Transport type is required.", | 795 | "transport-type-required": "Transport type is required.", |
796 | "transport-type-default": "Default", | 796 | "transport-type-default": "Default", |
797 | - "transport-type-default-hint": "Default transport type", | 797 | + "transport-type-default-hint": "Refers to already existing transport configuration or basic MQTT, HTTP, CoAP settings", |
798 | "transport-type-mqtt": "MQTT", | 798 | "transport-type-mqtt": "MQTT", |
799 | - "transport-type-mqtt-hint": "MQTT transport type", | 799 | + "transport-type-mqtt-hint": "Advanced MQTT topic filters and Device profile settings", |
800 | "transport-type-lwm2m": "LWM2M", | 800 | "transport-type-lwm2m": "LWM2M", |
801 | "transport-type-lwm2m-hint": "LWM2M transport type", | 801 | "transport-type-lwm2m-hint": "LWM2M transport type", |
802 | "description": "Description", | 802 | "description": "Description", |