Commit 65e4739320101a416b2eda9cb1007a3c07c9a382

Authored by Andrew Shvayka
Committed by GitHub
2 parents 1a6826c0 996658eb

Merge pull request #152 from thingsboard/dao-refactoring-vs

Dao refactoring to support PostgreSQL
Showing 84 changed files with 1020 additions and 1016 deletions

Too many changes to show.

To preserve performance only 84 of 334 files are displayed.

@@ -241,6 +241,21 @@ @@ -241,6 +241,21 @@
241 <artifactId>mockito-all</artifactId> 241 <artifactId>mockito-all</artifactId>
242 <scope>test</scope> 242 <scope>test</scope>
243 </dependency> 243 </dependency>
  244 + <dependency>
  245 + <groupId>org.dbunit</groupId>
  246 + <artifactId>dbunit</artifactId>
  247 + <scope>test</scope>
  248 + </dependency>
  249 + <dependency>
  250 + <groupId>com.github.springtestdbunit</groupId>
  251 + <artifactId>spring-test-dbunit</artifactId>
  252 + <scope>test</scope>
  253 + </dependency>
  254 + <dependency>
  255 + <groupId>ru.yandex.qatools.embed</groupId>
  256 + <artifactId>postgresql-embedded</artifactId>
  257 + <scope>test</scope>
  258 + </dependency>
244 </dependencies> 259 </dependencies>
245 260
246 <build> 261 <build>
@@ -16,15 +16,13 @@ @@ -16,15 +16,13 @@
16 package org.thingsboard.server; 16 package org.thingsboard.server;
17 17
18 import org.springframework.boot.SpringApplication; 18 import org.springframework.boot.SpringApplication;
19 -import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
20 -import org.springframework.boot.autoconfigure.SpringBootApplication; 19 +import org.springframework.boot.SpringBootConfiguration;
21 import org.springframework.context.annotation.ComponentScan; 20 import org.springframework.context.annotation.ComponentScan;
22 import springfox.documentation.swagger2.annotations.EnableSwagger2; 21 import springfox.documentation.swagger2.annotations.EnableSwagger2;
23 22
24 import java.util.Arrays; 23 import java.util.Arrays;
25 24
26 -@EnableAutoConfiguration  
27 -@SpringBootApplication 25 +@SpringBootConfiguration
28 @EnableSwagger2 26 @EnableSwagger2
29 @ComponentScan({"org.thingsboard.server"}) 27 @ComponentScan({"org.thingsboard.server"})
30 public class ThingsboardServerApplication { 28 public class ThingsboardServerApplication {
@@ -15,15 +15,7 @@ @@ -15,15 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.actors.plugin; 16 package org.thingsboard.server.actors.plugin;
17 17
18 -import java.io.IOException;  
19 -import java.util.*;  
20 -import java.util.concurrent.Executor;  
21 -import java.util.concurrent.Executors;  
22 -import java.util.stream.Collectors;  
23 -  
24 -import com.datastax.driver.core.ResultSet;  
25 -import com.datastax.driver.core.ResultSetFuture;  
26 -import com.datastax.driver.core.Row; 18 +import akka.actor.ActorRef;
27 import com.google.common.base.Function; 19 import com.google.common.base.Function;
28 import com.google.common.util.concurrent.FutureCallback; 20 import com.google.common.util.concurrent.FutureCallback;
29 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
@@ -45,8 +37,8 @@ import org.thingsboard.server.common.data.rule.RuleMetaData; @@ -45,8 +37,8 @@ import org.thingsboard.server.common.data.rule.RuleMetaData;
45 import org.thingsboard.server.common.msg.cluster.ServerAddress; 37 import org.thingsboard.server.common.msg.cluster.ServerAddress;
46 import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; 38 import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg;
47 import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; 39 import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext;
48 -import org.thingsboard.server.extensions.api.plugins.PluginContext;  
49 import org.thingsboard.server.extensions.api.plugins.PluginCallback; 40 import org.thingsboard.server.extensions.api.plugins.PluginCallback;
  41 +import org.thingsboard.server.extensions.api.plugins.PluginContext;
50 import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; 42 import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg;
51 import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; 43 import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg;
52 import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest; 44 import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest;
@@ -55,9 +47,12 @@ import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; @@ -55,9 +47,12 @@ import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg;
55 import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; 47 import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef;
56 import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; 48 import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg;
57 49
58 -import akka.actor.ActorRef;  
59 -  
60 import javax.annotation.Nullable; 50 import javax.annotation.Nullable;
  51 +import java.io.IOException;
  52 +import java.util.*;
  53 +import java.util.concurrent.Executor;
  54 +import java.util.concurrent.Executors;
  55 +import java.util.stream.Collectors;
61 56
62 @Slf4j 57 @Slf4j
63 public final class PluginProcessingContext implements PluginContext { 58 public final class PluginProcessingContext implements PluginContext {
@@ -95,8 +90,8 @@ public final class PluginProcessingContext implements PluginContext { @@ -95,8 +90,8 @@ public final class PluginProcessingContext implements PluginContext {
95 @Override 90 @Override
96 public void saveAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<AttributeKvEntry> attributes, final PluginCallback<Void> callback) { 91 public void saveAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<AttributeKvEntry> attributes, final PluginCallback<Void> callback) {
97 validate(entityId, new ValidationCallback(callback, ctx -> { 92 validate(entityId, new ValidationCallback(callback, ctx -> {
98 - ListenableFuture<List<ResultSet>> rsListFuture = pluginCtx.attributesService.save(entityId, scope, attributes);  
99 - Futures.addCallback(rsListFuture, getListCallback(callback, v -> { 93 + ListenableFuture<List<Void>> futures = pluginCtx.attributesService.save(entityId, scope, attributes);
  94 + Futures.addCallback(futures, getListCallback(callback, v -> {
100 if (entityId.getEntityType() == EntityType.DEVICE) { 95 if (entityId.getEntityType() == EntityType.DEVICE) {
101 onDeviceAttributesChanged(tenantId, new DeviceId(entityId.getId()), scope, attributes); 96 onDeviceAttributesChanged(tenantId, new DeviceId(entityId.getId()), scope, attributes);
102 } 97 }
@@ -108,8 +103,8 @@ public final class PluginProcessingContext implements PluginContext { @@ -108,8 +103,8 @@ public final class PluginProcessingContext implements PluginContext {
108 @Override 103 @Override
109 public void removeAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<String> keys, final PluginCallback<Void> callback) { 104 public void removeAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<String> keys, final PluginCallback<Void> callback) {
110 validate(entityId, new ValidationCallback(callback, ctx -> { 105 validate(entityId, new ValidationCallback(callback, ctx -> {
111 - ListenableFuture<List<ResultSet>> future = pluginCtx.attributesService.removeAll(entityId, scope, keys);  
112 - Futures.addCallback(future, getCallback(callback, v -> null), executor); 106 + ListenableFuture<List<Void>> futures = pluginCtx.attributesService.removeAll(entityId, scope, keys);
  107 + Futures.addCallback(futures, getCallback(callback, v -> null), executor);
113 if (entityId.getEntityType() == EntityType.DEVICE) { 108 if (entityId.getEntityType() == EntityType.DEVICE) {
114 onDeviceAttributesDeleted(tenantId, new DeviceId(entityId.getId()), keys.stream().map(key -> new AttributeKey(scope, key)).collect(Collectors.toSet())); 109 onDeviceAttributesDeleted(tenantId, new DeviceId(entityId.getId()), keys.stream().map(key -> new AttributeKey(scope, key)).collect(Collectors.toSet()));
115 } 110 }
@@ -161,7 +156,7 @@ public final class PluginProcessingContext implements PluginContext { @@ -161,7 +156,7 @@ public final class PluginProcessingContext implements PluginContext {
161 @Override 156 @Override
162 public void saveTsData(final EntityId entityId, final TsKvEntry entry, final PluginCallback<Void> callback) { 157 public void saveTsData(final EntityId entityId, final TsKvEntry entry, final PluginCallback<Void> callback) {
163 validate(entityId, new ValidationCallback(callback, ctx -> { 158 validate(entityId, new ValidationCallback(callback, ctx -> {
164 - ListenableFuture<List<ResultSet>> rsListFuture = pluginCtx.tsService.save(entityId, entry); 159 + ListenableFuture<List<Void>> rsListFuture = pluginCtx.tsService.save(entityId, entry);
165 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor); 160 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor);
166 })); 161 }));
167 } 162 }
@@ -174,7 +169,7 @@ public final class PluginProcessingContext implements PluginContext { @@ -174,7 +169,7 @@ public final class PluginProcessingContext implements PluginContext {
174 @Override 169 @Override
175 public void saveTsData(final EntityId entityId, final List<TsKvEntry> entries, long ttl, final PluginCallback<Void> callback) { 170 public void saveTsData(final EntityId entityId, final List<TsKvEntry> entries, long ttl, final PluginCallback<Void> callback) {
176 validate(entityId, new ValidationCallback(callback, ctx -> { 171 validate(entityId, new ValidationCallback(callback, ctx -> {
177 - ListenableFuture<List<ResultSet>> rsListFuture = pluginCtx.tsService.save(entityId, entries, ttl); 172 + ListenableFuture<List<Void>> rsListFuture = pluginCtx.tsService.save(entityId, entries, ttl);
178 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor); 173 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor);
179 })); 174 }));
180 } 175 }
@@ -191,26 +186,16 @@ public final class PluginProcessingContext implements PluginContext { @@ -191,26 +186,16 @@ public final class PluginProcessingContext implements PluginContext {
191 @Override 186 @Override
192 public void loadLatestTimeseries(final EntityId entityId, final PluginCallback<List<TsKvEntry>> callback) { 187 public void loadLatestTimeseries(final EntityId entityId, final PluginCallback<List<TsKvEntry>> callback) {
193 validate(entityId, new ValidationCallback(callback, ctx -> { 188 validate(entityId, new ValidationCallback(callback, ctx -> {
194 - ResultSetFuture future = pluginCtx.tsService.findAllLatest(entityId);  
195 - Futures.addCallback(future, getCallback(callback, pluginCtx.tsService::convertResultSetToTsKvEntryList), executor); 189 + ListenableFuture<List<TsKvEntry>> future = pluginCtx.tsService.findAllLatest(entityId);
  190 + Futures.addCallback(future, getCallback(callback, v -> v), executor);
196 })); 191 }));
197 } 192 }
198 193
199 @Override 194 @Override
200 public void loadLatestTimeseries(final EntityId entityId, final Collection<String> keys, final PluginCallback<List<TsKvEntry>> callback) { 195 public void loadLatestTimeseries(final EntityId entityId, final Collection<String> keys, final PluginCallback<List<TsKvEntry>> callback) {
201 validate(entityId, new ValidationCallback(callback, ctx -> { 196 validate(entityId, new ValidationCallback(callback, ctx -> {
202 - ListenableFuture<List<ResultSet>> rsListFuture = pluginCtx.tsService.findLatest(entityId, keys);  
203 - Futures.addCallback(rsListFuture, getListCallback(callback, rsList ->  
204 - {  
205 - List<TsKvEntry> result = new ArrayList<>();  
206 - for (ResultSet rs : rsList) {  
207 - Row row = rs.one();  
208 - if (row != null) {  
209 - result.add(pluginCtx.tsService.convertResultToTsKvEntry(row));  
210 - }  
211 - }  
212 - return result;  
213 - }), executor); 197 + ListenableFuture<List<TsKvEntry>> rsListFuture = pluginCtx.tsService.findLatest(entityId, keys);
  198 + Futures.addCallback(rsListFuture, getCallback(callback, v -> v), executor);
214 })); 199 }));
215 } 200 }
216 201
@@ -237,10 +222,10 @@ public final class PluginProcessingContext implements PluginContext { @@ -237,10 +222,10 @@ public final class PluginProcessingContext implements PluginContext {
237 pluginCtx.toDeviceActor(DeviceAttributesEventNotificationMsg.onUpdate(tenantId, deviceId, scope, values)); 222 pluginCtx.toDeviceActor(DeviceAttributesEventNotificationMsg.onUpdate(tenantId, deviceId, scope, values));
238 } 223 }
239 224
240 - private <T> FutureCallback<List<ResultSet>> getListCallback(final PluginCallback<T> callback, Function<List<ResultSet>, T> transformer) {  
241 - return new FutureCallback<List<ResultSet>>() { 225 + private <T, R> FutureCallback<List<T>> getListCallback(final PluginCallback<R> callback, Function<List<T>, R> transformer) {
  226 + return new FutureCallback<List<T>>() {
242 @Override 227 @Override
243 - public void onSuccess(@Nullable List<ResultSet> result) { 228 + public void onSuccess(@Nullable List<T> result) {
244 pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, transformer.apply(result)), ActorRef.noSender()); 229 pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, transformer.apply(result)), ActorRef.noSender());
245 } 230 }
246 231
@@ -15,8 +15,6 @@ @@ -15,8 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 16 package org.thingsboard.server.controller;
17 17
18 -import com.fasterxml.jackson.databind.JsonNode;  
19 -import com.fasterxml.jackson.databind.ObjectMapper;  
20 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
21 import org.apache.commons.lang3.StringUtils; 19 import org.apache.commons.lang3.StringUtils;
22 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
@@ -67,6 +67,20 @@ public class CustomerController extends BaseController { @@ -67,6 +67,20 @@ public class CustomerController extends BaseController {
67 } 67 }
68 } 68 }
69 69
  70 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  71 + @RequestMapping(value = "/customer/{customerId}/title", method = RequestMethod.GET, produces = "application/text")
  72 + @ResponseBody
  73 + public String getCustomerTitleById(@PathVariable("customerId") String strCustomerId) throws ThingsboardException {
  74 + checkParameter("customerId", strCustomerId);
  75 + try {
  76 + CustomerId customerId = new CustomerId(toUUID(strCustomerId));
  77 + Customer customer = checkCustomerId(customerId);
  78 + return customer.getTitle();
  79 + } catch (Exception e) {
  80 + throw handleException(e);
  81 + }
  82 + }
  83 +
70 @PreAuthorize("hasAuthority('TENANT_ADMIN')") 84 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
71 @RequestMapping(value = "/customer", method = RequestMethod.POST) 85 @RequestMapping(value = "/customer", method = RequestMethod.POST)
72 @ResponseBody 86 @ResponseBody
@@ -25,7 +25,6 @@ import org.thingsboard.server.common.data.page.TextPageLink; @@ -25,7 +25,6 @@ import org.thingsboard.server.common.data.page.TextPageLink;
25 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; 25 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
26 import org.thingsboard.server.common.data.plugin.PluginMetaData; 26 import org.thingsboard.server.common.data.plugin.PluginMetaData;
27 import org.thingsboard.server.common.data.security.Authority; 27 import org.thingsboard.server.common.data.security.Authority;
28 -import org.thingsboard.server.common.data.widget.WidgetsBundle;  
29 import org.thingsboard.server.dao.model.ModelConstants; 28 import org.thingsboard.server.dao.model.ModelConstants;
30 import org.thingsboard.server.exception.ThingsboardException; 29 import org.thingsboard.server.exception.ThingsboardException;
31 30
@@ -15,34 +15,31 @@ @@ -15,34 +15,31 @@
15 */ 15 */
16 package org.thingsboard.server.service.mail; 16 package org.thingsboard.server.service.mail;
17 17
18 -import java.util.HashMap;  
19 -import java.util.Locale;  
20 -import java.util.Map;  
21 -import java.util.Properties;  
22 -  
23 -import javax.annotation.PostConstruct;  
24 -import javax.mail.internet.MimeMessage;  
25 - 18 +import com.fasterxml.jackson.databind.JsonNode;
26 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
27 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
28 import org.apache.velocity.app.VelocityEngine; 21 import org.apache.velocity.app.VelocityEngine;
29 -import org.springframework.beans.factory.annotation.Qualifier;  
30 -import org.thingsboard.server.exception.ThingsboardErrorCode;  
31 -import org.thingsboard.server.exception.ThingsboardException;  
32 -import org.thingsboard.server.common.data.AdminSettings;  
33 -import org.thingsboard.server.dao.settings.AdminSettingsService;  
34 -import org.thingsboard.server.dao.exception.IncorrectParameterException;  
35 -import org.slf4j.Logger;  
36 -import org.slf4j.LoggerFactory;  
37 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.beans.factory.annotation.Qualifier;
38 import org.springframework.context.MessageSource; 24 import org.springframework.context.MessageSource;
39 import org.springframework.core.NestedRuntimeException; 25 import org.springframework.core.NestedRuntimeException;
40 import org.springframework.mail.javamail.JavaMailSenderImpl; 26 import org.springframework.mail.javamail.JavaMailSenderImpl;
41 import org.springframework.mail.javamail.MimeMessageHelper; 27 import org.springframework.mail.javamail.MimeMessageHelper;
42 import org.springframework.stereotype.Service; 28 import org.springframework.stereotype.Service;
43 import org.springframework.ui.velocity.VelocityEngineUtils; 29 import org.springframework.ui.velocity.VelocityEngineUtils;
  30 +import org.thingsboard.server.common.data.AdminSettings;
  31 +import org.thingsboard.server.dao.exception.IncorrectParameterException;
  32 +import org.thingsboard.server.dao.settings.AdminSettingsService;
  33 +import org.thingsboard.server.exception.ThingsboardErrorCode;
  34 +import org.thingsboard.server.exception.ThingsboardException;
  35 +
  36 +import javax.annotation.PostConstruct;
  37 +import javax.mail.internet.MimeMessage;
  38 +import java.util.HashMap;
  39 +import java.util.Locale;
  40 +import java.util.Map;
  41 +import java.util.Properties;
44 42
45 -import com.fasterxml.jackson.databind.JsonNode;  
46 @Service 43 @Service
47 @Slf4j 44 @Slf4j
48 public class DefaultMailService implements MailService { 45 public class DefaultMailService implements MailService {
@@ -69,9 +66,13 @@ public class DefaultMailService implements MailService { @@ -69,9 +66,13 @@ public class DefaultMailService implements MailService {
69 @Override 66 @Override
70 public void updateMailConfiguration() { 67 public void updateMailConfiguration() {
71 AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail"); 68 AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail");
72 - JsonNode jsonConfig = settings.getJsonValue();  
73 - mailSender = createMailSender(jsonConfig);  
74 - mailFrom = jsonConfig.get("mailFrom").asText(); 69 + if (settings != null) {
  70 + JsonNode jsonConfig = settings.getJsonValue();
  71 + mailSender = createMailSender(jsonConfig);
  72 + mailFrom = jsonConfig.get("mailFrom").asText();
  73 + } else {
  74 + throw new IncorrectParameterException("Failed to date mail configuration. Settings not found!");
  75 + }
75 } 76 }
76 77
77 private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) { 78 private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) {
@@ -107,6 +107,7 @@ coap: @@ -107,6 +107,7 @@ coap:
107 107
108 # Cassandra driver configuration parameters 108 # Cassandra driver configuration parameters
109 cassandra: 109 cassandra:
  110 + enabled: "${CASSANDRA_ENABLED:false}"
110 # Thingsboard cluster name 111 # Thingsboard cluster name
111 cluster_name: "${CASSANDRA_CLUSTER_NAME:Thingsboard Cluster}" 112 cluster_name: "${CASSANDRA_CLUSTER_NAME:Thingsboard Cluster}"
112 # Thingsboard keyspace name 113 # Thingsboard keyspace name
@@ -152,7 +153,7 @@ cassandra: @@ -152,7 +153,7 @@ cassandra:
152 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS 153 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS
153 ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}" 154 ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}"
154 # Specify max data points per request 155 # Specify max data points per request
155 - min_aggregation_step_ms: "${TS_KV_MIN_AGGREGATION_STEP_MS:100}" 156 + min_aggregation_step_ms: "${TS_KV_MIN_AGGREGATION_STEP_MS:1000}"
156 157
157 # Actor system parameters 158 # Actor system parameters
158 actors: 159 actors:
@@ -222,3 +223,24 @@ spring.mvc.cors: @@ -222,3 +223,24 @@ spring.mvc.cors:
222 allowed-headers: "*" 223 allowed-headers: "*"
223 max-age: "1800" 224 max-age: "1800"
224 allow-credentials: "true" 225 allow-credentials: "true"
  226 +
  227 +# SQL DAO Configuration
  228 +sql:
  229 + enabled: "${SQL_ENABLED:true}"
  230 +
  231 +spring:
  232 + data:
  233 + jpa:
  234 + repositories:
  235 + enabled: "true"
  236 + jpa:
  237 + show-sql: "false"
  238 + generate-ddl: "true"
  239 + database-platform: "org.hibernate.dialect.PostgreSQLDialect"
  240 + hibernate:
  241 + ddl-auto: "validate"
  242 + datasource:
  243 + driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
  244 + url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"
  245 + username: "${SPRING_DATASOURCE_USERNAME:postgres}"
  246 + password: "${SPRING_DATASOURCE_PASSWORD:postgres}"
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;  
17 -  
18 -import org.junit.Test;  
19 -import org.junit.runner.RunWith;  
20 -import org.springframework.test.context.web.WebAppConfiguration;  
21 -import org.springframework.boot.test.IntegrationTest;  
22 -import org.springframework.boot.test.SpringApplicationConfiguration;  
23 -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;  
24 -  
25 -@RunWith(SpringJUnit4ClassRunner.class)  
26 -@SpringApplicationConfiguration(classes = ThingsboardServerApplication.class)  
27 -@WebAppConfiguration  
28 -@IntegrationTest("server.port:0")  
29 -public class ThingsboardApplicationTests {  
30 -  
31 - @Test  
32 - public void contextLoads() {  
33 - String test = "[ \n" +  
34 - " {\n" +  
35 - " \"key\": \"name\",\n" +  
36 - "\t\"type\": \"text\" \n" +  
37 - " },\n" +  
38 - " {\n" +  
39 - "\t\"key\": \"name2\",\n" +  
40 - "\t\"type\": \"color\"\n" +  
41 - " },\n" +  
42 - " {\n" +  
43 - "\t\"key\": \"name3\",\n" +  
44 - "\t\"type\": \"javascript\"\n" +  
45 - " } \n" +  
46 - "]";  
47 - }  
48 -  
49 -}  
@@ -28,14 +28,9 @@ import org.junit.After; @@ -28,14 +28,9 @@ import org.junit.After;
28 import org.junit.Assert; 28 import org.junit.Assert;
29 import org.junit.Before; 29 import org.junit.Before;
30 import org.junit.runner.RunWith; 30 import org.junit.runner.RunWith;
31 -import org.mockito.Mockito;  
32 -import org.mockito.invocation.InvocationOnMock;  
33 -import org.mockito.stubbing.Answer;  
34 import org.springframework.beans.factory.annotation.Autowired; 31 import org.springframework.beans.factory.annotation.Autowired;
35 -import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
36 -import org.springframework.boot.test.IntegrationTest;  
37 -import org.springframework.boot.test.SpringApplicationContextLoader;  
38 -import org.springframework.context.annotation.Bean; 32 +import org.springframework.boot.test.context.SpringBootContextLoader;
  33 +import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.context.annotation.ComponentScan; 34 import org.springframework.context.annotation.ComponentScan;
40 import org.springframework.context.annotation.Configuration; 35 import org.springframework.context.annotation.Configuration;
41 import org.springframework.http.HttpHeaders; 36 import org.springframework.http.HttpHeaders;
@@ -48,7 +43,7 @@ import org.springframework.test.annotation.DirtiesContext; @@ -48,7 +43,7 @@ import org.springframework.test.annotation.DirtiesContext;
48 import org.springframework.test.context.ActiveProfiles; 43 import org.springframework.test.context.ActiveProfiles;
49 import org.springframework.test.context.ContextConfiguration; 44 import org.springframework.test.context.ContextConfiguration;
50 import org.springframework.test.context.TestPropertySource; 45 import org.springframework.test.context.TestPropertySource;
51 -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 46 +import org.springframework.test.context.junit4.SpringRunner;
52 import org.springframework.test.context.web.WebAppConfiguration; 47 import org.springframework.test.context.web.WebAppConfiguration;
53 import org.springframework.test.web.servlet.MockMvc; 48 import org.springframework.test.web.servlet.MockMvc;
54 import org.springframework.test.web.servlet.ResultActions; 49 import org.springframework.test.web.servlet.ResultActions;
@@ -66,11 +61,9 @@ import org.thingsboard.server.common.data.id.UUIDBased; @@ -66,11 +61,9 @@ import org.thingsboard.server.common.data.id.UUIDBased;
66 import org.thingsboard.server.common.data.page.TextPageLink; 61 import org.thingsboard.server.common.data.page.TextPageLink;
67 import org.thingsboard.server.common.data.security.Authority; 62 import org.thingsboard.server.common.data.security.Authority;
68 import org.thingsboard.server.config.ThingsboardSecurityConfiguration; 63 import org.thingsboard.server.config.ThingsboardSecurityConfiguration;
69 -import org.thingsboard.server.exception.ThingsboardException;  
70 -import org.thingsboard.server.service.mail.MailService;  
71 import org.thingsboard.server.service.mail.TestMailService; 64 import org.thingsboard.server.service.mail.TestMailService;
72 -import org.thingsboard.server.service.security.auth.rest.LoginRequest;  
73 import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest; 65 import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest;
  66 +import org.thingsboard.server.service.security.auth.rest.LoginRequest;
74 67
75 import java.io.IOException; 68 import java.io.IOException;
76 import java.nio.charset.Charset; 69 import java.nio.charset.Charset;
@@ -81,21 +74,18 @@ import java.util.List; @@ -81,21 +74,18 @@ import java.util.List;
81 74
82 import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; 75 import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
83 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 76 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
84 -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;  
85 -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;  
86 -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 77 +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
87 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; 78 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
88 79
89 @ActiveProfiles("test") 80 @ActiveProfiles("test")
90 -@RunWith(SpringJUnit4ClassRunner.class)  
91 -@ContextConfiguration(classes=AbstractControllerTest.class, loader=SpringApplicationContextLoader.class)  
92 -@TestPropertySource(locations = {"classpath:cassandra-test.properties", "classpath:thingsboard-test.properties"}) 81 +@RunWith(SpringRunner.class)
  82 +@ContextConfiguration(classes = AbstractControllerTest.class, loader = SpringBootContextLoader.class)
  83 +@TestPropertySource(locations = {"classpath:cassandra-test.properties", "classpath:application-test.properties", "classpath:nosql-test.properties"})
93 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) 84 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
94 @Configuration 85 @Configuration
95 -@EnableAutoConfiguration  
96 @ComponentScan({"org.thingsboard.server"}) 86 @ComponentScan({"org.thingsboard.server"})
97 @WebAppConfiguration 87 @WebAppConfiguration
98 -@IntegrationTest("server.port:0") 88 +@SpringBootTest
99 public abstract class AbstractControllerTest { 89 public abstract class AbstractControllerTest {
100 90
101 protected static final String TEST_TENANT_NAME = "TEST TENANT"; 91 protected static final String TEST_TENANT_NAME = "TEST TENANT";
@@ -113,7 +103,6 @@ public abstract class AbstractControllerTest { @@ -113,7 +103,6 @@ public abstract class AbstractControllerTest {
113 MediaType.APPLICATION_JSON.getSubtype(), 103 MediaType.APPLICATION_JSON.getSubtype(),
114 Charset.forName("utf8")); 104 Charset.forName("utf8"));
115 105
116 -  
117 protected MockMvc mockMvc; 106 protected MockMvc mockMvc;
118 107
119 protected String token; 108 protected String token;
@@ -305,7 +294,7 @@ public abstract class AbstractControllerTest { @@ -305,7 +294,7 @@ public abstract class AbstractControllerTest {
305 protected <T> T doPost(String urlTemplate, T content, Class<T> responseClass, String... params) throws Exception { 294 protected <T> T doPost(String urlTemplate, T content, Class<T> responseClass, String... params) throws Exception {
306 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass); 295 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass);
307 } 296 }
308 - 297 +
309 protected <T> T doDelete(String urlTemplate, Class<T> responseClass, String... params) throws Exception { 298 protected <T> T doDelete(String urlTemplate, Class<T> responseClass, String... params) throws Exception {
310 return readResponse(doDelete(urlTemplate, params).andExpect(status().isOk()), responseClass); 299 return readResponse(doDelete(urlTemplate, params).andExpect(status().isOk()), responseClass);
311 } 300 }
@@ -364,8 +353,8 @@ public abstract class AbstractControllerTest { @@ -364,8 +353,8 @@ public abstract class AbstractControllerTest {
364 ObjectMapper mapper = new ObjectMapper(); 353 ObjectMapper mapper = new ObjectMapper();
365 return mapper.readerFor(type).readValue(content); 354 return mapper.readerFor(type).readValue(content);
366 } 355 }
367 -  
368 - class IdComparator<D extends BaseData<? extends UUIDBased>> implements Comparator<D> { 356 +
  357 + public class IdComparator<D extends BaseData<? extends UUIDBased>> implements Comparator<D> {
369 @Override 358 @Override
370 public int compare(D o1, D o2) { 359 public int compare(D o1, D o2) {
371 return o1.getId().getId().compareTo(o2.getId().getId()); 360 return o1.getId().getId().compareTo(o2.getId().getId());
@@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.*; @@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.*;
28 import org.thingsboard.server.common.data.asset.Asset; 28 import org.thingsboard.server.common.data.asset.Asset;
29 import org.thingsboard.server.common.data.asset.TenantAssetType; 29 import org.thingsboard.server.common.data.asset.TenantAssetType;
30 import org.thingsboard.server.common.data.id.CustomerId; 30 import org.thingsboard.server.common.data.id.CustomerId;
31 -import org.thingsboard.server.common.data.id.AssetId;  
32 import org.thingsboard.server.common.data.page.TextPageData; 31 import org.thingsboard.server.common.data.page.TextPageData;
33 import org.thingsboard.server.common.data.page.TextPageLink; 32 import org.thingsboard.server.common.data.page.TextPageLink;
34 import org.thingsboard.server.common.data.security.Authority; 33 import org.thingsboard.server.common.data.security.Authority;
@@ -18,22 +18,22 @@ package org.thingsboard.server.controller; @@ -18,22 +18,22 @@ package org.thingsboard.server.controller;
18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
19 import org.junit.ClassRule; 19 import org.junit.ClassRule;
20 import org.junit.extensions.cpsuite.ClasspathSuite; 20 import org.junit.extensions.cpsuite.ClasspathSuite;
21 -import org.junit.extensions.cpsuite.ClasspathSuite.ClassnameFilters;  
22 import org.junit.runner.RunWith; 21 import org.junit.runner.RunWith;
23 import org.thingsboard.server.dao.CustomCassandraCQLUnit; 22 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
24 23
25 import java.util.Arrays; 24 import java.util.Arrays;
26 25
27 @RunWith(ClasspathSuite.class) 26 @RunWith(ClasspathSuite.class)
28 -@ClassnameFilters({"org.thingsboard.server.controller.*Test"}) 27 +@ClasspathSuite.ClassnameFilters({
  28 + "org.thingsboard.server.controller.*Test"})
29 public class ControllerTestSuite { 29 public class ControllerTestSuite {
30 30
31 @ClassRule 31 @ClassRule
32 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
33 - new CustomCassandraCQLUnit(Arrays.asList(  
34 - new ClassPathCQLDataSet("schema.cql", false, false),  
35 - new ClassPathCQLDataSet("system-data.cql", false, false),  
36 - new ClassPathCQLDataSet("system-test.cql", false, false)), 33 + new CustomCassandraCQLUnit(
  34 + Arrays.asList(
  35 + new ClassPathCQLDataSet("cassandra/schema.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
  37 + new ClassPathCQLDataSet("system-test.cql", false, false)),
37 "cassandra-test.yaml", 30000l); 38 "cassandra-test.yaml", 30000l);
38 -  
39 } 39 }
@@ -23,6 +23,7 @@ import java.util.ArrayList; @@ -23,6 +23,7 @@ import java.util.ArrayList;
23 import java.util.Collections; 23 import java.util.Collections;
24 import java.util.List; 24 import java.util.List;
25 25
  26 +import com.datastax.driver.core.utils.UUIDs;
26 import org.apache.commons.lang3.RandomStringUtils; 27 import org.apache.commons.lang3.RandomStringUtils;
27 import org.thingsboard.server.common.data.*; 28 import org.thingsboard.server.common.data.*;
28 import org.thingsboard.server.common.data.id.CustomerId; 29 import org.thingsboard.server.common.data.id.CustomerId;
@@ -35,7 +36,6 @@ import org.junit.Assert; @@ -35,7 +36,6 @@ import org.junit.Assert;
35 import org.junit.Before; 36 import org.junit.Before;
36 import org.junit.Test; 37 import org.junit.Test;
37 38
38 -import com.datastax.driver.core.utils.UUIDs;  
39 import com.fasterxml.jackson.core.type.TypeReference; 39 import com.fasterxml.jackson.core.type.TypeReference;
40 40
41 public class DashboardControllerTest extends AbstractControllerTest { 41 public class DashboardControllerTest extends AbstractControllerTest {
@@ -155,7 +155,7 @@ public class DashboardControllerTest extends AbstractControllerTest { @@ -155,7 +155,7 @@ public class DashboardControllerTest extends AbstractControllerTest {
155 dashboard.setTitle("My dashboard"); 155 dashboard.setTitle("My dashboard");
156 Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class); 156 Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
157 157
158 - doPost("/api/customer/" + UUIDs.timeBased().toString() 158 + doPost("/api/customer/" + UUIDs.timeBased().toString()
159 + "/dashboard/" + savedDashboard.getId().getId().toString()) 159 + "/dashboard/" + savedDashboard.getId().getId().toString())
160 .andExpect(status().isNotFound()); 160 .andExpect(status().isNotFound());
161 } 161 }
@@ -23,6 +23,7 @@ import java.util.ArrayList; @@ -23,6 +23,7 @@ import java.util.ArrayList;
23 import java.util.Collections; 23 import java.util.Collections;
24 import java.util.List; 24 import java.util.List;
25 25
  26 +import com.datastax.driver.core.utils.UUIDs;
26 import org.apache.commons.lang3.RandomStringUtils; 27 import org.apache.commons.lang3.RandomStringUtils;
27 import org.thingsboard.server.common.data.*; 28 import org.thingsboard.server.common.data.*;
28 import org.thingsboard.server.common.data.id.CustomerId; 29 import org.thingsboard.server.common.data.id.CustomerId;
@@ -39,7 +40,6 @@ import org.junit.Assert; @@ -39,7 +40,6 @@ import org.junit.Assert;
39 import org.junit.Before; 40 import org.junit.Before;
40 import org.junit.Test; 41 import org.junit.Test;
41 42
42 -import com.datastax.driver.core.utils.UUIDs;  
43 import com.fasterxml.jackson.core.type.TypeReference; 43 import com.fasterxml.jackson.core.type.TypeReference;
44 44
45 public class DeviceControllerTest extends AbstractControllerTest { 45 public class DeviceControllerTest extends AbstractControllerTest {
@@ -215,7 +215,7 @@ public class DeviceControllerTest extends AbstractControllerTest { @@ -215,7 +215,7 @@ public class DeviceControllerTest extends AbstractControllerTest {
215 device.setType("default"); 215 device.setType("default");
216 Device savedDevice = doPost("/api/device", device, Device.class); 216 Device savedDevice = doPost("/api/device", device, Device.class);
217 217
218 - doPost("/api/customer/" + UUIDs.timeBased().toString() 218 + doPost("/api/customer/" + UUIDs.timeBased().toString()
219 + "/device/" + savedDevice.getId().getId().toString()) 219 + "/device/" + savedDevice.getId().getId().toString())
220 .andExpect(status().isNotFound()); 220 .andExpect(status().isNotFound());
221 } 221 }
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.mqtt;  
17 -  
18 -import org.junit.runner.RunWith;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
21 -import org.springframework.boot.test.IntegrationTest;  
22 -import org.springframework.boot.test.SpringApplicationContextLoader;  
23 -import org.springframework.context.annotation.ComponentScan;  
24 -import org.springframework.context.annotation.Configuration;  
25 -import org.springframework.http.converter.HttpMessageConverter;  
26 -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;  
27 -import org.springframework.test.annotation.DirtiesContext;  
28 -import org.springframework.test.context.ActiveProfiles;  
29 -import org.springframework.test.context.ContextConfiguration;  
30 -import org.springframework.test.context.TestPropertySource;  
31 -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;  
32 -import org.springframework.test.context.web.WebAppConfiguration;  
33 -import org.springframework.web.context.WebApplicationContext;  
34 -import org.thingsboard.server.mqtt.telemetry.MqttTelemetryIntergrationTest;  
35 -  
36 -import java.util.Arrays;  
37 -  
38 -import static org.junit.Assert.assertNotNull;  
39 -  
40 -/**  
41 - * @author Valerii Sosliuk  
42 - */  
43 -@ActiveProfiles("default")  
44 -@RunWith(SpringJUnit4ClassRunner.class)  
45 -@ContextConfiguration(classes= MqttTelemetryIntergrationTest.class, loader=SpringApplicationContextLoader.class)  
46 -@TestPropertySource(locations = {"classpath:cassandra-test.properties", "classpath:thingsboard-test.properties"})  
47 -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)  
48 -@Configuration  
49 -@EnableAutoConfiguration  
50 -@ComponentScan({"org.thingsboard.server"})  
51 -@WebAppConfiguration  
52 -@IntegrationTest("server.port:8080")  
53 -public class AbstractFeatureIntegrationTest {  
54 -  
55 - @SuppressWarnings("rawtypes")  
56 - private HttpMessageConverter mappingJackson2HttpMessageConverter;  
57 -  
58 - @Autowired  
59 - private WebApplicationContext webApplicationContext;  
60 -  
61 - @Autowired  
62 - void setConverters(HttpMessageConverter<?>[] converters) {  
63 -  
64 - this.mappingJackson2HttpMessageConverter = Arrays.stream(converters)  
65 - .filter(hmc -> hmc instanceof MappingJackson2HttpMessageConverter)  
66 - .findAny()  
67 - .get();  
68 -  
69 - assertNotNull("the JSON message converter must not be null",  
70 - this.mappingJackson2HttpMessageConverter);  
71 - }  
72 -  
73 -}  
application/src/test/java/org/thingsboard/server/mqtt/MqttTestSuite.java renamed from application/src/test/java/org/thingsboard/server/mqtt/MqttSuite.java
@@ -23,19 +23,16 @@ import org.thingsboard.server.dao.CustomCassandraCQLUnit; @@ -23,19 +23,16 @@ import org.thingsboard.server.dao.CustomCassandraCQLUnit;
23 23
24 import java.util.Arrays; 24 import java.util.Arrays;
25 25
26 -/**  
27 - * @author Valerii Sosliuk  
28 - */  
29 @RunWith(ClasspathSuite.class) 26 @RunWith(ClasspathSuite.class)
30 -@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.mqtt.*.*Test"})  
31 -public class MqttSuite { 27 +@ClasspathSuite.ClassnameFilters({
  28 + "org.thingsboard.server.mqtt.*.*Test"})
  29 +public class MqttTestSuite {
32 30
33 @ClassRule 31 @ClassRule
34 public static CustomCassandraCQLUnit cassandraUnit = 32 public static CustomCassandraCQLUnit cassandraUnit =
35 new CustomCassandraCQLUnit( 33 new CustomCassandraCQLUnit(
36 - Arrays.asList(new ClassPathCQLDataSet("schema.cql", false, false),  
37 - new ClassPathCQLDataSet("system-data.cql", false, false),  
38 - new ClassPathCQLDataSet("demo-data.cql", false, false)), 34 + Arrays.asList(
  35 + new ClassPathCQLDataSet("cassandra/schema.cql", false, false),
  36 + new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
39 "cassandra-test.yaml", 30000l); 37 "cassandra-test.yaml", 30000l);
40 -  
41 } 38 }
@@ -17,47 +17,67 @@ package org.thingsboard.server.mqtt.rpc; @@ -17,47 +17,67 @@ package org.thingsboard.server.mqtt.rpc;
17 17
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.eclipse.paho.client.mqttv3.*; 19 import org.eclipse.paho.client.mqttv3.*;
20 -import org.junit.Assert;  
21 -import org.junit.Before;  
22 -import org.junit.Ignore;  
23 -import org.junit.Test; 20 +import org.junit.*;
24 import org.springframework.http.HttpStatus; 21 import org.springframework.http.HttpStatus;
25 -import org.springframework.http.ResponseEntity;  
26 import org.springframework.web.client.HttpClientErrorException; 22 import org.springframework.web.client.HttpClientErrorException;
27 -import org.thingsboard.client.tools.RestClient;  
28 import org.thingsboard.server.common.data.Device; 23 import org.thingsboard.server.common.data.Device;
  24 +import org.thingsboard.server.common.data.Tenant;
  25 +import org.thingsboard.server.common.data.User;
  26 +import org.thingsboard.server.common.data.security.Authority;
29 import org.thingsboard.server.common.data.security.DeviceCredentials; 27 import org.thingsboard.server.common.data.security.DeviceCredentials;
30 -import org.thingsboard.server.mqtt.AbstractFeatureIntegrationTest; 28 +import org.thingsboard.server.controller.AbstractControllerTest;
31 29
32 import java.util.UUID; 30 import java.util.UUID;
33 31
34 import static org.junit.Assert.assertEquals; 32 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertNotNull; 33 import static org.junit.Assert.assertNotNull;
  34 +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36 35
37 /** 36 /**
38 * @author Valerii Sosliuk 37 * @author Valerii Sosliuk
39 */ 38 */
40 @Slf4j 39 @Slf4j
41 -public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegrationTest { 40 +public class MqttServerSideRpcIntegrationTest extends AbstractControllerTest {
42 41
43 private static final String MQTT_URL = "tcp://localhost:1883"; 42 private static final String MQTT_URL = "tcp://localhost:1883";
44 - private static final String BASE_URL = "http://localhost:8080"; 43 + private static final String FAIL_MSG_IF_HTTP_CLIENT_ERROR_NOT_ENCOUNTERED = "HttpClientErrorException expected, but not encountered";
45 44
46 - private static final String USERNAME = "tenant@thingsboard.org";  
47 - private static final String PASSWORD = "tenant";  
48 -  
49 - private RestClient restClient; 45 + private Tenant savedTenant;
  46 + private User tenantAdmin;
50 47
51 @Before 48 @Before
52 public void beforeTest() throws Exception { 49 public void beforeTest() throws Exception {
53 - restClient = new RestClient(BASE_URL);  
54 - restClient.login(USERNAME, PASSWORD); 50 + loginSysAdmin();
  51 +
  52 + Tenant tenant = new Tenant();
  53 + tenant.setTitle("My tenant");
  54 + savedTenant = doPost("/api/tenant", tenant, Tenant.class);
  55 + Assert.assertNotNull(savedTenant);
  56 +
  57 + tenantAdmin = new User();
  58 + tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
  59 + tenantAdmin.setTenantId(savedTenant.getId());
  60 + tenantAdmin.setEmail("tenant2@thingsboard.org");
  61 + tenantAdmin.setFirstName("Joe");
  62 + tenantAdmin.setLastName("Downs");
  63 +
  64 + createUserAndLogin(tenantAdmin, "testPassword1");
  65 + }
  66 +
  67 + @After
  68 + public void afterTest() throws Exception {
  69 + loginSysAdmin();
  70 +
  71 + doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
  72 + .andExpect(status().isOk());
55 } 73 }
56 74
57 @Test 75 @Test
  76 + @Ignore
58 public void testServerMqttOneWayRpc() throws Exception { 77 public void testServerMqttOneWayRpc() throws Exception {
59 Device device = new Device(); 78 Device device = new Device();
60 device.setName("Test One-Way Server-Side RPC"); 79 device.setName("Test One-Way Server-Side RPC");
  80 + device.setType("default");
61 Device savedDevice = getSavedDevice(device); 81 Device savedDevice = getSavedDevice(device);
62 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice); 82 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
63 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); 83 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
@@ -69,22 +89,22 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -69,22 +89,22 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
69 89
70 MqttConnectOptions options = new MqttConnectOptions(); 90 MqttConnectOptions options = new MqttConnectOptions();
71 options.setUserName(accessToken); 91 options.setUserName(accessToken);
72 - client.connect(options);  
73 - Thread.sleep(3000); 92 + client.connect(options).waitForCompletion();
74 client.subscribe("v1/devices/me/rpc/request/+", 1); 93 client.subscribe("v1/devices/me/rpc/request/+", 1);
75 client.setCallback(new TestMqttCallback(client)); 94 client.setCallback(new TestMqttCallback(client));
76 95
77 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; 96 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
78 String deviceId = savedDevice.getId().getId().toString(); 97 String deviceId = savedDevice.getId().getId().toString();
79 - ResponseEntity result = restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class);  
80 - Assert.assertEquals(HttpStatus.OK, result.getStatusCode());  
81 - Assert.assertNull(result.getBody()); 98 + String result = doPost("api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class);
  99 + Assert.assertNull(result);
82 } 100 }
83 101
84 @Test 102 @Test
  103 + @Ignore
85 public void testServerMqttOneWayRpcDeviceOffline() throws Exception { 104 public void testServerMqttOneWayRpcDeviceOffline() throws Exception {
86 Device device = new Device(); 105 Device device = new Device();
87 device.setName("Test One-Way Server-Side RPC Device Offline"); 106 device.setName("Test One-Way Server-Side RPC Device Offline");
  107 + device.setType("default");
88 Device savedDevice = getSavedDevice(device); 108 Device savedDevice = getSavedDevice(device);
89 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice); 109 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
90 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); 110 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
@@ -94,8 +114,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -94,8 +114,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
94 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; 114 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
95 String deviceId = savedDevice.getId().getId().toString(); 115 String deviceId = savedDevice.getId().getId().toString();
96 try { 116 try {
97 - restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class);  
98 - Assert.fail("HttpClientErrorException expected, but not encountered"); 117 + doPost("api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class);
  118 + Assert.fail(FAIL_MSG_IF_HTTP_CLIENT_ERROR_NOT_ENCOUNTERED);
99 } catch (HttpClientErrorException e) { 119 } catch (HttpClientErrorException e) {
100 log.error(e.getMessage(), e); 120 log.error(e.getMessage(), e);
101 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode()); 121 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode());
@@ -104,12 +124,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -104,12 +124,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
104 } 124 }
105 125
106 @Test 126 @Test
  127 + @Ignore
107 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception { 128 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception {
108 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; 129 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
109 String nonExistentDeviceId = UUID.randomUUID().toString(); 130 String nonExistentDeviceId = UUID.randomUUID().toString();
110 try { 131 try {
111 - restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class);  
112 - Assert.fail("HttpClientErrorException expected, but not encountered"); 132 + doPost("api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class);
  133 + Assert.fail(FAIL_MSG_IF_HTTP_CLIENT_ERROR_NOT_ENCOUNTERED);
113 } catch (HttpClientErrorException e) { 134 } catch (HttpClientErrorException e) {
114 log.error(e.getMessage(), e); 135 log.error(e.getMessage(), e);
115 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); 136 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
@@ -118,10 +139,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -118,10 +139,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
118 } 139 }
119 140
120 @Test 141 @Test
  142 + @Ignore
121 public void testServerMqttTwoWayRpc() throws Exception { 143 public void testServerMqttTwoWayRpc() throws Exception {
122 -  
123 Device device = new Device(); 144 Device device = new Device();
124 device.setName("Test Two-Way Server-Side RPC"); 145 device.setName("Test Two-Way Server-Side RPC");
  146 + device.setType("default");
125 Device savedDevice = getSavedDevice(device); 147 Device savedDevice = getSavedDevice(device);
126 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice); 148 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
127 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); 149 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
@@ -133,8 +155,7 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -133,8 +155,7 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
133 155
134 MqttConnectOptions options = new MqttConnectOptions(); 156 MqttConnectOptions options = new MqttConnectOptions();
135 options.setUserName(accessToken); 157 options.setUserName(accessToken);
136 - client.connect(options);  
137 - Thread.sleep(3000); 158 + client.connect(options).waitForCompletion();
138 client.subscribe("v1/devices/me/rpc/request/+", 1); 159 client.subscribe("v1/devices/me/rpc/request/+", 1);
139 client.setCallback(new TestMqttCallback(client)); 160 client.setCallback(new TestMqttCallback(client));
140 161
@@ -145,9 +166,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -145,9 +166,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
145 } 166 }
146 167
147 @Test 168 @Test
  169 + @Ignore
148 public void testServerMqttTwoWayRpcDeviceOffline() throws Exception { 170 public void testServerMqttTwoWayRpcDeviceOffline() throws Exception {
149 Device device = new Device(); 171 Device device = new Device();
150 device.setName("Test Two-Way Server-Side RPC Device Offline"); 172 device.setName("Test Two-Way Server-Side RPC Device Offline");
  173 + device.setType("default");
151 Device savedDevice = getSavedDevice(device); 174 Device savedDevice = getSavedDevice(device);
152 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice); 175 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
153 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); 176 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
@@ -157,8 +180,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -157,8 +180,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
157 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; 180 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
158 String deviceId = savedDevice.getId().getId().toString(); 181 String deviceId = savedDevice.getId().getId().toString();
159 try { 182 try {
160 - restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class);  
161 - Assert.fail("HttpClientErrorException expected, but not encountered"); 183 + doPost("api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class);
  184 + Assert.fail(FAIL_MSG_IF_HTTP_CLIENT_ERROR_NOT_ENCOUNTERED);
162 } catch (HttpClientErrorException e) { 185 } catch (HttpClientErrorException e) {
163 log.error(e.getMessage(), e); 186 log.error(e.getMessage(), e);
164 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode()); 187 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode());
@@ -167,12 +190,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -167,12 +190,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
167 } 190 }
168 191
169 @Test 192 @Test
  193 + @Ignore
170 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception { 194 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception {
171 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; 195 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
172 String nonExistentDeviceId = UUID.randomUUID().toString(); 196 String nonExistentDeviceId = UUID.randomUUID().toString();
173 try { 197 try {
174 - restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class);  
175 - Assert.fail("HttpClientErrorException expected, but not encountered"); 198 + doPost("api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class);
  199 + Assert.fail(FAIL_MSG_IF_HTTP_CLIENT_ERROR_NOT_ENCOUNTERED);
176 } catch (HttpClientErrorException e) { 200 } catch (HttpClientErrorException e) {
177 log.error(e.getMessage(), e); 201 log.error(e.getMessage(), e);
178 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); 202 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
@@ -180,16 +204,16 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration @@ -180,16 +204,16 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
180 } 204 }
181 } 205 }
182 206
183 - private Device getSavedDevice(Device device) {  
184 - return restClient.getRestTemplate().postForEntity(BASE_URL + "/api/device", device, Device.class).getBody(); 207 + private Device getSavedDevice(Device device) throws Exception {
  208 + return doPost("/api/device", device, Device.class);
185 } 209 }
186 210
187 - private DeviceCredentials getDeviceCredentials(Device savedDevice) {  
188 - return restClient.getRestTemplate().getForEntity(BASE_URL + "/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class).getBody(); 211 + private DeviceCredentials getDeviceCredentials(Device savedDevice) throws Exception {
  212 + return doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
189 } 213 }
190 214
191 - private String getStringResult(String requestData, String callType, String deviceId) {  
192 - return restClient.getRestTemplate().postForEntity(BASE_URL + "api/plugins/rpc/" + callType + "/" + deviceId, requestData, String.class).getBody(); 215 + private String getStringResult(String requestData, String callType, String deviceId) throws Exception {
  216 + return doPost("api/plugins/rpc/" + callType + "/" + deviceId, requestData, String.class);
193 } 217 }
194 218
195 private static class TestMqttCallback implements MqttCallback { 219 private static class TestMqttCallback implements MqttCallback {
application/src/test/java/org/thingsboard/server/mqtt/telemetry/MqttTelemetryIntegrationTest.java renamed from application/src/test/java/org/thingsboard/server/mqtt/telemetry/MqttTelemetryIntergrationTest.java
@@ -20,12 +20,12 @@ import org.eclipse.paho.client.mqttv3.MqttAsyncClient; @@ -20,12 +20,12 @@ import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
20 import org.eclipse.paho.client.mqttv3.MqttConnectOptions; 20 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
21 import org.eclipse.paho.client.mqttv3.MqttMessage; 21 import org.eclipse.paho.client.mqttv3.MqttMessage;
22 import org.junit.Before; 22 import org.junit.Before;
  23 +import org.junit.Ignore;
23 import org.junit.Test; 24 import org.junit.Test;
24 import org.springframework.web.util.UriComponentsBuilder; 25 import org.springframework.web.util.UriComponentsBuilder;
25 -import org.thingsboard.client.tools.RestClient;  
26 import org.thingsboard.server.common.data.Device; 26 import org.thingsboard.server.common.data.Device;
27 import org.thingsboard.server.common.data.security.DeviceCredentials; 27 import org.thingsboard.server.common.data.security.DeviceCredentials;
28 -import org.thingsboard.server.mqtt.AbstractFeatureIntegrationTest; 28 +import org.thingsboard.server.controller.AbstractControllerTest;
29 29
30 import java.net.URI; 30 import java.net.URI;
31 import java.util.Arrays; 31 import java.util.Arrays;
@@ -39,35 +39,32 @@ import static org.junit.Assert.assertNotNull; @@ -39,35 +39,32 @@ import static org.junit.Assert.assertNotNull;
39 * @author Valerii Sosliuk 39 * @author Valerii Sosliuk
40 */ 40 */
41 @Slf4j 41 @Slf4j
42 -public class MqttTelemetryIntergrationTest extends AbstractFeatureIntegrationTest { 42 +public class MqttTelemetryIntegrationTest extends AbstractControllerTest {
43 43
44 private static final String MQTT_URL = "tcp://localhost:1883"; 44 private static final String MQTT_URL = "tcp://localhost:1883";
45 - private static final String BASE_URL = "http://localhost:8080";  
46 -  
47 - private static final String USERNAME = "tenant@thingsboard.org";  
48 - private static final String PASSWORD = "tenant";  
49 45
50 private Device savedDevice; 46 private Device savedDevice;
51 -  
52 private String accessToken; 47 private String accessToken;
53 - private RestClient restClient;  
54 48
55 @Before 49 @Before
56 public void beforeTest() throws Exception { 50 public void beforeTest() throws Exception {
57 - restClient = new RestClient(BASE_URL);  
58 - restClient.login(USERNAME, PASSWORD); 51 + loginTenantAdmin();
59 52
60 Device device = new Device(); 53 Device device = new Device();
61 device.setName("Test device"); 54 device.setName("Test device");
62 - savedDevice = restClient.getRestTemplate().postForEntity(BASE_URL + "/api/device", device, Device.class).getBody(); 55 + device.setType("default");
  56 + savedDevice = doPost("/api/device", device, Device.class);
  57 +
63 DeviceCredentials deviceCredentials = 58 DeviceCredentials deviceCredentials =
64 - restClient.getRestTemplate().getForEntity(BASE_URL + "/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class).getBody(); 59 + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
  60 +
65 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); 61 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
66 accessToken = deviceCredentials.getCredentialsId(); 62 accessToken = deviceCredentials.getCredentialsId();
67 assertNotNull(accessToken); 63 assertNotNull(accessToken);
68 } 64 }
69 65
70 @Test 66 @Test
  67 + @Ignore
71 public void testPushMqttRpcData() throws Exception { 68 public void testPushMqttRpcData() throws Exception {
72 String clientId = MqttAsyncClient.generateClientId(); 69 String clientId = MqttAsyncClient.generateClientId();
73 MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId); 70 MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId);
@@ -83,13 +80,13 @@ public class MqttTelemetryIntergrationTest extends AbstractFeatureIntegrationTes @@ -83,13 +80,13 @@ public class MqttTelemetryIntergrationTest extends AbstractFeatureIntegrationTes
83 String deviceId = savedDevice.getId().getId().toString(); 80 String deviceId = savedDevice.getId().getId().toString();
84 81
85 Thread.sleep(1000); 82 Thread.sleep(1000);
86 - List keys = restClient.getRestTemplate().getForEntity(BASE_URL + "/api/plugins/telemetry/" + deviceId + "/keys/timeseries", List.class).getBody(); 83 + Object keys = doGet("/api/plugins/telemetry/" + deviceId + "/keys/timeseries", Object.class);
87 assertEquals(Arrays.asList("key1", "key2", "key3", "key4"), keys); 84 assertEquals(Arrays.asList("key1", "key2", "key3", "key4"), keys);
88 85
89 - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(BASE_URL + "/api/plugins/telemetry/" + deviceId + "/values/timeseries")  
90 - .queryParam("keys", String.join(",", keys)); 86 + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("/api/plugins/telemetry/" + deviceId + "/values/timeseries")
  87 + .queryParam("keys", String.join(",", (CharSequence[]) keys));
91 URI uri = builder.build().encode().toUri(); 88 URI uri = builder.build().encode().toUri();
92 - Map<String, List<Map<String, String>>> values = restClient.getRestTemplate().getForEntity(uri, Map.class).getBody(); 89 + Map<String, List<Map<String, String>>> values = doGet(uri.getPath(), Map.class);
93 90
94 assertEquals("value1", values.get("key1").get(0).get("value")); 91 assertEquals("value1", values.get("key1").get(0).get("value"));
95 assertEquals("true", values.get("key2").get(0).get("value")); 92 assertEquals("true", values.get("key2").get(0).get("value"));
application/src/test/java/org/thingsboard/server/system/BaseHttpDeviceApiTest.java renamed from application/src/test/java/org/thingsboard/server/system/HttpDeviceApiTest.java
@@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
35 /** 35 /**
36 * @author Andrew Shvayka 36 * @author Andrew Shvayka
37 */ 37 */
38 -public class HttpDeviceApiTest extends AbstractControllerTest { 38 +public abstract class BaseHttpDeviceApiTest extends AbstractControllerTest {
39 39
40 private static final AtomicInteger idSeq = new AtomicInteger(new Random(System.currentTimeMillis()).nextInt()); 40 private static final AtomicInteger idSeq = new AtomicInteger(new Random(System.currentTimeMillis()).nextInt());
41 41
application/src/test/java/org/thingsboard/server/system/SystemNoSqlTestSuite.java renamed from application/src/test/java/org/thingsboard/server/system/SystemTestSuite.java
@@ -27,13 +27,14 @@ import java.util.Arrays; @@ -27,13 +27,14 @@ import java.util.Arrays;
27 * @author Andrew Shvayka 27 * @author Andrew Shvayka
28 */ 28 */
29 @RunWith(ClasspathSuite.class) 29 @RunWith(ClasspathSuite.class)
30 -@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.system.*Test"})  
31 -public class SystemTestSuite { 30 +@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.system.*NoSqlTest"})
  31 +public class SystemNoSqlTestSuite {
32 32
33 @ClassRule 33 @ClassRule
34 public static CustomCassandraCQLUnit cassandraUnit = 34 public static CustomCassandraCQLUnit cassandraUnit =
35 - new CustomCassandraCQLUnit(Arrays.asList(  
36 - new ClassPathCQLDataSet("schema.cql", false, false),  
37 - new ClassPathCQLDataSet("system-data.cql", false, false)), 35 + new CustomCassandraCQLUnit(
  36 + Arrays.asList(
  37 + new ClassPathCQLDataSet("cassandra/schema.cql", false, false),
  38 + new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
38 "cassandra-test.yaml", 30000l); 39 "cassandra-test.yaml", 30000l);
39 } 40 }
  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.system;
  17 +
  18 +import org.junit.ClassRule;
  19 +import org.junit.extensions.cpsuite.ClasspathSuite;
  20 +import org.junit.runner.RunWith;
  21 +import org.thingsboard.server.dao.CustomPostgresUnit;
  22 +
  23 +import java.util.Arrays;
  24 +
  25 +/**
  26 + * Created by Valerii Sosliuk on 6/27/2017.
  27 + */
  28 +@RunWith(ClasspathSuite.class)
  29 +@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.system.sql.*SqlTest"})
  30 +public class SystemSqlTestSuite {
  31 +
  32 + @ClassRule
  33 + public static CustomPostgresUnit postgresUnit = new CustomPostgresUnit(
  34 + Arrays.asList("postgres/schema.sql", "postgres/system-data.sql"),
  35 + "postgres-embedded-test.properties");
  36 +
  37 +
  38 +}
  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.system.nosql;
  17 +
  18 +import org.thingsboard.server.dao.service.DaoNoSqlTest;
  19 +import org.thingsboard.server.dao.util.NoSqlDao;
  20 +import org.thingsboard.server.system.BaseHttpDeviceApiTest;
  21 +
  22 +/**
  23 + * Created by Valerii Sosliuk on 6/27/2017.
  24 + */
  25 +@DaoNoSqlTest
  26 +public class DeviceApiNoSqlTest extends BaseHttpDeviceApiTest {
  27 +}
  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.system.sql;
  17 +
  18 +import org.thingsboard.server.dao.service.DaoSqlTest;
  19 +import org.thingsboard.server.system.BaseHttpDeviceApiTest;
  20 +
  21 +/**
  22 + * Created by Valerii Sosliuk on 6/27/2017.
  23 + */
  24 +@DaoSqlTest
  25 +public class DeviceApiSqlTest extends BaseHttpDeviceApiTest{
  26 +}
@@ -17,6 +17,8 @@ package org.thingsboard.server.common.data.asset; @@ -17,6 +17,8 @@ package org.thingsboard.server.common.data.asset;
17 17
18 import org.thingsboard.server.common.data.id.TenantId; 18 import org.thingsboard.server.common.data.id.TenantId;
19 19
  20 +import java.util.UUID;
  21 +
20 public class TenantAssetType { 22 public class TenantAssetType {
21 23
22 private static final long serialVersionUID = 8057290243855622101L; 24 private static final long serialVersionUID = 8057290243855622101L;
@@ -33,6 +35,11 @@ public class TenantAssetType { @@ -33,6 +35,11 @@ public class TenantAssetType {
33 this.tenantId = tenantId; 35 this.tenantId = tenantId;
34 } 36 }
35 37
  38 + public TenantAssetType(String type, UUID tenantId) {
  39 + this.type = type;
  40 + this.tenantId = new TenantId(tenantId);
  41 + }
  42 +
36 public String getType() { 43 public String getType() {
37 return type; 44 return type;
38 } 45 }
@@ -15,8 +15,6 @@ @@ -15,8 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.common.data.kv; 16 package org.thingsboard.server.common.data.kv;
17 17
18 -import java.util.Optional;  
19 -  
20 public interface TsKvQuery { 18 public interface TsKvQuery {
21 19
22 String getKey(); 20 String getKey();
@@ -18,8 +18,6 @@ package org.thingsboard.server.common.data.relation; @@ -18,8 +18,6 @@ package org.thingsboard.server.common.data.relation;
18 import com.fasterxml.jackson.databind.JsonNode; 18 import com.fasterxml.jackson.databind.JsonNode;
19 import org.thingsboard.server.common.data.id.EntityId; 19 import org.thingsboard.server.common.data.id.EntityId;
20 20
21 -import java.util.Objects;  
22 -  
23 public class EntityRelation { 21 public class EntityRelation {
24 22
25 private static final long serialVersionUID = 2807343040519543363L; 23 private static final long serialVersionUID = 2807343040519543363L;
@@ -15,15 +15,12 @@ @@ -15,15 +15,12 @@
15 */ 15 */
16 package org.thingsboard.server.common.data.rule; 16 package org.thingsboard.server.common.data.rule;
17 17
  18 +import com.fasterxml.jackson.databind.JsonNode;
18 import lombok.Data; 19 import lombok.Data;
19 -import lombok.ToString;  
20 import org.thingsboard.server.common.data.HasName; 20 import org.thingsboard.server.common.data.HasName;
21 import org.thingsboard.server.common.data.SearchTextBased; 21 import org.thingsboard.server.common.data.SearchTextBased;
22 -import org.thingsboard.server.common.data.id.CustomerId;  
23 import org.thingsboard.server.common.data.id.RuleId; 22 import org.thingsboard.server.common.data.id.RuleId;
24 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
25 -  
26 -import com.fasterxml.jackson.databind.JsonNode;  
27 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; 24 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
28 25
29 @Data 26 @Data
@@ -57,8 +57,8 @@ @@ -57,8 +57,8 @@
57 <artifactId>logback-classic</artifactId> 57 <artifactId>logback-classic</artifactId>
58 </dependency> 58 </dependency>
59 <dependency> 59 <dependency>
60 - <groupId>org.springframework</groupId>  
61 - <artifactId>spring-test</artifactId> 60 + <groupId>org.postgresql</groupId>
  61 + <artifactId>postgresql</artifactId>
62 </dependency> 62 </dependency>
63 <dependency> 63 <dependency>
64 <groupId>junit</groupId> 64 <groupId>junit</groupId>
@@ -66,6 +66,16 @@ @@ -66,6 +66,16 @@
66 <scope>test</scope> 66 <scope>test</scope>
67 </dependency> 67 </dependency>
68 <dependency> 68 <dependency>
  69 + <groupId>org.dbunit</groupId>
  70 + <artifactId>dbunit</artifactId>
  71 + <scope>test</scope>
  72 + </dependency>
  73 + <dependency>
  74 + <groupId>com.github.springtestdbunit</groupId>
  75 + <artifactId>spring-test-dbunit</artifactId>
  76 + <scope>test</scope>
  77 + </dependency>
  78 + <dependency>
69 <groupId>org.mockito</groupId> 79 <groupId>org.mockito</groupId>
70 <artifactId>mockito-all</artifactId> 80 <artifactId>mockito-all</artifactId>
71 <scope>test</scope> 81 <scope>test</scope>
@@ -150,6 +160,20 @@ @@ -150,6 +160,20 @@
150 <groupId>org.bouncycastle</groupId> 160 <groupId>org.bouncycastle</groupId>
151 <artifactId>bcprov-jdk15on</artifactId> 161 <artifactId>bcprov-jdk15on</artifactId>
152 </dependency> 162 </dependency>
  163 + <dependency>
  164 + <groupId>org.springframework.boot</groupId>
  165 + <artifactId>spring-boot-starter-data-jpa</artifactId>
  166 + </dependency>
  167 + <dependency>
  168 + <groupId>org.springframework</groupId>
  169 + <artifactId>spring-test</artifactId>
  170 + <scope>test</scope>
  171 + </dependency>
  172 + <dependency>
  173 + <groupId>ru.yandex.qatools.embed</groupId>
  174 + <artifactId>postgresql-embedded</artifactId>
  175 + <scope>test</scope>
  176 + </dependency>
153 </dependencies> 177 </dependencies>
154 <build> 178 <build>
155 <plugins> 179 <plugins>
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao; 16 package org.thingsboard.server.dao;
17 17
18 -import com.datastax.driver.core.ResultSet;  
19 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
20 19
21 import java.util.List; 20 import java.util.List;
@@ -31,6 +30,6 @@ public interface Dao<T> { @@ -31,6 +30,6 @@ public interface Dao<T> {
31 30
32 T save(T t); 31 T save(T t);
33 32
34 - ResultSet removeById(UUID id); 33 + boolean removeById(UUID id);
35 34
36 } 35 }
@@ -15,15 +15,11 @@ @@ -15,15 +15,11 @@
15 */ 15 */
16 package org.thingsboard.server.dao; 16 package org.thingsboard.server.dao;
17 17
18 -import java.util.ArrayList;  
19 -import java.util.Collection;  
20 -import java.util.Collections;  
21 -import java.util.List;  
22 -import java.util.UUID;  
23 -  
24 import org.thingsboard.server.common.data.id.UUIDBased; 18 import org.thingsboard.server.common.data.id.UUIDBased;
25 import org.thingsboard.server.dao.model.ToData; 19 import org.thingsboard.server.dao.model.ToData;
26 20
  21 +import java.util.*;
  22 +
27 public abstract class DaoUtil { 23 public abstract class DaoUtil {
28 24
29 private DaoUtil() { 25 private DaoUtil() {
@@ -34,7 +30,9 @@ public abstract class DaoUtil { @@ -34,7 +30,9 @@ public abstract class DaoUtil {
34 if (toDataList != null && !toDataList.isEmpty()) { 30 if (toDataList != null && !toDataList.isEmpty()) {
35 list = new ArrayList<>(); 31 list = new ArrayList<>();
36 for (ToData<T> object : toDataList) { 32 for (ToData<T> object : toDataList) {
37 - list.add(object.toData()); 33 + if (object != null) {
  34 + list.add(object.toData());
  35 + }
38 } 36 }
39 } 37 }
40 return list; 38 return list;
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao; 16 package org.thingsboard.server.dao;
17 17
18 -import com.google.common.base.CharMatcher;  
19 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
20 import org.bouncycastle.crypto.digests.SHA3Digest; 19 import org.bouncycastle.crypto.digests.SHA3Digest;
21 import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; 20 import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
  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;
  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.SqlDao;
  25 +
  26 +/**
  27 + * @author Valerii Sosliuk
  28 + */
  29 +@Configuration
  30 +@EnableAutoConfiguration
  31 +@ComponentScan("org.thingsboard.server.dao.sql")
  32 +@EnableJpaRepositories("org.thingsboard.server.dao.sql")
  33 +@EntityScan("org.thingsboard.server.dao.model.sql")
  34 +@EnableTransactionManagement
  35 +@SqlDao
  36 +public class JpaDaoConfig {
  37 +
  38 +}
  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;
  17 +
  18 +import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  19 +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  20 +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
  21 +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
  22 +import org.springframework.context.annotation.Configuration;
  23 +import org.thingsboard.server.dao.util.NoSqlDao;
  24 +
  25 +@Configuration
  26 +@EnableAutoConfiguration(
  27 + exclude = {
  28 + DataSourceAutoConfiguration.class,
  29 + DataSourceTransactionManagerAutoConfiguration.class,
  30 + HibernateJpaAutoConfiguration.class})
  31 +@NoSqlDao
  32 +public class NoSqlDaoConfig {
  33 +}
@@ -22,7 +22,6 @@ import org.thingsboard.server.common.data.alarm.AlarmQuery; @@ -22,7 +22,6 @@ import org.thingsboard.server.common.data.alarm.AlarmQuery;
22 import org.thingsboard.server.common.data.id.EntityId; 22 import org.thingsboard.server.common.data.id.EntityId;
23 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
24 import org.thingsboard.server.dao.Dao; 24 import org.thingsboard.server.dao.Dao;
25 -import org.thingsboard.server.dao.model.AlarmEntity;  
26 25
27 import java.util.List; 26 import java.util.List;
28 import java.util.UUID; 27 import java.util.UUID;
@@ -30,13 +29,13 @@ import java.util.UUID; @@ -30,13 +29,13 @@ import java.util.UUID;
30 /** 29 /**
31 * Created by ashvayka on 11.05.17. 30 * Created by ashvayka on 11.05.17.
32 */ 31 */
33 -public interface AlarmDao extends Dao<AlarmEntity> { 32 +public interface AlarmDao extends Dao<Alarm> {
34 33
35 ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type); 34 ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
36 35
37 ListenableFuture<Alarm> findAlarmByIdAsync(UUID key); 36 ListenableFuture<Alarm> findAlarmByIdAsync(UUID key);
38 37
39 - AlarmEntity save(Alarm alarm); 38 + Alarm save(Alarm alarm);
40 39
41 ListenableFuture<List<AlarmInfo>> findAlarms(AlarmQuery query); 40 ListenableFuture<List<AlarmInfo>> findAlarms(AlarmQuery query);
42 } 41 }
@@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j; @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
24 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
26 import org.springframework.util.StringUtils; 26 import org.springframework.util.StringUtils;
  27 +import org.thingsboard.server.common.data.Tenant;
27 import org.thingsboard.server.common.data.alarm.*; 28 import org.thingsboard.server.common.data.alarm.*;
28 import org.thingsboard.server.common.data.id.EntityId; 29 import org.thingsboard.server.common.data.id.EntityId;
29 import org.thingsboard.server.common.data.page.TimePageData; 30 import org.thingsboard.server.common.data.page.TimePageData;
@@ -31,10 +32,8 @@ import org.thingsboard.server.common.data.page.TimePageLink; @@ -31,10 +32,8 @@ import org.thingsboard.server.common.data.page.TimePageLink;
31 import org.thingsboard.server.common.data.relation.EntityRelation; 32 import org.thingsboard.server.common.data.relation.EntityRelation;
32 import org.thingsboard.server.common.data.relation.RelationTypeGroup; 33 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
33 import org.thingsboard.server.dao.entity.AbstractEntityService; 34 import org.thingsboard.server.dao.entity.AbstractEntityService;
34 -import org.thingsboard.server.dao.entity.BaseEntityService;  
35 import org.thingsboard.server.dao.entity.EntityService; 35 import org.thingsboard.server.dao.entity.EntityService;
36 import org.thingsboard.server.dao.exception.DataValidationException; 36 import org.thingsboard.server.dao.exception.DataValidationException;
37 -import org.thingsboard.server.dao.model.*;  
38 import org.thingsboard.server.dao.relation.EntityRelationsQuery; 37 import org.thingsboard.server.dao.relation.EntityRelationsQuery;
39 import org.thingsboard.server.dao.relation.EntitySearchDirection; 38 import org.thingsboard.server.dao.relation.EntitySearchDirection;
40 import org.thingsboard.server.dao.relation.RelationService; 39 import org.thingsboard.server.dao.relation.RelationService;
@@ -53,8 +52,7 @@ import java.util.concurrent.ExecutorService; @@ -53,8 +52,7 @@ import java.util.concurrent.ExecutorService;
53 import java.util.concurrent.Executors; 52 import java.util.concurrent.Executors;
54 import java.util.stream.Collectors; 53 import java.util.stream.Collectors;
55 54
56 -import static org.thingsboard.server.dao.DaoUtil.*;  
57 -import static org.thingsboard.server.dao.service.Validator.*; 55 +import static org.thingsboard.server.dao.service.Validator.validateId;
58 56
59 @Service 57 @Service
60 @Slf4j 58 @Slf4j
@@ -115,7 +113,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -115,7 +113,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
115 113
116 private Alarm createAlarm(Alarm alarm) throws InterruptedException, ExecutionException { 114 private Alarm createAlarm(Alarm alarm) throws InterruptedException, ExecutionException {
117 log.debug("New Alarm : {}", alarm); 115 log.debug("New Alarm : {}", alarm);
118 - Alarm saved = getData(alarmDao.save(new AlarmEntity(alarm))); 116 + Alarm saved = alarmDao.save(alarm);
119 EntityRelationsQuery query = new EntityRelationsQuery(); 117 EntityRelationsQuery query = new EntityRelationsQuery();
120 query.setParameters(new RelationsSearchParameters(saved.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE)); 118 query.setParameters(new RelationsSearchParameters(saved.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE));
121 List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList()); 119 List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList());
@@ -144,11 +142,11 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -144,11 +142,11 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
144 private Alarm updateAlarm(Alarm oldAlarm, Alarm newAlarm) { 142 private Alarm updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
145 AlarmStatus oldStatus = oldAlarm.getStatus(); 143 AlarmStatus oldStatus = oldAlarm.getStatus();
146 AlarmStatus newStatus = newAlarm.getStatus(); 144 AlarmStatus newStatus = newAlarm.getStatus();
147 - AlarmEntity result = alarmDao.save(new AlarmEntity(merge(oldAlarm, newAlarm))); 145 + Alarm result = alarmDao.save(merge(oldAlarm, newAlarm));
148 if (oldStatus != newStatus) { 146 if (oldStatus != newStatus) {
149 updateRelations(oldAlarm, oldStatus, newStatus); 147 updateRelations(oldAlarm, oldStatus, newStatus);
150 } 148 }
151 - return result.toData(); 149 + return result;
152 } 150 }
153 151
154 @Override 152 @Override
@@ -164,7 +162,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -164,7 +162,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
164 AlarmStatus newStatus = oldStatus.isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK; 162 AlarmStatus newStatus = oldStatus.isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK;
165 alarm.setStatus(newStatus); 163 alarm.setStatus(newStatus);
166 alarm.setAckTs(ackTime); 164 alarm.setAckTs(ackTime);
167 - alarmDao.save(new AlarmEntity(alarm)); 165 + alarmDao.save(alarm);
168 updateRelations(alarm, oldStatus, newStatus); 166 updateRelations(alarm, oldStatus, newStatus);
169 return true; 167 return true;
170 } 168 }
@@ -185,7 +183,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -185,7 +183,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
185 AlarmStatus newStatus = oldStatus.isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK; 183 AlarmStatus newStatus = oldStatus.isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK;
186 alarm.setStatus(newStatus); 184 alarm.setStatus(newStatus);
187 alarm.setClearTs(clearTime); 185 alarm.setClearTs(clearTime);
188 - alarmDao.save(new AlarmEntity(alarm)); 186 + alarmDao.save(alarm);
189 updateRelations(alarm, oldStatus, newStatus); 187 updateRelations(alarm, oldStatus, newStatus);
190 return true; 188 return true;
191 } 189 }
@@ -387,7 +385,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -387,7 +385,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
387 if (alarm.getTenantId() == null) { 385 if (alarm.getTenantId() == null) {
388 throw new DataValidationException("Alarm should be assigned to tenant!"); 386 throw new DataValidationException("Alarm should be assigned to tenant!");
389 } else { 387 } else {
390 - TenantEntity tenant = tenantDao.findById(alarm.getTenantId().getId()); 388 + Tenant tenant = tenantDao.findById(alarm.getTenantId().getId());
391 if (tenant == null) { 389 if (tenant == null) {
392 throw new DataValidationException("Alarm is referencing to non-existent tenant!"); 390 throw new DataValidationException("Alarm is referencing to non-existent tenant!");
393 } 391 }
dao/src/main/java/org/thingsboard/server/dao/alarm/CassandraAlarmDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/alarm/AlarmDaoImpl.java
@@ -33,10 +33,10 @@ import org.thingsboard.server.common.data.id.EntityId; @@ -33,10 +33,10 @@ import org.thingsboard.server.common.data.id.EntityId;
33 import org.thingsboard.server.common.data.id.TenantId; 33 import org.thingsboard.server.common.data.id.TenantId;
34 import org.thingsboard.server.common.data.relation.EntityRelation; 34 import org.thingsboard.server.common.data.relation.EntityRelation;
35 import org.thingsboard.server.common.data.relation.RelationTypeGroup; 35 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
36 -import org.thingsboard.server.dao.AbstractModelDao;  
37 -import org.thingsboard.server.dao.AbstractSearchTimeDao;  
38 -import org.thingsboard.server.dao.model.AlarmEntity; 36 +import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao;
  37 +import org.thingsboard.server.dao.util.NoSqlDao;
39 import org.thingsboard.server.dao.model.ModelConstants; 38 import org.thingsboard.server.dao.model.ModelConstants;
  39 +import org.thingsboard.server.dao.model.nosql.AlarmEntity;
40 import org.thingsboard.server.dao.relation.RelationDao; 40 import org.thingsboard.server.dao.relation.RelationDao;
41 41
42 import java.util.ArrayList; 42 import java.util.ArrayList;
@@ -49,7 +49,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; @@ -49,7 +49,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
49 49
50 @Component 50 @Component
51 @Slf4j 51 @Slf4j
52 -public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements AlarmDao { 52 +@NoSqlDao
  53 +public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Alarm> implements AlarmDao {
53 54
54 @Autowired 55 @Autowired
55 private RelationDao relationDao; 56 private RelationDao relationDao;
@@ -69,9 +70,9 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm @@ -69,9 +70,9 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
69 } 70 }
70 71
71 @Override 72 @Override
72 - public AlarmEntity save(Alarm alarm) { 73 + public Alarm save(Alarm alarm) {
73 log.debug("Save asset [{}] ", alarm); 74 log.debug("Save asset [{}] ", alarm);
74 - return save(new AlarmEntity(alarm)); 75 + return super.save(alarm);
75 } 76 }
76 77
77 @Override 78 @Override
@@ -84,16 +85,7 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm @@ -84,16 +85,7 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
84 query.and(eq(ALARM_TYPE_PROPERTY, type)); 85 query.and(eq(ALARM_TYPE_PROPERTY, type));
85 query.limit(1); 86 query.limit(1);
86 query.orderBy(QueryBuilder.asc(ModelConstants.ALARM_TYPE_PROPERTY), QueryBuilder.desc(ModelConstants.ID_PROPERTY)); 87 query.orderBy(QueryBuilder.asc(ModelConstants.ALARM_TYPE_PROPERTY), QueryBuilder.desc(ModelConstants.ID_PROPERTY));
87 - return Futures.transform(findOneByStatementAsync(query), toDataFunction());  
88 - }  
89 -  
90 - @Override  
91 - public ListenableFuture<Alarm> findAlarmByIdAsync(UUID key) {  
92 - log.debug("Get alarm by id {}", key);  
93 - Select.Where query = select().from(ALARM_BY_ID_VIEW_NAME).where(eq(ModelConstants.ID_PROPERTY, key));  
94 - query.limit(1);  
95 - log.trace("Execute query {}", query);  
96 - return Futures.transform(findOneByStatementAsync(query), toDataFunction()); 88 + return findOneByStatementAsync(query);
97 } 89 }
98 90
99 @Override 91 @Override
@@ -114,10 +106,19 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm @@ -114,10 +106,19 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
114 List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size()); 106 List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
115 for (EntityRelation relation : input) { 107 for (EntityRelation relation : input) {
116 alarmFutures.add(Futures.transform( 108 alarmFutures.add(Futures.transform(
117 - findAlarmByIdAsync(relation.getTo().getId()), (Function<Alarm, AlarmInfo>)  
118 - alarm1 -> new AlarmInfo(alarm1))); 109 + findAlarmByIdAsync(relation.getTo().getId()),
  110 + (Function<Alarm, AlarmInfo>) AlarmInfo::new));
119 } 111 }
120 return Futures.successfulAsList(alarmFutures); 112 return Futures.successfulAsList(alarmFutures);
121 }); 113 });
122 } 114 }
  115 +
  116 + @Override
  117 + public ListenableFuture<Alarm> findAlarmByIdAsync(UUID key) {
  118 + log.debug("Get alarm by id {}", key);
  119 + Select.Where query = select().from(ALARM_BY_ID_VIEW_NAME).where(eq(ModelConstants.ID_PROPERTY, key));
  120 + query.limit(1);
  121 + log.trace("Execute query {}", query);
  122 + return findOneByStatementAsync(query);
  123 + }
123 } 124 }
@@ -17,9 +17,9 @@ package org.thingsboard.server.dao.asset; @@ -17,9 +17,9 @@ package org.thingsboard.server.dao.asset;
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.asset.Asset; 19 import org.thingsboard.server.common.data.asset.Asset;
  20 +import org.thingsboard.server.common.data.asset.TenantAssetType;
20 import org.thingsboard.server.common.data.page.TextPageLink; 21 import org.thingsboard.server.common.data.page.TextPageLink;
21 import org.thingsboard.server.dao.Dao; 22 import org.thingsboard.server.dao.Dao;
22 -import org.thingsboard.server.dao.model.AssetEntity;  
23 import org.thingsboard.server.dao.model.TenantAssetTypeEntity; 23 import org.thingsboard.server.dao.model.TenantAssetTypeEntity;
24 24
25 import java.util.List; 25 import java.util.List;
@@ -30,7 +30,7 @@ import java.util.UUID; @@ -30,7 +30,7 @@ import java.util.UUID;
30 * The Interface AssetDao. 30 * The Interface AssetDao.
31 * 31 *
32 */ 32 */
33 -public interface AssetDao extends Dao<AssetEntity> { 33 +public interface AssetDao extends Dao<Asset> {
34 34
35 /** 35 /**
36 * Save or update asset object 36 * Save or update asset object
@@ -38,7 +38,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -38,7 +38,7 @@ public interface AssetDao extends Dao<AssetEntity> {
38 * @param asset the asset object 38 * @param asset the asset object
39 * @return saved asset object 39 * @return saved asset object
40 */ 40 */
41 - AssetEntity save(Asset asset); 41 + Asset save(Asset asset);
42 42
43 /** 43 /**
44 * Find assets by tenantId and page link. 44 * Find assets by tenantId and page link.
@@ -47,7 +47,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -47,7 +47,7 @@ public interface AssetDao extends Dao<AssetEntity> {
47 * @param pageLink the page link 47 * @param pageLink the page link
48 * @return the list of asset objects 48 * @return the list of asset objects
49 */ 49 */
50 - List<AssetEntity> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink); 50 + List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink);
51 51
52 /** 52 /**
53 * Find assets by tenantId, type and page link. 53 * Find assets by tenantId, type and page link.
@@ -57,7 +57,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -57,7 +57,7 @@ public interface AssetDao extends Dao<AssetEntity> {
57 * @param pageLink the page link 57 * @param pageLink the page link
58 * @return the list of asset objects 58 * @return the list of asset objects
59 */ 59 */
60 - List<AssetEntity> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink); 60 + List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink);
61 61
62 /** 62 /**
63 * Find assets by tenantId and assets Ids. 63 * Find assets by tenantId and assets Ids.
@@ -66,7 +66,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -66,7 +66,7 @@ public interface AssetDao extends Dao<AssetEntity> {
66 * @param assetIds the asset Ids 66 * @param assetIds the asset Ids
67 * @return the list of asset objects 67 * @return the list of asset objects
68 */ 68 */
69 - ListenableFuture<List<AssetEntity>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds); 69 + ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds);
70 70
71 /** 71 /**
72 * Find assets by tenantId, customerId and page link. 72 * Find assets by tenantId, customerId and page link.
@@ -76,7 +76,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -76,7 +76,7 @@ public interface AssetDao extends Dao<AssetEntity> {
76 * @param pageLink the page link 76 * @param pageLink the page link
77 * @return the list of asset objects 77 * @return the list of asset objects
78 */ 78 */
79 - List<AssetEntity> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); 79 + List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
80 80
81 /** 81 /**
82 * Find assets by tenantId, customerId, type and page link. 82 * Find assets by tenantId, customerId, type and page link.
@@ -87,7 +87,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -87,7 +87,7 @@ public interface AssetDao extends Dao<AssetEntity> {
87 * @param pageLink the page link 87 * @param pageLink the page link
88 * @return the list of asset objects 88 * @return the list of asset objects
89 */ 89 */
90 - List<AssetEntity> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink); 90 + List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink);
91 91
92 /** 92 /**
93 * Find assets by tenantId, customerId and assets Ids. 93 * Find assets by tenantId, customerId and assets Ids.
@@ -97,7 +97,7 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -97,7 +97,7 @@ public interface AssetDao extends Dao<AssetEntity> {
97 * @param assetIds the asset Ids 97 * @param assetIds the asset Ids
98 * @return the list of asset objects 98 * @return the list of asset objects
99 */ 99 */
100 - ListenableFuture<List<AssetEntity>> findAssetsByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds); 100 + ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds);
101 101
102 /** 102 /**
103 * Find assets by tenantId and asset name. 103 * Find assets by tenantId and asset name.
@@ -106,13 +106,13 @@ public interface AssetDao extends Dao<AssetEntity> { @@ -106,13 +106,13 @@ public interface AssetDao extends Dao<AssetEntity> {
106 * @param name the asset name 106 * @param name the asset name
107 * @return the optional asset object 107 * @return the optional asset object
108 */ 108 */
109 - Optional<AssetEntity> findAssetsByTenantIdAndName(UUID tenantId, String name); 109 + Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name);
110 110
111 /** 111 /**
112 * Find tenants asset types. 112 * Find tenants asset types.
113 * 113 *
114 * @return the list of tenant asset type objects 114 * @return the list of tenant asset type objects
115 */ 115 */
116 - ListenableFuture<List<TenantAssetTypeEntity>> findTenantAssetTypesAsync(); 116 + ListenableFuture<List<TenantAssetType>> findTenantAssetTypesAsync();
117 117
118 } 118 }
@@ -23,7 +23,6 @@ import org.thingsboard.server.dao.relation.EntityRelationsQuery; @@ -23,7 +23,6 @@ import org.thingsboard.server.dao.relation.EntityRelationsQuery;
23 import org.thingsboard.server.dao.relation.EntityTypeFilter; 23 import org.thingsboard.server.dao.relation.EntityTypeFilter;
24 24
25 import javax.annotation.Nullable; 25 import javax.annotation.Nullable;
26 -import java.util.ArrayList;  
27 import java.util.Collections; 26 import java.util.Collections;
28 import java.util.List; 27 import java.util.List;
29 28
@@ -24,7 +24,9 @@ import lombok.extern.slf4j.Slf4j; @@ -24,7 +24,9 @@ import lombok.extern.slf4j.Slf4j;
24 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
26 import org.springframework.util.StringUtils; 26 import org.springframework.util.StringUtils;
  27 +import org.thingsboard.server.common.data.Customer;
27 import org.thingsboard.server.common.data.EntityType; 28 import org.thingsboard.server.common.data.EntityType;
  29 +import org.thingsboard.server.common.data.Tenant;
28 import org.thingsboard.server.common.data.asset.Asset; 30 import org.thingsboard.server.common.data.asset.Asset;
29 import org.thingsboard.server.common.data.asset.TenantAssetType; 31 import org.thingsboard.server.common.data.asset.TenantAssetType;
30 import org.thingsboard.server.common.data.id.AssetId; 32 import org.thingsboard.server.common.data.id.AssetId;
@@ -37,7 +39,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation; @@ -37,7 +39,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
37 import org.thingsboard.server.dao.customer.CustomerDao; 39 import org.thingsboard.server.dao.customer.CustomerDao;
38 import org.thingsboard.server.dao.entity.AbstractEntityService; 40 import org.thingsboard.server.dao.entity.AbstractEntityService;
39 import org.thingsboard.server.dao.exception.DataValidationException; 41 import org.thingsboard.server.dao.exception.DataValidationException;
40 -import org.thingsboard.server.dao.model.*;  
41 import org.thingsboard.server.dao.relation.EntitySearchDirection; 42 import org.thingsboard.server.dao.relation.EntitySearchDirection;
42 import org.thingsboard.server.dao.service.DataValidator; 43 import org.thingsboard.server.dao.service.DataValidator;
43 import org.thingsboard.server.dao.service.PaginatedRemover; 44 import org.thingsboard.server.dao.service.PaginatedRemover;
@@ -45,6 +46,7 @@ import org.thingsboard.server.dao.tenant.TenantDao; @@ -45,6 +46,7 @@ import org.thingsboard.server.dao.tenant.TenantDao;
45 46
46 import javax.annotation.Nullable; 47 import javax.annotation.Nullable;
47 import java.util.ArrayList; 48 import java.util.ArrayList;
  49 +import java.util.Comparator;
48 import java.util.List; 50 import java.util.List;
49 import java.util.Optional; 51 import java.util.Optional;
50 import java.util.stream.Collectors; 52 import java.util.stream.Collectors;
@@ -70,35 +72,28 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -70,35 +72,28 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
70 public Asset findAssetById(AssetId assetId) { 72 public Asset findAssetById(AssetId assetId) {
71 log.trace("Executing findAssetById [{}]", assetId); 73 log.trace("Executing findAssetById [{}]", assetId);
72 validateId(assetId, "Incorrect assetId " + assetId); 74 validateId(assetId, "Incorrect assetId " + assetId);
73 - AssetEntity assetEntity = assetDao.findById(assetId.getId());  
74 - return getData(assetEntity); 75 + return assetDao.findById(assetId.getId());
75 } 76 }
76 77
77 @Override 78 @Override
78 public ListenableFuture<Asset> findAssetByIdAsync(AssetId assetId) { 79 public ListenableFuture<Asset> findAssetByIdAsync(AssetId assetId) {
79 log.trace("Executing findAssetById [{}]", assetId); 80 log.trace("Executing findAssetById [{}]", assetId);
80 validateId(assetId, "Incorrect assetId " + assetId); 81 validateId(assetId, "Incorrect assetId " + assetId);
81 - ListenableFuture<AssetEntity> assetEntity = assetDao.findByIdAsync(assetId.getId());  
82 - return Futures.transform(assetEntity, (Function<? super AssetEntity, ? extends Asset>) input -> getData(input)); 82 + return assetDao.findByIdAsync(assetId.getId());
83 } 83 }
84 84
85 @Override 85 @Override
86 public Optional<Asset> findAssetByTenantIdAndName(TenantId tenantId, String name) { 86 public Optional<Asset> findAssetByTenantIdAndName(TenantId tenantId, String name) {
87 log.trace("Executing findAssetByTenantIdAndName [{}][{}]", tenantId, name); 87 log.trace("Executing findAssetByTenantIdAndName [{}][{}]", tenantId, name);
88 validateId(tenantId, "Incorrect tenantId " + tenantId); 88 validateId(tenantId, "Incorrect tenantId " + tenantId);
89 - Optional<AssetEntity> assetEntityOpt = assetDao.findAssetsByTenantIdAndName(tenantId.getId(), name);  
90 - if (assetEntityOpt.isPresent()) {  
91 - return Optional.of(getData(assetEntityOpt.get()));  
92 - } else {  
93 - return Optional.empty();  
94 - } 89 + return assetDao.findAssetsByTenantIdAndName(tenantId.getId(), name);
95 } 90 }
96 91
97 @Override 92 @Override
98 public Asset saveAsset(Asset asset) { 93 public Asset saveAsset(Asset asset) {
99 log.trace("Executing saveAsset [{}]", asset); 94 log.trace("Executing saveAsset [{}]", asset);
100 assetValidator.validate(asset); 95 assetValidator.validate(asset);
101 - return getData(assetDao.save(asset)); 96 + return assetDao.save(asset);
102 } 97 }
103 98
104 @Override 99 @Override
@@ -128,8 +123,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -128,8 +123,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
128 log.trace("Executing findAssetsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); 123 log.trace("Executing findAssetsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
129 validateId(tenantId, "Incorrect tenantId " + tenantId); 124 validateId(tenantId, "Incorrect tenantId " + tenantId);
130 validatePageLink(pageLink, "Incorrect page link " + pageLink); 125 validatePageLink(pageLink, "Incorrect page link " + pageLink);
131 - List<AssetEntity> assetEntities = assetDao.findAssetsByTenantId(tenantId.getId(), pageLink);  
132 - List<Asset> assets = convertDataList(assetEntities); 126 + List<Asset> assets = assetDao.findAssetsByTenantId(tenantId.getId(), pageLink);
133 return new TextPageData<>(assets, pageLink); 127 return new TextPageData<>(assets, pageLink);
134 } 128 }
135 129
@@ -139,8 +133,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -139,8 +133,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
139 validateId(tenantId, "Incorrect tenantId " + tenantId); 133 validateId(tenantId, "Incorrect tenantId " + tenantId);
140 validateString(type, "Incorrect type " + type); 134 validateString(type, "Incorrect type " + type);
141 validatePageLink(pageLink, "Incorrect page link " + pageLink); 135 validatePageLink(pageLink, "Incorrect page link " + pageLink);
142 - List<AssetEntity> assetEntities = assetDao.findAssetsByTenantIdAndType(tenantId.getId(), type, pageLink);  
143 - List<Asset> assets = convertDataList(assetEntities); 136 + List<Asset> assets = assetDao.findAssetsByTenantIdAndType(tenantId.getId(), type, pageLink);
144 return new TextPageData<>(assets, pageLink); 137 return new TextPageData<>(assets, pageLink);
145 } 138 }
146 139
@@ -149,15 +142,14 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -149,15 +142,14 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
149 log.trace("Executing findAssetsByTenantIdAndIdsAsync, tenantId [{}], assetIds [{}]", tenantId, assetIds); 142 log.trace("Executing findAssetsByTenantIdAndIdsAsync, tenantId [{}], assetIds [{}]", tenantId, assetIds);
150 validateId(tenantId, "Incorrect tenantId " + tenantId); 143 validateId(tenantId, "Incorrect tenantId " + tenantId);
151 validateIds(assetIds, "Incorrect assetIds " + assetIds); 144 validateIds(assetIds, "Incorrect assetIds " + assetIds);
152 - ListenableFuture<List<AssetEntity>> assetEntities = assetDao.findAssetsByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(assetIds));  
153 - return Futures.transform(assetEntities, (Function<List<AssetEntity>, List<Asset>>) input -> convertDataList(input)); 145 + return assetDao.findAssetsByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(assetIds));
154 } 146 }
155 147
156 @Override 148 @Override
157 public void deleteAssetsByTenantId(TenantId tenantId) { 149 public void deleteAssetsByTenantId(TenantId tenantId) {
158 log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId); 150 log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId);
159 validateId(tenantId, "Incorrect tenantId " + tenantId); 151 validateId(tenantId, "Incorrect tenantId " + tenantId);
160 - tenantAssetsRemover.removeEntitites(tenantId); 152 + tenantAssetsRemover.removeEntities(tenantId);
161 } 153 }
162 154
163 @Override 155 @Override
@@ -166,9 +158,8 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -166,9 +158,8 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
166 validateId(tenantId, "Incorrect tenantId " + tenantId); 158 validateId(tenantId, "Incorrect tenantId " + tenantId);
167 validateId(customerId, "Incorrect customerId " + customerId); 159 validateId(customerId, "Incorrect customerId " + customerId);
168 validatePageLink(pageLink, "Incorrect page link " + pageLink); 160 validatePageLink(pageLink, "Incorrect page link " + pageLink);
169 - List<AssetEntity> assetEntities = assetDao.findAssetsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);  
170 - List<Asset> assets = convertDataList(assetEntities);  
171 - return new TextPageData<>(assets, pageLink); 161 + List<Asset> assets = assetDao.findAssetsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
  162 + return new TextPageData<Asset>(assets, pageLink);
172 } 163 }
173 164
174 @Override 165 @Override
@@ -178,20 +169,17 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -178,20 +169,17 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
178 validateId(customerId, "Incorrect customerId " + customerId); 169 validateId(customerId, "Incorrect customerId " + customerId);
179 validateString(type, "Incorrect type " + type); 170 validateString(type, "Incorrect type " + type);
180 validatePageLink(pageLink, "Incorrect page link " + pageLink); 171 validatePageLink(pageLink, "Incorrect page link " + pageLink);
181 - List<AssetEntity> assetEntities = assetDao.findAssetsByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);  
182 - List<Asset> assets = convertDataList(assetEntities); 172 + List<Asset> assets = assetDao.findAssetsByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
183 return new TextPageData<>(assets, pageLink); 173 return new TextPageData<>(assets, pageLink);
184 } 174 }
185 175
186 @Override 176 @Override
187 public ListenableFuture<List<Asset>> findAssetsByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<AssetId> assetIds) { 177 public ListenableFuture<List<Asset>> findAssetsByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<AssetId> assetIds) {
188 - log.trace("Executing findAssetsByTenantIdCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], assetIds [{}]", tenantId, customerId, assetIds); 178 + log.trace("Executing findAssetsByTenantIdAndCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], assetIds [{}]", tenantId, customerId, assetIds);
189 validateId(tenantId, "Incorrect tenantId " + tenantId); 179 validateId(tenantId, "Incorrect tenantId " + tenantId);
190 validateId(customerId, "Incorrect customerId " + customerId); 180 validateId(customerId, "Incorrect customerId " + customerId);
191 validateIds(assetIds, "Incorrect assetIds " + assetIds); 181 validateIds(assetIds, "Incorrect assetIds " + assetIds);
192 - ListenableFuture<List<AssetEntity>> assetEntities = assetDao.findAssetsByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),  
193 - customerId.getId(), toUUIDs(assetIds));  
194 - return Futures.transform(assetEntities, (Function<List<AssetEntity>, List<Asset>>) input -> convertDataList(input)); 182 + return assetDao.findAssetsByTenantIdAndCustomerIdAndIdsAsync(tenantId.getId(), customerId.getId(), toUUIDs(assetIds));
195 } 183 }
196 184
197 @Override 185 @Override
@@ -199,7 +187,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -199,7 +187,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
199 log.trace("Executing unassignCustomerAssets, tenantId [{}], customerId [{}]", tenantId, customerId); 187 log.trace("Executing unassignCustomerAssets, tenantId [{}], customerId [{}]", tenantId, customerId);
200 validateId(tenantId, "Incorrect tenantId " + tenantId); 188 validateId(tenantId, "Incorrect tenantId " + tenantId);
201 validateId(customerId, "Incorrect customerId " + customerId); 189 validateId(customerId, "Incorrect customerId " + customerId);
202 - new CustomerAssetsUnassigner(tenantId).removeEntitites(customerId); 190 + new CustomerAssetsUnassigner(tenantId).removeEntities(customerId);
203 } 191 }
204 192
205 @Override 193 @Override
@@ -232,16 +220,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -232,16 +220,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
232 public ListenableFuture<List<TenantAssetType>> findAssetTypesByTenantId(TenantId tenantId) { 220 public ListenableFuture<List<TenantAssetType>> findAssetTypesByTenantId(TenantId tenantId) {
233 log.trace("Executing findAssetTypesByTenantId, tenantId [{}]", tenantId); 221 log.trace("Executing findAssetTypesByTenantId, tenantId [{}]", tenantId);
234 validateId(tenantId, "Incorrect tenantId " + tenantId); 222 validateId(tenantId, "Incorrect tenantId " + tenantId);
235 - ListenableFuture<List<TenantAssetTypeEntity>> tenantAssetTypeEntities = assetDao.findTenantAssetTypesAsync(); 223 + ListenableFuture<List<TenantAssetType>> tenantAssetTypeEntities = assetDao.findTenantAssetTypesAsync();
236 ListenableFuture<List<TenantAssetType>> tenantAssetTypes = Futures.transform(tenantAssetTypeEntities, 224 ListenableFuture<List<TenantAssetType>> tenantAssetTypes = Futures.transform(tenantAssetTypeEntities,
237 - (Function<List<TenantAssetTypeEntity>, List<TenantAssetType>>) assetTypeEntities -> { 225 + (Function<List<TenantAssetType>, List<TenantAssetType>>) assetTypeEntities -> {
238 List<TenantAssetType> assetTypes = new ArrayList<>(); 226 List<TenantAssetType> assetTypes = new ArrayList<>();
239 - for (TenantAssetTypeEntity assetTypeEntity : assetTypeEntities) {  
240 - if (assetTypeEntity.getTenantId().equals(tenantId.getId())) {  
241 - assetTypes.add(assetTypeEntity.toTenantAssetType()); 227 + for (TenantAssetType assetType : assetTypeEntities) {
  228 + if (assetType.getTenantId().equals(tenantId)) {
  229 + assetTypes.add(assetType);
242 } 230 }
243 } 231 }
244 - assetTypes.sort((TenantAssetType o1, TenantAssetType o2) -> o1.getType().compareTo(o2.getType())); 232 + assetTypes.sort(Comparator.comparing(TenantAssetType::getType));
245 return assetTypes; 233 return assetTypes;
246 }); 234 });
247 return tenantAssetTypes; 235 return tenantAssetTypes;
@@ -263,7 +251,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -263,7 +251,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
263 protected void validateUpdate(Asset asset) { 251 protected void validateUpdate(Asset asset) {
264 assetDao.findAssetsByTenantIdAndName(asset.getTenantId().getId(), asset.getName()).ifPresent( 252 assetDao.findAssetsByTenantIdAndName(asset.getTenantId().getId(), asset.getName()).ifPresent(
265 d -> { 253 d -> {
266 - if (!d.getId().equals(asset.getUuidId())) { 254 + if (!d.getId().equals(asset.getId())) {
267 throw new DataValidationException("Asset with such name already exists!"); 255 throw new DataValidationException("Asset with such name already exists!");
268 } 256 }
269 } 257 }
@@ -281,7 +269,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -281,7 +269,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
281 if (asset.getTenantId() == null) { 269 if (asset.getTenantId() == null) {
282 throw new DataValidationException("Asset should be assigned to tenant!"); 270 throw new DataValidationException("Asset should be assigned to tenant!");
283 } else { 271 } else {
284 - TenantEntity tenant = tenantDao.findById(asset.getTenantId().getId()); 272 + Tenant tenant = tenantDao.findById(asset.getTenantId().getId());
285 if (tenant == null) { 273 if (tenant == null) {
286 throw new DataValidationException("Asset is referencing to non-existent tenant!"); 274 throw new DataValidationException("Asset is referencing to non-existent tenant!");
287 } 275 }
@@ -289,32 +277,32 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -289,32 +277,32 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
289 if (asset.getCustomerId() == null) { 277 if (asset.getCustomerId() == null) {
290 asset.setCustomerId(new CustomerId(NULL_UUID)); 278 asset.setCustomerId(new CustomerId(NULL_UUID));
291 } else if (!asset.getCustomerId().getId().equals(NULL_UUID)) { 279 } else if (!asset.getCustomerId().getId().equals(NULL_UUID)) {
292 - CustomerEntity customer = customerDao.findById(asset.getCustomerId().getId()); 280 + Customer customer = customerDao.findById(asset.getCustomerId().getId());
293 if (customer == null) { 281 if (customer == null) {
294 throw new DataValidationException("Can't assign asset to non-existent customer!"); 282 throw new DataValidationException("Can't assign asset to non-existent customer!");
295 } 283 }
296 - if (!customer.getTenantId().equals(asset.getTenantId().getId())) { 284 + if (!customer.getTenantId().equals(asset.getTenantId())) {
297 throw new DataValidationException("Can't assign asset to customer from different tenant!"); 285 throw new DataValidationException("Can't assign asset to customer from different tenant!");
298 } 286 }
299 } 287 }
300 } 288 }
301 }; 289 };
302 290
303 - private PaginatedRemover<TenantId, AssetEntity> tenantAssetsRemover =  
304 - new PaginatedRemover<TenantId, AssetEntity>() { 291 + private PaginatedRemover<TenantId, Asset> tenantAssetsRemover =
  292 + new PaginatedRemover<TenantId, Asset>() {
305 293
306 @Override 294 @Override
307 - protected List<AssetEntity> findEntities(TenantId id, TextPageLink pageLink) { 295 + protected List<Asset> findEntities(TenantId id, TextPageLink pageLink) {
308 return assetDao.findAssetsByTenantId(id.getId(), pageLink); 296 return assetDao.findAssetsByTenantId(id.getId(), pageLink);
309 } 297 }
310 298
311 @Override 299 @Override
312 - protected void removeEntity(AssetEntity entity) {  
313 - deleteAsset(new AssetId(entity.getId())); 300 + protected void removeEntity(Asset entity) {
  301 + deleteAsset(new AssetId(entity.getId().getId()));
314 } 302 }
315 }; 303 };
316 304
317 - class CustomerAssetsUnassigner extends PaginatedRemover<CustomerId, AssetEntity> { 305 + class CustomerAssetsUnassigner extends PaginatedRemover<CustomerId, Asset> {
318 306
319 private TenantId tenantId; 307 private TenantId tenantId;
320 308
@@ -323,13 +311,13 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -323,13 +311,13 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
323 } 311 }
324 312
325 @Override 313 @Override
326 - protected List<AssetEntity> findEntities(CustomerId id, TextPageLink pageLink) { 314 + protected List<Asset> findEntities(CustomerId id, TextPageLink pageLink) {
327 return assetDao.findAssetsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); 315 return assetDao.findAssetsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
328 } 316 }
329 317
330 @Override 318 @Override
331 - protected void removeEntity(AssetEntity entity) {  
332 - unassignAssetFromCustomer(new AssetId(entity.getId())); 319 + protected void removeEntity(Asset entity) {
  320 + unassignAssetFromCustomer(new AssetId(entity.getId().getId()));
333 } 321 }
334 } 322 }
335 } 323 }
dao/src/main/java/org/thingsboard/server/dao/asset/CassandraAssetDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/asset/AssetDaoImpl.java
@@ -25,10 +25,13 @@ import com.google.common.util.concurrent.ListenableFuture; @@ -25,10 +25,13 @@ import com.google.common.util.concurrent.ListenableFuture;
25 import lombok.extern.slf4j.Slf4j; 25 import lombok.extern.slf4j.Slf4j;
26 import org.springframework.stereotype.Component; 26 import org.springframework.stereotype.Component;
27 import org.thingsboard.server.common.data.asset.Asset; 27 import org.thingsboard.server.common.data.asset.Asset;
  28 +import org.thingsboard.server.common.data.asset.TenantAssetType;
28 import org.thingsboard.server.common.data.page.TextPageLink; 29 import org.thingsboard.server.common.data.page.TextPageLink;
29 -import org.thingsboard.server.dao.AbstractSearchTextDao;  
30 -import org.thingsboard.server.dao.model.AssetEntity; 30 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  31 +import org.thingsboard.server.dao.DaoUtil;
  32 +import org.thingsboard.server.dao.util.NoSqlDao;
31 import org.thingsboard.server.dao.model.TenantAssetTypeEntity; 33 import org.thingsboard.server.dao.model.TenantAssetTypeEntity;
  34 +import org.thingsboard.server.dao.model.nosql.AssetEntity;
32 35
33 import javax.annotation.Nullable; 36 import javax.annotation.Nullable;
34 import java.util.*; 37 import java.util.*;
@@ -38,7 +41,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; @@ -38,7 +41,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
38 41
39 @Component 42 @Component
40 @Slf4j 43 @Slf4j
41 -public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements AssetDao { 44 +@NoSqlDao
  45 +public class CassandraAssetDao extends CassandraAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao {
42 46
43 @Override 47 @Override
44 protected Class<AssetEntity> getColumnFamilyClass() { 48 protected Class<AssetEntity> getColumnFamilyClass() {
@@ -51,33 +55,26 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -51,33 +55,26 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
51 } 55 }
52 56
53 @Override 57 @Override
54 - public AssetEntity save(Asset asset) {  
55 - log.debug("Save asset [{}] ", asset);  
56 - return save(new AssetEntity(asset));  
57 - }  
58 -  
59 - @Override  
60 - public List<AssetEntity> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) { 58 + public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) {
61 log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink); 59 log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
62 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 60 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
63 Collections.singletonList(eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink); 61 Collections.singletonList(eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink);
64 62
65 log.trace("Found assets [{}] by tenantId [{}] and pageLink [{}]", assetEntities, tenantId, pageLink); 63 log.trace("Found assets [{}] by tenantId [{}] and pageLink [{}]", assetEntities, tenantId, pageLink);
66 - return assetEntities; 64 + return DaoUtil.convertDataList(assetEntities);
67 } 65 }
68 66
69 @Override 67 @Override
70 - public List<AssetEntity> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { 68 + public List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) {
71 log.debug("Try to find assets by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink); 69 log.debug("Try to find assets by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink);
72 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 70 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
73 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type), 71 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type),
74 eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink); 72 eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink);
75 log.trace("Found assets [{}] by tenantId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, type, pageLink); 73 log.trace("Found assets [{}] by tenantId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, type, pageLink);
76 - return assetEntities; 74 + return DaoUtil.convertDataList(assetEntities);
77 } 75 }
78 76
79 - @Override  
80 - public ListenableFuture<List<AssetEntity>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { 77 + public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) {
81 log.debug("Try to find assets by tenantId [{}] and asset Ids [{}]", tenantId, assetIds); 78 log.debug("Try to find assets by tenantId [{}] and asset Ids [{}]", tenantId, assetIds);
82 Select select = select().from(getColumnFamilyName()); 79 Select select = select().from(getColumnFamilyName());
83 Select.Where query = select.where(); 80 Select.Where query = select.where();
@@ -87,7 +84,7 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -87,7 +84,7 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
87 } 84 }
88 85
89 @Override 86 @Override
90 - public List<AssetEntity> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { 87 + public List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
91 log.debug("Try to find assets by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); 88 log.debug("Try to find assets by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
92 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 89 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
93 Arrays.asList(eq(ASSET_CUSTOMER_ID_PROPERTY, customerId), 90 Arrays.asList(eq(ASSET_CUSTOMER_ID_PROPERTY, customerId),
@@ -95,11 +92,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -95,11 +92,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
95 pageLink); 92 pageLink);
96 93
97 log.trace("Found assets [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", assetEntities, tenantId, customerId, pageLink); 94 log.trace("Found assets [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", assetEntities, tenantId, customerId, pageLink);
98 - return assetEntities; 95 + return DaoUtil.convertDataList(assetEntities);
99 } 96 }
100 97
101 @Override 98 @Override
102 - public List<AssetEntity> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { 99 + public List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) {
103 log.debug("Try to find assets by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink); 100 log.debug("Try to find assets by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink);
104 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 101 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
105 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type), 102 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type),
@@ -108,11 +105,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -108,11 +105,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
108 pageLink); 105 pageLink);
109 106
110 log.trace("Found assets [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, customerId, type, pageLink); 107 log.trace("Found assets [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, customerId, type, pageLink);
111 - return assetEntities; 108 + return DaoUtil.convertDataList(assetEntities);
112 } 109 }
113 110
114 @Override 111 @Override
115 - public ListenableFuture<List<AssetEntity>> findAssetsByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { 112 + public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) {
116 log.debug("Try to find assets by tenantId [{}], customerId [{}] and asset Ids [{}]", tenantId, customerId, assetIds); 113 log.debug("Try to find assets by tenantId [{}], customerId [{}] and asset Ids [{}]", tenantId, customerId, assetIds);
117 Select select = select().from(getColumnFamilyName()); 114 Select select = select().from(getColumnFamilyName());
118 Select.Where query = select.where(); 115 Select.Where query = select.where();
@@ -123,16 +120,17 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -123,16 +120,17 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
123 } 120 }
124 121
125 @Override 122 @Override
126 - public Optional<AssetEntity> findAssetsByTenantIdAndName(UUID tenantId, String assetName) { 123 + public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String assetName) {
127 Select select = select().from(ASSET_BY_TENANT_AND_NAME_VIEW_NAME); 124 Select select = select().from(ASSET_BY_TENANT_AND_NAME_VIEW_NAME);
128 Select.Where query = select.where(); 125 Select.Where query = select.where();
129 query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId)); 126 query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId));
130 query.and(eq(ASSET_NAME_PROPERTY, assetName)); 127 query.and(eq(ASSET_NAME_PROPERTY, assetName));
131 - return Optional.ofNullable(findOneByStatement(query)); 128 + AssetEntity assetEntity = (AssetEntity) findOneByStatement(query);
  129 + return Optional.ofNullable(DaoUtil.getData(assetEntity));
132 } 130 }
133 131
134 @Override 132 @Override
135 - public ListenableFuture<List<TenantAssetTypeEntity>> findTenantAssetTypesAsync() { 133 + public ListenableFuture<List<TenantAssetType>> findTenantAssetTypesAsync() {
136 Select statement = select().distinct().column(ASSET_TYPE_PROPERTY).column(ASSET_TENANT_ID_PROPERTY).from(ASSET_TYPES_BY_TENANT_VIEW_NAME); 134 Select statement = select().distinct().column(ASSET_TYPE_PROPERTY).column(ASSET_TENANT_ID_PROPERTY).from(ASSET_TYPES_BY_TENANT_VIEW_NAME);
137 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); 135 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
138 ResultSetFuture resultSetFuture = getSession().executeAsync(statement); 136 ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
@@ -148,7 +146,20 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements @@ -148,7 +146,20 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
148 } 146 }
149 } 147 }
150 }); 148 });
151 - return result; 149 + return Futures.transform(result, new Function<List<TenantAssetTypeEntity>, List<TenantAssetType>>() {
  150 + @Nullable
  151 + @Override
  152 + public List<TenantAssetType> apply(@Nullable List<TenantAssetTypeEntity> entityList) {
  153 + List<TenantAssetType> list = Collections.emptyList();
  154 + if (entityList != null && !entityList.isEmpty()) {
  155 + list = new ArrayList<>();
  156 + for (TenantAssetTypeEntity object : entityList) {
  157 + list.add(object.toTenantAssetType());
  158 + }
  159 + }
  160 + return list;
  161 + }
  162 + });
152 } 163 }
153 164
154 } 165 }
@@ -15,8 +15,6 @@ @@ -15,8 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao.attributes; 16 package org.thingsboard.server.dao.attributes;
17 17
18 -import com.datastax.driver.core.ResultSet;  
19 -import com.datastax.driver.core.ResultSetFuture;  
20 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
21 import org.thingsboard.server.common.data.id.EntityId; 19 import org.thingsboard.server.common.data.id.EntityId;
22 import org.thingsboard.server.common.data.kv.AttributeKvEntry; 20 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
@@ -36,7 +34,7 @@ public interface AttributesDao { @@ -36,7 +34,7 @@ public interface AttributesDao {
36 34
37 ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType); 35 ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType);
38 36
39 - ResultSetFuture save(EntityId entityId, String attributeType, AttributeKvEntry attribute); 37 + ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute);
40 38
41 - ListenableFuture<List<ResultSet>> removeAll(EntityId entityId, String scope, List<String> keys); 39 + ListenableFuture<List<Void>> removeAll(EntityId entityId, String attributeType, List<String> keys);
42 } 40 }
@@ -15,12 +15,8 @@ @@ -15,12 +15,8 @@
15 */ 15 */
16 package org.thingsboard.server.dao.attributes; 16 package org.thingsboard.server.dao.attributes;
17 17
18 -import com.datastax.driver.core.ResultSet;  
19 -import com.datastax.driver.core.ResultSetFuture;  
20 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
21 -import org.thingsboard.server.common.data.id.DeviceId;  
22 import org.thingsboard.server.common.data.id.EntityId; 19 import org.thingsboard.server.common.data.id.EntityId;
23 -import org.thingsboard.server.common.data.id.UUIDBased;  
24 import org.thingsboard.server.common.data.kv.AttributeKvEntry; 20 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
25 21
26 import java.util.Collection; 22 import java.util.Collection;
@@ -38,7 +34,7 @@ public interface AttributesService { @@ -38,7 +34,7 @@ public interface AttributesService {
38 34
39 ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String scope); 35 ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String scope);
40 36
41 - ListenableFuture<List<ResultSet>> save(EntityId entityId, String scope, List<AttributeKvEntry> attributes); 37 + ListenableFuture<List<Void>> save(EntityId entityId, String scope, List<AttributeKvEntry> attributes);
42 38
43 - ListenableFuture<List<ResultSet>> removeAll(EntityId entityId, String scope, List<String> attributeKeys); 39 + ListenableFuture<List<Void>> removeAll(EntityId entityId, String scope, List<String> attributeKeys);
44 } 40 }
@@ -20,11 +20,11 @@ import com.datastax.driver.core.ResultSetFuture; @@ -20,11 +20,11 @@ import com.datastax.driver.core.ResultSetFuture;
20 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
21 import com.google.common.util.concurrent.Futures; 21 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture; 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.stereotype.Service;
23 import org.thingsboard.server.common.data.id.EntityId; 25 import org.thingsboard.server.common.data.id.EntityId;
24 import org.thingsboard.server.common.data.kv.AttributeKvEntry; 26 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
25 import org.thingsboard.server.dao.exception.IncorrectParameterException; 27 import org.thingsboard.server.dao.exception.IncorrectParameterException;
26 -import org.springframework.beans.factory.annotation.Autowired;  
27 -import org.springframework.stereotype.Service;  
28 import org.thingsboard.server.dao.service.Validator; 28 import org.thingsboard.server.dao.service.Validator;
29 29
30 import java.util.Collection; 30 import java.util.Collection;
@@ -61,10 +61,10 @@ public class BaseAttributesService implements AttributesService { @@ -61,10 +61,10 @@ public class BaseAttributesService implements AttributesService {
61 } 61 }
62 62
63 @Override 63 @Override
64 - public ListenableFuture<List<ResultSet>> save(EntityId entityId, String scope, List<AttributeKvEntry> attributes) { 64 + public ListenableFuture<List<Void>> save(EntityId entityId, String scope, List<AttributeKvEntry> attributes) {
65 validate(entityId, scope); 65 validate(entityId, scope);
66 attributes.forEach(attribute -> validate(attribute)); 66 attributes.forEach(attribute -> validate(attribute));
67 - List<ResultSetFuture> futures = Lists.newArrayListWithExpectedSize(attributes.size()); 67 + List<ListenableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(attributes.size());
68 for (AttributeKvEntry attribute : attributes) { 68 for (AttributeKvEntry attribute : attributes) {
69 futures.add(attributesDao.save(entityId, scope, attribute)); 69 futures.add(attributesDao.save(entityId, scope, attribute));
70 } 70 }
@@ -72,7 +72,7 @@ public class BaseAttributesService implements AttributesService { @@ -72,7 +72,7 @@ public class BaseAttributesService implements AttributesService {
72 } 72 }
73 73
74 @Override 74 @Override
75 - public ListenableFuture<List<ResultSet>> removeAll(EntityId entityId, String scope, List<String> keys) { 75 + public ListenableFuture<List<Void>> removeAll(EntityId entityId, String scope, List<String> keys) {
76 validate(entityId, scope); 76 validate(entityId, scope);
77 return attributesDao.removeAll(entityId, scope, keys); 77 return attributesDao.removeAll(entityId, scope, keys);
78 } 78 }
dao/src/main/java/org/thingsboard/server/dao/attributes/CassandraBaseAttributesDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesDao.java
@@ -24,10 +24,12 @@ import com.google.common.util.concurrent.ListenableFuture; @@ -24,10 +24,12 @@ import com.google.common.util.concurrent.ListenableFuture;
24 import lombok.extern.slf4j.Slf4j; 24 import lombok.extern.slf4j.Slf4j;
25 import org.springframework.stereotype.Component; 25 import org.springframework.stereotype.Component;
26 import org.thingsboard.server.common.data.id.EntityId; 26 import org.thingsboard.server.common.data.id.EntityId;
27 -import org.thingsboard.server.dao.AbstractAsyncDao; 27 +import org.thingsboard.server.common.data.kv.AttributeKvEntry;
  28 +import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
  29 +import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao;
  30 +import org.thingsboard.server.dao.util.NoSqlDao;
28 import org.thingsboard.server.dao.model.ModelConstants; 31 import org.thingsboard.server.dao.model.ModelConstants;
29 -import org.thingsboard.server.common.data.kv.*;  
30 -import org.thingsboard.server.dao.timeseries.BaseTimeseriesDao; 32 +import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao;
31 33
32 import javax.annotation.PostConstruct; 34 import javax.annotation.PostConstruct;
33 import javax.annotation.PreDestroy; 35 import javax.annotation.PreDestroy;
@@ -37,15 +39,17 @@ import java.util.List; @@ -37,15 +39,17 @@ import java.util.List;
37 import java.util.Optional; 39 import java.util.Optional;
38 import java.util.stream.Collectors; 40 import java.util.stream.Collectors;
39 41
  42 +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
  43 +import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
40 import static org.thingsboard.server.dao.model.ModelConstants.*; 44 import static org.thingsboard.server.dao.model.ModelConstants.*;
41 -import static com.datastax.driver.core.querybuilder.QueryBuilder.*;  
42 45
43 /** 46 /**
44 * @author Andrew Shvayka 47 * @author Andrew Shvayka
45 */ 48 */
46 @Component 49 @Component
47 @Slf4j 50 @Slf4j
48 -public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao { 51 +@NoSqlDao
  52 +public class CassandraBaseAttributesDao extends CassandraAbstractAsyncDao implements AttributesDao {
49 53
50 private PreparedStatement saveStmt; 54 private PreparedStatement saveStmt;
51 55
@@ -97,7 +101,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao @@ -97,7 +101,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
97 } 101 }
98 102
99 @Override 103 @Override
100 - public ResultSetFuture save(EntityId entityId, String attributeType, AttributeKvEntry attribute) { 104 + public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) {
101 BoundStatement stmt = getSaveStmt().bind(); 105 BoundStatement stmt = getSaveStmt().bind();
102 stmt.setString(0, entityId.getEntityType().name()); 106 stmt.setString(0, entityId.getEntityType().name());
103 stmt.setUUID(1, entityId.getId()); 107 stmt.setUUID(1, entityId.getId());
@@ -120,23 +124,27 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao @@ -120,23 +124,27 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
120 } else { 124 } else {
121 stmt.setToNull(8); 125 stmt.setToNull(8);
122 } 126 }
123 - return executeAsyncWrite(stmt); 127 + log.trace("Generated save stmt [{}] for entityId {} and attributeType {} and attribute", stmt, entityId, attributeType, attribute);
  128 + return getFuture(executeAsyncWrite(stmt), rs -> null);
124 } 129 }
125 130
126 @Override 131 @Override
127 - public ListenableFuture<List<ResultSet>> removeAll(EntityId entityId, String attributeType, List<String> keys) {  
128 - List<ResultSetFuture> futures = keys.stream().map(key -> delete(entityId, attributeType, key)).collect(Collectors.toList()); 132 + public ListenableFuture<List<Void>> removeAll(EntityId entityId, String attributeType, List<String> keys) {
  133 + List<ListenableFuture<Void>> futures = keys
  134 + .stream()
  135 + .map(key -> delete(entityId, attributeType, key))
  136 + .collect(Collectors.toList());
129 return Futures.allAsList(futures); 137 return Futures.allAsList(futures);
130 } 138 }
131 139
132 - private ResultSetFuture delete(EntityId entityId, String attributeType, String key) { 140 + private ListenableFuture<Void> delete(EntityId entityId, String attributeType, String key) {
133 Statement delete = QueryBuilder.delete().all().from(ModelConstants.ATTRIBUTES_KV_CF) 141 Statement delete = QueryBuilder.delete().all().from(ModelConstants.ATTRIBUTES_KV_CF)
134 .where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType())) 142 .where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType()))
135 .and(eq(ENTITY_ID_COLUMN, entityId.getId())) 143 .and(eq(ENTITY_ID_COLUMN, entityId.getId()))
136 .and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType)) 144 .and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType))
137 .and(eq(ATTRIBUTE_KEY_COLUMN, key)); 145 .and(eq(ATTRIBUTE_KEY_COLUMN, key));
138 log.debug("Remove request: {}", delete.toString()); 146 log.debug("Remove request: {}", delete.toString());
139 - return getSession().executeAsync(delete); 147 + return getFuture(getSession().executeAsync(delete), rs -> null);
140 } 148 }
141 149
142 private PreparedStatement getSaveStmt() { 150 private PreparedStatement getSaveStmt() {
@@ -161,7 +169,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao @@ -161,7 +169,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
161 AttributeKvEntry attributeEntry = null; 169 AttributeKvEntry attributeEntry = null;
162 if (row != null) { 170 if (row != null) {
163 long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class); 171 long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class);
164 - attributeEntry = new BaseAttributeKvEntry(BaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs); 172 + attributeEntry = new BaseAttributeKvEntry(CassandraBaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs);
165 } 173 }
166 return attributeEntry; 174 return attributeEntry;
167 } 175 }
@@ -57,16 +57,25 @@ public class ServiceCacheConfiguration { @@ -57,16 +57,25 @@ public class ServiceCacheConfiguration {
57 Config config = new Config(); 57 Config config = new Config();
58 58
59 if (zkEnabled) { 59 if (zkEnabled) {
60 - config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);  
61 -  
62 - config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), Boolean.TRUE.toString());  
63 - DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory());  
64 - discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zkUrl);  
65 - discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH.key(), zkDir);  
66 - discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.GROUP.key(), HAZELCAST_CLUSTER_NAME);  
67 - config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig); 60 + addZkConfig(config);
68 } 61 }
69 62
  63 + config.addMapConfig(createDeviceCredentialsCacheConfig());
  64 +
  65 + return Hazelcast.newHazelcastInstance(config);
  66 + }
  67 +
  68 + private void addZkConfig(Config config) {
  69 + config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
  70 + config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), Boolean.TRUE.toString());
  71 + DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory());
  72 + discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zkUrl);
  73 + discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH.key(), zkDir);
  74 + discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.GROUP.key(), HAZELCAST_CLUSTER_NAME);
  75 + config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig);
  76 + }
  77 +
  78 + private MapConfig createDeviceCredentialsCacheConfig() {
70 MapConfig deviceCredentialsCacheConfig = new MapConfig(CacheConstants.DEVICE_CREDENTIALS_CACHE); 79 MapConfig deviceCredentialsCacheConfig = new MapConfig(CacheConstants.DEVICE_CREDENTIALS_CACHE);
71 deviceCredentialsCacheConfig.setTimeToLiveSeconds(cacheDeviceCredentialsTTL); 80 deviceCredentialsCacheConfig.setTimeToLiveSeconds(cacheDeviceCredentialsTTL);
72 deviceCredentialsCacheConfig.setEvictionPolicy(EvictionPolicy.LRU); 81 deviceCredentialsCacheConfig.setEvictionPolicy(EvictionPolicy.LRU);
@@ -75,9 +84,7 @@ public class ServiceCacheConfiguration { @@ -75,9 +84,7 @@ public class ServiceCacheConfiguration {
75 cacheDeviceCredentialsMaxSizeSize, 84 cacheDeviceCredentialsMaxSizeSize,
76 MaxSizeConfig.MaxSizePolicy.valueOf(cacheDeviceCredentialsMaxSizePolicy)) 85 MaxSizeConfig.MaxSizePolicy.valueOf(cacheDeviceCredentialsMaxSizePolicy))
77 ); 86 );
78 - config.addMapConfig(deviceCredentialsCacheConfig);  
79 -  
80 - return Hazelcast.newHazelcastInstance(config); 87 + return deviceCredentialsCacheConfig;
81 } 88 }
82 89
83 @Bean 90 @Bean
@@ -16,13 +16,8 @@ @@ -16,13 +16,8 @@
16 package org.thingsboard.server.dao.cassandra; 16 package org.thingsboard.server.dao.cassandra;
17 17
18 18
19 -import com.datastax.driver.core.Cluster;  
20 -import com.datastax.driver.core.ConsistencyLevel;  
21 -import com.datastax.driver.core.HostDistance;  
22 -import com.datastax.driver.core.PoolingOptions; 19 +import com.datastax.driver.core.*;
23 import com.datastax.driver.core.ProtocolOptions.Compression; 20 import com.datastax.driver.core.ProtocolOptions.Compression;
24 -import com.datastax.driver.core.Session;  
25 -import com.datastax.driver.core.exceptions.NoHostAvailableException;  
26 import com.datastax.driver.mapping.Mapper; 21 import com.datastax.driver.mapping.Mapper;
27 import com.datastax.driver.mapping.MappingManager; 22 import com.datastax.driver.mapping.MappingManager;
28 import lombok.Data; 23 import lombok.Data;
@@ -31,20 +26,19 @@ import org.apache.commons.lang3.StringUtils; @@ -31,20 +26,19 @@ import org.apache.commons.lang3.StringUtils;
31 import org.springframework.beans.factory.annotation.Autowired; 26 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Value; 27 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.stereotype.Component; 28 import org.springframework.stereotype.Component;
34 -import org.thingsboard.server.dao.exception.DatabaseException; 29 +import org.thingsboard.server.dao.util.NoSqlDao;
35 30
36 import javax.annotation.PostConstruct; 31 import javax.annotation.PostConstruct;
37 import javax.annotation.PreDestroy; 32 import javax.annotation.PreDestroy;
38 -import java.io.Closeable;  
39 import java.net.InetSocketAddress; 33 import java.net.InetSocketAddress;
40 import java.util.ArrayList; 34 import java.util.ArrayList;
41 import java.util.Collections; 35 import java.util.Collections;
42 import java.util.List; 36 import java.util.List;
43 -import java.util.StringTokenizer;  
44 37
  38 +@Data
45 @Component 39 @Component
46 @Slf4j 40 @Slf4j
47 -@Data 41 +@NoSqlDao
48 public class CassandraCluster { 42 public class CassandraCluster {
49 43
50 private static final String COMMA = ","; 44 private static final String COMMA = ",";
@@ -21,15 +21,14 @@ import lombok.Data; @@ -21,15 +21,14 @@ import lombok.Data;
21 import org.springframework.beans.factory.annotation.Value; 21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.context.annotation.Configuration; 22 import org.springframework.context.annotation.Configuration;
23 import org.springframework.stereotype.Component; 23 import org.springframework.stereotype.Component;
24 -import org.springframework.util.StringUtils; 24 +import org.thingsboard.server.dao.util.NoSqlDao;
25 25
26 import javax.annotation.PostConstruct; 26 import javax.annotation.PostConstruct;
27 27
28 -import static org.apache.commons.lang3.StringUtils.isNotBlank;  
29 -  
30 @Component 28 @Component
31 @Configuration 29 @Configuration
32 @Data 30 @Data
  31 +@NoSqlDao
33 public class CassandraQueryOptions { 32 public class CassandraQueryOptions {
34 33
35 @Value("${cassandra.query.default_fetch_size}") 34 @Value("${cassandra.query.default_fetch_size}")
@@ -15,18 +15,19 @@ @@ -15,18 +15,19 @@
15 */ 15 */
16 package org.thingsboard.server.dao.cassandra; 16 package org.thingsboard.server.dao.cassandra;
17 17
  18 +import com.datastax.driver.core.SocketOptions;
18 import lombok.Data; 19 import lombok.Data;
19 import org.springframework.beans.factory.annotation.Value; 20 import org.springframework.beans.factory.annotation.Value;
20 import org.springframework.context.annotation.Configuration; 21 import org.springframework.context.annotation.Configuration;
21 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
22 -  
23 -import com.datastax.driver.core.SocketOptions; 23 +import org.thingsboard.server.dao.util.NoSqlDao;
24 24
25 import javax.annotation.PostConstruct; 25 import javax.annotation.PostConstruct;
26 26
27 @Component 27 @Component
28 @Configuration 28 @Configuration
29 @Data 29 @Data
  30 +@NoSqlDao
30 public class CassandraSocketOptions { 31 public class CassandraSocketOptions {
31 32
32 @Value("${cassandra.socket.connect_timeout}") 33 @Value("${cassandra.socket.connect_timeout}")
@@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope; @@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope;
32 import org.thingsboard.server.common.data.plugin.ComponentType; 32 import org.thingsboard.server.common.data.plugin.ComponentType;
33 import org.thingsboard.server.dao.exception.DataValidationException; 33 import org.thingsboard.server.dao.exception.DataValidationException;
34 import org.thingsboard.server.dao.exception.IncorrectParameterException; 34 import org.thingsboard.server.dao.exception.IncorrectParameterException;
35 -import org.thingsboard.server.dao.model.ComponentDescriptorEntity;  
36 import org.thingsboard.server.dao.service.DataValidator; 35 import org.thingsboard.server.dao.service.DataValidator;
37 import org.thingsboard.server.dao.service.Validator; 36 import org.thingsboard.server.dao.service.Validator;
38 37
39 import java.util.List; 38 import java.util.List;
40 import java.util.Optional; 39 import java.util.Optional;
41 40
42 -import static org.thingsboard.server.dao.DaoUtil.convertDataList;  
43 -import static org.thingsboard.server.dao.DaoUtil.getData;  
44 -  
45 /** 41 /**
46 * @author Andrew Shvayka 42 * @author Andrew Shvayka
47 */ 43 */
@@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic @@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic
55 @Override 51 @Override
56 public ComponentDescriptor saveComponent(ComponentDescriptor component) { 52 public ComponentDescriptor saveComponent(ComponentDescriptor component) {
57 componentValidator.validate(component); 53 componentValidator.validate(component);
58 - Optional<ComponentDescriptorEntity> result = componentDescriptorDao.save(component); 54 + Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(component);
59 if (result.isPresent()) { 55 if (result.isPresent()) {
60 - return getData(result.get()); 56 + return result.get();
61 } else { 57 } else {
62 - return getData(componentDescriptorDao.findByClazz(component.getClazz())); 58 + return componentDescriptorDao.findByClazz(component.getClazz());
63 } 59 }
64 } 60 }
65 61
66 @Override 62 @Override
67 public ComponentDescriptor findById(ComponentDescriptorId componentId) { 63 public ComponentDescriptor findById(ComponentDescriptorId componentId) {
68 Validator.validateId(componentId, "Incorrect component id for search request."); 64 Validator.validateId(componentId, "Incorrect component id for search request.");
69 - return getData(componentDescriptorDao.findById(componentId)); 65 + return componentDescriptorDao.findById(componentId);
70 } 66 }
71 67
72 @Override 68 @Override
73 public ComponentDescriptor findByClazz(String clazz) { 69 public ComponentDescriptor findByClazz(String clazz) {
74 Validator.validateString(clazz, "Incorrect clazz for search request."); 70 Validator.validateString(clazz, "Incorrect clazz for search request.");
75 - return getData(componentDescriptorDao.findByClazz(clazz)); 71 + return componentDescriptorDao.findByClazz(clazz);
76 } 72 }
77 73
78 @Override 74 @Override
79 public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { 75 public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
80 Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); 76 Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request.");
81 - List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByTypeAndPageLink(type, pageLink);  
82 - List<ComponentDescriptor> components = convertDataList(pluginEntities); 77 + List<ComponentDescriptor> components = componentDescriptorDao.findByTypeAndPageLink(type, pageLink);
83 return new TextPageData<>(components, pageLink); 78 return new TextPageData<>(components, pageLink);
84 } 79 }
85 80
86 @Override 81 @Override
87 public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { 82 public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
88 Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); 83 Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request.");
89 - List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink);  
90 - List<ComponentDescriptor> components = convertDataList(pluginEntities); 84 + List<ComponentDescriptor> components = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink);
91 return new TextPageData<>(components, pageLink); 85 return new TextPageData<>(components, pageLink);
92 } 86 }
93 87
dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorDao.java
@@ -27,9 +27,11 @@ import org.thingsboard.server.common.data.page.TextPageLink; @@ -27,9 +27,11 @@ import org.thingsboard.server.common.data.page.TextPageLink;
27 import org.thingsboard.server.common.data.plugin.ComponentDescriptor; 27 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
28 import org.thingsboard.server.common.data.plugin.ComponentScope; 28 import org.thingsboard.server.common.data.plugin.ComponentScope;
29 import org.thingsboard.server.common.data.plugin.ComponentType; 29 import org.thingsboard.server.common.data.plugin.ComponentType;
30 -import org.thingsboard.server.dao.AbstractSearchTextDao; 30 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  31 +import org.thingsboard.server.dao.DaoUtil;
  32 +import org.thingsboard.server.dao.util.NoSqlDao;
31 import org.thingsboard.server.dao.model.ModelConstants; 33 import org.thingsboard.server.dao.model.ModelConstants;
32 -import org.thingsboard.server.dao.model.ComponentDescriptorEntity; 34 +import org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity;
33 35
34 import java.util.Arrays; 36 import java.util.Arrays;
35 import java.util.List; 37 import java.util.List;
@@ -44,7 +46,8 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select; @@ -44,7 +46,8 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
44 */ 46 */
45 @Component 47 @Component
46 @Slf4j 48 @Slf4j
47 -public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentDescriptorEntity> implements ComponentDescriptorDao { 49 +@NoSqlDao
  50 +public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao {
48 51
49 @Override 52 @Override
50 protected Class<ComponentDescriptorEntity> getColumnFamilyClass() { 53 protected Class<ComponentDescriptorEntity> getColumnFamilyClass() {
@@ -57,10 +60,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD @@ -57,10 +60,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
57 } 60 }
58 61
59 @Override 62 @Override
60 - public Optional<ComponentDescriptorEntity> save(ComponentDescriptor component) { 63 + public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
61 ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component); 64 ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component);
62 log.debug("Save component entity [{}]", entity); 65 log.debug("Save component entity [{}]", entity);
63 - Optional<ComponentDescriptorEntity> result = saveIfNotExist(entity); 66 + Optional<ComponentDescriptor> result = saveIfNotExist(entity);
64 if (log.isTraceEnabled()) { 67 if (log.isTraceEnabled()) {
65 log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null)); 68 log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null));
66 } else { 69 } else {
@@ -70,19 +73,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD @@ -70,19 +73,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
70 } 73 }
71 74
72 @Override 75 @Override
73 - public ComponentDescriptorEntity findById(ComponentDescriptorId componentId) { 76 + public ComponentDescriptor findById(ComponentDescriptorId componentId) {
74 log.debug("Search component entity by id [{}]", componentId); 77 log.debug("Search component entity by id [{}]", componentId);
75 - ComponentDescriptorEntity entity = super.findById(componentId.getId()); 78 + ComponentDescriptor componentDescriptor = super.findById(componentId.getId());
76 if (log.isTraceEnabled()) { 79 if (log.isTraceEnabled()) {
77 - log.trace("Search result: [{}] for component entity [{}]", entity != null, entity); 80 + log.trace("Search result: [{}] for component entity [{}]", componentDescriptor != null, componentDescriptor);
78 } else { 81 } else {
79 - log.debug("Search result: [{}]", entity != null); 82 + log.debug("Search result: [{}]", componentDescriptor != null);
80 } 83 }
81 - return entity; 84 + return componentDescriptor;
82 } 85 }
83 86
84 @Override 87 @Override
85 - public ComponentDescriptorEntity findByClazz(String clazz) { 88 + public ComponentDescriptor findByClazz(String clazz) {
86 log.debug("Search component entity by clazz [{}]", clazz); 89 log.debug("Search component entity by clazz [{}]", clazz);
87 Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); 90 Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz));
88 log.trace("Execute query [{}]", query); 91 log.trace("Execute query [{}]", query);
@@ -92,47 +95,47 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD @@ -92,47 +95,47 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
92 } else { 95 } else {
93 log.debug("Search result: [{}]", entity != null); 96 log.debug("Search result: [{}]", entity != null);
94 } 97 }
95 - return entity; 98 + return DaoUtil.getData(entity);
96 } 99 }
97 100
98 @Override 101 @Override
99 - public List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { 102 + public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
100 log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink); 103 log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink);
101 List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 104 List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
102 - Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name())), pageLink); 105 + Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type)), pageLink);
103 if (log.isTraceEnabled()) { 106 if (log.isTraceEnabled()) {
104 log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); 107 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
105 } else { 108 } else {
106 log.debug("Search result: [{}]", entities.size()); 109 log.debug("Search result: [{}]", entities.size());
107 } 110 }
108 - return entities; 111 + return DaoUtil.convertDataList(entities);
109 } 112 }
110 113
111 @Override 114 @Override
112 - public List<ComponentDescriptorEntity> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { 115 + public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
113 log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink); 116 log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink);
114 List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 117 List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
115 - Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name()), 118 + Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type),
116 eq(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, scope.name())), pageLink); 119 eq(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, scope.name())), pageLink);
117 if (log.isTraceEnabled()) { 120 if (log.isTraceEnabled()) {
118 log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); 121 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
119 } else { 122 } else {
120 log.debug("Search result: [{}]", entities.size()); 123 log.debug("Search result: [{}]", entities.size());
121 } 124 }
122 - return entities; 125 + return DaoUtil.convertDataList(entities);
123 } 126 }
124 127
125 - public ResultSet removeById(UUID key) { 128 + public boolean removeById(UUID key) {
126 Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key)); 129 Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key));
127 log.debug("Remove request: {}", delete.toString()); 130 log.debug("Remove request: {}", delete.toString());
128 - return getSession().execute(delete); 131 + return getSession().execute(delete).wasApplied();
129 } 132 }
130 133
131 @Override 134 @Override
132 public void deleteById(ComponentDescriptorId id) { 135 public void deleteById(ComponentDescriptorId id) {
133 log.debug("Delete plugin meta-data entity by id [{}]", id); 136 log.debug("Delete plugin meta-data entity by id [{}]", id);
134 - ResultSet resultSet = removeById(id.getId());  
135 - log.debug("Delete result: [{}]", resultSet.wasApplied()); 137 + boolean result = removeById(id.getId());
  138 + log.debug("Delete result: [{}]", result);
136 } 139 }
137 140
138 @Override 141 @Override
@@ -144,7 +147,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD @@ -144,7 +147,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
144 log.debug("Delete result: [{}]", resultSet.wasApplied()); 147 log.debug("Delete result: [{}]", resultSet.wasApplied());
145 } 148 }
146 149
147 - private Optional<ComponentDescriptorEntity> saveIfNotExist(ComponentDescriptorEntity entity) { 150 + private Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptorEntity entity) {
148 if (entity.getId() == null) { 151 if (entity.getId() == null) {
149 entity.setId(UUIDs.timeBased()); 152 entity.setId(UUIDs.timeBased());
150 } 153 }
@@ -161,7 +164,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD @@ -161,7 +164,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
161 .ifNotExists() 164 .ifNotExists()
162 ); 165 );
163 if (rs.wasApplied()) { 166 if (rs.wasApplied()) {
164 - return Optional.of(entity); 167 + return Optional.of(DaoUtil.getData(entity));
165 } else { 168 } else {
166 return Optional.empty(); 169 return Optional.empty();
167 } 170 }
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor; @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
21 import org.thingsboard.server.common.data.plugin.ComponentScope; 21 import org.thingsboard.server.common.data.plugin.ComponentScope;
22 import org.thingsboard.server.common.data.plugin.ComponentType; 22 import org.thingsboard.server.common.data.plugin.ComponentType;
23 import org.thingsboard.server.dao.Dao; 23 import org.thingsboard.server.dao.Dao;
24 -import org.thingsboard.server.dao.model.ComponentDescriptorEntity;  
25 24
26 import java.util.List; 25 import java.util.List;
27 import java.util.Optional; 26 import java.util.Optional;
@@ -29,17 +28,17 @@ import java.util.Optional; @@ -29,17 +28,17 @@ import java.util.Optional;
29 /** 28 /**
30 * @author Andrew Shvayka 29 * @author Andrew Shvayka
31 */ 30 */
32 -public interface ComponentDescriptorDao extends Dao<ComponentDescriptorEntity> { 31 +public interface ComponentDescriptorDao extends Dao<ComponentDescriptor> {
33 32
34 - Optional<ComponentDescriptorEntity> save(ComponentDescriptor component); 33 + Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component);
35 34
36 - ComponentDescriptorEntity findById(ComponentDescriptorId componentId); 35 + ComponentDescriptor findById(ComponentDescriptorId componentId);
37 36
38 - ComponentDescriptorEntity findByClazz(String clazz); 37 + ComponentDescriptor findByClazz(String clazz);
39 38
40 - List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink); 39 + List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink);
41 40
42 - List<ComponentDescriptorEntity> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink); 41 + List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink);
43 42
44 void deleteById(ComponentDescriptorId componentId); 43 void deleteById(ComponentDescriptorId componentId);
45 44
dao/src/main/java/org/thingsboard/server/dao/customer/CassandraCustomerDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDaoImpl.java
@@ -15,31 +15,29 @@ @@ -15,31 +15,29 @@
15 */ 15 */
16 package org.thingsboard.server.dao.customer; 16 package org.thingsboard.server.dao.customer;
17 17
18 -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;  
19 -import static com.datastax.driver.core.querybuilder.QueryBuilder.select;  
20 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME;  
21 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TITLE_PROPERTY;  
22 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TENANT_ID_PROPERTY;  
23 -  
24 -  
25 -import java.util.Arrays;  
26 -import java.util.List;  
27 -import java.util.Optional;  
28 -import java.util.UUID;  
29 -  
30 import com.datastax.driver.core.querybuilder.Select; 18 import com.datastax.driver.core.querybuilder.Select;
31 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
32 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
33 import org.thingsboard.server.common.data.Customer; 21 import org.thingsboard.server.common.data.Customer;
34 import org.thingsboard.server.common.data.page.TextPageLink; 22 import org.thingsboard.server.common.data.page.TextPageLink;
35 -import org.thingsboard.server.dao.AbstractSearchTextDao;  
36 -import org.thingsboard.server.dao.model.CustomerEntity;  
37 -import org.slf4j.Logger;  
38 -import org.slf4j.LoggerFactory; 23 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  24 +import org.thingsboard.server.dao.DaoUtil;
  25 +import org.thingsboard.server.dao.util.NoSqlDao;
39 import org.thingsboard.server.dao.model.ModelConstants; 26 import org.thingsboard.server.dao.model.ModelConstants;
  27 +import org.thingsboard.server.dao.model.nosql.CustomerEntity;
  28 +
  29 +import java.util.Arrays;
  30 +import java.util.List;
  31 +import java.util.Optional;
  32 +import java.util.UUID;
  33 +
  34 +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
  35 +import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
  36 +import static org.thingsboard.server.dao.model.ModelConstants.*;
40 @Component 37 @Component
41 @Slf4j 38 @Slf4j
42 -public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> implements CustomerDao { 39 +@NoSqlDao
  40 +public class CassandraCustomerDao extends CassandraAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao {
43 41
44 @Override 42 @Override
45 protected Class<CustomerEntity> getColumnFamilyClass() { 43 protected Class<CustomerEntity> getColumnFamilyClass() {
@@ -50,30 +48,26 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple @@ -50,30 +48,26 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple
50 protected String getColumnFamilyName() { 48 protected String getColumnFamilyName() {
51 return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; 49 return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME;
52 } 50 }
53 -  
54 - @Override  
55 - public CustomerEntity save(Customer customer) {  
56 - log.debug("Save customer [{}] ", customer);  
57 - return save(new CustomerEntity(customer));  
58 - }  
59 51
60 @Override 52 @Override
61 - public List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { 53 + public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) {
62 log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink); 54 log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
63 List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 55 List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
64 Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)), 56 Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)),
65 pageLink); 57 pageLink);
66 log.trace("Found customers [{}] by tenantId [{}] and pageLink [{}]", customerEntities, tenantId, pageLink); 58 log.trace("Found customers [{}] by tenantId [{}] and pageLink [{}]", customerEntities, tenantId, pageLink);
67 - return customerEntities; 59 + return DaoUtil.convertDataList(customerEntities);
68 } 60 }
69 61
70 @Override 62 @Override
71 - public Optional<CustomerEntity> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { 63 + public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) {
72 Select select = select().from(CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME); 64 Select select = select().from(CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME);
73 Select.Where query = select.where(); 65 Select.Where query = select.where();
74 query.and(eq(CUSTOMER_TENANT_ID_PROPERTY, tenantId)); 66 query.and(eq(CUSTOMER_TENANT_ID_PROPERTY, tenantId));
75 query.and(eq(CUSTOMER_TITLE_PROPERTY, title)); 67 query.and(eq(CUSTOMER_TITLE_PROPERTY, title));
76 - return Optional.ofNullable(findOneByStatement(query)); 68 + CustomerEntity customerEntity = findOneByStatement(query);
  69 + Customer customer = DaoUtil.getData(customerEntity);
  70 + return Optional.ofNullable(customer);
77 } 71 }
78 72
79 } 73 }
@@ -15,20 +15,18 @@ @@ -15,20 +15,18 @@
15 */ 15 */
16 package org.thingsboard.server.dao.customer; 16 package org.thingsboard.server.dao.customer;
17 17
18 -import java.util.List;  
19 import java.util.Optional; 18 import java.util.Optional;
20 -import java.util.UUID;  
21 -  
22 import org.thingsboard.server.common.data.Customer; 19 import org.thingsboard.server.common.data.Customer;
23 import org.thingsboard.server.common.data.page.TextPageLink; 20 import org.thingsboard.server.common.data.page.TextPageLink;
24 import org.thingsboard.server.dao.Dao; 21 import org.thingsboard.server.dao.Dao;
25 -import org.thingsboard.server.dao.model.CustomerEntity;  
26 -import org.thingsboard.server.dao.model.DeviceEntity; 22 +
  23 +import java.util.List;
  24 +import java.util.UUID;
27 25
28 /** 26 /**
29 * The Interface CustomerDao. 27 * The Interface CustomerDao.
30 */ 28 */
31 -public interface CustomerDao extends Dao<CustomerEntity> { 29 +public interface CustomerDao extends Dao<Customer> {
32 30
33 /** 31 /**
34 * Save or update customer object 32 * Save or update customer object
@@ -36,7 +34,7 @@ public interface CustomerDao extends Dao<CustomerEntity> { @@ -36,7 +34,7 @@ public interface CustomerDao extends Dao<CustomerEntity> {
36 * @param customer the customer object 34 * @param customer the customer object
37 * @return saved customer object 35 * @return saved customer object
38 */ 36 */
39 - CustomerEntity save(Customer customer); 37 + Customer save(Customer customer);
40 38
41 /** 39 /**
42 * Find customers by tenant id and page link. 40 * Find customers by tenant id and page link.
@@ -45,7 +43,7 @@ public interface CustomerDao extends Dao<CustomerEntity> { @@ -45,7 +43,7 @@ public interface CustomerDao extends Dao<CustomerEntity> {
45 * @param pageLink the page link 43 * @param pageLink the page link
46 * @return the list of customer objects 44 * @return the list of customer objects
47 */ 45 */
48 - List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink); 46 + List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink);
49 47
50 /** 48 /**
51 * Find customers by tenantId and customer title. 49 * Find customers by tenantId and customer title.
@@ -54,6 +52,6 @@ public interface CustomerDao extends Dao<CustomerEntity> { @@ -54,6 +52,6 @@ public interface CustomerDao extends Dao<CustomerEntity> {
54 * @param title the customer title 52 * @param title the customer title
55 * @return the optional customer object 53 * @return the optional customer object
56 */ 54 */
57 - Optional<CustomerEntity> findCustomersByTenantIdAndTitle(UUID tenantId, String title); 55 + Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title);
58 56
59 } 57 }
@@ -27,13 +27,13 @@ public interface CustomerService { @@ -27,13 +27,13 @@ public interface CustomerService {
27 Customer findCustomerById(CustomerId customerId); 27 Customer findCustomerById(CustomerId customerId);
28 28
29 ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId); 29 ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId);
30 - 30 +
31 Customer saveCustomer(Customer customer); 31 Customer saveCustomer(Customer customer);
32 32
33 void deleteCustomer(CustomerId customerId); 33 void deleteCustomer(CustomerId customerId);
34 34
35 Customer findOrCreatePublicCustomer(TenantId tenantId); 35 Customer findOrCreatePublicCustomer(TenantId tenantId);
36 - 36 +
37 TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink); 37 TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink);
38 38
39 void deleteCustomersByTenantId(TenantId tenantId); 39 void deleteCustomersByTenantId(TenantId tenantId);
@@ -15,8 +15,6 @@ @@ -15,8 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao.customer; 16 package org.thingsboard.server.dao.customer;
17 17
18 -import static org.thingsboard.server.dao.DaoUtil.convertDataList;  
19 -import static org.thingsboard.server.dao.DaoUtil.getData;  
20 import static org.thingsboard.server.dao.service.Validator.validateId; 18 import static org.thingsboard.server.dao.service.Validator.validateId;
21 19
22 import java.io.IOException; 20 import java.io.IOException;
@@ -25,12 +23,13 @@ import java.util.Optional; @@ -25,12 +23,13 @@ import java.util.Optional;
25 23
26 import com.fasterxml.jackson.databind.JsonNode; 24 import com.fasterxml.jackson.databind.JsonNode;
27 import com.fasterxml.jackson.databind.ObjectMapper; 25 import com.fasterxml.jackson.databind.ObjectMapper;
28 -import com.google.common.base.Function;  
29 -import com.google.common.util.concurrent.Futures;  
30 import com.google.common.util.concurrent.ListenableFuture; 26 import com.google.common.util.concurrent.ListenableFuture;
31 import lombok.extern.slf4j.Slf4j; 27 import lombok.extern.slf4j.Slf4j;
32 import org.apache.commons.lang3.StringUtils; 28 import org.apache.commons.lang3.StringUtils;
  29 +import org.springframework.beans.factory.annotation.Autowired;
  30 +import org.springframework.stereotype.Service;
33 import org.thingsboard.server.common.data.Customer; 31 import org.thingsboard.server.common.data.Customer;
  32 +import org.thingsboard.server.common.data.Tenant;
34 import org.thingsboard.server.common.data.id.CustomerId; 33 import org.thingsboard.server.common.data.id.CustomerId;
35 import org.thingsboard.server.common.data.id.TenantId; 34 import org.thingsboard.server.common.data.id.TenantId;
36 import org.thingsboard.server.common.data.page.TextPageData; 35 import org.thingsboard.server.common.data.page.TextPageData;
@@ -40,15 +39,12 @@ import org.thingsboard.server.dao.device.DeviceService; @@ -40,15 +39,12 @@ import org.thingsboard.server.dao.device.DeviceService;
40 import org.thingsboard.server.dao.entity.AbstractEntityService; 39 import org.thingsboard.server.dao.entity.AbstractEntityService;
41 import org.thingsboard.server.dao.exception.DataValidationException; 40 import org.thingsboard.server.dao.exception.DataValidationException;
42 import org.thingsboard.server.dao.exception.IncorrectParameterException; 41 import org.thingsboard.server.dao.exception.IncorrectParameterException;
43 -import org.thingsboard.server.dao.model.CustomerEntity;  
44 -import org.thingsboard.server.dao.model.TenantEntity;  
45 import org.thingsboard.server.dao.service.DataValidator; 42 import org.thingsboard.server.dao.service.DataValidator;
46 import org.thingsboard.server.dao.service.PaginatedRemover; 43 import org.thingsboard.server.dao.service.PaginatedRemover;
  44 +import org.thingsboard.server.dao.service.Validator;
47 import org.thingsboard.server.dao.tenant.TenantDao; 45 import org.thingsboard.server.dao.tenant.TenantDao;
48 import org.thingsboard.server.dao.user.UserService; 46 import org.thingsboard.server.dao.user.UserService;
49 -import org.springframework.beans.factory.annotation.Autowired;  
50 -import org.springframework.stereotype.Service;  
51 -import org.thingsboard.server.dao.service.Validator; 47 +
52 @Service 48 @Service
53 @Slf4j 49 @Slf4j
54 public class CustomerServiceImpl extends AbstractEntityService implements CustomerService { 50 public class CustomerServiceImpl extends AbstractEntityService implements CustomerService {
@@ -57,41 +53,38 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -57,41 +53,38 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
57 53
58 @Autowired 54 @Autowired
59 private CustomerDao customerDao; 55 private CustomerDao customerDao;
60 - 56 +
61 @Autowired 57 @Autowired
62 private UserService userService; 58 private UserService userService;
63 - 59 +
64 @Autowired 60 @Autowired
65 private TenantDao tenantDao; 61 private TenantDao tenantDao;
66 - 62 +
67 @Autowired 63 @Autowired
68 private DeviceService deviceService; 64 private DeviceService deviceService;
69 - 65 +
70 @Autowired 66 @Autowired
71 private DashboardService dashboardService; 67 private DashboardService dashboardService;
72 - 68 +
73 @Override 69 @Override
74 public Customer findCustomerById(CustomerId customerId) { 70 public Customer findCustomerById(CustomerId customerId) {
75 log.trace("Executing findCustomerById [{}]", customerId); 71 log.trace("Executing findCustomerById [{}]", customerId);
76 Validator.validateId(customerId, "Incorrect customerId " + customerId); 72 Validator.validateId(customerId, "Incorrect customerId " + customerId);
77 - CustomerEntity customerEntity = customerDao.findById(customerId.getId());  
78 - return getData(customerEntity); 73 + return customerDao.findById(customerId.getId());
79 } 74 }
80 75
81 @Override 76 @Override
82 public ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId) { 77 public ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId) {
83 log.trace("Executing findCustomerByIdAsync [{}]", customerId); 78 log.trace("Executing findCustomerByIdAsync [{}]", customerId);
84 validateId(customerId, "Incorrect customerId " + customerId); 79 validateId(customerId, "Incorrect customerId " + customerId);
85 - ListenableFuture<CustomerEntity> customerEntity = customerDao.findByIdAsync(customerId.getId());  
86 - return Futures.transform(customerEntity, (Function<? super CustomerEntity, ? extends Customer>) input -> getData(input)); 80 + return customerDao.findByIdAsync(customerId.getId());
87 } 81 }
88 82
89 @Override 83 @Override
90 public Customer saveCustomer(Customer customer) { 84 public Customer saveCustomer(Customer customer) {
91 log.trace("Executing saveCustomer [{}]", customer); 85 log.trace("Executing saveCustomer [{}]", customer);
92 customerValidator.validate(customer); 86 customerValidator.validate(customer);
93 - CustomerEntity customerEntity = customerDao.save(customer);  
94 - return getData(customerEntity); 87 + return customerDao.save(customer);
95 } 88 }
96 89
97 @Override 90 @Override
@@ -113,9 +106,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -113,9 +106,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
113 public Customer findOrCreatePublicCustomer(TenantId tenantId) { 106 public Customer findOrCreatePublicCustomer(TenantId tenantId) {
114 log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId); 107 log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
115 Validator.validateId(tenantId, "Incorrect customerId " + tenantId); 108 Validator.validateId(tenantId, "Incorrect customerId " + tenantId);
116 - Optional<CustomerEntity> publicCustomerEntity = customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);  
117 - if (publicCustomerEntity.isPresent()) {  
118 - return getData(publicCustomerEntity.get()); 109 + Optional<Customer> publicCustomerOpt = customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);
  110 + if (publicCustomerOpt.isPresent()) {
  111 + return publicCustomerOpt.get();
119 } else { 112 } else {
120 Customer publicCustomer = new Customer(); 113 Customer publicCustomer = new Customer();
121 publicCustomer.setTenantId(tenantId); 114 publicCustomer.setTenantId(tenantId);
@@ -125,8 +118,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -125,8 +118,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
125 } catch (IOException e) { 118 } catch (IOException e) {
126 throw new IncorrectParameterException("Unable to create public customer.", e); 119 throw new IncorrectParameterException("Unable to create public customer.", e);
127 } 120 }
128 - CustomerEntity customerEntity = customerDao.save(publicCustomer);  
129 - return getData(customerEntity); 121 + return customerDao.save(publicCustomer);
130 } 122 }
131 } 123 }
132 124
@@ -135,18 +127,17 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -135,18 +127,17 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
135 log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); 127 log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
136 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 128 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
137 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); 129 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
138 - List<CustomerEntity> customerEntities = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink);  
139 - List<Customer> customers = convertDataList(customerEntities);  
140 - return new TextPageData<Customer>(customers, pageLink); 130 + List<Customer> customers = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink);
  131 + return new TextPageData<>(customers, pageLink);
141 } 132 }
142 133
143 @Override 134 @Override
144 public void deleteCustomersByTenantId(TenantId tenantId) { 135 public void deleteCustomersByTenantId(TenantId tenantId) {
145 log.trace("Executing deleteCustomersByTenantId, tenantId [{}]", tenantId); 136 log.trace("Executing deleteCustomersByTenantId, tenantId [{}]", tenantId);
146 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
147 - customersByTenantRemover.removeEntitites(tenantId); 138 + customersByTenantRemover.removeEntities(tenantId);
148 } 139 }
149 - 140 +
150 private DataValidator<Customer> customerValidator = 141 private DataValidator<Customer> customerValidator =
151 new DataValidator<Customer>() { 142 new DataValidator<Customer>() {
152 143
@@ -184,25 +175,25 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom @@ -184,25 +175,25 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
184 if (customer.getTenantId() == null) { 175 if (customer.getTenantId() == null) {
185 throw new DataValidationException("Customer should be assigned to tenant!"); 176 throw new DataValidationException("Customer should be assigned to tenant!");
186 } else { 177 } else {
187 - TenantEntity tenant = tenantDao.findById(customer.getTenantId().getId()); 178 + Tenant tenant = tenantDao.findById(customer.getTenantId().getId());
188 if (tenant == null) { 179 if (tenant == null) {
189 throw new DataValidationException("Customer is referencing to non-existent tenant!"); 180 throw new DataValidationException("Customer is referencing to non-existent tenant!");
190 } 181 }
191 } 182 }
192 } 183 }
193 - };  
194 -  
195 - private PaginatedRemover<TenantId, CustomerEntity> customersByTenantRemover =  
196 - new PaginatedRemover<TenantId, CustomerEntity>() {  
197 -  
198 - @Override  
199 - protected List<CustomerEntity> findEntities(TenantId id, TextPageLink pageLink) {  
200 - return customerDao.findCustomersByTenantId(id.getId(), pageLink);  
201 - } 184 + };
202 185
203 - @Override  
204 - protected void removeEntity(CustomerEntity entity) {  
205 - deleteCustomer(new CustomerId(entity.getId()));  
206 - }  
207 - }; 186 + private PaginatedRemover<TenantId, Customer> customersByTenantRemover =
  187 + new PaginatedRemover<TenantId, Customer>() {
  188 +
  189 + @Override
  190 + protected List<Customer> findEntities(TenantId id, TextPageLink pageLink) {
  191 + return customerDao.findCustomersByTenantId(id.getId(), pageLink);
  192 + }
  193 +
  194 + @Override
  195 + protected void removeEntity(Customer entity) {
  196 + deleteCustomer(new CustomerId(entity.getUuidId()));
  197 + }
  198 + };
208 } 199 }
dao/src/main/java/org/thingsboard/server/dao/dashboard/CassandraDashboardDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDaoImpl.java
@@ -15,31 +15,17 @@ @@ -15,31 +15,17 @@
15 */ 15 */
16 package org.thingsboard.server.dao.dashboard; 16 package org.thingsboard.server.dao.dashboard;
17 17
18 -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;  
19 -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME;  
20 -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME;  
21 -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME;  
22 -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY;  
23 -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY;  
24 -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;  
25 -  
26 -import java.util.Arrays;  
27 -import java.util.List;  
28 -import java.util.UUID;  
29 -  
30 -import lombok.extern.slf4j.Slf4j;  
31 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
32 import org.thingsboard.server.common.data.Dashboard; 19 import org.thingsboard.server.common.data.Dashboard;
33 -import org.thingsboard.server.common.data.page.TextPageLink;  
34 -import org.thingsboard.server.dao.AbstractSearchTextDao;  
35 -import org.thingsboard.server.dao.model.DashboardEntity;  
36 -import org.slf4j.Logger;  
37 -import org.slf4j.LoggerFactory;  
38 -import org.thingsboard.server.dao.model.DashboardInfoEntity; 20 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  21 +import org.thingsboard.server.dao.util.NoSqlDao;
  22 +import org.thingsboard.server.dao.model.nosql.DashboardEntity;
  23 +
  24 +import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME;
39 25
40 @Component 26 @Component
41 -@Slf4j  
42 -public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> implements DashboardDao { 27 +@NoSqlDao
  28 +public class CassandraDashboardDao extends CassandraAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao {
43 29
44 @Override 30 @Override
45 protected Class<DashboardEntity> getColumnFamilyClass() { 31 protected Class<DashboardEntity> getColumnFamilyClass() {
@@ -50,11 +36,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp @@ -50,11 +36,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp
50 protected String getColumnFamilyName() { 36 protected String getColumnFamilyName() {
51 return DASHBOARD_COLUMN_FAMILY_NAME; 37 return DASHBOARD_COLUMN_FAMILY_NAME;
52 } 38 }
53 -  
54 - @Override  
55 - public DashboardEntity save(Dashboard dashboard) {  
56 - log.debug("Save dashboard [{}] ", dashboard);  
57 - return save(new DashboardEntity(dashboard));  
58 - }  
59 -  
60 } 39 }
dao/src/main/java/org/thingsboard/server/dao/dashboard/CassandraDashboardInfoDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardInfoDaoImpl.java
@@ -17,9 +17,12 @@ package org.thingsboard.server.dao.dashboard; @@ -17,9 +17,12 @@ package org.thingsboard.server.dao.dashboard;
17 17
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
  20 +import org.thingsboard.server.common.data.DashboardInfo;
20 import org.thingsboard.server.common.data.page.TextPageLink; 21 import org.thingsboard.server.common.data.page.TextPageLink;
21 -import org.thingsboard.server.dao.AbstractSearchTextDao;  
22 -import org.thingsboard.server.dao.model.DashboardInfoEntity; 22 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  23 +import org.thingsboard.server.dao.DaoUtil;
  24 +import org.thingsboard.server.dao.util.NoSqlDao;
  25 +import org.thingsboard.server.dao.model.nosql.DashboardInfoEntity;
23 26
24 import java.util.Arrays; 27 import java.util.Arrays;
25 import java.util.Collections; 28 import java.util.Collections;
@@ -31,7 +34,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; @@ -31,7 +34,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
31 34
32 @Component 35 @Component
33 @Slf4j 36 @Slf4j
34 -public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEntity> implements DashboardInfoDao { 37 +@NoSqlDao
  38 +public class CassandraDashboardInfoDao extends CassandraAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao {
35 39
36 @Override 40 @Override
37 protected Class<DashboardInfoEntity> getColumnFamilyClass() { 41 protected Class<DashboardInfoEntity> getColumnFamilyClass() {
@@ -44,18 +48,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt @@ -44,18 +48,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt
44 } 48 }
45 49
46 @Override 50 @Override
47 - public List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { 51 + public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) {
48 log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink); 52 log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
49 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 53 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
50 Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)), 54 Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)),
51 pageLink); 55 pageLink);
52 56
53 log.trace("Found dashboards [{}] by tenantId [{}] and pageLink [{}]", dashboardEntities, tenantId, pageLink); 57 log.trace("Found dashboards [{}] by tenantId [{}] and pageLink [{}]", dashboardEntities, tenantId, pageLink);
54 - return dashboardEntities; 58 + return DaoUtil.convertDataList(dashboardEntities);
55 } 59 }
56 60
57 @Override 61 @Override
58 - public List<DashboardInfoEntity> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { 62 + public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
59 log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); 63 log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
60 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 64 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
61 Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId), 65 Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId),
@@ -63,7 +67,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt @@ -63,7 +67,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt
63 pageLink); 67 pageLink);
64 68
65 log.trace("Found dashboards [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", dashboardEntities, tenantId, customerId, pageLink); 69 log.trace("Found dashboards [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", dashboardEntities, tenantId, customerId, pageLink);
66 - return dashboardEntities; 70 + return DaoUtil.convertDataList(dashboardEntities);
67 } 71 }
68 72
69 } 73 }
@@ -15,21 +15,13 @@ @@ -15,21 +15,13 @@
15 */ 15 */
16 package org.thingsboard.server.dao.dashboard; 16 package org.thingsboard.server.dao.dashboard;
17 17
18 -import java.util.List;  
19 -import java.util.UUID;  
20 -  
21 import org.thingsboard.server.common.data.Dashboard; 18 import org.thingsboard.server.common.data.Dashboard;
22 -import org.thingsboard.server.common.data.page.TextPageLink;  
23 import org.thingsboard.server.dao.Dao; 19 import org.thingsboard.server.dao.Dao;
24 -import org.thingsboard.server.dao.model.DashboardEntity;  
25 -import org.thingsboard.server.dao.model.DashboardInfoEntity;  
26 20
27 /** 21 /**
28 * The Interface DashboardDao. 22 * The Interface DashboardDao.
29 - *  
30 - * @param <T> the generic type  
31 */ 23 */
32 -public interface DashboardDao extends Dao<DashboardEntity> { 24 +public interface DashboardDao extends Dao<Dashboard> {
33 25
34 /** 26 /**
35 * Save or update dashboard object 27 * Save or update dashboard object
@@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> { @@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> {
37 * @param dashboard the dashboard object 29 * @param dashboard the dashboard object
38 * @return saved dashboard object 30 * @return saved dashboard object
39 */ 31 */
40 - DashboardEntity save(Dashboard dashboard); 32 + Dashboard save(Dashboard dashboard);
41 33
42 } 34 }
@@ -15,21 +15,17 @@ @@ -15,21 +15,17 @@
15 */ 15 */
16 package org.thingsboard.server.dao.dashboard; 16 package org.thingsboard.server.dao.dashboard;
17 17
18 -import java.util.List;  
19 -import java.util.UUID;  
20 -  
21 -import org.thingsboard.server.common.data.Dashboard; 18 +import org.thingsboard.server.common.data.DashboardInfo;
22 import org.thingsboard.server.common.data.page.TextPageLink; 19 import org.thingsboard.server.common.data.page.TextPageLink;
23 import org.thingsboard.server.dao.Dao; 20 import org.thingsboard.server.dao.Dao;
24 -import org.thingsboard.server.dao.model.DashboardEntity;  
25 -import org.thingsboard.server.dao.model.DashboardInfoEntity; 21 +
  22 +import java.util.List;
  23 +import java.util.UUID;
26 24
27 /** 25 /**
28 * The Interface DashboardInfoDao. 26 * The Interface DashboardInfoDao.
29 - *  
30 - * @param <T> the generic type  
31 */ 27 */
32 -public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { 28 +public interface DashboardInfoDao extends Dao<DashboardInfo> {
33 29
34 /** 30 /**
35 * Find dashboards by tenantId and page link. 31 * Find dashboards by tenantId and page link.
@@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { @@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
38 * @param pageLink the page link 34 * @param pageLink the page link
39 * @return the list of dashboard objects 35 * @return the list of dashboard objects
40 */ 36 */
41 - List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink); 37 + List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink);
42 38
43 /** 39 /**
44 * Find dashboards by tenantId, customerId and page link. 40 * Find dashboards by tenantId, customerId and page link.
@@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { @@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
48 * @param pageLink the page link 44 * @param pageLink the page link
49 * @return the list of dashboard objects 45 * @return the list of dashboard objects
50 */ 46 */
51 - List<DashboardInfoEntity> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); 47 + List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
52 48
53 } 49 }
@@ -26,28 +26,28 @@ import org.thingsboard.server.common.data.page.TextPageLink; @@ -26,28 +26,28 @@ import org.thingsboard.server.common.data.page.TextPageLink;
26 26
27 public interface DashboardService { 27 public interface DashboardService {
28 28
29 - public Dashboard findDashboardById(DashboardId dashboardId); 29 + Dashboard findDashboardById(DashboardId dashboardId);
30 30
31 - public ListenableFuture<Dashboard> findDashboardByIdAsync(DashboardId dashboardId); 31 + ListenableFuture<Dashboard> findDashboardByIdAsync(DashboardId dashboardId);
32 32
33 - public DashboardInfo findDashboardInfoById(DashboardId dashboardId); 33 + DashboardInfo findDashboardInfoById(DashboardId dashboardId);
34 34
35 - public ListenableFuture<DashboardInfo> findDashboardInfoByIdAsync(DashboardId dashboardId); 35 + ListenableFuture<DashboardInfo> findDashboardInfoByIdAsync(DashboardId dashboardId);
36 36
37 - public Dashboard saveDashboard(Dashboard dashboard);  
38 -  
39 - public Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId); 37 + Dashboard saveDashboard(Dashboard dashboard);
40 38
41 - public Dashboard unassignDashboardFromCustomer(DashboardId dashboardId); 39 + Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId);
42 40
43 - public void deleteDashboard(DashboardId dashboardId);  
44 -  
45 - public TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink); 41 + Dashboard unassignDashboardFromCustomer(DashboardId dashboardId);
46 42
47 - public void deleteDashboardsByTenantId(TenantId tenantId);  
48 -  
49 - public TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink); 43 + void deleteDashboard(DashboardId dashboardId);
  44 +
  45 + TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink);
  46 +
  47 + void deleteDashboardsByTenantId(TenantId tenantId);
  48 +
  49 + TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink);
  50 +
  51 + void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId);
50 52
51 - public void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId);  
52 -  
53 } 53 }
@@ -15,19 +15,15 @@ @@ -15,19 +15,15 @@
15 */ 15 */
16 package org.thingsboard.server.dao.dashboard; 16 package org.thingsboard.server.dao.dashboard;
17 17
18 -import static org.thingsboard.server.dao.DaoUtil.convertDataList;  
19 -import static org.thingsboard.server.dao.DaoUtil.getData;  
20 -import static org.thingsboard.server.dao.service.Validator.validateId;  
21 -  
22 -import java.util.List;  
23 -  
24 -import com.google.common.base.Function;  
25 -import com.google.common.util.concurrent.Futures;  
26 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
27 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
28 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.stereotype.Service;
  23 +import org.thingsboard.server.common.data.Customer;
29 import org.thingsboard.server.common.data.Dashboard; 24 import org.thingsboard.server.common.data.Dashboard;
30 import org.thingsboard.server.common.data.DashboardInfo; 25 import org.thingsboard.server.common.data.DashboardInfo;
  26 +import org.thingsboard.server.common.data.Tenant;
31 import org.thingsboard.server.common.data.id.CustomerId; 27 import org.thingsboard.server.common.data.id.CustomerId;
32 import org.thingsboard.server.common.data.id.DashboardId; 28 import org.thingsboard.server.common.data.id.DashboardId;
33 import org.thingsboard.server.common.data.id.TenantId; 29 import org.thingsboard.server.common.data.id.TenantId;
@@ -36,13 +32,15 @@ import org.thingsboard.server.common.data.page.TextPageLink; @@ -36,13 +32,15 @@ import org.thingsboard.server.common.data.page.TextPageLink;
36 import org.thingsboard.server.dao.customer.CustomerDao; 32 import org.thingsboard.server.dao.customer.CustomerDao;
37 import org.thingsboard.server.dao.entity.AbstractEntityService; 33 import org.thingsboard.server.dao.entity.AbstractEntityService;
38 import org.thingsboard.server.dao.exception.DataValidationException; 34 import org.thingsboard.server.dao.exception.DataValidationException;
39 -import org.thingsboard.server.dao.model.*; 35 +import org.thingsboard.server.dao.model.ModelConstants;
40 import org.thingsboard.server.dao.service.DataValidator; 36 import org.thingsboard.server.dao.service.DataValidator;
41 import org.thingsboard.server.dao.service.PaginatedRemover; 37 import org.thingsboard.server.dao.service.PaginatedRemover;
42 -import org.thingsboard.server.dao.tenant.TenantDao;  
43 -import org.springframework.beans.factory.annotation.Autowired;  
44 -import org.springframework.stereotype.Service;  
45 import org.thingsboard.server.dao.service.Validator; 38 import org.thingsboard.server.dao.service.Validator;
  39 +import org.thingsboard.server.dao.tenant.TenantDao;
  40 +
  41 +import java.util.List;
  42 +
  43 +import static org.thingsboard.server.dao.service.Validator.validateId;
46 44
47 @Service 45 @Service
48 @Slf4j 46 @Slf4j
@@ -64,40 +62,35 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -64,40 +62,35 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
64 public Dashboard findDashboardById(DashboardId dashboardId) { 62 public Dashboard findDashboardById(DashboardId dashboardId) {
65 log.trace("Executing findDashboardById [{}]", dashboardId); 63 log.trace("Executing findDashboardById [{}]", dashboardId);
66 Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId); 64 Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
67 - DashboardEntity dashboardEntity = dashboardDao.findById(dashboardId.getId());  
68 - return getData(dashboardEntity); 65 + return dashboardDao.findById(dashboardId.getId());
69 } 66 }
70 67
71 @Override 68 @Override
72 public ListenableFuture<Dashboard> findDashboardByIdAsync(DashboardId dashboardId) { 69 public ListenableFuture<Dashboard> findDashboardByIdAsync(DashboardId dashboardId) {
73 log.trace("Executing findDashboardByIdAsync [{}]", dashboardId); 70 log.trace("Executing findDashboardByIdAsync [{}]", dashboardId);
74 validateId(dashboardId, "Incorrect dashboardId " + dashboardId); 71 validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
75 - ListenableFuture<DashboardEntity> dashboardEntity = dashboardDao.findByIdAsync(dashboardId.getId());  
76 - return Futures.transform(dashboardEntity, (Function<? super DashboardEntity, ? extends Dashboard>) input -> getData(input)); 72 + return dashboardDao.findByIdAsync(dashboardId.getId());
77 } 73 }
78 74
79 @Override 75 @Override
80 public DashboardInfo findDashboardInfoById(DashboardId dashboardId) { 76 public DashboardInfo findDashboardInfoById(DashboardId dashboardId) {
81 log.trace("Executing findDashboardInfoById [{}]", dashboardId); 77 log.trace("Executing findDashboardInfoById [{}]", dashboardId);
82 Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId); 78 Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
83 - DashboardInfoEntity dashboardInfoEntity = dashboardInfoDao.findById(dashboardId.getId());  
84 - return getData(dashboardInfoEntity); 79 + return dashboardInfoDao.findById(dashboardId.getId());
85 } 80 }
86 81
87 @Override 82 @Override
88 public ListenableFuture<DashboardInfo> findDashboardInfoByIdAsync(DashboardId dashboardId) { 83 public ListenableFuture<DashboardInfo> findDashboardInfoByIdAsync(DashboardId dashboardId) {
89 log.trace("Executing findDashboardInfoByIdAsync [{}]", dashboardId); 84 log.trace("Executing findDashboardInfoByIdAsync [{}]", dashboardId);
90 validateId(dashboardId, "Incorrect dashboardId " + dashboardId); 85 validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
91 - ListenableFuture<DashboardInfoEntity> dashboardInfoEntity = dashboardInfoDao.findByIdAsync(dashboardId.getId());  
92 - return Futures.transform(dashboardInfoEntity, (Function<? super DashboardInfoEntity, ? extends DashboardInfo>) input -> getData(input)); 86 + return dashboardInfoDao.findByIdAsync(dashboardId.getId());
93 } 87 }
94 88
95 @Override 89 @Override
96 public Dashboard saveDashboard(Dashboard dashboard) { 90 public Dashboard saveDashboard(Dashboard dashboard) {
97 log.trace("Executing saveDashboard [{}]", dashboard); 91 log.trace("Executing saveDashboard [{}]", dashboard);
98 dashboardValidator.validate(dashboard); 92 dashboardValidator.validate(dashboard);
99 - DashboardEntity dashboardEntity = dashboardDao.save(dashboard);  
100 - return getData(dashboardEntity); 93 + return dashboardDao.save(dashboard);
101 } 94 }
102 95
103 @Override 96 @Override
@@ -127,16 +120,15 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -127,16 +120,15 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
127 log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); 120 log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
128 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 121 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
129 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); 122 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
130 - List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink);  
131 - List<DashboardInfo> dashboards = convertDataList(dashboardEntities);  
132 - return new TextPageData<DashboardInfo>(dashboards, pageLink); 123 + List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink);
  124 + return new TextPageData<>(dashboards, pageLink);
133 } 125 }
134 126
135 @Override 127 @Override
136 public void deleteDashboardsByTenantId(TenantId tenantId) { 128 public void deleteDashboardsByTenantId(TenantId tenantId) {
137 log.trace("Executing deleteDashboardsByTenantId, tenantId [{}]", tenantId); 129 log.trace("Executing deleteDashboardsByTenantId, tenantId [{}]", tenantId);
138 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 130 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
139 - tenantDashboardsRemover.removeEntitites(tenantId); 131 + tenantDashboardsRemover.removeEntities(tenantId);
140 } 132 }
141 133
142 @Override 134 @Override
@@ -145,9 +137,8 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -145,9 +137,8 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
145 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
146 Validator.validateId(customerId, "Incorrect customerId " + customerId); 138 Validator.validateId(customerId, "Incorrect customerId " + customerId);
147 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); 139 Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
148 - List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);  
149 - List<DashboardInfo> dashboards = convertDataList(dashboardEntities);  
150 - return new TextPageData<DashboardInfo>(dashboards, pageLink); 140 + List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
  141 + return new TextPageData<>(dashboards, pageLink);
151 } 142 }
152 143
153 @Override 144 @Override
@@ -155,7 +146,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -155,7 +146,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
155 log.trace("Executing unassignCustomerDashboards, tenantId [{}], customerId [{}]", tenantId, customerId); 146 log.trace("Executing unassignCustomerDashboards, tenantId [{}], customerId [{}]", tenantId, customerId);
156 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); 147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
157 Validator.validateId(customerId, "Incorrect customerId " + customerId); 148 Validator.validateId(customerId, "Incorrect customerId " + customerId);
158 - new CustomerDashboardsUnassigner(tenantId).removeEntitites(customerId); 149 + new CustomerDashboardsUnassigner(tenantId).removeEntities(customerId);
159 } 150 }
160 151
161 private DataValidator<Dashboard> dashboardValidator = 152 private DataValidator<Dashboard> dashboardValidator =
@@ -168,7 +159,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -168,7 +159,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
168 if (dashboard.getTenantId() == null) { 159 if (dashboard.getTenantId() == null) {
169 throw new DataValidationException("Dashboard should be assigned to tenant!"); 160 throw new DataValidationException("Dashboard should be assigned to tenant!");
170 } else { 161 } else {
171 - TenantEntity tenant = tenantDao.findById(dashboard.getTenantId().getId()); 162 + Tenant tenant = tenantDao.findById(dashboard.getTenantId().getId());
172 if (tenant == null) { 163 if (tenant == null) {
173 throw new DataValidationException("Dashboard is referencing to non-existent tenant!"); 164 throw new DataValidationException("Dashboard is referencing to non-existent tenant!");
174 } 165 }
@@ -176,32 +167,32 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -176,32 +167,32 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
176 if (dashboard.getCustomerId() == null) { 167 if (dashboard.getCustomerId() == null) {
177 dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID)); 168 dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID));
178 } else if (!dashboard.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) { 169 } else if (!dashboard.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
179 - CustomerEntity customer = customerDao.findById(dashboard.getCustomerId().getId()); 170 + Customer customer = customerDao.findById(dashboard.getCustomerId().getId());
180 if (customer == null) { 171 if (customer == null) {
181 throw new DataValidationException("Can't assign dashboard to non-existent customer!"); 172 throw new DataValidationException("Can't assign dashboard to non-existent customer!");
182 } 173 }
183 - if (!customer.getTenantId().equals(dashboard.getTenantId().getId())) { 174 + if (!customer.getTenantId().getId().equals(dashboard.getTenantId().getId())) {
184 throw new DataValidationException("Can't assign dashboard to customer from different tenant!"); 175 throw new DataValidationException("Can't assign dashboard to customer from different tenant!");
185 } 176 }
186 } 177 }
187 } 178 }
188 }; 179 };
189 180
190 - private PaginatedRemover<TenantId, DashboardInfoEntity> tenantDashboardsRemover =  
191 - new PaginatedRemover<TenantId, DashboardInfoEntity>() { 181 + private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover =
  182 + new PaginatedRemover<TenantId, DashboardInfo>() {
192 183
193 @Override 184 @Override
194 - protected List<DashboardInfoEntity> findEntities(TenantId id, TextPageLink pageLink) { 185 + protected List<DashboardInfo> findEntities(TenantId id, TextPageLink pageLink) {
195 return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink); 186 return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
196 } 187 }
197 188
198 @Override 189 @Override
199 - protected void removeEntity(DashboardInfoEntity entity) {  
200 - deleteDashboard(new DashboardId(entity.getId())); 190 + protected void removeEntity(DashboardInfo entity) {
  191 + deleteDashboard(new DashboardId(entity.getUuidId()));
201 } 192 }
202 }; 193 };
203 194
204 - class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfoEntity> { 195 + private class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfo> {
205 196
206 private TenantId tenantId; 197 private TenantId tenantId;
207 198
@@ -210,13 +201,13 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -210,13 +201,13 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
210 } 201 }
211 202
212 @Override 203 @Override
213 - protected List<DashboardInfoEntity> findEntities(CustomerId id, TextPageLink pageLink) { 204 + protected List<DashboardInfo> findEntities(CustomerId id, TextPageLink pageLink) {
214 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); 205 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
215 } 206 }
216 207
217 @Override 208 @Override
218 - protected void removeEntity(DashboardInfoEntity entity) {  
219 - unassignDashboardFromCustomer(new DashboardId(entity.getId())); 209 + protected void removeEntity(DashboardInfo entity) {
  210 + unassignDashboardFromCustomer(new DashboardId(entity.getUuidId()));
220 } 211 }
221 212
222 } 213 }
dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceCredentialsDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsDaoImpl.java
@@ -15,26 +15,25 @@ @@ -15,26 +15,25 @@
15 */ 15 */
16 package org.thingsboard.server.dao.device; 16 package org.thingsboard.server.dao.device;
17 17
18 -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;  
19 -import static com.datastax.driver.core.querybuilder.QueryBuilder.select;  
20 -  
21 -import java.util.UUID;  
22 - 18 +import com.datastax.driver.core.querybuilder.Select.Where;
23 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
24 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
25 import org.thingsboard.server.common.data.security.DeviceCredentials; 21 import org.thingsboard.server.common.data.security.DeviceCredentials;
26 -import org.thingsboard.server.dao.AbstractModelDao;  
27 -import org.thingsboard.server.dao.model.DeviceCredentialsEntity;  
28 -import org.slf4j.Logger;  
29 -import org.slf4j.LoggerFactory;  
30 -import org.springframework.stereotype.Repository;  
31 -  
32 -import com.datastax.driver.core.querybuilder.Select.Where; 22 +import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao;
  23 +import org.thingsboard.server.dao.DaoUtil;
  24 +import org.thingsboard.server.dao.util.NoSqlDao;
33 import org.thingsboard.server.dao.model.ModelConstants; 25 import org.thingsboard.server.dao.model.ModelConstants;
  26 +import org.thingsboard.server.dao.model.nosql.DeviceCredentialsEntity;
  27 +
  28 +import java.util.UUID;
  29 +
  30 +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
  31 +import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
34 32
35 @Component 33 @Component
36 @Slf4j 34 @Slf4j
37 -public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentialsEntity> implements DeviceCredentialsDao { 35 +@NoSqlDao
  36 +public class CassandraDeviceCredentialsDao extends CassandraAbstractModelDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao {
38 37
39 @Override 38 @Override
40 protected Class<DeviceCredentialsEntity> getColumnFamilyClass() { 39 protected Class<DeviceCredentialsEntity> getColumnFamilyClass() {
@@ -47,31 +46,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials @@ -47,31 +46,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials
47 } 46 }
48 47
49 @Override 48 @Override
50 - public DeviceCredentialsEntity findByDeviceId(UUID deviceId) { 49 + public DeviceCredentials findByDeviceId(UUID deviceId) {
51 log.debug("Try to find device credentials by deviceId [{}] ", deviceId); 50 log.debug("Try to find device credentials by deviceId [{}] ", deviceId);
52 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME) 51 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME)
53 .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId)); 52 .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId));
54 log.trace("Execute query {}", query); 53 log.trace("Execute query {}", query);
55 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); 54 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query);
56 log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId); 55 log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId);
57 - return deviceCredentialsEntity; 56 + return DaoUtil.getData(deviceCredentialsEntity);
58 } 57 }
59 58
60 @Override 59 @Override
61 - public DeviceCredentialsEntity findByCredentialsId(String credentialsId) { 60 + public DeviceCredentials findByCredentialsId(String credentialsId) {
62 log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId); 61 log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId);
63 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME) 62 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME)
64 .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId)); 63 .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId));
65 log.trace("Execute query {}", query); 64 log.trace("Execute query {}", query);
66 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); 65 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query);
67 log.trace("Found device credentials [{}] by credentialsId [{}]", deviceCredentialsEntity, credentialsId); 66 log.trace("Found device credentials [{}] by credentialsId [{}]", deviceCredentialsEntity, credentialsId);
68 - return deviceCredentialsEntity; 67 + return DaoUtil.getData(deviceCredentialsEntity);
69 } 68 }
70 -  
71 - @Override  
72 - public DeviceCredentialsEntity save(DeviceCredentials deviceCredentials) {  
73 - log.debug("Save device credentials [{}] ", deviceCredentials);  
74 - return save(new DeviceCredentialsEntity(deviceCredentials));  
75 - }  
76 -  
77 } 69 }
dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/device/DeviceDaoImpl.java
@@ -15,13 +15,6 @@ @@ -15,13 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao.device; 16 package org.thingsboard.server.dao.device;
17 17
18 -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;  
19 -import static com.datastax.driver.core.querybuilder.QueryBuilder.in;  
20 -import static com.datastax.driver.core.querybuilder.QueryBuilder.select;  
21 -import static org.thingsboard.server.dao.model.ModelConstants.*;  
22 -  
23 -import java.util.*;  
24 -  
25 import com.datastax.driver.core.ResultSet; 18 import com.datastax.driver.core.ResultSet;
26 import com.datastax.driver.core.ResultSetFuture; 19 import com.datastax.driver.core.ResultSetFuture;
27 import com.datastax.driver.core.querybuilder.Select; 20 import com.datastax.driver.core.querybuilder.Select;
@@ -32,18 +25,24 @@ import com.google.common.util.concurrent.ListenableFuture; @@ -32,18 +25,24 @@ import com.google.common.util.concurrent.ListenableFuture;
32 import lombok.extern.slf4j.Slf4j; 25 import lombok.extern.slf4j.Slf4j;
33 import org.springframework.stereotype.Component; 26 import org.springframework.stereotype.Component;
34 import org.thingsboard.server.common.data.Device; 27 import org.thingsboard.server.common.data.Device;
  28 +import org.thingsboard.server.common.data.TenantDeviceType;
35 import org.thingsboard.server.common.data.page.TextPageLink; 29 import org.thingsboard.server.common.data.page.TextPageLink;
36 -import org.thingsboard.server.dao.AbstractSearchTextDao;  
37 -import org.thingsboard.server.dao.model.DeviceEntity;  
38 -import org.slf4j.Logger;  
39 -import org.slf4j.LoggerFactory; 30 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao;
  31 +import org.thingsboard.server.dao.DaoUtil;
  32 +import org.thingsboard.server.dao.util.NoSqlDao;
40 import org.thingsboard.server.dao.model.TenantDeviceTypeEntity; 33 import org.thingsboard.server.dao.model.TenantDeviceTypeEntity;
  34 +import org.thingsboard.server.dao.model.nosql.DeviceEntity;
41 35
42 import javax.annotation.Nullable; 36 import javax.annotation.Nullable;
  37 +import java.util.*;
  38 +
  39 +import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
  40 +import static org.thingsboard.server.dao.model.ModelConstants.*;
43 41
44 @Component 42 @Component
45 @Slf4j 43 @Slf4j
46 -public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implements DeviceDao { 44 +@NoSqlDao
  45 +public class CassandraDeviceDao extends CassandraAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao {
47 46
48 @Override 47 @Override
49 protected Class<DeviceEntity> getColumnFamilyClass() { 48 protected Class<DeviceEntity> getColumnFamilyClass() {
@@ -56,33 +55,27 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement @@ -56,33 +55,27 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
56 } 55 }
57 56
58 @Override 57 @Override
59 - public DeviceEntity save(Device device) {  
60 - log.debug("Save device [{}] ", device);  
61 - return save(new DeviceEntity(device));  
62 - }  
63 -  
64 - @Override  
65 - public List<DeviceEntity> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { 58 + public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) {
66 log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink); 59 log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
67 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 60 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
68 Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); 61 Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink);
69 62
70 log.trace("Found devices [{}] by tenantId [{}] and pageLink [{}]", deviceEntities, tenantId, pageLink); 63 log.trace("Found devices [{}] by tenantId [{}] and pageLink [{}]", deviceEntities, tenantId, pageLink);
71 - return deviceEntities; 64 + return DaoUtil.convertDataList(deviceEntities);
72 } 65 }
73 66
74 @Override 67 @Override
75 - public List<DeviceEntity> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { 68 + public List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) {
76 log.debug("Try to find devices by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink); 69 log.debug("Try to find devices by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink);
77 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 70 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
78 Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type), 71 Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type),
79 - eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); 72 + eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink);
80 log.trace("Found devices [{}] by tenantId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, type, pageLink); 73 log.trace("Found devices [{}] by tenantId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, type, pageLink);
81 - return deviceEntities; 74 + return DaoUtil.convertDataList(deviceEntities);
82 } 75 }
83 76
84 @Override 77 @Override
85 - public ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { 78 + public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) {
86 log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds); 79 log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds);
87 Select select = select().from(getColumnFamilyName()); 80 Select select = select().from(getColumnFamilyName());
88 Select.Where query = select.where(); 81 Select.Where query = select.where();
@@ -92,32 +85,32 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement @@ -92,32 +85,32 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
92 } 85 }
93 86
94 @Override 87 @Override
95 - public List<DeviceEntity> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {  
96 - log.debug("Try to find devices by tenantId [{}], customerId [{}] and pageLink [{}]", tenantId, customerId, pageLink); 88 + public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
  89 + log.debug("Try to find devices by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
97 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 90 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
98 Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), 91 Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId),
99 eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), 92 eq(DEVICE_TENANT_ID_PROPERTY, tenantId)),
100 pageLink); 93 pageLink);
101 94
102 log.trace("Found devices [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, pageLink); 95 log.trace("Found devices [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, pageLink);
103 - return deviceEntities; 96 + return DaoUtil.convertDataList(deviceEntities);
104 } 97 }
105 98
106 @Override 99 @Override
107 - public List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { 100 + public List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) {
108 log.debug("Try to find devices by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink); 101 log.debug("Try to find devices by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink);
109 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, 102 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
110 Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type), 103 Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type),
111 - eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId),  
112 - eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), 104 + eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId),
  105 + eq(DEVICE_TENANT_ID_PROPERTY, tenantId)),
113 pageLink); 106 pageLink);
114 107
115 log.trace("Found devices [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, type, pageLink); 108 log.trace("Found devices [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, type, pageLink);
116 - return deviceEntities; 109 + return DaoUtil.convertDataList(deviceEntities);
117 } 110 }
118 111
119 @Override 112 @Override
120 - public ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { 113 + public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) {
121 log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds); 114 log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds);
122 Select select = select().from(getColumnFamilyName()); 115 Select select = select().from(getColumnFamilyName());
123 Select.Where query = select.where(); 116 Select.Where query = select.where();
@@ -128,16 +121,16 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement @@ -128,16 +121,16 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
128 } 121 }
129 122
130 @Override 123 @Override
131 - public Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) { 124 + public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String deviceName) {
132 Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME); 125 Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME);
133 Select.Where query = select.where(); 126 Select.Where query = select.where();
134 query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); 127 query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId));
135 query.and(eq(DEVICE_NAME_PROPERTY, deviceName)); 128 query.and(eq(DEVICE_NAME_PROPERTY, deviceName));
136 - return Optional.ofNullable(findOneByStatement(query)); 129 + return Optional.ofNullable(DaoUtil.getData(findOneByStatement(query)));
137 } 130 }
138 131
139 @Override 132 @Override
140 - public ListenableFuture<List<TenantDeviceTypeEntity>> findTenantDeviceTypesAsync() { 133 + public ListenableFuture<List<TenantDeviceType>> findTenantDeviceTypesAsync() {
141 Select statement = select().distinct().column(DEVICE_TYPE_PROPERTY).column(DEVICE_TENANT_ID_PROPERTY).from(DEVICE_TYPES_BY_TENANT_VIEW_NAME); 134 Select statement = select().distinct().column(DEVICE_TYPE_PROPERTY).column(DEVICE_TENANT_ID_PROPERTY).from(DEVICE_TYPES_BY_TENANT_VIEW_NAME);
142 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); 135 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
143 ResultSetFuture resultSetFuture = getSession().executeAsync(statement); 136 ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
@@ -153,7 +146,20 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement @@ -153,7 +146,20 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
153 } 146 }
154 } 147 }
155 }); 148 });
156 - return result; 149 + return Futures.transform(result, new Function<List<TenantDeviceTypeEntity>, List<TenantDeviceType>>() {
  150 + @Nullable
  151 + @Override
  152 + public List<TenantDeviceType> apply(@Nullable List<TenantDeviceTypeEntity> entityList) {
  153 + List<TenantDeviceType> list = Collections.emptyList();
  154 + if (entityList != null && !entityList.isEmpty()) {
  155 + list = new ArrayList<>();
  156 + for (TenantDeviceTypeEntity object : entityList) {
  157 + list.add(object.toTenantDeviceType());
  158 + }
  159 + }
  160 + return list;
  161 + }
  162 + });
157 } 163 }
158 164
159 } 165 }
@@ -15,18 +15,15 @@ @@ -15,18 +15,15 @@
15 */ 15 */
16 package org.thingsboard.server.dao.device; 16 package org.thingsboard.server.dao.device;
17 17
18 -import java.util.UUID;  
19 -  
20 import org.thingsboard.server.common.data.security.DeviceCredentials; 18 import org.thingsboard.server.common.data.security.DeviceCredentials;
21 import org.thingsboard.server.dao.Dao; 19 import org.thingsboard.server.dao.Dao;
22 -import org.thingsboard.server.dao.model.DeviceCredentialsEntity; 20 +
  21 +import java.util.UUID;
23 22
24 /** 23 /**
25 * The Interface DeviceCredentialsDao. 24 * The Interface DeviceCredentialsDao.
26 - *  
27 - * @param <T> the generic type  
28 */ 25 */
29 -public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { 26 +public interface DeviceCredentialsDao extends Dao<DeviceCredentials> {
30 27
31 /** 28 /**
32 * Save or update device credentials object 29 * Save or update device credentials object
@@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { @@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
34 * @param deviceCredentials the device credentials object 31 * @param deviceCredentials the device credentials object
35 * @return saved device credentials object 32 * @return saved device credentials object
36 */ 33 */
37 - DeviceCredentialsEntity save(DeviceCredentials deviceCredentials); 34 + DeviceCredentials save(DeviceCredentials deviceCredentials);
38 35
39 /** 36 /**
40 * Find device credentials by device id. 37 * Find device credentials by device id.
@@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { @@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
42 * @param deviceId the device id 39 * @param deviceId the device id
43 * @return the device credentials object 40 * @return the device credentials object
44 */ 41 */
45 - DeviceCredentialsEntity findByDeviceId(UUID deviceId); 42 + DeviceCredentials findByDeviceId(UUID deviceId);
46 43
47 /** 44 /**
48 * Find device credentials by credentials id. 45 * Find device credentials by credentials id.
@@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { @@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
50 * @param credentialsId the credentials id 47 * @param credentialsId the credentials id
51 * @return the device credentials object 48 * @return the device credentials object
52 */ 49 */
53 - DeviceCredentialsEntity findByCredentialsId(String credentialsId); 50 + DeviceCredentials findByCredentialsId(String credentialsId);
54 51
55 } 52 }
@@ -15,25 +15,18 @@ @@ -15,25 +15,18 @@
15 */ 15 */
16 package org.thingsboard.server.dao.device; 16 package org.thingsboard.server.dao.device;
17 17
18 -import org.springframework.cache.annotation.CacheEvict;  
19 -import org.springframework.cache.annotation.Cacheable;  
20 import org.thingsboard.server.common.data.id.DeviceId; 18 import org.thingsboard.server.common.data.id.DeviceId;
21 import org.thingsboard.server.common.data.security.DeviceCredentials; 19 import org.thingsboard.server.common.data.security.DeviceCredentials;
22 20
23 -import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CREDENTIALS_CACHE;  
24 -  
25 public interface DeviceCredentialsService { 21 public interface DeviceCredentialsService {
26 22
27 DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId); 23 DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId);
28 24
29 - @Cacheable(cacheNames = DEVICE_CREDENTIALS_CACHE, unless="#result == null")  
30 DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId); 25 DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId);
31 26
32 - @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, keyGenerator="previousDeviceCredentialsId", beforeInvocation = true)  
33 DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials); 27 DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials);
34 28
35 DeviceCredentials createDeviceCredentials(DeviceCredentials deviceCredentials); 29 DeviceCredentials createDeviceCredentials(DeviceCredentials deviceCredentials);
36 30
37 - @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, key="#deviceCredentials.credentialsId")  
38 void deleteDeviceCredentials(DeviceCredentials deviceCredentials); 31 void deleteDeviceCredentials(DeviceCredentials deviceCredentials);
39 } 32 }
@@ -18,6 +18,8 @@ package org.thingsboard.server.dao.device; @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.device;
18 18
19 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
20 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.cache.annotation.CacheEvict;
  22 +import org.springframework.cache.annotation.Cacheable;
21 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
22 import org.springframework.util.StringUtils; 24 import org.springframework.util.StringUtils;
23 import org.thingsboard.server.common.data.Device; 25 import org.thingsboard.server.common.data.Device;
@@ -26,10 +28,9 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; @@ -26,10 +28,9 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
26 import org.thingsboard.server.common.data.security.DeviceCredentialsType; 28 import org.thingsboard.server.common.data.security.DeviceCredentialsType;
27 import org.thingsboard.server.dao.EncryptionUtil; 29 import org.thingsboard.server.dao.EncryptionUtil;
28 import org.thingsboard.server.dao.exception.DataValidationException; 30 import org.thingsboard.server.dao.exception.DataValidationException;
29 -import org.thingsboard.server.dao.model.DeviceCredentialsEntity;  
30 import org.thingsboard.server.dao.service.DataValidator; 31 import org.thingsboard.server.dao.service.DataValidator;
31 32
32 -import static org.thingsboard.server.dao.DaoUtil.getData; 33 +import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CREDENTIALS_CACHE;
33 import static org.thingsboard.server.dao.service.Validator.validateId; 34 import static org.thingsboard.server.dao.service.Validator.validateId;
34 import static org.thingsboard.server.dao.service.Validator.validateString; 35 import static org.thingsboard.server.dao.service.Validator.validateString;
35 36
@@ -47,19 +48,19 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { @@ -47,19 +48,19 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
47 public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) { 48 public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) {
48 log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId); 49 log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId);
49 validateId(deviceId, "Incorrect deviceId " + deviceId); 50 validateId(deviceId, "Incorrect deviceId " + deviceId);
50 - DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByDeviceId(deviceId.getId());  
51 - return getData(deviceCredentialsEntity); 51 + return deviceCredentialsDao.findByDeviceId(deviceId.getId());
52 } 52 }
53 53
54 @Override 54 @Override
  55 + @Cacheable(cacheNames = DEVICE_CREDENTIALS_CACHE, unless="#result == null")
55 public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) { 56 public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) {
56 log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId); 57 log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId);
57 validateString(credentialsId, "Incorrect credentialsId " + credentialsId); 58 validateString(credentialsId, "Incorrect credentialsId " + credentialsId);
58 - DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByCredentialsId(credentialsId);  
59 - return getData(deviceCredentialsEntity); 59 + return deviceCredentialsDao.findByCredentialsId(credentialsId);
60 } 60 }
61 61
62 @Override 62 @Override
  63 + @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, keyGenerator="previousDeviceCredentialsId", beforeInvocation = true)
63 public DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials) { 64 public DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials) {
64 return saveOrUpdare(deviceCredentials); 65 return saveOrUpdare(deviceCredentials);
65 } 66 }
@@ -75,7 +76,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { @@ -75,7 +76,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
75 } 76 }
76 log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials); 77 log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials);
77 credentialsValidator.validate(deviceCredentials); 78 credentialsValidator.validate(deviceCredentials);
78 - return getData(deviceCredentialsDao.save(deviceCredentials)); 79 + return deviceCredentialsDao.save(deviceCredentials);
79 } 80 }
80 81
81 private void formatCertData(DeviceCredentials deviceCredentials) { 82 private void formatCertData(DeviceCredentials deviceCredentials) {
@@ -86,6 +87,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { @@ -86,6 +87,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
86 } 87 }
87 88
88 @Override 89 @Override
  90 + @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, key="#deviceCredentials.credentialsId")
89 public void deleteDeviceCredentials(DeviceCredentials deviceCredentials) { 91 public void deleteDeviceCredentials(DeviceCredentials deviceCredentials) {
90 log.trace("Executing deleteDeviceCredentials [{}]", deviceCredentials); 92 log.trace("Executing deleteDeviceCredentials [{}]", deviceCredentials);
91 deviceCredentialsDao.removeById(deviceCredentials.getUuidId()); 93 deviceCredentialsDao.removeById(deviceCredentials.getUuidId());
@@ -96,7 +98,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { @@ -96,7 +98,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
96 98
97 @Override 99 @Override
98 protected void validateCreate(DeviceCredentials deviceCredentials) { 100 protected void validateCreate(DeviceCredentials deviceCredentials) {
99 - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); 101 + DeviceCredentials existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
100 if (existingCredentialsEntity != null) { 102 if (existingCredentialsEntity != null) {
101 throw new DataValidationException("Create of existent device credentials!"); 103 throw new DataValidationException("Create of existent device credentials!");
102 } 104 }
@@ -104,12 +106,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { @@ -104,12 +106,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
104 106
105 @Override 107 @Override
106 protected void validateUpdate(DeviceCredentials deviceCredentials) { 108 protected void validateUpdate(DeviceCredentials deviceCredentials) {
107 - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findById(deviceCredentials.getUuidId());  
108 - if (existingCredentialsEntity == null) { 109 + DeviceCredentials existingCredentials = deviceCredentialsDao.findById(deviceCredentials.getUuidId());
  110 + if (existingCredentials == null) {
109 throw new DataValidationException("Unable to update non-existent device credentials!"); 111 throw new DataValidationException("Unable to update non-existent device credentials!");
110 } 112 }
111 - DeviceCredentialsEntity sameCredentialsIdEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());  
112 - if (sameCredentialsIdEntity != null && !sameCredentialsIdEntity.getId().equals(deviceCredentials.getUuidId())) { 113 + DeviceCredentials sameCredentialsId = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
  114 + if (sameCredentialsId != null && !sameCredentialsId.getUuidId().equals(deviceCredentials.getUuidId())) {
113 throw new DataValidationException("Specified credentials are already registered!"); 115 throw new DataValidationException("Specified credentials are already registered!");
114 } 116 }
115 } 117 }
@@ -15,22 +15,22 @@ @@ -15,22 +15,22 @@
15 */ 15 */
16 package org.thingsboard.server.dao.device; 16 package org.thingsboard.server.dao.device;
17 17
18 -import java.util.List;  
19 -import java.util.Optional;  
20 -import java.util.UUID;  
21 -  
22 import com.google.common.util.concurrent.ListenableFuture; 18 import com.google.common.util.concurrent.ListenableFuture;
23 import org.thingsboard.server.common.data.Device; 19 import org.thingsboard.server.common.data.Device;
  20 +import org.thingsboard.server.common.data.TenantDeviceType;
24 import org.thingsboard.server.common.data.page.TextPageLink; 21 import org.thingsboard.server.common.data.page.TextPageLink;
25 import org.thingsboard.server.dao.Dao; 22 import org.thingsboard.server.dao.Dao;
26 -import org.thingsboard.server.dao.model.DeviceEntity;  
27 import org.thingsboard.server.dao.model.TenantDeviceTypeEntity; 23 import org.thingsboard.server.dao.model.TenantDeviceTypeEntity;
28 24
  25 +import java.util.List;
  26 +import java.util.Optional;
  27 +import java.util.UUID;
  28 +
29 /** 29 /**
30 * The Interface DeviceDao. 30 * The Interface DeviceDao.
31 * 31 *
32 */ 32 */
33 -public interface DeviceDao extends Dao<DeviceEntity> { 33 +public interface DeviceDao extends Dao<Device> {
34 34
35 /** 35 /**
36 * Save or update device object 36 * Save or update device object
@@ -38,7 +38,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -38,7 +38,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
38 * @param device the device object 38 * @param device the device object
39 * @return saved device object 39 * @return saved device object
40 */ 40 */
41 - DeviceEntity save(Device device); 41 + Device save(Device device);
42 42
43 /** 43 /**
44 * Find devices by tenantId and page link. 44 * Find devices by tenantId and page link.
@@ -47,7 +47,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -47,7 +47,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
47 * @param pageLink the page link 47 * @param pageLink the page link
48 * @return the list of device objects 48 * @return the list of device objects
49 */ 49 */
50 - List<DeviceEntity> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink); 50 + List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink);
51 51
52 /** 52 /**
53 * Find devices by tenantId, type and page link. 53 * Find devices by tenantId, type and page link.
@@ -57,7 +57,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -57,7 +57,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
57 * @param pageLink the page link 57 * @param pageLink the page link
58 * @return the list of device objects 58 * @return the list of device objects
59 */ 59 */
60 - List<DeviceEntity> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink); 60 + List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink);
61 61
62 /** 62 /**
63 * Find devices by tenantId and devices Ids. 63 * Find devices by tenantId and devices Ids.
@@ -66,7 +66,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -66,7 +66,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
66 * @param deviceIds the device Ids 66 * @param deviceIds the device Ids
67 * @return the list of device objects 67 * @return the list of device objects
68 */ 68 */
69 - ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds); 69 + ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds);
70 70
71 /** 71 /**
72 * Find devices by tenantId, customerId and page link. 72 * Find devices by tenantId, customerId and page link.
@@ -76,7 +76,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -76,7 +76,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
76 * @param pageLink the page link 76 * @param pageLink the page link
77 * @return the list of device objects 77 * @return the list of device objects
78 */ 78 */
79 - List<DeviceEntity> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); 79 + List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
80 80
81 /** 81 /**
82 * Find devices by tenantId, customerId, type and page link. 82 * Find devices by tenantId, customerId, type and page link.
@@ -87,7 +87,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -87,7 +87,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
87 * @param pageLink the page link 87 * @param pageLink the page link
88 * @return the list of device objects 88 * @return the list of device objects
89 */ 89 */
90 - List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink); 90 + List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink);
91 91
92 92
93 /** 93 /**
@@ -98,7 +98,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -98,7 +98,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
98 * @param deviceIds the device Ids 98 * @param deviceIds the device Ids
99 * @return the list of device objects 99 * @return the list of device objects
100 */ 100 */
101 - ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds); 101 + ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds);
102 102
103 /** 103 /**
104 * Find devices by tenantId and device name. 104 * Find devices by tenantId and device name.
@@ -107,12 +107,12 @@ public interface DeviceDao extends Dao<DeviceEntity> { @@ -107,12 +107,12 @@ public interface DeviceDao extends Dao<DeviceEntity> {
107 * @param name the device name 107 * @param name the device name
108 * @return the optional device object 108 * @return the optional device object
109 */ 109 */
110 - Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String name); 110 + Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String name);
111 111
112 /** 112 /**
113 * Find tenants device types. 113 * Find tenants device types.
114 * 114 *
115 * @return the list of tenant device type objects 115 * @return the list of tenant device type objects
116 */ 116 */
117 - ListenableFuture<List<TenantDeviceTypeEntity>> findTenantDeviceTypesAsync(); 117 + ListenableFuture<List<TenantDeviceType>> findTenantDeviceTypesAsync();
118 } 118 }
@@ -18,9 +18,9 @@ package org.thingsboard.server.dao.device; @@ -18,9 +18,9 @@ package org.thingsboard.server.dao.device;
18 import lombok.Data; 18 import lombok.Data;
19 import org.thingsboard.server.common.data.EntityType; 19 import org.thingsboard.server.common.data.EntityType;
20 import org.thingsboard.server.common.data.relation.EntityRelation; 20 import org.thingsboard.server.common.data.relation.EntityRelation;
21 -import org.thingsboard.server.dao.relation.RelationsSearchParameters;  
22 import org.thingsboard.server.dao.relation.EntityRelationsQuery; 21 import org.thingsboard.server.dao.relation.EntityRelationsQuery;
23 import org.thingsboard.server.dao.relation.EntityTypeFilter; 22 import org.thingsboard.server.dao.relation.EntityTypeFilter;
  23 +import org.thingsboard.server.dao.relation.RelationsSearchParameters;
24 24
25 import javax.annotation.Nullable; 25 import javax.annotation.Nullable;
26 import java.util.Collections; 26 import java.util.Collections;
@@ -24,9 +24,7 @@ import org.apache.commons.lang3.RandomStringUtils; @@ -24,9 +24,7 @@ import org.apache.commons.lang3.RandomStringUtils;
24 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
26 import org.springframework.util.StringUtils; 26 import org.springframework.util.StringUtils;
27 -import org.thingsboard.server.common.data.Device;  
28 -import org.thingsboard.server.common.data.EntityType;  
29 -import org.thingsboard.server.common.data.TenantDeviceType; 27 +import org.thingsboard.server.common.data.*;
30 import org.thingsboard.server.common.data.id.CustomerId; 28 import org.thingsboard.server.common.data.id.CustomerId;
31 import org.thingsboard.server.common.data.id.DeviceId; 29 import org.thingsboard.server.common.data.id.DeviceId;
32 import org.thingsboard.server.common.data.id.EntityId; 30 import org.thingsboard.server.common.data.id.EntityId;
@@ -39,20 +37,19 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; @@ -39,20 +37,19 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType;
39 import org.thingsboard.server.dao.customer.CustomerDao; 37 import org.thingsboard.server.dao.customer.CustomerDao;
40 import org.thingsboard.server.dao.entity.AbstractEntityService; 38 import org.thingsboard.server.dao.entity.AbstractEntityService;
41 import org.thingsboard.server.dao.exception.DataValidationException; 39 import org.thingsboard.server.dao.exception.DataValidationException;
42 -import org.thingsboard.server.dao.model.CustomerEntity;  
43 -import org.thingsboard.server.dao.model.DeviceEntity;  
44 -import org.thingsboard.server.dao.model.TenantDeviceTypeEntity;  
45 -import org.thingsboard.server.dao.model.TenantEntity;  
46 import org.thingsboard.server.dao.relation.EntitySearchDirection; 40 import org.thingsboard.server.dao.relation.EntitySearchDirection;
47 import org.thingsboard.server.dao.service.DataValidator; 41 import org.thingsboard.server.dao.service.DataValidator;
48 import org.thingsboard.server.dao.service.PaginatedRemover; 42 import org.thingsboard.server.dao.service.PaginatedRemover;
49 import org.thingsboard.server.dao.tenant.TenantDao; 43 import org.thingsboard.server.dao.tenant.TenantDao;
50 44
51 import javax.annotation.Nullable; 45 import javax.annotation.Nullable;
52 -import java.util.*; 46 +import java.util.ArrayList;
  47 +import java.util.Comparator;
  48 +import java.util.List;
  49 +import java.util.Optional;
53 import java.util.stream.Collectors; 50 import java.util.stream.Collectors;
54 51
55 -import static org.thingsboard.server.dao.DaoUtil.*; 52 +import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
56 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; 53 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
57 import static org.thingsboard.server.dao.service.Validator.*; 54 import static org.thingsboard.server.dao.service.Validator.*;
58 55
@@ -76,25 +73,23 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -76,25 +73,23 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
76 public Device findDeviceById(DeviceId deviceId) { 73 public Device findDeviceById(DeviceId deviceId) {
77 log.trace("Executing findDeviceById [{}]", deviceId); 74 log.trace("Executing findDeviceById [{}]", deviceId);
78 validateId(deviceId, "Incorrect deviceId " + deviceId); 75 validateId(deviceId, "Incorrect deviceId " + deviceId);
79 - DeviceEntity deviceEntity = deviceDao.findById(deviceId.getId());  
80 - return getData(deviceEntity); 76 + return deviceDao.findById(deviceId.getId());
81 } 77 }
82 78
83 @Override 79 @Override
84 public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) { 80 public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) {
85 log.trace("Executing findDeviceById [{}]", deviceId); 81 log.trace("Executing findDeviceById [{}]", deviceId);
86 validateId(deviceId, "Incorrect deviceId " + deviceId); 82 validateId(deviceId, "Incorrect deviceId " + deviceId);
87 - ListenableFuture<DeviceEntity> deviceEntity = deviceDao.findByIdAsync(deviceId.getId());  
88 - return Futures.transform(deviceEntity, (Function<? super DeviceEntity, ? extends Device>) input -> getData(input)); 83 + return deviceDao.findByIdAsync(deviceId.getId());
89 } 84 }
90 85
91 @Override 86 @Override
92 public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) { 87 public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) {
93 log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name); 88 log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name);
94 validateId(tenantId, "Incorrect tenantId " + tenantId); 89 validateId(tenantId, "Incorrect tenantId " + tenantId);
95 - Optional<DeviceEntity> deviceEntityOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name);  
96 - if (deviceEntityOpt.isPresent()) {  
97 - return Optional.of(getData(deviceEntityOpt.get())); 90 + Optional<Device> deviceOpt = deviceDao.findDeviceByTenantIdAndName(tenantId.getId(), name);
  91 + if (deviceOpt.isPresent()) {
  92 + return Optional.of(deviceOpt.get());
98 } else { 93 } else {
99 return Optional.empty(); 94 return Optional.empty();
100 } 95 }
@@ -104,15 +99,15 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -104,15 +99,15 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
104 public Device saveDevice(Device device) { 99 public Device saveDevice(Device device) {
105 log.trace("Executing saveDevice [{}]", device); 100 log.trace("Executing saveDevice [{}]", device);
106 deviceValidator.validate(device); 101 deviceValidator.validate(device);
107 - DeviceEntity deviceEntity = deviceDao.save(device); 102 + Device savedDevice = deviceDao.save(device);
108 if (device.getId() == null) { 103 if (device.getId() == null) {
109 DeviceCredentials deviceCredentials = new DeviceCredentials(); 104 DeviceCredentials deviceCredentials = new DeviceCredentials();
110 - deviceCredentials.setDeviceId(new DeviceId(deviceEntity.getId())); 105 + deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId()));
111 deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); 106 deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
112 deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); 107 deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
113 deviceCredentialsService.createDeviceCredentials(deviceCredentials); 108 deviceCredentialsService.createDeviceCredentials(deviceCredentials);
114 } 109 }
115 - return getData(deviceEntity); 110 + return savedDevice;
116 } 111 }
117 112
118 @Override 113 @Override
@@ -146,8 +141,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -146,8 +141,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
146 log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); 141 log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
147 validateId(tenantId, "Incorrect tenantId " + tenantId); 142 validateId(tenantId, "Incorrect tenantId " + tenantId);
148 validatePageLink(pageLink, "Incorrect page link " + pageLink); 143 validatePageLink(pageLink, "Incorrect page link " + pageLink);
149 - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink);  
150 - List<Device> devices = convertDataList(deviceEntities); 144 + List<Device> devices = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink);
151 return new TextPageData<>(devices, pageLink); 145 return new TextPageData<>(devices, pageLink);
152 } 146 }
153 147
@@ -157,8 +151,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -157,8 +151,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
157 validateId(tenantId, "Incorrect tenantId " + tenantId); 151 validateId(tenantId, "Incorrect tenantId " + tenantId);
158 validateString(type, "Incorrect type " + type); 152 validateString(type, "Incorrect type " + type);
159 validatePageLink(pageLink, "Incorrect page link " + pageLink); 153 validatePageLink(pageLink, "Incorrect page link " + pageLink);
160 - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndType(tenantId.getId(), type, pageLink);  
161 - List<Device> devices = convertDataList(deviceEntities); 154 + List<Device> devices = deviceDao.findDevicesByTenantIdAndType(tenantId.getId(), type, pageLink);
162 return new TextPageData<>(devices, pageLink); 155 return new TextPageData<>(devices, pageLink);
163 } 156 }
164 157
@@ -167,8 +160,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -167,8 +160,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
167 log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds); 160 log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds);
168 validateId(tenantId, "Incorrect tenantId " + tenantId); 161 validateId(tenantId, "Incorrect tenantId " + tenantId);
169 validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); 162 validateIds(deviceIds, "Incorrect deviceIds " + deviceIds);
170 - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds));  
171 - return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input)); 163 + return deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds));
172 } 164 }
173 165
174 166
@@ -176,7 +168,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -176,7 +168,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
176 public void deleteDevicesByTenantId(TenantId tenantId) { 168 public void deleteDevicesByTenantId(TenantId tenantId) {
177 log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId); 169 log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId);
178 validateId(tenantId, "Incorrect tenantId " + tenantId); 170 validateId(tenantId, "Incorrect tenantId " + tenantId);
179 - tenantDevicesRemover.removeEntitites(tenantId); 171 + tenantDevicesRemover.removeEntities(tenantId);
180 } 172 }
181 173
182 @Override 174 @Override
@@ -185,8 +177,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -185,8 +177,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
185 validateId(tenantId, "Incorrect tenantId " + tenantId); 177 validateId(tenantId, "Incorrect tenantId " + tenantId);
186 validateId(customerId, "Incorrect customerId " + customerId); 178 validateId(customerId, "Incorrect customerId " + customerId);
187 validatePageLink(pageLink, "Incorrect page link " + pageLink); 179 validatePageLink(pageLink, "Incorrect page link " + pageLink);
188 - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);  
189 - List<Device> devices = convertDataList(deviceEntities); 180 + List<Device> devices = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
190 return new TextPageData<>(devices, pageLink); 181 return new TextPageData<>(devices, pageLink);
191 } 182 }
192 183
@@ -197,8 +188,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -197,8 +188,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
197 validateId(customerId, "Incorrect customerId " + customerId); 188 validateId(customerId, "Incorrect customerId " + customerId);
198 validateString(type, "Incorrect type " + type); 189 validateString(type, "Incorrect type " + type);
199 validatePageLink(pageLink, "Incorrect page link " + pageLink); 190 validatePageLink(pageLink, "Incorrect page link " + pageLink);
200 - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);  
201 - List<Device> devices = convertDataList(deviceEntities); 191 + List<Device> devices = deviceDao.findDevicesByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
202 return new TextPageData<>(devices, pageLink); 192 return new TextPageData<>(devices, pageLink);
203 } 193 }
204 194
@@ -208,9 +198,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -208,9 +198,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
208 validateId(tenantId, "Incorrect tenantId " + tenantId); 198 validateId(tenantId, "Incorrect tenantId " + tenantId);
209 validateId(customerId, "Incorrect customerId " + customerId); 199 validateId(customerId, "Incorrect customerId " + customerId);
210 validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); 200 validateIds(deviceIds, "Incorrect deviceIds " + deviceIds);
211 - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(), 201 + return deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),
212 customerId.getId(), toUUIDs(deviceIds)); 202 customerId.getId(), toUUIDs(deviceIds));
213 - return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input));  
214 } 203 }
215 204
216 @Override 205 @Override
@@ -218,7 +207,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -218,7 +207,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
218 log.trace("Executing unassignCustomerDevices, tenantId [{}], customerId [{}]", tenantId, customerId); 207 log.trace("Executing unassignCustomerDevices, tenantId [{}], customerId [{}]", tenantId, customerId);
219 validateId(tenantId, "Incorrect tenantId " + tenantId); 208 validateId(tenantId, "Incorrect tenantId " + tenantId);
220 validateId(customerId, "Incorrect customerId " + customerId); 209 validateId(customerId, "Incorrect customerId " + customerId);
221 - new CustomerDevicesUnassigner(tenantId).removeEntitites(customerId); 210 + new CustomerDevicesUnassigner(tenantId).removeEntities(customerId);
222 } 211 }
223 212
224 @Override 213 @Override
@@ -251,16 +240,16 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -251,16 +240,16 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
251 public ListenableFuture<List<TenantDeviceType>> findDeviceTypesByTenantId(TenantId tenantId) { 240 public ListenableFuture<List<TenantDeviceType>> findDeviceTypesByTenantId(TenantId tenantId) {
252 log.trace("Executing findDeviceTypesByTenantId, tenantId [{}]", tenantId); 241 log.trace("Executing findDeviceTypesByTenantId, tenantId [{}]", tenantId);
253 validateId(tenantId, "Incorrect tenantId " + tenantId); 242 validateId(tenantId, "Incorrect tenantId " + tenantId);
254 - ListenableFuture<List<TenantDeviceTypeEntity>> tenantDeviceTypeEntities = deviceDao.findTenantDeviceTypesAsync(); 243 + ListenableFuture<List<TenantDeviceType>> tenantDeviceTypeEntities = deviceDao.findTenantDeviceTypesAsync();
255 ListenableFuture<List<TenantDeviceType>> tenantDeviceTypes = Futures.transform(tenantDeviceTypeEntities, 244 ListenableFuture<List<TenantDeviceType>> tenantDeviceTypes = Futures.transform(tenantDeviceTypeEntities,
256 - (Function<List<TenantDeviceTypeEntity>, List<TenantDeviceType>>) deviceTypeEntities -> { 245 + (Function<List<TenantDeviceType>, List<TenantDeviceType>>) deviceTypeEntities -> {
257 List<TenantDeviceType> deviceTypes = new ArrayList<>(); 246 List<TenantDeviceType> deviceTypes = new ArrayList<>();
258 - for (TenantDeviceTypeEntity deviceTypeEntity : deviceTypeEntities) {  
259 - if (deviceTypeEntity.getTenantId().equals(tenantId.getId())) {  
260 - deviceTypes.add(deviceTypeEntity.toTenantDeviceType()); 247 + for (TenantDeviceType deviceType : deviceTypeEntities) {
  248 + if (deviceType.getTenantId().equals(tenantId)) {
  249 + deviceTypes.add(deviceType);
261 } 250 }
262 } 251 }
263 - deviceTypes.sort((TenantDeviceType o1, TenantDeviceType o2) -> o1.getType().compareTo(o2.getType())); 252 + deviceTypes.sort(Comparator.comparing(TenantDeviceType::getType));
264 return deviceTypes; 253 return deviceTypes;
265 }); 254 });
266 return tenantDeviceTypes; 255 return tenantDeviceTypes;
@@ -271,7 +260,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -271,7 +260,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
271 260
272 @Override 261 @Override
273 protected void validateCreate(Device device) { 262 protected void validateCreate(Device device) {
274 - deviceDao.findDevicesByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent( 263 + deviceDao.findDeviceByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent(
275 d -> { 264 d -> {
276 throw new DataValidationException("Device with such name already exists!"); 265 throw new DataValidationException("Device with such name already exists!");
277 } 266 }
@@ -280,9 +269,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -280,9 +269,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
280 269
281 @Override 270 @Override
282 protected void validateUpdate(Device device) { 271 protected void validateUpdate(Device device) {
283 - deviceDao.findDevicesByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent( 272 + deviceDao.findDeviceByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent(
284 d -> { 273 d -> {
285 - if (!d.getId().equals(device.getUuidId())) { 274 + if (!d.getUuidId().equals(device.getUuidId())) {
286 throw new DataValidationException("Device with such name already exists!"); 275 throw new DataValidationException("Device with such name already exists!");
287 } 276 }
288 } 277 }
@@ -300,7 +289,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -300,7 +289,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
300 if (device.getTenantId() == null) { 289 if (device.getTenantId() == null) {
301 throw new DataValidationException("Device should be assigned to tenant!"); 290 throw new DataValidationException("Device should be assigned to tenant!");
302 } else { 291 } else {
303 - TenantEntity tenant = tenantDao.findById(device.getTenantId().getId()); 292 + Tenant tenant = tenantDao.findById(device.getTenantId().getId());
304 if (tenant == null) { 293 if (tenant == null) {
305 throw new DataValidationException("Device is referencing to non-existent tenant!"); 294 throw new DataValidationException("Device is referencing to non-existent tenant!");
306 } 295 }
@@ -308,32 +297,32 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -308,32 +297,32 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
308 if (device.getCustomerId() == null) { 297 if (device.getCustomerId() == null) {
309 device.setCustomerId(new CustomerId(NULL_UUID)); 298 device.setCustomerId(new CustomerId(NULL_UUID));
310 } else if (!device.getCustomerId().getId().equals(NULL_UUID)) { 299 } else if (!device.getCustomerId().getId().equals(NULL_UUID)) {
311 - CustomerEntity customer = customerDao.findById(device.getCustomerId().getId()); 300 + Customer customer = customerDao.findById(device.getCustomerId().getId());
312 if (customer == null) { 301 if (customer == null) {
313 throw new DataValidationException("Can't assign device to non-existent customer!"); 302 throw new DataValidationException("Can't assign device to non-existent customer!");
314 } 303 }
315 - if (!customer.getTenantId().equals(device.getTenantId().getId())) { 304 + if (!customer.getTenantId().getId().equals(device.getTenantId().getId())) {
316 throw new DataValidationException("Can't assign device to customer from different tenant!"); 305 throw new DataValidationException("Can't assign device to customer from different tenant!");
317 } 306 }
318 } 307 }
319 } 308 }
320 }; 309 };
321 310
322 - private PaginatedRemover<TenantId, DeviceEntity> tenantDevicesRemover =  
323 - new PaginatedRemover<TenantId, DeviceEntity>() { 311 + private PaginatedRemover<TenantId, Device> tenantDevicesRemover =
  312 + new PaginatedRemover<TenantId, Device>() {
324 313
325 @Override 314 @Override
326 - protected List<DeviceEntity> findEntities(TenantId id, TextPageLink pageLink) { 315 + protected List<Device> findEntities(TenantId id, TextPageLink pageLink) {
327 return deviceDao.findDevicesByTenantId(id.getId(), pageLink); 316 return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
328 } 317 }
329 318
330 @Override 319 @Override
331 - protected void removeEntity(DeviceEntity entity) {  
332 - deleteDevice(new DeviceId(entity.getId())); 320 + protected void removeEntity(Device entity) {
  321 + deleteDevice(new DeviceId(entity.getUuidId()));
333 } 322 }
334 }; 323 };
335 324
336 - class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, DeviceEntity> { 325 + private class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, Device> {
337 326
338 private TenantId tenantId; 327 private TenantId tenantId;
339 328
@@ -342,13 +331,13 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -342,13 +331,13 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
342 } 331 }
343 332
344 @Override 333 @Override
345 - protected List<DeviceEntity> findEntities(CustomerId id, TextPageLink pageLink) { 334 + protected List<Device> findEntities(CustomerId id, TextPageLink pageLink) {
346 return deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); 335 return deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
347 } 336 }
348 337
349 @Override 338 @Override
350 - protected void removeEntity(DeviceEntity entity) {  
351 - unassignDeviceFromCustomer(new DeviceId(entity.getId())); 339 + protected void removeEntity(Device entity) {
  340 + unassignDeviceFromCustomer(new DeviceId(entity.getUuidId()));
352 } 341 }
353 342
354 } 343 }
@@ -15,51 +15,32 @@ @@ -15,51 +15,32 @@
15 */ 15 */
16 package org.thingsboard.server.dao.event; 16 package org.thingsboard.server.dao.event;
17 17
18 -import com.datastax.driver.core.utils.UUIDs;  
19 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
20 import org.apache.commons.lang3.StringUtils; 19 import org.apache.commons.lang3.StringUtils;
21 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
23 import org.thingsboard.server.common.data.Event; 22 import org.thingsboard.server.common.data.Event;
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.EventId;  
26 import org.thingsboard.server.common.data.id.TenantId; 24 import org.thingsboard.server.common.data.id.TenantId;
27 import org.thingsboard.server.common.data.page.TimePageData; 25 import org.thingsboard.server.common.data.page.TimePageData;
28 import org.thingsboard.server.common.data.page.TimePageLink; 26 import org.thingsboard.server.common.data.page.TimePageLink;
29 import org.thingsboard.server.dao.exception.DataValidationException; 27 import org.thingsboard.server.dao.exception.DataValidationException;
30 -import org.thingsboard.server.dao.model.EventEntity;  
31 import org.thingsboard.server.dao.service.DataValidator; 28 import org.thingsboard.server.dao.service.DataValidator;
32 29
33 import java.util.List; 30 import java.util.List;
34 import java.util.Optional; 31 import java.util.Optional;
35 32
36 -import static org.thingsboard.server.dao.DaoUtil.convertDataList;  
37 -import static org.thingsboard.server.dao.DaoUtil.getData;  
38 -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;  
39 -  
40 @Service 33 @Service
41 @Slf4j 34 @Slf4j
42 public class BaseEventService implements EventService { 35 public class BaseEventService implements EventService {
43 36
44 - private final TenantId systemTenantId = new TenantId(NULL_UUID);  
45 -  
46 @Autowired 37 @Autowired
47 public EventDao eventDao; 38 public EventDao eventDao;
48 39
49 @Override 40 @Override
50 public Event save(Event event) { 41 public Event save(Event event) {
51 eventValidator.validate(event); 42 eventValidator.validate(event);
52 - if (event.getTenantId() == null) {  
53 - log.trace("Save system event with predefined id {}", systemTenantId);  
54 - event.setTenantId(systemTenantId);  
55 - }  
56 - if (event.getId() == null) {  
57 - event.setId(new EventId(UUIDs.timeBased()));  
58 - }  
59 - if (StringUtils.isEmpty(event.getUid())) {  
60 - event.setUid(event.getId().toString());  
61 - }  
62 - return getData(eventDao.save(event)); 43 + return eventDao.save(event);
63 } 44 }
64 45
65 @Override 46 @Override
@@ -68,15 +49,7 @@ public class BaseEventService implements EventService { @@ -68,15 +49,7 @@ public class BaseEventService implements EventService {
68 if (StringUtils.isEmpty(event.getUid())) { 49 if (StringUtils.isEmpty(event.getUid())) {
69 throw new DataValidationException("Event uid should be specified!."); 50 throw new DataValidationException("Event uid should be specified!.");
70 } 51 }
71 - if (event.getTenantId() == null) {  
72 - log.trace("Save system event with predefined id {}", systemTenantId);  
73 - event.setTenantId(systemTenantId);  
74 - }  
75 - if (event.getId() == null) {  
76 - event.setId(new EventId(UUIDs.timeBased()));  
77 - }  
78 - Optional<EventEntity> result = eventDao.saveIfNotExists(event);  
79 - return result.isPresent() ? Optional.of(getData(result.get())) : Optional.empty(); 52 + return eventDao.saveIfNotExists(event);
80 } 53 }
81 54
82 @Override 55 @Override
@@ -93,23 +66,20 @@ public class BaseEventService implements EventService { @@ -93,23 +66,20 @@ public class BaseEventService implements EventService {
93 if (StringUtils.isEmpty(eventUid)) { 66 if (StringUtils.isEmpty(eventUid)) {
94 throw new DataValidationException("Event uid should be specified!."); 67 throw new DataValidationException("Event uid should be specified!.");
95 } 68 }
96 - EventEntity entity = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid);  
97 - return entity != null ? Optional.of(getData(entity)) : Optional.empty(); 69 + Event event = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid);
  70 + return event != null ? Optional.of(event) : Optional.empty();
98 } 71 }
99 72
100 @Override 73 @Override
101 public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, TimePageLink pageLink) { 74 public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, TimePageLink pageLink) {
102 - List<EventEntity> entities = eventDao.findEvents(tenantId.getId(), entityId, pageLink);  
103 - List<Event> events = convertDataList(entities);  
104 - return new TimePageData<Event>(events, pageLink); 75 + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, pageLink);
  76 + return new TimePageData<>(events, pageLink);
105 } 77 }
106 78
107 -  
108 @Override 79 @Override
109 public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { 80 public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, String eventType, TimePageLink pageLink) {
110 - List<EventEntity> entities = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink);  
111 - List<Event> events = convertDataList(entities);  
112 - return new TimePageData<Event>(events, pageLink); 81 + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink);
  82 + return new TimePageData<>(events, pageLink);
113 } 83 }
114 84
115 private DataValidator<Event> eventValidator = 85 private DataValidator<Event> eventValidator =
dao/src/main/java/org/thingsboard/server/dao/event/CassandraBaseEventDao.java renamed from dao/src/main/java/org/thingsboard/server/dao/event/BaseEventDao.java
@@ -21,13 +21,18 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; @@ -21,13 +21,18 @@ import com.datastax.driver.core.querybuilder.QueryBuilder;
21 import com.datastax.driver.core.querybuilder.Select; 21 import com.datastax.driver.core.querybuilder.Select;
22 import com.datastax.driver.core.utils.UUIDs; 22 import com.datastax.driver.core.utils.UUIDs;
23 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
  24 +import org.apache.commons.lang3.StringUtils;
24 import org.springframework.stereotype.Component; 25 import org.springframework.stereotype.Component;
25 import org.thingsboard.server.common.data.Event; 26 import org.thingsboard.server.common.data.Event;
26 import org.thingsboard.server.common.data.id.EntityId; 27 import org.thingsboard.server.common.data.id.EntityId;
  28 +import org.thingsboard.server.common.data.id.EventId;
  29 +import org.thingsboard.server.common.data.id.TenantId;
27 import org.thingsboard.server.common.data.page.TimePageLink; 30 import org.thingsboard.server.common.data.page.TimePageLink;
28 -import org.thingsboard.server.dao.AbstractSearchTimeDao;  
29 -import org.thingsboard.server.dao.model.EventEntity; 31 +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao;
  32 +import org.thingsboard.server.dao.DaoUtil;
  33 +import org.thingsboard.server.dao.util.NoSqlDao;
30 import org.thingsboard.server.dao.model.ModelConstants; 34 import org.thingsboard.server.dao.model.ModelConstants;
  35 +import org.thingsboard.server.dao.model.nosql.EventEntity;
31 36
32 import java.util.Arrays; 37 import java.util.Arrays;
33 import java.util.List; 38 import java.util.List;
@@ -36,13 +41,14 @@ import java.util.UUID; @@ -36,13 +41,14 @@ import java.util.UUID;
36 41
37 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; 42 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
38 import static com.datastax.driver.core.querybuilder.QueryBuilder.select; 43 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
39 -import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BY_ID_VIEW_NAME;  
40 -import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BY_TYPE_AND_ID_VIEW_NAME;  
41 -import static org.thingsboard.server.dao.model.ModelConstants.EVENT_COLUMN_FAMILY_NAME; 44 +import static org.thingsboard.server.dao.model.ModelConstants.*;
42 45
43 @Component 46 @Component
44 @Slf4j 47 @Slf4j
45 -public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements EventDao { 48 +@NoSqlDao
  49 +public class CassandraBaseEventDao extends CassandraAbstractSearchTimeDao<EventEntity, Event> implements EventDao {
  50 +
  51 + private final TenantId systemTenantId = new TenantId(NULL_UUID);
46 52
47 @Override 53 @Override
48 protected Class<EventEntity> getColumnFamilyClass() { 54 protected Class<EventEntity> getColumnFamilyClass() {
@@ -55,18 +61,35 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements @@ -55,18 +61,35 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
55 } 61 }
56 62
57 @Override 63 @Override
58 - public EventEntity save(Event event) { 64 + public Event save(Event event) {
59 log.debug("Save event [{}] ", event); 65 log.debug("Save event [{}] ", event);
  66 + if (event.getTenantId() == null) {
  67 + log.trace("Save system event with predefined id {}", systemTenantId);
  68 + event.setTenantId(systemTenantId);
  69 + }
  70 + if (event.getId() == null) {
  71 + event.setId(new EventId(UUIDs.timeBased()));
  72 + }
  73 + if (StringUtils.isEmpty(event.getUid())) {
  74 + event.setUid(event.getId().toString());
  75 + }
60 return save(new EventEntity(event), false).orElse(null); 76 return save(new EventEntity(event), false).orElse(null);
61 } 77 }
62 78
63 @Override 79 @Override
64 - public Optional<EventEntity> saveIfNotExists(Event event) { 80 + public Optional<Event> saveIfNotExists(Event event) {
  81 + if (event.getTenantId() == null) {
  82 + log.trace("Save system event with predefined id {}", systemTenantId);
  83 + event.setTenantId(systemTenantId);
  84 + }
  85 + if (event.getId() == null) {
  86 + event.setId(new EventId(UUIDs.timeBased()));
  87 + }
65 return save(new EventEntity(event), true); 88 return save(new EventEntity(event), true);
66 } 89 }
67 90
68 @Override 91 @Override
69 - public EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { 92 + public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) {
70 log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid); 93 log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid);
71 Select.Where query = select().from(getColumnFamilyName()).where( 94 Select.Where query = select().from(getColumnFamilyName()).where(
72 eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)) 95 eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId))
@@ -81,11 +104,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements @@ -81,11 +104,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
81 } else { 104 } else {
82 log.debug("Search result: [{}]", entity != null); 105 log.debug("Search result: [{}]", entity != null);
83 } 106 }
84 - return entity; 107 + return DaoUtil.getData(entity);
85 } 108 }
86 109
87 @Override 110 @Override
88 - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { 111 + public List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) {
89 log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink); 112 log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink);
90 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME, 113 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME,
91 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), 114 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId),
@@ -93,11 +116,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements @@ -93,11 +116,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
93 eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())), 116 eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())),
94 pageLink); 117 pageLink);
95 log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); 118 log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink);
96 - return entities; 119 + return DaoUtil.convertDataList(entities);
97 } 120 }
98 121
99 @Override 122 @Override
100 - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { 123 + public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) {
101 log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); 124 log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink);
102 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME, 125 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME,
103 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), 126 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId),
@@ -108,10 +131,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements @@ -108,10 +131,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
108 QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), 131 QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY),
109 pageLink); 132 pageLink);
110 log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); 133 log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink);
111 - return entities; 134 + return DaoUtil.convertDataList(entities);
112 } 135 }
113 136
114 - private Optional<EventEntity> save(EventEntity entity, boolean ifNotExists) { 137 + private Optional<Event> save(EventEntity entity, boolean ifNotExists) {
115 if (entity.getId() == null) { 138 if (entity.getId() == null) {
116 entity.setId(UUIDs.timeBased()); 139 entity.setId(UUIDs.timeBased());
117 } 140 }
@@ -121,14 +144,14 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements @@ -121,14 +144,14 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
121 .value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType()) 144 .value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType())
122 .value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId()) 145 .value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId())
123 .value(ModelConstants.EVENT_TYPE_PROPERTY, entity.getEventType()) 146 .value(ModelConstants.EVENT_TYPE_PROPERTY, entity.getEventType())
124 - .value(ModelConstants.EVENT_UID_PROPERTY, entity.getEventUId()) 147 + .value(ModelConstants.EVENT_UID_PROPERTY, entity.getEventUid())
125 .value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody()); 148 .value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody());
126 if (ifNotExists) { 149 if (ifNotExists) {
127 insert = insert.ifNotExists(); 150 insert = insert.ifNotExists();
128 } 151 }
129 ResultSet rs = executeWrite(insert); 152 ResultSet rs = executeWrite(insert);
130 if (rs.wasApplied()) { 153 if (rs.wasApplied()) {
131 - return Optional.of(entity); 154 + return Optional.of(DaoUtil.getData(entity));
132 } else { 155 } else {
133 return Optional.empty(); 156 return Optional.empty();
134 } 157 }
@@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event; @@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event;
19 import org.thingsboard.server.common.data.id.EntityId; 19 import org.thingsboard.server.common.data.id.EntityId;
20 import org.thingsboard.server.common.data.page.TimePageLink; 20 import org.thingsboard.server.common.data.page.TimePageLink;
21 import org.thingsboard.server.dao.Dao; 21 import org.thingsboard.server.dao.Dao;
22 -import org.thingsboard.server.dao.model.EventEntity;  
23 22
24 import java.util.List; 23 import java.util.List;
25 import java.util.Optional; 24 import java.util.Optional;
@@ -27,10 +26,8 @@ import java.util.UUID; @@ -27,10 +26,8 @@ import java.util.UUID;
27 26
28 /** 27 /**
29 * The Interface DeviceDao. 28 * The Interface DeviceDao.
30 - *  
31 - * @param <T> the generic type  
32 */ 29 */
33 -public interface EventDao extends Dao<EventEntity> { 30 +public interface EventDao extends Dao<Event> {
34 31
35 /** 32 /**
36 * Save or update event object 33 * Save or update event object
@@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> { @@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> {
38 * @param event the event object 35 * @param event the event object
39 * @return saved event object 36 * @return saved event object
40 */ 37 */
41 - EventEntity save(Event event); 38 + Event save(Event event);
42 39
43 /** 40 /**
44 * Save event object if it is not yet saved 41 * Save event object if it is not yet saved
@@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> { @@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> {
46 * @param event the event object 43 * @param event the event object
47 * @return saved event object 44 * @return saved event object
48 */ 45 */
49 - Optional<EventEntity> saveIfNotExists(Event event); 46 + Optional<Event> saveIfNotExists(Event event);
50 47
51 /** 48 /**
52 * Find event by tenantId, entityId and eventUid. 49 * Find event by tenantId, entityId and eventUid.
@@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> { @@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> {
57 * @param eventUid the eventUid 54 * @param eventUid the eventUid
58 * @return the event 55 * @return the event
59 */ 56 */
60 - EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid); 57 + Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid);
61 58
62 /** 59 /**
63 * Find events by tenantId, entityId and pageLink. 60 * Find events by tenantId, entityId and pageLink.
@@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> { @@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> {
67 * @param pageLink the pageLink 64 * @param pageLink the pageLink
68 * @return the event list 65 * @return the event list
69 */ 66 */
70 - List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink); 67 + List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink);
71 68
72 /** 69 /**
73 * Find events by tenantId, entityId, eventType and pageLink. 70 * Find events by tenantId, entityId, eventType and pageLink.
@@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> { @@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> {
78 * @param pageLink the pageLink 75 * @param pageLink the pageLink
79 * @return the event list 76 * @return the event list
80 */ 77 */
81 - List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink); 78 + List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink);
82 } 79 }
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId; @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId;
21 import org.thingsboard.server.common.data.page.TimePageData; 21 import org.thingsboard.server.common.data.page.TimePageData;
22 import org.thingsboard.server.common.data.page.TimePageLink; 22 import org.thingsboard.server.common.data.page.TimePageLink;
23 23
24 -import java.util.List;  
25 import java.util.Optional; 24 import java.util.Optional;
26 25
27 public interface EventService { 26 public interface EventService {
@@ -17,22 +17,22 @@ package org.thingsboard.server.dao.exception; @@ -17,22 +17,22 @@ package org.thingsboard.server.dao.exception;
17 17
18 public class DatabaseException extends RuntimeException { 18 public class DatabaseException extends RuntimeException {
19 19
20 - private static final long serialVersionUID = 3463762014441887103L; 20 + private static final long serialVersionUID = 3463762014441887103L;
21 21
22 - public DatabaseException() {  
23 - super();  
24 - } 22 + public DatabaseException() {
  23 + super();
  24 + }
25 25
26 - public DatabaseException(String message, Throwable cause) {  
27 - super(message, cause);  
28 - } 26 + public DatabaseException(String message, Throwable cause) {
  27 + super(message, cause);
  28 + }
29 29
30 - public DatabaseException(String message) {  
31 - super(message);  
32 - } 30 + public DatabaseException(String message) {
  31 + super(message);
  32 + }
33 33
34 - public DatabaseException(Throwable cause) {  
35 - super(cause);  
36 - } 34 + public DatabaseException(Throwable cause) {
  35 + super(cause);
  36 + }
37 37
38 } 38 }
@@ -18,9 +18,9 @@ package org.thingsboard.server.dao.exception; @@ -18,9 +18,9 @@ package org.thingsboard.server.dao.exception;
18 18
19 public class IncorrectParameterException extends RuntimeException { 19 public class IncorrectParameterException extends RuntimeException {
20 20
21 - private static final long serialVersionUID = 601995650578985289L; 21 + private static final long serialVersionUID = 601995650578985289L;
22 22
23 - public IncorrectParameterException(String message) { 23 + public IncorrectParameterException(String message) {
24 super(message); 24 super(message);
25 } 25 }
26 26
@@ -33,7 +33,7 @@ public class ModelConstants { @@ -33,7 +33,7 @@ public class ModelConstants {
33 */ 33 */
34 public static final String ID_PROPERTY = "id"; 34 public static final String ID_PROPERTY = "id";
35 public static final String USER_ID_PROPERTY = "user_id"; 35 public static final String USER_ID_PROPERTY = "user_id";
36 - public static final String TENTANT_ID_PROPERTY = "tenant_id"; 36 + public static final String TENANT_ID_PROPERTY = "tenant_id";
37 public static final String CUSTOMER_ID_PROPERTY = "customer_id"; 37 public static final String CUSTOMER_ID_PROPERTY = "customer_id";
38 public static final String DEVICE_ID_PROPERTY = "device_id"; 38 public static final String DEVICE_ID_PROPERTY = "device_id";
39 public static final String TITLE_PROPERTY = "title"; 39 public static final String TITLE_PROPERTY = "title";
@@ -45,7 +45,8 @@ public class ModelConstants { @@ -45,7 +45,8 @@ public class ModelConstants {
45 * Cassandra user constants. 45 * Cassandra user constants.
46 */ 46 */
47 public static final String USER_COLUMN_FAMILY_NAME = "user"; 47 public static final String USER_COLUMN_FAMILY_NAME = "user";
48 - public static final String USER_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 48 + public static final String USER_PG_HIBERNATE_COLUMN_FAMILY_NAME = "tb_user";
  49 + public static final String USER_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
49 public static final String USER_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; 50 public static final String USER_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
50 public static final String USER_EMAIL_PROPERTY = "email"; 51 public static final String USER_EMAIL_PROPERTY = "email";
51 public static final String USER_AUTHORITY_PROPERTY = "authority"; 52 public static final String USER_AUTHORITY_PROPERTY = "authority";
@@ -106,7 +107,7 @@ public class ModelConstants { @@ -106,7 +107,7 @@ public class ModelConstants {
106 * Cassandra customer constants. 107 * Cassandra customer constants.
107 */ 108 */
108 public static final String CUSTOMER_COLUMN_FAMILY_NAME = "customer"; 109 public static final String CUSTOMER_COLUMN_FAMILY_NAME = "customer";
109 - public static final String CUSTOMER_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 110 + public static final String CUSTOMER_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
110 public static final String CUSTOMER_TITLE_PROPERTY = TITLE_PROPERTY; 111 public static final String CUSTOMER_TITLE_PROPERTY = TITLE_PROPERTY;
111 public static final String CUSTOMER_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; 112 public static final String CUSTOMER_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
112 113
@@ -117,7 +118,7 @@ public class ModelConstants { @@ -117,7 +118,7 @@ public class ModelConstants {
117 * Cassandra device constants. 118 * Cassandra device constants.
118 */ 119 */
119 public static final String DEVICE_COLUMN_FAMILY_NAME = "device"; 120 public static final String DEVICE_COLUMN_FAMILY_NAME = "device";
120 - public static final String DEVICE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 121 + public static final String DEVICE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
121 public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; 122 public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
122 public static final String DEVICE_NAME_PROPERTY = "name"; 123 public static final String DEVICE_NAME_PROPERTY = "name";
123 public static final String DEVICE_TYPE_PROPERTY = "type"; 124 public static final String DEVICE_TYPE_PROPERTY = "type";
@@ -134,7 +135,7 @@ public class ModelConstants { @@ -134,7 +135,7 @@ public class ModelConstants {
134 * Cassandra asset constants. 135 * Cassandra asset constants.
135 */ 136 */
136 public static final String ASSET_COLUMN_FAMILY_NAME = "asset"; 137 public static final String ASSET_COLUMN_FAMILY_NAME = "asset";
137 - public static final String ASSET_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 138 + public static final String ASSET_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
138 public static final String ASSET_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; 139 public static final String ASSET_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
139 public static final String ASSET_NAME_PROPERTY = "name"; 140 public static final String ASSET_NAME_PROPERTY = "name";
140 public static final String ASSET_TYPE_PROPERTY = "type"; 141 public static final String ASSET_TYPE_PROPERTY = "type";
@@ -151,7 +152,7 @@ public class ModelConstants { @@ -151,7 +152,7 @@ public class ModelConstants {
151 * Cassandra alarm constants. 152 * Cassandra alarm constants.
152 */ 153 */
153 public static final String ALARM_COLUMN_FAMILY_NAME = "alarm"; 154 public static final String ALARM_COLUMN_FAMILY_NAME = "alarm";
154 - public static final String ALARM_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 155 + public static final String ALARM_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
155 public static final String ALARM_TYPE_PROPERTY = "type"; 156 public static final String ALARM_TYPE_PROPERTY = "type";
156 public static final String ALARM_DETAILS_PROPERTY = "details"; 157 public static final String ALARM_DETAILS_PROPERTY = "details";
157 public static final String ALARM_ORIGINATOR_ID_PROPERTY = "originator_id"; 158 public static final String ALARM_ORIGINATOR_ID_PROPERTY = "originator_id";
@@ -197,7 +198,7 @@ public class ModelConstants { @@ -197,7 +198,7 @@ public class ModelConstants {
197 * Cassandra widgets_bundle constants. 198 * Cassandra widgets_bundle constants.
198 */ 199 */
199 public static final String WIDGETS_BUNDLE_COLUMN_FAMILY_NAME = "widgets_bundle"; 200 public static final String WIDGETS_BUNDLE_COLUMN_FAMILY_NAME = "widgets_bundle";
200 - public static final String WIDGETS_BUNDLE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 201 + public static final String WIDGETS_BUNDLE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
201 public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY; 202 public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY;
202 public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY; 203 public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY;
203 public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image"; 204 public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image";
@@ -209,7 +210,7 @@ public class ModelConstants { @@ -209,7 +210,7 @@ public class ModelConstants {
209 * Cassandra widget_type constants. 210 * Cassandra widget_type constants.
210 */ 211 */
211 public static final String WIDGET_TYPE_COLUMN_FAMILY_NAME = "widget_type"; 212 public static final String WIDGET_TYPE_COLUMN_FAMILY_NAME = "widget_type";
212 - public static final String WIDGET_TYPE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 213 + public static final String WIDGET_TYPE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
213 public static final String WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY = "bundle_alias"; 214 public static final String WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY = "bundle_alias";
214 public static final String WIDGET_TYPE_ALIAS_PROPERTY = ALIAS_PROPERTY; 215 public static final String WIDGET_TYPE_ALIAS_PROPERTY = ALIAS_PROPERTY;
215 public static final String WIDGET_TYPE_NAME_PROPERTY = "name"; 216 public static final String WIDGET_TYPE_NAME_PROPERTY = "name";
@@ -221,7 +222,7 @@ public class ModelConstants { @@ -221,7 +222,7 @@ public class ModelConstants {
221 * Cassandra dashboard constants. 222 * Cassandra dashboard constants.
222 */ 223 */
223 public static final String DASHBOARD_COLUMN_FAMILY_NAME = "dashboard"; 224 public static final String DASHBOARD_COLUMN_FAMILY_NAME = "dashboard";
224 - public static final String DASHBOARD_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 225 + public static final String DASHBOARD_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
225 public static final String DASHBOARD_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; 226 public static final String DASHBOARD_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
226 public static final String DASHBOARD_TITLE_PROPERTY = TITLE_PROPERTY; 227 public static final String DASHBOARD_TITLE_PROPERTY = TITLE_PROPERTY;
227 public static final String DASHBOARD_CONFIGURATION_PROPERTY = "configuration"; 228 public static final String DASHBOARD_CONFIGURATION_PROPERTY = "configuration";
@@ -234,7 +235,7 @@ public class ModelConstants { @@ -234,7 +235,7 @@ public class ModelConstants {
234 * Cassandra plugin metadata constants. 235 * Cassandra plugin metadata constants.
235 */ 236 */
236 public static final String PLUGIN_COLUMN_FAMILY_NAME = "plugin"; 237 public static final String PLUGIN_COLUMN_FAMILY_NAME = "plugin";
237 - public static final String PLUGIN_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 238 + public static final String PLUGIN_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
238 public static final String PLUGIN_NAME_PROPERTY = "name"; 239 public static final String PLUGIN_NAME_PROPERTY = "name";
239 public static final String PLUGIN_API_TOKEN_PROPERTY = "api_token"; 240 public static final String PLUGIN_API_TOKEN_PROPERTY = "api_token";
240 public static final String PLUGIN_CLASS_PROPERTY = "plugin_class"; 241 public static final String PLUGIN_CLASS_PROPERTY = "plugin_class";
@@ -264,7 +265,7 @@ public class ModelConstants { @@ -264,7 +265,7 @@ public class ModelConstants {
264 * Cassandra rule metadata constants. 265 * Cassandra rule metadata constants.
265 */ 266 */
266 public static final String RULE_COLUMN_FAMILY_NAME = "rule"; 267 public static final String RULE_COLUMN_FAMILY_NAME = "rule";
267 - public static final String RULE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 268 + public static final String RULE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
268 public static final String RULE_NAME_PROPERTY = "name"; 269 public static final String RULE_NAME_PROPERTY = "name";
269 public static final String RULE_STATE_PROPERTY = "state"; 270 public static final String RULE_STATE_PROPERTY = "state";
270 public static final String RULE_WEIGHT_PROPERTY = "weight"; 271 public static final String RULE_WEIGHT_PROPERTY = "weight";
@@ -280,7 +281,7 @@ public class ModelConstants { @@ -280,7 +281,7 @@ public class ModelConstants {
280 * Cassandra event constants. 281 * Cassandra event constants.
281 */ 282 */
282 public static final String EVENT_COLUMN_FAMILY_NAME = "event"; 283 public static final String EVENT_COLUMN_FAMILY_NAME = "event";
283 - public static final String EVENT_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; 284 + public static final String EVENT_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
284 public static final String EVENT_TYPE_PROPERTY = "event_type"; 285 public static final String EVENT_TYPE_PROPERTY = "event_type";
285 public static final String EVENT_UID_PROPERTY = "event_uid"; 286 public static final String EVENT_UID_PROPERTY = "event_uid";
286 public static final String EVENT_ENTITY_TYPE_PROPERTY = "entity_type"; 287 public static final String EVENT_ENTITY_TYPE_PROPERTY = "entity_type";
dao/src/main/java/org/thingsboard/server/dao/model/nosql/AdminSettingsEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/AdminSettingsEntity.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; 18 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
19 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_JSON_VALUE_PROPERTY; 19 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_JSON_VALUE_PROPERTY;
@@ -24,6 +24,7 @@ import java.util.UUID; @@ -24,6 +24,7 @@ import java.util.UUID;
24 24
25 import org.thingsboard.server.common.data.AdminSettings; 25 import org.thingsboard.server.common.data.AdminSettings;
26 import org.thingsboard.server.common.data.id.AdminSettingsId; 26 import org.thingsboard.server.common.data.id.AdminSettingsId;
  27 +import org.thingsboard.server.dao.model.BaseEntity;
27 import org.thingsboard.server.dao.model.type.JsonCodec; 28 import org.thingsboard.server.dao.model.type.JsonCodec;
28 29
29 import com.datastax.driver.core.utils.UUIDs; 30 import com.datastax.driver.core.utils.UUIDs;
dao/src/main/java/org/thingsboard/server/dao/model/nosql/AlarmEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/AlarmEntity.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import com.datastax.driver.core.utils.UUIDs; 18 import com.datastax.driver.core.utils.UUIDs;
19 import com.datastax.driver.mapping.annotations.*; 19 import com.datastax.driver.mapping.annotations.*;
@@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSeverity; @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSeverity;
25 import org.thingsboard.server.common.data.alarm.AlarmStatus; 25 import org.thingsboard.server.common.data.alarm.AlarmStatus;
26 import org.thingsboard.server.common.data.id.EntityIdFactory; 26 import org.thingsboard.server.common.data.id.EntityIdFactory;
27 import org.thingsboard.server.common.data.id.TenantId; 27 import org.thingsboard.server.common.data.id.TenantId;
  28 +import org.thingsboard.server.dao.model.BaseEntity;
28 import org.thingsboard.server.dao.model.type.AlarmSeverityCodec; 29 import org.thingsboard.server.dao.model.type.AlarmSeverityCodec;
29 import org.thingsboard.server.dao.model.type.AlarmStatusCodec; 30 import org.thingsboard.server.dao.model.type.AlarmStatusCodec;
30 import org.thingsboard.server.dao.model.type.EntityTypeCodec; 31 import org.thingsboard.server.dao.model.type.EntityTypeCodec;
dao/src/main/java/org/thingsboard/server/dao/model/nosql/AssetEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/AssetEntity.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import com.datastax.driver.core.utils.UUIDs; 18 import com.datastax.driver.core.utils.UUIDs;
19 import com.datastax.driver.mapping.annotations.Column; 19 import com.datastax.driver.mapping.annotations.Column;
@@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.asset.Asset; @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.asset.Asset;
25 import org.thingsboard.server.common.data.id.AssetId; 25 import org.thingsboard.server.common.data.id.AssetId;
26 import org.thingsboard.server.common.data.id.CustomerId; 26 import org.thingsboard.server.common.data.id.CustomerId;
27 import org.thingsboard.server.common.data.id.TenantId; 27 import org.thingsboard.server.common.data.id.TenantId;
  28 +import org.thingsboard.server.dao.model.SearchTextEntity;
28 import org.thingsboard.server.dao.model.type.JsonCodec; 29 import org.thingsboard.server.dao.model.type.JsonCodec;
29 30
30 import java.util.UUID; 31 import java.util.UUID;
dao/src/main/java/org/thingsboard/server/dao/model/nosql/ComponentDescriptorEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/ComponentDescriptorEntity.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import com.datastax.driver.mapping.annotations.Column; 18 import com.datastax.driver.mapping.annotations.Column;
19 import com.datastax.driver.mapping.annotations.PartitionKey; 19 import com.datastax.driver.mapping.annotations.PartitionKey;
@@ -23,41 +23,44 @@ import org.thingsboard.server.common.data.id.ComponentDescriptorId; @@ -23,41 +23,44 @@ import org.thingsboard.server.common.data.id.ComponentDescriptorId;
23 import org.thingsboard.server.common.data.plugin.ComponentDescriptor; 23 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
24 import org.thingsboard.server.common.data.plugin.ComponentScope; 24 import org.thingsboard.server.common.data.plugin.ComponentScope;
25 import org.thingsboard.server.common.data.plugin.ComponentType; 25 import org.thingsboard.server.common.data.plugin.ComponentType;
  26 +import org.thingsboard.server.dao.model.SearchTextEntity;
26 import org.thingsboard.server.dao.model.type.JsonCodec; 27 import org.thingsboard.server.dao.model.type.JsonCodec;
27 28
28 import java.util.UUID; 29 import java.util.UUID;
29 30
  31 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  32 +
30 /** 33 /**
31 * @author Andrew Shvayka 34 * @author Andrew Shvayka
32 */ 35 */
33 -@Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME) 36 +@Table(name = COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME)
34 public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> { 37 public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> {
35 38
36 private static final long serialVersionUID = 1L; 39 private static final long serialVersionUID = 1L;
37 40
38 @PartitionKey 41 @PartitionKey
39 - @Column(name = ModelConstants.ID_PROPERTY) 42 + @Column(name = ID_PROPERTY)
40 private UUID id; 43 private UUID id;
41 44
42 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY) 45 + @Column(name = COMPONENT_DESCRIPTOR_TYPE_PROPERTY)
43 private ComponentType type; 46 private ComponentType type;
44 47
45 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY) 48 + @Column(name = COMPONENT_DESCRIPTOR_SCOPE_PROPERTY)
46 private ComponentScope scope; 49 private ComponentScope scope;
47 50
48 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY) 51 + @Column(name = COMPONENT_DESCRIPTOR_NAME_PROPERTY)
49 private String name; 52 private String name;
50 53
51 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY) 54 + @Column(name = COMPONENT_DESCRIPTOR_CLASS_PROPERTY)
52 private String clazz; 55 private String clazz;
53 56
54 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, codec = JsonCodec.class) 57 + @Column(name = COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, codec = JsonCodec.class)
55 private JsonNode configurationDescriptor; 58 private JsonNode configurationDescriptor;
56 59
57 - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY) 60 + @Column(name = COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
58 private String actions; 61 private String actions;
59 62
60 - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) 63 + @Column(name = SEARCH_TEXT_PROPERTY)
61 private String searchText; 64 private String searchText;
62 65
63 public ComponentDescriptorEntity() { 66 public ComponentDescriptorEntity() {
dao/src/main/java/org/thingsboard/server/dao/model/nosql/CustomerEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/CustomerEntity.java
@@ -13,28 +13,14 @@ @@ -13,28 +13,14 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model;  
17 -  
18 -import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS2_PROPERTY;  
19 -import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS_PROPERTY;  
20 -import static org.thingsboard.server.dao.model.ModelConstants.CITY_PROPERTY;  
21 -import static org.thingsboard.server.dao.model.ModelConstants.COUNTRY_PROPERTY;  
22 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY;  
23 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME;  
24 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TENANT_ID_PROPERTY;  
25 -import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TITLE_PROPERTY;  
26 -import static org.thingsboard.server.dao.model.ModelConstants.EMAIL_PROPERTY;  
27 -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY;  
28 -import static org.thingsboard.server.dao.model.ModelConstants.PHONE_PROPERTY;  
29 -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;  
30 -import static org.thingsboard.server.dao.model.ModelConstants.STATE_PROPERTY;  
31 -import static org.thingsboard.server.dao.model.ModelConstants.ZIP_PROPERTY; 16 +package org.thingsboard.server.dao.model.nosql;
32 17
33 import java.util.UUID; 18 import java.util.UUID;
34 19
35 import org.thingsboard.server.common.data.Customer; 20 import org.thingsboard.server.common.data.Customer;
36 import org.thingsboard.server.common.data.id.CustomerId; 21 import org.thingsboard.server.common.data.id.CustomerId;
37 import org.thingsboard.server.common.data.id.TenantId; 22 import org.thingsboard.server.common.data.id.TenantId;
  23 +import org.thingsboard.server.dao.model.SearchTextEntity;
38 import org.thingsboard.server.dao.model.type.JsonCodec; 24 import org.thingsboard.server.dao.model.type.JsonCodec;
39 25
40 import com.datastax.driver.core.utils.UUIDs; 26 import com.datastax.driver.core.utils.UUIDs;
@@ -44,6 +30,8 @@ import com.datastax.driver.mapping.annotations.Table; @@ -44,6 +30,8 @@ import com.datastax.driver.mapping.annotations.Table;
44 import com.datastax.driver.mapping.annotations.Transient; 30 import com.datastax.driver.mapping.annotations.Transient;
45 import com.fasterxml.jackson.databind.JsonNode; 31 import com.fasterxml.jackson.databind.JsonNode;
46 32
  33 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  34 +
47 @Table(name = CUSTOMER_COLUMN_FAMILY_NAME) 35 @Table(name = CUSTOMER_COLUMN_FAMILY_NAME)
48 public final class CustomerEntity implements SearchTextEntity<Customer> { 36 public final class CustomerEntity implements SearchTextEntity<Customer> {
49 37
dao/src/main/java/org/thingsboard/server/dao/model/nosql/DashboardEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/DashboardEntity.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import java.util.UUID; 18 import java.util.UUID;
19 19
@@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.Dashboard; @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.Dashboard;
21 import org.thingsboard.server.common.data.id.CustomerId; 21 import org.thingsboard.server.common.data.id.CustomerId;
22 import org.thingsboard.server.common.data.id.DashboardId; 22 import org.thingsboard.server.common.data.id.DashboardId;
23 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
  24 +import org.thingsboard.server.dao.model.SearchTextEntity;
24 import org.thingsboard.server.dao.model.type.JsonCodec; 25 import org.thingsboard.server.dao.model.type.JsonCodec;
25 26
26 import com.datastax.driver.core.utils.UUIDs; 27 import com.datastax.driver.core.utils.UUIDs;
@@ -30,31 +31,33 @@ import com.datastax.driver.mapping.annotations.Table; @@ -30,31 +31,33 @@ import com.datastax.driver.mapping.annotations.Table;
30 import com.datastax.driver.mapping.annotations.Transient; 31 import com.datastax.driver.mapping.annotations.Transient;
31 import com.fasterxml.jackson.databind.JsonNode; 32 import com.fasterxml.jackson.databind.JsonNode;
32 33
33 -@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) 34 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  35 +
  36 +@Table(name = DASHBOARD_COLUMN_FAMILY_NAME)
34 public final class DashboardEntity implements SearchTextEntity<Dashboard> { 37 public final class DashboardEntity implements SearchTextEntity<Dashboard> {
35 38
36 @Transient 39 @Transient
37 private static final long serialVersionUID = 2998395951247446191L; 40 private static final long serialVersionUID = 2998395951247446191L;
38 41
39 @PartitionKey(value = 0) 42 @PartitionKey(value = 0)
40 - @Column(name = ModelConstants.ID_PROPERTY) 43 + @Column(name = ID_PROPERTY)
41 private UUID id; 44 private UUID id;
42 45
43 @PartitionKey(value = 1) 46 @PartitionKey(value = 1)
44 - @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) 47 + @Column(name = DASHBOARD_TENANT_ID_PROPERTY)
45 private UUID tenantId; 48 private UUID tenantId;
46 49
47 @PartitionKey(value = 2) 50 @PartitionKey(value = 2)
48 - @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) 51 + @Column(name = DASHBOARD_CUSTOMER_ID_PROPERTY)
49 private UUID customerId; 52 private UUID customerId;
50 53
51 - @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) 54 + @Column(name = DASHBOARD_TITLE_PROPERTY)
52 private String title; 55 private String title;
53 56
54 - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) 57 + @Column(name = SEARCH_TEXT_PROPERTY)
55 private String searchText; 58 private String searchText;
56 59
57 - @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY, codec = JsonCodec.class) 60 + @Column(name = DASHBOARD_CONFIGURATION_PROPERTY, codec = JsonCodec.class)
58 private JsonNode configuration; 61 private JsonNode configuration;
59 62
60 public DashboardEntity() { 63 public DashboardEntity() {
dao/src/main/java/org/thingsboard/server/dao/model/nosql/DashboardInfoEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/model/DashboardInfoEntity.java
@@ -13,46 +13,46 @@ @@ -13,46 +13,46 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.dao.model; 16 +package org.thingsboard.server.dao.model.nosql;
17 17
18 import java.util.UUID; 18 import java.util.UUID;
19 19
20 -import org.thingsboard.server.common.data.Dashboard;  
21 import org.thingsboard.server.common.data.DashboardInfo; 20 import org.thingsboard.server.common.data.DashboardInfo;
22 import org.thingsboard.server.common.data.id.CustomerId; 21 import org.thingsboard.server.common.data.id.CustomerId;
23 import org.thingsboard.server.common.data.id.DashboardId; 22 import org.thingsboard.server.common.data.id.DashboardId;
24 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
25 -import org.thingsboard.server.dao.model.type.JsonCodec; 24 +import org.thingsboard.server.dao.model.SearchTextEntity;
26 25
27 import com.datastax.driver.core.utils.UUIDs; 26 import com.datastax.driver.core.utils.UUIDs;
28 import com.datastax.driver.mapping.annotations.Column; 27 import com.datastax.driver.mapping.annotations.Column;
29 import com.datastax.driver.mapping.annotations.PartitionKey; 28 import com.datastax.driver.mapping.annotations.PartitionKey;
30 import com.datastax.driver.mapping.annotations.Table; 29 import com.datastax.driver.mapping.annotations.Table;
31 import com.datastax.driver.mapping.annotations.Transient; 30 import com.datastax.driver.mapping.annotations.Transient;
32 -import com.fasterxml.jackson.databind.JsonNode;  
33 31
34 -@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) 32 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  33 +
  34 +@Table(name = DASHBOARD_COLUMN_FAMILY_NAME)
35 public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { 35 public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
36 36
37 @Transient 37 @Transient
38 private static final long serialVersionUID = 2998395951247446191L; 38 private static final long serialVersionUID = 2998395951247446191L;
39 39
40 @PartitionKey(value = 0) 40 @PartitionKey(value = 0)
41 - @Column(name = ModelConstants.ID_PROPERTY) 41 + @Column(name = ID_PROPERTY)
42 private UUID id; 42 private UUID id;
43 43
44 @PartitionKey(value = 1) 44 @PartitionKey(value = 1)
45 - @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) 45 + @Column(name = DASHBOARD_TENANT_ID_PROPERTY)
46 private UUID tenantId; 46 private UUID tenantId;
47 47
48 @PartitionKey(value = 2) 48 @PartitionKey(value = 2)
49 - @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) 49 + @Column(name = DASHBOARD_CUSTOMER_ID_PROPERTY)
50 private UUID customerId; 50 private UUID customerId;
51 51
52 - @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) 52 + @Column(name = DASHBOARD_TITLE_PROPERTY)
53 private String title; 53 private String title;
54 54
55 - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) 55 + @Column(name = SEARCH_TEXT_PROPERTY)
56 private String searchText; 56 private String searchText;
57 57
58 public DashboardInfoEntity() { 58 public DashboardInfoEntity() {