diff --git a/application/src/main/data/upgrade/2.4.0/schema_update.cql b/application/src/main/data/upgrade/2.4.0/schema_update.cql new file mode 100644 index 0000000000..3cf2308f7b --- /dev/null +++ b/application/src/main/data/upgrade/2.4.0/schema_update.cql @@ -0,0 +1,23 @@ +-- +-- Copyright © 2016-2019 The Thingsboard Authors +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +ALTER TABLE thingsboard.device ADD label text; diff --git a/application/src/main/data/upgrade/2.4.0/schema_update.sql b/application/src/main/data/upgrade/2.4.0/schema_update.sql new file mode 100644 index 0000000000..ab4ae4d804 --- /dev/null +++ b/application/src/main/data/upgrade/2.4.0/schema_update.sql @@ -0,0 +1,17 @@ +-- +-- Copyright © 2016-2019 The Thingsboard Authors +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +ALTER TABLE device ADD COLUMN label varchar(255); diff --git a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java index 66f8c24424..93449be05f 100644 --- a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java +++ b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java @@ -111,6 +111,11 @@ public class ThingsboardInstallService { databaseUpgradeService.upgradeDatabase("2.3.0"); + case "2.3.1": + log.info("Upgrading ThingsBoard from version 2.3.1 to 2.4.0 ..."); + + databaseUpgradeService.upgradeDatabase("2.3.1"); + log.info("Updating system data..."); systemDataLoaderService.deleteSystemWidgetBundle("charts"); @@ -127,6 +132,7 @@ public class ThingsboardInstallService { systemDataLoaderService.deleteSystemWidgetBundle("date"); systemDataLoaderService.loadSystemWidgets(); + break; default: throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion); diff --git a/application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java index 1bab31d9e0..fd495fc4a2 100644 --- a/application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java +++ b/application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java @@ -257,6 +257,12 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService { break; case "2.3.0": break; + case "2.3.1": + log.info("Updating schema ..."); + schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_CQL); + loadCql(schemaUpdateFile); + log.info("Schema updated."); + break; default: throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion); } diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java index 5e4dc7537b..816852222f 100644 --- a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java +++ b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java @@ -165,6 +165,14 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService { log.info("Schema updated."); } break; + case "2.3.1": + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { + log.info("Updating schema ..."); + schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL); + loadSql(schemaUpdateFile, conn); + log.info("Schema updated."); + } + break; default: throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/Device.java b/common/data/src/main/java/org/thingsboard/server/common/data/Device.java index 49d9690e9e..971a5568d4 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/Device.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/Device.java @@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.TenantId; -import com.fasterxml.jackson.databind.JsonNode; - @EqualsAndHashCode(callSuper = true) public class Device extends SearchTextBasedWithAdditionalInfo implements HasName, HasTenantId, HasCustomerId { @@ -31,6 +29,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen private CustomerId customerId; private String name; private String type; + private String label; public Device() { super(); @@ -46,6 +45,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen this.customerId = device.getCustomerId(); this.name = device.getName(); this.type = device.getType(); + this.label = device.getLabel(); } public TenantId getTenantId() { @@ -81,6 +81,14 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen this.type = type; } + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + @Override public String getSearchText() { return getName(); @@ -97,6 +105,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen builder.append(name); builder.append(", type="); builder.append(type); + builder.append(", label="); + builder.append(label); builder.append(", additionalInfo="); builder.append(getAdditionalInfo()); builder.append(", createdTime="); diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java index 95638e45c6..d9cb365a14 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java @@ -134,6 +134,7 @@ public class ModelConstants { public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; public static final String DEVICE_NAME_PROPERTY = "name"; public static final String DEVICE_TYPE_PROPERTY = "type"; + public static final String DEVICE_LABEL_PROPERTY = "label"; public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; public static final String DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_and_search_text"; public static final String DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_by_type_and_search_text"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java index b901b9e19b..2c44cf3d87 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java @@ -31,14 +31,7 @@ import org.thingsboard.server.dao.model.type.JsonCodec; import java.util.UUID; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_COLUMN_FAMILY_NAME; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_NAME_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TENANT_ID_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; +import static org.thingsboard.server.dao.model.ModelConstants.*; @Table(name = DEVICE_COLUMN_FAMILY_NAME) @EqualsAndHashCode @@ -64,6 +57,9 @@ public final class DeviceEntity implements SearchTextEntity { @Column(name = DEVICE_NAME_PROPERTY) private String name; + @Column(name = DEVICE_LABEL_PROPERTY) + private String label; + @Column(name = SEARCH_TEXT_PROPERTY) private String searchText; @@ -86,6 +82,7 @@ public final class DeviceEntity implements SearchTextEntity { } this.name = device.getName(); this.type = device.getType(); + this.label = device.getLabel(); this.additionalInfo = device.getAdditionalInfo(); } @@ -163,6 +160,7 @@ public final class DeviceEntity implements SearchTextEntity { } device.setName(name); device.setType(type); + device.setLabel(label); device.setAdditionalInfo(additionalInfo); return device; } diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java index c98ae01b8e..66feed0077 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java @@ -53,6 +53,9 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) private String name; + @Column(name = ModelConstants.DEVICE_LABEL_PROPERTY) + private String label; + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) private String searchText; @@ -76,6 +79,7 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT } this.name = device.getName(); this.type = device.getType(); + this.label = device.getLabel(); this.additionalInfo = device.getAdditionalInfo(); } @@ -101,6 +105,7 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT } device.setName(name); device.setType(type); + device.setLabel(label); device.setAdditionalInfo(additionalInfo); return device; } diff --git a/dao/src/main/resources/cassandra/schema-entities.cql b/dao/src/main/resources/cassandra/schema-entities.cql index 897bd6ad50..611c08d5ef 100644 --- a/dao/src/main/resources/cassandra/schema-entities.cql +++ b/dao/src/main/resources/cassandra/schema-entities.cql @@ -157,6 +157,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.device ( customer_id timeuuid, name text, type text, + label text, search_text text, additional_info text, PRIMARY KEY (id, tenant_id, customer_id, type) diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 16099e18bc..2903ca2fb1 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -117,6 +117,7 @@ CREATE TABLE IF NOT EXISTS device ( customer_id varchar(31), type varchar(255), name varchar(255), + label varchar(255), search_text varchar(255), tenant_id varchar(31) ); diff --git a/ui/src/app/api/alias-controller.js b/ui/src/app/api/alias-controller.js index 824ccfa3eb..b038e04448 100644 --- a/ui/src/app/api/alias-controller.js +++ b/ui/src/app/api/alias-controller.js @@ -151,7 +151,8 @@ export default class AliasController { newDatasource.entityId = resolvedEntity.id; newDatasource.entityType = resolvedEntity.entityType; newDatasource.entityName = resolvedEntity.name; - newDatasource.entityDescription = resolvedEntity.entityDescription + newDatasource.entityLabel = resolvedEntity.label; + newDatasource.entityDescription = resolvedEntity.entityDescription; newDatasource.name = resolvedEntity.name; newDatasource.generated = i > 0 ? true : false; datasources.push(newDatasource); @@ -177,6 +178,7 @@ export default class AliasController { datasource.entityId = entity.id; datasource.entityType = entity.entityType; datasource.entityName = entity.name; + datasource.entityLabel = entity.label; datasource.name = entity.name; datasource.entityDescription = entity.entityDescription; deferred.resolve([datasource]); diff --git a/ui/src/app/api/entity.service.js b/ui/src/app/api/entity.service.js index 6cadc1ca25..f39615c933 100644 --- a/ui/src/app/api/entity.service.js +++ b/ui/src/app/api/entity.service.js @@ -345,7 +345,14 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device } function entityToEntityInfo(entity) { - return { origEntity: entity, name: entity.name, entityType: entity.id.entityType, id: entity.id.id, entityDescription: entity.additionalInfo?entity.additionalInfo.description:"" }; + return { + origEntity: entity, + name: entity.name, + label: entity.label?entity.label:"", + entityType: entity.id.entityType, + id: entity.id.id, + entityDescription: entity.additionalInfo?entity.additionalInfo.description:"" + }; } function entityRelationInfoToEntityInfo(entityRelationInfo, direction) { diff --git a/ui/src/app/common/utils.service.js b/ui/src/app/common/utils.service.js index 7f05481f0e..cebce6caee 100644 --- a/ui/src/app/common/utils.service.js +++ b/ui/src/app/common/utils.service.js @@ -503,6 +503,8 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t label = label.split(variable).join(datasource.entityName); } else if (variableName === 'deviceName') { label = label.split(variable).join(datasource.entityName); + } else if (variableName === 'entityLabel') { + label = label.split(variable).join(datasource.entityLabel); } else if (variableName === 'aliasName') { label = label.split(variable).join(datasource.aliasName); } else if (variableName === 'entityDescription') { diff --git a/ui/src/app/device/device-fieldset.tpl.html b/ui/src/app/device/device-fieldset.tpl.html index c9d0d1b9bc..aa0cbb5b05 100644 --- a/ui/src/app/device/device-fieldset.tpl.html +++ b/ui/src/app/device/device-fieldset.tpl.html @@ -71,6 +71,10 @@ ng-model="device.type" entity-type="types.entityType.device"> + + + + {{ 'device.is-gateway' | translate }} diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index e6a0a956cc..69d2a02e71 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -656,6 +656,7 @@ "name": "Name", "name-required": "Name is required.", "description": "Description", + "label": "Label", "events": "Events", "details": "Details", "copyId": "Copy device Id",