Commit 7724495cb12530a45e64761c5cb66b908686237f
Committed by
Andrew Shvayka
1 parent
461da688
added default queue for device profile
Showing
16 changed files
with
55 additions
and
0 deletions
... | ... | @@ -96,6 +96,7 @@ CREATE TABLE IF NOT EXISTS device_profile ( |
96 | 96 | is_default boolean, |
97 | 97 | tenant_id uuid, |
98 | 98 | default_rule_chain_id uuid, |
99 | + default_queue_name varchar(255), | |
99 | 100 | provision_device_key varchar, |
100 | 101 | CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), |
101 | 102 | CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key), | ... | ... |
... | ... | @@ -159,6 +159,10 @@ public class DefaultTbClusterService implements TbClusterService { |
159 | 159 | if (targetRuleChainId != null && !targetRuleChainId.equals(tbMsg.getRuleChainId())) { |
160 | 160 | tbMsg = TbMsg.transformMsg(tbMsg, targetRuleChainId); |
161 | 161 | } |
162 | + String targetQueueName = deviceProfile.getDefaultQueueName(); | |
163 | + if (targetQueueName != null && !targetQueueName.equals(tbMsg.getQueueName())) { | |
164 | + tbMsg = TbMsg.transformMsg(tbMsg, targetQueueName); | |
165 | + } | |
162 | 166 | } |
163 | 167 | return tbMsg; |
164 | 168 | } | ... | ... |
... | ... | @@ -43,6 +43,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H |
43 | 43 | private DeviceTransportType transportType; |
44 | 44 | private DeviceProfileProvisionType provisionType; |
45 | 45 | private RuleChainId defaultRuleChainId; |
46 | + private String defaultQueueName; | |
46 | 47 | private transient DeviceProfileData profileData; |
47 | 48 | @JsonIgnore |
48 | 49 | private byte[] profileDataBytes; |
... | ... | @@ -63,6 +64,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H |
63 | 64 | this.description = deviceProfile.getDescription(); |
64 | 65 | this.isDefault = deviceProfile.isDefault(); |
65 | 66 | this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId(); |
67 | + this.defaultQueueName = deviceProfile.getDefaultQueueName(); | |
66 | 68 | this.setProfileData(deviceProfile.getProfileData()); |
67 | 69 | this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey(); |
68 | 70 | } | ... | ... |
... | ... | @@ -90,6 +90,11 @@ public final class TbMsg implements Serializable { |
90 | 90 | origMsg.data, ruleChainId, null, origMsg.getCallback()); |
91 | 91 | } |
92 | 92 | |
93 | + public static TbMsg transformMsg(TbMsg origMsg, String queueName) { | |
94 | + return new TbMsg(queueName, origMsg.id, origMsg.ts, origMsg.type, origMsg.originator, origMsg.metaData, origMsg.dataType, | |
95 | + origMsg.data, origMsg.getRuleChainId(), null, origMsg.getCallback()); | |
96 | + } | |
97 | + | |
93 | 98 | public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) { |
94 | 99 | return new TbMsg(tbMsg.getQueueName(), UUID.randomUUID(), tbMsg.getTs(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(), |
95 | 100 | tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); | ... | ... |
... | ... | @@ -174,6 +174,7 @@ public class ModelConstants { |
174 | 174 | public static final String DEVICE_PROFILE_DESCRIPTION_PROPERTY = "description"; |
175 | 175 | public static final String DEVICE_PROFILE_IS_DEFAULT_PROPERTY = "is_default"; |
176 | 176 | public static final String DEVICE_PROFILE_DEFAULT_RULE_CHAIN_ID_PROPERTY = "default_rule_chain_id"; |
177 | + public static final String DEVICE_PROFILE_DEFAULT_QUEUE_NAME_PROPERTY = "default_queue_name"; | |
177 | 178 | public static final String DEVICE_PROFILE_PROVISION_DEVICE_KEY = "provision_device_key"; |
178 | 179 | |
179 | 180 | /** | ... | ... |
... | ... | @@ -79,6 +79,9 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl |
79 | 79 | @Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_RULE_CHAIN_ID_PROPERTY, columnDefinition = "uuid") |
80 | 80 | private UUID defaultRuleChainId; |
81 | 81 | |
82 | + @Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_QUEUE_NAME_PROPERTY) | |
83 | + private String defaultQueueName; | |
84 | + | |
82 | 85 | @Type(type = "jsonb") |
83 | 86 | @Column(name = ModelConstants.DEVICE_PROFILE_PROFILE_DATA_PROPERTY, columnDefinition = "jsonb") |
84 | 87 | private JsonNode profileData; |
... | ... | @@ -108,6 +111,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl |
108 | 111 | if (deviceProfile.getDefaultRuleChainId() != null) { |
109 | 112 | this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId().getId(); |
110 | 113 | } |
114 | + this.defaultQueueName = deviceProfile.getDefaultQueueName(); | |
111 | 115 | this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey(); |
112 | 116 | } |
113 | 117 | |
... | ... | @@ -142,6 +146,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl |
142 | 146 | if (defaultRuleChainId != null) { |
143 | 147 | deviceProfile.setDefaultRuleChainId(new RuleChainId(defaultRuleChainId)); |
144 | 148 | } |
149 | + deviceProfile.setDefaultQueueName(defaultQueueName); | |
145 | 150 | deviceProfile.setProvisionDeviceKey(provisionDeviceKey); |
146 | 151 | return deviceProfile; |
147 | 152 | } | ... | ... |
... | ... | @@ -170,6 +170,7 @@ CREATE TABLE IF NOT EXISTS device_profile ( |
170 | 170 | is_default boolean, |
171 | 171 | tenant_id uuid, |
172 | 172 | default_rule_chain_id uuid, |
173 | + default_queue_name varchar(255), | |
173 | 174 | provision_device_key varchar, |
174 | 175 | CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), |
175 | 176 | CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key), | ... | ... |
... | ... | @@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS device_profile ( |
188 | 188 | is_default boolean, |
189 | 189 | tenant_id uuid, |
190 | 190 | default_rule_chain_id uuid, |
191 | + default_queue_name varchar(255), | |
191 | 192 | provision_device_key varchar, |
192 | 193 | CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), |
193 | 194 | CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key), | ... | ... |
... | ... | @@ -45,6 +45,11 @@ |
45 | 45 | labelText="device-profile.default-rule-chain" |
46 | 46 | formControlName="defaultRuleChainId"> |
47 | 47 | </tb-rule-chain-autocomplete> |
48 | + <tb-queue-type-list | |
49 | + [queueType]="serviceType" | |
50 | + formControlName="defaultQueueName"> | |
51 | + </tb-queue-type-list> | |
52 | + <div class="tb-hint" translate>device-profile.select-queue-hint</div> | |
48 | 53 | <mat-form-field fxHide class="mat-block"> |
49 | 54 | <mat-label translate>device-profile.type</mat-label> |
50 | 55 | <mat-select formControlName="type" required> | ... | ... |
... | ... | @@ -48,6 +48,7 @@ import { MatHorizontalStepper } from '@angular/material/stepper'; |
48 | 48 | import { RuleChainId } from '@shared/models/id/rule-chain-id'; |
49 | 49 | import { StepperSelectionEvent } from '@angular/cdk/stepper'; |
50 | 50 | import { deepTrim } from '@core/utils'; |
51 | +import {ServiceType} from "@shared/models/queue.models"; | |
51 | 52 | |
52 | 53 | export interface AddDeviceProfileDialogData { |
53 | 54 | deviceProfileName: string; |
... | ... | @@ -89,6 +90,8 @@ export class AddDeviceProfileDialogComponent extends |
89 | 90 | |
90 | 91 | provisionConfigFormGroup: FormGroup; |
91 | 92 | |
93 | + serviceType = ServiceType.TB_RULE_ENGINE; | |
94 | + | |
92 | 95 | constructor(protected store: Store<AppState>, |
93 | 96 | protected router: Router, |
94 | 97 | @Inject(MAT_DIALOG_DATA) public data: AddDeviceProfileDialogData, |
... | ... | @@ -104,6 +107,7 @@ export class AddDeviceProfileDialogComponent extends |
104 | 107 | name: [data.deviceProfileName, [Validators.required]], |
105 | 108 | type: [DeviceProfileType.DEFAULT, [Validators.required]], |
106 | 109 | defaultRuleChainId: [null, []], |
110 | + defaultQueueName: ['', []], | |
107 | 111 | description: ['', []] |
108 | 112 | } |
109 | 113 | ); | ... | ... |
... | ... | @@ -53,6 +53,11 @@ |
53 | 53 | labelText="device-profile.default-rule-chain" |
54 | 54 | formControlName="defaultRuleChainId"> |
55 | 55 | </tb-rule-chain-autocomplete> |
56 | + <tb-queue-type-list | |
57 | + [queueType]="serviceType" | |
58 | + formControlName="defaultQueueName"> | |
59 | + </tb-queue-type-list> | |
60 | + <div class="tb-hint" translate>device-profile.select-queue-hint</div> | |
56 | 61 | <mat-form-field fxHide class="mat-block"> |
57 | 62 | <mat-label translate>device-profile.type</mat-label> |
58 | 63 | <mat-select formControlName="type" required> | ... | ... |
... | ... | @@ -38,6 +38,7 @@ import { |
38 | 38 | } from '@shared/models/device.models'; |
39 | 39 | import { EntityType } from '@shared/models/entity-type.models'; |
40 | 40 | import { RuleChainId } from '@shared/models/id/rule-chain-id'; |
41 | +import {ServiceType} from "@shared/models/queue.models"; | |
41 | 42 | |
42 | 43 | @Component({ |
43 | 44 | selector: 'tb-device-profile', |
... | ... | @@ -63,6 +64,8 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> { |
63 | 64 | |
64 | 65 | displayTransportConfiguration: boolean; |
65 | 66 | |
67 | + serviceType = ServiceType.TB_RULE_ENGINE; | |
68 | + | |
66 | 69 | constructor(protected store: Store<AppState>, |
67 | 70 | protected translate: TranslateService, |
68 | 71 | @Optional() @Inject('entity') protected entityValue: DeviceProfile, |
... | ... | @@ -101,6 +104,7 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> { |
101 | 104 | provisionConfiguration: [deviceProvisionConfiguration, Validators.required] |
102 | 105 | }), |
103 | 106 | defaultRuleChainId: [entity && entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null, []], |
107 | + defaultQueueName: [entity ? entity.defaultQueueName : '', []], | |
104 | 108 | description: [entity ? entity.description : '', []], |
105 | 109 | } |
106 | 110 | ); |
... | ... | @@ -174,6 +178,7 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> { |
174 | 178 | provisionConfiguration: deviceProvisionConfiguration |
175 | 179 | }}); |
176 | 180 | this.entityForm.patchValue({defaultRuleChainId: entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null}); |
181 | + this.entityForm.patchValue({defaultQueueName: entity.defaultQueueName}); | |
177 | 182 | this.entityForm.patchValue({description: entity.description}); |
178 | 183 | } |
179 | 184 | ... | ... |
... | ... | @@ -97,6 +97,13 @@ |
97 | 97 | formControlName="defaultRuleChainId"> |
98 | 98 | </tb-rule-chain-autocomplete> |
99 | 99 | </div> |
100 | + <div fxLayout="column" fxLayoutAlign="flex-end start"> | |
101 | + <tb-queue-type-list | |
102 | + [queueType]="serviceType" | |
103 | + formControlName="defaultQueueName"> | |
104 | + </tb-queue-type-list> | |
105 | + <div class="tb-hint" translate>device-profile.select-queue-hint</div> | |
106 | + </div> | |
100 | 107 | </div> |
101 | 108 | <mat-checkbox formControlName="gateway" style="padding-bottom: 16px;"> |
102 | 109 | {{ 'device.is-gateway' | translate }} | ... | ... |
... | ... | @@ -43,6 +43,7 @@ import { StepperSelectionEvent } from '@angular/cdk/stepper'; |
43 | 43 | import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout'; |
44 | 44 | import { MediaBreakpoints } from '@shared/models/constants'; |
45 | 45 | import { RuleChainId } from '@shared/models/id/rule-chain-id'; |
46 | +import {ServiceType} from "@shared/models/queue.models"; | |
46 | 47 | |
47 | 48 | @Component({ |
48 | 49 | selector: 'tb-device-wizard', |
... | ... | @@ -84,6 +85,8 @@ export class DeviceWizardDialogComponent extends |
84 | 85 | |
85 | 86 | labelPosition = 'end'; |
86 | 87 | |
88 | + serviceType = ServiceType.TB_RULE_ENGINE; | |
89 | + | |
87 | 90 | private subscriptions: Subscription[] = []; |
88 | 91 | |
89 | 92 | constructor(protected store: Store<AppState>, |
... | ... | @@ -105,6 +108,7 @@ export class DeviceWizardDialogComponent extends |
105 | 108 | deviceProfileId: [null, Validators.required], |
106 | 109 | newDeviceProfileTitle: [{value: null, disabled: true}], |
107 | 110 | defaultRuleChainId: [{value: null, disabled: true}], |
111 | + defaultQueueName: [''], | |
108 | 112 | description: [''] |
109 | 113 | } |
110 | 114 | ); |
... | ... | @@ -117,6 +121,7 @@ export class DeviceWizardDialogComponent extends |
117 | 121 | this.deviceWizardFormGroup.get('newDeviceProfileTitle').setValidators(null); |
118 | 122 | this.deviceWizardFormGroup.get('newDeviceProfileTitle').disable(); |
119 | 123 | this.deviceWizardFormGroup.get('defaultRuleChainId').disable(); |
124 | + this.deviceWizardFormGroup.get('defaultQueueName').disable(); | |
120 | 125 | this.deviceWizardFormGroup.updateValueAndValidity(); |
121 | 126 | this.createProfile = false; |
122 | 127 | this.createTransportConfiguration = false; |
... | ... | @@ -126,6 +131,8 @@ export class DeviceWizardDialogComponent extends |
126 | 131 | this.deviceWizardFormGroup.get('newDeviceProfileTitle').setValidators([Validators.required]); |
127 | 132 | this.deviceWizardFormGroup.get('newDeviceProfileTitle').enable(); |
128 | 133 | this.deviceWizardFormGroup.get('defaultRuleChainId').enable(); |
134 | + this.deviceWizardFormGroup.get('defaultQueueName').enable(); | |
135 | + | |
129 | 136 | this.deviceWizardFormGroup.updateValueAndValidity(); |
130 | 137 | this.createProfile = true; |
131 | 138 | this.createTransportConfiguration = this.deviceWizardFormGroup.get('transportType').value && | ... | ... |
... | ... | @@ -369,6 +369,7 @@ export interface DeviceProfile extends BaseData<DeviceProfileId> { |
369 | 369 | provisionType: DeviceProvisionType; |
370 | 370 | provisionDeviceKey?: string; |
371 | 371 | defaultRuleChainId?: RuleChainId; |
372 | + defaultQueueName?: string; | |
372 | 373 | profileData: DeviceProfileData; |
373 | 374 | } |
374 | 375 | ... | ... |
... | ... | @@ -872,6 +872,7 @@ |
872 | 872 | "profile-configuration": "Profile configuration", |
873 | 873 | "transport-configuration": "Transport configuration", |
874 | 874 | "default-rule-chain": "Default rule chain", |
875 | + "select-queue-hint": "The queue name can be selected from a drop-down list or add a custom name.", | |
875 | 876 | "delete-device-profile-title": "Are you sure you want to delete the device profile '{{deviceProfileName}}'?", |
876 | 877 | "delete-device-profile-text": "Be careful, after the confirmation the device profile and all related data will become unrecoverable.", |
877 | 878 | "delete-device-profiles-title": "Are you sure you want to delete { count, plural, 1 {1 device profile} other {# device profiles} }?", | ... | ... |