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 | 20 | import io.netty.channel.EventLoopGroup; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
22 | 22 | import org.springframework.data.redis.core.RedisTemplate; |
23 | +import org.springframework.util.StringUtils; | |
23 | 24 | import org.thingsboard.common.util.ListeningExecutor; |
24 | 25 | import org.thingsboard.rule.engine.api.MailService; |
25 | 26 | import org.thingsboard.rule.engine.api.RuleEngineAlarmService; |
... | ... | @@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.rule.RuleNodeState; |
47 | 48 | import org.thingsboard.server.common.msg.TbActorMsg; |
48 | 49 | import org.thingsboard.server.common.msg.TbMsg; |
49 | 50 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
51 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; | |
50 | 52 | import org.thingsboard.server.common.msg.queue.ServiceType; |
51 | 53 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
52 | 54 | import org.thingsboard.server.dao.asset.AssetService; |
... | ... | @@ -183,6 +185,9 @@ class DefaultTbContext implements TbContext { |
183 | 185 | } |
184 | 186 | |
185 | 187 | private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) { |
188 | + if (StringUtils.isEmpty(queueName)) { | |
189 | + queueName = ServiceQueue.MAIN; | |
190 | + } | |
186 | 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 | 74 | if (device != null) { |
75 | 75 | profileId = device.getDeviceProfileId(); |
76 | 76 | devicesMap.put(deviceId, profileId); |
77 | + } else { | |
78 | + return null; | |
77 | 79 | } |
78 | 80 | } |
79 | 81 | return get(tenantId, profileId); | ... | ... |
... | ... | @@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService { |
392 | 392 | if (stateData != null) { |
393 | 393 | DeviceState state = stateData.getState(); |
394 | 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 | 396 | state.setLastInactivityAlarmTime(ts); |
397 | 397 | pushRuleEngineMessage(stateData, INACTIVITY_EVENT); |
398 | 398 | save(deviceId, INACTIVITY_ALARM_TIME, ts); |
... | ... | @@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService { |
479 | 479 | return DeviceStateData.builder() |
480 | 480 | .tenantId(device.getTenantId()) |
481 | 481 | .deviceId(device.getId()) |
482 | + .deviceCreationTime(device.getCreatedTime()) | |
482 | 483 | .metaData(md) |
483 | 484 | .state(deviceState).build(); |
484 | 485 | } catch (Exception e) { | ... | ... |
... | ... | @@ -65,6 +65,9 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, |
65 | 65 | selectDefaultProfile = false; |
66 | 66 | |
67 | 67 | @Input() |
68 | + selectFirstProfile = false; | |
69 | + | |
70 | + @Input() | |
68 | 71 | displayAllOnEmpty = false; |
69 | 72 | |
70 | 73 | @Input() |
... | ... | @@ -183,12 +186,34 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, |
183 | 186 | if (this.selectDefaultProfile && !this.modelValue) { |
184 | 187 | this.deviceProfileService.getDefaultDeviceProfileInfo().subscribe( |
185 | 188 | (profile) => { |
186 | - if (profile && !this.transportType || (profile.transportType === this.transportType)) { | |
189 | + if (profile && (!this.transportType || (profile.transportType === this.transportType))) { | |
187 | 190 | this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(profile, {emitEvent: false}); |
188 | 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 | 79 | (deviceProfileChanged)="$event?.transportType ? deviceWizardFormGroup.get('transportType').patchValue($event?.transportType) : {}" |
80 | 80 | [addNewProfile]="false" |
81 | 81 | [selectDefaultProfile]="true" |
82 | + [selectFirstProfile]="true" | |
82 | 83 | [editProfileEnabled]="false"> |
83 | 84 | </tb-device-profile-autocomplete> |
84 | 85 | <mat-form-field fxFlex class="mat-block"> | ... | ... |
... | ... | @@ -794,9 +794,9 @@ |
794 | 794 | "transport-type": "Transport type", |
795 | 795 | "transport-type-required": "Transport type is required.", |
796 | 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 | 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 | 800 | "transport-type-lwm2m": "LWM2M", |
801 | 801 | "transport-type-lwm2m-hint": "LWM2M transport type", |
802 | 802 | "description": "Description", | ... | ... |