Browse Source

added default queue for device profile

pull/3652/head
YevhenBondarenko 6 years ago
committed by Andrew Shvayka
parent
commit
7724495cb1
  1. 1
      application/src/main/data/upgrade/3.1.1/schema_update_before.sql
  2. 4
      application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java
  3. 2
      common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java
  4. 5
      common/message/src/main/java/org/thingsboard/server/common/msg/TbMsg.java
  5. 1
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  6. 5
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java
  7. 1
      dao/src/main/resources/sql/schema-entities-hsql.sql
  8. 1
      dao/src/main/resources/sql/schema-entities.sql
  9. 5
      ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.html
  10. 4
      ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts
  11. 5
      ui-ngx/src/app/modules/home/components/profile/device-profile.component.html
  12. 5
      ui-ngx/src/app/modules/home/components/profile/device-profile.component.ts
  13. 7
      ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html
  14. 7
      ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts
  15. 1
      ui-ngx/src/app/shared/models/device.models.ts
  16. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

1
application/src/main/data/upgrade/3.1.1/schema_update_before.sql

@ -96,6 +96,7 @@ CREATE TABLE IF NOT EXISTS device_profile (
is_default boolean,
tenant_id uuid,
default_rule_chain_id uuid,
default_queue_name varchar(255),
provision_device_key varchar,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),

4
application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java

@ -159,6 +159,10 @@ public class DefaultTbClusterService implements TbClusterService {
if (targetRuleChainId != null && !targetRuleChainId.equals(tbMsg.getRuleChainId())) {
tbMsg = TbMsg.transformMsg(tbMsg, targetRuleChainId);
}
String targetQueueName = deviceProfile.getDefaultQueueName();
if (targetQueueName != null && !targetQueueName.equals(tbMsg.getQueueName())) {
tbMsg = TbMsg.transformMsg(tbMsg, targetQueueName);
}
}
return tbMsg;
}

2
common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java

@ -43,6 +43,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H
private DeviceTransportType transportType;
private DeviceProfileProvisionType provisionType;
private RuleChainId defaultRuleChainId;
private String defaultQueueName;
private transient DeviceProfileData profileData;
@JsonIgnore
private byte[] profileDataBytes;
@ -63,6 +64,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H
this.description = deviceProfile.getDescription();
this.isDefault = deviceProfile.isDefault();
this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId();
this.defaultQueueName = deviceProfile.getDefaultQueueName();
this.setProfileData(deviceProfile.getProfileData());
this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey();
}

5
common/message/src/main/java/org/thingsboard/server/common/msg/TbMsg.java

@ -90,6 +90,11 @@ public final class TbMsg implements Serializable {
origMsg.data, ruleChainId, null, origMsg.getCallback());
}
public static TbMsg transformMsg(TbMsg origMsg, String queueName) {
return new TbMsg(queueName, origMsg.id, origMsg.ts, origMsg.type, origMsg.originator, origMsg.metaData, origMsg.dataType,
origMsg.data, origMsg.getRuleChainId(), null, origMsg.getCallback());
}
public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
return new TbMsg(tbMsg.getQueueName(), UUID.randomUUID(), tbMsg.getTs(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(),
tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY);

1
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -174,6 +174,7 @@ public class ModelConstants {
public static final String DEVICE_PROFILE_DESCRIPTION_PROPERTY = "description";
public static final String DEVICE_PROFILE_IS_DEFAULT_PROPERTY = "is_default";
public static final String DEVICE_PROFILE_DEFAULT_RULE_CHAIN_ID_PROPERTY = "default_rule_chain_id";
public static final String DEVICE_PROFILE_DEFAULT_QUEUE_NAME_PROPERTY = "default_queue_name";
public static final String DEVICE_PROFILE_PROVISION_DEVICE_KEY = "provision_device_key";
/**

5
dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java

@ -79,6 +79,9 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
@Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_RULE_CHAIN_ID_PROPERTY, columnDefinition = "uuid")
private UUID defaultRuleChainId;
@Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_QUEUE_NAME_PROPERTY)
private String defaultQueueName;
@Type(type = "jsonb")
@Column(name = ModelConstants.DEVICE_PROFILE_PROFILE_DATA_PROPERTY, columnDefinition = "jsonb")
private JsonNode profileData;
@ -108,6 +111,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
if (deviceProfile.getDefaultRuleChainId() != null) {
this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId().getId();
}
this.defaultQueueName = deviceProfile.getDefaultQueueName();
this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey();
}
@ -142,6 +146,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> impl
if (defaultRuleChainId != null) {
deviceProfile.setDefaultRuleChainId(new RuleChainId(defaultRuleChainId));
}
deviceProfile.setDefaultQueueName(defaultQueueName);
deviceProfile.setProvisionDeviceKey(provisionDeviceKey);
return deviceProfile;
}

1
dao/src/main/resources/sql/schema-entities-hsql.sql

@ -170,6 +170,7 @@ CREATE TABLE IF NOT EXISTS device_profile (
is_default boolean,
tenant_id uuid,
default_rule_chain_id uuid,
default_queue_name varchar(255),
provision_device_key varchar,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),

1
dao/src/main/resources/sql/schema-entities.sql

@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS device_profile (
is_default boolean,
tenant_id uuid,
default_rule_chain_id uuid,
default_queue_name varchar(255),
provision_device_key varchar,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),

5
ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.html

@ -45,6 +45,11 @@
labelText="device-profile.default-rule-chain"
formControlName="defaultRuleChainId">
</tb-rule-chain-autocomplete>
<tb-queue-type-list
[queueType]="serviceType"
formControlName="defaultQueueName">
</tb-queue-type-list>
<div class="tb-hint" translate>device-profile.select-queue-hint</div>
<mat-form-field fxHide class="mat-block">
<mat-label translate>device-profile.type</mat-label>
<mat-select formControlName="type" required>

4
ui-ngx/src/app/modules/home/components/profile/add-device-profile-dialog.component.ts

@ -48,6 +48,7 @@ import { MatHorizontalStepper } from '@angular/material/stepper';
import { RuleChainId } from '@shared/models/id/rule-chain-id';
import { StepperSelectionEvent } from '@angular/cdk/stepper';
import { deepTrim } from '@core/utils';
import {ServiceType} from "@shared/models/queue.models";
export interface AddDeviceProfileDialogData {
deviceProfileName: string;
@ -89,6 +90,8 @@ export class AddDeviceProfileDialogComponent extends
provisionConfigFormGroup: FormGroup;
serviceType = ServiceType.TB_RULE_ENGINE;
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: AddDeviceProfileDialogData,
@ -104,6 +107,7 @@ export class AddDeviceProfileDialogComponent extends
name: [data.deviceProfileName, [Validators.required]],
type: [DeviceProfileType.DEFAULT, [Validators.required]],
defaultRuleChainId: [null, []],
defaultQueueName: ['', []],
description: ['', []]
}
);

5
ui-ngx/src/app/modules/home/components/profile/device-profile.component.html

@ -53,6 +53,11 @@
labelText="device-profile.default-rule-chain"
formControlName="defaultRuleChainId">
</tb-rule-chain-autocomplete>
<tb-queue-type-list
[queueType]="serviceType"
formControlName="defaultQueueName">
</tb-queue-type-list>
<div class="tb-hint" translate>device-profile.select-queue-hint</div>
<mat-form-field fxHide class="mat-block">
<mat-label translate>device-profile.type</mat-label>
<mat-select formControlName="type" required>

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

@ -38,6 +38,7 @@ import {
} from '@shared/models/device.models';
import { EntityType } from '@shared/models/entity-type.models';
import { RuleChainId } from '@shared/models/id/rule-chain-id';
import {ServiceType} from "@shared/models/queue.models";
@Component({
selector: 'tb-device-profile',
@ -63,6 +64,8 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> {
displayTransportConfiguration: boolean;
serviceType = ServiceType.TB_RULE_ENGINE;
constructor(protected store: Store<AppState>,
protected translate: TranslateService,
@Optional() @Inject('entity') protected entityValue: DeviceProfile,
@ -101,6 +104,7 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> {
provisionConfiguration: [deviceProvisionConfiguration, Validators.required]
}),
defaultRuleChainId: [entity && entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null, []],
defaultQueueName: [entity ? entity.defaultQueueName : '', []],
description: [entity ? entity.description : '', []],
}
);
@ -174,6 +178,7 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> {
provisionConfiguration: deviceProvisionConfiguration
}});
this.entityForm.patchValue({defaultRuleChainId: entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null});
this.entityForm.patchValue({defaultQueueName: entity.defaultQueueName});
this.entityForm.patchValue({description: entity.description});
}

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

@ -97,6 +97,13 @@
formControlName="defaultRuleChainId">
</tb-rule-chain-autocomplete>
</div>
<div fxLayout="column" fxLayoutAlign="flex-end start">
<tb-queue-type-list
[queueType]="serviceType"
formControlName="defaultQueueName">
</tb-queue-type-list>
<div class="tb-hint" translate>device-profile.select-queue-hint</div>
</div>
</div>
<mat-checkbox formControlName="gateway" style="padding-bottom: 16px;">
{{ 'device.is-gateway' | translate }}

7
ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.ts

@ -43,6 +43,7 @@ import { StepperSelectionEvent } from '@angular/cdk/stepper';
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
import { MediaBreakpoints } from '@shared/models/constants';
import { RuleChainId } from '@shared/models/id/rule-chain-id';
import {ServiceType} from "@shared/models/queue.models";
@Component({
selector: 'tb-device-wizard',
@ -84,6 +85,8 @@ export class DeviceWizardDialogComponent extends
labelPosition = 'end';
serviceType = ServiceType.TB_RULE_ENGINE;
private subscriptions: Subscription[] = [];
constructor(protected store: Store<AppState>,
@ -105,6 +108,7 @@ export class DeviceWizardDialogComponent extends
deviceProfileId: [null, Validators.required],
newDeviceProfileTitle: [{value: null, disabled: true}],
defaultRuleChainId: [{value: null, disabled: true}],
defaultQueueName: [''],
description: ['']
}
);
@ -117,6 +121,7 @@ export class DeviceWizardDialogComponent extends
this.deviceWizardFormGroup.get('newDeviceProfileTitle').setValidators(null);
this.deviceWizardFormGroup.get('newDeviceProfileTitle').disable();
this.deviceWizardFormGroup.get('defaultRuleChainId').disable();
this.deviceWizardFormGroup.get('defaultQueueName').disable();
this.deviceWizardFormGroup.updateValueAndValidity();
this.createProfile = false;
this.createTransportConfiguration = false;
@ -126,6 +131,8 @@ export class DeviceWizardDialogComponent extends
this.deviceWizardFormGroup.get('newDeviceProfileTitle').setValidators([Validators.required]);
this.deviceWizardFormGroup.get('newDeviceProfileTitle').enable();
this.deviceWizardFormGroup.get('defaultRuleChainId').enable();
this.deviceWizardFormGroup.get('defaultQueueName').enable();
this.deviceWizardFormGroup.updateValueAndValidity();
this.createProfile = true;
this.createTransportConfiguration = this.deviceWizardFormGroup.get('transportType').value &&

1
ui-ngx/src/app/shared/models/device.models.ts

@ -369,6 +369,7 @@ export interface DeviceProfile extends BaseData<DeviceProfileId> {
provisionType: DeviceProvisionType;
provisionDeviceKey?: string;
defaultRuleChainId?: RuleChainId;
defaultQueueName?: string;
profileData: DeviceProfileData;
}

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

@ -872,6 +872,7 @@
"profile-configuration": "Profile configuration",
"transport-configuration": "Transport configuration",
"default-rule-chain": "Default rule chain",
"select-queue-hint": "The queue name can be selected from a drop-down list or add a custom name.",
"delete-device-profile-title": "Are you sure you want to delete the device profile '{{deviceProfileName}}'?",
"delete-device-profile-text": "Be careful, after the confirmation the device profile and all related data will become unrecoverable.",
"delete-device-profiles-title": "Are you sure you want to delete { count, plural, 1 {1 device profile} other {# device profiles} }?",

Loading…
Cancel
Save