Commit ed3c57d1eacfb82016f9efef52be49609b0cceb5
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,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
18 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
19 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
@@ -26,26 +27,27 @@ import org.springframework.beans.factory.annotation.Value; | @@ -26,26 +27,27 @@ import org.springframework.beans.factory.annotation.Value; | ||
26 | import org.springframework.security.core.Authentication; | 27 | import org.springframework.security.core.Authentication; |
27 | import org.springframework.security.core.context.SecurityContextHolder; | 28 | import org.springframework.security.core.context.SecurityContextHolder; |
28 | import org.springframework.web.bind.annotation.ExceptionHandler; | 29 | import org.springframework.web.bind.annotation.ExceptionHandler; |
29 | -import org.thingsboard.server.common.data.*; | ||
30 | import org.thingsboard.server.common.data.Customer; | 30 | import org.thingsboard.server.common.data.Customer; |
31 | import org.thingsboard.server.common.data.Dashboard; | 31 | import org.thingsboard.server.common.data.Dashboard; |
32 | import org.thingsboard.server.common.data.DashboardInfo; | 32 | import org.thingsboard.server.common.data.DashboardInfo; |
33 | import org.thingsboard.server.common.data.DataConstants; | 33 | import org.thingsboard.server.common.data.DataConstants; |
34 | import org.thingsboard.server.common.data.Device; | 34 | import org.thingsboard.server.common.data.Device; |
35 | +import org.thingsboard.server.common.data.DeviceInfo; | ||
35 | import org.thingsboard.server.common.data.EntityType; | 36 | import org.thingsboard.server.common.data.EntityType; |
36 | import org.thingsboard.server.common.data.EntityView; | 37 | import org.thingsboard.server.common.data.EntityView; |
38 | +import org.thingsboard.server.common.data.EntityViewInfo; | ||
37 | import org.thingsboard.server.common.data.HasName; | 39 | import org.thingsboard.server.common.data.HasName; |
38 | import org.thingsboard.server.common.data.HasTenantId; | 40 | import org.thingsboard.server.common.data.HasTenantId; |
39 | import org.thingsboard.server.common.data.Tenant; | 41 | import org.thingsboard.server.common.data.Tenant; |
40 | import org.thingsboard.server.common.data.User; | 42 | import org.thingsboard.server.common.data.User; |
41 | import org.thingsboard.server.common.data.alarm.Alarm; | 43 | import org.thingsboard.server.common.data.alarm.Alarm; |
42 | -import org.thingsboard.server.common.data.id.AlarmId; | ||
43 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 44 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
44 | import org.thingsboard.server.common.data.asset.Asset; | 45 | import org.thingsboard.server.common.data.asset.Asset; |
45 | import org.thingsboard.server.common.data.asset.AssetInfo; | 46 | import org.thingsboard.server.common.data.asset.AssetInfo; |
46 | import org.thingsboard.server.common.data.audit.ActionType; | 47 | import org.thingsboard.server.common.data.audit.ActionType; |
47 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 48 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
48 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 49 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
50 | +import org.thingsboard.server.common.data.id.AlarmId; | ||
49 | import org.thingsboard.server.common.data.id.AssetId; | 51 | import org.thingsboard.server.common.data.id.AssetId; |
50 | import org.thingsboard.server.common.data.id.CustomerId; | 52 | import org.thingsboard.server.common.data.id.CustomerId; |
51 | import org.thingsboard.server.common.data.id.DashboardId; | 53 | import org.thingsboard.server.common.data.id.DashboardId; |
@@ -73,7 +75,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle; | @@ -73,7 +75,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle; | ||
73 | import org.thingsboard.server.common.msg.TbMsg; | 75 | import org.thingsboard.server.common.msg.TbMsg; |
74 | import org.thingsboard.server.common.msg.TbMsgDataType; | 76 | import org.thingsboard.server.common.msg.TbMsgDataType; |
75 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 77 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
76 | -import org.thingsboard.server.dao.alarm.AlarmService; | ||
77 | import org.thingsboard.server.dao.asset.AssetService; | 78 | import org.thingsboard.server.dao.asset.AssetService; |
78 | import org.thingsboard.server.dao.attributes.AttributesService; | 79 | import org.thingsboard.server.dao.attributes.AttributesService; |
79 | import org.thingsboard.server.dao.audit.AuditLogService; | 80 | import org.thingsboard.server.dao.audit.AuditLogService; |
@@ -640,6 +641,12 @@ public abstract class BaseController { | @@ -640,6 +641,12 @@ public abstract class BaseController { | ||
640 | case ALARM_CLEAR: | 641 | case ALARM_CLEAR: |
641 | msgType = DataConstants.ALARM_CLEAR; | 642 | msgType = DataConstants.ALARM_CLEAR; |
642 | break; | 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 | if (!StringUtils.isEmpty(msgType)) { | 651 | if (!StringUtils.isEmpty(msgType)) { |
645 | try { | 652 | try { |
@@ -659,6 +666,16 @@ public abstract class BaseController { | @@ -659,6 +666,16 @@ public abstract class BaseController { | ||
659 | String strCustomerName = extractParameter(String.class, 2, additionalInfo); | 666 | String strCustomerName = extractParameter(String.class, 2, additionalInfo); |
660 | metaData.putValue("unassignedCustomerId", strCustomerId); | 667 | metaData.putValue("unassignedCustomerId", strCustomerId); |
661 | metaData.putValue("unassignedCustomerName", strCustomerName); | 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 | ObjectNode entityNode; | 680 | ObjectNode entityNode; |
664 | if (entity != null) { | 681 | if (entity != null) { |
@@ -722,5 +739,13 @@ public abstract class BaseController { | @@ -722,5 +739,13 @@ public abstract class BaseController { | ||
722 | return result; | 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,8 +40,10 @@ import org.thingsboard.server.common.data.Device; | ||
40 | import org.thingsboard.server.common.data.DeviceInfo; | 40 | import org.thingsboard.server.common.data.DeviceInfo; |
41 | import org.thingsboard.server.common.data.EntitySubtype; | 41 | import org.thingsboard.server.common.data.EntitySubtype; |
42 | import org.thingsboard.server.common.data.EntityType; | 42 | import org.thingsboard.server.common.data.EntityType; |
43 | +import org.thingsboard.server.common.data.Tenant; | ||
43 | import org.thingsboard.server.common.data.audit.ActionType; | 44 | import org.thingsboard.server.common.data.audit.ActionType; |
44 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; | 45 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; |
46 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
45 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 47 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
46 | import org.thingsboard.server.common.data.id.CustomerId; | 48 | import org.thingsboard.server.common.data.id.CustomerId; |
47 | import org.thingsboard.server.common.data.id.DeviceId; | 49 | import org.thingsboard.server.common.data.id.DeviceId; |
@@ -49,6 +51,9 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -49,6 +51,9 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
49 | import org.thingsboard.server.common.data.page.PageData; | 51 | import org.thingsboard.server.common.data.page.PageData; |
50 | import org.thingsboard.server.common.data.page.PageLink; | 52 | import org.thingsboard.server.common.data.page.PageLink; |
51 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 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 | import org.thingsboard.server.dao.device.claim.ClaimResponse; | 57 | import org.thingsboard.server.dao.device.claim.ClaimResponse; |
53 | import org.thingsboard.server.dao.device.claim.ClaimResult; | 58 | import org.thingsboard.server.dao.device.claim.ClaimResult; |
54 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 59 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
@@ -71,6 +76,7 @@ public class DeviceController extends BaseController { | @@ -71,6 +76,7 @@ public class DeviceController extends BaseController { | ||
71 | 76 | ||
72 | private static final String DEVICE_ID = "deviceId"; | 77 | private static final String DEVICE_ID = "deviceId"; |
73 | private static final String DEVICE_NAME = "deviceName"; | 78 | private static final String DEVICE_NAME = "deviceName"; |
79 | + private static final String TENANT_ID = "tenantId"; | ||
74 | 80 | ||
75 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 81 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
76 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET) | 82 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET) |
@@ -547,4 +553,54 @@ public class DeviceController extends BaseController { | @@ -547,4 +553,54 @@ public class DeviceController extends BaseController { | ||
547 | } | 553 | } |
548 | return DataConstants.DEFAULT_SECRET_KEY; | 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,7 +28,9 @@ import org.thingsboard.server.service.install.DatabaseTsUpgradeService; | ||
28 | import org.thingsboard.server.service.install.EntityDatabaseSchemaService; | 28 | import org.thingsboard.server.service.install.EntityDatabaseSchemaService; |
29 | import org.thingsboard.server.service.install.SystemDataLoaderService; | 29 | import org.thingsboard.server.service.install.SystemDataLoaderService; |
30 | import org.thingsboard.server.service.install.TsDatabaseSchemaService; | 30 | import org.thingsboard.server.service.install.TsDatabaseSchemaService; |
31 | +import org.thingsboard.server.service.install.TsLatestDatabaseSchemaService; | ||
31 | import org.thingsboard.server.service.install.migrate.EntitiesMigrateService; | 32 | import org.thingsboard.server.service.install.migrate.EntitiesMigrateService; |
33 | +import org.thingsboard.server.service.install.migrate.TsLatestMigrateService; | ||
32 | import org.thingsboard.server.service.install.update.DataUpdateService; | 34 | import org.thingsboard.server.service.install.update.DataUpdateService; |
33 | 35 | ||
34 | @Service | 36 | @Service |
@@ -51,6 +53,9 @@ public class ThingsboardInstallService { | @@ -51,6 +53,9 @@ public class ThingsboardInstallService { | ||
51 | @Autowired | 53 | @Autowired |
52 | private TsDatabaseSchemaService tsDatabaseSchemaService; | 54 | private TsDatabaseSchemaService tsDatabaseSchemaService; |
53 | 55 | ||
56 | + @Autowired(required = false) | ||
57 | + private TsLatestDatabaseSchemaService tsLatestDatabaseSchemaService; | ||
58 | + | ||
54 | @Autowired | 59 | @Autowired |
55 | private DatabaseEntitiesUpgradeService databaseEntitiesUpgradeService; | 60 | private DatabaseEntitiesUpgradeService databaseEntitiesUpgradeService; |
56 | 61 | ||
@@ -72,6 +77,9 @@ public class ThingsboardInstallService { | @@ -72,6 +77,9 @@ public class ThingsboardInstallService { | ||
72 | @Autowired(required = false) | 77 | @Autowired(required = false) |
73 | private EntitiesMigrateService entitiesMigrateService; | 78 | private EntitiesMigrateService entitiesMigrateService; |
74 | 79 | ||
80 | + @Autowired(required = false) | ||
81 | + private TsLatestMigrateService latestMigrateService; | ||
82 | + | ||
75 | public void performInstall() { | 83 | public void performInstall() { |
76 | try { | 84 | try { |
77 | if (isUpgrade) { | 85 | if (isUpgrade) { |
@@ -82,6 +90,10 @@ public class ThingsboardInstallService { | @@ -82,6 +90,10 @@ public class ThingsboardInstallService { | ||
82 | entitiesMigrateService.migrate(); | 90 | entitiesMigrateService.migrate(); |
83 | log.info("Updating system data..."); | 91 | log.info("Updating system data..."); |
84 | systemDataLoaderService.updateSystemWidgets(); | 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 | } else { | 97 | } else { |
86 | switch (upgradeFromVersion) { | 98 | switch (upgradeFromVersion) { |
87 | case "1.2.3": //NOSONAR, Need to execute gradual upgrade starting from upgradeFromVersion | 99 | case "1.2.3": //NOSONAR, Need to execute gradual upgrade starting from upgradeFromVersion |
@@ -181,6 +193,10 @@ public class ThingsboardInstallService { | @@ -181,6 +193,10 @@ public class ThingsboardInstallService { | ||
181 | 193 | ||
182 | tsDatabaseSchemaService.createDatabaseSchema(); | 194 | tsDatabaseSchemaService.createDatabaseSchema(); |
183 | 195 | ||
196 | + if (tsLatestDatabaseSchemaService != null) { | ||
197 | + tsLatestDatabaseSchemaService.createDatabaseSchema(); | ||
198 | + } | ||
199 | + | ||
184 | log.info("Loading system data..."); | 200 | log.info("Loading system data..."); |
185 | 201 | ||
186 | componentDiscoveryService.discoverComponents(); | 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,11 +18,9 @@ package org.thingsboard.server.service.install; | ||
18 | import org.springframework.context.annotation.Profile; | 18 | import org.springframework.context.annotation.Profile; |
19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
20 | import org.thingsboard.server.dao.util.HsqlDao; | 20 | import org.thingsboard.server.dao.util.HsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | @Service | 22 | @Service |
24 | @HsqlDao | 23 | @HsqlDao |
25 | -@SqlDao | ||
26 | @Profile("install") | 24 | @Profile("install") |
27 | public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService | 25 | public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
28 | implements EntityDatabaseSchemaService { | 26 | implements EntityDatabaseSchemaService { |
@@ -18,10 +18,8 @@ package org.thingsboard.server.service.install; | @@ -18,10 +18,8 @@ package org.thingsboard.server.service.install; | ||
18 | import org.springframework.context.annotation.Profile; | 18 | import org.springframework.context.annotation.Profile; |
19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
20 | import org.thingsboard.server.dao.util.PsqlDao; | 20 | import org.thingsboard.server.dao.util.PsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | @Service | 22 | @Service |
24 | -@SqlDao | ||
25 | @PsqlDao | 23 | @PsqlDao |
26 | @Profile("install") | 24 | @Profile("install") |
27 | public class PsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService | 25 | public class PsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value; | @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value; | ||
21 | import org.springframework.context.annotation.Profile; | 21 | import org.springframework.context.annotation.Profile; |
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.server.dao.dashboard.DashboardService; | 23 | import org.thingsboard.server.dao.dashboard.DashboardService; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | import org.thingsboard.server.service.install.sql.SqlDbHelper; | 24 | import org.thingsboard.server.service.install.sql.SqlDbHelper; |
26 | 25 | ||
27 | import java.nio.charset.Charset; | 26 | import java.nio.charset.Charset; |
@@ -58,7 +57,6 @@ import static org.thingsboard.server.service.install.DatabaseHelper.TYPE; | @@ -58,7 +57,6 @@ import static org.thingsboard.server.service.install.DatabaseHelper.TYPE; | ||
58 | @Service | 57 | @Service |
59 | @Profile("install") | 58 | @Profile("install") |
60 | @Slf4j | 59 | @Slf4j |
61 | -@SqlDao | ||
62 | public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService { | 60 | public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService { |
63 | 61 | ||
64 | private static final String SCHEMA_UPDATE_SQL = "schema_update.sql"; | 62 | private static final String SCHEMA_UPDATE_SQL = "schema_update.sql"; |
application/src/main/java/org/thingsboard/server/service/install/TsLatestDatabaseSchemaService.java
0 → 100644
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,7 +24,6 @@ import org.thingsboard.server.common.data.EntityType; | ||
24 | import org.thingsboard.server.common.data.UUIDConverter; | 24 | import org.thingsboard.server.common.data.UUIDConverter; |
25 | import org.thingsboard.server.dao.cassandra.CassandraCluster; | 25 | import org.thingsboard.server.dao.cassandra.CassandraCluster; |
26 | import org.thingsboard.server.dao.util.NoSqlAnyDao; | 26 | import org.thingsboard.server.dao.util.NoSqlAnyDao; |
27 | -import org.thingsboard.server.dao.util.SqlDao; | ||
28 | import org.thingsboard.server.service.install.EntityDatabaseSchemaService; | 27 | import org.thingsboard.server.service.install.EntityDatabaseSchemaService; |
29 | 28 | ||
30 | import java.sql.Connection; | 29 | import java.sql.Connection; |
@@ -42,7 +41,6 @@ import static org.thingsboard.server.service.install.migrate.CassandraToSqlColum | @@ -42,7 +41,6 @@ import static org.thingsboard.server.service.install.migrate.CassandraToSqlColum | ||
42 | 41 | ||
43 | @Service | 42 | @Service |
44 | @Profile("install") | 43 | @Profile("install") |
45 | -@SqlDao | ||
46 | @NoSqlAnyDao | 44 | @NoSqlAnyDao |
47 | @Slf4j | 45 | @Slf4j |
48 | public class CassandraEntitiesToSqlMigrateService implements EntitiesMigrateService { | 46 | public class CassandraEntitiesToSqlMigrateService implements EntitiesMigrateService { |
@@ -128,7 +128,7 @@ public class CassandraToSqlTable { | @@ -128,7 +128,7 @@ public class CassandraToSqlTable { | ||
128 | return this.validateColumnData(data); | 128 | return this.validateColumnData(data); |
129 | } | 129 | } |
130 | 130 | ||
131 | - private CassandraToSqlColumnData[] validateColumnData(CassandraToSqlColumnData[] data) { | 131 | + protected CassandraToSqlColumnData[] validateColumnData(CassandraToSqlColumnData[] data) { |
132 | for (int i=0;i<data.length;i++) { | 132 | for (int i=0;i<data.length;i++) { |
133 | CassandraToSqlColumn column = this.columns.get(i); | 133 | CassandraToSqlColumn column = this.columns.get(i); |
134 | if (column.getType() == CassandraToSqlColumnType.STRING) { | 134 | if (column.getType() == CassandraToSqlColumnType.STRING) { |
@@ -148,7 +148,7 @@ public class CassandraToSqlTable { | @@ -148,7 +148,7 @@ public class CassandraToSqlTable { | ||
148 | return data; | 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 | boolean retry = false; | 152 | boolean retry = false; |
153 | for (CassandraToSqlColumnData[] data : batchData) { | 153 | for (CassandraToSqlColumnData[] data : batchData) { |
154 | for (CassandraToSqlColumn column: this.columns) { | 154 | for (CassandraToSqlColumn column: this.columns) { |
@@ -269,7 +269,7 @@ public class CassandraToSqlTable { | @@ -269,7 +269,7 @@ public class CassandraToSqlTable { | ||
269 | return Optional.empty(); | 269 | return Optional.empty(); |
270 | } | 270 | } |
271 | 271 | ||
272 | - private Statement createCassandraSelectStatement() { | 272 | + protected Statement createCassandraSelectStatement() { |
273 | StringBuilder selectStatementBuilder = new StringBuilder(); | 273 | StringBuilder selectStatementBuilder = new StringBuilder(); |
274 | selectStatementBuilder.append("SELECT "); | 274 | selectStatementBuilder.append("SELECT "); |
275 | for (CassandraToSqlColumn column : columns) { | 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 | +} |
application/src/main/java/org/thingsboard/server/service/install/migrate/TsLatestMigrateService.java
0 → 100644
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,7 +28,6 @@ import org.thingsboard.server.common.msg.TbActorMsg; | ||
28 | import org.thingsboard.server.common.msg.queue.ServiceType; | 28 | import org.thingsboard.server.common.msg.queue.ServiceType; |
29 | import org.thingsboard.server.common.msg.queue.TbCallback; | 29 | import org.thingsboard.server.common.msg.queue.TbCallback; |
30 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; | 30 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
31 | -import org.thingsboard.server.gen.transport.TransportProtos; | ||
32 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceStateServiceMsgProto; | 31 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceStateServiceMsgProto; |
33 | import org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto; | 32 | import org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto; |
34 | import org.thingsboard.server.gen.transport.TransportProtos.LocalSubscriptionServiceMsgProto; | 33 | import org.thingsboard.server.gen.transport.TransportProtos.LocalSubscriptionServiceMsgProto; |
@@ -61,7 +60,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra | @@ -61,7 +60,6 @@ import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWra | ||
61 | 60 | ||
62 | import javax.annotation.PostConstruct; | 61 | import javax.annotation.PostConstruct; |
63 | import javax.annotation.PreDestroy; | 62 | import javax.annotation.PreDestroy; |
64 | -import java.util.ArrayList; | ||
65 | import java.util.List; | 63 | import java.util.List; |
66 | import java.util.Optional; | 64 | import java.util.Optional; |
67 | import java.util.UUID; | 65 | import java.util.UUID; |
@@ -18,6 +18,6 @@ package org.thingsboard.server.service.security.permission; | @@ -18,6 +18,6 @@ package org.thingsboard.server.service.security.permission; | ||
18 | public enum Operation { | 18 | public enum Operation { |
19 | 19 | ||
20 | ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL, | 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,7 +20,6 @@ import org.springframework.beans.factory.annotation.Value; | ||
20 | import org.springframework.scheduling.annotation.Scheduled; | 20 | import org.springframework.scheduling.annotation.Scheduled; |
21 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
22 | import org.thingsboard.server.dao.util.PsqlDao; | 22 | import org.thingsboard.server.dao.util.PsqlDao; |
23 | -import org.thingsboard.server.dao.util.SqlDao; | ||
24 | import org.thingsboard.server.service.ttl.AbstractCleanUpService; | 23 | import org.thingsboard.server.service.ttl.AbstractCleanUpService; |
25 | 24 | ||
26 | import java.sql.Connection; | 25 | import java.sql.Connection; |
@@ -28,7 +27,6 @@ import java.sql.DriverManager; | @@ -28,7 +27,6 @@ import java.sql.DriverManager; | ||
28 | import java.sql.SQLException; | 27 | import java.sql.SQLException; |
29 | 28 | ||
30 | @PsqlDao | 29 | @PsqlDao |
31 | -@SqlDao | ||
32 | @Slf4j | 30 | @Slf4j |
33 | @Service | 31 | @Service |
34 | public class EventsCleanUpService extends AbstractCleanUpService { | 32 | public class EventsCleanUpService extends AbstractCleanUpService { |
@@ -19,11 +19,13 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,11 +19,13 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.springframework.beans.factory.annotation.Value; | 19 | import org.springframework.beans.factory.annotation.Value; |
20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
21 | import org.thingsboard.server.dao.model.ModelConstants; | 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 | import java.sql.Connection; | 25 | import java.sql.Connection; |
25 | 26 | ||
26 | -@PsqlTsDao | 27 | +@SqlTsDao |
28 | +@PsqlDao | ||
27 | @Service | 29 | @Service |
28 | @Slf4j | 30 | @Slf4j |
29 | public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpService { | 31 | public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpService { |
@@ -33,9 +35,9 @@ public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpServi | @@ -33,9 +35,9 @@ public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpServi | ||
33 | 35 | ||
34 | @Override | 36 | @Override |
35 | protected void doCleanUp(Connection connection) { | 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 | } |
@@ -178,8 +178,8 @@ database: | @@ -178,8 +178,8 @@ database: | ||
178 | ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by single API call to fetch telemetry records | 178 | ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by single API call to fetch telemetry records |
179 | ts: | 179 | ts: |
180 | type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale) | 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 | # note: timescale works only with postgreSQL database for DATABASE_ENTITIES_TYPE. | 184 | # note: timescale works only with postgreSQL database for DATABASE_ENTITIES_TYPE. |
185 | 185 |
@@ -15,74 +15,17 @@ | @@ -15,74 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 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 | import lombok.extern.slf4j.Slf4j; | 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 | import org.junit.runner.RunWith; | 19 | import org.junit.runner.RunWith; |
36 | -import org.springframework.beans.factory.annotation.Autowired; | ||
37 | import org.springframework.boot.test.context.SpringBootContextLoader; | 20 | import org.springframework.boot.test.context.SpringBootContextLoader; |
38 | import org.springframework.boot.test.context.SpringBootTest; | 21 | import org.springframework.boot.test.context.SpringBootTest; |
39 | import org.springframework.context.annotation.ComponentScan; | 22 | import org.springframework.context.annotation.ComponentScan; |
40 | import org.springframework.context.annotation.Configuration; | 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 | import org.springframework.test.annotation.DirtiesContext; | 24 | import org.springframework.test.annotation.DirtiesContext; |
49 | import org.springframework.test.context.ActiveProfiles; | 25 | import org.springframework.test.context.ActiveProfiles; |
50 | import org.springframework.test.context.ContextConfiguration; | 26 | import org.springframework.test.context.ContextConfiguration; |
51 | import org.springframework.test.context.junit4.SpringRunner; | 27 | import org.springframework.test.context.junit4.SpringRunner; |
52 | import org.springframework.test.context.web.WebAppConfiguration; | 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 | @ActiveProfiles("test") | 30 | @ActiveProfiles("test") |
88 | @RunWith(SpringRunner.class) | 31 | @RunWith(SpringRunner.class) |
@@ -218,6 +218,7 @@ public abstract class AbstractWebTest { | @@ -218,6 +218,7 @@ public abstract class AbstractWebTest { | ||
218 | } | 218 | } |
219 | 219 | ||
220 | private Tenant savedDifferentTenant; | 220 | private Tenant savedDifferentTenant; |
221 | + | ||
221 | protected void loginDifferentTenant() throws Exception { | 222 | protected void loginDifferentTenant() throws Exception { |
222 | loginSysAdmin(); | 223 | loginSysAdmin(); |
223 | Tenant tenant = new Tenant(); | 224 | Tenant tenant = new Tenant(); |
@@ -313,6 +314,10 @@ public abstract class AbstractWebTest { | @@ -313,6 +314,10 @@ public abstract class AbstractWebTest { | ||
313 | return readResponse(doGet(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass); | 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 | protected <T> T doGetAsync(String urlTemplate, Class<T> responseClass, Object... urlVariables) throws Exception { | 321 | protected <T> T doGetAsync(String urlTemplate, Class<T> responseClass, Object... urlVariables) throws Exception { |
317 | return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass); | 322 | return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass); |
318 | } | 323 | } |
@@ -352,9 +357,9 @@ public abstract class AbstractWebTest { | @@ -352,9 +357,9 @@ public abstract class AbstractWebTest { | ||
352 | return readResponse(doGet(urlTemplate, vars).andExpect(status().isOk()), responseType); | 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 | List<Object> pageLinkVariables = new ArrayList<>(); | 363 | List<Object> pageLinkVariables = new ArrayList<>(); |
359 | urlTemplate += "pageSize={pageSize}&page={page}"; | 364 | urlTemplate += "pageSize={pageSize}&page={page}"; |
360 | pageLinkVariables.add(pageLink.getPageSize()); | 365 | pageLinkVariables.add(pageLink.getPageSize()); |
@@ -395,11 +400,11 @@ public abstract class AbstractWebTest { | @@ -395,11 +400,11 @@ public abstract class AbstractWebTest { | ||
395 | return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass); | 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 | return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass); | 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 | return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseType); | 408 | return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseType); |
404 | } | 409 | } |
405 | 410 | ||
@@ -430,7 +435,7 @@ public abstract class AbstractWebTest { | @@ -430,7 +435,7 @@ public abstract class AbstractWebTest { | ||
430 | return mockMvc.perform(postRequest); | 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 | MockHttpServletRequestBuilder postRequest = post(urlTemplate, params); | 439 | MockHttpServletRequestBuilder postRequest = post(urlTemplate, params); |
435 | setJwtToken(postRequest); | 440 | setJwtToken(postRequest); |
436 | String json = json(content); | 441 | String json = json(content); |
@@ -15,74 +15,79 @@ | @@ -15,74 +15,79 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 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 | import com.datastax.oss.driver.api.core.uuid.Uuids; | 18 | import com.datastax.oss.driver.api.core.uuid.Uuids; |
19 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
27 | import org.apache.commons.lang3.RandomStringUtils; | 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 | import org.thingsboard.server.common.data.id.CustomerId; | 30 | import org.thingsboard.server.common.data.id.CustomerId; |
30 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; | 31 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
31 | import org.thingsboard.server.common.data.id.DeviceId; | 32 | import org.thingsboard.server.common.data.id.DeviceId; |
32 | import org.thingsboard.server.common.data.page.PageData; | 33 | import org.thingsboard.server.common.data.page.PageData; |
33 | import org.thingsboard.server.common.data.page.PageLink; | 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 | import org.thingsboard.server.common.data.security.Authority; | 37 | import org.thingsboard.server.common.data.security.Authority; |
35 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 38 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
36 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; | 39 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
37 | import org.thingsboard.server.dao.model.ModelConstants; | 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 | public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | 50 | public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
46 | - | 51 | + |
47 | private IdComparator<Device> idComparator = new IdComparator<>(); | 52 | private IdComparator<Device> idComparator = new IdComparator<>(); |
48 | - | 53 | + |
49 | private Tenant savedTenant; | 54 | private Tenant savedTenant; |
50 | private User tenantAdmin; | 55 | private User tenantAdmin; |
51 | - | 56 | + |
52 | @Before | 57 | @Before |
53 | public void beforeTest() throws Exception { | 58 | public void beforeTest() throws Exception { |
54 | loginSysAdmin(); | 59 | loginSysAdmin(); |
55 | - | 60 | + |
56 | Tenant tenant = new Tenant(); | 61 | Tenant tenant = new Tenant(); |
57 | tenant.setTitle("My tenant"); | 62 | tenant.setTitle("My tenant"); |
58 | savedTenant = doPost("/api/tenant", tenant, Tenant.class); | 63 | savedTenant = doPost("/api/tenant", tenant, Tenant.class); |
59 | Assert.assertNotNull(savedTenant); | 64 | Assert.assertNotNull(savedTenant); |
60 | - | 65 | + |
61 | tenantAdmin = new User(); | 66 | tenantAdmin = new User(); |
62 | tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | 67 | tenantAdmin.setAuthority(Authority.TENANT_ADMIN); |
63 | tenantAdmin.setTenantId(savedTenant.getId()); | 68 | tenantAdmin.setTenantId(savedTenant.getId()); |
64 | tenantAdmin.setEmail("tenant2@thingsboard.org"); | 69 | tenantAdmin.setEmail("tenant2@thingsboard.org"); |
65 | tenantAdmin.setFirstName("Joe"); | 70 | tenantAdmin.setFirstName("Joe"); |
66 | tenantAdmin.setLastName("Downs"); | 71 | tenantAdmin.setLastName("Downs"); |
67 | - | 72 | + |
68 | tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | 73 | tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); |
69 | } | 74 | } |
70 | - | 75 | + |
71 | @After | 76 | @After |
72 | public void afterTest() throws Exception { | 77 | public void afterTest() throws Exception { |
73 | loginSysAdmin(); | 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 | @Test | 84 | @Test |
80 | public void testSaveDevice() throws Exception { | 85 | public void testSaveDevice() throws Exception { |
81 | Device device = new Device(); | 86 | Device device = new Device(); |
82 | device.setName("My device"); | 87 | device.setName("My device"); |
83 | device.setType("default"); | 88 | device.setType("default"); |
84 | Device savedDevice = doPost("/api/device", device, Device.class); | 89 | Device savedDevice = doPost("/api/device", device, Device.class); |
85 | - | 90 | + |
86 | Assert.assertNotNull(savedDevice); | 91 | Assert.assertNotNull(savedDevice); |
87 | Assert.assertNotNull(savedDevice.getId()); | 92 | Assert.assertNotNull(savedDevice.getId()); |
88 | Assert.assertTrue(savedDevice.getCreatedTime() > 0); | 93 | Assert.assertTrue(savedDevice.getCreatedTime() > 0); |
@@ -90,9 +95,9 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -90,9 +95,9 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
90 | Assert.assertNotNull(savedDevice.getCustomerId()); | 95 | Assert.assertNotNull(savedDevice.getCustomerId()); |
91 | Assert.assertEquals(NULL_UUID, savedDevice.getCustomerId().getId()); | 96 | Assert.assertEquals(NULL_UUID, savedDevice.getCustomerId().getId()); |
92 | Assert.assertEquals(device.getName(), savedDevice.getName()); | 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 | Assert.assertNotNull(deviceCredentials); | 102 | Assert.assertNotNull(deviceCredentials); |
98 | Assert.assertNotNull(deviceCredentials.getId()); | 103 | Assert.assertNotNull(deviceCredentials.getId()); |
@@ -100,10 +105,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -100,10 +105,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
100 | Assert.assertEquals(DeviceCredentialsType.ACCESS_TOKEN, deviceCredentials.getCredentialsType()); | 105 | Assert.assertEquals(DeviceCredentialsType.ACCESS_TOKEN, deviceCredentials.getCredentialsType()); |
101 | Assert.assertNotNull(deviceCredentials.getCredentialsId()); | 106 | Assert.assertNotNull(deviceCredentials.getCredentialsId()); |
102 | Assert.assertEquals(20, deviceCredentials.getCredentialsId().length()); | 107 | Assert.assertEquals(20, deviceCredentials.getCredentialsId().length()); |
103 | - | 108 | + |
104 | savedDevice.setName("My new device"); | 109 | savedDevice.setName("My new device"); |
105 | doPost("/api/device", savedDevice, Device.class); | 110 | doPost("/api/device", savedDevice, Device.class); |
106 | - | 111 | + |
107 | Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); | 112 | Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); |
108 | Assert.assertEquals(foundDevice.getName(), savedDevice.getName()); | 113 | Assert.assertEquals(foundDevice.getName(), savedDevice.getName()); |
109 | } | 114 | } |
@@ -115,10 +120,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -115,10 +120,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
115 | device.setType("default"); | 120 | device.setType("default"); |
116 | Device savedDevice = doPost("/api/device", device, Device.class); | 121 | Device savedDevice = doPost("/api/device", device, Device.class); |
117 | loginDifferentTenant(); | 122 | loginDifferentTenant(); |
118 | - doPost("/api/device", savedDevice, Device.class, status().isForbidden()); | 123 | + doPost("/api/device", savedDevice, Device.class, status().isNotFound()); |
119 | deleteDifferentTenant(); | 124 | deleteDifferentTenant(); |
120 | } | 125 | } |
121 | - | 126 | + |
122 | @Test | 127 | @Test |
123 | public void testFindDeviceById() throws Exception { | 128 | public void testFindDeviceById() throws Exception { |
124 | Device device = new Device(); | 129 | Device device = new Device(); |
@@ -133,26 +138,27 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -133,26 +138,27 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
133 | @Test | 138 | @Test |
134 | public void testFindDeviceTypesByTenantId() throws Exception { | 139 | public void testFindDeviceTypesByTenantId() throws Exception { |
135 | List<Device> devices = new ArrayList<>(); | 140 | List<Device> devices = new ArrayList<>(); |
136 | - for (int i=0;i<3;i++) { | 141 | + for (int i = 0; i < 3; i++) { |
137 | Device device = new Device(); | 142 | Device device = new Device(); |
138 | - device.setName("My device B"+i); | 143 | + device.setName("My device B" + i); |
139 | device.setType("typeB"); | 144 | device.setType("typeB"); |
140 | devices.add(doPost("/api/device", device, Device.class)); | 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 | Device device = new Device(); | 148 | Device device = new Device(); |
144 | - device.setName("My device C"+i); | 149 | + device.setName("My device C" + i); |
145 | device.setType("typeC"); | 150 | device.setType("typeC"); |
146 | devices.add(doPost("/api/device", device, Device.class)); | 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 | Device device = new Device(); | 154 | Device device = new Device(); |
150 | - device.setName("My device A"+i); | 155 | + device.setName("My device A" + i); |
151 | device.setType("typeA"); | 156 | device.setType("typeA"); |
152 | devices.add(doPost("/api/device", device, Device.class)); | 157 | devices.add(doPost("/api/device", device, Device.class)); |
153 | } | 158 | } |
154 | List<EntitySubtype> deviceTypes = doGetTyped("/api/device/types", | 159 | List<EntitySubtype> deviceTypes = doGetTyped("/api/device/types", |
155 | - new TypeReference<List<EntitySubtype>>(){}); | 160 | + new TypeReference<List<EntitySubtype>>() { |
161 | + }); | ||
156 | 162 | ||
157 | Assert.assertNotNull(deviceTypes); | 163 | Assert.assertNotNull(deviceTypes); |
158 | Assert.assertEquals(3, deviceTypes.size()); | 164 | Assert.assertEquals(3, deviceTypes.size()); |
@@ -160,19 +166,19 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -160,19 +166,19 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
160 | Assert.assertEquals("typeB", deviceTypes.get(1).getType()); | 166 | Assert.assertEquals("typeB", deviceTypes.get(1).getType()); |
161 | Assert.assertEquals("typeC", deviceTypes.get(2).getType()); | 167 | Assert.assertEquals("typeC", deviceTypes.get(2).getType()); |
162 | } | 168 | } |
163 | - | 169 | + |
164 | @Test | 170 | @Test |
165 | public void testDeleteDevice() throws Exception { | 171 | public void testDeleteDevice() throws Exception { |
166 | Device device = new Device(); | 172 | Device device = new Device(); |
167 | device.setName("My device"); | 173 | device.setName("My device"); |
168 | device.setType("default"); | 174 | device.setType("default"); |
169 | Device savedDevice = doPost("/api/device", device, Device.class); | 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 | @Test | 184 | @Test |
@@ -189,52 +195,51 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -189,52 +195,51 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
189 | Device device = new Device(); | 195 | Device device = new Device(); |
190 | device.setType("default"); | 196 | device.setType("default"); |
191 | doPost("/api/device", device) | 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 | @Test | 202 | @Test |
197 | public void testAssignUnassignDeviceToCustomer() throws Exception { | 203 | public void testAssignUnassignDeviceToCustomer() throws Exception { |
198 | Device device = new Device(); | 204 | Device device = new Device(); |
199 | device.setName("My device"); | 205 | device.setName("My device"); |
200 | device.setType("default"); | 206 | device.setType("default"); |
201 | Device savedDevice = doPost("/api/device", device, Device.class); | 207 | Device savedDevice = doPost("/api/device", device, Device.class); |
202 | - | 208 | + |
203 | Customer customer = new Customer(); | 209 | Customer customer = new Customer(); |
204 | customer.setTitle("My customer"); | 210 | customer.setTitle("My customer"); |
205 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); | 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 | + "/device/" + savedDevice.getId().getId().toString(), Device.class); | 214 | + "/device/" + savedDevice.getId().getId().toString(), Device.class); |
209 | Assert.assertEquals(savedCustomer.getId(), assignedDevice.getCustomerId()); | 215 | Assert.assertEquals(savedCustomer.getId(), assignedDevice.getCustomerId()); |
210 | - | 216 | + |
211 | Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); | 217 | Device foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); |
212 | Assert.assertEquals(savedCustomer.getId(), foundDevice.getCustomerId()); | 218 | Assert.assertEquals(savedCustomer.getId(), foundDevice.getCustomerId()); |
213 | 219 | ||
214 | - Device unassignedDevice = | 220 | + Device unassignedDevice = |
215 | doDelete("/api/customer/device/" + savedDevice.getId().getId().toString(), Device.class); | 221 | doDelete("/api/customer/device/" + savedDevice.getId().getId().toString(), Device.class); |
216 | Assert.assertEquals(ModelConstants.NULL_UUID, unassignedDevice.getCustomerId().getId()); | 222 | Assert.assertEquals(ModelConstants.NULL_UUID, unassignedDevice.getCustomerId().getId()); |
217 | - | 223 | + |
218 | foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); | 224 | foundDevice = doGet("/api/device/" + savedDevice.getId().getId().toString(), Device.class); |
219 | Assert.assertEquals(ModelConstants.NULL_UUID, foundDevice.getCustomerId().getId()); | 225 | Assert.assertEquals(ModelConstants.NULL_UUID, foundDevice.getCustomerId().getId()); |
220 | } | 226 | } |
221 | - | 227 | + |
222 | @Test | 228 | @Test |
223 | public void testAssignDeviceToNonExistentCustomer() throws Exception { | 229 | public void testAssignDeviceToNonExistentCustomer() throws Exception { |
224 | Device device = new Device(); | 230 | Device device = new Device(); |
225 | device.setName("My device"); | 231 | device.setName("My device"); |
226 | device.setType("default"); | 232 | device.setType("default"); |
227 | Device savedDevice = doPost("/api/device", device, Device.class); | 233 | Device savedDevice = doPost("/api/device", device, Device.class); |
228 | - | ||
229 | doPost("/api/customer/" + Uuids.timeBased().toString() | 234 | doPost("/api/customer/" + Uuids.timeBased().toString() |
230 | + "/device/" + savedDevice.getId().getId().toString()) | 235 | + "/device/" + savedDevice.getId().getId().toString()) |
231 | - .andExpect(status().isNotFound()); | 236 | + .andExpect(status().isNotFound()); |
232 | } | 237 | } |
233 | - | 238 | + |
234 | @Test | 239 | @Test |
235 | public void testAssignDeviceToCustomerFromDifferentTenant() throws Exception { | 240 | public void testAssignDeviceToCustomerFromDifferentTenant() throws Exception { |
236 | loginSysAdmin(); | 241 | loginSysAdmin(); |
237 | - | 242 | + |
238 | Tenant tenant2 = new Tenant(); | 243 | Tenant tenant2 = new Tenant(); |
239 | tenant2.setTitle("Different tenant"); | 244 | tenant2.setTitle("Different tenant"); |
240 | Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class); | 245 | Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class); |
@@ -246,103 +251,103 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -246,103 +251,103 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
246 | tenantAdmin2.setEmail("tenant3@thingsboard.org"); | 251 | tenantAdmin2.setEmail("tenant3@thingsboard.org"); |
247 | tenantAdmin2.setFirstName("Joe"); | 252 | tenantAdmin2.setFirstName("Joe"); |
248 | tenantAdmin2.setLastName("Downs"); | 253 | tenantAdmin2.setLastName("Downs"); |
249 | - | 254 | + |
250 | tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1"); | 255 | tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1"); |
251 | - | 256 | + |
252 | Customer customer = new Customer(); | 257 | Customer customer = new Customer(); |
253 | customer.setTitle("Different customer"); | 258 | customer.setTitle("Different customer"); |
254 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); | 259 | Customer savedCustomer = doPost("/api/customer", customer, Customer.class); |
255 | 260 | ||
256 | login(tenantAdmin.getEmail(), "testPassword1"); | 261 | login(tenantAdmin.getEmail(), "testPassword1"); |
257 | - | 262 | + |
258 | Device device = new Device(); | 263 | Device device = new Device(); |
259 | device.setName("My device"); | 264 | device.setName("My device"); |
260 | device.setType("default"); | 265 | device.setType("default"); |
261 | Device savedDevice = doPost("/api/device", device, Device.class); | 266 | Device savedDevice = doPost("/api/device", device, Device.class); |
262 | - | 267 | + |
263 | doPost("/api/customer/" + savedCustomer.getId().getId().toString() | 268 | doPost("/api/customer/" + savedCustomer.getId().getId().toString() |
264 | + "/device/" + savedDevice.getId().getId().toString()) | 269 | + "/device/" + savedDevice.getId().getId().toString()) |
265 | - .andExpect(status().isForbidden()); | ||
266 | - | 270 | + .andExpect(status().isForbidden()); |
271 | + | ||
267 | loginSysAdmin(); | 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 | @Test | 278 | @Test |
274 | public void testFindDeviceCredentialsByDeviceId() throws Exception { | 279 | public void testFindDeviceCredentialsByDeviceId() throws Exception { |
275 | Device device = new Device(); | 280 | Device device = new Device(); |
276 | device.setName("My device"); | 281 | device.setName("My device"); |
277 | device.setType("default"); | 282 | device.setType("default"); |
278 | Device savedDevice = doPost("/api/device", device, Device.class); | 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 | Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); | 286 | Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); |
282 | } | 287 | } |
283 | - | 288 | + |
284 | @Test | 289 | @Test |
285 | public void testSaveDeviceCredentials() throws Exception { | 290 | public void testSaveDeviceCredentials() throws Exception { |
286 | Device device = new Device(); | 291 | Device device = new Device(); |
287 | device.setName("My device"); | 292 | device.setName("My device"); |
288 | device.setType("default"); | 293 | device.setType("default"); |
289 | Device savedDevice = doPost("/api/device", device, Device.class); | 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 | Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); | 297 | Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); |
293 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); | 298 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); |
294 | deviceCredentials.setCredentialsId("access_token"); | 299 | deviceCredentials.setCredentialsId("access_token"); |
295 | doPost("/api/device/credentials", deviceCredentials) | 300 | doPost("/api/device/credentials", deviceCredentials) |
296 | - .andExpect(status().isOk()); | ||
297 | - | ||
298 | - DeviceCredentials foundDeviceCredentials = | 301 | + .andExpect(status().isOk()); |
302 | + | ||
303 | + DeviceCredentials foundDeviceCredentials = | ||
299 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | 304 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
300 | - | 305 | + |
301 | Assert.assertEquals(deviceCredentials, foundDeviceCredentials); | 306 | Assert.assertEquals(deviceCredentials, foundDeviceCredentials); |
302 | } | 307 | } |
303 | - | 308 | + |
304 | @Test | 309 | @Test |
305 | public void testSaveDeviceCredentialsWithEmptyDevice() throws Exception { | 310 | public void testSaveDeviceCredentialsWithEmptyDevice() throws Exception { |
306 | DeviceCredentials deviceCredentials = new DeviceCredentials(); | 311 | DeviceCredentials deviceCredentials = new DeviceCredentials(); |
307 | doPost("/api/device/credentials", deviceCredentials) | 312 | doPost("/api/device/credentials", deviceCredentials) |
308 | - .andExpect(status().isBadRequest()); | 313 | + .andExpect(status().isBadRequest()); |
309 | } | 314 | } |
310 | - | 315 | + |
311 | @Test | 316 | @Test |
312 | public void testSaveDeviceCredentialsWithEmptyCredentialsType() throws Exception { | 317 | public void testSaveDeviceCredentialsWithEmptyCredentialsType() throws Exception { |
313 | Device device = new Device(); | 318 | Device device = new Device(); |
314 | device.setName("My device"); | 319 | device.setName("My device"); |
315 | device.setType("default"); | 320 | device.setType("default"); |
316 | Device savedDevice = doPost("/api/device", device, Device.class); | 321 | Device savedDevice = doPost("/api/device", device, Device.class); |
317 | - DeviceCredentials deviceCredentials = | 322 | + DeviceCredentials deviceCredentials = |
318 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | 323 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
319 | deviceCredentials.setCredentialsType(null); | 324 | deviceCredentials.setCredentialsType(null); |
320 | doPost("/api/device/credentials", deviceCredentials) | 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 | @Test | 330 | @Test |
326 | public void testSaveDeviceCredentialsWithEmptyCredentialsId() throws Exception { | 331 | public void testSaveDeviceCredentialsWithEmptyCredentialsId() throws Exception { |
327 | Device device = new Device(); | 332 | Device device = new Device(); |
328 | device.setName("My device"); | 333 | device.setName("My device"); |
329 | device.setType("default"); | 334 | device.setType("default"); |
330 | Device savedDevice = doPost("/api/device", device, Device.class); | 335 | Device savedDevice = doPost("/api/device", device, Device.class); |
331 | - DeviceCredentials deviceCredentials = | 336 | + DeviceCredentials deviceCredentials = |
332 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | 337 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
333 | deviceCredentials.setCredentialsId(null); | 338 | deviceCredentials.setCredentialsId(null); |
334 | doPost("/api/device/credentials", deviceCredentials) | 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 | @Test | 344 | @Test |
340 | public void testSaveNonExistentDeviceCredentials() throws Exception { | 345 | public void testSaveNonExistentDeviceCredentials() throws Exception { |
341 | Device device = new Device(); | 346 | Device device = new Device(); |
342 | device.setName("My device"); | 347 | device.setName("My device"); |
343 | device.setType("default"); | 348 | device.setType("default"); |
344 | Device savedDevice = doPost("/api/device", device, Device.class); | 349 | Device savedDevice = doPost("/api/device", device, Device.class); |
345 | - DeviceCredentials deviceCredentials = | 350 | + DeviceCredentials deviceCredentials = |
346 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | 351 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
347 | DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased())); | 352 | DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(Uuids.timeBased())); |
348 | newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); | 353 | newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime()); |
@@ -350,29 +355,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -350,29 +355,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
350 | newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); | 355 | newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType()); |
351 | newDeviceCredentials.setCredentialsId(deviceCredentials.getCredentialsId()); | 356 | newDeviceCredentials.setCredentialsId(deviceCredentials.getCredentialsId()); |
352 | doPost("/api/device/credentials", newDeviceCredentials) | 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 | @Test | 362 | @Test |
358 | public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception { | 363 | public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception { |
359 | Device device = new Device(); | 364 | Device device = new Device(); |
360 | device.setName("My device"); | 365 | device.setName("My device"); |
361 | device.setType("default"); | 366 | device.setType("default"); |
362 | Device savedDevice = doPost("/api/device", device, Device.class); | 367 | Device savedDevice = doPost("/api/device", device, Device.class); |
363 | - DeviceCredentials deviceCredentials = | 368 | + DeviceCredentials deviceCredentials = |
364 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | 369 | doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); |
365 | deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased())); | 370 | deviceCredentials.setDeviceId(new DeviceId(Uuids.timeBased())); |
366 | doPost("/api/device/credentials", deviceCredentials) | 371 | doPost("/api/device/credentials", deviceCredentials) |
367 | - .andExpect(status().isNotFound()); | 372 | + .andExpect(status().isNotFound()); |
368 | } | 373 | } |
369 | 374 | ||
370 | @Test | 375 | @Test |
371 | public void testFindTenantDevices() throws Exception { | 376 | public void testFindTenantDevices() throws Exception { |
372 | List<Device> devices = new ArrayList<>(); | 377 | List<Device> devices = new ArrayList<>(); |
373 | - for (int i=0;i<178;i++) { | 378 | + for (int i = 0; i < 178; i++) { |
374 | Device device = new Device(); | 379 | Device device = new Device(); |
375 | - device.setName("Device"+i); | 380 | + device.setName("Device" + i); |
376 | device.setType("default"); | 381 | device.setType("default"); |
377 | devices.add(doPost("/api/device", device, Device.class)); | 382 | devices.add(doPost("/api/device", device, Device.class)); |
378 | } | 383 | } |
@@ -380,28 +385,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -380,28 +385,29 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
380 | PageLink pageLink = new PageLink(23); | 385 | PageLink pageLink = new PageLink(23); |
381 | PageData<Device> pageData = null; | 386 | PageData<Device> pageData = null; |
382 | do { | 387 | do { |
383 | - pageData = doGetTypedWithPageLink("/api/tenant/devices?", | 388 | + pageData = doGetTypedWithPageLink("/api/tenant/devices?", |
384 | new TypeReference<PageData<Device>>(){}, pageLink); | 389 | new TypeReference<PageData<Device>>(){}, pageLink); |
390 | + | ||
385 | loadedDevices.addAll(pageData.getData()); | 391 | loadedDevices.addAll(pageData.getData()); |
386 | if (pageData.hasNext()) { | 392 | if (pageData.hasNext()) { |
387 | pageLink = pageLink.nextPageLink(); | 393 | pageLink = pageLink.nextPageLink(); |
388 | } | 394 | } |
389 | } while (pageData.hasNext()); | 395 | } while (pageData.hasNext()); |
390 | - | 396 | + |
391 | Collections.sort(devices, idComparator); | 397 | Collections.sort(devices, idComparator); |
392 | Collections.sort(loadedDevices, idComparator); | 398 | Collections.sort(loadedDevices, idComparator); |
393 | - | 399 | + |
394 | Assert.assertEquals(devices, loadedDevices); | 400 | Assert.assertEquals(devices, loadedDevices); |
395 | } | 401 | } |
396 | - | 402 | + |
397 | @Test | 403 | @Test |
398 | public void testFindTenantDevicesByName() throws Exception { | 404 | public void testFindTenantDevicesByName() throws Exception { |
399 | String title1 = "Device title 1"; | 405 | String title1 = "Device title 1"; |
400 | List<Device> devicesTitle1 = new ArrayList<>(); | 406 | List<Device> devicesTitle1 = new ArrayList<>(); |
401 | - for (int i=0;i<143;i++) { | 407 | + for (int i = 0; i < 143; i++) { |
402 | Device device = new Device(); | 408 | Device device = new Device(); |
403 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 409 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
404 | - String name = title1+suffix; | 410 | + String name = title1 + suffix; |
405 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 411 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
406 | device.setName(name); | 412 | device.setName(name); |
407 | device.setType("default"); | 413 | device.setType("default"); |
@@ -409,37 +415,37 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -409,37 +415,37 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
409 | } | 415 | } |
410 | String title2 = "Device title 2"; | 416 | String title2 = "Device title 2"; |
411 | List<Device> devicesTitle2 = new ArrayList<>(); | 417 | List<Device> devicesTitle2 = new ArrayList<>(); |
412 | - for (int i=0;i<75;i++) { | 418 | + for (int i = 0; i < 75; i++) { |
413 | Device device = new Device(); | 419 | Device device = new Device(); |
414 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 420 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
415 | - String name = title2+suffix; | 421 | + String name = title2 + suffix; |
416 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 422 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
417 | device.setName(name); | 423 | device.setName(name); |
418 | device.setType("default"); | 424 | device.setType("default"); |
419 | devicesTitle2.add(doPost("/api/device", device, Device.class)); | 425 | devicesTitle2.add(doPost("/api/device", device, Device.class)); |
420 | } | 426 | } |
421 | - | 427 | + |
422 | List<Device> loadedDevicesTitle1 = new ArrayList<>(); | 428 | List<Device> loadedDevicesTitle1 = new ArrayList<>(); |
423 | PageLink pageLink = new PageLink(15, 0, title1); | 429 | PageLink pageLink = new PageLink(15, 0, title1); |
424 | PageData<Device> pageData = null; | 430 | PageData<Device> pageData = null; |
425 | do { | 431 | do { |
426 | - pageData = doGetTypedWithPageLink("/api/tenant/devices?", | 432 | + pageData = doGetTypedWithPageLink("/api/tenant/devices?", |
427 | new TypeReference<PageData<Device>>(){}, pageLink); | 433 | new TypeReference<PageData<Device>>(){}, pageLink); |
428 | loadedDevicesTitle1.addAll(pageData.getData()); | 434 | loadedDevicesTitle1.addAll(pageData.getData()); |
429 | if (pageData.hasNext()) { | 435 | if (pageData.hasNext()) { |
430 | pageLink = pageLink.nextPageLink(); | 436 | pageLink = pageLink.nextPageLink(); |
431 | } | 437 | } |
432 | } while (pageData.hasNext()); | 438 | } while (pageData.hasNext()); |
433 | - | 439 | + |
434 | Collections.sort(devicesTitle1, idComparator); | 440 | Collections.sort(devicesTitle1, idComparator); |
435 | Collections.sort(loadedDevicesTitle1, idComparator); | 441 | Collections.sort(loadedDevicesTitle1, idComparator); |
436 | - | 442 | + |
437 | Assert.assertEquals(devicesTitle1, loadedDevicesTitle1); | 443 | Assert.assertEquals(devicesTitle1, loadedDevicesTitle1); |
438 | - | 444 | + |
439 | List<Device> loadedDevicesTitle2 = new ArrayList<>(); | 445 | List<Device> loadedDevicesTitle2 = new ArrayList<>(); |
440 | pageLink = new PageLink(4, 0, title2); | 446 | pageLink = new PageLink(4, 0, title2); |
441 | do { | 447 | do { |
442 | - pageData = doGetTypedWithPageLink("/api/tenant/devices?", | 448 | + pageData = doGetTypedWithPageLink("/api/tenant/devices?", |
443 | new TypeReference<PageData<Device>>(){}, pageLink); | 449 | new TypeReference<PageData<Device>>(){}, pageLink); |
444 | loadedDevicesTitle2.addAll(pageData.getData()); | 450 | loadedDevicesTitle2.addAll(pageData.getData()); |
445 | if (pageData.hasNext()) { | 451 | if (pageData.hasNext()) { |
@@ -449,25 +455,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -449,25 +455,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
449 | 455 | ||
450 | Collections.sort(devicesTitle2, idComparator); | 456 | Collections.sort(devicesTitle2, idComparator); |
451 | Collections.sort(loadedDevicesTitle2, idComparator); | 457 | Collections.sort(loadedDevicesTitle2, idComparator); |
452 | - | 458 | + |
453 | Assert.assertEquals(devicesTitle2, loadedDevicesTitle2); | 459 | Assert.assertEquals(devicesTitle2, loadedDevicesTitle2); |
454 | - | 460 | + |
455 | for (Device device : loadedDevicesTitle1) { | 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 | pageLink = new PageLink(4, 0, title1); | 465 | pageLink = new PageLink(4, 0, title1); |
461 | pageData = doGetTypedWithPageLink("/api/tenant/devices?", | 466 | pageData = doGetTypedWithPageLink("/api/tenant/devices?", |
462 | new TypeReference<PageData<Device>>(){}, pageLink); | 467 | new TypeReference<PageData<Device>>(){}, pageLink); |
463 | Assert.assertFalse(pageData.hasNext()); | 468 | Assert.assertFalse(pageData.hasNext()); |
464 | Assert.assertEquals(0, pageData.getData().size()); | 469 | Assert.assertEquals(0, pageData.getData().size()); |
465 | - | 470 | + |
466 | for (Device device : loadedDevicesTitle2) { | 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 | pageLink = new PageLink(4, 0, title2); | 475 | pageLink = new PageLink(4, 0, title2); |
472 | pageData = doGetTypedWithPageLink("/api/tenant/devices?", | 476 | pageData = doGetTypedWithPageLink("/api/tenant/devices?", |
473 | new TypeReference<PageData<Device>>(){}, pageLink); | 477 | new TypeReference<PageData<Device>>(){}, pageLink); |
@@ -480,10 +484,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -480,10 +484,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
480 | String title1 = "Device title 1"; | 484 | String title1 = "Device title 1"; |
481 | String type1 = "typeA"; | 485 | String type1 = "typeA"; |
482 | List<Device> devicesType1 = new ArrayList<>(); | 486 | List<Device> devicesType1 = new ArrayList<>(); |
483 | - for (int i=0;i<143;i++) { | 487 | + for (int i = 0; i < 143; i++) { |
484 | Device device = new Device(); | 488 | Device device = new Device(); |
485 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 489 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
486 | - String name = title1+suffix; | 490 | + String name = title1 + suffix; |
487 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 491 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
488 | device.setName(name); | 492 | device.setName(name); |
489 | device.setType(type1); | 493 | device.setType(type1); |
@@ -492,10 +496,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -492,10 +496,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
492 | String title2 = "Device title 2"; | 496 | String title2 = "Device title 2"; |
493 | String type2 = "typeB"; | 497 | String type2 = "typeB"; |
494 | List<Device> devicesType2 = new ArrayList<>(); | 498 | List<Device> devicesType2 = new ArrayList<>(); |
495 | - for (int i=0;i<75;i++) { | 499 | + for (int i = 0; i < 75; i++) { |
496 | Device device = new Device(); | 500 | Device device = new Device(); |
497 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 501 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
498 | - String name = title2+suffix; | 502 | + String name = title2 + suffix; |
499 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 503 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
500 | device.setName(name); | 504 | device.setName(name); |
501 | device.setType(type2); | 505 | device.setType(type2); |
@@ -536,7 +540,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -536,7 +540,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
536 | Assert.assertEquals(devicesType2, loadedDevicesType2); | 540 | Assert.assertEquals(devicesType2, loadedDevicesType2); |
537 | 541 | ||
538 | for (Device device : loadedDevicesType1) { | 542 | for (Device device : loadedDevicesType1) { |
539 | - doDelete("/api/device/"+device.getId().getId().toString()) | 543 | + doDelete("/api/device/" + device.getId().getId().toString()) |
540 | .andExpect(status().isOk()); | 544 | .andExpect(status().isOk()); |
541 | } | 545 | } |
542 | 546 | ||
@@ -547,7 +551,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -547,7 +551,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
547 | Assert.assertEquals(0, pageData.getData().size()); | 551 | Assert.assertEquals(0, pageData.getData().size()); |
548 | 552 | ||
549 | for (Device device : loadedDevicesType2) { | 553 | for (Device device : loadedDevicesType2) { |
550 | - doDelete("/api/device/"+device.getId().getId().toString()) | 554 | + doDelete("/api/device/" + device.getId().getId().toString()) |
551 | .andExpect(status().isOk()); | 555 | .andExpect(status().isOk()); |
552 | } | 556 | } |
553 | 557 | ||
@@ -557,42 +561,42 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -557,42 +561,42 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
557 | Assert.assertFalse(pageData.hasNext()); | 561 | Assert.assertFalse(pageData.hasNext()); |
558 | Assert.assertEquals(0, pageData.getData().size()); | 562 | Assert.assertEquals(0, pageData.getData().size()); |
559 | } | 563 | } |
560 | - | 564 | + |
561 | @Test | 565 | @Test |
562 | public void testFindCustomerDevices() throws Exception { | 566 | public void testFindCustomerDevices() throws Exception { |
563 | Customer customer = new Customer(); | 567 | Customer customer = new Customer(); |
564 | customer.setTitle("Test customer"); | 568 | customer.setTitle("Test customer"); |
565 | customer = doPost("/api/customer", customer, Customer.class); | 569 | customer = doPost("/api/customer", customer, Customer.class); |
566 | CustomerId customerId = customer.getId(); | 570 | CustomerId customerId = customer.getId(); |
567 | - | 571 | + |
568 | List<Device> devices = new ArrayList<>(); | 572 | List<Device> devices = new ArrayList<>(); |
569 | - for (int i=0;i<128;i++) { | 573 | + for (int i = 0; i < 128; i++) { |
570 | Device device = new Device(); | 574 | Device device = new Device(); |
571 | - device.setName("Device"+i); | 575 | + device.setName("Device" + i); |
572 | device.setType("default"); | 576 | device.setType("default"); |
573 | device = doPost("/api/device", device, Device.class); | 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 | List<Device> loadedDevices = new ArrayList<>(); | 582 | List<Device> loadedDevices = new ArrayList<>(); |
579 | PageLink pageLink = new PageLink(23); | 583 | PageLink pageLink = new PageLink(23); |
580 | PageData<Device> pageData = null; | 584 | PageData<Device> pageData = null; |
581 | do { | 585 | do { |
582 | - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", | 586 | + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", |
583 | new TypeReference<PageData<Device>>(){}, pageLink); | 587 | new TypeReference<PageData<Device>>(){}, pageLink); |
584 | loadedDevices.addAll(pageData.getData()); | 588 | loadedDevices.addAll(pageData.getData()); |
585 | if (pageData.hasNext()) { | 589 | if (pageData.hasNext()) { |
586 | pageLink = pageLink.nextPageLink(); | 590 | pageLink = pageLink.nextPageLink(); |
587 | } | 591 | } |
588 | } while (pageData.hasNext()); | 592 | } while (pageData.hasNext()); |
589 | - | 593 | + |
590 | Collections.sort(devices, idComparator); | 594 | Collections.sort(devices, idComparator); |
591 | Collections.sort(loadedDevices, idComparator); | 595 | Collections.sort(loadedDevices, idComparator); |
592 | - | 596 | + |
593 | Assert.assertEquals(devices, loadedDevices); | 597 | Assert.assertEquals(devices, loadedDevices); |
594 | } | 598 | } |
595 | - | 599 | + |
596 | @Test | 600 | @Test |
597 | public void testFindCustomerDevicesByName() throws Exception { | 601 | public void testFindCustomerDevicesByName() throws Exception { |
598 | Customer customer = new Customer(); | 602 | Customer customer = new Customer(); |
@@ -602,52 +606,52 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -602,52 +606,52 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
602 | 606 | ||
603 | String title1 = "Device title 1"; | 607 | String title1 = "Device title 1"; |
604 | List<Device> devicesTitle1 = new ArrayList<>(); | 608 | List<Device> devicesTitle1 = new ArrayList<>(); |
605 | - for (int i=0;i<125;i++) { | 609 | + for (int i = 0; i < 125; i++) { |
606 | Device device = new Device(); | 610 | Device device = new Device(); |
607 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 611 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
608 | - String name = title1+suffix; | 612 | + String name = title1 + suffix; |
609 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 613 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
610 | device.setName(name); | 614 | device.setName(name); |
611 | device.setType("default"); | 615 | device.setType("default"); |
612 | device = doPost("/api/device", device, Device.class); | 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 | + "/device/" + device.getId().getId().toString(), Device.class)); | 618 | + "/device/" + device.getId().getId().toString(), Device.class)); |
615 | } | 619 | } |
616 | String title2 = "Device title 2"; | 620 | String title2 = "Device title 2"; |
617 | List<Device> devicesTitle2 = new ArrayList<>(); | 621 | List<Device> devicesTitle2 = new ArrayList<>(); |
618 | - for (int i=0;i<143;i++) { | 622 | + for (int i = 0; i < 143; i++) { |
619 | Device device = new Device(); | 623 | Device device = new Device(); |
620 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 624 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
621 | - String name = title2+suffix; | 625 | + String name = title2 + suffix; |
622 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 626 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
623 | device.setName(name); | 627 | device.setName(name); |
624 | device.setType("default"); | 628 | device.setType("default"); |
625 | device = doPost("/api/device", device, Device.class); | 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 | + "/device/" + device.getId().getId().toString(), Device.class)); | 631 | + "/device/" + device.getId().getId().toString(), Device.class)); |
628 | } | 632 | } |
629 | - | 633 | + |
630 | List<Device> loadedDevicesTitle1 = new ArrayList<>(); | 634 | List<Device> loadedDevicesTitle1 = new ArrayList<>(); |
631 | PageLink pageLink = new PageLink(15, 0, title1); | 635 | PageLink pageLink = new PageLink(15, 0, title1); |
632 | PageData<Device> pageData = null; | 636 | PageData<Device> pageData = null; |
633 | do { | 637 | do { |
634 | - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", | 638 | + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", |
635 | new TypeReference<PageData<Device>>(){}, pageLink); | 639 | new TypeReference<PageData<Device>>(){}, pageLink); |
636 | loadedDevicesTitle1.addAll(pageData.getData()); | 640 | loadedDevicesTitle1.addAll(pageData.getData()); |
637 | if (pageData.hasNext()) { | 641 | if (pageData.hasNext()) { |
638 | pageLink = pageLink.nextPageLink(); | 642 | pageLink = pageLink.nextPageLink(); |
639 | } | 643 | } |
640 | } while (pageData.hasNext()); | 644 | } while (pageData.hasNext()); |
641 | - | 645 | + |
642 | Collections.sort(devicesTitle1, idComparator); | 646 | Collections.sort(devicesTitle1, idComparator); |
643 | Collections.sort(loadedDevicesTitle1, idComparator); | 647 | Collections.sort(loadedDevicesTitle1, idComparator); |
644 | - | 648 | + |
645 | Assert.assertEquals(devicesTitle1, loadedDevicesTitle1); | 649 | Assert.assertEquals(devicesTitle1, loadedDevicesTitle1); |
646 | - | 650 | + |
647 | List<Device> loadedDevicesTitle2 = new ArrayList<>(); | 651 | List<Device> loadedDevicesTitle2 = new ArrayList<>(); |
648 | pageLink = new PageLink(4, 0, title2); | 652 | pageLink = new PageLink(4, 0, title2); |
649 | do { | 653 | do { |
650 | - pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", | 654 | + pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", |
651 | new TypeReference<PageData<Device>>(){}, pageLink); | 655 | new TypeReference<PageData<Device>>(){}, pageLink); |
652 | loadedDevicesTitle2.addAll(pageData.getData()); | 656 | loadedDevicesTitle2.addAll(pageData.getData()); |
653 | if (pageData.hasNext()) { | 657 | if (pageData.hasNext()) { |
@@ -657,25 +661,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -657,25 +661,23 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
657 | 661 | ||
658 | Collections.sort(devicesTitle2, idComparator); | 662 | Collections.sort(devicesTitle2, idComparator); |
659 | Collections.sort(loadedDevicesTitle2, idComparator); | 663 | Collections.sort(loadedDevicesTitle2, idComparator); |
660 | - | 664 | + |
661 | Assert.assertEquals(devicesTitle2, loadedDevicesTitle2); | 665 | Assert.assertEquals(devicesTitle2, loadedDevicesTitle2); |
662 | - | 666 | + |
663 | for (Device device : loadedDevicesTitle1) { | 667 | for (Device device : loadedDevicesTitle1) { |
664 | doDelete("/api/customer/device/" + device.getId().getId().toString()) | 668 | doDelete("/api/customer/device/" + device.getId().getId().toString()) |
665 | - .andExpect(status().isOk()); | 669 | + .andExpect(status().isOk()); |
666 | } | 670 | } |
667 | - | ||
668 | pageLink = new PageLink(4, 0, title1); | 671 | pageLink = new PageLink(4, 0, title1); |
669 | pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", | 672 | pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", |
670 | new TypeReference<PageData<Device>>(){}, pageLink); | 673 | new TypeReference<PageData<Device>>(){}, pageLink); |
671 | Assert.assertFalse(pageData.hasNext()); | 674 | Assert.assertFalse(pageData.hasNext()); |
672 | Assert.assertEquals(0, pageData.getData().size()); | 675 | Assert.assertEquals(0, pageData.getData().size()); |
673 | - | 676 | + |
674 | for (Device device : loadedDevicesTitle2) { | 677 | for (Device device : loadedDevicesTitle2) { |
675 | doDelete("/api/customer/device/" + device.getId().getId().toString()) | 678 | doDelete("/api/customer/device/" + device.getId().getId().toString()) |
676 | - .andExpect(status().isOk()); | 679 | + .andExpect(status().isOk()); |
677 | } | 680 | } |
678 | - | ||
679 | pageLink = new PageLink(4, 0, title2); | 681 | pageLink = new PageLink(4, 0, title2); |
680 | pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", | 682 | pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", |
681 | new TypeReference<PageData<Device>>(){}, pageLink); | 683 | new TypeReference<PageData<Device>>(){}, pageLink); |
@@ -693,10 +695,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -693,10 +695,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
693 | String title1 = "Device title 1"; | 695 | String title1 = "Device title 1"; |
694 | String type1 = "typeC"; | 696 | String type1 = "typeC"; |
695 | List<Device> devicesType1 = new ArrayList<>(); | 697 | List<Device> devicesType1 = new ArrayList<>(); |
696 | - for (int i=0;i<125;i++) { | 698 | + for (int i = 0; i < 125; i++) { |
697 | Device device = new Device(); | 699 | Device device = new Device(); |
698 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 700 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
699 | - String name = title1+suffix; | 701 | + String name = title1 + suffix; |
700 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 702 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
701 | device.setName(name); | 703 | device.setName(name); |
702 | device.setType(type1); | 704 | device.setType(type1); |
@@ -707,10 +709,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -707,10 +709,10 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
707 | String title2 = "Device title 2"; | 709 | String title2 = "Device title 2"; |
708 | String type2 = "typeD"; | 710 | String type2 = "typeD"; |
709 | List<Device> devicesType2 = new ArrayList<>(); | 711 | List<Device> devicesType2 = new ArrayList<>(); |
710 | - for (int i=0;i<143;i++) { | 712 | + for (int i = 0; i < 143; i++) { |
711 | Device device = new Device(); | 713 | Device device = new Device(); |
712 | String suffix = RandomStringUtils.randomAlphanumeric(15); | 714 | String suffix = RandomStringUtils.randomAlphanumeric(15); |
713 | - String name = title2+suffix; | 715 | + String name = title2 + suffix; |
714 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); | 716 | name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase(); |
715 | device.setName(name); | 717 | device.setName(name); |
716 | device.setType(type2); | 718 | device.setType(type2); |
@@ -775,4 +777,54 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | @@ -775,4 +777,54 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { | ||
775 | Assert.assertEquals(0, pageData.getData().size()); | 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,7 +41,9 @@ public class MqttNoSqlTestSuite { | ||
41 | public static CustomCassandraCQLUnit cassandraUnit = | 41 | public static CustomCassandraCQLUnit cassandraUnit = |
42 | new CustomCassandraCQLUnit( | 42 | new CustomCassandraCQLUnit( |
43 | Arrays.asList( | 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 | "cassandra-test.yaml", 30000l); | 47 | "cassandra-test.yaml", 30000l); |
46 | 48 | ||
47 | @BeforeClass | 49 | @BeforeClass |
@@ -16,14 +16,12 @@ | @@ -16,14 +16,12 @@ | ||
16 | package org.thingsboard.server.dao.audit; | 16 | package org.thingsboard.server.dao.audit; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | -import org.thingsboard.server.common.data.BaseData; | ||
20 | import org.thingsboard.server.common.data.HasName; | 19 | import org.thingsboard.server.common.data.HasName; |
21 | import org.thingsboard.server.common.data.audit.ActionType; | 20 | import org.thingsboard.server.common.data.audit.ActionType; |
22 | import org.thingsboard.server.common.data.audit.AuditLog; | 21 | import org.thingsboard.server.common.data.audit.AuditLog; |
23 | import org.thingsboard.server.common.data.id.CustomerId; | 22 | import org.thingsboard.server.common.data.id.CustomerId; |
24 | import org.thingsboard.server.common.data.id.EntityId; | 23 | import org.thingsboard.server.common.data.id.EntityId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
26 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
27 | import org.thingsboard.server.common.data.id.UserId; | 25 | import org.thingsboard.server.common.data.id.UserId; |
28 | import org.thingsboard.server.common.data.page.PageData; | 26 | import org.thingsboard.server.common.data.page.PageData; |
29 | import org.thingsboard.server.common.data.page.TimePageLink; | 27 | import org.thingsboard.server.common.data.page.TimePageLink; |
@@ -49,5 +47,4 @@ public interface AuditLogService { | @@ -49,5 +47,4 @@ public interface AuditLogService { | ||
49 | E entity, | 47 | E entity, |
50 | ActionType actionType, | 48 | ActionType actionType, |
51 | Exception e, Object... additionalInfo); | 49 | Exception e, Object... additionalInfo); |
52 | - | ||
53 | } | 50 | } |
@@ -76,4 +76,6 @@ public interface DeviceService { | @@ -76,4 +76,6 @@ public interface DeviceService { | ||
76 | 76 | ||
77 | ListenableFuture<List<EntitySubtype>> findDeviceTypesByTenantId(TenantId tenantId); | 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,4 +41,6 @@ public interface EventService { | ||
41 | 41 | ||
42 | List<Event> findLatestEvents(TenantId tenantId, EntityId entityId, String eventType, int limit); | 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,7 +24,6 @@ import org.thingsboard.server.common.data.relation.EntityRelationsQuery; | ||
24 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 24 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
25 | 25 | ||
26 | import java.util.List; | 26 | import java.util.List; |
27 | -import java.util.concurrent.ExecutionException; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by ashvayka on 27.04.17. | 29 | * Created by ashvayka on 27.04.17. |
@@ -77,6 +76,8 @@ public interface RelationService { | @@ -77,6 +76,8 @@ public interface RelationService { | ||
77 | 76 | ||
78 | ListenableFuture<List<EntityRelationInfo>> findInfoByQuery(TenantId tenantId, EntityRelationsQuery query); | 77 | ListenableFuture<List<EntityRelationInfo>> findInfoByQuery(TenantId tenantId, EntityRelationsQuery query); |
79 | 78 | ||
79 | + void removeRelations(TenantId tenantId, EntityId entityId); | ||
80 | + | ||
80 | // TODO: This method may be useful for some validations in the future | 81 | // TODO: This method may be useful for some validations in the future |
81 | // ListenableFuture<Boolean> checkRecursiveRelation(EntityId from, EntityId to); | 82 | // ListenableFuture<Boolean> checkRecursiveRelation(EntityId from, EntityId to); |
82 | 83 |
@@ -21,6 +21,6 @@ import java.lang.annotation.Retention; | @@ -21,6 +21,6 @@ import java.lang.annotation.Retention; | ||
21 | import java.lang.annotation.RetentionPolicy; | 21 | import java.lang.annotation.RetentionPolicy; |
22 | 22 | ||
23 | @Retention(RetentionPolicy.RUNTIME) | 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 | public @interface NoSqlAnyDao { | 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,9 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.util; | 16 | package org.thingsboard.server.dao.util; |
17 | 17 | ||
18 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
19 | + | ||
18 | import java.lang.annotation.Retention; | 20 | import java.lang.annotation.Retention; |
19 | import java.lang.annotation.RetentionPolicy; | 21 | import java.lang.annotation.RetentionPolicy; |
20 | 22 | ||
21 | @Retention(RetentionPolicy.RUNTIME) | 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,7 +21,7 @@ import java.lang.annotation.Retention; | ||
21 | import java.lang.annotation.RetentionPolicy; | 21 | import java.lang.annotation.RetentionPolicy; |
22 | 22 | ||
23 | @Retention(RetentionPolicy.RUNTIME) | 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 | "&& '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'") | 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,6 +21,6 @@ import java.lang.annotation.Retention; | ||
21 | import java.lang.annotation.RetentionPolicy; | 21 | import java.lang.annotation.RetentionPolicy; |
22 | 22 | ||
23 | @Retention(RetentionPolicy.RUNTIME) | 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,5 +21,6 @@ import java.lang.annotation.Retention; | ||
21 | import java.lang.annotation.RetentionPolicy; | 21 | import java.lang.annotation.RetentionPolicy; |
22 | 22 | ||
23 | @Retention(RetentionPolicy.RUNTIME) | 23 | @Retention(RetentionPolicy.RUNTIME) |
24 | -@ConditionalOnExpression("'${database.ts.type}'=='sql' && '${spring.jpa.database-platform}'=='org.hibernate.dialect.PostgreSQLDialect'") | ||
25 | -public @interface PsqlTsDao { } | ||
24 | +@ConditionalOnExpression("'${database.ts.type}'=='timescale' || '${database.ts_latest.type}'=='timescale'") | ||
25 | +public @interface TimescaleDBTsOrTsLatestDao { | ||
26 | +} |
@@ -57,6 +57,8 @@ public class DataConstants { | @@ -57,6 +57,8 @@ public class DataConstants { | ||
57 | public static final String ATTRIBUTES_DELETED = "ATTRIBUTES_DELETED"; | 57 | public static final String ATTRIBUTES_DELETED = "ATTRIBUTES_DELETED"; |
58 | public static final String ALARM_ACK = "ALARM_ACK"; | 58 | public static final String ALARM_ACK = "ALARM_ACK"; |
59 | public static final String ALARM_CLEAR = "ALARM_CLEAR"; | 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 | public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE"; | 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,7 +40,9 @@ public enum ActionType { | ||
40 | ALARM_CLEAR(false), | 40 | ALARM_CLEAR(false), |
41 | LOGIN(false), | 41 | LOGIN(false), |
42 | LOGOUT(false), | 42 | LOGOUT(false), |
43 | - LOCKOUT(false); | 43 | + LOCKOUT(false), |
44 | + ASSIGNED_FROM_TENANT(false), | ||
45 | + ASSIGNED_TO_TENANT(false); | ||
44 | 46 | ||
45 | private final boolean isRead; | 47 | private final boolean isRead; |
46 | 48 |
@@ -27,8 +27,8 @@ import org.thingsboard.server.dao.util.SqlTsDao; | @@ -27,8 +27,8 @@ import org.thingsboard.server.dao.util.SqlTsDao; | ||
27 | @Configuration | 27 | @Configuration |
28 | @EnableAutoConfiguration | 28 | @EnableAutoConfiguration |
29 | @ComponentScan({"org.thingsboard.server.dao.sqlts.hsql"}) | 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 | @EnableTransactionManagement | 32 | @EnableTransactionManagement |
33 | @SqlTsDao | 33 | @SqlTsDao |
34 | @HsqlDao | 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,7 +21,6 @@ import org.springframework.context.annotation.ComponentScan; | ||
21 | import org.springframework.context.annotation.Configuration; | 21 | import org.springframework.context.annotation.Configuration; |
22 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | 22 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
23 | import org.springframework.transaction.annotation.EnableTransactionManagement; | 23 | import org.springframework.transaction.annotation.EnableTransactionManagement; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 24 | ||
26 | /** | 25 | /** |
27 | * @author Valerii Sosliuk | 26 | * @author Valerii Sosliuk |
@@ -32,7 +31,6 @@ import org.thingsboard.server.dao.util.SqlDao; | @@ -32,7 +31,6 @@ import org.thingsboard.server.dao.util.SqlDao; | ||
32 | @EnableJpaRepositories("org.thingsboard.server.dao.sql") | 31 | @EnableJpaRepositories("org.thingsboard.server.dao.sql") |
33 | @EntityScan("org.thingsboard.server.dao.model.sql") | 32 | @EntityScan("org.thingsboard.server.dao.model.sql") |
34 | @EnableTransactionManagement | 33 | @EnableTransactionManagement |
35 | -@SqlDao | ||
36 | public class JpaDaoConfig { | 34 | public class JpaDaoConfig { |
37 | 35 | ||
38 | } | 36 | } |
@@ -27,11 +27,11 @@ import org.thingsboard.server.dao.util.SqlTsDao; | @@ -27,11 +27,11 @@ import org.thingsboard.server.dao.util.SqlTsDao; | ||
27 | @Configuration | 27 | @Configuration |
28 | @EnableAutoConfiguration | 28 | @EnableAutoConfiguration |
29 | @ComponentScan({"org.thingsboard.server.dao.sqlts.psql"}) | 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 | @EnableTransactionManagement | 32 | @EnableTransactionManagement |
33 | -@SqlTsDao | ||
34 | @PsqlDao | 33 | @PsqlDao |
34 | +@SqlTsDao | ||
35 | public class PsqlTsDaoConfig { | 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,8 +27,8 @@ import org.thingsboard.server.dao.util.TimescaleDBTsDao; | ||
27 | @Configuration | 27 | @Configuration |
28 | @EnableAutoConfiguration | 28 | @EnableAutoConfiguration |
29 | @ComponentScan({"org.thingsboard.server.dao.sqlts.timescale"}) | 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 | @EnableTransactionManagement | 32 | @EnableTransactionManagement |
33 | @TimescaleDBTsDao | 33 | @TimescaleDBTsDao |
34 | @PsqlDao | 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,7 +163,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ | ||
163 | try { | 163 | try { |
164 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get(); | 164 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(asset.getTenantId(), assetId).get(); |
165 | if (entityViews != null && !entityViews.isEmpty()) { | 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 | } catch (ExecutionException | InterruptedException e) { | 168 | } catch (ExecutionException | InterruptedException e) { |
169 | log.error("Exception while finding entity views for assetId [{}]", assetId, e); | 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,11 +23,12 @@ import org.thingsboard.server.common.data.id.EntityId; | ||
23 | import org.thingsboard.server.common.data.id.UserId; | 23 | import org.thingsboard.server.common.data.id.UserId; |
24 | import org.thingsboard.server.common.data.page.PageData; | 24 | import org.thingsboard.server.common.data.page.PageData; |
25 | import org.thingsboard.server.common.data.page.TimePageLink; | 25 | import org.thingsboard.server.common.data.page.TimePageLink; |
26 | +import org.thingsboard.server.dao.Dao; | ||
26 | 27 | ||
27 | import java.util.List; | 28 | import java.util.List; |
28 | import java.util.UUID; | 29 | import java.util.UUID; |
29 | 30 | ||
30 | -public interface AuditLogDao { | 31 | +public interface AuditLogDao extends Dao<AuditLog> { |
31 | 32 | ||
32 | ListenableFuture<Void> saveByTenantId(AuditLog auditLog); | 33 | ListenableFuture<Void> saveByTenantId(AuditLog auditLog); |
33 | 34 |
@@ -163,6 +163,7 @@ public class AuditLogServiceImpl implements AuditLogService { | @@ -163,6 +163,7 @@ public class AuditLogServiceImpl implements AuditLogService { | ||
163 | case ALARM_ACK: | 163 | case ALARM_ACK: |
164 | case ALARM_CLEAR: | 164 | case ALARM_CLEAR: |
165 | case RELATIONS_DELETED: | 165 | case RELATIONS_DELETED: |
166 | + case ASSIGNED_TO_TENANT: | ||
166 | if (entity != null) { | 167 | if (entity != null) { |
167 | ObjectNode entityNode = objectMapper.valueToTree(entity); | 168 | ObjectNode entityNode = objectMapper.valueToTree(entity); |
168 | if (entityId.getEntityType() == EntityType.DASHBOARD) { | 169 | if (entityId.getEntityType() == EntityType.DASHBOARD) { |
@@ -58,5 +58,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService { | @@ -58,5 +58,4 @@ public class DummyAuditLogServiceImpl implements AuditLogService { | ||
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) { | 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 | return null; | 59 | return null; |
60 | } | 60 | } |
61 | - | ||
62 | } | 61 | } |
@@ -166,4 +166,21 @@ public interface DeviceDao extends Dao<Device> { | @@ -166,4 +166,21 @@ public interface DeviceDao extends Dao<Device> { | ||
166 | * @return the list of tenant device type objects | 166 | * @return the list of tenant device type objects |
167 | */ | 167 | */ |
168 | ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId); | 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,6 +28,8 @@ import org.springframework.cache.CacheManager; | ||
28 | import org.springframework.cache.annotation.CacheEvict; | 28 | import org.springframework.cache.annotation.CacheEvict; |
29 | import org.springframework.cache.annotation.Cacheable; | 29 | import org.springframework.cache.annotation.Cacheable; |
30 | import org.springframework.stereotype.Service; | 30 | import org.springframework.stereotype.Service; |
31 | +import org.springframework.transaction.annotation.Transactional; | ||
32 | +import org.springframework.util.CollectionUtils; | ||
31 | import org.springframework.util.StringUtils; | 33 | import org.springframework.util.StringUtils; |
32 | import org.thingsboard.server.common.data.Customer; | 34 | import org.thingsboard.server.common.data.Customer; |
33 | import org.thingsboard.server.common.data.Device; | 35 | import org.thingsboard.server.common.data.Device; |
@@ -50,6 +52,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; | @@ -50,6 +52,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
50 | import org.thingsboard.server.dao.customer.CustomerDao; | 52 | import org.thingsboard.server.dao.customer.CustomerDao; |
51 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 53 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
52 | import org.thingsboard.server.dao.entityview.EntityViewService; | 54 | import org.thingsboard.server.dao.entityview.EntityViewService; |
55 | +import org.thingsboard.server.dao.event.EventService; | ||
53 | import org.thingsboard.server.dao.exception.DataValidationException; | 56 | import org.thingsboard.server.dao.exception.DataValidationException; |
54 | import org.thingsboard.server.dao.service.DataValidator; | 57 | import org.thingsboard.server.dao.service.DataValidator; |
55 | import org.thingsboard.server.dao.service.PaginatedRemover; | 58 | import org.thingsboard.server.dao.service.PaginatedRemover; |
@@ -98,6 +101,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -98,6 +101,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
98 | @Autowired | 101 | @Autowired |
99 | private CacheManager cacheManager; | 102 | private CacheManager cacheManager; |
100 | 103 | ||
104 | + @Autowired | ||
105 | + private EventService eventService; | ||
106 | + | ||
101 | @Override | 107 | @Override |
102 | public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { | 108 | public DeviceInfo findDeviceInfoById(TenantId tenantId, DeviceId deviceId) { |
103 | log.trace("Executing findDeviceInfoById [{}]", deviceId); | 109 | log.trace("Executing findDeviceInfoById [{}]", deviceId); |
@@ -109,14 +115,22 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -109,14 +115,22 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
109 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { | 115 | public Device findDeviceById(TenantId tenantId, DeviceId deviceId) { |
110 | log.trace("Executing findDeviceById [{}]", deviceId); | 116 | log.trace("Executing findDeviceById [{}]", deviceId); |
111 | validateId(deviceId, INCORRECT_DEVICE_ID + deviceId); | 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 | @Override | 125 | @Override |
116 | public ListenableFuture<Device> findDeviceByIdAsync(TenantId tenantId, DeviceId deviceId) { | 126 | public ListenableFuture<Device> findDeviceByIdAsync(TenantId tenantId, DeviceId deviceId) { |
117 | log.trace("Executing findDeviceById [{}]", deviceId); | 127 | log.trace("Executing findDeviceById [{}]", deviceId); |
118 | validateId(deviceId, INCORRECT_DEVICE_ID + deviceId); | 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 | @Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #name}") | 136 | @Cacheable(cacheNames = DEVICE_CACHE, key = "{#tenantId, #name}") |
@@ -187,7 +201,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -187,7 +201,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
187 | try { | 201 | try { |
188 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); | 202 | List<EntityView> entityViews = entityViewService.findEntityViewsByTenantIdAndEntityIdAsync(device.getTenantId(), deviceId).get(); |
189 | if (entityViews != null && !entityViews.isEmpty()) { | 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 | } catch (ExecutionException | InterruptedException e) { | 206 | } catch (ExecutionException | InterruptedException e) { |
193 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); | 207 | log.error("Exception while finding entity views for deviceId [{}]", deviceId, e); |
@@ -353,6 +367,31 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | @@ -353,6 +367,31 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe | ||
353 | }, MoreExecutors.directExecutor()); | 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 | private DataValidator<Device> deviceValidator = | 395 | private DataValidator<Device> deviceValidator = |
357 | new DataValidator<Device>() { | 396 | new DataValidator<Device>() { |
358 | 397 |
@@ -92,6 +92,21 @@ public class BaseEventService implements EventService { | @@ -92,6 +92,21 @@ public class BaseEventService implements EventService { | ||
92 | return eventDao.findLatestEvents(tenantId.getId(), entityId, eventType, limit); | 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 | private DataValidator<Event> eventValidator = | 110 | private DataValidator<Event> eventValidator = |
96 | new DataValidator<Event>() { | 111 | new DataValidator<Event>() { |
97 | @Override | 112 | @Override |
@@ -506,6 +506,22 @@ public class BaseRelationService implements RelationService { | @@ -506,6 +506,22 @@ public class BaseRelationService implements RelationService { | ||
506 | }, MoreExecutors.directExecutor()); | 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 | protected void validate(EntityRelation relation) { | 525 | protected void validate(EntityRelation relation) { |
510 | if (relation == null) { | 526 | if (relation == null) { |
511 | throw new DataValidationException("Relation type should be specified!"); | 527 | throw new DataValidationException("Relation type should be specified!"); |
@@ -18,10 +18,8 @@ package org.thingsboard.server.dao.sql; | @@ -18,10 +18,8 @@ package org.thingsboard.server.dao.sql; | ||
18 | import org.springframework.beans.factory.annotation.Value; | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
20 | import org.thingsboard.common.util.AbstractListeningExecutor; | 20 | import org.thingsboard.common.util.AbstractListeningExecutor; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | @Component | 22 | @Component |
24 | -@SqlDao | ||
25 | public class JpaExecutorService extends AbstractListeningExecutor { | 23 | public class JpaExecutorService extends AbstractListeningExecutor { |
26 | 24 | ||
27 | @Value("${spring.datasource.hikari.maximumPoolSize}") | 25 | @Value("${spring.datasource.hikari.maximumPoolSize}") |
@@ -21,25 +21,15 @@ import org.springframework.data.jpa.repository.Query; | @@ -21,25 +21,15 @@ import org.springframework.data.jpa.repository.Query; | ||
21 | import org.springframework.data.repository.CrudRepository; | 21 | import org.springframework.data.repository.CrudRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 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 | import org.thingsboard.server.dao.model.sql.AlarmEntity; | 24 | import org.thingsboard.server.dao.model.sql.AlarmEntity; |
31 | import org.thingsboard.server.dao.model.sql.AlarmInfoEntity; | 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 | import java.util.List; | 27 | import java.util.List; |
36 | -import java.util.Set; | ||
37 | import java.util.UUID; | 28 | import java.util.UUID; |
38 | 29 | ||
39 | /** | 30 | /** |
40 | * Created by Valerii Sosliuk on 5/21/2017. | 31 | * Created by Valerii Sosliuk on 5/21/2017. |
41 | */ | 32 | */ |
42 | -@SqlDao | ||
43 | public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> { | 33 | public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> { |
44 | 34 | ||
45 | @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC") | 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,7 +39,6 @@ import org.thingsboard.server.dao.model.sql.AlarmEntity; | ||
39 | import org.thingsboard.server.dao.relation.RelationDao; | 39 | import org.thingsboard.server.dao.relation.RelationDao; |
40 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 40 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
41 | import org.thingsboard.server.dao.sql.query.AlarmQueryRepository; | 41 | import org.thingsboard.server.dao.sql.query.AlarmQueryRepository; |
42 | -import org.thingsboard.server.dao.util.SqlDao; | ||
43 | 42 | ||
44 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
45 | import java.util.Collection; | 44 | import java.util.Collection; |
@@ -54,7 +53,6 @@ import java.util.UUID; | @@ -54,7 +53,6 @@ import java.util.UUID; | ||
54 | */ | 53 | */ |
55 | @Slf4j | 54 | @Slf4j |
56 | @Component | 55 | @Component |
57 | -@SqlDao | ||
58 | public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements AlarmDao { | 56 | public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements AlarmDao { |
59 | 57 | ||
60 | @Autowired | 58 | @Autowired |
@@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | ||
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.AssetEntity; | 23 | import org.thingsboard.server.dao.model.sql.AssetEntity; |
24 | import org.thingsboard.server.dao.model.sql.AssetInfoEntity; | 24 | import org.thingsboard.server.dao.model.sql.AssetInfoEntity; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.List; | 26 | import java.util.List; |
28 | import java.util.UUID; | 27 | import java.util.UUID; |
@@ -30,7 +29,6 @@ import java.util.UUID; | @@ -30,7 +29,6 @@ import java.util.UUID; | ||
30 | /** | 29 | /** |
31 | * Created by Valerii Sosliuk on 5/21/2017. | 30 | * Created by Valerii Sosliuk on 5/21/2017. |
32 | */ | 31 | */ |
33 | -@SqlDao | ||
34 | public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, UUID> { | 32 | public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, UUID> { |
35 | 33 | ||
36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " + | 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,7 +31,6 @@ import org.thingsboard.server.dao.asset.AssetDao; | ||
31 | import org.thingsboard.server.dao.model.sql.AssetEntity; | 31 | import org.thingsboard.server.dao.model.sql.AssetEntity; |
32 | import org.thingsboard.server.dao.model.sql.AssetInfoEntity; | 32 | import org.thingsboard.server.dao.model.sql.AssetInfoEntity; |
33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
34 | -import org.thingsboard.server.dao.util.SqlDao; | ||
35 | 34 | ||
36 | import java.util.ArrayList; | 35 | import java.util.ArrayList; |
37 | import java.util.Collections; | 36 | import java.util.Collections; |
@@ -44,7 +43,6 @@ import java.util.UUID; | @@ -44,7 +43,6 @@ import java.util.UUID; | ||
44 | * Created by Valerii Sosliuk on 5/19/2017. | 43 | * Created by Valerii Sosliuk on 5/19/2017. |
45 | */ | 44 | */ |
46 | @Component | 45 | @Component |
47 | -@SqlDao | ||
48 | public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao { | 46 | public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao { |
49 | 47 | ||
50 | @Autowired | 48 | @Autowired |
@@ -25,7 +25,6 @@ import org.springframework.transaction.TransactionStatus; | @@ -25,7 +25,6 @@ import org.springframework.transaction.TransactionStatus; | ||
25 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; | 25 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
26 | import org.springframework.transaction.support.TransactionTemplate; | 26 | import org.springframework.transaction.support.TransactionTemplate; |
27 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 27 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
28 | -import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 28 | ||
30 | import java.sql.PreparedStatement; | 29 | import java.sql.PreparedStatement; |
31 | import java.sql.SQLException; | 30 | import java.sql.SQLException; |
@@ -35,7 +34,6 @@ import java.util.ArrayList; | @@ -35,7 +34,6 @@ import java.util.ArrayList; | ||
35 | import java.util.List; | 34 | import java.util.List; |
36 | import java.util.regex.Pattern; | 35 | import java.util.regex.Pattern; |
37 | 36 | ||
38 | -@SqlDao | ||
39 | @Repository | 37 | @Repository |
40 | @Slf4j | 38 | @Slf4j |
41 | public abstract class AttributeKvInsertRepository { | 39 | public abstract class AttributeKvInsertRepository { |
@@ -23,12 +23,10 @@ import org.springframework.transaction.annotation.Transactional; | @@ -23,12 +23,10 @@ import org.springframework.transaction.annotation.Transactional; | ||
23 | import org.thingsboard.server.common.data.EntityType; | 23 | import org.thingsboard.server.common.data.EntityType; |
24 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; | 24 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; |
25 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 25 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
26 | -import org.thingsboard.server.dao.util.SqlDao; | ||
27 | 26 | ||
28 | import java.util.List; | 27 | import java.util.List; |
29 | import java.util.UUID; | 28 | import java.util.UUID; |
30 | 29 | ||
31 | -@SqlDao | ||
32 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { | 30 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { |
33 | 31 | ||
34 | @Query("SELECT a FROM AttributeKvEntity a WHERE a.id.entityType = :entityType " + | 32 | @Query("SELECT a FROM AttributeKvEntity a WHERE a.id.entityType = :entityType " + |
@@ -19,12 +19,10 @@ import org.springframework.stereotype.Repository; | @@ -19,12 +19,10 @@ import org.springframework.stereotype.Repository; | ||
19 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
20 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 20 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
21 | import org.thingsboard.server.dao.util.HsqlDao; | 21 | import org.thingsboard.server.dao.util.HsqlDao; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | 22 | ||
24 | import java.sql.Types; | 23 | import java.sql.Types; |
25 | import java.util.List; | 24 | import java.util.List; |
26 | 25 | ||
27 | -@SqlDao | ||
28 | @HsqlDao | 26 | @HsqlDao |
29 | @Repository | 27 | @Repository |
30 | @Transactional | 28 | @Transactional |
@@ -34,7 +34,6 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | @@ -34,7 +34,6 @@ import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | ||
34 | import org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent; | 34 | import org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent; |
35 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams; | 35 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams; |
36 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper; | 36 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper; |
37 | -import org.thingsboard.server.dao.util.SqlDao; | ||
38 | 37 | ||
39 | import javax.annotation.PostConstruct; | 38 | import javax.annotation.PostConstruct; |
40 | import javax.annotation.PreDestroy; | 39 | import javax.annotation.PreDestroy; |
@@ -46,7 +45,6 @@ import java.util.stream.Collectors; | @@ -46,7 +45,6 @@ import java.util.stream.Collectors; | ||
46 | 45 | ||
47 | @Component | 46 | @Component |
48 | @Slf4j | 47 | @Slf4j |
49 | -@SqlDao | ||
50 | public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService implements AttributesDao { | 48 | public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService implements AttributesDao { |
51 | 49 | ||
52 | @Autowired | 50 | @Autowired |
@@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.attributes; | @@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.attributes; | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
20 | import org.thingsboard.server.dao.util.PsqlDao; | 20 | import org.thingsboard.server.dao.util.PsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | -@SqlDao | ||
24 | @PsqlDao | 22 | @PsqlDao |
25 | @Repository | 23 | @Repository |
26 | @Transactional | 24 | @Transactional |
@@ -30,14 +30,12 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -30,14 +30,12 @@ import org.thingsboard.server.dao.DaoUtil; | ||
30 | import org.thingsboard.server.dao.audit.AuditLogDao; | 30 | import org.thingsboard.server.dao.audit.AuditLogDao; |
31 | import org.thingsboard.server.dao.model.sql.AuditLogEntity; | 31 | import org.thingsboard.server.dao.model.sql.AuditLogEntity; |
32 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 32 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
33 | -import org.thingsboard.server.dao.util.SqlDao; | ||
34 | 33 | ||
35 | import java.util.List; | 34 | import java.util.List; |
36 | import java.util.Objects; | 35 | import java.util.Objects; |
37 | import java.util.UUID; | 36 | import java.util.UUID; |
38 | 37 | ||
39 | @Component | 38 | @Component |
40 | -@SqlDao | ||
41 | public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> implements AuditLogDao { | 39 | public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> implements AuditLogDao { |
42 | 40 | ||
43 | @Autowired | 41 | @Autowired |
@@ -23,14 +23,12 @@ import org.springframework.data.repository.query.Param; | @@ -23,14 +23,12 @@ import org.springframework.data.repository.query.Param; | ||
23 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 23 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
24 | import org.thingsboard.server.common.data.plugin.ComponentType; | 24 | import org.thingsboard.server.common.data.plugin.ComponentType; |
25 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 25 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
26 | -import org.thingsboard.server.dao.util.SqlDao; | ||
27 | 26 | ||
28 | import java.util.UUID; | 27 | import java.util.UUID; |
29 | 28 | ||
30 | /** | 29 | /** |
31 | * Created by Valerii Sosliuk on 5/6/2017. | 30 | * Created by Valerii Sosliuk on 5/6/2017. |
32 | */ | 31 | */ |
33 | -@SqlDao | ||
34 | public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, UUID> { | 32 | public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, UUID> { |
35 | 33 | ||
36 | ComponentDescriptorEntity findByClazz(String clazz); | 34 | ComponentDescriptorEntity findByClazz(String clazz); |
@@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.component; | @@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.component; | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
20 | import org.thingsboard.server.dao.util.HsqlDao; | 20 | import org.thingsboard.server.dao.util.HsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | import javax.persistence.Query; | 22 | import javax.persistence.Query; |
24 | 23 | ||
25 | -@SqlDao | ||
26 | @HsqlDao | 24 | @HsqlDao |
27 | @Repository | 25 | @Repository |
28 | public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { | 26 | public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { |
@@ -31,7 +31,6 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -31,7 +31,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
31 | import org.thingsboard.server.dao.component.ComponentDescriptorDao; | 31 | import org.thingsboard.server.dao.component.ComponentDescriptorDao; |
32 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 32 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
34 | -import org.thingsboard.server.dao.util.SqlDao; | ||
35 | 34 | ||
36 | import java.util.Objects; | 35 | import java.util.Objects; |
37 | import java.util.Optional; | 36 | import java.util.Optional; |
@@ -41,7 +40,6 @@ import java.util.UUID; | @@ -41,7 +40,6 @@ import java.util.UUID; | ||
41 | * Created by Valerii Sosliuk on 5/6/2017. | 40 | * Created by Valerii Sosliuk on 5/6/2017. |
42 | */ | 41 | */ |
43 | @Component | 42 | @Component |
44 | -@SqlDao | ||
45 | public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> | 43 | public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> |
46 | implements ComponentDescriptorDao { | 44 | implements ComponentDescriptorDao { |
47 | 45 |
@@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.component; | @@ -18,9 +18,7 @@ package org.thingsboard.server.dao.sql.component; | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
20 | import org.thingsboard.server.dao.util.PsqlDao; | 20 | import org.thingsboard.server.dao.util.PsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | -@SqlDao | ||
24 | @PsqlDao | 22 | @PsqlDao |
25 | @Repository | 23 | @Repository |
26 | public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { | 24 | public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { |
@@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | ||
21 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.CustomerEntity; | 23 | import org.thingsboard.server.dao.model.sql.CustomerEntity; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 24 | ||
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | /** | 27 | /** |
29 | * Created by Valerii Sosliuk on 5/6/2017. | 28 | * Created by Valerii Sosliuk on 5/6/2017. |
30 | */ | 29 | */ |
31 | -@SqlDao | ||
32 | public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, UUID> { | 30 | public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, UUID> { |
33 | 31 | ||
34 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + | 32 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + |
@@ -25,7 +25,6 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -25,7 +25,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
25 | import org.thingsboard.server.dao.customer.CustomerDao; | 25 | import org.thingsboard.server.dao.customer.CustomerDao; |
26 | import org.thingsboard.server.dao.model.sql.CustomerEntity; | 26 | import org.thingsboard.server.dao.model.sql.CustomerEntity; |
27 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 27 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
28 | -import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 28 | ||
30 | import java.util.Objects; | 29 | import java.util.Objects; |
31 | import java.util.Optional; | 30 | import java.util.Optional; |
@@ -35,7 +34,6 @@ import java.util.UUID; | @@ -35,7 +34,6 @@ import java.util.UUID; | ||
35 | * Created by Valerii Sosliuk on 5/6/2017. | 34 | * Created by Valerii Sosliuk on 5/6/2017. |
36 | */ | 35 | */ |
37 | @Component | 36 | @Component |
38 | -@SqlDao | ||
39 | public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao { | 37 | public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao { |
40 | 38 | ||
41 | @Autowired | 39 | @Autowired |
@@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | ||
21 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; | 23 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 24 | ||
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | /** | 27 | /** |
29 | * Created by Valerii Sosliuk on 5/6/2017. | 28 | * Created by Valerii Sosliuk on 5/6/2017. |
30 | */ | 29 | */ |
31 | -@SqlDao | ||
32 | public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, UUID> { | 30 | public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, UUID> { |
33 | 31 | ||
34 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + | 32 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + |
@@ -17,13 +17,11 @@ package org.thingsboard.server.dao.sql.dashboard; | @@ -17,13 +17,11 @@ package org.thingsboard.server.dao.sql.dashboard; | ||
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | import org.thingsboard.server.dao.model.sql.DashboardEntity; | 19 | import org.thingsboard.server.dao.model.sql.DashboardEntity; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | ||
21 | 20 | ||
22 | import java.util.UUID; | 21 | import java.util.UUID; |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Created by Valerii Sosliuk on 5/6/2017. | 24 | * Created by Valerii Sosliuk on 5/6/2017. |
26 | */ | 25 | */ |
27 | -@SqlDao | ||
28 | public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> { | 26 | public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> { |
29 | } | 27 | } |
@@ -22,7 +22,6 @@ import org.thingsboard.server.common.data.Dashboard; | @@ -22,7 +22,6 @@ import org.thingsboard.server.common.data.Dashboard; | ||
22 | import org.thingsboard.server.dao.dashboard.DashboardDao; | 22 | import org.thingsboard.server.dao.dashboard.DashboardDao; |
23 | import org.thingsboard.server.dao.model.sql.DashboardEntity; | 23 | import org.thingsboard.server.dao.model.sql.DashboardEntity; |
24 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 24 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.UUID; | 26 | import java.util.UUID; |
28 | 27 | ||
@@ -30,7 +29,6 @@ import java.util.UUID; | @@ -30,7 +29,6 @@ import java.util.UUID; | ||
30 | * Created by Valerii Sosliuk on 5/6/2017. | 29 | * Created by Valerii Sosliuk on 5/6/2017. |
31 | */ | 30 | */ |
32 | @Component | 31 | @Component |
33 | -@SqlDao | ||
34 | public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao { | 32 | public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao { |
35 | 33 | ||
36 | @Autowired | 34 | @Autowired |
@@ -27,7 +27,6 @@ import org.thingsboard.server.dao.dashboard.DashboardInfoDao; | @@ -27,7 +27,6 @@ import org.thingsboard.server.dao.dashboard.DashboardInfoDao; | ||
27 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; | 27 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
28 | import org.thingsboard.server.dao.relation.RelationDao; | 28 | import org.thingsboard.server.dao.relation.RelationDao; |
29 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 29 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
30 | -import org.thingsboard.server.dao.util.SqlDao; | ||
31 | 30 | ||
32 | import java.util.Objects; | 31 | import java.util.Objects; |
33 | import java.util.UUID; | 32 | import java.util.UUID; |
@@ -37,7 +36,6 @@ import java.util.UUID; | @@ -37,7 +36,6 @@ import java.util.UUID; | ||
37 | */ | 36 | */ |
38 | @Slf4j | 37 | @Slf4j |
39 | @Component | 38 | @Component |
40 | -@SqlDao | ||
41 | public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { | 39 | public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { |
42 | 40 | ||
43 | @Autowired | 41 | @Autowired |
@@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.device; | @@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.device; | ||
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; | 19 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | ||
21 | 20 | ||
22 | import java.util.UUID; | 21 | import java.util.UUID; |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Created by Valerii Sosliuk on 5/6/2017. | 24 | * Created by Valerii Sosliuk on 5/6/2017. |
26 | */ | 25 | */ |
27 | -@SqlDao | ||
28 | public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> { | 26 | public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> { |
29 | 27 | ||
30 | DeviceCredentialsEntity findByDeviceId(UUID deviceId); | 28 | DeviceCredentialsEntity findByDeviceId(UUID deviceId); |
@@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | ||
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.DeviceEntity; | 23 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
24 | import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; | 24 | import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.List; | 26 | import java.util.List; |
28 | import java.util.UUID; | 27 | import java.util.UUID; |
@@ -30,7 +29,6 @@ import java.util.UUID; | @@ -30,7 +29,6 @@ import java.util.UUID; | ||
30 | /** | 29 | /** |
31 | * Created by Valerii Sosliuk on 5/6/2017. | 30 | * Created by Valerii Sosliuk on 5/6/2017. |
32 | */ | 31 | */ |
33 | -@SqlDao | ||
34 | public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, UUID> { | 32 | public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, UUID> { |
35 | 33 | ||
36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo) " + | 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,4 +125,7 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
127 | List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); | 125 | List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); |
128 | 126 | ||
129 | List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds); | 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,7 +24,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
24 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; | 24 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; |
25 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; | 25 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; |
26 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 26 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
27 | -import org.thingsboard.server.dao.util.SqlDao; | ||
28 | 27 | ||
29 | import java.util.UUID; | 28 | import java.util.UUID; |
30 | 29 | ||
@@ -32,7 +31,6 @@ import java.util.UUID; | @@ -32,7 +31,6 @@ import java.util.UUID; | ||
32 | * Created by Valerii Sosliuk on 5/6/2017. | 31 | * Created by Valerii Sosliuk on 5/6/2017. |
33 | */ | 32 | */ |
34 | @Component | 33 | @Component |
35 | -@SqlDao | ||
36 | public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao { | 34 | public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao { |
37 | 35 | ||
38 | @Autowired | 36 | @Autowired |
@@ -32,7 +32,6 @@ import org.thingsboard.server.dao.device.DeviceDao; | @@ -32,7 +32,6 @@ import org.thingsboard.server.dao.device.DeviceDao; | ||
32 | import org.thingsboard.server.dao.model.sql.DeviceEntity; | 32 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
33 | import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; | 33 | import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; |
34 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 34 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
35 | -import org.thingsboard.server.dao.util.SqlDao; | ||
36 | 35 | ||
37 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
38 | import java.util.Collections; | 37 | import java.util.Collections; |
@@ -45,7 +44,6 @@ import java.util.UUID; | @@ -45,7 +44,6 @@ import java.util.UUID; | ||
45 | * Created by Valerii Sosliuk on 5/6/2017. | 44 | * Created by Valerii Sosliuk on 5/6/2017. |
46 | */ | 45 | */ |
47 | @Component | 46 | @Component |
48 | -@SqlDao | ||
49 | public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao { | 47 | public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao { |
50 | 48 | ||
51 | @Autowired | 49 | @Autowired |
@@ -175,6 +173,16 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -175,6 +173,16 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
175 | return service.submit(() -> convertTenantDeviceTypesToDto(tenantId, deviceRepository.findTenantDeviceTypes(tenantId))); | 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 | private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) { | 186 | private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) { |
179 | List<EntitySubtype> list = Collections.emptyList(); | 187 | List<EntitySubtype> list = Collections.emptyList(); |
180 | if (types != null && !types.isEmpty()) { | 188 | if (types != null && !types.isEmpty()) { |
@@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | ||
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; | 23 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; |
24 | import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; | 24 | import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.List; | 26 | import java.util.List; |
28 | import java.util.UUID; | 27 | import java.util.UUID; |
@@ -30,7 +29,6 @@ import java.util.UUID; | @@ -30,7 +29,6 @@ import java.util.UUID; | ||
30 | /** | 29 | /** |
31 | * Created by Victor Basanets on 8/31/2017. | 30 | * Created by Victor Basanets on 8/31/2017. |
32 | */ | 31 | */ |
33 | -@SqlDao | ||
34 | public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, UUID> { | 32 | public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, UUID> { |
35 | 33 | ||
36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " + | 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,7 +31,6 @@ import org.thingsboard.server.dao.entityview.EntityViewDao; | ||
31 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; | 31 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; |
32 | import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; | 32 | import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; |
33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 33 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
34 | -import org.thingsboard.server.dao.util.SqlDao; | ||
35 | 34 | ||
36 | import java.util.ArrayList; | 35 | import java.util.ArrayList; |
37 | import java.util.Collections; | 36 | import java.util.Collections; |
@@ -44,7 +43,6 @@ import java.util.UUID; | @@ -44,7 +43,6 @@ import java.util.UUID; | ||
44 | * Created by Victor Basanets on 8/31/2017. | 43 | * Created by Victor Basanets on 8/31/2017. |
45 | */ | 44 | */ |
46 | @Component | 45 | @Component |
47 | -@SqlDao | ||
48 | public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, EntityView> | 46 | public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, EntityView> |
49 | implements EntityViewDao { | 47 | implements EntityViewDao { |
50 | 48 |
@@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | @@ -22,7 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | ||
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.common.data.EntityType; | 23 | import org.thingsboard.server.common.data.EntityType; |
24 | import org.thingsboard.server.dao.model.sql.EventEntity; | 24 | import org.thingsboard.server.dao.model.sql.EventEntity; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.List; | 26 | import java.util.List; |
28 | import java.util.UUID; | 27 | import java.util.UUID; |
@@ -30,7 +29,6 @@ import java.util.UUID; | @@ -30,7 +29,6 @@ import java.util.UUID; | ||
30 | /** | 29 | /** |
31 | * Created by Valerii Sosliuk on 5/3/2017. | 30 | * Created by Valerii Sosliuk on 5/3/2017. |
32 | */ | 31 | */ |
33 | -@SqlDao | ||
34 | public interface EventRepository extends PagingAndSortingRepository<EventEntity, UUID> { | 32 | public interface EventRepository extends PagingAndSortingRepository<EventEntity, UUID> { |
35 | 33 | ||
36 | EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(UUID tenantId, | 34 | EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(UUID tenantId, |
@@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.event; | @@ -18,11 +18,9 @@ package org.thingsboard.server.dao.sql.event; | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | import org.thingsboard.server.dao.model.sql.EventEntity; | 19 | import org.thingsboard.server.dao.model.sql.EventEntity; |
20 | import org.thingsboard.server.dao.util.HsqlDao; | 20 | import org.thingsboard.server.dao.util.HsqlDao; |
21 | -import org.thingsboard.server.dao.util.SqlDao; | ||
22 | 21 | ||
23 | import javax.persistence.Query; | 22 | import javax.persistence.Query; |
24 | 23 | ||
25 | -@SqlDao | ||
26 | @HsqlDao | 24 | @HsqlDao |
27 | @Repository | 25 | @Repository |
28 | public class HsqlEventInsertRepository extends AbstractEventInsertRepository { | 26 | public class HsqlEventInsertRepository extends AbstractEventInsertRepository { |
@@ -21,7 +21,6 @@ import lombok.extern.slf4j.Slf4j; | @@ -21,7 +21,6 @@ import lombok.extern.slf4j.Slf4j; | ||
21 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.data.domain.PageRequest; | 23 | import org.springframework.data.domain.PageRequest; |
24 | -import org.springframework.data.jpa.domain.Specification; | ||
25 | import org.springframework.data.repository.CrudRepository; | 24 | import org.springframework.data.repository.CrudRepository; |
26 | import org.springframework.stereotype.Component; | 25 | import org.springframework.stereotype.Component; |
27 | import org.thingsboard.server.common.data.Event; | 26 | import org.thingsboard.server.common.data.Event; |
@@ -34,10 +33,7 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -34,10 +33,7 @@ import org.thingsboard.server.dao.DaoUtil; | ||
34 | import org.thingsboard.server.dao.event.EventDao; | 33 | import org.thingsboard.server.dao.event.EventDao; |
35 | import org.thingsboard.server.dao.model.sql.EventEntity; | 34 | import org.thingsboard.server.dao.model.sql.EventEntity; |
36 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 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 | import java.util.List; | 37 | import java.util.List; |
42 | import java.util.Objects; | 38 | import java.util.Objects; |
43 | import java.util.Optional; | 39 | import java.util.Optional; |
@@ -50,7 +46,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | @@ -50,7 +46,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | ||
50 | */ | 46 | */ |
51 | @Slf4j | 47 | @Slf4j |
52 | @Component | 48 | @Component |
53 | -@SqlDao | ||
54 | public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implements EventDao { | 49 | public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implements EventDao { |
55 | 50 | ||
56 | private final UUID systemTenantId = NULL_UUID; | 51 | private final UUID systemTenantId = NULL_UUID; |
@@ -19,10 +19,8 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,10 +19,8 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.springframework.stereotype.Repository; | 19 | import org.springframework.stereotype.Repository; |
20 | import org.thingsboard.server.dao.model.sql.EventEntity; | 20 | import org.thingsboard.server.dao.model.sql.EventEntity; |
21 | import org.thingsboard.server.dao.util.PsqlDao; | 21 | import org.thingsboard.server.dao.util.PsqlDao; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | 22 | ||
24 | @Slf4j | 23 | @Slf4j |
25 | -@SqlDao | ||
26 | @PsqlDao | 24 | @PsqlDao |
27 | @Repository | 25 | @Repository |
28 | public class PsqlEventInsertRepository extends AbstractEventInsertRepository { | 26 | public class PsqlEventInsertRepository extends AbstractEventInsertRepository { |
@@ -39,7 +39,6 @@ import org.thingsboard.server.common.data.query.EntityDataSortOrder; | @@ -39,7 +39,6 @@ import org.thingsboard.server.common.data.query.EntityDataSortOrder; | ||
39 | import org.thingsboard.server.common.data.query.EntityKey; | 39 | import org.thingsboard.server.common.data.query.EntityKey; |
40 | import org.thingsboard.server.common.data.query.EntityKeyType; | 40 | import org.thingsboard.server.common.data.query.EntityKeyType; |
41 | import org.thingsboard.server.dao.model.ModelConstants; | 41 | import org.thingsboard.server.dao.model.ModelConstants; |
42 | -import org.thingsboard.server.dao.util.SqlDao; | ||
43 | 42 | ||
44 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
45 | import java.util.Arrays; | 44 | import java.util.Arrays; |
@@ -52,7 +51,6 @@ import java.util.Objects; | @@ -52,7 +51,6 @@ import java.util.Objects; | ||
52 | import java.util.Set; | 51 | import java.util.Set; |
53 | import java.util.stream.Collectors; | 52 | import java.util.stream.Collectors; |
54 | 53 | ||
55 | -@SqlDao | ||
56 | @Repository | 54 | @Repository |
57 | @Slf4j | 55 | @Slf4j |
58 | public class DefaultAlarmQueryRepository implements AlarmQueryRepository { | 56 | public class DefaultAlarmQueryRepository implements AlarmQueryRepository { |
@@ -50,7 +50,6 @@ import org.thingsboard.server.common.data.query.RelationsQueryFilter; | @@ -50,7 +50,6 @@ import org.thingsboard.server.common.data.query.RelationsQueryFilter; | ||
50 | import org.thingsboard.server.common.data.query.SingleEntityFilter; | 50 | import org.thingsboard.server.common.data.query.SingleEntityFilter; |
51 | import org.thingsboard.server.common.data.relation.EntitySearchDirection; | 51 | import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
52 | import org.thingsboard.server.common.data.relation.EntityTypeFilter; | 52 | import org.thingsboard.server.common.data.relation.EntityTypeFilter; |
53 | -import org.thingsboard.server.dao.util.SqlDao; | ||
54 | 53 | ||
55 | import java.util.Arrays; | 54 | import java.util.Arrays; |
56 | import java.util.Collections; | 55 | import java.util.Collections; |
@@ -61,7 +60,6 @@ import java.util.Optional; | @@ -61,7 +60,6 @@ import java.util.Optional; | ||
61 | import java.util.UUID; | 60 | import java.util.UUID; |
62 | import java.util.stream.Collectors; | 61 | import java.util.stream.Collectors; |
63 | 62 | ||
64 | -@SqlDao | ||
65 | @Repository | 63 | @Repository |
66 | @Slf4j | 64 | @Slf4j |
67 | public class DefaultEntityQueryRepository implements EntityQueryRepository { | 65 | public class DefaultEntityQueryRepository implements EntityQueryRepository { |
@@ -24,10 +24,8 @@ import org.thingsboard.server.common.data.query.EntityCountQuery; | @@ -24,10 +24,8 @@ import org.thingsboard.server.common.data.query.EntityCountQuery; | ||
24 | import org.thingsboard.server.common.data.query.EntityData; | 24 | import org.thingsboard.server.common.data.query.EntityData; |
25 | import org.thingsboard.server.common.data.query.EntityDataQuery; | 25 | import org.thingsboard.server.common.data.query.EntityDataQuery; |
26 | import org.thingsboard.server.dao.entity.EntityQueryDao; | 26 | import org.thingsboard.server.dao.entity.EntityQueryDao; |
27 | -import org.thingsboard.server.dao.util.SqlDao; | ||
28 | 27 | ||
29 | @Component | 28 | @Component |
30 | -@SqlDao | ||
31 | public class JpaEntityQueryDao implements EntityQueryDao { | 29 | public class JpaEntityQueryDao implements EntityQueryDao { |
32 | 30 | ||
33 | @Autowired | 31 | @Autowired |
@@ -20,12 +20,10 @@ import org.springframework.transaction.annotation.Transactional; | @@ -20,12 +20,10 @@ import org.springframework.transaction.annotation.Transactional; | ||
20 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | 20 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
21 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 21 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
22 | import org.thingsboard.server.dao.util.HsqlDao; | 22 | import org.thingsboard.server.dao.util.HsqlDao; |
23 | -import org.thingsboard.server.dao.util.SqlDao; | ||
24 | 23 | ||
25 | import javax.persistence.Query; | 24 | import javax.persistence.Query; |
26 | 25 | ||
27 | @HsqlDao | 26 | @HsqlDao |
28 | -@SqlDao | ||
29 | @Repository | 27 | @Repository |
30 | @Transactional | 28 | @Transactional |
31 | public class HsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository { | 29 | public class HsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository { |
@@ -30,7 +30,6 @@ import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | @@ -30,7 +30,6 @@ import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | ||
30 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 30 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
31 | import org.thingsboard.server.dao.relation.RelationDao; | 31 | import org.thingsboard.server.dao.relation.RelationDao; |
32 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | 32 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; |
33 | -import org.thingsboard.server.dao.util.SqlDao; | ||
34 | 33 | ||
35 | import javax.persistence.criteria.Predicate; | 34 | import javax.persistence.criteria.Predicate; |
36 | import java.util.ArrayList; | 35 | import java.util.ArrayList; |
@@ -41,7 +40,6 @@ import java.util.List; | @@ -41,7 +40,6 @@ import java.util.List; | ||
41 | */ | 40 | */ |
42 | @Slf4j | 41 | @Slf4j |
43 | @Component | 42 | @Component |
44 | -@SqlDao | ||
45 | public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService implements RelationDao { | 43 | public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService implements RelationDao { |
46 | 44 | ||
47 | @Autowired | 45 | @Autowired |
@@ -19,10 +19,8 @@ import org.springframework.stereotype.Repository; | @@ -19,10 +19,8 @@ import org.springframework.stereotype.Repository; | ||
19 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
20 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 20 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
21 | import org.thingsboard.server.dao.util.PsqlDao; | 21 | import org.thingsboard.server.dao.util.PsqlDao; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | 22 | ||
24 | @PsqlDao | 23 | @PsqlDao |
25 | -@SqlDao | ||
26 | @Repository | 24 | @Repository |
27 | @Transactional | 25 | @Transactional |
28 | public class PsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository { | 26 | public class PsqlRelationInsertRepository extends AbstractRelationInsertRepository implements RelationInsertRepository { |
@@ -20,12 +20,10 @@ import org.springframework.data.repository.CrudRepository; | @@ -20,12 +20,10 @@ import org.springframework.data.repository.CrudRepository; | ||
20 | import org.springframework.transaction.annotation.Transactional; | 20 | import org.springframework.transaction.annotation.Transactional; |
21 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | 21 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
22 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 22 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
23 | -import org.thingsboard.server.dao.util.SqlDao; | ||
24 | 23 | ||
25 | import java.util.List; | 24 | import java.util.List; |
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | -@SqlDao | ||
29 | public interface RelationRepository | 27 | public interface RelationRepository |
30 | extends CrudRepository<RelationEntity, RelationCompositeKey>, JpaSpecificationExecutor<RelationEntity> { | 28 | extends CrudRepository<RelationEntity, RelationCompositeKey>, JpaSpecificationExecutor<RelationEntity> { |
31 | 29 |
@@ -26,14 +26,12 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -26,14 +26,12 @@ import org.thingsboard.server.dao.DaoUtil; | ||
26 | import org.thingsboard.server.dao.model.sql.RuleChainEntity; | 26 | import org.thingsboard.server.dao.model.sql.RuleChainEntity; |
27 | import org.thingsboard.server.dao.rule.RuleChainDao; | 27 | import org.thingsboard.server.dao.rule.RuleChainDao; |
28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
29 | -import org.thingsboard.server.dao.util.SqlDao; | ||
30 | 29 | ||
31 | import java.util.Objects; | 30 | import java.util.Objects; |
32 | import java.util.UUID; | 31 | import java.util.UUID; |
33 | 32 | ||
34 | @Slf4j | 33 | @Slf4j |
35 | @Component | 34 | @Component |
36 | -@SqlDao | ||
37 | public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao { | 35 | public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao { |
38 | 36 | ||
39 | @Autowired | 37 | @Autowired |
@@ -23,11 +23,9 @@ import org.thingsboard.server.common.data.rule.RuleNode; | @@ -23,11 +23,9 @@ import org.thingsboard.server.common.data.rule.RuleNode; | ||
23 | import org.thingsboard.server.dao.model.sql.RuleNodeEntity; | 23 | import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
24 | import org.thingsboard.server.dao.rule.RuleNodeDao; | 24 | import org.thingsboard.server.dao.rule.RuleNodeDao; |
25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
26 | -import org.thingsboard.server.dao.util.SqlDao; | ||
27 | 26 | ||
28 | @Slf4j | 27 | @Slf4j |
29 | @Component | 28 | @Component |
30 | -@SqlDao | ||
31 | public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { | 29 | public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { |
32 | 30 | ||
33 | @Autowired | 31 | @Autowired |
@@ -21,11 +21,9 @@ import org.springframework.data.jpa.repository.Query; | @@ -21,11 +21,9 @@ import org.springframework.data.jpa.repository.Query; | ||
21 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.RuleChainEntity; | 23 | import org.thingsboard.server.dao.model.sql.RuleChainEntity; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 24 | ||
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | -@SqlDao | ||
29 | public interface RuleChainRepository extends PagingAndSortingRepository<RuleChainEntity, UUID> { | 27 | public interface RuleChainRepository extends PagingAndSortingRepository<RuleChainEntity, UUID> { |
30 | 28 | ||
31 | @Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " + | 29 | @Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " + |
@@ -17,9 +17,7 @@ package org.thingsboard.server.dao.sql.rule; | @@ -17,9 +17,7 @@ package org.thingsboard.server.dao.sql.rule; | ||
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | import org.thingsboard.server.dao.model.sql.RuleNodeEntity; | 19 | import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | ||
21 | 20 | ||
22 | -@SqlDao | ||
23 | public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> { | 21 | public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> { |
24 | 22 | ||
25 | } | 23 | } |
@@ -25,13 +25,11 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -25,13 +25,11 @@ import org.thingsboard.server.dao.DaoUtil; | ||
25 | import org.thingsboard.server.dao.model.sql.AdminSettingsEntity; | 25 | import org.thingsboard.server.dao.model.sql.AdminSettingsEntity; |
26 | import org.thingsboard.server.dao.settings.AdminSettingsDao; | 26 | import org.thingsboard.server.dao.settings.AdminSettingsDao; |
27 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 27 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
28 | -import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 28 | ||
30 | import java.util.UUID; | 29 | import java.util.UUID; |
31 | 30 | ||
32 | @Component | 31 | @Component |
33 | @Slf4j | 32 | @Slf4j |
34 | -@SqlDao | ||
35 | public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao { | 33 | public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao { |
36 | 34 | ||
37 | @Autowired | 35 | @Autowired |
@@ -26,7 +26,6 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -26,7 +26,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
26 | import org.thingsboard.server.dao.model.sql.TenantEntity; | 26 | import org.thingsboard.server.dao.model.sql.TenantEntity; |
27 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 27 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
28 | import org.thingsboard.server.dao.tenant.TenantDao; | 28 | import org.thingsboard.server.dao.tenant.TenantDao; |
29 | -import org.thingsboard.server.dao.util.SqlDao; | ||
30 | 29 | ||
31 | import java.util.Objects; | 30 | import java.util.Objects; |
32 | import java.util.UUID; | 31 | import java.util.UUID; |
@@ -36,7 +35,6 @@ import java.util.UUID; | @@ -36,7 +35,6 @@ import java.util.UUID; | ||
36 | * Created by Valerii Sosliuk on 4/30/2017. | 35 | * Created by Valerii Sosliuk on 4/30/2017. |
37 | */ | 36 | */ |
38 | @Component | 37 | @Component |
39 | -@SqlDao | ||
40 | public class JpaTenantDao extends JpaAbstractSearchTextDao<TenantEntity, Tenant> implements TenantDao { | 38 | public class JpaTenantDao extends JpaAbstractSearchTextDao<TenantEntity, Tenant> implements TenantDao { |
41 | 39 | ||
42 | @Autowired | 40 | @Autowired |
@@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | @@ -21,14 +21,12 @@ import org.springframework.data.jpa.repository.Query; | ||
21 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.dao.model.sql.TenantEntity; | 23 | import org.thingsboard.server.dao.model.sql.TenantEntity; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 24 | ||
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | /** | 27 | /** |
29 | * Created by Valerii Sosliuk on 4/30/2017. | 28 | * Created by Valerii Sosliuk on 4/30/2017. |
30 | */ | 29 | */ |
31 | -@SqlDao | ||
32 | public interface TenantRepository extends PagingAndSortingRepository<TenantEntity, UUID> { | 30 | public interface TenantRepository extends PagingAndSortingRepository<TenantEntity, UUID> { |
33 | 31 | ||
34 | @Query("SELECT t FROM TenantEntity t WHERE t.region = :region " + | 32 | @Query("SELECT t FROM TenantEntity t WHERE t.region = :region " + |
@@ -24,7 +24,6 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -24,7 +24,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
24 | import org.thingsboard.server.dao.model.sql.UserCredentialsEntity; | 24 | import org.thingsboard.server.dao.model.sql.UserCredentialsEntity; |
25 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 25 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
26 | import org.thingsboard.server.dao.user.UserCredentialsDao; | 26 | import org.thingsboard.server.dao.user.UserCredentialsDao; |
27 | -import org.thingsboard.server.dao.util.SqlDao; | ||
28 | 27 | ||
29 | import java.util.UUID; | 28 | import java.util.UUID; |
30 | 29 | ||
@@ -32,7 +31,6 @@ import java.util.UUID; | @@ -32,7 +31,6 @@ import java.util.UUID; | ||
32 | * Created by Valerii Sosliuk on 4/22/2017. | 31 | * Created by Valerii Sosliuk on 4/22/2017. |
33 | */ | 32 | */ |
34 | @Component | 33 | @Component |
35 | -@SqlDao | ||
36 | public class JpaUserCredentialsDao extends JpaAbstractDao<UserCredentialsEntity, UserCredentials> implements UserCredentialsDao { | 34 | public class JpaUserCredentialsDao extends JpaAbstractDao<UserCredentialsEntity, UserCredentials> implements UserCredentialsDao { |
37 | 35 | ||
38 | @Autowired | 36 | @Autowired |
@@ -27,7 +27,6 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -27,7 +27,6 @@ import org.thingsboard.server.dao.DaoUtil; | ||
27 | import org.thingsboard.server.dao.model.sql.UserEntity; | 27 | import org.thingsboard.server.dao.model.sql.UserEntity; |
28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
29 | import org.thingsboard.server.dao.user.UserDao; | 29 | import org.thingsboard.server.dao.user.UserDao; |
30 | -import org.thingsboard.server.dao.util.SqlDao; | ||
31 | 30 | ||
32 | import java.util.Objects; | 31 | import java.util.Objects; |
33 | import java.util.UUID; | 32 | import java.util.UUID; |
@@ -38,7 +37,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | @@ -38,7 +37,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | ||
38 | * @author Valerii Sosliuk | 37 | * @author Valerii Sosliuk |
39 | */ | 38 | */ |
40 | @Component | 39 | @Component |
41 | -@SqlDao | ||
42 | public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao { | 40 | public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao { |
43 | 41 | ||
44 | @Autowired | 42 | @Autowired |
@@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.user; | @@ -17,14 +17,12 @@ package org.thingsboard.server.dao.sql.user; | ||
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | import org.thingsboard.server.dao.model.sql.UserCredentialsEntity; | 19 | import org.thingsboard.server.dao.model.sql.UserCredentialsEntity; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | ||
21 | 20 | ||
22 | import java.util.UUID; | 21 | import java.util.UUID; |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Created by Valerii Sosliuk on 4/22/2017. | 24 | * Created by Valerii Sosliuk on 4/22/2017. |
26 | */ | 25 | */ |
27 | -@SqlDao | ||
28 | public interface UserCredentialsRepository extends CrudRepository<UserCredentialsEntity, UUID> { | 26 | public interface UserCredentialsRepository extends CrudRepository<UserCredentialsEntity, UUID> { |
29 | 27 | ||
30 | UserCredentialsEntity findByUserId(UUID userId); | 28 | UserCredentialsEntity findByUserId(UUID userId); |
@@ -22,14 +22,12 @@ import org.springframework.data.repository.PagingAndSortingRepository; | @@ -22,14 +22,12 @@ import org.springframework.data.repository.PagingAndSortingRepository; | ||
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | import org.thingsboard.server.common.data.security.Authority; | 23 | import org.thingsboard.server.common.data.security.Authority; |
24 | import org.thingsboard.server.dao.model.sql.UserEntity; | 24 | import org.thingsboard.server.dao.model.sql.UserEntity; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 25 | ||
27 | import java.util.UUID; | 26 | import java.util.UUID; |
28 | 27 | ||
29 | /** | 28 | /** |
30 | * @author Valerii Sosliuk | 29 | * @author Valerii Sosliuk |
31 | */ | 30 | */ |
32 | -@SqlDao | ||
33 | public interface UserRepository extends PagingAndSortingRepository<UserEntity, UUID> { | 31 | public interface UserRepository extends PagingAndSortingRepository<UserEntity, UUID> { |
34 | 32 | ||
35 | UserEntity findByEmail(String email); | 33 | UserEntity findByEmail(String email); |