diff --git a/application/src/main/data/upgrade/3.3.4/schema_update.sql b/application/src/main/data/upgrade/3.3.4/schema_update.sql index 69df2afdc9..edd57775a9 100644 --- a/application/src/main/data/upgrade/3.3.4/schema_update.sql +++ b/application/src/main/data/upgrade/3.3.4/schema_update.sql @@ -70,3 +70,4 @@ CREATE TABLE IF NOT EXISTS user_auth_settings ( two_fa_settings varchar ); +CREATE INDEX IF NOT EXISTS idx_api_usage_state_entity_id ON api_usage_state(entity_id); diff --git a/application/src/main/java/org/thingsboard/server/controller/QueueController.java b/application/src/main/java/org/thingsboard/server/controller/QueueController.java index 644bee9ff0..0f29ced288 100644 --- a/application/src/main/java/org/thingsboard/server/controller/QueueController.java +++ b/application/src/main/java/org/thingsboard/server/controller/QueueController.java @@ -75,6 +75,14 @@ public class QueueController extends BaseController { return checkNotNull(queueService.findQueueById(getTenantId(), queueId)); } + @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") + @RequestMapping(value = "/queues/name/{queueName}", method = RequestMethod.GET) + @ResponseBody + public Queue getQueueByName(@PathVariable("queueName") String queueName) throws ThingsboardException { + checkParameter("queueName", queueName); + return checkNotNull(queueService.findQueueByTenantIdAndName(getTenantId(), queueName)); + } + @PreAuthorize("hasAnyAuthority('SYS_ADMIN')") @RequestMapping(value = "/queues", params = {"serviceType"}, method = RequestMethod.POST) @ResponseBody diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java b/common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java index e087ba0b7c..eb2881e63e 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java @@ -74,12 +74,13 @@ public class DeviceProfile extends SearchTextBased implements H private RuleChainId defaultRuleChainId; @ApiModelProperty(position = 6, value = "Reference to the dashboard. Used in the mobile application to open the default dashboard when user navigates to device details.") private DashboardId defaultDashboardId; + + @JsonIgnore + private QueueId defaultQueueId; @NoXss - @ApiModelProperty(position = 8, value = "Reference to the rule engine queue. " + + @ApiModelProperty(position = 8, value = "Rule engine queue name. " + "If present, the specified queue will be used to store all unprocessed messages related to device, including telemetry, attribute updates, etc. " + "Otherwise, the 'Main' queue will be used to store those messages.") - private QueueId defaultQueueId; - private String defaultQueueName; @Valid private transient DeviceProfileData profileData; @@ -114,6 +115,7 @@ public class DeviceProfile extends SearchTextBased implements H this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId(); this.defaultDashboardId = deviceProfile.getDefaultDashboardId(); this.defaultQueueId = deviceProfile.getDefaultQueueId(); + this.defaultQueueName = deviceProfile.getDefaultQueueName(); this.setProfileData(deviceProfile.getProfileData()); this.provisionDeviceKey = deviceProfile.getProvisionDeviceKey(); this.firmwareId = deviceProfile.getFirmwareId(); @@ -174,13 +176,4 @@ public class DeviceProfile extends SearchTextBased implements H } } - @JsonIgnore - public String getDefaultQueueName() { - return defaultQueueName; - } - - @JsonProperty - public void setDefaultQueueName(String defaultQueueName) { - this.defaultQueueName = defaultQueueName; - } } diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java index a6cfa33fb8..4cc019a206 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java @@ -120,7 +120,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService impl @Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_QUEUE_ID_PROPERTY) private UUID defaultQueueId; + @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; @@ -133,6 +136,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity impl if (deviceProfile.getDefaultDashboardId() != null) { this.defaultDashboardId = deviceProfile.getDefaultDashboardId().getId(); } + this.defaultQueueName = deviceProfile.getDefaultQueueName(); if (deviceProfile.getDefaultQueueId() != null) { this.defaultQueueId = deviceProfile.getDefaultQueueId().getId(); } @@ -176,6 +180,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity impl deviceProfile.setProvisionType(provisionType); deviceProfile.setDescription(description); deviceProfile.setDefault(isDefault); + deviceProfile.setDefaultQueueName(defaultQueueName); deviceProfile.setProfileData(JacksonUtil.convertValue(profileData, DeviceProfileData.class)); if (defaultRuleChainId != null) { deviceProfile.setDefaultRuleChainId(new RuleChainId(defaultRuleChainId)); @@ -191,7 +196,6 @@ public final class DeviceProfileEntity extends BaseSqlEntity impl if (firmwareId != null) { deviceProfile.setFirmwareId(new OtaPackageId(firmwareId)); } - if (softwareId != null) { deviceProfile.setSoftwareId(new OtaPackageId(softwareId)); } diff --git a/dao/src/main/resources/sql/schema-entities-idx.sql b/dao/src/main/resources/sql/schema-entities-idx.sql index d4537a700d..80a5b03b92 100644 --- a/dao/src/main/resources/sql/schema-entities-idx.sql +++ b/dao/src/main/resources/sql/schema-entities-idx.sql @@ -70,4 +70,6 @@ CREATE INDEX IF NOT EXISTS idx_widgets_bundle_external_id ON widgets_bundle(tena CREATE INDEX IF NOT EXISTS idx_rule_node_external_id ON rule_node(rule_chain_id, external_id); -CREATE INDEX IF NOT EXISTS idx_rule_node_type ON rule_node(type); \ No newline at end of file +CREATE INDEX IF NOT EXISTS idx_rule_node_type ON rule_node(type); + +CREATE INDEX IF NOT EXISTS idx_api_usage_state_entity_id ON api_usage_state(entity_id); diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 953276cbee..d3dabca331 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -254,6 +254,7 @@ CREATE TABLE IF NOT EXISTS device_profile ( default_rule_chain_id uuid, default_dashboard_id uuid, default_queue_id uuid, + default_queue_name varchar(255), provision_device_key varchar, external_id uuid, CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/flow/TbCheckpointNodeConfiguration.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/flow/TbCheckpointNodeConfiguration.java index 42bd6342c9..879c7e1df7 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/flow/TbCheckpointNodeConfiguration.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/flow/TbCheckpointNodeConfiguration.java @@ -22,7 +22,7 @@ import org.thingsboard.server.common.data.id.QueueId; @Data public class TbCheckpointNodeConfiguration implements NodeConfiguration { - private String queueId; + private String queueName; @Override public TbCheckpointNodeConfiguration defaultConfiguration() {