Commit ed3c57d1eacfb82016f9efef52be49609b0cceb5

Authored by Vladyslav_Prykhodko
2 parents b29a610f 9b76d785

Merge remote-tracking branch 'upstream/master' into feature/rule-chain/open-rule-chain-node

Showing 100 changed files with 976 additions and 389 deletions

Too many changes to show.

To preserve performance only 100 of 150 files are displayed.

... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
  18 +import com.fasterxml.jackson.core.JsonProcessingException;
18 19 import com.fasterxml.jackson.databind.ObjectMapper;
19 20 import com.fasterxml.jackson.databind.node.ArrayNode;
20 21 import com.fasterxml.jackson.databind.node.ObjectNode;
... ... @@ -26,26 +27,27 @@ import org.springframework.beans.factory.annotation.Value;
26 27 import org.springframework.security.core.Authentication;
27 28 import org.springframework.security.core.context.SecurityContextHolder;
28 29 import org.springframework.web.bind.annotation.ExceptionHandler;
29   -import org.thingsboard.server.common.data.*;
30 30 import org.thingsboard.server.common.data.Customer;
31 31 import org.thingsboard.server.common.data.Dashboard;
32 32 import org.thingsboard.server.common.data.DashboardInfo;
33 33 import org.thingsboard.server.common.data.DataConstants;
34 34 import org.thingsboard.server.common.data.Device;
  35 +import org.thingsboard.server.common.data.DeviceInfo;
35 36 import org.thingsboard.server.common.data.EntityType;
36 37 import org.thingsboard.server.common.data.EntityView;
  38 +import org.thingsboard.server.common.data.EntityViewInfo;
37 39 import org.thingsboard.server.common.data.HasName;
38 40 import org.thingsboard.server.common.data.HasTenantId;
39 41 import org.thingsboard.server.common.data.Tenant;
40 42 import org.thingsboard.server.common.data.User;
41 43 import org.thingsboard.server.common.data.alarm.Alarm;
42   -import org.thingsboard.server.common.data.id.AlarmId;
43 44 import org.thingsboard.server.common.data.alarm.AlarmInfo;
44 45 import org.thingsboard.server.common.data.asset.Asset;
45 46 import org.thingsboard.server.common.data.asset.AssetInfo;
46 47 import org.thingsboard.server.common.data.audit.ActionType;
47 48 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
48 49 import org.thingsboard.server.common.data.exception.ThingsboardException;
  50 +import org.thingsboard.server.common.data.id.AlarmId;
49 51 import org.thingsboard.server.common.data.id.AssetId;
50 52 import org.thingsboard.server.common.data.id.CustomerId;
51 53 import org.thingsboard.server.common.data.id.DashboardId;
... ... @@ -73,7 +75,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
73 75 import org.thingsboard.server.common.msg.TbMsg;
74 76 import org.thingsboard.server.common.msg.TbMsgDataType;
75 77 import org.thingsboard.server.common.msg.TbMsgMetaData;
76   -import org.thingsboard.server.dao.alarm.AlarmService;
77 78 import org.thingsboard.server.dao.asset.AssetService;
78 79 import org.thingsboard.server.dao.attributes.AttributesService;
79 80 import org.thingsboard.server.dao.audit.AuditLogService;
... ... @@ -640,6 +641,12 @@ public abstract class BaseController {
640 641 case ALARM_CLEAR:
641 642 msgType = DataConstants.ALARM_CLEAR;
642 643 break;
  644 + case ASSIGNED_FROM_TENANT:
  645 + msgType = DataConstants.ENTITY_ASSIGNED_FROM_TENANT;
  646 + break;
  647 + case ASSIGNED_TO_TENANT:
  648 + msgType = DataConstants.ENTITY_ASSIGNED_TO_TENANT;
  649 + break;
643 650 }
644 651 if (!StringUtils.isEmpty(msgType)) {
645 652 try {
... ... @@ -659,6 +666,16 @@ public abstract class BaseController {
659 666 String strCustomerName = extractParameter(String.class, 2, additionalInfo);
660 667 metaData.putValue("unassignedCustomerId", strCustomerId);
661 668 metaData.putValue("unassignedCustomerName", strCustomerName);
  669 + } else if (actionType == ActionType.ASSIGNED_FROM_TENANT) {
  670 + String strTenantId = extractParameter(String.class, 0, additionalInfo);
  671 + String strTenantName = extractParameter(String.class, 1, additionalInfo);
  672 + metaData.putValue("assignedFromTenantId", strTenantId);
  673 + metaData.putValue("assignedFromTenantName", strTenantName);
  674 + } else if (actionType == ActionType.ASSIGNED_TO_TENANT) {
  675 + String strTenantId = extractParameter(String.class, 0, additionalInfo);
  676 + String strTenantName = extractParameter(String.class, 1, additionalInfo);
  677 + metaData.putValue("assignedToTenantId", strTenantId);
  678 + metaData.putValue("assignedToTenantName", strTenantName);
662 679 }
663 680 ObjectNode entityNode;
664 681 if (entity != null) {
... ... @@ -722,5 +739,13 @@ public abstract class BaseController {
722 739 return result;
723 740 }
724 741
  742 + protected <E extends HasName> String entityToStr(E entity) {
  743 + try {
  744 + return json.writeValueAsString(json.valueToTree(entity));
  745 + } catch (JsonProcessingException e) {
  746 + log.warn("[{}] Failed to convert entity to string!", entity, e);
  747 + }
  748 + return null;
  749 + }
725 750
726 751 }
... ...
... ... @@ -40,8 +40,10 @@ import org.thingsboard.server.common.data.Device;
40 40 import org.thingsboard.server.common.data.DeviceInfo;
41 41 import org.thingsboard.server.common.data.EntitySubtype;
42 42 import org.thingsboard.server.common.data.EntityType;
  43 +import org.thingsboard.server.common.data.Tenant;
43 44 import org.thingsboard.server.common.data.audit.ActionType;
44 45 import org.thingsboard.server.common.data.device.DeviceSearchQuery;
  46 +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
45 47 import org.thingsboard.server.common.data.exception.ThingsboardException;
46 48 import org.thingsboard.server.common.data.id.CustomerId;
47 49 import org.thingsboard.server.common.data.id.DeviceId;
... ... @@ -49,6 +51,9 @@ import org.thingsboard.server.common.data.id.TenantId;
49 51 import org.thingsboard.server.common.data.page.PageData;
50 52 import org.thingsboard.server.common.data.page.PageLink;
51 53 import org.thingsboard.server.common.data.security.DeviceCredentials;
  54 +import org.thingsboard.server.common.msg.TbMsg;
  55 +import org.thingsboard.server.common.msg.TbMsgDataType;
  56 +import org.thingsboard.server.common.msg.TbMsgMetaData;
52 57 import org.thingsboard.server.dao.device.claim.ClaimResponse;
53 58 import org.thingsboard.server.dao.device.claim.ClaimResult;
54 59 import org.thingsboard.server.dao.exception.IncorrectParameterException;
... ... @@ -71,6 +76,7 @@ public class DeviceController extends BaseController {
71 76
72 77 private static final String DEVICE_ID = "deviceId";
73 78 private static final String DEVICE_NAME = "deviceName";
  79 + private static final String TENANT_ID = "tenantId";
74 80
75 81 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
76 82 @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET)
... ... @@ -547,4 +553,54 @@ public class DeviceController extends BaseController {
547 553 }
548 554 return DataConstants.DEFAULT_SECRET_KEY;
549 555 }
  556 +
  557 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  558 + @RequestMapping(value = "/tenant/{tenantId}/device/{deviceId}", method = RequestMethod.POST)
  559 + @ResponseBody
  560 + public Device assignDeviceToTenant(@PathVariable(TENANT_ID) String strTenantId,
  561 + @PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException {
  562 + checkParameter(TENANT_ID, strTenantId);
  563 + checkParameter(DEVICE_ID, strDeviceId);
  564 + try {
  565 + DeviceId deviceId = new DeviceId(toUUID(strDeviceId));
  566 + Device device = checkDeviceId(deviceId, Operation.ASSIGN_TO_TENANT);
  567 +
  568 + TenantId newTenantId = new TenantId(toUUID(strTenantId));
  569 + Tenant newTenant = tenantService.findTenantById(newTenantId);
  570 + if (newTenant == null) {
  571 + throw new ThingsboardException("Could not find the specified Tenant!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
  572 + }
  573 +
  574 + Device assignedDevice = deviceService.assignDeviceToTenant(newTenantId, device);
  575 +
  576 + logEntityAction(getCurrentUser(), deviceId, assignedDevice,
  577 + assignedDevice.getCustomerId(),
  578 + ActionType.ASSIGNED_TO_TENANT, null, strTenantId, newTenant.getName());
  579 +
  580 + Tenant currentTenant = tenantService.findTenantById(getTenantId());
  581 + pushAssignedFromNotification(currentTenant, newTenantId, assignedDevice);
  582 +
  583 + return assignedDevice;
  584 + } catch (Exception e) {
  585 + logEntityAction(getCurrentUser(), emptyId(EntityType.DEVICE), null,
  586 + null,
  587 + ActionType.ASSIGNED_TO_TENANT, e, strTenantId);
  588 + throw handleException(e);
  589 + }
  590 + }
  591 +
  592 + private void pushAssignedFromNotification(Tenant currentTenant, TenantId newTenantId, Device assignedDevice) {
  593 + String data = entityToStr(assignedDevice);
  594 + if (data != null) {
  595 + TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_ASSIGNED_FROM_TENANT, assignedDevice.getId(), getMetaDataForAssignedFrom(currentTenant), TbMsgDataType.JSON, data);
  596 + tbClusterService.pushMsgToRuleEngine(newTenantId, assignedDevice.getId(), tbMsg, null);
  597 + }
  598 + }
  599 +
  600 + private TbMsgMetaData getMetaDataForAssignedFrom(Tenant tenant) {
  601 + TbMsgMetaData metaData = new TbMsgMetaData();
  602 + metaData.putValue("assignedFromTenantId", tenant.getId().getId().toString());
  603 + metaData.putValue("assignedFromTenantName", tenant.getName());
  604 + return metaData;
  605 + }
550 606 }
... ...
... ... @@ -28,7 +28,9 @@ import org.thingsboard.server.service.install.DatabaseTsUpgradeService;
28 28 import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
29 29 import org.thingsboard.server.service.install.SystemDataLoaderService;
30 30 import org.thingsboard.server.service.install.TsDatabaseSchemaService;
  31 +import org.thingsboard.server.service.install.TsLatestDatabaseSchemaService;
31 32 import org.thingsboard.server.service.install.migrate.EntitiesMigrateService;
  33 +import org.thingsboard.server.service.install.migrate.TsLatestMigrateService;
32 34 import org.thingsboard.server.service.install.update.DataUpdateService;
33 35
34 36 @Service
... ... @@ -51,6 +53,9 @@ public class ThingsboardInstallService {
51 53 @Autowired
52 54 private TsDatabaseSchemaService tsDatabaseSchemaService;
53 55
  56 + @Autowired(required = false)
  57 + private TsLatestDatabaseSchemaService tsLatestDatabaseSchemaService;
  58 +
54 59 @Autowired
55 60 private DatabaseEntitiesUpgradeService databaseEntitiesUpgradeService;
56 61
... ... @@ -72,6 +77,9 @@ public class ThingsboardInstallService {
72 77 @Autowired(required = false)
73 78 private EntitiesMigrateService entitiesMigrateService;
74 79
  80 + @Autowired(required = false)
  81 + private TsLatestMigrateService latestMigrateService;
  82 +
75 83 public void performInstall() {
76 84 try {
77 85 if (isUpgrade) {
... ... @@ -82,6 +90,10 @@ public class ThingsboardInstallService {
82 90 entitiesMigrateService.migrate();
83 91 log.info("Updating system data...");
84 92 systemDataLoaderService.updateSystemWidgets();
  93 + } else if ("3.0.1-cassandra".equals(upgradeFromVersion)) {
  94 + log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ...");
  95 + latestMigrateService.migrate();
  96 + log.info("Updating system data...");
85 97 } else {
86 98 switch (upgradeFromVersion) {
87 99 case "1.2.3": //NOSONAR, Need to execute gradual upgrade starting from upgradeFromVersion
... ... @@ -181,6 +193,10 @@ public class ThingsboardInstallService {
181 193
182 194 tsDatabaseSchemaService.createDatabaseSchema();
183 195
  196 + if (tsLatestDatabaseSchemaService != null) {
  197 + tsLatestDatabaseSchemaService.createDatabaseSchema();
  198 + }
  199 +
184 200 log.info("Loading system data...");
185 201
186 202 componentDiscoveryService.discoverComponents();
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +import org.springframework.context.annotation.Profile;
  19 +import org.springframework.stereotype.Service;
  20 +import org.thingsboard.server.dao.util.NoSqlTsLatestDao;
  21 +
  22 +@Service
  23 +@NoSqlTsLatestDao
  24 +@Profile("install")
  25 +public class CassandraTsLatestDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService
  26 + implements TsLatestDatabaseSchemaService {
  27 + public CassandraTsLatestDatabaseSchemaService() {
  28 + super("schema-ts-latest.cql");
  29 + }
  30 +}
... ...
... ... @@ -18,11 +18,9 @@ package org.thingsboard.server.service.install;
18 18 import org.springframework.context.annotation.Profile;
19 19 import org.springframework.stereotype.Service;
20 20 import org.thingsboard.server.dao.util.HsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23 22 @Service
24 23 @HsqlDao
25   -@SqlDao
26 24 @Profile("install")
27 25 public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
28 26 implements EntityDatabaseSchemaService {
... ...
... ... @@ -18,10 +18,8 @@ package org.thingsboard.server.service.install;
18 18 import org.springframework.context.annotation.Profile;
19 19 import org.springframework.stereotype.Service;
20 20 import org.thingsboard.server.dao.util.PsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23 22 @Service
24   -@SqlDao
25 23 @PsqlDao
26 24 @Profile("install")
27 25 public class PsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
... ...
... ... @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
21 21 import org.springframework.context.annotation.Profile;
22 22 import org.springframework.stereotype.Service;
23 23 import org.thingsboard.server.dao.dashboard.DashboardService;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24 import org.thingsboard.server.service.install.sql.SqlDbHelper;
26 25
27 26 import java.nio.charset.Charset;
... ... @@ -58,7 +57,6 @@ import static org.thingsboard.server.service.install.DatabaseHelper.TYPE;
58 57 @Service
59 58 @Profile("install")
60 59 @Slf4j
61   -@SqlDao
62 60 public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService {
63 61
64 62 private static final String SCHEMA_UPDATE_SQL = "schema_update.sql";
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install;
  17 +
  18 +public interface TsLatestDatabaseSchemaService extends DatabaseSchemaService {
  19 +}
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.EntityType;
24 24 import org.thingsboard.server.common.data.UUIDConverter;
25 25 import org.thingsboard.server.dao.cassandra.CassandraCluster;
26 26 import org.thingsboard.server.dao.util.NoSqlAnyDao;
27   -import org.thingsboard.server.dao.util.SqlDao;
28 27 import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
29 28
30 29 import java.sql.Connection;
... ... @@ -42,7 +41,6 @@ import static org.thingsboard.server.service.install.migrate.CassandraToSqlColum
42 41
43 42 @Service
44 43 @Profile("install")
45   -@SqlDao
46 44 @NoSqlAnyDao
47 45 @Slf4j
48 46 public class CassandraEntitiesToSqlMigrateService implements EntitiesMigrateService {
... ...
... ... @@ -128,7 +128,7 @@ public class CassandraToSqlTable {
128 128 return this.validateColumnData(data);
129 129 }
130 130
131   - private CassandraToSqlColumnData[] validateColumnData(CassandraToSqlColumnData[] data) {
  131 + protected CassandraToSqlColumnData[] validateColumnData(CassandraToSqlColumnData[] data) {
132 132 for (int i=0;i<data.length;i++) {
133 133 CassandraToSqlColumn column = this.columns.get(i);
134 134 if (column.getType() == CassandraToSqlColumnType.STRING) {
... ... @@ -148,7 +148,7 @@ public class CassandraToSqlTable {
148 148 return data;
149 149 }
150 150
151   - private void batchInsert(List<CassandraToSqlColumnData[]> batchData, Connection conn) throws SQLException {
  151 + protected void batchInsert(List<CassandraToSqlColumnData[]> batchData, Connection conn) throws SQLException {
152 152 boolean retry = false;
153 153 for (CassandraToSqlColumnData[] data : batchData) {
154 154 for (CassandraToSqlColumn column: this.columns) {
... ... @@ -269,7 +269,7 @@ public class CassandraToSqlTable {
269 269 return Optional.empty();
270 270 }
271 271
272   - private Statement createCassandraSelectStatement() {
  272 + protected Statement createCassandraSelectStatement() {
273 273 StringBuilder selectStatementBuilder = new StringBuilder();
274 274 selectStatementBuilder.append("SELECT ");
275 275 for (CassandraToSqlColumn column : columns) {
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install.migrate;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +import org.apache.commons.lang3.StringUtils;
  20 +import org.hibernate.exception.ConstraintViolationException;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.beans.factory.annotation.Value;
  23 +import org.springframework.context.annotation.Profile;
  24 +import org.springframework.stereotype.Service;
  25 +import org.thingsboard.server.common.data.UUIDConverter;
  26 +import org.thingsboard.server.dao.cassandra.CassandraCluster;
  27 +import org.thingsboard.server.dao.model.sqlts.dictionary.TsKvDictionary;
  28 +import org.thingsboard.server.dao.model.sqlts.dictionary.TsKvDictionaryCompositeKey;
  29 +import org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity;
  30 +import org.thingsboard.server.dao.sqlts.dictionary.TsKvDictionaryRepository;
  31 +import org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository;
  32 +import org.thingsboard.server.dao.util.NoSqlAnyDao;
  33 +import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
  34 +
  35 +import java.sql.Connection;
  36 +import java.sql.DriverManager;
  37 +import java.util.Arrays;
  38 +import java.util.List;
  39 +import java.util.Optional;
  40 +import java.util.concurrent.ConcurrentHashMap;
  41 +import java.util.concurrent.ConcurrentMap;
  42 +import java.util.concurrent.locks.ReentrantLock;
  43 +import java.util.stream.Collectors;
  44 +
  45 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.bigintColumn;
  46 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.booleanColumn;
  47 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.doubleColumn;
  48 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.idColumn;
  49 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.jsonColumn;
  50 +import static org.thingsboard.server.service.install.migrate.CassandraToSqlColumn.stringColumn;
  51 +
  52 +@Service
  53 +@Profile("install")
  54 +@NoSqlAnyDao
  55 +@Slf4j
  56 +public class CassandraTsLatestToSqlMigrateService implements TsLatestMigrateService {
  57 +
  58 + @Autowired
  59 + private EntityDatabaseSchemaService entityDatabaseSchemaService;
  60 +
  61 + @Autowired
  62 + private InsertLatestTsRepository insertLatestTsRepository;
  63 +
  64 + @Autowired
  65 + protected CassandraCluster cluster;
  66 +
  67 + @Autowired
  68 + protected TsKvDictionaryRepository dictionaryRepository;
  69 +
  70 + @Value("${spring.datasource.url}")
  71 + protected String dbUrl;
  72 +
  73 + @Value("${spring.datasource.username}")
  74 + protected String dbUserName;
  75 +
  76 + @Value("${spring.datasource.password}")
  77 + protected String dbPassword;
  78 +
  79 + private final ConcurrentMap<String, Integer> tsKvDictionaryMap = new ConcurrentHashMap<>();
  80 +
  81 + protected static final ReentrantLock tsCreationLock = new ReentrantLock();
  82 +
  83 + @Override
  84 + public void migrate() throws Exception {
  85 + log.info("Performing migration of latest timeseries data from cassandra to SQL database ...");
  86 + entityDatabaseSchemaService.createDatabaseSchema(false);
  87 + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
  88 + conn.setAutoCommit(false);
  89 + for (CassandraToSqlTable table : tables) {
  90 + table.migrateToSql(cluster.getSession(), conn);
  91 + }
  92 + } catch (Exception e) {
  93 + log.error("Unexpected error during ThingsBoard entities data migration!", e);
  94 + throw e;
  95 + }
  96 + entityDatabaseSchemaService.createDatabaseIndexes();
  97 + }
  98 +
  99 + private List<CassandraToSqlTable> tables = Arrays.asList(
  100 + new CassandraToSqlTable("ts_kv_latest_cf",
  101 + idColumn("entity_id"),
  102 + stringColumn("key"),
  103 + bigintColumn("ts"),
  104 + booleanColumn("bool_v"),
  105 + stringColumn("str_v"),
  106 + bigintColumn("long_v"),
  107 + doubleColumn("dbl_v"),
  108 + jsonColumn("json_v")) {
  109 +
  110 + @Override
  111 + protected void batchInsert(List<CassandraToSqlColumnData[]> batchData, Connection conn) {
  112 + insertLatestTsRepository
  113 + .saveOrUpdate(batchData.stream().map(data -> getTsKvLatestEntity(data)).collect(Collectors.toList()));
  114 + }
  115 +
  116 + @Override
  117 + protected CassandraToSqlColumnData[] validateColumnData(CassandraToSqlColumnData[] data) {
  118 + return data;
  119 + }
  120 + });
  121 +
  122 + private TsKvLatestEntity getTsKvLatestEntity(CassandraToSqlColumnData[] data) {
  123 + TsKvLatestEntity latestEntity = new TsKvLatestEntity();
  124 + latestEntity.setEntityId(UUIDConverter.fromString(data[0].getValue()));
  125 + latestEntity.setKey(getOrSaveKeyId(data[1].getValue()));
  126 + latestEntity.setTs(Long.parseLong(data[2].getValue()));
  127 +
  128 + String strV = data[4].getValue();
  129 + if (strV != null) {
  130 + latestEntity.setStrValue(strV);
  131 + } else {
  132 + Long longV = null;
  133 + try {
  134 + longV = Long.parseLong(data[5].getValue());
  135 + } catch (Exception e) {
  136 + }
  137 + if (longV != null) {
  138 + latestEntity.setLongValue(longV);
  139 + } else {
  140 + Double doubleV = null;
  141 + try {
  142 + doubleV = Double.parseDouble(data[6].getValue());
  143 + } catch (Exception e) {
  144 + }
  145 + if (doubleV != null) {
  146 + latestEntity.setDoubleValue(doubleV);
  147 + } else {
  148 +
  149 + String jsonV = data[7].getValue();
  150 + if (StringUtils.isNoneEmpty(jsonV)) {
  151 + latestEntity.setJsonValue(jsonV);
  152 + } else {
  153 + Boolean boolV = null;
  154 + try {
  155 + boolV = Boolean.parseBoolean(data[3].getValue());
  156 + } catch (Exception e) {
  157 + }
  158 + if (boolV != null) {
  159 + latestEntity.setBooleanValue(boolV);
  160 + } else {
  161 + log.warn("All values in key-value row are nullable ");
  162 + }
  163 + }
  164 + }
  165 + }
  166 + }
  167 + return latestEntity;
  168 + }
  169 +
  170 + protected Integer getOrSaveKeyId(String strKey) {
  171 + Integer keyId = tsKvDictionaryMap.get(strKey);
  172 + if (keyId == null) {
  173 + Optional<TsKvDictionary> tsKvDictionaryOptional;
  174 + tsKvDictionaryOptional = dictionaryRepository.findById(new TsKvDictionaryCompositeKey(strKey));
  175 + if (!tsKvDictionaryOptional.isPresent()) {
  176 + tsCreationLock.lock();
  177 + try {
  178 + tsKvDictionaryOptional = dictionaryRepository.findById(new TsKvDictionaryCompositeKey(strKey));
  179 + if (!tsKvDictionaryOptional.isPresent()) {
  180 + TsKvDictionary tsKvDictionary = new TsKvDictionary();
  181 + tsKvDictionary.setKey(strKey);
  182 + try {
  183 + TsKvDictionary saved = dictionaryRepository.save(tsKvDictionary);
  184 + tsKvDictionaryMap.put(saved.getKey(), saved.getKeyId());
  185 + keyId = saved.getKeyId();
  186 + } catch (ConstraintViolationException e) {
  187 + tsKvDictionaryOptional = dictionaryRepository.findById(new TsKvDictionaryCompositeKey(strKey));
  188 + TsKvDictionary dictionary = tsKvDictionaryOptional.orElseThrow(() -> new RuntimeException("Failed to get TsKvDictionary entity from DB!"));
  189 + tsKvDictionaryMap.put(dictionary.getKey(), dictionary.getKeyId());
  190 + keyId = dictionary.getKeyId();
  191 + }
  192 + } else {
  193 + keyId = tsKvDictionaryOptional.get().getKeyId();
  194 + }
  195 + } finally {
  196 + tsCreationLock.unlock();
  197 + }
  198 + } else {
  199 + keyId = tsKvDictionaryOptional.get().getKeyId();
  200 + tsKvDictionaryMap.put(strKey, keyId);
  201 + }
  202 + }
  203 + return keyId;
  204 + }
  205 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install.migrate;
  17 +
  18 +public interface TsLatestMigrateService {
  19 +
  20 + void migrate() throws Exception;
  21 +}
... ...
... ... @@ -28,7 +28,6 @@ import org.thingsboard.server.common.msg.TbActorMsg;
28 28 import org.thingsboard.server.common.msg.queue.ServiceType;
29 29 import org.thingsboard.server.common.msg.queue.TbCallback;
30 30 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
31   -import org.thingsboard.server.gen.transport.TransportProtos;
32 31 import org.thingsboard.server.gen.transport.TransportProtos.DeviceStateServiceMsgProto;
33 32 import org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto;
34 33 import org.thingsboard.server.gen.transport.TransportProtos.LocalSubscriptionServiceMsgProto;
... ... @@ -61,7 +60,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra
61 60
62 61 import javax.annotation.PostConstruct;
63 62 import javax.annotation.PreDestroy;
64   -import java.util.ArrayList;
65 63 import java.util.List;
66 64 import java.util.Optional;
67 65 import java.util.UUID;
... ...
... ... @@ -18,6 +18,6 @@ package org.thingsboard.server.service.security.permission;
18 18 public enum Operation {
19 19
20 20 ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL,
21   - READ_CREDENTIALS, WRITE_CREDENTIALS, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_TELEMETRY, WRITE_TELEMETRY, CLAIM_DEVICES
  21 + READ_CREDENTIALS, WRITE_CREDENTIALS, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_TELEMETRY, WRITE_TELEMETRY, CLAIM_DEVICES, ASSIGN_TO_TENANT
22 22
23 23 }
... ...
... ... @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Value;
20 20 import org.springframework.scheduling.annotation.Scheduled;
21 21 import org.springframework.stereotype.Service;
22 22 import org.thingsboard.server.dao.util.PsqlDao;
23   -import org.thingsboard.server.dao.util.SqlDao;
24 23 import org.thingsboard.server.service.ttl.AbstractCleanUpService;
25 24
26 25 import java.sql.Connection;
... ... @@ -28,7 +27,6 @@ import java.sql.DriverManager;
28 27 import java.sql.SQLException;
29 28
30 29 @PsqlDao
31   -@SqlDao
32 30 @Slf4j
33 31 @Service
34 32 public class EventsCleanUpService extends AbstractCleanUpService {
... ...
... ... @@ -19,11 +19,13 @@ import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Value;
20 20 import org.springframework.stereotype.Service;
21 21 import org.thingsboard.server.dao.model.ModelConstants;
22   -import org.thingsboard.server.dao.util.PsqlTsDao;
  22 +import org.thingsboard.server.dao.util.PsqlDao;
  23 +import org.thingsboard.server.dao.util.SqlTsDao;
23 24
24 25 import java.sql.Connection;
25 26
26   -@PsqlTsDao
  27 +@SqlTsDao
  28 +@PsqlDao
27 29 @Service
28 30 @Slf4j
29 31 public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpService {
... ... @@ -33,9 +35,9 @@ public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpServi
33 35
34 36 @Override
35 37 protected void doCleanUp(Connection connection) {
36   - long totalPartitionsRemoved = executeQuery(connection, "call drop_partitions_by_max_ttl('" + partitionType + "'," + systemTtl + ", 0);");
37   - log.info("Total partitions removed by TTL: [{}]", totalPartitionsRemoved);
38   - long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID + "'," + systemTtl + ", 0);");
39   - log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved);
  38 + long totalPartitionsRemoved = executeQuery(connection, "call drop_partitions_by_max_ttl('" + partitionType + "'," + systemTtl + ", 0);");
  39 + log.info("Total partitions removed by TTL: [{}]", totalPartitionsRemoved);
  40 + long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID + "'," + systemTtl + ", 0);");
  41 + log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved);
40 42 }
41 43 }
\ No newline at end of file
... ...
... ... @@ -178,8 +178,8 @@ database:
178 178 ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by single API call to fetch telemetry records
179 179 ts:
180 180 type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
181   - latest_ts:
182   - type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
  181 + ts_latest:
  182 + type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
183 183
184 184 # note: timescale works only with postgreSQL database for DATABASE_ENTITIES_TYPE.
185 185
... ...
... ... @@ -15,74 +15,17 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import com.fasterxml.jackson.core.type.TypeReference;
19   -import com.fasterxml.jackson.databind.JsonNode;
20   -import com.fasterxml.jackson.databind.ObjectMapper;
21   -import io.jsonwebtoken.Claims;
22   -import io.jsonwebtoken.Header;
23   -import io.jsonwebtoken.Jwt;
24   -import io.jsonwebtoken.Jwts;
25 18 import lombok.extern.slf4j.Slf4j;
26   -import org.apache.commons.lang3.StringUtils;
27   -import org.hamcrest.Matcher;
28   -import org.junit.After;
29   -import org.junit.Assert;
30   -import org.junit.Before;
31   -import org.junit.Rule;
32   -import org.junit.rules.TestRule;
33   -import org.junit.rules.TestWatcher;
34   -import org.junit.runner.Description;
35 19 import org.junit.runner.RunWith;
36   -import org.springframework.beans.factory.annotation.Autowired;
37 20 import org.springframework.boot.test.context.SpringBootContextLoader;
38 21 import org.springframework.boot.test.context.SpringBootTest;
39 22 import org.springframework.context.annotation.ComponentScan;
40 23 import org.springframework.context.annotation.Configuration;
41   -import org.springframework.http.HttpHeaders;
42   -import org.springframework.http.MediaType;
43   -import org.springframework.http.converter.HttpMessageConverter;
44   -import org.springframework.http.converter.StringHttpMessageConverter;
45   -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
46   -import org.springframework.mock.http.MockHttpInputMessage;
47   -import org.springframework.mock.http.MockHttpOutputMessage;
48 24 import org.springframework.test.annotation.DirtiesContext;
49 25 import org.springframework.test.context.ActiveProfiles;
50 26 import org.springframework.test.context.ContextConfiguration;
51 27 import org.springframework.test.context.junit4.SpringRunner;
52 28 import org.springframework.test.context.web.WebAppConfiguration;
53   -import org.springframework.test.web.servlet.MockMvc;
54   -import org.springframework.test.web.servlet.MvcResult;
55   -import org.springframework.test.web.servlet.ResultActions;
56   -import org.springframework.test.web.servlet.ResultMatcher;
57   -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
58   -import org.springframework.util.LinkedMultiValueMap;
59   -import org.springframework.util.MultiValueMap;
60   -import org.springframework.web.context.WebApplicationContext;
61   -import org.thingsboard.server.common.data.BaseData;
62   -import org.thingsboard.server.common.data.Customer;
63   -import org.thingsboard.server.common.data.Tenant;
64   -import org.thingsboard.server.common.data.User;
65   -import org.thingsboard.server.common.data.id.TenantId;
66   -import org.thingsboard.server.common.data.id.UUIDBased;
67   -import org.thingsboard.server.common.data.page.PageLink;
68   -import org.thingsboard.server.common.data.page.SortOrder;
69   -import org.thingsboard.server.common.data.page.TimePageLink;
70   -import org.thingsboard.server.common.data.security.Authority;
71   -import org.thingsboard.server.config.ThingsboardSecurityConfiguration;
72   -import org.thingsboard.server.service.mail.TestMailService;
73   -import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest;
74   -import org.thingsboard.server.service.security.auth.rest.LoginRequest;
75   -
76   -import java.io.IOException;
77   -import java.util.ArrayList;
78   -import java.util.Arrays;
79   -import java.util.Comparator;
80   -import java.util.List;
81   -
82   -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
83   -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
84   -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
85   -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
86 29
87 30 @ActiveProfiles("test")
88 31 @RunWith(SpringRunner.class)
... ...
... ... @@ -218,6 +218,7 @@ public abstract class AbstractWebTest {
218 218 }
219 219
220 220 private Tenant savedDifferentTenant;
  221 +
221 222 protected void loginDifferentTenant() throws Exception {
222 223 loginSysAdmin();
223 224 Tenant tenant = new Tenant();
... ... @@ -313,6 +314,10 @@ public abstract class AbstractWebTest {
313 314 return readResponse(doGet(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass);
314 315 }
315 316
  317 + protected <T> T doGet(String urlTemplate, Class<T> responseClass, ResultMatcher resultMatcher, Object... urlVariables) throws Exception {
  318 + return readResponse(doGet(urlTemplate, urlVariables).andExpect(resultMatcher), responseClass);
  319 + }
  320 +
316 321 protected <T> T doGetAsync(String urlTemplate, Class<T> responseClass, Object... urlVariables) throws Exception {
317 322 return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass);
318 323 }
... ... @@ -352,9 +357,9 @@ public abstract class AbstractWebTest {
352 357 return readResponse(doGet(urlTemplate, vars).andExpect(status().isOk()), responseType);
353 358 }
354 359
355   - protected <T> T doGetTypedWithTimePageLink(String urlTemplate, TypeReference<T> responseType,
356   - TimePageLink pageLink,
357   - Object... urlVariables) throws Exception {
  360 + protected <T> T doGetTypedWithTimePageLink(String urlTemplate, TypeReference<T> responseType,
  361 + TimePageLink pageLink,
  362 + Object... urlVariables) throws Exception {
358 363 List<Object> pageLinkVariables = new ArrayList<>();
359 364 urlTemplate += "pageSize={pageSize}&page={page}";
360 365 pageLinkVariables.add(pageLink.getPageSize());
... ... @@ -395,11 +400,11 @@ public abstract class AbstractWebTest {
395 400 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass);
396 401 }
397 402
398   - protected <T,R> R doPostWithResponse(String urlTemplate, T content, Class<R> responseClass, String... params) throws Exception {
  403 + protected <T, R> R doPostWithResponse(String urlTemplate, T content, Class<R> responseClass, String... params) throws Exception {
399 404 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass);
400 405 }
401 406
402   - protected <T,R> R doPostWithTypedResponse(String urlTemplate, T content, TypeReference<R> responseType, String... params) throws Exception {
  407 + protected <T, R> R doPostWithTypedResponse(String urlTemplate, T content, TypeReference<R> responseType, String... params) throws Exception {
403 408 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseType);
404 409 }
405 410
... ... @@ -430,7 +435,7 @@ public abstract class AbstractWebTest {
430 435 return mockMvc.perform(postRequest);
431 436 }
432 437
433   - protected <T> ResultActions doPostAsync(String urlTemplate, T content, Long timeout, String... params) throws Exception {
  438 + protected <T> ResultActions doPostAsync(String urlTemplate, T content, Long timeout, String... params) throws Exception {
434 439 MockHttpServletRequestBuilder postRequest = post(urlTemplate, params);
435 440 setJwtToken(postRequest);
436 441 String json = json(content);
... ...
... ... @@ -15,74 +15,79 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import static org.hamcrest.Matchers.containsString;
19   -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
20   -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
21   -
22   -import java.util.ArrayList;
23   -import java.util.Collections;
24   -import java.util.List;
25   -
26 18 import com.datastax.oss.driver.api.core.uuid.Uuids;
  19 +import com.fasterxml.jackson.core.type.TypeReference;
27 20 import org.apache.commons.lang3.RandomStringUtils;
28   -import org.thingsboard.server.common.data.*;
  21 +import org.junit.After;
  22 +import org.junit.Assert;
  23 +import org.junit.Before;
  24 +import org.junit.Test;
  25 +import org.thingsboard.server.common.data.Customer;
  26 +import org.thingsboard.server.common.data.Device;
  27 +import org.thingsboard.server.common.data.EntitySubtype;
  28 +import org.thingsboard.server.common.data.Tenant;
  29 +import org.thingsboard.server.common.data.User;
29 30 import org.thingsboard.server.common.data.id.CustomerId;
30 31 import org.thingsboard.server.common.data.id.DeviceCredentialsId;
31 32 import org.thingsboard.server.common.data.id.DeviceId;
32 33 import org.thingsboard.server.common.data.page.PageData;
33 34 import org.thingsboard.server.common.data.page.PageLink;
  35 +import org.thingsboard.server.common.data.relation.EntityRelation;
  36 +import org.thingsboard.server.common.data.relation.RelationTypeGroup;
34 37 import org.thingsboard.server.common.data.security.Authority;
35 38 import org.thingsboard.server.common.data.security.DeviceCredentials;
36 39 import org.thingsboard.server.common.data.security.DeviceCredentialsType;
37 40 import org.thingsboard.server.dao.model.ModelConstants;
38   -import org.junit.After;
39   -import org.junit.Assert;
40   -import org.junit.Before;
41   -import org.junit.Test;
42 41
43   -import com.fasterxml.jackson.core.type.TypeReference;
  42 +import java.util.ArrayList;
  43 +import java.util.Collections;
  44 +import java.util.List;
  45 +
  46 +import static org.hamcrest.Matchers.containsString;
  47 +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  48 +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
44 49
45 50 public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
46   -
  51 +
47 52 private IdComparator<Device> idComparator = new IdComparator<>();
48   -
  53 +
49 54 private Tenant savedTenant;
50 55 private User tenantAdmin;
51   -
  56 +
52 57 @Before
53 58 public void beforeTest() throws Exception {
54 59 loginSysAdmin();
55   -
  60 +
56 61 Tenant tenant = new Tenant();
57 62 tenant.setTitle("My tenant");
58 63 savedTenant = doPost("/api/tenant", tenant, Tenant.class);
59 64 Assert.assertNotNull(savedTenant);
60   -
  65 +
61 66 tenantAdmin = new User();
62 67 tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
63 68 tenantAdmin.setTenantId(savedTenant.getId());
64 69 tenantAdmin.setEmail("tenant2@thingsboard.org");
65 70 tenantAdmin.setFirstName("Joe");
66 71 tenantAdmin.setLastName("Downs");
67   -
  72 +
68 73 tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
69 74 }
70   -
  75 +
71 76 @After
72 77 public void afterTest() throws Exception {
73 78 loginSysAdmin();
74   -
75   - doDelete("/api/tenant/"+savedTenant.getId().getId().toString())
76   - .andExpect(status().isOk());
  79 +
  80 + doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
  81 + .andExpect(status().isOk());
77 82 }
78   -
  83 +
79 84 @Test
80 85 public void testSaveDevice() throws Exception {
81 86 Device device = new Device();
82 87 device.setName("My device");
83 88 device.setType("default");
84 89 Device savedDevice = doPost("/api/device", device, Device.class);
85   -
  90 +
86 91 Assert.assertNotNull(savedDevice);
87 92 Assert.assertNotNull(savedDevice.getId());
88 93 Assert.assertTrue(savedDevice.getCreatedTime() > 0);
... ... @@ -90,9 +95,9 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
90 95 Assert.assertNotNull(savedDevice.getCustomerId());
91 96 Assert.assertEquals(NULL_UUID, savedDevice.getCustomerId().getId());
92 97 Assert.assertEquals(device.getName(), savedDevice.getName());
93   -
94   - DeviceCredentials deviceCredentials =
95   - doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
  98 +
  99 + DeviceCredentials deviceCredentials =
  100 + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
96 101
97 102 Assert.assertNotNull(deviceCredentials);
98 103 Assert.assertNotNull(deviceCredentials.getId());
... ... @@ -100,10 +105,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
100 105 Assert.assertEquals(DeviceCredentialsType.ACCESS_TOKEN, deviceCredentials.getCredentialsType());
101 106 Assert.assertNotNull(deviceCredentials.getCredentialsId());
102 107 Assert.assertEquals(20, deviceCredentials.getCredentialsId().length());
103   -
  108 +
104 109 savedDevice.setName("My new device");
105 110 doPost("/api/device", savedDevice, Device.class);
106   -
  111 +
107 112 Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
108 113 Assert.assertEquals(foundDevice.getName(), savedDevice.getName());
109 114 }
... ... @@ -115,10 +120,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
115 120 device.setType("default");
116 121 Device savedDevice = doPost("/api/device", device, Device.class);
117 122 loginDifferentTenant();
118   - doPost("/api/device", savedDevice, Device.class, status().isForbidden());
  123 + doPost("/api/device", savedDevice, Device.class, status().isNotFound());
119 124 deleteDifferentTenant();
120 125 }
121   -
  126 +
122 127 @Test
123 128 public void testFindDeviceById() throws Exception {
124 129 Device device = new Device();
... ... @@ -133,26 +138,27 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
133 138 @Test
134 139 public void testFindDeviceTypesByTenantId() throws Exception {
135 140 List<Device> devices = new ArrayList<>();
136   - for (int i=0;i<3;i++) {
  141 + for (int i = 0; i < 3; i++) {
137 142 Device device = new Device();
138   - device.setName("My device B"+i);
  143 + device.setName("My device B" + i);
139 144 device.setType("typeB");
140 145 devices.add(doPost("/api/device", device, Device.class));
141 146 }
142   - for (int i=0;i<7;i++) {
  147 + for (int i = 0; i < 7; i++) {
143 148 Device device = new Device();
144   - device.setName("My device C"+i);
  149 + device.setName("My device C" + i);
145 150 device.setType("typeC");
146 151 devices.add(doPost("/api/device", device, Device.class));
147 152 }
148   - for (int i=0;i<9;i++) {
  153 + for (int i = 0; i < 9; i++) {
149 154 Device device = new Device();
150   - device.setName("My device A"+i);
  155 + device.setName("My device A" + i);
151 156 device.setType("typeA");
152 157 devices.add(doPost("/api/device", device, Device.class));
153 158 }
154 159 List<EntitySubtype> deviceTypes = doGetTyped("/api/device/types",
155   - new TypeReference<List<EntitySubtype>>(){});
  160 + new TypeReference<List<EntitySubtype>>() {
  161 + });
156 162
157 163 Assert.assertNotNull(deviceTypes);
158 164 Assert.assertEquals(3, deviceTypes.size());
... ... @@ -160,19 +166,19 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
160 166 Assert.assertEquals("typeB", deviceTypes.get(1).getType());
161 167 Assert.assertEquals("typeC", deviceTypes.get(2).getType());
162 168 }
163   -
  169 +
164 170 @Test
165 171 public void testDeleteDevice() throws Exception {
166 172 Device device = new Device();
167 173 device.setName("My device");
168 174 device.setType("default");
169 175 Device savedDevice = doPost("/api/device", device, Device.class);
170   -
171   - doDelete("/api/device/"+savedDevice.getId().getId().toString())
172   - .andExpect(status().isOk());
173 176
174   - doGet("/api/device/"+savedDevice.getId().getId().toString())
175   - .andExpect(status().isNotFound());
  177 + doDelete("/api/device/" + savedDevice.getId().getId().toString())
  178 + .andExpect(status().isOk());
  179 +
  180 + doGet("/api/device/" + savedDevice.getId().getId().toString())
  181 + .andExpect(status().isNotFound());
176 182 }
177 183
178 184 @Test
... ... @@ -189,52 +195,51 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
189 195 Device device = new Device();
190 196 device.setType("default");
191 197 doPost("/api/device", device)
192   - .andExpect(status().isBadRequest())
193   - .andExpect(statusReason(containsString("Device name should be specified")));
  198 + .andExpect(status().isBadRequest())
  199 + .andExpect(statusReason(containsString("Device name should be specified")));
194 200 }
195   -
  201 +
196 202 @Test
197 203 public void testAssignUnassignDeviceToCustomer() throws Exception {
198 204 Device device = new Device();
199 205 device.setName("My device");
200 206 device.setType("default");
201 207 Device savedDevice = doPost("/api/device", device, Device.class);
202   -
  208 +
203 209 Customer customer = new Customer();
204 210 customer.setTitle("My customer");
205 211 Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
206   -
207   - Device assignedDevice = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
  212 +
  213 + Device assignedDevice = doPost("/api/customer/" + savedCustomer.getId().getId().toString()
208 214 + "/device/" + savedDevice.getId().getId().toString(), Device.class);
209 215 Assert.assertEquals(savedCustomer.getId(), assignedDevice.getCustomerId());
210   -
  216 +
211 217 Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
212 218 Assert.assertEquals(savedCustomer.getId(), foundDevice.getCustomerId());
213 219
214   - Device unassignedDevice =
  220 + Device unassignedDevice =
215 221 doDelete("/api/customer/device/" + savedDevice.getId().getId().toString(), Device.class);
216 222 Assert.assertEquals(ModelConstants.NULL_UUID, unassignedDevice.getCustomerId().getId());
217   -
  223 +
218 224 foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class);
219 225 Assert.assertEquals(ModelConstants.NULL_UUID, foundDevice.getCustomerId().getId());
220 226 }
221   -
  227 +
222 228 @Test
223 229 public void testAssignDeviceToNonExistentCustomer() throws Exception {
224 230 Device device = new Device();
225 231 device.setName("My device");
226 232 device.setType("default");
227 233 Device savedDevice = doPost("/api/device", device, Device.class);
228   -
229 234 doPost("/api/customer/" + Uuids.timeBased().toString()
230 235 + "/device/" + savedDevice.getId().getId().toString())
231   - .andExpect(status().isNotFound());
  236 + .andExpect(status().isNotFound());
232 237 }
233   -
  238 +
234 239 @Test
235 240 public void testAssignDeviceToCustomerFromDifferentTenant() throws Exception {
236 241 loginSysAdmin();
237   -
  242 +
238 243 Tenant tenant2 = new Tenant();
239 244 tenant2.setTitle("Different tenant");
240 245 Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class);
... ... @@ -246,103 +251,103 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
246 251 tenantAdmin2.setEmail("tenant3@thingsboard.org");
247 252 tenantAdmin2.setFirstName("Joe");
248 253 tenantAdmin2.setLastName("Downs");
249   -
  254 +
250 255 tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1");
251   -
  256 +
252 257 Customer customer = new Customer();
253 258 customer.setTitle("Different customer");
254 259 Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
255 260
256 261 login(tenantAdmin.getEmail(), "testPassword1");
257   -
  262 +
258 263 Device device = new Device();
259 264 device.setName("My device");
260 265 device.setType("default");
261 266 Device savedDevice = doPost("/api/device", device, Device.class);
262   -
  267 +
263 268 doPost("/api/customer/" + savedCustomer.getId().getId().toString()
264 269 + "/device/" + savedDevice.getId().getId().toString())
265   - .andExpect(status().isForbidden());
266   -
  270 + .andExpect(status().isForbidden());
  271 +
267 272 loginSysAdmin();
268   -
269   - doDelete("/api/tenant/"+savedTenant2.getId().getId().toString())
270   - .andExpect(status().isOk());
  273 +
  274 + doDelete("/api/tenant/" + savedTenant2.getId().getId().toString())
  275 + .andExpect(status().isOk());
271 276 }
272   -
  277 +
273 278 @Test
274 279 public void testFindDeviceCredentialsByDeviceId() throws Exception {
275 280 Device device = new Device();
276 281 device.setName("My device");
277 282 device.setType("default");
278 283 Device savedDevice = doPost("/api/device", device, Device.class);
279   - DeviceCredentials deviceCredentials =
280   - doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
  284 + DeviceCredentials deviceCredentials =
  285 + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
281 286 Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
282 287 }
283   -
  288 +
284 289 @Test
285 290 public void testSaveDeviceCredentials() throws Exception {
286 291 Device device = new Device();
287 292 device.setName("My device");
288 293 device.setType("default");
289 294 Device savedDevice = doPost("/api/device", device, Device.class);
290   - DeviceCredentials deviceCredentials =
291   - doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
  295 + DeviceCredentials deviceCredentials =
  296 + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
292 297 Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
293 298 deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
294 299 deviceCredentials.setCredentialsId("access_token");
295 300 doPost("/api/device/credentials", deviceCredentials)
296   - .andExpect(status().isOk());
297   -
298   - DeviceCredentials foundDeviceCredentials =
  301 + .andExpect(status().isOk());
  302 +
  303 + DeviceCredentials foundDeviceCredentials =
299 304 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
300   -
  305 +
301 306 Assert.assertEquals(deviceCredentials, foundDeviceCredentials);
302 307 }
303   -
  308 +
304 309 @Test
305 310 public void testSaveDeviceCredentialsWithEmptyDevice() throws Exception {
306 311 DeviceCredentials deviceCredentials = new DeviceCredentials();
307 312 doPost("/api/device/credentials", deviceCredentials)
308   - .andExpect(status().isBadRequest());
  313 + .andExpect(status().isBadRequest());
309 314 }
310   -
  315 +
311 316 @Test
312 317 public void testSaveDeviceCredentialsWithEmptyCredentialsType() throws Exception {
313 318 Device device = new Device();
314 319 device.setName("My device");
315 320 device.setType("default");
316 321 Device savedDevice = doPost("/api/device", device, Device.class);
317   - DeviceCredentials deviceCredentials =
  322 + DeviceCredentials deviceCredentials =
318 323 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
319 324 deviceCredentials.setCredentialsType(null);
320 325 doPost("/api/device/credentials", deviceCredentials)
321   - .andExpect(status().isBadRequest())
322   - .andExpect(statusReason(containsString("Device credentials type should be specified")));
  326 + .andExpect(status().isBadRequest())
  327 + .andExpect(statusReason(containsString("Device credentials type should be specified")));
323 328 }
324   -
  329 +
325 330 @Test
326 331 public void testSaveDeviceCredentialsWithEmptyCredentialsId() throws Exception {
327 332 Device device = new Device();
328 333 device.setName("My device");
329 334 device.setType("default");
330 335 Device savedDevice = doPost("/api/device", device, Device.class);
331   - DeviceCredentials deviceCredentials =
  336 + DeviceCredentials deviceCredentials =
332 337 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
333 338 deviceCredentials.setCredentialsId(null);
334 339 doPost("/api/device/credentials", deviceCredentials)
335   - .andExpect(status().isBadRequest())
336   - .andExpect(statusReason(containsString("Device credentials id should be specified")));
  340 + .andExpect(status().isBadRequest())
  341 + .andExpect(statusReason(containsString("Device credentials id should be specified")));
337 342 }
338   -
  343 +
339 344 @Test
340 345 public void testSaveNonExistentDeviceCredentials() throws Exception {
341 346 Device device = new Device();
342 347 device.setName("My device");
343 348 device.setType("default");
344 349 Device savedDevice = doPost("/api/device", device, Device.class);
345   - DeviceCredentials deviceCredentials =
  350 + DeviceCredentials deviceCredentials =
346 351 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
347 352 DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased()));
348 353 newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
... ... @@ -350,29 +355,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
350 355 newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
351 356 newDeviceCredentials.setCredentialsId(deviceCredentials.getCredentialsId());
352 357 doPost("/api/device/credentials", newDeviceCredentials)
353   - .andExpect(status().isBadRequest())
354   - .andExpect(statusReason(containsString("Unable to update non-existent device credentials")));
  358 + .andExpect(status().isBadRequest())
  359 + .andExpect(statusReason(containsString("Unable to update non-existent device credentials")));
355 360 }
356   -
  361 +
357 362 @Test
358 363 public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception {
359 364 Device device = new Device();
360 365 device.setName("My device");
361 366 device.setType("default");
362 367 Device savedDevice = doPost("/api/device", device, Device.class);
363   - DeviceCredentials deviceCredentials =
  368 + DeviceCredentials deviceCredentials =
364 369 doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
365 370 deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased()));
366 371 doPost("/api/device/credentials", deviceCredentials)
367   - .andExpect(status().isNotFound());
  372 + .andExpect(status().isNotFound());
368 373 }
369 374
370 375 @Test
371 376 public void testFindTenantDevices() throws Exception {
372 377 List<Device> devices = new ArrayList<>();
373   - for (int i=0;i<178;i++) {
  378 + for (int i = 0; i < 178; i++) {
374 379 Device device = new Device();
375   - device.setName("Device"+i);
  380 + device.setName("Device" + i);
376 381 device.setType("default");
377 382 devices.add(doPost("/api/device", device, Device.class));
378 383 }
... ... @@ -380,28 +385,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
380 385 PageLink pageLink = new PageLink(23);
381 386 PageData<Device> pageData = null;
382 387 do {
383   - pageData = doGetTypedWithPageLink("/api/tenant/devices?",
  388 + pageData = doGetTypedWithPageLink("/api/tenant/devices?",
384 389 new TypeReference<PageData<Device>>(){}, pageLink);
  390 +
385 391 loadedDevices.addAll(pageData.getData());
386 392 if (pageData.hasNext()) {
387 393 pageLink = pageLink.nextPageLink();
388 394 }
389 395 } while (pageData.hasNext());
390   -
  396 +
391 397 Collections.sort(devices, idComparator);
392 398 Collections.sort(loadedDevices, idComparator);
393   -
  399 +
394 400 Assert.assertEquals(devices, loadedDevices);
395 401 }
396   -
  402 +
397 403 @Test
398 404 public void testFindTenantDevicesByName() throws Exception {
399 405 String title1 = "Device title 1";
400 406 List<Device> devicesTitle1 = new ArrayList<>();
401   - for (int i=0;i<143;i++) {
  407 + for (int i = 0; i < 143; i++) {
402 408 Device device = new Device();
403 409 String suffix = RandomStringUtils.randomAlphanumeric(15);
404   - String name = title1+suffix;
  410 + String name = title1 + suffix;
405 411 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
406 412 device.setName(name);
407 413 device.setType("default");
... ... @@ -409,37 +415,37 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
409 415 }
410 416 String title2 = "Device title 2";
411 417 List<Device> devicesTitle2 = new ArrayList<>();
412   - for (int i=0;i<75;i++) {
  418 + for (int i = 0; i < 75; i++) {
413 419 Device device = new Device();
414 420 String suffix = RandomStringUtils.randomAlphanumeric(15);
415   - String name = title2+suffix;
  421 + String name = title2 + suffix;
416 422 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
417 423 device.setName(name);
418 424 device.setType("default");
419 425 devicesTitle2.add(doPost("/api/device", device, Device.class));
420 426 }
421   -
  427 +
422 428 List<Device> loadedDevicesTitle1 = new ArrayList<>();
423 429 PageLink pageLink = new PageLink(15, 0, title1);
424 430 PageData<Device> pageData = null;
425 431 do {
426   - pageData = doGetTypedWithPageLink("/api/tenant/devices?",
  432 + pageData = doGetTypedWithPageLink("/api/tenant/devices?",
427 433 new TypeReference<PageData<Device>>(){}, pageLink);
428 434 loadedDevicesTitle1.addAll(pageData.getData());
429 435 if (pageData.hasNext()) {
430 436 pageLink = pageLink.nextPageLink();
431 437 }
432 438 } while (pageData.hasNext());
433   -
  439 +
434 440 Collections.sort(devicesTitle1, idComparator);
435 441 Collections.sort(loadedDevicesTitle1, idComparator);
436   -
  442 +
437 443 Assert.assertEquals(devicesTitle1, loadedDevicesTitle1);
438   -
  444 +
439 445 List<Device> loadedDevicesTitle2 = new ArrayList<>();
440 446 pageLink = new PageLink(4, 0, title2);
441 447 do {
442   - pageData = doGetTypedWithPageLink("/api/tenant/devices?",
  448 + pageData = doGetTypedWithPageLink("/api/tenant/devices?",
443 449 new TypeReference<PageData<Device>>(){}, pageLink);
444 450 loadedDevicesTitle2.addAll(pageData.getData());
445 451 if (pageData.hasNext()) {
... ... @@ -449,25 +455,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
449 455
450 456 Collections.sort(devicesTitle2, idComparator);
451 457 Collections.sort(loadedDevicesTitle2, idComparator);
452   -
  458 +
453 459 Assert.assertEquals(devicesTitle2, loadedDevicesTitle2);
454   -
  460 +
455 461 for (Device device : loadedDevicesTitle1) {
456   - doDelete("/api/device/"+device.getId().getId().toString())
457   - .andExpect(status().isOk());
  462 + doDelete("/api/device/" + device.getId().getId().toString())
  463 + .andExpect(status().isOk());
458 464 }
459   -
460 465 pageLink = new PageLink(4, 0, title1);
461 466 pageData = doGetTypedWithPageLink("/api/tenant/devices?",
462 467 new TypeReference<PageData<Device>>(){}, pageLink);
463 468 Assert.assertFalse(pageData.hasNext());
464 469 Assert.assertEquals(0, pageData.getData().size());
465   -
  470 +
466 471 for (Device device : loadedDevicesTitle2) {
467   - doDelete("/api/device/"+device.getId().getId().toString())
468   - .andExpect(status().isOk());
  472 + doDelete("/api/device/" + device.getId().getId().toString())
  473 + .andExpect(status().isOk());
469 474 }
470   -
471 475 pageLink = new PageLink(4, 0, title2);
472 476 pageData = doGetTypedWithPageLink("/api/tenant/devices?",
473 477 new TypeReference<PageData<Device>>(){}, pageLink);
... ... @@ -480,10 +484,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
480 484 String title1 = "Device title 1";
481 485 String type1 = "typeA";
482 486 List<Device> devicesType1 = new ArrayList<>();
483   - for (int i=0;i<143;i++) {
  487 + for (int i = 0; i < 143; i++) {
484 488 Device device = new Device();
485 489 String suffix = RandomStringUtils.randomAlphanumeric(15);
486   - String name = title1+suffix;
  490 + String name = title1 + suffix;
487 491 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
488 492 device.setName(name);
489 493 device.setType(type1);
... ... @@ -492,10 +496,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
492 496 String title2 = "Device title 2";
493 497 String type2 = "typeB";
494 498 List<Device> devicesType2 = new ArrayList<>();
495   - for (int i=0;i<75;i++) {
  499 + for (int i = 0; i < 75; i++) {
496 500 Device device = new Device();
497 501 String suffix = RandomStringUtils.randomAlphanumeric(15);
498   - String name = title2+suffix;
  502 + String name = title2 + suffix;
499 503 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
500 504 device.setName(name);
501 505 device.setType(type2);
... ... @@ -536,7 +540,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
536 540 Assert.assertEquals(devicesType2, loadedDevicesType2);
537 541
538 542 for (Device device : loadedDevicesType1) {
539   - doDelete("/api/device/"+device.getId().getId().toString())
  543 + doDelete("/api/device/" + device.getId().getId().toString())
540 544 .andExpect(status().isOk());
541 545 }
542 546
... ... @@ -547,7 +551,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
547 551 Assert.assertEquals(0, pageData.getData().size());
548 552
549 553 for (Device device : loadedDevicesType2) {
550   - doDelete("/api/device/"+device.getId().getId().toString())
  554 + doDelete("/api/device/" + device.getId().getId().toString())
551 555 .andExpect(status().isOk());
552 556 }
553 557
... ... @@ -557,42 +561,42 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
557 561 Assert.assertFalse(pageData.hasNext());
558 562 Assert.assertEquals(0, pageData.getData().size());
559 563 }
560   -
  564 +
561 565 @Test
562 566 public void testFindCustomerDevices() throws Exception {
563 567 Customer customer = new Customer();
564 568 customer.setTitle("Test customer");
565 569 customer = doPost("/api/customer", customer, Customer.class);
566 570 CustomerId customerId = customer.getId();
567   -
  571 +
568 572 List<Device> devices = new ArrayList<>();
569   - for (int i=0;i<128;i++) {
  573 + for (int i = 0; i < 128; i++) {
570 574 Device device = new Device();
571   - device.setName("Device"+i);
  575 + device.setName("Device" + i);
572 576 device.setType("default");
573 577 device = doPost("/api/device", device, Device.class);
574   - devices.add(doPost("/api/customer/" + customerId.getId().toString()
575   - + "/device/" + device.getId().getId().toString(), Device.class));
  578 + devices.add(doPost("/api/customer/" + customerId.getId().toString()
  579 + + "/device/" + device.getId().getId().toString(), Device.class));
576 580 }
577   -
  581 +
578 582 List<Device> loadedDevices = new ArrayList<>();
579 583 PageLink pageLink = new PageLink(23);
580 584 PageData<Device> pageData = null;
581 585 do {
582   - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
  586 + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
583 587 new TypeReference<PageData<Device>>(){}, pageLink);
584 588 loadedDevices.addAll(pageData.getData());
585 589 if (pageData.hasNext()) {
586 590 pageLink = pageLink.nextPageLink();
587 591 }
588 592 } while (pageData.hasNext());
589   -
  593 +
590 594 Collections.sort(devices, idComparator);
591 595 Collections.sort(loadedDevices, idComparator);
592   -
  596 +
593 597 Assert.assertEquals(devices, loadedDevices);
594 598 }
595   -
  599 +
596 600 @Test
597 601 public void testFindCustomerDevicesByName() throws Exception {
598 602 Customer customer = new Customer();
... ... @@ -602,52 +606,52 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
602 606
603 607 String title1 = "Device title 1";
604 608 List<Device> devicesTitle1 = new ArrayList<>();
605   - for (int i=0;i<125;i++) {
  609 + for (int i = 0; i < 125; i++) {
606 610 Device device = new Device();
607 611 String suffix = RandomStringUtils.randomAlphanumeric(15);
608   - String name = title1+suffix;
  612 + String name = title1 + suffix;
609 613 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
610 614 device.setName(name);
611 615 device.setType("default");
612 616 device = doPost("/api/device", device, Device.class);
613   - devicesTitle1.add(doPost("/api/customer/" + customerId.getId().toString()
  617 + devicesTitle1.add(doPost("/api/customer/" + customerId.getId().toString()
614 618 + "/device/" + device.getId().getId().toString(), Device.class));
615 619 }
616 620 String title2 = "Device title 2";
617 621 List<Device> devicesTitle2 = new ArrayList<>();
618   - for (int i=0;i<143;i++) {
  622 + for (int i = 0; i < 143; i++) {
619 623 Device device = new Device();
620 624 String suffix = RandomStringUtils.randomAlphanumeric(15);
621   - String name = title2+suffix;
  625 + String name = title2 + suffix;
622 626 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
623 627 device.setName(name);
624 628 device.setType("default");
625 629 device = doPost("/api/device", device, Device.class);
626   - devicesTitle2.add(doPost("/api/customer/" + customerId.getId().toString()
  630 + devicesTitle2.add(doPost("/api/customer/" + customerId.getId().toString()
627 631 + "/device/" + device.getId().getId().toString(), Device.class));
628 632 }
629   -
  633 +
630 634 List<Device> loadedDevicesTitle1 = new ArrayList<>();
631 635 PageLink pageLink = new PageLink(15, 0, title1);
632 636 PageData<Device> pageData = null;
633 637 do {
634   - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
  638 + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
635 639 new TypeReference<PageData<Device>>(){}, pageLink);
636 640 loadedDevicesTitle1.addAll(pageData.getData());
637 641 if (pageData.hasNext()) {
638 642 pageLink = pageLink.nextPageLink();
639 643 }
640 644 } while (pageData.hasNext());
641   -
  645 +
642 646 Collections.sort(devicesTitle1, idComparator);
643 647 Collections.sort(loadedDevicesTitle1, idComparator);
644   -
  648 +
645 649 Assert.assertEquals(devicesTitle1, loadedDevicesTitle1);
646   -
  650 +
647 651 List<Device> loadedDevicesTitle2 = new ArrayList<>();
648 652 pageLink = new PageLink(4, 0, title2);
649 653 do {
650   - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
  654 + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
651 655 new TypeReference<PageData<Device>>(){}, pageLink);
652 656 loadedDevicesTitle2.addAll(pageData.getData());
653 657 if (pageData.hasNext()) {
... ... @@ -657,25 +661,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
657 661
658 662 Collections.sort(devicesTitle2, idComparator);
659 663 Collections.sort(loadedDevicesTitle2, idComparator);
660   -
  664 +
661 665 Assert.assertEquals(devicesTitle2, loadedDevicesTitle2);
662   -
  666 +
663 667 for (Device device : loadedDevicesTitle1) {
664 668 doDelete("/api/customer/device/" + device.getId().getId().toString())
665   - .andExpect(status().isOk());
  669 + .andExpect(status().isOk());
666 670 }
667   -
668 671 pageLink = new PageLink(4, 0, title1);
669 672 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
670 673 new TypeReference<PageData<Device>>(){}, pageLink);
671 674 Assert.assertFalse(pageData.hasNext());
672 675 Assert.assertEquals(0, pageData.getData().size());
673   -
  676 +
674 677 for (Device device : loadedDevicesTitle2) {
675 678 doDelete("/api/customer/device/" + device.getId().getId().toString())
676   - .andExpect(status().isOk());
  679 + .andExpect(status().isOk());
677 680 }
678   -
679 681 pageLink = new PageLink(4, 0, title2);
680 682 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?",
681 683 new TypeReference<PageData<Device>>(){}, pageLink);
... ... @@ -693,10 +695,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
693 695 String title1 = "Device title 1";
694 696 String type1 = "typeC";
695 697 List<Device> devicesType1 = new ArrayList<>();
696   - for (int i=0;i<125;i++) {
  698 + for (int i = 0; i < 125; i++) {
697 699 Device device = new Device();
698 700 String suffix = RandomStringUtils.randomAlphanumeric(15);
699   - String name = title1+suffix;
  701 + String name = title1 + suffix;
700 702 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
701 703 device.setName(name);
702 704 device.setType(type1);
... ... @@ -707,10 +709,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
707 709 String title2 = "Device title 2";
708 710 String type2 = "typeD";
709 711 List<Device> devicesType2 = new ArrayList<>();
710   - for (int i=0;i<143;i++) {
  712 + for (int i = 0; i < 143; i++) {
711 713 Device device = new Device();
712 714 String suffix = RandomStringUtils.randomAlphanumeric(15);
713   - String name = title2+suffix;
  715 + String name = title2 + suffix;
714 716 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
715 717 device.setName(name);
716 718 device.setType(type2);
... ... @@ -775,4 +777,54 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
775 777 Assert.assertEquals(0, pageData.getData().size());
776 778 }
777 779
  780 + @Test
  781 + public void testAssignDeviceToTenant() throws Exception {
  782 + Device device = new Device();
  783 + device.setName("My device");
  784 + device.setType("default");
  785 + Device savedDevice = doPost("/api/device", device, Device.class);
  786 +
  787 + Device anotherDevice = new Device();
  788 + anotherDevice.setName("My device1");
  789 + anotherDevice.setType("default");
  790 + Device savedAnotherDevice = doPost("/api/device", anotherDevice, Device.class);
  791 +
  792 + EntityRelation relation = new EntityRelation();
  793 + relation.setFrom(savedDevice.getId());
  794 + relation.setTo(savedAnotherDevice.getId());
  795 + relation.setTypeGroup(RelationTypeGroup.COMMON);
  796 + relation.setType("Contains");
  797 + doPost("/api/relation", relation).andExpect(status().isOk());
  798 +
  799 + loginSysAdmin();
  800 + Tenant tenant = new Tenant();
  801 + tenant.setTitle("Different tenant");
  802 + Tenant savedDifferentTenant = doPost("/api/tenant", tenant, Tenant.class);
  803 + Assert.assertNotNull(savedDifferentTenant);
  804 +
  805 + User user = new User();
  806 + user.setAuthority(Authority.TENANT_ADMIN);
  807 + user.setTenantId(savedDifferentTenant.getId());
  808 + user.setEmail("tenant9@thingsboard.org");
  809 + user.setFirstName("Sam");
  810 + user.setLastName("Downs");
  811 +
  812 + createUserAndLogin(user, "testPassword1");
  813 +
  814 + login("tenant2@thingsboard.org", "testPassword1");
  815 + Device assignedDevice = doPost("/api/tenant/" + savedDifferentTenant.getId().getId() + "/device/" + savedDevice.getId().getId(), Device.class);
  816 +
  817 + doGet("/api/device/" + assignedDevice.getId().getId().toString(), Device.class, status().isNotFound());
  818 +
  819 + login("tenant9@thingsboard.org", "testPassword1");
  820 +
  821 + Device foundDevice1 = doGet("/api/device/" + assignedDevice.getId().getId().toString(), Device.class);
  822 + Assert.assertNotNull(foundDevice1);
  823 +
  824 + doGet("/api/relation?fromId=" + savedDevice.getId().getId() + "&fromType=DEVICE&relationType=Contains&toId=" + savedAnotherDevice.getId().getId() + "&toType=DEVICE", EntityRelation.class, status().isNotFound());
  825 +
  826 + loginSysAdmin();
  827 + doDelete("/api/tenant/" + savedDifferentTenant.getId().getId().toString())
  828 + .andExpect(status().isOk());
  829 + }
778 830 }
... ...
... ... @@ -41,7 +41,9 @@ public class MqttNoSqlTestSuite {
41 41 public static CustomCassandraCQLUnit cassandraUnit =
42 42 new CustomCassandraCQLUnit(
43 43 Arrays.asList(
44   - new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false)),
  44 + new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false),
  45 + new ClassPathCQLDataSet("cassandra/schema-ts-latest.cql", false, false)
  46 + ),
45 47 "cassandra-test.yaml", 30000l);
46 48
47 49 @BeforeClass
... ...
... ... @@ -16,14 +16,12 @@
16 16 package org.thingsboard.server.dao.audit;
17 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19   -import org.thingsboard.server.common.data.BaseData;
20 19 import org.thingsboard.server.common.data.HasName;
21 20 import org.thingsboard.server.common.data.audit.ActionType;
22 21 import org.thingsboard.server.common.data.audit.AuditLog;
23 22 import org.thingsboard.server.common.data.id.CustomerId;
24 23 import org.thingsboard.server.common.data.id.EntityId;
25 24 import org.thingsboard.server.common.data.id.TenantId;
26   -import org.thingsboard.server.common.data.id.UUIDBased;
27 25 import org.thingsboard.server.common.data.id.UserId;
28 26 import org.thingsboard.server.common.data.page.PageData;
29 27 import org.thingsboard.server.common.data.page.TimePageLink;
... ... @@ -49,5 +47,4 @@ public interface AuditLogService {
49 47 E entity,
50 48 ActionType actionType,
51 49 Exception e, Object... additionalInfo);
52   -
53 50 }
... ...
... ... @@ -76,4 +76,6 @@ public interface DeviceService {
76 76
77 77 ListenableFuture<List<EntitySubtype>> findDeviceTypesByTenantId(TenantId tenantId);
78 78
  79 + Device assignDeviceToTenant(TenantId tenantId, Device device);
  80 +
79 81 }
... ...
... ... @@ -41,4 +41,6 @@ public interface EventService {
41 41
42 42 List<Event> findLatestEvents(TenantId tenantId, EntityId entityId, String eventType, int limit);
43 43
  44 + void removeEvents(TenantId tenantId, EntityId entityId);
  45 +
44 46 }
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
24 24 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
25 25
26 26 import java.util.List;
27   -import java.util.concurrent.ExecutionException;
28 27
29 28 /**
30 29 * Created by ashvayka on 27.04.17.
... ... @@ -77,6 +76,8 @@ public interface RelationService {
77 76
78 77 ListenableFuture<List<EntityRelationInfo>> findInfoByQuery(TenantId tenantId, EntityRelationsQuery query);
79 78
  79 + void removeRelations(TenantId tenantId, EntityId entityId);
  80 +
80 81 // TODO: This method may be useful for some validations in the future
81 82 // ListenableFuture<Boolean> checkRecursiveRelation(EntityId from, EntityId to);
82 83
... ...
... ... @@ -21,6 +21,6 @@ import java.lang.annotation.Retention;
21 21 import java.lang.annotation.RetentionPolicy;
22 22
23 23 @Retention(RetentionPolicy.RUNTIME)
24   -@ConditionalOnExpression("'${database.ts.type}'=='cassandra' || '${database.entities.type}'=='cassandra'")
  24 +@ConditionalOnExpression("'${database.ts.type}'=='cassandra' || '${database.ts_latest.type}'=='cassandra'")
25 25 public @interface NoSqlAnyDao {
26 26 }
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/util/NoSqlTsLatestDao.java renamed from common/dao-api/src/main/java/org/thingsboard/server/dao/util/SqlDao.java
... ... @@ -15,9 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.dao.util;
17 17
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +
18 20 import java.lang.annotation.Retention;
19 21 import java.lang.annotation.RetentionPolicy;
20 22
21 23 @Retention(RetentionPolicy.RUNTIME)
22   -public @interface SqlDao {
  24 +@ConditionalOnProperty(prefix = "database.ts_latest", value = "type", havingValue = "cassandra")
  25 +public @interface NoSqlTsLatestDao {
23 26 }
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/util/PsqlTsLatestAnyDao.java renamed from common/dao-api/src/main/java/org/thingsboard/server/dao/util/PsqlTsAnyDao.java
... ... @@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
21 21 import java.lang.annotation.RetentionPolicy;
22 22
23 23 @Retention(RetentionPolicy.RUNTIME)
24   -@ConditionalOnExpression("('${database.ts.type}'=='sql' || '${database.ts.type}'=='timescale') " +
  24 +@ConditionalOnExpression("('${database.ts_latest.type}'=='sql' || '${database.ts_latest.type}'=='timescale') " +
25 25 "&& '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'")
26   -public @interface PsqlTsAnyDao {
  26 +public @interface PsqlTsLatestAnyDao {
27 27 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
  19 +
  20 +import java.lang.annotation.Retention;
  21 +import java.lang.annotation.RetentionPolicy;
  22 +
  23 +@Retention(RetentionPolicy.RUNTIME)
  24 +@ConditionalOnExpression("'${database.ts_latest.type}'=='sql' || '${database.ts_latest.type}'=='timescale'")
  25 +public @interface SqlTsLatestAnyDao {
  26 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +
  20 +import java.lang.annotation.Retention;
  21 +import java.lang.annotation.RetentionPolicy;
  22 +
  23 +@Retention(RetentionPolicy.RUNTIME)
  24 +@ConditionalOnProperty(prefix = "database.ts_latest", value = "type", havingValue = "sql")
  25 +public @interface SqlTsLatestDao {
  26 +}
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/util/SqlTsOrTsLatestAnyDao.java renamed from common/dao-api/src/main/java/org/thingsboard/server/dao/util/SqlTsAnyDao.java
... ... @@ -21,6 +21,6 @@ import java.lang.annotation.Retention;
21 21 import java.lang.annotation.RetentionPolicy;
22 22
23 23 @Retention(RetentionPolicy.RUNTIME)
24   -@ConditionalOnExpression("'${database.ts.type}'=='sql' || '${database.ts.type}'=='timescale'")
25   -public @interface SqlTsAnyDao {
  24 +@ConditionalOnExpression("'${database.ts.type}'=='sql' || '${database.ts.type}'=='timescale' || '${database.ts_latest.type}'=='sql' || '${database.ts_latest.type}'=='timescale'")
  25 +public @interface SqlTsOrTsLatestAnyDao {
26 26 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.util;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +
  20 +import java.lang.annotation.Retention;
  21 +import java.lang.annotation.RetentionPolicy;
  22 +
  23 +@Retention(RetentionPolicy.RUNTIME)
  24 +@ConditionalOnProperty(prefix = "database.ts_latest", value = "type", havingValue = "timescale")
  25 +public @interface TimescaleDBTsLatestDao {
  26 +}
... ...
common/dao-api/src/main/java/org/thingsboard/server/dao/util/TimescaleDBTsOrTsLatestDao.java renamed from common/dao-api/src/main/java/org/thingsboard/server/dao/util/PsqlTsDao.java
... ... @@ -21,5 +21,6 @@ import java.lang.annotation.Retention;
21 21 import java.lang.annotation.RetentionPolicy;
22 22
23 23 @Retention(RetentionPolicy.RUNTIME)
24   -@ConditionalOnExpression("'${database.ts.type}'=='sql' && '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'")
25   -public @interface PsqlTsDao { }
\ No newline at end of file
  24 +@ConditionalOnExpression("'${database.ts.type}'=='timescale' || '${database.ts_latest.type}'=='timescale'")
  25 +public @interface TimescaleDBTsOrTsLatestDao {
  26 +}
... ...
... ... @@ -57,6 +57,8 @@ public class DataConstants {
57 57 public static final String ATTRIBUTES_DELETED = "ATTRIBUTES_DELETED";
58 58 public static final String ALARM_ACK = "ALARM_ACK";
59 59 public static final String ALARM_CLEAR = "ALARM_CLEAR";
  60 + public static final String ENTITY_ASSIGNED_FROM_TENANT = "ENTITY_ASSIGNED_FROM_TENANT";
  61 + public static final String ENTITY_ASSIGNED_TO_TENANT = "ENTITY_ASSIGNED_TO_TENANT";
60 62
61 63 public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE";
62 64
... ...
... ... @@ -40,7 +40,9 @@ public enum ActionType {
40 40 ALARM_CLEAR(false),
41 41 LOGIN(false),
42 42 LOGOUT(false),
43   - LOCKOUT(false);
  43 + LOCKOUT(false),
  44 + ASSIGNED_FROM_TENANT(false),
  45 + ASSIGNED_TO_TENANT(false);
44 46
45 47 private final boolean isRead;
46 48
... ...
... ... @@ -27,8 +27,8 @@ import org.thingsboard.server.dao.util.SqlTsDao;
27 27 @Configuration
28 28 @EnableAutoConfiguration
29 29 @ComponentScan({"org.thingsboard.server.dao.sqlts.hsql"})
30   -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.hsql", "org.thingsboard.server.dao.sqlts.insert.latest.hsql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"})
31   -@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.hsql"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts"})
32 32 @EnableTransactionManagement
33 33 @SqlTsDao
34 34 @HsqlDao
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao;
  17 +
  18 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  19 +import org.springframework.boot.autoconfigure.domain.EntityScan;
  20 +import org.springframework.context.annotation.ComponentScan;
  21 +import org.springframework.context.annotation.Configuration;
  22 +import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  23 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  24 +import org.thingsboard.server.dao.util.HsqlDao;
  25 +import org.thingsboard.server.dao.util.SqlTsLatestDao;
  26 +
  27 +@Configuration
  28 +@EnableAutoConfiguration
  29 +@ComponentScan({"org.thingsboard.server.dao.sqlts.hsql"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.insert.latest.hsql", "org.thingsboard.server.dao.sqlts.latest"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.latest"})
  32 +@EnableTransactionManagement
  33 +@SqlTsLatestDao
  34 +@HsqlDao
  35 +public class HsqlTsLatestDaoConfig {
  36 +
  37 +}
... ...
... ... @@ -21,7 +21,6 @@ import org.springframework.context.annotation.ComponentScan;
21 21 import org.springframework.context.annotation.Configuration;
22 22 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
23 23 import org.springframework.transaction.annotation.EnableTransactionManagement;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24
26 25 /**
27 26 * @author Valerii Sosliuk
... ... @@ -32,7 +31,6 @@ import org.thingsboard.server.dao.util.SqlDao;
32 31 @EnableJpaRepositories("org.thingsboard.server.dao.sql")
33 32 @EntityScan("org.thingsboard.server.dao.model.sql")
34 33 @EnableTransactionManagement
35   -@SqlDao
36 34 public class JpaDaoConfig {
37 35
38 36 }
... ...
... ... @@ -27,11 +27,11 @@ import org.thingsboard.server.dao.util.SqlTsDao;
27 27 @Configuration
28 28 @EnableAutoConfiguration
29 29 @ComponentScan({"org.thingsboard.server.dao.sqlts.psql"})
30   -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.psql", "org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"})
31   -@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.psql"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts"})
32 32 @EnableTransactionManagement
33   -@SqlTsDao
34 33 @PsqlDao
  34 +@SqlTsDao
35 35 public class PsqlTsDaoConfig {
36 36
37 37 }
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao;
  17 +
  18 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  19 +import org.springframework.boot.autoconfigure.domain.EntityScan;
  20 +import org.springframework.context.annotation.ComponentScan;
  21 +import org.springframework.context.annotation.Configuration;
  22 +import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  23 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  24 +import org.thingsboard.server.dao.util.PsqlDao;
  25 +import org.thingsboard.server.dao.util.SqlTsLatestDao;
  26 +
  27 +@Configuration
  28 +@EnableAutoConfiguration
  29 +@ComponentScan({"org.thingsboard.server.dao.sqlts.psql"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.latest"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.latest"})
  32 +@EnableTransactionManagement
  33 +@SqlTsLatestDao
  34 +@PsqlDao
  35 +public class PsqlTsLatestDaoConfig {
  36 +
  37 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao;
  17 +
  18 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  19 +import org.springframework.boot.autoconfigure.domain.EntityScan;
  20 +import org.springframework.context.annotation.Configuration;
  21 +import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  22 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  23 +import org.thingsboard.server.dao.util.PsqlDao;
  24 +import org.thingsboard.server.dao.util.SqlTsOrTsLatestAnyDao;
  25 +
  26 +@Configuration
  27 +@EnableAutoConfiguration
  28 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.dictionary"})
  29 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.dictionary"})
  30 +@EnableTransactionManagement
  31 +@SqlTsOrTsLatestAnyDao
  32 +public class SqlTimeseriesDaoConfig {
  33 +
  34 +}
... ...
... ... @@ -27,8 +27,8 @@ import org.thingsboard.server.dao.util.TimescaleDBTsDao;
27 27 @Configuration
28 28 @EnableAutoConfiguration
29 29 @ComponentScan({"org.thingsboard.server.dao.sqlts.timescale"})
30   -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.timescale", "org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.insert.timescale", "org.thingsboard.server.dao.sqlts.dictionary", "org.thingsboard.server.dao.sqlts.latest"})
31   -@EntityScan({"org.thingsboard.server.dao.model.sqlts.timescale", "org.thingsboard.server.dao.model.sqlts.dictionary", "org.thingsboard.server.dao.model.sqlts.latest"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.timescale", "org.thingsboard.server.dao.sqlts.insert.timescale"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.timescale"})
32 32 @EnableTransactionManagement
33 33 @TimescaleDBTsDao
34 34 @PsqlDao
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao;
  17 +
  18 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  19 +import org.springframework.boot.autoconfigure.domain.EntityScan;
  20 +import org.springframework.context.annotation.ComponentScan;
  21 +import org.springframework.context.annotation.Configuration;
  22 +import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  23 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  24 +import org.thingsboard.server.dao.util.PsqlDao;
  25 +import org.thingsboard.server.dao.util.TimescaleDBTsLatestDao;
  26 +
  27 +@Configuration
  28 +@EnableAutoConfiguration
  29 +@ComponentScan({"org.thingsboard.server.dao.sqlts.timescale"})
  30 +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.latest"})
  31 +@EntityScan({"org.thingsboard.server.dao.model.sqlts.latest"})
  32 +@EnableTransactionManagement
  33 +@TimescaleDBTsLatestDao
  34 +@PsqlDao
  35 +public class TimescaleTsLatestDaoConfig {
  36 +
  37 +}
... ...
... ... @@ -163,7 +163,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
163 163 try {
164 164 List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get();
165 165 if (entityViews != null && !entityViews.isEmpty()) {
166   - throw new DataValidationException("Can't delete asset that is assigned to entity views!");
  166 + throw new DataValidationException("Can't delete asset that has entity views!");
167 167 }
168 168 } catch (ExecutionException | InterruptedException e) {
169 169 log.error("Exception while finding entity views for assetId [{}]", assetId, e);
... ...
... ... @@ -23,11 +23,12 @@ import org.thingsboard.server.common.data.id.EntityId;
23 23 import org.thingsboard.server.common.data.id.UserId;
24 24 import org.thingsboard.server.common.data.page.PageData;
25 25 import org.thingsboard.server.common.data.page.TimePageLink;
  26 +import org.thingsboard.server.dao.Dao;
26 27
27 28 import java.util.List;
28 29 import java.util.UUID;
29 30
30   -public interface AuditLogDao {
  31 +public interface AuditLogDao extends Dao<AuditLog> {
31 32
32 33 ListenableFuture<Void> saveByTenantId(AuditLog auditLog);
33 34
... ...
... ... @@ -163,6 +163,7 @@ public class AuditLogServiceImpl implements AuditLogService {
163 163 case ALARM_ACK:
164 164 case ALARM_CLEAR:
165 165 case RELATIONS_DELETED:
  166 + case ASSIGNED_TO_TENANT:
166 167 if (entity != null) {
167 168 ObjectNode entityNode = objectMapper.valueToTree(entity);
168 169 if (entityId.getEntityType() == EntityType.DASHBOARD) {
... ...
... ... @@ -58,5 +58,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService {
58 58 public <E extends HasName, I extends EntityId> ListenableFuture<List<Void>> logEntityAction(TenantId tenantId, CustomerId customerId, UserId userId, String userName, I entityId, E entity, ActionType actionType, Exception e, Object... additionalInfo) {
59 59 return null;
60 60 }
61   -
62 61 }
... ...
... ... @@ -166,4 +166,21 @@ public interface DeviceDao extends Dao<Device> {
166 166 * @return the list of tenant device type objects
167 167 */
168 168 ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId);
  169 +
  170 + /**
  171 + * Find devices by tenantId and device id.
  172 + * @param tenantId the tenant Id
  173 + * @param id the device Id
  174 + * @return the device object
  175 + */
  176 + Device findDeviceByTenantIdAndId(TenantId tenantId, UUID id);
  177 +
  178 + /**
  179 + * Find devices by tenantId and device id.
  180 + * @param tenantId tenantId the tenantId
  181 + * @param id the deviceId
  182 + * @return the device object
  183 + */
  184 + ListenableFuture<Device> findDeviceByTenantIdAndIdAsync(TenantId tenantId, UUID id);
  185 +
169 186 }
... ...
... ... @@ -28,6 +28,8 @@ import org.springframework.cache.CacheManager;
28 28 import org.springframework.cache.annotation.CacheEvict;
29 29 import org.springframework.cache.annotation.Cacheable;
30 30 import org.springframework.stereotype.Service;
  31 +import org.springframework.transaction.annotation.Transactional;
  32 +import org.springframework.util.CollectionUtils;
31 33 import org.springframework.util.StringUtils;
32 34 import org.thingsboard.server.common.data.Customer;
33 35 import org.thingsboard.server.common.data.Device;
... ... @@ -50,6 +52,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType;
50 52 import org.thingsboard.server.dao.customer.CustomerDao;
51 53 import org.thingsboard.server.dao.entity.AbstractEntityService;
52 54 import org.thingsboard.server.dao.entityview.EntityViewService;
  55 +import org.thingsboard.server.dao.event.EventService;
53 56 import org.thingsboard.server.dao.exception.DataValidationException;
54 57 import org.thingsboard.server.dao.service.DataValidator;
55 58 import org.thingsboard.server.dao.service.PaginatedRemover;
... ... @@ -98,6 +101,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
98 101 @Autowired
99 102 private CacheManager cacheManager;
100 103
  104 + @Autowired
  105 + private EventService eventService;
  106 +
101 107 @Override
102 108 public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) {
103 109 log.trace("Executing findDeviceInfoById [{}]", deviceId);
... ... @@ -109,14 +115,22 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
109 115 public Device findDeviceById(TenantId tenantId, DeviceId deviceId) {
110 116 log.trace("Executing findDeviceById [{}]", deviceId);
111 117 validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
112   - return deviceDao.findById(tenantId, deviceId.getId());
  118 + if (TenantId.SYS_TENANT_ID.equals(tenantId)) {
  119 + return deviceDao.findById(tenantId, deviceId.getId());
  120 + } else {
  121 + return deviceDao.findDeviceByTenantIdAndId(tenantId, deviceId.getId());
  122 + }
113 123 }
114 124
115 125 @Override
116 126 public ListenableFuture<Device> findDeviceByIdAsync(TenantId tenantId, DeviceId deviceId) {
117 127 log.trace("Executing findDeviceById [{}]", deviceId);
118 128 validateId(deviceId, INCORRECT_DEVICE_ID + deviceId);
119   - return deviceDao.findByIdAsync(tenantId, deviceId.getId());
  129 + if (TenantId.SYS_TENANT_ID.equals(tenantId)) {
  130 + return deviceDao.findByIdAsync(tenantId, deviceId.getId());
  131 + } else {
  132 + return deviceDao.findDeviceByTenantIdAndIdAsync(tenantId, deviceId.getId());
  133 + }
120 134 }
121 135
122 136 @Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #name}")
... ... @@ -187,7 +201,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
187 201 try {
188 202 List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get();
189 203 if (entityViews != null && !entityViews.isEmpty()) {
190   - throw new DataValidationException("Can't delete device that is assigned to entity views!");
  204 + throw new DataValidationException("Can't delete device that has entity views!");
191 205 }
192 206 } catch (ExecutionException | InterruptedException e) {
193 207 log.error("Exception while finding entity views for deviceId [{}]", deviceId, e);
... ... @@ -353,6 +367,31 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
353 367 }, MoreExecutors.directExecutor());
354 368 }
355 369
  370 + @Transactional
  371 + @CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}")
  372 + @Override
  373 + public Device assignDeviceToTenant(TenantId tenantId, Device device) {
  374 + log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device);
  375 +
  376 + try {
  377 + List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), device.getId()).get();
  378 + if (!CollectionUtils.isEmpty(entityViews)) {
  379 + throw new DataValidationException("Can't assign device that has entity views to another tenant!");
  380 + }
  381 + } catch (ExecutionException | InterruptedException e) {
  382 + log.error("Exception while finding entity views for deviceId [{}]", device.getId(), e);
  383 + throw new RuntimeException("Exception while finding entity views for deviceId [" + device.getId() + "]", e);
  384 + }
  385 +
  386 + eventService.removeEvents(device.getTenantId(), device.getId());
  387 +
  388 + relationService.removeRelations(device.getTenantId(), device.getId());
  389 +
  390 + device.setTenantId(tenantId);
  391 + device.setCustomerId(null);
  392 + return doSaveDevice(device, null);
  393 + }
  394 +
356 395 private DataValidator<Device> deviceValidator =
357 396 new DataValidator<Device>() {
358 397
... ...
... ... @@ -92,6 +92,21 @@ public class BaseEventService implements EventService {
92 92 return eventDao.findLatestEvents(tenantId.getId(), entityId, eventType, limit);
93 93 }
94 94
  95 + @Override
  96 + public void removeEvents(TenantId tenantId, EntityId entityId) {
  97 + PageData<Event> eventPageData;
  98 + TimePageLink eventPageLink = new TimePageLink(1000);
  99 + do {
  100 + eventPageData = findEvents(tenantId, entityId, eventPageLink);
  101 + for (Event event : eventPageData.getData()) {
  102 + eventDao.removeById(tenantId, event.getUuidId());
  103 + }
  104 + if (eventPageData.hasNext()) {
  105 + eventPageLink = eventPageLink.nextPageLink();
  106 + }
  107 + } while (eventPageData.hasNext());
  108 + }
  109 +
95 110 private DataValidator<Event> eventValidator =
96 111 new DataValidator<Event>() {
97 112 @Override
... ...
... ... @@ -506,6 +506,22 @@ public class BaseRelationService implements RelationService {
506 506 }, MoreExecutors.directExecutor());
507 507 }
508 508
  509 + @Override
  510 + public void removeRelations(TenantId tenantId, EntityId entityId) {
  511 + Cache cache = cacheManager.getCache(RELATIONS_CACHE);
  512 +
  513 + List<EntityRelation> relations = new ArrayList<>();
  514 + for (RelationTypeGroup relationTypeGroup : RelationTypeGroup.values()) {
  515 + relations.addAll(findByFrom(tenantId, entityId, relationTypeGroup));
  516 + relations.addAll(findByTo(tenantId, entityId, relationTypeGroup));
  517 + }
  518 +
  519 + for (EntityRelation relation : relations) {
  520 + cacheEviction(relation, cache);
  521 + deleteRelation(tenantId, relation);
  522 + }
  523 + }
  524 +
509 525 protected void validate(EntityRelation relation) {
510 526 if (relation == null) {
511 527 throw new DataValidationException("Relation type should be specified!");
... ...
... ... @@ -18,10 +18,8 @@ package org.thingsboard.server.dao.sql;
18 18 import org.springframework.beans.factory.annotation.Value;
19 19 import org.springframework.stereotype.Component;
20 20 import org.thingsboard.common.util.AbstractListeningExecutor;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23 22 @Component
24   -@SqlDao
25 23 public class JpaExecutorService extends AbstractListeningExecutor {
26 24
27 25 @Value("${spring.datasource.hikari.maximumPoolSize}")
... ...
... ... @@ -21,25 +21,15 @@ import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.CrudRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.common.data.alarm.AlarmStatus;
24   -import org.thingsboard.server.common.data.id.CustomerId;
25   -import org.thingsboard.server.common.data.id.EntityId;
26   -import org.thingsboard.server.common.data.id.TenantId;
27   -import org.thingsboard.server.common.data.page.PageData;
28   -import org.thingsboard.server.common.data.query.AlarmData;
29   -import org.thingsboard.server.common.data.query.AlarmDataQuery;
30 24 import org.thingsboard.server.dao.model.sql.AlarmEntity;
31 25 import org.thingsboard.server.dao.model.sql.AlarmInfoEntity;
32   -import org.thingsboard.server.dao.util.SqlDao;
33 26
34   -import java.util.Collection;
35 27 import java.util.List;
36   -import java.util.Set;
37 28 import java.util.UUID;
38 29
39 30 /**
40 31 * Created by Valerii Sosliuk on 5/21/2017.
41 32 */
42   -@SqlDao
43 33 public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> {
44 34
45 35 @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC")
... ...
... ... @@ -39,7 +39,6 @@ import org.thingsboard.server.dao.model.sql.AlarmEntity;
39 39 import org.thingsboard.server.dao.relation.RelationDao;
40 40 import org.thingsboard.server.dao.sql.JpaAbstractDao;
41 41 import org.thingsboard.server.dao.sql.query.AlarmQueryRepository;
42   -import org.thingsboard.server.dao.util.SqlDao;
43 42
44 43 import java.util.ArrayList;
45 44 import java.util.Collection;
... ... @@ -54,7 +53,6 @@ import java.util.UUID;
54 53 */
55 54 @Slf4j
56 55 @Component
57   -@SqlDao
58 56 public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements AlarmDao {
59 57
60 58 @Autowired
... ...
... ... @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.AssetEntity;
24 24 import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.List;
28 27 import java.util.UUID;
... ... @@ -30,7 +29,6 @@ import java.util.UUID;
30 29 /**
31 30 * Created by Valerii Sosliuk on 5/21/2017.
32 31 */
33   -@SqlDao
34 32 public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, UUID> {
35 33
36 34 @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
... ...
... ... @@ -31,7 +31,6 @@ import org.thingsboard.server.dao.asset.AssetDao;
31 31 import org.thingsboard.server.dao.model.sql.AssetEntity;
32 32 import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
33 33 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
34   -import org.thingsboard.server.dao.util.SqlDao;
35 34
36 35 import java.util.ArrayList;
37 36 import java.util.Collections;
... ... @@ -44,7 +43,6 @@ import java.util.UUID;
44 43 * Created by Valerii Sosliuk on 5/19/2017.
45 44 */
46 45 @Component
47   -@SqlDao
48 46 public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao {
49 47
50 48 @Autowired
... ...
... ... @@ -25,7 +25,6 @@ import org.springframework.transaction.TransactionStatus;
25 25 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
26 26 import org.springframework.transaction.support.TransactionTemplate;
27 27 import org.thingsboard.server.dao.model.sql.AttributeKvEntity;
28   -import org.thingsboard.server.dao.util.SqlDao;
29 28
30 29 import java.sql.PreparedStatement;
31 30 import java.sql.SQLException;
... ... @@ -35,7 +34,6 @@ import java.util.ArrayList;
35 34 import java.util.List;
36 35 import java.util.regex.Pattern;
37 36
38   -@SqlDao
39 37 @Repository
40 38 @Slf4j
41 39 public abstract class AttributeKvInsertRepository {
... ...
... ... @@ -23,12 +23,10 @@ import org.springframework.transaction.annotation.Transactional;
23 23 import org.thingsboard.server.common.data.EntityType;
24 24 import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey;
25 25 import org.thingsboard.server.dao.model.sql.AttributeKvEntity;
26   -import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 import java.util.List;
29 28 import java.util.UUID;
30 29
31   -@SqlDao
32 30 public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> {
33 31
34 32 @Query("SELECT a FROM AttributeKvEntity a WHERE a.id.entityType = :entityType " +
... ...
... ... @@ -19,12 +19,10 @@ import org.springframework.stereotype.Repository;
19 19 import org.springframework.transaction.annotation.Transactional;
20 20 import org.thingsboard.server.dao.model.sql.AttributeKvEntity;
21 21 import org.thingsboard.server.dao.util.HsqlDao;
22   -import org.thingsboard.server.dao.util.SqlDao;
23 22
24 23 import java.sql.Types;
25 24 import java.util.List;
26 25
27   -@SqlDao
28 26 @HsqlDao
29 27 @Repository
30 28 @Transactional
... ...
... ... @@ -34,7 +34,6 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
34 34 import org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent;
35 35 import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams;
36 36 import org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper;
37   -import org.thingsboard.server.dao.util.SqlDao;
38 37
39 38 import javax.annotation.PostConstruct;
40 39 import javax.annotation.PreDestroy;
... ... @@ -46,7 +45,6 @@ import java.util.stream.Collectors;
46 45
47 46 @Component
48 47 @Slf4j
49   -@SqlDao
50 48 public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService implements AttributesDao {
51 49
52 50 @Autowired
... ...
... ... @@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.attributes;
18 18 import org.springframework.stereotype.Repository;
19 19 import org.springframework.transaction.annotation.Transactional;
20 20 import org.thingsboard.server.dao.util.PsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23   -@SqlDao
24 22 @PsqlDao
25 23 @Repository
26 24 @Transactional
... ...
... ... @@ -30,14 +30,12 @@ import org.thingsboard.server.dao.DaoUtil;
30 30 import org.thingsboard.server.dao.audit.AuditLogDao;
31 31 import org.thingsboard.server.dao.model.sql.AuditLogEntity;
32 32 import org.thingsboard.server.dao.sql.JpaAbstractDao;
33   -import org.thingsboard.server.dao.util.SqlDao;
34 33
35 34 import java.util.List;
36 35 import java.util.Objects;
37 36 import java.util.UUID;
38 37
39 38 @Component
40   -@SqlDao
41 39 public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> implements AuditLogDao {
42 40
43 41 @Autowired
... ...
... ... @@ -23,14 +23,12 @@ import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.common.data.plugin.ComponentScope;
24 24 import org.thingsboard.server.common.data.plugin.ComponentType;
25 25 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
26   -import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 import java.util.UUID;
29 28
30 29 /**
31 30 * Created by Valerii Sosliuk on 5/6/2017.
32 31 */
33   -@SqlDao
34 32 public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, UUID> {
35 33
36 34 ComponentDescriptorEntity findByClazz(String clazz);
... ...
... ... @@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.component;
18 18 import org.springframework.stereotype.Repository;
19 19 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
20 20 import org.thingsboard.server.dao.util.HsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23 22 import javax.persistence.Query;
24 23
25   -@SqlDao
26 24 @HsqlDao
27 25 @Repository
28 26 public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository {
... ...
... ... @@ -31,7 +31,6 @@ import org.thingsboard.server.dao.DaoUtil;
31 31 import org.thingsboard.server.dao.component.ComponentDescriptorDao;
32 32 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
33 33 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
34   -import org.thingsboard.server.dao.util.SqlDao;
35 34
36 35 import java.util.Objects;
37 36 import java.util.Optional;
... ... @@ -41,7 +40,6 @@ import java.util.UUID;
41 40 * Created by Valerii Sosliuk on 5/6/2017.
42 41 */
43 42 @Component
44   -@SqlDao
45 43 public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor>
46 44 implements ComponentDescriptorDao {
47 45
... ...
... ... @@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.component;
18 18 import org.springframework.stereotype.Repository;
19 19 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
20 20 import org.thingsboard.server.dao.util.PsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23   -@SqlDao
24 22 @PsqlDao
25 23 @Repository
26 24 public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository {
... ...
... ... @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.CustomerEntity;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24
26 25 import java.util.UUID;
27 26
28 27 /**
29 28 * Created by Valerii Sosliuk on 5/6/2017.
30 29 */
31   -@SqlDao
32 30 public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, UUID> {
33 31
34 32 @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " +
... ...
... ... @@ -25,7 +25,6 @@ import org.thingsboard.server.dao.DaoUtil;
25 25 import org.thingsboard.server.dao.customer.CustomerDao;
26 26 import org.thingsboard.server.dao.model.sql.CustomerEntity;
27 27 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
28   -import org.thingsboard.server.dao.util.SqlDao;
29 28
30 29 import java.util.Objects;
31 30 import java.util.Optional;
... ... @@ -35,7 +34,6 @@ import java.util.UUID;
35 34 * Created by Valerii Sosliuk on 5/6/2017.
36 35 */
37 36 @Component
38   -@SqlDao
39 37 public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao {
40 38
41 39 @Autowired
... ...
... ... @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24
26 25 import java.util.UUID;
27 26
28 27 /**
29 28 * Created by Valerii Sosliuk on 5/6/2017.
30 29 */
31   -@SqlDao
32 30 public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, UUID> {
33 31
34 32 @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " +
... ...
... ... @@ -17,13 +17,11 @@ package org.thingsboard.server.dao.sql.dashboard;
17 17
18 18 import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.DashboardEntity;
20   -import org.thingsboard.server.dao.util.SqlDao;
21 20
22 21 import java.util.UUID;
23 22
24 23 /**
25 24 * Created by Valerii Sosliuk on 5/6/2017.
26 25 */
27   -@SqlDao
28 26 public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> {
29 27 }
... ...
... ... @@ -22,7 +22,6 @@ import org.thingsboard.server.common.data.Dashboard;
22 22 import org.thingsboard.server.dao.dashboard.DashboardDao;
23 23 import org.thingsboard.server.dao.model.sql.DashboardEntity;
24 24 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.UUID;
28 27
... ... @@ -30,7 +29,6 @@ import java.util.UUID;
30 29 * Created by Valerii Sosliuk on 5/6/2017.
31 30 */
32 31 @Component
33   -@SqlDao
34 32 public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao {
35 33
36 34 @Autowired
... ...
... ... @@ -27,7 +27,6 @@ import org.thingsboard.server.dao.dashboard.DashboardInfoDao;
27 27 import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
28 28 import org.thingsboard.server.dao.relation.RelationDao;
29 29 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
30   -import org.thingsboard.server.dao.util.SqlDao;
31 30
32 31 import java.util.Objects;
33 32 import java.util.UUID;
... ... @@ -37,7 +36,6 @@ import java.util.UUID;
37 36 */
38 37 @Slf4j
39 38 @Component
40   -@SqlDao
41 39 public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao {
42 40
43 41 @Autowired
... ...
... ... @@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.device;
17 17
18 18 import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
20   -import org.thingsboard.server.dao.util.SqlDao;
21 20
22 21 import java.util.UUID;
23 22
24 23 /**
25 24 * Created by Valerii Sosliuk on 5/6/2017.
26 25 */
27   -@SqlDao
28 26 public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> {
29 27
30 28 DeviceCredentialsEntity findByDeviceId(UUID deviceId);
... ...
... ... @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.DeviceEntity;
24 24 import org.thingsboard.server.dao.model.sql.DeviceInfoEntity;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.List;
28 27 import java.util.UUID;
... ... @@ -30,7 +29,6 @@ import java.util.UUID;
30 29 /**
31 30 * Created by Valerii Sosliuk on 5/6/2017.
32 31 */
33   -@SqlDao
34 32 public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, UUID> {
35 33
36 34 @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo) " +
... ... @@ -127,4 +125,7 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
127 125 List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds);
128 126
129 127 List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds);
  128 +
  129 + DeviceEntity findByTenantIdAndId(UUID tenantId, UUID id);
  130 +
130 131 }
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.dao.DaoUtil;
24 24 import org.thingsboard.server.dao.device.DeviceCredentialsDao;
25 25 import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
26 26 import org.thingsboard.server.dao.sql.JpaAbstractDao;
27   -import org.thingsboard.server.dao.util.SqlDao;
28 27
29 28 import java.util.UUID;
30 29
... ... @@ -32,7 +31,6 @@ import java.util.UUID;
32 31 * Created by Valerii Sosliuk on 5/6/2017.
33 32 */
34 33 @Component
35   -@SqlDao
36 34 public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao {
37 35
38 36 @Autowired
... ...
... ... @@ -32,7 +32,6 @@ import org.thingsboard.server.dao.device.DeviceDao;
32 32 import org.thingsboard.server.dao.model.sql.DeviceEntity;
33 33 import org.thingsboard.server.dao.model.sql.DeviceInfoEntity;
34 34 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
35   -import org.thingsboard.server.dao.util.SqlDao;
36 35
37 36 import java.util.ArrayList;
38 37 import java.util.Collections;
... ... @@ -45,7 +44,6 @@ import java.util.UUID;
45 44 * Created by Valerii Sosliuk on 5/6/2017.
46 45 */
47 46 @Component
48   -@SqlDao
49 47 public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao {
50 48
51 49 @Autowired
... ... @@ -175,6 +173,16 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
175 173 return service.submit(() -> convertTenantDeviceTypesToDto(tenantId, deviceRepository.findTenantDeviceTypes(tenantId)));
176 174 }
177 175
  176 + @Override
  177 + public Device findDeviceByTenantIdAndId(TenantId tenantId, UUID id) {
  178 + return DaoUtil.getData(deviceRepository.findByTenantIdAndId(tenantId.getId(), id));
  179 + }
  180 +
  181 + @Override
  182 + public ListenableFuture<Device> findDeviceByTenantIdAndIdAsync(TenantId tenantId, UUID id) {
  183 + return service.submit(() -> DaoUtil.getData(deviceRepository.findByTenantIdAndId(tenantId.getId(), id)));
  184 + }
  185 +
178 186 private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) {
179 187 List<EntitySubtype> list = Collections.emptyList();
180 188 if (types != null && !types.isEmpty()) {
... ...
... ... @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.EntityViewEntity;
24 24 import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.List;
28 27 import java.util.UUID;
... ... @@ -30,7 +29,6 @@ import java.util.UUID;
30 29 /**
31 30 * Created by Victor Basanets on 8/31/2017.
32 31 */
33   -@SqlDao
34 32 public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, UUID> {
35 33
36 34 @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
... ...
... ... @@ -31,7 +31,6 @@ import org.thingsboard.server.dao.entityview.EntityViewDao;
31 31 import org.thingsboard.server.dao.model.sql.EntityViewEntity;
32 32 import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity;
33 33 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
34   -import org.thingsboard.server.dao.util.SqlDao;
35 34
36 35 import java.util.ArrayList;
37 36 import java.util.Collections;
... ... @@ -44,7 +43,6 @@ import java.util.UUID;
44 43 * Created by Victor Basanets on 8/31/2017.
45 44 */
46 45 @Component
47   -@SqlDao
48 46 public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, EntityView>
49 47 implements EntityViewDao {
50 48
... ...
... ... @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.common.data.EntityType;
24 24 import org.thingsboard.server.dao.model.sql.EventEntity;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.List;
28 27 import java.util.UUID;
... ... @@ -30,7 +29,6 @@ import java.util.UUID;
30 29 /**
31 30 * Created by Valerii Sosliuk on 5/3/2017.
32 31 */
33   -@SqlDao
34 32 public interface EventRepository extends PagingAndSortingRepository<EventEntity, UUID> {
35 33
36 34 EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(UUID tenantId,
... ...
... ... @@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.event;
18 18 import org.springframework.stereotype.Repository;
19 19 import org.thingsboard.server.dao.model.sql.EventEntity;
20 20 import org.thingsboard.server.dao.util.HsqlDao;
21   -import org.thingsboard.server.dao.util.SqlDao;
22 21
23 22 import javax.persistence.Query;
24 23
25   -@SqlDao
26 24 @HsqlDao
27 25 @Repository
28 26 public class HsqlEventInsertRepository extends AbstractEventInsertRepository {
... ...
... ... @@ -21,7 +21,6 @@ import lombok.extern.slf4j.Slf4j;
21 21 import org.apache.commons.lang3.StringUtils;
22 22 import org.springframework.beans.factory.annotation.Autowired;
23 23 import org.springframework.data.domain.PageRequest;
24   -import org.springframework.data.jpa.domain.Specification;
25 24 import org.springframework.data.repository.CrudRepository;
26 25 import org.springframework.stereotype.Component;
27 26 import org.thingsboard.server.common.data.Event;
... ... @@ -34,10 +33,7 @@ import org.thingsboard.server.dao.DaoUtil;
34 33 import org.thingsboard.server.dao.event.EventDao;
35 34 import org.thingsboard.server.dao.model.sql.EventEntity;
36 35 import org.thingsboard.server.dao.sql.JpaAbstractDao;
37   -import org.thingsboard.server.dao.util.SqlDao;
38 36
39   -import javax.persistence.criteria.Predicate;
40   -import java.util.ArrayList;
41 37 import java.util.List;
42 38 import java.util.Objects;
43 39 import java.util.Optional;
... ... @@ -50,7 +46,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
50 46 */
51 47 @Slf4j
52 48 @Component
53   -@SqlDao
54 49 public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implements EventDao {
55 50
56 51 private final UUID systemTenantId = NULL_UUID;
... ...
... ... @@ -19,10 +19,8 @@ import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.stereotype.Repository;
20 20 import org.thingsboard.server.dao.model.sql.EventEntity;
21 21 import org.thingsboard.server.dao.util.PsqlDao;
22   -import org.thingsboard.server.dao.util.SqlDao;
23 22
24 23 @Slf4j
25   -@SqlDao
26 24 @PsqlDao
27 25 @Repository
28 26 public class PsqlEventInsertRepository extends AbstractEventInsertRepository {
... ...
... ... @@ -39,7 +39,6 @@ import org.thingsboard.server.common.data.query.EntityDataSortOrder;
39 39 import org.thingsboard.server.common.data.query.EntityKey;
40 40 import org.thingsboard.server.common.data.query.EntityKeyType;
41 41 import org.thingsboard.server.dao.model.ModelConstants;
42   -import org.thingsboard.server.dao.util.SqlDao;
43 42
44 43 import java.util.ArrayList;
45 44 import java.util.Arrays;
... ... @@ -52,7 +51,6 @@ import java.util.Objects;
52 51 import java.util.Set;
53 52 import java.util.stream.Collectors;
54 53
55   -@SqlDao
56 54 @Repository
57 55 @Slf4j
58 56 public class DefaultAlarmQueryRepository implements AlarmQueryRepository {
... ...
... ... @@ -50,7 +50,6 @@ import org.thingsboard.server.common.data.query.RelationsQueryFilter;
50 50 import org.thingsboard.server.common.data.query.SingleEntityFilter;
51 51 import org.thingsboard.server.common.data.relation.EntitySearchDirection;
52 52 import org.thingsboard.server.common.data.relation.EntityTypeFilter;
53   -import org.thingsboard.server.dao.util.SqlDao;
54 53
55 54 import java.util.Arrays;
56 55 import java.util.Collections;
... ... @@ -61,7 +60,6 @@ import java.util.Optional;
61 60 import java.util.UUID;
62 61 import java.util.stream.Collectors;
63 62
64   -@SqlDao
65 63 @Repository
66 64 @Slf4j
67 65 public class DefaultEntityQueryRepository implements EntityQueryRepository {
... ...
... ... @@ -24,10 +24,8 @@ import org.thingsboard.server.common.data.query.EntityCountQuery;
24 24 import org.thingsboard.server.common.data.query.EntityData;
25 25 import org.thingsboard.server.common.data.query.EntityDataQuery;
26 26 import org.thingsboard.server.dao.entity.EntityQueryDao;
27   -import org.thingsboard.server.dao.util.SqlDao;
28 27
29 28 @Component
30   -@SqlDao
31 29 public class JpaEntityQueryDao implements EntityQueryDao {
32 30
33 31 @Autowired
... ...
... ... @@ -20,12 +20,10 @@ import org.springframework.transaction.annotation.Transactional;
20 20 import org.thingsboard.server.dao.model.sql.RelationCompositeKey;
21 21 import org.thingsboard.server.dao.model.sql.RelationEntity;
22 22 import org.thingsboard.server.dao.util.HsqlDao;
23   -import org.thingsboard.server.dao.util.SqlDao;
24 23
25 24 import javax.persistence.Query;
26 25
27 26 @HsqlDao
28   -@SqlDao
29 27 @Repository
30 28 @Transactional
31 29 public class HsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository {
... ...
... ... @@ -30,7 +30,6 @@ import org.thingsboard.server.dao.model.sql.RelationCompositeKey;
30 30 import org.thingsboard.server.dao.model.sql.RelationEntity;
31 31 import org.thingsboard.server.dao.relation.RelationDao;
32 32 import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
33   -import org.thingsboard.server.dao.util.SqlDao;
34 33
35 34 import javax.persistence.criteria.Predicate;
36 35 import java.util.ArrayList;
... ... @@ -41,7 +40,6 @@ import java.util.List;
41 40 */
42 41 @Slf4j
43 42 @Component
44   -@SqlDao
45 43 public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService implements RelationDao {
46 44
47 45 @Autowired
... ...
... ... @@ -19,10 +19,8 @@ import org.springframework.stereotype.Repository;
19 19 import org.springframework.transaction.annotation.Transactional;
20 20 import org.thingsboard.server.dao.model.sql.RelationEntity;
21 21 import org.thingsboard.server.dao.util.PsqlDao;
22   -import org.thingsboard.server.dao.util.SqlDao;
23 22
24 23 @PsqlDao
25   -@SqlDao
26 24 @Repository
27 25 @Transactional
28 26 public class PsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository {
... ...
... ... @@ -20,12 +20,10 @@ import org.springframework.data.repository.CrudRepository;
20 20 import org.springframework.transaction.annotation.Transactional;
21 21 import org.thingsboard.server.dao.model.sql.RelationCompositeKey;
22 22 import org.thingsboard.server.dao.model.sql.RelationEntity;
23   -import org.thingsboard.server.dao.util.SqlDao;
24 23
25 24 import java.util.List;
26 25 import java.util.UUID;
27 26
28   -@SqlDao
29 27 public interface RelationRepository
30 28 extends CrudRepository<RelationEntity, RelationCompositeKey>, JpaSpecificationExecutor<RelationEntity> {
31 29
... ...
... ... @@ -26,14 +26,12 @@ import org.thingsboard.server.dao.DaoUtil;
26 26 import org.thingsboard.server.dao.model.sql.RuleChainEntity;
27 27 import org.thingsboard.server.dao.rule.RuleChainDao;
28 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
29   -import org.thingsboard.server.dao.util.SqlDao;
30 29
31 30 import java.util.Objects;
32 31 import java.util.UUID;
33 32
34 33 @Slf4j
35 34 @Component
36   -@SqlDao
37 35 public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao {
38 36
39 37 @Autowired
... ...
... ... @@ -23,11 +23,9 @@ import org.thingsboard.server.common.data.rule.RuleNode;
23 23 import org.thingsboard.server.dao.model.sql.RuleNodeEntity;
24 24 import org.thingsboard.server.dao.rule.RuleNodeDao;
25 25 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
26   -import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 @Slf4j
29 28 @Component
30   -@SqlDao
31 29 public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao {
32 30
33 31 @Autowired
... ...
... ... @@ -21,11 +21,9 @@ import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.RuleChainEntity;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24
26 25 import java.util.UUID;
27 26
28   -@SqlDao
29 27 public interface RuleChainRepository extends PagingAndSortingRepository<RuleChainEntity, UUID> {
30 28
31 29 @Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " +
... ...
... ... @@ -17,9 +17,7 @@ package org.thingsboard.server.dao.sql.rule;
17 17
18 18 import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.RuleNodeEntity;
20   -import org.thingsboard.server.dao.util.SqlDao;
21 20
22   -@SqlDao
23 21 public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> {
24 22
25 23 }
... ...
... ... @@ -25,13 +25,11 @@ import org.thingsboard.server.dao.DaoUtil;
25 25 import org.thingsboard.server.dao.model.sql.AdminSettingsEntity;
26 26 import org.thingsboard.server.dao.settings.AdminSettingsDao;
27 27 import org.thingsboard.server.dao.sql.JpaAbstractDao;
28   -import org.thingsboard.server.dao.util.SqlDao;
29 28
30 29 import java.util.UUID;
31 30
32 31 @Component
33 32 @Slf4j
34   -@SqlDao
35 33 public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao {
36 34
37 35 @Autowired
... ...
... ... @@ -26,7 +26,6 @@ import org.thingsboard.server.dao.DaoUtil;
26 26 import org.thingsboard.server.dao.model.sql.TenantEntity;
27 27 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
28 28 import org.thingsboard.server.dao.tenant.TenantDao;
29   -import org.thingsboard.server.dao.util.SqlDao;
30 29
31 30 import java.util.Objects;
32 31 import java.util.UUID;
... ... @@ -36,7 +35,6 @@ import java.util.UUID;
36 35 * Created by Valerii Sosliuk on 4/30/2017.
37 36 */
38 37 @Component
39   -@SqlDao
40 38 public class JpaTenantDao extends JpaAbstractSearchTextDao<TenantEntity, Tenant> implements TenantDao {
41 39
42 40 @Autowired
... ...
... ... @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.dao.model.sql.TenantEntity;
24   -import org.thingsboard.server.dao.util.SqlDao;
25 24
26 25 import java.util.UUID;
27 26
28 27 /**
29 28 * Created by Valerii Sosliuk on 4/30/2017.
30 29 */
31   -@SqlDao
32 30 public interface TenantRepository extends PagingAndSortingRepository<TenantEntity, UUID> {
33 31
34 32 @Query("SELECT t FROM TenantEntity t WHERE t.region = :region " +
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.dao.DaoUtil;
24 24 import org.thingsboard.server.dao.model.sql.UserCredentialsEntity;
25 25 import org.thingsboard.server.dao.sql.JpaAbstractDao;
26 26 import org.thingsboard.server.dao.user.UserCredentialsDao;
27   -import org.thingsboard.server.dao.util.SqlDao;
28 27
29 28 import java.util.UUID;
30 29
... ... @@ -32,7 +31,6 @@ import java.util.UUID;
32 31 * Created by Valerii Sosliuk on 4/22/2017.
33 32 */
34 33 @Component
35   -@SqlDao
36 34 public class JpaUserCredentialsDao extends JpaAbstractDao<UserCredentialsEntity, UserCredentials> implements UserCredentialsDao {
37 35
38 36 @Autowired
... ...
... ... @@ -27,7 +27,6 @@ import org.thingsboard.server.dao.DaoUtil;
27 27 import org.thingsboard.server.dao.model.sql.UserEntity;
28 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
29 29 import org.thingsboard.server.dao.user.UserDao;
30   -import org.thingsboard.server.dao.util.SqlDao;
31 30
32 31 import java.util.Objects;
33 32 import java.util.UUID;
... ... @@ -38,7 +37,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
38 37 * @author Valerii Sosliuk
39 38 */
40 39 @Component
41   -@SqlDao
42 40 public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao {
43 41
44 42 @Autowired
... ...
... ... @@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.user;
17 17
18 18 import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.UserCredentialsEntity;
20   -import org.thingsboard.server.dao.util.SqlDao;
21 20
22 21 import java.util.UUID;
23 22
24 23 /**
25 24 * Created by Valerii Sosliuk on 4/22/2017.
26 25 */
27   -@SqlDao
28 26 public interface UserCredentialsRepository extends CrudRepository<UserCredentialsEntity, UUID> {
29 27
30 28 UserCredentialsEntity findByUserId(UUID userId);
... ...
... ... @@ -22,14 +22,12 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.common.data.security.Authority;
24 24 import org.thingsboard.server.dao.model.sql.UserEntity;
25   -import org.thingsboard.server.dao.util.SqlDao;
26 25
27 26 import java.util.UUID;
28 27
29 28 /**
30 29 * @author Valerii Sosliuk
31 30 */
32   -@SqlDao
33 31 public interface UserRepository extends PagingAndSortingRepository<UserEntity, UUID> {
34 32
35 33 UserEntity findByEmail(String email);
... ...