Commit 5ab6e886bcd1589961124787cf3233e5d8a0d6d1

Authored by Volodymyr Babak
1 parent 73d6eee4

JPA Dao misc fixes due to test failures

Showing 24 changed files with 97 additions and 374 deletions
  1 +/**
  2 + * Copyright © 2016-2017 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 + */
1 package org.thingsboard.server.dao.annotation; 16 package org.thingsboard.server.dao.annotation;
2 17
3 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  1 +/**
  2 + * Copyright © 2016-2017 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 + */
1 package org.thingsboard.server.dao.annotation; 16 package org.thingsboard.server.dao.annotation;
2 17
3 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 18 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -39,7 +39,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation; @@ -39,7 +39,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
39 import org.thingsboard.server.dao.customer.CustomerDao; 39 import org.thingsboard.server.dao.customer.CustomerDao;
40 import org.thingsboard.server.dao.entity.AbstractEntityService; 40 import org.thingsboard.server.dao.entity.AbstractEntityService;
41 import org.thingsboard.server.dao.exception.DataValidationException; 41 import org.thingsboard.server.dao.exception.DataValidationException;
42 -import org.thingsboard.server.dao.model.*;  
43 import org.thingsboard.server.dao.relation.EntitySearchDirection; 42 import org.thingsboard.server.dao.relation.EntitySearchDirection;
44 import org.thingsboard.server.dao.service.DataValidator; 43 import org.thingsboard.server.dao.service.DataValidator;
45 import org.thingsboard.server.dao.service.PaginatedRemover; 44 import org.thingsboard.server.dao.service.PaginatedRemover;
@@ -150,7 +149,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -150,7 +149,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
150 public void deleteAssetsByTenantId(TenantId tenantId) { 149 public void deleteAssetsByTenantId(TenantId tenantId) {
151 log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId); 150 log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId);
152 validateId(tenantId, "Incorrect tenantId " + tenantId); 151 validateId(tenantId, "Incorrect tenantId " + tenantId);
153 - tenantAssetsRemover.removeEntitites(tenantId); 152 + tenantAssetsRemover.removeEntities(tenantId);
154 } 153 }
155 154
156 @Override 155 @Override
@@ -188,7 +187,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -188,7 +187,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
188 log.trace("Executing unassignCustomerAssets, tenantId [{}], customerId [{}]", tenantId, customerId); 187 log.trace("Executing unassignCustomerAssets, tenantId [{}], customerId [{}]", tenantId, customerId);
189 validateId(tenantId, "Incorrect tenantId " + tenantId); 188 validateId(tenantId, "Incorrect tenantId " + tenantId);
190 validateId(customerId, "Incorrect customerId " + customerId); 189 validateId(customerId, "Incorrect customerId " + customerId);
191 - new CustomerAssetsUnassigner(tenantId).removeEntitites(customerId); 190 + new CustomerAssetsUnassigner(tenantId).removeEntities(customerId);
192 } 191 }
193 192
194 @Override 193 @Override
@@ -135,7 +135,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -135,7 +135,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
135 public void deleteCustomersByTenantId(TenantId tenantId) { 135 public void deleteCustomersByTenantId(TenantId tenantId) {
136 log.trace("Executing deleteCustomersByTenantId, tenantId [{}]", tenantId); 136 log.trace("Executing deleteCustomersByTenantId, tenantId [{}]", tenantId);
137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
138 - customersByTenantRemover.removeEntitites(tenantId); 138 + customersByTenantRemover.removeEntities(tenantId);
139 } 139 }
140 140
141 private DataValidator<Customer> customerValidator = 141 private DataValidator<Customer> customerValidator =
@@ -128,7 +128,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -128,7 +128,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
128 public void deleteDashboardsByTenantId(TenantId tenantId) { 128 public void deleteDashboardsByTenantId(TenantId tenantId) {
129 log.trace("Executing deleteDashboardsByTenantId, tenantId [{}]", tenantId); 129 log.trace("Executing deleteDashboardsByTenantId, tenantId [{}]", tenantId);
130 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 130 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
131 - tenantDashboardsRemover.removeEntitites(tenantId); 131 + tenantDashboardsRemover.removeEntities(tenantId);
132 } 132 }
133 133
134 @Override 134 @Override
@@ -146,7 +146,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -146,7 +146,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
146 log.trace("Executing unassignCustomerDashboards, tenantId [{}], customerId [{}]", tenantId, customerId); 146 log.trace("Executing unassignCustomerDashboards, tenantId [{}], customerId [{}]", tenantId, customerId);
147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
148 Validator.validateId(customerId, "Incorrect customerId " + customerId); 148 Validator.validateId(customerId, "Incorrect customerId " + customerId);
149 - new CustomerDashboardsUnassigner(tenantId).removeEntitites(customerId); 149 + new CustomerDashboardsUnassigner(tenantId).removeEntities(customerId);
150 } 150 }
151 151
152 private DataValidator<Dashboard> dashboardValidator = 152 private DataValidator<Dashboard> dashboardValidator =
@@ -168,7 +168,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -168,7 +168,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
168 public void deleteDevicesByTenantId(TenantId tenantId) { 168 public void deleteDevicesByTenantId(TenantId tenantId) {
169 log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId); 169 log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId);
170 validateId(tenantId, "Incorrect tenantId " + tenantId); 170 validateId(tenantId, "Incorrect tenantId " + tenantId);
171 - tenantDevicesRemover.removeEntitites(tenantId); 171 + tenantDevicesRemover.removeEntities(tenantId);
172 } 172 }
173 173
174 @Override 174 @Override
@@ -207,7 +207,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -207,7 +207,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
207 log.trace("Executing unassignCustomerDevices, tenantId [{}], customerId [{}]", tenantId, customerId); 207 log.trace("Executing unassignCustomerDevices, tenantId [{}], customerId [{}]", tenantId, customerId);
208 validateId(tenantId, "Incorrect tenantId " + tenantId); 208 validateId(tenantId, "Incorrect tenantId " + tenantId);
209 validateId(customerId, "Incorrect customerId " + customerId); 209 validateId(customerId, "Incorrect customerId " + customerId);
210 - new CustomerDevicesUnassigner(tenantId).removeEntitites(customerId); 210 + new CustomerDevicesUnassigner(tenantId).removeEntities(customerId);
211 } 211 }
212 212
213 @Override 213 @Override
@@ -83,15 +83,6 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { @@ -83,15 +83,6 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
83 } 83 }
84 84
85 @Override 85 @Override
86 - public UUID getId() {  
87 - return id;  
88 - }  
89 -  
90 - @Override  
91 - public void setId(UUID id) {  
92 - }  
93 -  
94 - @Override  
95 public String getSearchTextSource() { 86 public String getSearchTextSource() {
96 return title; 87 return title;
97 } 88 }
@@ -100,10 +91,6 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { @@ -100,10 +91,6 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
100 public void setSearchText(String searchText) { 91 public void setSearchText(String searchText) {
101 this.searchText = searchText; 92 this.searchText = searchText;
102 } 93 }
103 -  
104 - public String getSearchText() {  
105 - return searchText;  
106 - }  
107 94
108 @Override 95 @Override
109 public Dashboard toData() { 96 public Dashboard toData() {
@@ -96,10 +96,6 @@ public final class DeviceEntity implements SearchTextEntity<Device> { @@ -96,10 +96,6 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
96 this.searchText = searchText; 96 this.searchText = searchText;
97 } 97 }
98 98
99 - public String getSearchText() {  
100 - return searchText;  
101 - }  
102 -  
103 @Override 99 @Override
104 public Device toData() { 100 public Device toData() {
105 Device device = new Device(new DeviceId(id)); 101 Device device = new Device(new DeviceId(id));
@@ -99,7 +99,7 @@ public class UserEntity implements SearchTextEntity<User> { @@ -99,7 +99,7 @@ public class UserEntity implements SearchTextEntity<User> {
99 99
100 @Override 100 @Override
101 public String getSearchTextSource() { 101 public String getSearchTextSource() {
102 - return searchText; 102 + return email;
103 } 103 }
104 104
105 @Override 105 @Override
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao.plugin; 16 package org.thingsboard.server.dao.plugin;
17 17
18 -import com.google.common.util.concurrent.Futures;  
19 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
20 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
21 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
@@ -223,7 +222,7 @@ public class BasePluginService extends AbstractEntityService implements PluginSe @@ -223,7 +222,7 @@ public class BasePluginService extends AbstractEntityService implements PluginSe
223 @Override 222 @Override
224 public void deletePluginsByTenantId(TenantId tenantId) { 223 public void deletePluginsByTenantId(TenantId tenantId) {
225 Validator.validateId(tenantId, "Incorrect tenant id for delete plugins request."); 224 Validator.validateId(tenantId, "Incorrect tenant id for delete plugins request.");
226 - tenantPluginRemover.removeEntitites(tenantId); 225 + tenantPluginRemover.removeEntities(tenantId);
227 } 226 }
228 227
229 228
@@ -265,7 +265,7 @@ public class BaseRuleService extends AbstractEntityService implements RuleServic @@ -265,7 +265,7 @@ public class BaseRuleService extends AbstractEntityService implements RuleServic
265 @Override 265 @Override
266 public void deleteRulesByTenantId(TenantId tenantId) { 266 public void deleteRulesByTenantId(TenantId tenantId) {
267 validateId(tenantId, "Incorrect tenant id for delete rules request."); 267 validateId(tenantId, "Incorrect tenant id for delete rules request.");
268 - tenantRulesRemover.removeEntitites(tenantId); 268 + tenantRulesRemover.removeEntities(tenantId);
269 } 269 }
270 270
271 private DataValidator<RuleMetaData> ruleValidator = 271 private DataValidator<RuleMetaData> ruleValidator =
@@ -25,7 +25,7 @@ public abstract class PaginatedRemover<I, D extends IdBased<?>> { @@ -25,7 +25,7 @@ public abstract class PaginatedRemover<I, D extends IdBased<?>> {
25 25
26 private static final int DEFAULT_LIMIT = 100; 26 private static final int DEFAULT_LIMIT = 100;
27 27
28 - public void removeEntitites(I id) { 28 + public void removeEntities(I id) {
29 TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT); 29 TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT);
30 boolean hasNext = true; 30 boolean hasNext = true;
31 while (hasNext) { 31 while (hasNext) {
@@ -178,21 +178,21 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple @@ -178,21 +178,21 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
178 public Predicate toPredicate(Root<RelationEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { 178 public Predicate toPredicate(Root<RelationEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
179 List<Predicate> predicates = new ArrayList<>(); 179 List<Predicate> predicates = new ArrayList<>();
180 if (from != null) { 180 if (from != null) {
181 - Predicate fromIdPredicate = criteriaBuilder.equal(root.get(RELATION_FROM_ID_PROPERTY), from.getId()); 181 + Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"), from.getId());
182 predicates.add(fromIdPredicate); 182 predicates.add(fromIdPredicate);
183 - Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get(RELATION_FROM_TYPE_PROPERTY), from.getEntityType().name()); 183 + Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name());
184 predicates.add(fromEntityTypePredicate); 184 predicates.add(fromEntityTypePredicate);
185 } 185 }
186 if (relationType != null) { 186 if (relationType != null) {
187 - Predicate relationTypePredicate = criteriaBuilder.equal(root.get(RELATION_TYPE_PROPERTY), relationType); 187 + Predicate relationTypePredicate = criteriaBuilder.equal(root.get("relationType"), relationType);
188 predicates.add(relationTypePredicate); 188 predicates.add(relationTypePredicate);
189 } 189 }
190 if (typeGroup != null) { 190 if (typeGroup != null) {
191 - Predicate typeGroupPredicate = criteriaBuilder.equal(root.get(RELATION_TYPE_GROUP_PROPERTY), typeGroup); 191 + Predicate typeGroupPredicate = criteriaBuilder.equal(root.get("relationTypeGroup"), typeGroup);
192 predicates.add(typeGroupPredicate); 192 predicates.add(typeGroupPredicate);
193 } 193 }
194 if (childType != null) { 194 if (childType != null) {
195 - Predicate childTypePredicate = criteriaBuilder.equal(root.get(RELATION_TO_TYPE_PROPERTY), childType.name()); 195 + Predicate childTypePredicate = criteriaBuilder.equal(root.get("toType"), childType.name());
196 predicates.add(childTypePredicate); 196 predicates.add(childTypePredicate);
197 } 197 }
198 return criteriaBuilder.and(predicates.toArray(new Predicate[0])); 198 return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
@@ -31,7 +31,7 @@ import java.util.UUID; @@ -31,7 +31,7 @@ import java.util.UUID;
31 @Component 31 @Component
32 @Slf4j 32 @Slf4j
33 @SqlDao 33 @SqlDao
34 -public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{ 34 +public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao {
35 35
36 @Autowired 36 @Autowired
37 private AdminSettingsRepository adminSettingsRepository; 37 private AdminSettingsRepository adminSettingsRepository;
@@ -20,10 +20,12 @@ import org.springframework.data.repository.CrudRepository; @@ -20,10 +20,12 @@ import org.springframework.data.repository.CrudRepository;
20 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
21 import org.thingsboard.server.common.data.User; 21 import org.thingsboard.server.common.data.User;
22 import org.thingsboard.server.common.data.page.TextPageLink; 22 import org.thingsboard.server.common.data.page.TextPageLink;
  23 +import org.thingsboard.server.common.data.security.Authority;
23 import org.thingsboard.server.dao.DaoUtil; 24 import org.thingsboard.server.dao.DaoUtil;
24 import org.thingsboard.server.dao.annotation.SqlDao; 25 import org.thingsboard.server.dao.annotation.SqlDao;
25 import org.thingsboard.server.dao.model.sql.UserEntity; 26 import org.thingsboard.server.dao.model.sql.UserEntity;
26 import org.thingsboard.server.dao.sql.JpaAbstractDao; 27 import org.thingsboard.server.dao.sql.JpaAbstractDao;
  28 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
27 import org.thingsboard.server.dao.user.UserDao; 29 import org.thingsboard.server.dao.user.UserDao;
28 30
29 import java.util.List; 31 import java.util.List;
@@ -36,7 +38,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; @@ -36,7 +38,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
36 */ 38 */
37 @Component 39 @Component
38 @SqlDao 40 @SqlDao
39 -public class JpaUserDao extends JpaAbstractDao<UserEntity, User> implements UserDao { 41 +public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao {
40 42
41 @Autowired 43 @Autowired
42 private UserRepository userRepository; 44 private UserRepository userRepository;
@@ -60,20 +62,26 @@ public class JpaUserDao extends JpaAbstractDao<UserEntity, User> implements User @@ -60,20 +62,26 @@ public class JpaUserDao extends JpaAbstractDao<UserEntity, User> implements User
60 public List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink) { 62 public List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink) {
61 return DaoUtil.convertDataList( 63 return DaoUtil.convertDataList(
62 userRepository 64 userRepository
63 - .findTenantAdmins(  
64 - pageLink.getLimit(), 65 + .findUsersByAuthority(
65 tenantId, 66 tenantId,
66 - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())); 67 + NULL_UUID,
  68 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  69 + pageLink.getTextSearch(),
  70 + Authority.TENANT_ADMIN.name(),
  71 + pageLink.getLimit()));
67 } 72 }
68 73
69 @Override 74 @Override
70 public List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink) { 75 public List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink) {
71 return DaoUtil.convertDataList( 76 return DaoUtil.convertDataList(
72 userRepository 77 userRepository
73 - .findCustomerUsers(  
74 - pageLink.getLimit(), 78 + .findUsersByAuthority(
75 tenantId, 79 tenantId,
76 customerId, 80 customerId,
77 - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())); 81 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  82 + pageLink.getTextSearch(),
  83 + Authority.CUSTOMER_USER.name(),
  84 + pageLink.getLimit()));
  85 +
78 } 86 }
79 } 87 }
@@ -33,18 +33,14 @@ public interface UserRepository extends CrudRepository<UserEntity, UUID> { @@ -33,18 +33,14 @@ public interface UserRepository extends CrudRepository<UserEntity, UUID> {
33 UserEntity findByEmail(String email); 33 UserEntity findByEmail(String email);
34 34
35 @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = :tenantId " + 35 @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = :tenantId " +
36 - "AND CUSTOMER_ID IS NULL AND AUTHORITY = 'TENANT_ADMIN' " + 36 + "AND CUSTOMER_ID = :customerId AND AUTHORITY = :authority " +
  37 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:searchText, '%'))" +
37 "AND ID > :idOffset ORDER BY ID LIMIT :limit") 38 "AND ID > :idOffset ORDER BY ID LIMIT :limit")
38 - List<UserEntity> findTenantAdmins(@Param("limit") int limit,  
39 - @Param("tenantId") UUID tenantId,  
40 - @Param("idOffset") UUID idOffset);  
41 -  
42 - @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = :tenantId " +  
43 - "AND CUSTOMER_ID = :customerId AND AUTHORITY = 'CUSTOMER_USER' " +  
44 - "AND ID > :idOffset ORDER BY ID LIMIT :limit")  
45 - List<UserEntity> findCustomerUsers(@Param("limit") int limit,  
46 - @Param("tenantId") UUID tenantId,  
47 - @Param("customerId") UUID customerId,  
48 - @Param("idOffset") UUID idOffset); 39 + List<UserEntity> findUsersByAuthority(@Param("tenantId") UUID tenantId,
  40 + @Param("customerId") UUID customerId,
  41 + @Param("idOffset") UUID idOffset,
  42 + @Param("searchText") String searchText,
  43 + @Param("authority") String authority,
  44 + @Param("limit") int limit);
49 45
50 } 46 }
@@ -119,7 +119,7 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe @@ -119,7 +119,7 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe
119 @Override 119 @Override
120 public void deleteTenants() { 120 public void deleteTenants() {
121 log.trace("Executing deleteTenants"); 121 log.trace("Executing deleteTenants");
122 - tenantsRemover.removeEntitites(DEFAULT_TENANT_REGION); 122 + tenantsRemover.removeEntities(DEFAULT_TENANT_REGION);
123 } 123 }
124 124
125 private DataValidator<Tenant> tenantValidator = 125 private DataValidator<Tenant> tenantValidator =
@@ -15,14 +15,12 @@ @@ -15,14 +15,12 @@
15 */ 15 */
16 package org.thingsboard.server.dao.user; 16 package org.thingsboard.server.dao.user;
17 17
18 -import static org.thingsboard.server.dao.DaoUtil.getData;  
19 import static org.thingsboard.server.dao.service.Validator.validateId; 18 import static org.thingsboard.server.dao.service.Validator.validateId;
20 import static org.thingsboard.server.dao.service.Validator.validatePageLink; 19 import static org.thingsboard.server.dao.service.Validator.validatePageLink;
21 import static org.thingsboard.server.dao.service.Validator.validateString; 20 import static org.thingsboard.server.dao.service.Validator.validateString;
22 21
23 import java.util.List; 22 import java.util.List;
24 23
25 -import com.google.common.util.concurrent.Futures;  
26 import com.google.common.util.concurrent.ListenableFuture; 24 import com.google.common.util.concurrent.ListenableFuture;
27 import lombok.extern.slf4j.Slf4j; 25 import lombok.extern.slf4j.Slf4j;
28 import org.apache.commons.lang3.RandomStringUtils; 26 import org.apache.commons.lang3.RandomStringUtils;
@@ -48,10 +46,6 @@ import org.thingsboard.server.dao.service.DataValidator; @@ -48,10 +46,6 @@ import org.thingsboard.server.dao.service.DataValidator;
48 import org.thingsboard.server.dao.service.PaginatedRemover; 46 import org.thingsboard.server.dao.service.PaginatedRemover;
49 import org.thingsboard.server.dao.tenant.TenantDao; 47 import org.thingsboard.server.dao.tenant.TenantDao;
50 48
51 -import java.util.List;  
52 -  
53 -import static org.thingsboard.server.dao.service.Validator.*;  
54 -  
55 @Service 49 @Service
56 @Slf4j 50 @Slf4j
57 public class UserServiceImpl extends AbstractEntityService implements UserService { 51 public class UserServiceImpl extends AbstractEntityService implements UserService {
@@ -193,7 +187,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -193,7 +187,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
193 public void deleteTenantAdmins(TenantId tenantId) { 187 public void deleteTenantAdmins(TenantId tenantId) {
194 log.trace("Executing deleteTenantAdmins, tenantId [{}]", tenantId); 188 log.trace("Executing deleteTenantAdmins, tenantId [{}]", tenantId);
195 validateId(tenantId, "Incorrect tenantId " + tenantId); 189 validateId(tenantId, "Incorrect tenantId " + tenantId);
196 - tenantAdminsRemover.removeEntitites(tenantId); 190 + tenantAdminsRemover.removeEntities(tenantId);
197 } 191 }
198 192
199 @Override 193 @Override
@@ -211,7 +205,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic @@ -211,7 +205,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
211 log.trace("Executing deleteCustomerUsers, customerId [{}]", customerId); 205 log.trace("Executing deleteCustomerUsers, customerId [{}]", customerId);
212 validateId(tenantId, "Incorrect tenantId " + tenantId); 206 validateId(tenantId, "Incorrect tenantId " + tenantId);
213 validateId(customerId, "Incorrect customerId " + customerId); 207 validateId(customerId, "Incorrect customerId " + customerId);
214 - new CustomerUsersRemover(tenantId).removeEntitites(customerId); 208 + new CustomerUsersRemover(tenantId).removeEntities(customerId);
215 } 209 }
216 210
217 private DataValidator<User> userValidator = 211 private DataValidator<User> userValidator =
@@ -145,7 +145,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { @@ -145,7 +145,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
145 public void deleteWidgetsBundlesByTenantId(TenantId tenantId) { 145 public void deleteWidgetsBundlesByTenantId(TenantId tenantId) {
146 log.trace("Executing deleteWidgetsBundlesByTenantId, tenantId [{}]", tenantId); 146 log.trace("Executing deleteWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
148 - tenantWidgetsBundleRemover.removeEntitites(tenantId); 148 + tenantWidgetsBundleRemover.removeEntities(tenantId);
149 } 149 }
150 150
151 private DataValidator<WidgetsBundle> widgetsBundleValidator = 151 private DataValidator<WidgetsBundle> widgetsBundleValidator =
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 17
18 CREATE TABLE IF NOT EXISTS admin_settings ( 18 CREATE TABLE IF NOT EXISTS admin_settings (
19 id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY, 19 id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY,
20 - json_value varchar, 20 + json_value text,
21 key character varying(255) 21 key character varying(255)
22 ); 22 );
23 23
@@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS alarm ( @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS alarm (
25 id uuid NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY, 25 id uuid NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY,
26 ack_ts bigint, 26 ack_ts bigint,
27 clear_ts bigint, 27 clear_ts bigint,
28 - additional_info varchar, 28 + additional_info text,
29 end_ts bigint, 29 end_ts bigint,
30 originator_id uuid, 30 originator_id uuid,
31 originator_type integer, 31 originator_type integer,
@@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS alarm ( @@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS alarm (
39 39
40 CREATE TABLE IF NOT EXISTS asset ( 40 CREATE TABLE IF NOT EXISTS asset (
41 id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, 41 id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY,
42 - additional_info varchar, 42 + additional_info text,
43 customer_id uuid, 43 customer_id uuid,
44 name character varying(255), 44 name character varying(255),
45 search_text character varying(255), 45 search_text character varying(255),
@@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor (
64 id uuid NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY, 64 id uuid NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY,
65 actions character varying(255), 65 actions character varying(255),
66 clazz character varying(255), 66 clazz character varying(255),
67 - configuration_descriptor varchar, 67 + configuration_descriptor text,
68 name character varying(255), 68 name character varying(255),
69 scope character varying(255), 69 scope character varying(255),
70 search_text character varying(255), 70 search_text character varying(255),
@@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( @@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor (
73 73
74 CREATE TABLE IF NOT EXISTS customer ( 74 CREATE TABLE IF NOT EXISTS customer (
75 id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY, 75 id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY,
76 - additional_info varchar, 76 + additional_info text,
77 address character varying(255), 77 address character varying(255),
78 address2 character varying(255), 78 address2 character varying(255),
79 city character varying(255), 79 city character varying(255),
@@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS customer ( @@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS customer (
89 89
90 CREATE TABLE IF NOT EXISTS dashboard ( 90 CREATE TABLE IF NOT EXISTS dashboard (
91 id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, 91 id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY,
92 - configuration varchar, 92 + configuration text,
93 customer_id uuid, 93 customer_id uuid,
94 search_text character varying(255), 94 search_text character varying(255),
95 tenant_id uuid, 95 tenant_id uuid,
@@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS dashboard ( @@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS dashboard (
98 98
99 CREATE TABLE IF NOT EXISTS device ( 99 CREATE TABLE IF NOT EXISTS device (
100 id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY, 100 id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY,
101 - additional_info varchar, 101 + additional_info text,
102 customer_id uuid, 102 customer_id uuid,
103 type character varying(255), 103 type character varying(255),
104 name character varying(255), 104 name character varying(255),
@@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS device_credentials ( @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS device_credentials (
116 116
117 CREATE TABLE IF NOT EXISTS event ( 117 CREATE TABLE IF NOT EXISTS event (
118 id uuid NOT NULL CONSTRAINT event_pkey PRIMARY KEY, 118 id uuid NOT NULL CONSTRAINT event_pkey PRIMARY KEY,
119 - body varchar, 119 + body text,
120 entity_id uuid, 120 entity_id uuid,
121 entity_type character varying(255), 121 entity_type character varying(255),
122 event_type character varying(255), 122 event_type character varying(255),
@@ -126,10 +126,10 @@ CREATE TABLE IF NOT EXISTS event ( @@ -126,10 +126,10 @@ CREATE TABLE IF NOT EXISTS event (
126 126
127 CREATE TABLE IF NOT EXISTS plugin ( 127 CREATE TABLE IF NOT EXISTS plugin (
128 id uuid NOT NULL CONSTRAINT plugin_pkey PRIMARY KEY, 128 id uuid NOT NULL CONSTRAINT plugin_pkey PRIMARY KEY,
129 - additional_info varchar, 129 + additional_info text,
130 api_token character varying(255), 130 api_token character varying(255),
131 plugin_class character varying(255), 131 plugin_class character varying(255),
132 - configuration varchar, 132 + configuration text,
133 name character varying(255), 133 name character varying(255),
134 public_access boolean, 134 public_access boolean,
135 search_text character varying(255), 135 search_text character varying(255),
@@ -144,18 +144,18 @@ CREATE TABLE IF NOT EXISTS relation ( @@ -144,18 +144,18 @@ CREATE TABLE IF NOT EXISTS relation (
144 to_type character varying(255), 144 to_type character varying(255),
145 relation_type_group character varying(255), 145 relation_type_group character varying(255),
146 relation_type character varying(255), 146 relation_type character varying(255),
147 - additional_info varchar, 147 + additional_info text,
148 CONSTRAINT relation_unq_key UNIQUE (from_id, from_type, relation_type_group, relation_type, to_id, to_type) 148 CONSTRAINT relation_unq_key UNIQUE (from_id, from_type, relation_type_group, relation_type, to_id, to_type)
149 ); 149 );
150 150
151 CREATE TABLE IF NOT EXISTS rule ( 151 CREATE TABLE IF NOT EXISTS rule (
152 id uuid NOT NULL CONSTRAINT rule_pkey PRIMARY KEY, 152 id uuid NOT NULL CONSTRAINT rule_pkey PRIMARY KEY,
153 - action varchar,  
154 - additional_info varchar,  
155 - filters varchar, 153 + action text,
  154 + additional_info text,
  155 + filters text,
156 name character varying(255), 156 name character varying(255),
157 plugin_token character varying(255), 157 plugin_token character varying(255),
158 - processor varchar, 158 + processor text,
159 search_text character varying(255), 159 search_text character varying(255),
160 state character varying(255), 160 state character varying(255),
161 tenant_id uuid, 161 tenant_id uuid,
@@ -164,7 +164,7 @@ CREATE TABLE IF NOT EXISTS rule ( @@ -164,7 +164,7 @@ CREATE TABLE IF NOT EXISTS rule (
164 164
165 CREATE TABLE IF NOT EXISTS tb_user ( 165 CREATE TABLE IF NOT EXISTS tb_user (
166 id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, 166 id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY,
167 - additional_info varchar, 167 + additional_info text,
168 authority character varying(255), 168 authority character varying(255),
169 customer_id uuid, 169 customer_id uuid,
170 email character varying(255) UNIQUE, 170 email character varying(255) UNIQUE,
@@ -176,7 +176,7 @@ CREATE TABLE IF NOT EXISTS tb_user ( @@ -176,7 +176,7 @@ CREATE TABLE IF NOT EXISTS tb_user (
176 176
177 CREATE TABLE IF NOT EXISTS tenant ( 177 CREATE TABLE IF NOT EXISTS tenant (
178 id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY, 178 id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY,
179 - additional_info varchar, 179 + additional_info text,
180 address character varying(255), 180 address character varying(255),
181 address2 character varying(255), 181 address2 character varying(255),
182 city character varying(255), 182 city character varying(255),
@@ -227,7 +227,7 @@ CREATE TABLE IF NOT EXISTS widget_type ( @@ -227,7 +227,7 @@ CREATE TABLE IF NOT EXISTS widget_type (
227 id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY, 227 id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY,
228 alias character varying(255), 228 alias character varying(255),
229 bundle_alias character varying(255), 229 bundle_alias character varying(255),
230 - descriptor varchar, 230 + descriptor text,
231 name character varying(255), 231 name character varying(255),
232 tenant_id uuid 232 tenant_id uuid
233 ); 233 );
@@ -16,13 +16,11 @@ @@ -16,13 +16,11 @@
16 package org.thingsboard.server.dao.service; 16 package org.thingsboard.server.dao.service;
17 17
18 import com.datastax.driver.core.utils.UUIDs; 18 import com.datastax.driver.core.utils.UUIDs;
19 -import com.google.common.util.concurrent.ListenableFuture;  
20 import org.junit.After; 19 import org.junit.After;
21 import org.junit.Assert; 20 import org.junit.Assert;
22 import org.junit.Before; 21 import org.junit.Before;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.thingsboard.server.common.data.EntityType; 23 import org.thingsboard.server.common.data.EntityType;
25 -import org.thingsboard.server.common.data.asset.Asset;  
26 import org.thingsboard.server.common.data.id.AssetId; 24 import org.thingsboard.server.common.data.id.AssetId;
27 import org.thingsboard.server.common.data.id.DeviceId; 25 import org.thingsboard.server.common.data.id.DeviceId;
28 import org.thingsboard.server.common.data.relation.EntityRelation; 26 import org.thingsboard.server.common.data.relation.EntityRelation;
1 -/**  
2 - * Copyright © 2016-2017 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.service;  
17 -  
18 -import com.datastax.driver.core.utils.UUIDs;  
19 -import com.google.common.util.concurrent.ListenableFuture;  
20 -import org.junit.After;  
21 -import org.junit.Assert;  
22 -import org.junit.Before;  
23 -import org.junit.Test;  
24 -import org.thingsboard.server.common.data.EntityType;  
25 -import org.thingsboard.server.common.data.asset.Asset;  
26 -import org.thingsboard.server.common.data.id.AssetId;  
27 -import org.thingsboard.server.common.data.id.DeviceId;  
28 -import org.thingsboard.server.common.data.relation.EntityRelation;  
29 -import org.thingsboard.server.common.data.relation.RelationTypeGroup;  
30 -import org.thingsboard.server.dao.exception.DataValidationException;  
31 -import org.thingsboard.server.dao.relation.EntityRelationsQuery;  
32 -import org.thingsboard.server.dao.relation.EntitySearchDirection;  
33 -import org.thingsboard.server.dao.relation.EntityTypeFilter;  
34 -import org.thingsboard.server.dao.relation.RelationsSearchParameters;  
35 -  
36 -import java.util.Collections;  
37 -import java.util.List;  
38 -import java.util.concurrent.ExecutionException;  
39 -  
40 -public class RelationServiceTest extends AbstractServiceTest {  
41 -  
42 - @Before  
43 - public void before() {  
44 - }  
45 -  
46 - @After  
47 - public void after() {  
48 - }  
49 -  
50 - @Test  
51 - public void testSaveRelation() throws ExecutionException, InterruptedException {  
52 - AssetId parentId = new AssetId(UUIDs.timeBased());  
53 - AssetId childId = new AssetId(UUIDs.timeBased());  
54 -  
55 - EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);  
56 -  
57 - Assert.assertTrue(saveRelation(relation));  
58 -  
59 - Assert.assertTrue(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
60 -  
61 - Assert.assertFalse(relationService.checkRelation(parentId, childId, "NOT_EXISTING_TYPE", RelationTypeGroup.COMMON).get());  
62 -  
63 - Assert.assertFalse(relationService.checkRelation(childId, parentId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
64 -  
65 - Assert.assertFalse(relationService.checkRelation(childId, parentId, "NOT_EXISTING_TYPE", RelationTypeGroup.COMMON).get());  
66 - }  
67 -  
68 - @Test  
69 - public void testDeleteRelation() throws ExecutionException, InterruptedException {  
70 - AssetId parentId = new AssetId(UUIDs.timeBased());  
71 - AssetId childId = new AssetId(UUIDs.timeBased());  
72 - AssetId subChildId = new AssetId(UUIDs.timeBased());  
73 -  
74 - EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);  
75 - EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);  
76 -  
77 - saveRelation(relationA);  
78 - saveRelation(relationB);  
79 -  
80 - Assert.assertTrue(relationService.deleteRelation(relationA).get());  
81 -  
82 - Assert.assertFalse(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
83 -  
84 - Assert.assertTrue(relationService.checkRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
85 -  
86 - Assert.assertTrue(relationService.deleteRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
87 - }  
88 -  
89 - @Test  
90 - public void testDeleteEntityRelations() throws ExecutionException, InterruptedException {  
91 - AssetId parentId = new AssetId(UUIDs.timeBased());  
92 - AssetId childId = new AssetId(UUIDs.timeBased());  
93 - AssetId subChildId = new AssetId(UUIDs.timeBased());  
94 -  
95 - EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);  
96 - EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);  
97 -  
98 - saveRelation(relationA);  
99 - saveRelation(relationB);  
100 -  
101 - Assert.assertTrue(relationService.deleteEntityRelations(childId).get());  
102 -  
103 - Assert.assertFalse(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
104 -  
105 - Assert.assertFalse(relationService.checkRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());  
106 - }  
107 -  
108 - @Test  
109 - public void testFindFrom() throws ExecutionException, InterruptedException {  
110 - AssetId parentA = new AssetId(UUIDs.timeBased());  
111 - AssetId parentB = new AssetId(UUIDs.timeBased());  
112 - AssetId childA = new AssetId(UUIDs.timeBased());  
113 - AssetId childB = new AssetId(UUIDs.timeBased());  
114 -  
115 - EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);  
116 - EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);  
117 -  
118 - EntityRelation relationB1 = new EntityRelation(parentB, childA, EntityRelation.MANAGES_TYPE);  
119 - EntityRelation relationB2 = new EntityRelation(parentB, childB, EntityRelation.MANAGES_TYPE);  
120 -  
121 - saveRelation(relationA1);  
122 - saveRelation(relationA2);  
123 -  
124 - saveRelation(relationB1);  
125 - saveRelation(relationB2);  
126 -  
127 - List<EntityRelation> relations = relationService.findByFrom(parentA, RelationTypeGroup.COMMON).get();  
128 - Assert.assertEquals(2, relations.size());  
129 - for (EntityRelation relation : relations) {  
130 - Assert.assertEquals(EntityRelation.CONTAINS_TYPE, relation.getType());  
131 - Assert.assertEquals(parentA, relation.getFrom());  
132 - Assert.assertTrue(childA.equals(relation.getTo()) || childB.equals(relation.getTo()));  
133 - }  
134 -  
135 - relations = relationService.findByFromAndType(parentA, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get();  
136 - Assert.assertEquals(2, relations.size());  
137 -  
138 - relations = relationService.findByFromAndType(parentA, EntityRelation.MANAGES_TYPE, RelationTypeGroup.COMMON).get();  
139 - Assert.assertEquals(0, relations.size());  
140 -  
141 - relations = relationService.findByFrom(parentB, RelationTypeGroup.COMMON).get();  
142 - Assert.assertEquals(2, relations.size());  
143 - for (EntityRelation relation : relations) {  
144 - Assert.assertEquals(EntityRelation.MANAGES_TYPE, relation.getType());  
145 - Assert.assertEquals(parentB, relation.getFrom());  
146 - Assert.assertTrue(childA.equals(relation.getTo()) || childB.equals(relation.getTo()));  
147 - }  
148 -  
149 - relations = relationService.findByFromAndType(parentB, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get();  
150 - Assert.assertEquals(0, relations.size());  
151 -  
152 - relations = relationService.findByFromAndType(parentB, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get();  
153 - Assert.assertEquals(0, relations.size());  
154 - }  
155 -  
156 - private Boolean saveRelation(EntityRelation relationA1) throws ExecutionException, InterruptedException {  
157 - return relationService.saveRelation(relationA1).get();  
158 - }  
159 -  
160 - @Test  
161 - public void testFindTo() throws ExecutionException, InterruptedException {  
162 - AssetId parentA = new AssetId(UUIDs.timeBased());  
163 - AssetId parentB = new AssetId(UUIDs.timeBased());  
164 - AssetId childA = new AssetId(UUIDs.timeBased());  
165 - AssetId childB = new AssetId(UUIDs.timeBased());  
166 -  
167 - EntityRelation relationA1 = new EntityRelation(parentA, childA, EntityRelation.CONTAINS_TYPE);  
168 - EntityRelation relationA2 = new EntityRelation(parentA, childB, EntityRelation.CONTAINS_TYPE);  
169 -  
170 - EntityRelation relationB1 = new EntityRelation(parentB, childA, EntityRelation.MANAGES_TYPE);  
171 - EntityRelation relationB2 = new EntityRelation(parentB, childB, EntityRelation.MANAGES_TYPE);  
172 -  
173 - saveRelation(relationA1);  
174 - saveRelation(relationA2);  
175 -  
176 - saveRelation(relationB1);  
177 - saveRelation(relationB2);  
178 -  
179 - // Data propagation to views is async  
180 - Thread.sleep(3000);  
181 -  
182 - List<EntityRelation> relations = relationService.findByTo(childA, RelationTypeGroup.COMMON).get();  
183 - Assert.assertEquals(2, relations.size());  
184 - for (EntityRelation relation : relations) {  
185 - Assert.assertEquals(childA, relation.getTo());  
186 - Assert.assertTrue(parentA.equals(relation.getFrom()) || parentB.equals(relation.getFrom()));  
187 - }  
188 -  
189 - relations = relationService.findByToAndType(childA, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get();  
190 - Assert.assertEquals(1, relations.size());  
191 -  
192 - relations = relationService.findByToAndType(childB, EntityRelation.MANAGES_TYPE, RelationTypeGroup.COMMON).get();  
193 - Assert.assertEquals(1, relations.size());  
194 -  
195 - relations = relationService.findByToAndType(parentA, EntityRelation.MANAGES_TYPE, RelationTypeGroup.COMMON).get();  
196 - Assert.assertEquals(0, relations.size());  
197 -  
198 - relations = relationService.findByToAndType(parentB, EntityRelation.MANAGES_TYPE, RelationTypeGroup.COMMON).get();  
199 - Assert.assertEquals(0, relations.size());  
200 -  
201 - relations = relationService.findByTo(childB, RelationTypeGroup.COMMON).get();  
202 - Assert.assertEquals(2, relations.size());  
203 - for (EntityRelation relation : relations) {  
204 - Assert.assertEquals(childB, relation.getTo());  
205 - Assert.assertTrue(parentA.equals(relation.getFrom()) || parentB.equals(relation.getFrom()));  
206 - }  
207 - }  
208 -  
209 - @Test  
210 - public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException {  
211 - // A -> B -> C -> A  
212 - AssetId assetA = new AssetId(UUIDs.timeBased());  
213 - AssetId assetB = new AssetId(UUIDs.timeBased());  
214 - AssetId assetC = new AssetId(UUIDs.timeBased());  
215 -  
216 - EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);  
217 - EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);  
218 - EntityRelation relationC = new EntityRelation(assetC, assetA, EntityRelation.CONTAINS_TYPE);  
219 -  
220 - saveRelation(relationA);  
221 - saveRelation(relationB);  
222 - saveRelation(relationC);  
223 -  
224 - EntityRelationsQuery query = new EntityRelationsQuery();  
225 - query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));  
226 - query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));  
227 - List<EntityRelation> relations = relationService.findByQuery(query).get();  
228 - Assert.assertEquals(3, relations.size());  
229 - Assert.assertTrue(relations.contains(relationA));  
230 - Assert.assertTrue(relations.contains(relationB));  
231 - Assert.assertTrue(relations.contains(relationC));  
232 - }  
233 -  
234 - @Test  
235 - public void testRecursiveRelation() throws ExecutionException, InterruptedException {  
236 - // A -> B -> [C,D]  
237 - AssetId assetA = new AssetId(UUIDs.timeBased());  
238 - AssetId assetB = new AssetId(UUIDs.timeBased());  
239 - AssetId assetC = new AssetId(UUIDs.timeBased());  
240 - DeviceId deviceD = new DeviceId(UUIDs.timeBased());  
241 -  
242 - EntityRelation relationAB = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);  
243 - EntityRelation relationBC = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);  
244 - EntityRelation relationBD = new EntityRelation(assetB, deviceD, EntityRelation.CONTAINS_TYPE);  
245 -  
246 -  
247 - saveRelation(relationAB);  
248 - saveRelation(relationBC);  
249 - saveRelation(relationBD);  
250 -  
251 - EntityRelationsQuery query = new EntityRelationsQuery();  
252 - query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));  
253 - query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));  
254 - List<EntityRelation> relations = relationService.findByQuery(query).get();  
255 - Assert.assertEquals(2, relations.size());  
256 - Assert.assertTrue(relations.contains(relationAB));  
257 - Assert.assertTrue(relations.contains(relationBC));  
258 - }  
259 -  
260 -  
261 - @Test(expected = DataValidationException.class)  
262 - public void testSaveRelationWithEmptyFrom() throws ExecutionException, InterruptedException {  
263 - EntityRelation relation = new EntityRelation();  
264 - relation.setTo(new AssetId(UUIDs.timeBased()));  
265 - relation.setType(EntityRelation.CONTAINS_TYPE);  
266 - Assert.assertTrue(saveRelation(relation));  
267 - }  
268 -  
269 - @Test(expected = DataValidationException.class)  
270 - public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException {  
271 - EntityRelation relation = new EntityRelation();  
272 - relation.setFrom(new AssetId(UUIDs.timeBased()));  
273 - relation.setType(EntityRelation.CONTAINS_TYPE);  
274 - Assert.assertTrue(saveRelation(relation));  
275 - }  
276 -  
277 - @Test(expected = DataValidationException.class)  
278 - public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException {  
279 - EntityRelation relation = new EntityRelation();  
280 - relation.setFrom(new AssetId(UUIDs.timeBased()));  
281 - relation.setTo(new AssetId(UUIDs.timeBased()));  
282 - Assert.assertTrue(saveRelation(relation));  
283 - }  
284 -}  
@@ -5,8 +5,6 @@ sql.enabled=true @@ -5,8 +5,6 @@ sql.enabled=true
5 spring.jpa.show-sql=false 5 spring.jpa.show-sql=false
6 spring.jpa.hibernate.ddl-auto=validate 6 spring.jpa.hibernate.ddl-auto=validate
7 7
8 -spring.datasource.driverClassName=org.h2.Driver  
9 -spring.datasource.url=jdbc:h2:mem:test;MODE=PostgreSQL  
10 -spring.datasource.schema=classpath:postgres/schema.sql  
11 -spring.datasource.data=classpath:postgres/system-data.sql;classpath:system-test.sql  
12 - 8 +spring.datasource.url=jdbc:postgresql://localhost:5432/thingsboard
  9 +spring.datasource.username=postgres
  10 +spring.datasource.password=postgres
  1 +TRUNCATE TABLE plugin;
  2 +TRUNCATE TABLE rule;