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 241 <artifactId>mockito-all</artifactId>
242 242 <scope>test</scope>
243 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 259 </dependencies>
245 260
246 261 <build>
... ...
... ... @@ -16,15 +16,13 @@
16 16 package org.thingsboard.server;
17 17
18 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 20 import org.springframework.context.annotation.ComponentScan;
22 21 import springfox.documentation.swagger2.annotations.EnableSwagger2;
23 22
24 23 import java.util.Arrays;
25 24
26   -@EnableAutoConfiguration
27   -@SpringBootApplication
  25 +@SpringBootConfiguration
28 26 @EnableSwagger2
29 27 @ComponentScan({"org.thingsboard.server"})
30 28 public class ThingsboardServerApplication {
... ...
... ... @@ -15,15 +15,7 @@
15 15 */
16 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 19 import com.google.common.base.Function;
28 20 import com.google.common.util.concurrent.FutureCallback;
29 21 import com.google.common.util.concurrent.Futures;
... ... @@ -45,8 +37,8 @@ import org.thingsboard.server.common.data.rule.RuleMetaData;
45 37 import org.thingsboard.server.common.msg.cluster.ServerAddress;
46 38 import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg;
47 39 import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext;
48   -import org.thingsboard.server.extensions.api.plugins.PluginContext;
49 40 import org.thingsboard.server.extensions.api.plugins.PluginCallback;
  41 +import org.thingsboard.server.extensions.api.plugins.PluginContext;
50 42 import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg;
51 43 import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg;
52 44 import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest;
... ... @@ -55,9 +47,12 @@ import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg;
55 47 import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef;
56 48 import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg;
57 49
58   -import akka.actor.ActorRef;
59   -
60 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 57 @Slf4j
63 58 public final class PluginProcessingContext implements PluginContext {
... ... @@ -95,8 +90,8 @@ public final class PluginProcessingContext implements PluginContext {
95 90 @Override
96 91 public void saveAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<AttributeKvEntry> attributes, final PluginCallback<Void> callback) {
97 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 95 if (entityId.getEntityType() == EntityType.DEVICE) {
101 96 onDeviceAttributesChanged(tenantId, new DeviceId(entityId.getId()), scope, attributes);
102 97 }
... ... @@ -108,8 +103,8 @@ public final class PluginProcessingContext implements PluginContext {
108 103 @Override
109 104 public void removeAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<String> keys, final PluginCallback<Void> callback) {
110 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 108 if (entityId.getEntityType() == EntityType.DEVICE) {
114 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 156 @Override
162 157 public void saveTsData(final EntityId entityId, final TsKvEntry entry, final PluginCallback<Void> callback) {
163 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 160 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor);
166 161 }));
167 162 }
... ... @@ -174,7 +169,7 @@ public final class PluginProcessingContext implements PluginContext {
174 169 @Override
175 170 public void saveTsData(final EntityId entityId, final List<TsKvEntry> entries, long ttl, final PluginCallback<Void> callback) {
176 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 173 Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor);
179 174 }));
180 175 }
... ... @@ -191,26 +186,16 @@ public final class PluginProcessingContext implements PluginContext {
191 186 @Override
192 187 public void loadLatestTimeseries(final EntityId entityId, final PluginCallback<List<TsKvEntry>> callback) {
193 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 194 @Override
200 195 public void loadLatestTimeseries(final EntityId entityId, final Collection<String> keys, final PluginCallback<List<TsKvEntry>> callback) {
201 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 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 227 @Override
243   - public void onSuccess(@Nullable List<ResultSet> result) {
  228 + public void onSuccess(@Nullable List<T> result) {
244 229 pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, transformer.apply(result)), ActorRef.noSender());
245 230 }
246 231
... ...
... ... @@ -15,8 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
18   -import com.fasterxml.jackson.databind.JsonNode;
19   -import com.fasterxml.jackson.databind.ObjectMapper;
20 18 import lombok.extern.slf4j.Slf4j;
21 19 import org.apache.commons.lang3.StringUtils;
22 20 import org.springframework.beans.factory.annotation.Autowired;
... ...
... ... @@ -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 84 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
71 85 @RequestMapping(value = "/customer", method = RequestMethod.POST)
72 86 @ResponseBody
... ...
... ... @@ -25,7 +25,6 @@ import org.thingsboard.server.common.data.page.TextPageLink;
25 25 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
26 26 import org.thingsboard.server.common.data.plugin.PluginMetaData;
27 27 import org.thingsboard.server.common.data.security.Authority;
28   -import org.thingsboard.server.common.data.widget.WidgetsBundle;
29 28 import org.thingsboard.server.dao.model.ModelConstants;
30 29 import org.thingsboard.server.exception.ThingsboardException;
31 30
... ...
... ... @@ -15,34 +15,31 @@
15 15 */
16 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 19 import lombok.extern.slf4j.Slf4j;
27 20 import org.apache.commons.lang3.StringUtils;
28 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 22 import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.beans.factory.annotation.Qualifier;
38 24 import org.springframework.context.MessageSource;
39 25 import org.springframework.core.NestedRuntimeException;
40 26 import org.springframework.mail.javamail.JavaMailSenderImpl;
41 27 import org.springframework.mail.javamail.MimeMessageHelper;
42 28 import org.springframework.stereotype.Service;
43 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 43 @Service
47 44 @Slf4j
48 45 public class DefaultMailService implements MailService {
... ... @@ -69,9 +66,13 @@ public class DefaultMailService implements MailService {
69 66 @Override
70 67 public void updateMailConfiguration() {
71 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 78 private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) {
... ...
... ... @@ -107,6 +107,7 @@ coap:
107 107
108 108 # Cassandra driver configuration parameters
109 109 cassandra:
  110 + enabled: "${CASSANDRA_ENABLED:false}"
110 111 # Thingsboard cluster name
111 112 cluster_name: "${CASSANDRA_CLUSTER_NAME:Thingsboard Cluster}"
112 113 # Thingsboard keyspace name
... ... @@ -152,7 +153,7 @@ cassandra:
152 153 # Specify partitioning size for timestamp key-value storage. Example MINUTES, HOURS, DAYS, MONTHS
153 154 ts_key_value_partitioning: "${TS_KV_PARTITIONING:MONTHS}"
154 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 158 # Actor system parameters
158 159 actors:
... ... @@ -222,3 +223,24 @@ spring.mvc.cors:
222 223 allowed-headers: "*"
223 224 max-age: "1800"
224 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}"
\ No newline at end of file
... ...
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 28 import org.junit.Assert;
29 29 import org.junit.Before;
30 30 import org.junit.runner.RunWith;
31   -import org.mockito.Mockito;
32   -import org.mockito.invocation.InvocationOnMock;
33   -import org.mockito.stubbing.Answer;
34 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 34 import org.springframework.context.annotation.ComponentScan;
40 35 import org.springframework.context.annotation.Configuration;
41 36 import org.springframework.http.HttpHeaders;
... ... @@ -48,7 +43,7 @@ import org.springframework.test.annotation.DirtiesContext;
48 43 import org.springframework.test.context.ActiveProfiles;
49 44 import org.springframework.test.context.ContextConfiguration;
50 45 import org.springframework.test.context.TestPropertySource;
51   -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  46 +import org.springframework.test.context.junit4.SpringRunner;
52 47 import org.springframework.test.context.web.WebAppConfiguration;
53 48 import org.springframework.test.web.servlet.MockMvc;
54 49 import org.springframework.test.web.servlet.ResultActions;
... ... @@ -66,11 +61,9 @@ import org.thingsboard.server.common.data.id.UUIDBased;
66 61 import org.thingsboard.server.common.data.page.TextPageLink;
67 62 import org.thingsboard.server.common.data.security.Authority;
68 63 import org.thingsboard.server.config.ThingsboardSecurityConfiguration;
69   -import org.thingsboard.server.exception.ThingsboardException;
70   -import org.thingsboard.server.service.mail.MailService;
71 64 import org.thingsboard.server.service.mail.TestMailService;
72   -import org.thingsboard.server.service.security.auth.rest.LoginRequest;
73 65 import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest;
  66 +import org.thingsboard.server.service.security.auth.rest.LoginRequest;
74 67
75 68 import java.io.IOException;
76 69 import java.nio.charset.Charset;
... ... @@ -81,21 +74,18 @@ import java.util.List;
81 74
82 75 import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
83 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 78 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
88 79
89 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 84 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
94 85 @Configuration
95   -@EnableAutoConfiguration
96 86 @ComponentScan({"org.thingsboard.server"})
97 87 @WebAppConfiguration
98   -@IntegrationTest("server.port:0")
  88 +@SpringBootTest
99 89 public abstract class AbstractControllerTest {
100 90
101 91 protected static final String TEST_TENANT_NAME = "TEST TENANT";
... ... @@ -113,7 +103,6 @@ public abstract class AbstractControllerTest {
113 103 MediaType.APPLICATION_JSON.getSubtype(),
114 104 Charset.forName("utf8"));
115 105
116   -
117 106 protected MockMvc mockMvc;
118 107
119 108 protected String token;
... ... @@ -305,7 +294,7 @@ public abstract class AbstractControllerTest {
305 294 protected <T> T doPost(String urlTemplate, T content, Class<T> responseClass, String... params) throws Exception {
306 295 return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass);
307 296 }
308   -
  297 +
309 298 protected <T> T doDelete(String urlTemplate, Class<T> responseClass, String... params) throws Exception {
310 299 return readResponse(doDelete(urlTemplate, params).andExpect(status().isOk()), responseClass);
311 300 }
... ... @@ -364,8 +353,8 @@ public abstract class AbstractControllerTest {
364 353 ObjectMapper mapper = new ObjectMapper();
365 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 358 @Override
370 359 public int compare(D o1, D o2) {
371 360 return o1.getId().getId().compareTo(o2.getId().getId());
... ...
... ... @@ -28,7 +28,6 @@ import org.thingsboard.server.common.data.*;
28 28 import org.thingsboard.server.common.data.asset.Asset;
29 29 import org.thingsboard.server.common.data.asset.TenantAssetType;
30 30 import org.thingsboard.server.common.data.id.CustomerId;
31   -import org.thingsboard.server.common.data.id.AssetId;
32 31 import org.thingsboard.server.common.data.page.TextPageData;
33 32 import org.thingsboard.server.common.data.page.TextPageLink;
34 33 import org.thingsboard.server.common.data.security.Authority;
... ...
... ... @@ -18,22 +18,22 @@ package org.thingsboard.server.controller;
18 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
19 19 import org.junit.ClassRule;
20 20 import org.junit.extensions.cpsuite.ClasspathSuite;
21   -import org.junit.extensions.cpsuite.ClasspathSuite.ClassnameFilters;
22 21 import org.junit.runner.RunWith;
23 22 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
24 23
25 24 import java.util.Arrays;
26 25
27 26 @RunWith(ClasspathSuite.class)
28   -@ClassnameFilters({"org.thingsboard.server.controller.*Test"})
  27 +@ClasspathSuite.ClassnameFilters({
  28 + "org.thingsboard.server.controller.*Test"})
29 29 public class ControllerTestSuite {
30 30
31 31 @ClassRule
32 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 38 "cassandra-test.yaml", 30000l);
38   -
39 39 }
... ...
... ... @@ -23,6 +23,7 @@ import java.util.ArrayList;
23 23 import java.util.Collections;
24 24 import java.util.List;
25 25
  26 +import com.datastax.driver.core.utils.UUIDs;
26 27 import org.apache.commons.lang3.RandomStringUtils;
27 28 import org.thingsboard.server.common.data.*;
28 29 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -35,7 +36,6 @@ import org.junit.Assert;
35 36 import org.junit.Before;
36 37 import org.junit.Test;
37 38
38   -import com.datastax.driver.core.utils.UUIDs;
39 39 import com.fasterxml.jackson.core.type.TypeReference;
40 40
41 41 public class DashboardControllerTest extends AbstractControllerTest {
... ... @@ -155,7 +155,7 @@ public class DashboardControllerTest extends AbstractControllerTest {
155 155 dashboard.setTitle("My dashboard");
156 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 159 + "/dashboard/" + savedDashboard.getId().getId().toString())
160 160 .andExpect(status().isNotFound());
161 161 }
... ...
... ... @@ -23,6 +23,7 @@ import java.util.ArrayList;
23 23 import java.util.Collections;
24 24 import java.util.List;
25 25
  26 +import com.datastax.driver.core.utils.UUIDs;
26 27 import org.apache.commons.lang3.RandomStringUtils;
27 28 import org.thingsboard.server.common.data.*;
28 29 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -39,7 +40,6 @@ import org.junit.Assert;
39 40 import org.junit.Before;
40 41 import org.junit.Test;
41 42
42   -import com.datastax.driver.core.utils.UUIDs;
43 43 import com.fasterxml.jackson.core.type.TypeReference;
44 44
45 45 public class DeviceControllerTest extends AbstractControllerTest {
... ... @@ -215,7 +215,7 @@ public class DeviceControllerTest extends AbstractControllerTest {
215 215 device.setType("default");
216 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 219 + "/device/" + savedDevice.getId().getId().toString())
220 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 23
24 24 import java.util.Arrays;
25 25
26   -/**
27   - * @author Valerii Sosliuk
28   - */
29 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 31 @ClassRule
34 32 public static CustomCassandraCQLUnit cassandraUnit =
35 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 37 "cassandra-test.yaml", 30000l);
40   -
41 38 }
... ...
... ... @@ -17,47 +17,67 @@ package org.thingsboard.server.mqtt.rpc;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
19 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 21 import org.springframework.http.HttpStatus;
25   -import org.springframework.http.ResponseEntity;
26 22 import org.springframework.web.client.HttpClientErrorException;
27   -import org.thingsboard.client.tools.RestClient;
28 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 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 30 import java.util.UUID;
33 31
34 32 import static org.junit.Assert.assertEquals;
35 33 import static org.junit.Assert.assertNotNull;
  34 +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36 35
37 36 /**
38 37 * @author Valerii Sosliuk
39 38 */
40 39 @Slf4j
41   -public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegrationTest {
  40 +public class MqttServerSideRpcIntegrationTest extends AbstractControllerTest {
42 41
43 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 48 @Before
52 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 75 @Test
  76 + @Ignore
58 77 public void testServerMqttOneWayRpc() throws Exception {
59 78 Device device = new Device();
60 79 device.setName("Test One-Way Server-Side RPC");
  80 + device.setType("default");
61 81 Device savedDevice = getSavedDevice(device);
62 82 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
63 83 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
... ... @@ -69,22 +89,22 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
69 89
70 90 MqttConnectOptions options = new MqttConnectOptions();
71 91 options.setUserName(accessToken);
72   - client.connect(options);
73   - Thread.sleep(3000);
  92 + client.connect(options).waitForCompletion();
74 93 client.subscribe("v1/devices/me/rpc/request/+", 1);
75 94 client.setCallback(new TestMqttCallback(client));
76 95
77 96 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
78 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 102 @Test
  103 + @Ignore
85 104 public void testServerMqttOneWayRpcDeviceOffline() throws Exception {
86 105 Device device = new Device();
87 106 device.setName("Test One-Way Server-Side RPC Device Offline");
  107 + device.setType("default");
88 108 Device savedDevice = getSavedDevice(device);
89 109 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
90 110 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
... ... @@ -94,8 +114,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
94 114 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
95 115 String deviceId = savedDevice.getId().getId().toString();
96 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 119 } catch (HttpClientErrorException e) {
100 120 log.error(e.getMessage(), e);
101 121 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode());
... ... @@ -104,12 +124,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
104 124 }
105 125
106 126 @Test
  127 + @Ignore
107 128 public void testServerMqttOneWayRpcDeviceDoesNotExist() throws Exception {
108 129 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
109 130 String nonExistentDeviceId = UUID.randomUUID().toString();
110 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 134 } catch (HttpClientErrorException e) {
114 135 log.error(e.getMessage(), e);
115 136 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
... ... @@ -118,10 +139,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
118 139 }
119 140
120 141 @Test
  142 + @Ignore
121 143 public void testServerMqttTwoWayRpc() throws Exception {
122   -
123 144 Device device = new Device();
124 145 device.setName("Test Two-Way Server-Side RPC");
  146 + device.setType("default");
125 147 Device savedDevice = getSavedDevice(device);
126 148 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
127 149 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
... ... @@ -133,8 +155,7 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
133 155
134 156 MqttConnectOptions options = new MqttConnectOptions();
135 157 options.setUserName(accessToken);
136   - client.connect(options);
137   - Thread.sleep(3000);
  158 + client.connect(options).waitForCompletion();
138 159 client.subscribe("v1/devices/me/rpc/request/+", 1);
139 160 client.setCallback(new TestMqttCallback(client));
140 161
... ... @@ -145,9 +166,11 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
145 166 }
146 167
147 168 @Test
  169 + @Ignore
148 170 public void testServerMqttTwoWayRpcDeviceOffline() throws Exception {
149 171 Device device = new Device();
150 172 device.setName("Test Two-Way Server-Side RPC Device Offline");
  173 + device.setType("default");
151 174 Device savedDevice = getSavedDevice(device);
152 175 DeviceCredentials deviceCredentials = getDeviceCredentials(savedDevice);
153 176 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
... ... @@ -157,8 +180,8 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
157 180 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
158 181 String deviceId = savedDevice.getId().getId().toString();
159 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 185 } catch (HttpClientErrorException e) {
163 186 log.error(e.getMessage(), e);
164 187 Assert.assertEquals(HttpStatus.REQUEST_TIMEOUT, e.getStatusCode());
... ... @@ -167,12 +190,13 @@ public class MqttServerSideRpcIntegrationTest extends AbstractFeatureIntegration
167 190 }
168 191
169 192 @Test
  193 + @Ignore
170 194 public void testServerMqttTwoWayRpcDeviceDoesNotExist() throws Exception {
171 195 String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}";
172 196 String nonExistentDeviceId = UUID.randomUUID().toString();
173 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 200 } catch (HttpClientErrorException e) {
177 201 log.error(e.getMessage(), e);
178 202 Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
... ... @@ -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 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 20 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
21 21 import org.eclipse.paho.client.mqttv3.MqttMessage;
22 22 import org.junit.Before;
  23 +import org.junit.Ignore;
23 24 import org.junit.Test;
24 25 import org.springframework.web.util.UriComponentsBuilder;
25   -import org.thingsboard.client.tools.RestClient;
26 26 import org.thingsboard.server.common.data.Device;
27 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 30 import java.net.URI;
31 31 import java.util.Arrays;
... ... @@ -39,35 +39,32 @@ import static org.junit.Assert.assertNotNull;
39 39 * @author Valerii Sosliuk
40 40 */
41 41 @Slf4j
42   -public class MqttTelemetryIntergrationTest extends AbstractFeatureIntegrationTest {
  42 +public class MqttTelemetryIntegrationTest extends AbstractControllerTest {
43 43
44 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 46 private Device savedDevice;
51   -
52 47 private String accessToken;
53   - private RestClient restClient;
54 48
55 49 @Before
56 50 public void beforeTest() throws Exception {
57   - restClient = new RestClient(BASE_URL);
58   - restClient.login(USERNAME, PASSWORD);
  51 + loginTenantAdmin();
59 52
60 53 Device device = new Device();
61 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 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 61 assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
66 62 accessToken = deviceCredentials.getCredentialsId();
67 63 assertNotNull(accessToken);
68 64 }
69 65
70 66 @Test
  67 + @Ignore
71 68 public void testPushMqttRpcData() throws Exception {
72 69 String clientId = MqttAsyncClient.generateClientId();
73 70 MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId);
... ... @@ -83,13 +80,13 @@ public class MqttTelemetryIntergrationTest extends AbstractFeatureIntegrationTes
83 80 String deviceId = savedDevice.getId().getId().toString();
84 81
85 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 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 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 91 assertEquals("value1", values.get("key1").get(0).get("value"));
95 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 35 /**
36 36 * @author Andrew Shvayka
37 37 */
38   -public class HttpDeviceApiTest extends AbstractControllerTest {
  38 +public abstract class BaseHttpDeviceApiTest extends AbstractControllerTest {
39 39
40 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 27 * @author Andrew Shvayka
28 28 */
29 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 33 @ClassRule
34 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 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 +}
... ...
1   -updates.enabled=false
\ No newline at end of file
... ... @@ -17,6 +17,8 @@ package org.thingsboard.server.common.data.asset;
17 17
18 18 import org.thingsboard.server.common.data.id.TenantId;
19 19
  20 +import java.util.UUID;
  21 +
20 22 public class TenantAssetType {
21 23
22 24 private static final long serialVersionUID = 8057290243855622101L;
... ... @@ -33,6 +35,11 @@ public class TenantAssetType {
33 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 43 public String getType() {
37 44 return type;
38 45 }
... ...
... ... @@ -15,8 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.common.data.kv;
17 17
18   -import java.util.Optional;
19   -
20 18 public interface TsKvQuery {
21 19
22 20 String getKey();
... ...
... ... @@ -18,8 +18,6 @@ package org.thingsboard.server.common.data.relation;
18 18 import com.fasterxml.jackson.databind.JsonNode;
19 19 import org.thingsboard.server.common.data.id.EntityId;
20 20
21   -import java.util.Objects;
22   -
23 21 public class EntityRelation {
24 22
25 23 private static final long serialVersionUID = 2807343040519543363L;
... ...
... ... @@ -15,15 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.common.data.rule;
17 17
  18 +import com.fasterxml.jackson.databind.JsonNode;
18 19 import lombok.Data;
19   -import lombok.ToString;
20 20 import org.thingsboard.server.common.data.HasName;
21 21 import org.thingsboard.server.common.data.SearchTextBased;
22   -import org.thingsboard.server.common.data.id.CustomerId;
23 22 import org.thingsboard.server.common.data.id.RuleId;
24 23 import org.thingsboard.server.common.data.id.TenantId;
25   -
26   -import com.fasterxml.jackson.databind.JsonNode;
27 24 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
28 25
29 26 @Data
... ...
... ... @@ -57,8 +57,8 @@
57 57 <artifactId>logback-classic</artifactId>
58 58 </dependency>
59 59 <dependency>
60   - <groupId>org.springframework</groupId>
61   - <artifactId>spring-test</artifactId>
  60 + <groupId>org.postgresql</groupId>
  61 + <artifactId>postgresql</artifactId>
62 62 </dependency>
63 63 <dependency>
64 64 <groupId>junit</groupId>
... ... @@ -66,6 +66,16 @@
66 66 <scope>test</scope>
67 67 </dependency>
68 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 79 <groupId>org.mockito</groupId>
70 80 <artifactId>mockito-all</artifactId>
71 81 <scope>test</scope>
... ... @@ -150,6 +160,20 @@
150 160 <groupId>org.bouncycastle</groupId>
151 161 <artifactId>bcprov-jdk15on</artifactId>
152 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 177 </dependencies>
154 178 <build>
155 179 <plugins>
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao;
17 17
18   -import com.datastax.driver.core.ResultSet;
19 18 import com.google.common.util.concurrent.ListenableFuture;
20 19
21 20 import java.util.List;
... ... @@ -31,6 +30,6 @@ public interface Dao<T> {
31 30
32 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 */
16 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 18 import org.thingsboard.server.common.data.id.UUIDBased;
25 19 import org.thingsboard.server.dao.model.ToData;
26 20
  21 +import java.util.*;
  22 +
27 23 public abstract class DaoUtil {
28 24
29 25 private DaoUtil() {
... ... @@ -34,7 +30,9 @@ public abstract class DaoUtil {
34 30 if (toDataList != null && !toDataList.isEmpty()) {
35 31 list = new ArrayList<>();
36 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 38 return list;
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao;
17 17
18   -import com.google.common.base.CharMatcher;
19 18 import lombok.extern.slf4j.Slf4j;
20 19 import org.bouncycastle.crypto.digests.SHA3Digest;
21 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 22 import org.thingsboard.server.common.data.id.EntityId;
23 23 import org.thingsboard.server.common.data.id.TenantId;
24 24 import org.thingsboard.server.dao.Dao;
25   -import org.thingsboard.server.dao.model.AlarmEntity;
26 25
27 26 import java.util.List;
28 27 import java.util.UUID;
... ... @@ -30,13 +29,13 @@ import java.util.UUID;
30 29 /**
31 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 34 ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
36 35
37 36 ListenableFuture<Alarm> findAlarmByIdAsync(UUID key);
38 37
39   - AlarmEntity save(Alarm alarm);
  38 + Alarm save(Alarm alarm);
40 39
41 40 ListenableFuture<List<AlarmInfo>> findAlarms(AlarmQuery query);
42 41 }
... ...
... ... @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
24 24 import org.springframework.beans.factory.annotation.Autowired;
25 25 import org.springframework.stereotype.Service;
26 26 import org.springframework.util.StringUtils;
  27 +import org.thingsboard.server.common.data.Tenant;
27 28 import org.thingsboard.server.common.data.alarm.*;
28 29 import org.thingsboard.server.common.data.id.EntityId;
29 30 import org.thingsboard.server.common.data.page.TimePageData;
... ... @@ -31,10 +32,8 @@ import org.thingsboard.server.common.data.page.TimePageLink;
31 32 import org.thingsboard.server.common.data.relation.EntityRelation;
32 33 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
33 34 import org.thingsboard.server.dao.entity.AbstractEntityService;
34   -import org.thingsboard.server.dao.entity.BaseEntityService;
35 35 import org.thingsboard.server.dao.entity.EntityService;
36 36 import org.thingsboard.server.dao.exception.DataValidationException;
37   -import org.thingsboard.server.dao.model.*;
38 37 import org.thingsboard.server.dao.relation.EntityRelationsQuery;
39 38 import org.thingsboard.server.dao.relation.EntitySearchDirection;
40 39 import org.thingsboard.server.dao.relation.RelationService;
... ... @@ -53,8 +52,7 @@ import java.util.concurrent.ExecutorService;
53 52 import java.util.concurrent.Executors;
54 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 57 @Service
60 58 @Slf4j
... ... @@ -115,7 +113,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
115 113
116 114 private Alarm createAlarm(Alarm alarm) throws InterruptedException, ExecutionException {
117 115 log.debug("New Alarm : {}", alarm);
118   - Alarm saved = getData(alarmDao.save(new AlarmEntity(alarm)));
  116 + Alarm saved = alarmDao.save(alarm);
119 117 EntityRelationsQuery query = new EntityRelationsQuery();
120 118 query.setParameters(new RelationsSearchParameters(saved.getOriginator(), EntitySearchDirection.TO, Integer.MAX_VALUE));
121 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 142 private Alarm updateAlarm(Alarm oldAlarm, Alarm newAlarm) {
145 143 AlarmStatus oldStatus = oldAlarm.getStatus();
146 144 AlarmStatus newStatus = newAlarm.getStatus();
147   - AlarmEntity result = alarmDao.save(new AlarmEntity(merge(oldAlarm, newAlarm)));
  145 + Alarm result = alarmDao.save(merge(oldAlarm, newAlarm));
148 146 if (oldStatus != newStatus) {
149 147 updateRelations(oldAlarm, oldStatus, newStatus);
150 148 }
151   - return result.toData();
  149 + return result;
152 150 }
153 151
154 152 @Override
... ... @@ -164,7 +162,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
164 162 AlarmStatus newStatus = oldStatus.isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK;
165 163 alarm.setStatus(newStatus);
166 164 alarm.setAckTs(ackTime);
167   - alarmDao.save(new AlarmEntity(alarm));
  165 + alarmDao.save(alarm);
168 166 updateRelations(alarm, oldStatus, newStatus);
169 167 return true;
170 168 }
... ... @@ -185,7 +183,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
185 183 AlarmStatus newStatus = oldStatus.isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK;
186 184 alarm.setStatus(newStatus);
187 185 alarm.setClearTs(clearTime);
188   - alarmDao.save(new AlarmEntity(alarm));
  186 + alarmDao.save(alarm);
189 187 updateRelations(alarm, oldStatus, newStatus);
190 188 return true;
191 189 }
... ... @@ -387,7 +385,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
387 385 if (alarm.getTenantId() == null) {
388 386 throw new DataValidationException("Alarm should be assigned to tenant!");
389 387 } else {
390   - TenantEntity tenant = tenantDao.findById(alarm.getTenantId().getId());
  388 + Tenant tenant = tenantDao.findById(alarm.getTenantId().getId());
391 389 if (tenant == null) {
392 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 33 import org.thingsboard.server.common.data.id.TenantId;
34 34 import org.thingsboard.server.common.data.relation.EntityRelation;
35 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 38 import org.thingsboard.server.dao.model.ModelConstants;
  39 +import org.thingsboard.server.dao.model.nosql.AlarmEntity;
40 40 import org.thingsboard.server.dao.relation.RelationDao;
41 41
42 42 import java.util.ArrayList;
... ... @@ -49,7 +49,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
49 49
50 50 @Component
51 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 55 @Autowired
55 56 private RelationDao relationDao;
... ... @@ -69,9 +70,9 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
69 70 }
70 71
71 72 @Override
72   - public AlarmEntity save(Alarm alarm) {
  73 + public Alarm save(Alarm alarm) {
73 74 log.debug("Save asset [{}] ", alarm);
74   - return save(new AlarmEntity(alarm));
  75 + return super.save(alarm);
75 76 }
76 77
77 78 @Override
... ... @@ -84,16 +85,7 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
84 85 query.and(eq(ALARM_TYPE_PROPERTY, type));
85 86 query.limit(1);
86 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 91 @Override
... ... @@ -114,10 +106,19 @@ public class AlarmDaoImpl extends AbstractModelDao<AlarmEntity> implements Alarm
114 106 List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
115 107 for (EntityRelation relation : input) {
116 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 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 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.thingsboard.server.common.data.asset.Asset;
  20 +import org.thingsboard.server.common.data.asset.TenantAssetType;
20 21 import org.thingsboard.server.common.data.page.TextPageLink;
21 22 import org.thingsboard.server.dao.Dao;
22   -import org.thingsboard.server.dao.model.AssetEntity;
23 23 import org.thingsboard.server.dao.model.TenantAssetTypeEntity;
24 24
25 25 import java.util.List;
... ... @@ -30,7 +30,7 @@ import java.util.UUID;
30 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 36 * Save or update asset object
... ... @@ -38,7 +38,7 @@ public interface AssetDao extends Dao<AssetEntity> {
38 38 * @param asset the asset object
39 39 * @return saved asset object
40 40 */
41   - AssetEntity save(Asset asset);
  41 + Asset save(Asset asset);
42 42
43 43 /**
44 44 * Find assets by tenantId and page link.
... ... @@ -47,7 +47,7 @@ public interface AssetDao extends Dao<AssetEntity> {
47 47 * @param pageLink the page link
48 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 53 * Find assets by tenantId, type and page link.
... ... @@ -57,7 +57,7 @@ public interface AssetDao extends Dao<AssetEntity> {
57 57 * @param pageLink the page link
58 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 63 * Find assets by tenantId and assets Ids.
... ... @@ -66,7 +66,7 @@ public interface AssetDao extends Dao<AssetEntity> {
66 66 * @param assetIds the asset Ids
67 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 72 * Find assets by tenantId, customerId and page link.
... ... @@ -76,7 +76,7 @@ public interface AssetDao extends Dao<AssetEntity> {
76 76 * @param pageLink the page link
77 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 82 * Find assets by tenantId, customerId, type and page link.
... ... @@ -87,7 +87,7 @@ public interface AssetDao extends Dao<AssetEntity> {
87 87 * @param pageLink the page link
88 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 93 * Find assets by tenantId, customerId and assets Ids.
... ... @@ -97,7 +97,7 @@ public interface AssetDao extends Dao<AssetEntity> {
97 97 * @param assetIds the asset Ids
98 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 103 * Find assets by tenantId and asset name.
... ... @@ -106,13 +106,13 @@ public interface AssetDao extends Dao<AssetEntity> {
106 106 * @param name the asset name
107 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 112 * Find tenants asset types.
113 113 *
114 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 23 import org.thingsboard.server.dao.relation.EntityTypeFilter;
24 24
25 25 import javax.annotation.Nullable;
26   -import java.util.ArrayList;
27 26 import java.util.Collections;
28 27 import java.util.List;
29 28
... ...
... ... @@ -24,7 +24,9 @@ import lombok.extern.slf4j.Slf4j;
24 24 import org.springframework.beans.factory.annotation.Autowired;
25 25 import org.springframework.stereotype.Service;
26 26 import org.springframework.util.StringUtils;
  27 +import org.thingsboard.server.common.data.Customer;
27 28 import org.thingsboard.server.common.data.EntityType;
  29 +import org.thingsboard.server.common.data.Tenant;
28 30 import org.thingsboard.server.common.data.asset.Asset;
29 31 import org.thingsboard.server.common.data.asset.TenantAssetType;
30 32 import org.thingsboard.server.common.data.id.AssetId;
... ... @@ -37,7 +39,6 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
37 39 import org.thingsboard.server.dao.customer.CustomerDao;
38 40 import org.thingsboard.server.dao.entity.AbstractEntityService;
39 41 import org.thingsboard.server.dao.exception.DataValidationException;
40   -import org.thingsboard.server.dao.model.*;
41 42 import org.thingsboard.server.dao.relation.EntitySearchDirection;
42 43 import org.thingsboard.server.dao.service.DataValidator;
43 44 import org.thingsboard.server.dao.service.PaginatedRemover;
... ... @@ -45,6 +46,7 @@ import org.thingsboard.server.dao.tenant.TenantDao;
45 46
46 47 import javax.annotation.Nullable;
47 48 import java.util.ArrayList;
  49 +import java.util.Comparator;
48 50 import java.util.List;
49 51 import java.util.Optional;
50 52 import java.util.stream.Collectors;
... ... @@ -70,35 +72,28 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
70 72 public Asset findAssetById(AssetId assetId) {
71 73 log.trace("Executing findAssetById [{}]", assetId);
72 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 78 @Override
78 79 public ListenableFuture<Asset> findAssetByIdAsync(AssetId assetId) {
79 80 log.trace("Executing findAssetById [{}]", assetId);
80 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 85 @Override
86 86 public Optional<Asset> findAssetByTenantIdAndName(TenantId tenantId, String name) {
87 87 log.trace("Executing findAssetByTenantIdAndName [{}][{}]", tenantId, name);
88 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 92 @Override
98 93 public Asset saveAsset(Asset asset) {
99 94 log.trace("Executing saveAsset [{}]", asset);
100 95 assetValidator.validate(asset);
101   - return getData(assetDao.save(asset));
  96 + return assetDao.save(asset);
102 97 }
103 98
104 99 @Override
... ... @@ -128,8 +123,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
128 123 log.trace("Executing findAssetsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
129 124 validateId(tenantId, "Incorrect tenantId " + tenantId);
130 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 127 return new TextPageData<>(assets, pageLink);
134 128 }
135 129
... ... @@ -139,8 +133,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
139 133 validateId(tenantId, "Incorrect tenantId " + tenantId);
140 134 validateString(type, "Incorrect type " + type);
141 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 137 return new TextPageData<>(assets, pageLink);
145 138 }
146 139
... ... @@ -149,15 +142,14 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
149 142 log.trace("Executing findAssetsByTenantIdAndIdsAsync, tenantId [{}], assetIds [{}]", tenantId, assetIds);
150 143 validateId(tenantId, "Incorrect tenantId " + tenantId);
151 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 148 @Override
157 149 public void deleteAssetsByTenantId(TenantId tenantId) {
158 150 log.trace("Executing deleteAssetsByTenantId, tenantId [{}]", tenantId);
159 151 validateId(tenantId, "Incorrect tenantId " + tenantId);
160   - tenantAssetsRemover.removeEntitites(tenantId);
  152 + tenantAssetsRemover.removeEntities(tenantId);
161 153 }
162 154
163 155 @Override
... ... @@ -166,9 +158,8 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
166 158 validateId(tenantId, "Incorrect tenantId " + tenantId);
167 159 validateId(customerId, "Incorrect customerId " + customerId);
168 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 165 @Override
... ... @@ -178,20 +169,17 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
178 169 validateId(customerId, "Incorrect customerId " + customerId);
179 170 validateString(type, "Incorrect type " + type);
180 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 173 return new TextPageData<>(assets, pageLink);
184 174 }
185 175
186 176 @Override
187 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 179 validateId(tenantId, "Incorrect tenantId " + tenantId);
190 180 validateId(customerId, "Incorrect customerId " + customerId);
191 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 185 @Override
... ... @@ -199,7 +187,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
199 187 log.trace("Executing unassignCustomerAssets, tenantId [{}], customerId [{}]", tenantId, customerId);
200 188 validateId(tenantId, "Incorrect tenantId " + tenantId);
201 189 validateId(customerId, "Incorrect customerId " + customerId);
202   - new CustomerAssetsUnassigner(tenantId).removeEntitites(customerId);
  190 + new CustomerAssetsUnassigner(tenantId).removeEntities(customerId);
203 191 }
204 192
205 193 @Override
... ... @@ -232,16 +220,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
232 220 public ListenableFuture<List<TenantAssetType>> findAssetTypesByTenantId(TenantId tenantId) {
233 221 log.trace("Executing findAssetTypesByTenantId, tenantId [{}]", tenantId);
234 222 validateId(tenantId, "Incorrect tenantId " + tenantId);
235   - ListenableFuture<List<TenantAssetTypeEntity>> tenantAssetTypeEntities = assetDao.findTenantAssetTypesAsync();
  223 + ListenableFuture<List<TenantAssetType>> tenantAssetTypeEntities = assetDao.findTenantAssetTypesAsync();
236 224 ListenableFuture<List<TenantAssetType>> tenantAssetTypes = Futures.transform(tenantAssetTypeEntities,
237   - (Function<List<TenantAssetTypeEntity>, List<TenantAssetType>>) assetTypeEntities -> {
  225 + (Function<List<TenantAssetType>, List<TenantAssetType>>) assetTypeEntities -> {
238 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 233 return assetTypes;
246 234 });
247 235 return tenantAssetTypes;
... ... @@ -263,7 +251,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
263 251 protected void validateUpdate(Asset asset) {
264 252 assetDao.findAssetsByTenantIdAndName(asset.getTenantId().getId(), asset.getName()).ifPresent(
265 253 d -> {
266   - if (!d.getId().equals(asset.getUuidId())) {
  254 + if (!d.getId().equals(asset.getId())) {
267 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 269 if (asset.getTenantId() == null) {
282 270 throw new DataValidationException("Asset should be assigned to tenant!");
283 271 } else {
284   - TenantEntity tenant = tenantDao.findById(asset.getTenantId().getId());
  272 + Tenant tenant = tenantDao.findById(asset.getTenantId().getId());
285 273 if (tenant == null) {
286 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 277 if (asset.getCustomerId() == null) {
290 278 asset.setCustomerId(new CustomerId(NULL_UUID));
291 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 281 if (customer == null) {
294 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 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 294 @Override
307   - protected List<AssetEntity> findEntities(TenantId id, TextPageLink pageLink) {
  295 + protected List<Asset> findEntities(TenantId id, TextPageLink pageLink) {
308 296 return assetDao.findAssetsByTenantId(id.getId(), pageLink);
309 297 }
310 298
311 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 307 private TenantId tenantId;
320 308
... ... @@ -323,13 +311,13 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
323 311 }
324 312
325 313 @Override
326   - protected List<AssetEntity> findEntities(CustomerId id, TextPageLink pageLink) {
  314 + protected List<Asset> findEntities(CustomerId id, TextPageLink pageLink) {
327 315 return assetDao.findAssetsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
328 316 }
329 317
330 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 25 import lombok.extern.slf4j.Slf4j;
26 26 import org.springframework.stereotype.Component;
27 27 import org.thingsboard.server.common.data.asset.Asset;
  28 +import org.thingsboard.server.common.data.asset.TenantAssetType;
28 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 33 import org.thingsboard.server.dao.model.TenantAssetTypeEntity;
  34 +import org.thingsboard.server.dao.model.nosql.AssetEntity;
32 35
33 36 import javax.annotation.Nullable;
34 37 import java.util.*;
... ... @@ -38,7 +41,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
38 41
39 42 @Component
40 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 47 @Override
44 48 protected Class<AssetEntity> getColumnFamilyClass() {
... ... @@ -51,33 +55,26 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
51 55 }
52 56
53 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 59 log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
62 60 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
63 61 Collections.singletonList(eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink);
64 62
65 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 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 69 log.debug("Try to find assets by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink);
72 70 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
73 71 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type),
74 72 eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink);
75 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 78 log.debug("Try to find assets by tenantId [{}] and asset Ids [{}]", tenantId, assetIds);
82 79 Select select = select().from(getColumnFamilyName());
83 80 Select.Where query = select.where();
... ... @@ -87,7 +84,7 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
87 84 }
88 85
89 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 88 log.debug("Try to find assets by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
92 89 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
93 90 Arrays.asList(eq(ASSET_CUSTOMER_ID_PROPERTY, customerId),
... ... @@ -95,11 +92,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
95 92 pageLink);
96 93
97 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 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 100 log.debug("Try to find assets by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink);
104 101 List<AssetEntity> assetEntities = findPageWithTextSearch(ASSET_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
105 102 Arrays.asList(eq(ASSET_TYPE_PROPERTY, type),
... ... @@ -108,11 +105,11 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
108 105 pageLink);
109 106
110 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 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 113 log.debug("Try to find assets by tenantId [{}], customerId [{}] and asset Ids [{}]", tenantId, customerId, assetIds);
117 114 Select select = select().from(getColumnFamilyName());
118 115 Select.Where query = select.where();
... ... @@ -123,16 +120,17 @@ public class AssetDaoImpl extends AbstractSearchTextDao<AssetEntity> implements
123 120 }
124 121
125 122 @Override
126   - public Optional<AssetEntity> findAssetsByTenantIdAndName(UUID tenantId, String assetName) {
  123 + public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String assetName) {
127 124 Select select = select().from(ASSET_BY_TENANT_AND_NAME_VIEW_NAME);
128 125 Select.Where query = select.where();
129 126 query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId));
130 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 132 @Override
135   - public ListenableFuture<List<TenantAssetTypeEntity>> findTenantAssetTypesAsync() {
  133 + public ListenableFuture<List<TenantAssetType>> findTenantAssetTypesAsync() {
136 134 Select statement = select().distinct().column(ASSET_TYPE_PROPERTY).column(ASSET_TENANT_ID_PROPERTY).from(ASSET_TYPES_BY_TENANT_VIEW_NAME);
137 135 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
138 136 ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
... ... @@ -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 15 */
16 16 package org.thingsboard.server.dao.attributes;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.ResultSetFuture;
20 18 import com.google.common.util.concurrent.ListenableFuture;
21 19 import org.thingsboard.server.common.data.id.EntityId;
22 20 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
... ... @@ -36,7 +34,7 @@ public interface AttributesDao {
36 34
37 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 15 */
16 16 package org.thingsboard.server.dao.attributes;
17 17
18   -import com.datastax.driver.core.ResultSet;
19   -import com.datastax.driver.core.ResultSetFuture;
20 18 import com.google.common.util.concurrent.ListenableFuture;
21   -import org.thingsboard.server.common.data.id.DeviceId;
22 19 import org.thingsboard.server.common.data.id.EntityId;
23   -import org.thingsboard.server.common.data.id.UUIDBased;
24 20 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
25 21
26 22 import java.util.Collection;
... ... @@ -38,7 +34,7 @@ public interface AttributesService {
38 34
39 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 20 import com.google.common.collect.Lists;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.stereotype.Service;
23 25 import org.thingsboard.server.common.data.id.EntityId;
24 26 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
25 27 import org.thingsboard.server.dao.exception.IncorrectParameterException;
26   -import org.springframework.beans.factory.annotation.Autowired;
27   -import org.springframework.stereotype.Service;
28 28 import org.thingsboard.server.dao.service.Validator;
29 29
30 30 import java.util.Collection;
... ... @@ -61,10 +61,10 @@ public class BaseAttributesService implements AttributesService {
61 61 }
62 62
63 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 65 validate(entityId, scope);
66 66 attributes.forEach(attribute -> validate(attribute));
67   - List<ResultSetFuture> futures = Lists.newArrayListWithExpectedSize(attributes.size());
  67 + List<ListenableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(attributes.size());
68 68 for (AttributeKvEntry attribute : attributes) {
69 69 futures.add(attributesDao.save(entityId, scope, attribute));
70 70 }
... ... @@ -72,7 +72,7 @@ public class BaseAttributesService implements AttributesService {
72 72 }
73 73
74 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 76 validate(entityId, scope);
77 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 24 import lombok.extern.slf4j.Slf4j;
25 25 import org.springframework.stereotype.Component;
26 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 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 34 import javax.annotation.PostConstruct;
33 35 import javax.annotation.PreDestroy;
... ... @@ -37,15 +39,17 @@ import java.util.List;
37 39 import java.util.Optional;
38 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 44 import static org.thingsboard.server.dao.model.ModelConstants.*;
41   -import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
42 45
43 46 /**
44 47 * @author Andrew Shvayka
45 48 */
46 49 @Component
47 50 @Slf4j
48   -public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao {
  51 +@NoSqlDao
  52 +public class CassandraBaseAttributesDao extends CassandraAbstractAsyncDao implements AttributesDao {
49 53
50 54 private PreparedStatement saveStmt;
51 55
... ... @@ -97,7 +101,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
97 101 }
98 102
99 103 @Override
100   - public ResultSetFuture save(EntityId entityId, String attributeType, AttributeKvEntry attribute) {
  104 + public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) {
101 105 BoundStatement stmt = getSaveStmt().bind();
102 106 stmt.setString(0, entityId.getEntityType().name());
103 107 stmt.setUUID(1, entityId.getId());
... ... @@ -120,23 +124,27 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
120 124 } else {
121 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 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 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 141 Statement delete = QueryBuilder.delete().all().from(ModelConstants.ATTRIBUTES_KV_CF)
134 142 .where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType()))
135 143 .and(eq(ENTITY_ID_COLUMN, entityId.getId()))
136 144 .and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType))
137 145 .and(eq(ATTRIBUTE_KEY_COLUMN, key));
138 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 150 private PreparedStatement getSaveStmt() {
... ... @@ -161,7 +169,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao
161 169 AttributeKvEntry attributeEntry = null;
162 170 if (row != null) {
163 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 174 return attributeEntry;
167 175 }
... ...
... ... @@ -57,16 +57,25 @@ public class ServiceCacheConfiguration {
57 57 Config config = new Config();
58 58
59 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 79 MapConfig deviceCredentialsCacheConfig = new MapConfig(CacheConstants.DEVICE_CREDENTIALS_CACHE);
71 80 deviceCredentialsCacheConfig.setTimeToLiveSeconds(cacheDeviceCredentialsTTL);
72 81 deviceCredentialsCacheConfig.setEvictionPolicy(EvictionPolicy.LRU);
... ... @@ -75,9 +84,7 @@ public class ServiceCacheConfiguration {
75 84 cacheDeviceCredentialsMaxSizeSize,
76 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 90 @Bean
... ...
... ... @@ -16,13 +16,8 @@
16 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 20 import com.datastax.driver.core.ProtocolOptions.Compression;
24   -import com.datastax.driver.core.Session;
25   -import com.datastax.driver.core.exceptions.NoHostAvailableException;
26 21 import com.datastax.driver.mapping.Mapper;
27 22 import com.datastax.driver.mapping.MappingManager;
28 23 import lombok.Data;
... ... @@ -31,20 +26,19 @@ import org.apache.commons.lang3.StringUtils;
31 26 import org.springframework.beans.factory.annotation.Autowired;
32 27 import org.springframework.beans.factory.annotation.Value;
33 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 31 import javax.annotation.PostConstruct;
37 32 import javax.annotation.PreDestroy;
38   -import java.io.Closeable;
39 33 import java.net.InetSocketAddress;
40 34 import java.util.ArrayList;
41 35 import java.util.Collections;
42 36 import java.util.List;
43   -import java.util.StringTokenizer;
44 37
  38 +@Data
45 39 @Component
46 40 @Slf4j
47   -@Data
  41 +@NoSqlDao
48 42 public class CassandraCluster {
49 43
50 44 private static final String COMMA = ",";
... ...
... ... @@ -21,15 +21,14 @@ import lombok.Data;
21 21 import org.springframework.beans.factory.annotation.Value;
22 22 import org.springframework.context.annotation.Configuration;
23 23 import org.springframework.stereotype.Component;
24   -import org.springframework.util.StringUtils;
  24 +import org.thingsboard.server.dao.util.NoSqlDao;
25 25
26 26 import javax.annotation.PostConstruct;
27 27
28   -import static org.apache.commons.lang3.StringUtils.isNotBlank;
29   -
30 28 @Component
31 29 @Configuration
32 30 @Data
  31 +@NoSqlDao
33 32 public class CassandraQueryOptions {
34 33
35 34 @Value("${cassandra.query.default_fetch_size}")
... ...
... ... @@ -15,18 +15,19 @@
15 15 */
16 16 package org.thingsboard.server.dao.cassandra;
17 17
  18 +import com.datastax.driver.core.SocketOptions;
18 19 import lombok.Data;
19 20 import org.springframework.beans.factory.annotation.Value;
20 21 import org.springframework.context.annotation.Configuration;
21 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 25 import javax.annotation.PostConstruct;
26 26
27 27 @Component
28 28 @Configuration
29 29 @Data
  30 +@NoSqlDao
30 31 public class CassandraSocketOptions {
31 32
32 33 @Value("${cassandra.socket.connect_timeout}")
... ...
... ... @@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope;
32 32 import org.thingsboard.server.common.data.plugin.ComponentType;
33 33 import org.thingsboard.server.dao.exception.DataValidationException;
34 34 import org.thingsboard.server.dao.exception.IncorrectParameterException;
35   -import org.thingsboard.server.dao.model.ComponentDescriptorEntity;
36 35 import org.thingsboard.server.dao.service.DataValidator;
37 36 import org.thingsboard.server.dao.service.Validator;
38 37
39 38 import java.util.List;
40 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 42 * @author Andrew Shvayka
47 43 */
... ... @@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic
55 51 @Override
56 52 public ComponentDescriptor saveComponent(ComponentDescriptor component) {
57 53 componentValidator.validate(component);
58   - Optional<ComponentDescriptorEntity> result = componentDescriptorDao.save(component);
  54 + Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(component);
59 55 if (result.isPresent()) {
60   - return getData(result.get());
  56 + return result.get();
61 57 } else {
62   - return getData(componentDescriptorDao.findByClazz(component.getClazz()));
  58 + return componentDescriptorDao.findByClazz(component.getClazz());
63 59 }
64 60 }
65 61
66 62 @Override
67 63 public ComponentDescriptor findById(ComponentDescriptorId componentId) {
68 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 68 @Override
73 69 public ComponentDescriptor findByClazz(String clazz) {
74 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 74 @Override
79 75 public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
80 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 78 return new TextPageData<>(components, pageLink);
84 79 }
85 80
86 81 @Override
87 82 public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
88 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 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 27 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
28 28 import org.thingsboard.server.common.data.plugin.ComponentScope;
29 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 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 36 import java.util.Arrays;
35 37 import java.util.List;
... ... @@ -44,7 +46,8 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
44 46 */
45 47 @Component
46 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 52 @Override
50 53 protected Class<ComponentDescriptorEntity> getColumnFamilyClass() {
... ... @@ -57,10 +60,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
57 60 }
58 61
59 62 @Override
60   - public Optional<ComponentDescriptorEntity> save(ComponentDescriptor component) {
  63 + public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
61 64 ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component);
62 65 log.debug("Save component entity [{}]", entity);
63   - Optional<ComponentDescriptorEntity> result = saveIfNotExist(entity);
  66 + Optional<ComponentDescriptor> result = saveIfNotExist(entity);
64 67 if (log.isTraceEnabled()) {
65 68 log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null));
66 69 } else {
... ... @@ -70,19 +73,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
70 73 }
71 74
72 75 @Override
73   - public ComponentDescriptorEntity findById(ComponentDescriptorId componentId) {
  76 + public ComponentDescriptor findById(ComponentDescriptorId componentId) {
74 77 log.debug("Search component entity by id [{}]", componentId);
75   - ComponentDescriptorEntity entity = super.findById(componentId.getId());
  78 + ComponentDescriptor componentDescriptor = super.findById(componentId.getId());
76 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 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 87 @Override
85   - public ComponentDescriptorEntity findByClazz(String clazz) {
  88 + public ComponentDescriptor findByClazz(String clazz) {
86 89 log.debug("Search component entity by clazz [{}]", clazz);
87 90 Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz));
88 91 log.trace("Execute query [{}]", query);
... ... @@ -92,47 +95,47 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
92 95 } else {
93 96 log.debug("Search result: [{}]", entity != null);
94 97 }
95   - return entity;
  98 + return DaoUtil.getData(entity);
96 99 }
97 100
98 101 @Override
99   - public List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
  102 + public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
100 103 log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink);
101 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 106 if (log.isTraceEnabled()) {
104 107 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
105 108 } else {
106 109 log.debug("Search result: [{}]", entities.size());
107 110 }
108   - return entities;
  111 + return DaoUtil.convertDataList(entities);
109 112 }
110 113
111 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 116 log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink);
114 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 119 eq(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, scope.name())), pageLink);
117 120 if (log.isTraceEnabled()) {
118 121 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
119 122 } else {
120 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 129 Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key));
127 130 log.debug("Remove request: {}", delete.toString());
128   - return getSession().execute(delete);
  131 + return getSession().execute(delete).wasApplied();
129 132 }
130 133
131 134 @Override
132 135 public void deleteById(ComponentDescriptorId id) {
133 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 141 @Override
... ... @@ -144,7 +147,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
144 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 151 if (entity.getId() == null) {
149 152 entity.setId(UUIDs.timeBased());
150 153 }
... ... @@ -161,7 +164,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD
161 164 .ifNotExists()
162 165 );
163 166 if (rs.wasApplied()) {
164   - return Optional.of(entity);
  167 + return Optional.of(DaoUtil.getData(entity));
165 168 } else {
166 169 return Optional.empty();
167 170 }
... ...
... ... @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
21 21 import org.thingsboard.server.common.data.plugin.ComponentScope;
22 22 import org.thingsboard.server.common.data.plugin.ComponentType;
23 23 import org.thingsboard.server.dao.Dao;
24   -import org.thingsboard.server.dao.model.ComponentDescriptorEntity;
25 24
26 25 import java.util.List;
27 26 import java.util.Optional;
... ... @@ -29,17 +28,17 @@ import java.util.Optional;
29 28 /**
30 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 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 15 */
16 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 18 import com.datastax.driver.core.querybuilder.Select;
31 19 import lombok.extern.slf4j.Slf4j;
32 20 import org.springframework.stereotype.Component;
33 21 import org.thingsboard.server.common.data.Customer;
34 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 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 37 @Component
41 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 42 @Override
45 43 protected Class<CustomerEntity> getColumnFamilyClass() {
... ... @@ -50,30 +48,26 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple
50 48 protected String getColumnFamilyName() {
51 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 52 @Override
61   - public List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) {
  53 + public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) {
62 54 log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
63 55 List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
64 56 Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)),
65 57 pageLink);
66 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 62 @Override
71   - public Optional<CustomerEntity> findCustomersByTenantIdAndTitle(UUID tenantId, String title) {
  63 + public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) {
72 64 Select select = select().from(CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME);
73 65 Select.Where query = select.where();
74 66 query.and(eq(CUSTOMER_TENANT_ID_PROPERTY, tenantId));
75 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 15 */
16 16 package org.thingsboard.server.dao.customer;
17 17
18   -import java.util.List;
19 18 import java.util.Optional;
20   -import java.util.UUID;
21   -
22 19 import org.thingsboard.server.common.data.Customer;
23 20 import org.thingsboard.server.common.data.page.TextPageLink;
24 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 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 32 * Save or update customer object
... ... @@ -36,7 +34,7 @@ public interface CustomerDao extends Dao<CustomerEntity> {
36 34 * @param customer the customer object
37 35 * @return saved customer object
38 36 */
39   - CustomerEntity save(Customer customer);
  37 + Customer save(Customer customer);
40 38
41 39 /**
42 40 * Find customers by tenant id and page link.
... ... @@ -45,7 +43,7 @@ public interface CustomerDao extends Dao<CustomerEntity> {
45 43 * @param pageLink the page link
46 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 49 * Find customers by tenantId and customer title.
... ... @@ -54,6 +52,6 @@ public interface CustomerDao extends Dao<CustomerEntity> {
54 52 * @param title the customer title
55 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 27 Customer findCustomerById(CustomerId customerId);
28 28
29 29 ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId);
30   -
  30 +
31 31 Customer saveCustomer(Customer customer);
32 32
33 33 void deleteCustomer(CustomerId customerId);
34 34
35 35 Customer findOrCreatePublicCustomer(TenantId tenantId);
36   -
  36 +
37 37 TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink);
38 38
39 39 void deleteCustomersByTenantId(TenantId tenantId);
... ...
... ... @@ -15,8 +15,6 @@
15 15 */
16 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 18 import static org.thingsboard.server.dao.service.Validator.validateId;
21 19
22 20 import java.io.IOException;
... ... @@ -25,12 +23,13 @@ import java.util.Optional;
25 23
26 24 import com.fasterxml.jackson.databind.JsonNode;
27 25 import com.fasterxml.jackson.databind.ObjectMapper;
28   -import com.google.common.base.Function;
29   -import com.google.common.util.concurrent.Futures;
30 26 import com.google.common.util.concurrent.ListenableFuture;
31 27 import lombok.extern.slf4j.Slf4j;
32 28 import org.apache.commons.lang3.StringUtils;
  29 +import org.springframework.beans.factory.annotation.Autowired;
  30 +import org.springframework.stereotype.Service;
33 31 import org.thingsboard.server.common.data.Customer;
  32 +import org.thingsboard.server.common.data.Tenant;
34 33 import org.thingsboard.server.common.data.id.CustomerId;
35 34 import org.thingsboard.server.common.data.id.TenantId;
36 35 import org.thingsboard.server.common.data.page.TextPageData;
... ... @@ -40,15 +39,12 @@ import org.thingsboard.server.dao.device.DeviceService;
40 39 import org.thingsboard.server.dao.entity.AbstractEntityService;
41 40 import org.thingsboard.server.dao.exception.DataValidationException;
42 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 42 import org.thingsboard.server.dao.service.DataValidator;
46 43 import org.thingsboard.server.dao.service.PaginatedRemover;
  44 +import org.thingsboard.server.dao.service.Validator;
47 45 import org.thingsboard.server.dao.tenant.TenantDao;
48 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 48 @Service
53 49 @Slf4j
54 50 public class CustomerServiceImpl extends AbstractEntityService implements CustomerService {
... ... @@ -57,41 +53,38 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
57 53
58 54 @Autowired
59 55 private CustomerDao customerDao;
60   -
  56 +
61 57 @Autowired
62 58 private UserService userService;
63   -
  59 +
64 60 @Autowired
65 61 private TenantDao tenantDao;
66   -
  62 +
67 63 @Autowired
68 64 private DeviceService deviceService;
69   -
  65 +
70 66 @Autowired
71 67 private DashboardService dashboardService;
72   -
  68 +
73 69 @Override
74 70 public Customer findCustomerById(CustomerId customerId) {
75 71 log.trace("Executing findCustomerById [{}]", customerId);
76 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 76 @Override
82 77 public ListenableFuture<Customer> findCustomerByIdAsync(CustomerId customerId) {
83 78 log.trace("Executing findCustomerByIdAsync [{}]", customerId);
84 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 83 @Override
90 84 public Customer saveCustomer(Customer customer) {
91 85 log.trace("Executing saveCustomer [{}]", customer);
92 86 customerValidator.validate(customer);
93   - CustomerEntity customerEntity = customerDao.save(customer);
94   - return getData(customerEntity);
  87 + return customerDao.save(customer);
95 88 }
96 89
97 90 @Override
... ... @@ -113,9 +106,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
113 106 public Customer findOrCreatePublicCustomer(TenantId tenantId) {
114 107 log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
115 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 112 } else {
120 113 Customer publicCustomer = new Customer();
121 114 publicCustomer.setTenantId(tenantId);
... ... @@ -125,8 +118,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
125 118 } catch (IOException e) {
126 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 127 log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
136 128 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
137 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 134 @Override
144 135 public void deleteCustomersByTenantId(TenantId tenantId) {
145 136 log.trace("Executing deleteCustomersByTenantId, tenantId [{}]", tenantId);
146 137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
147   - customersByTenantRemover.removeEntitites(tenantId);
  138 + customersByTenantRemover.removeEntities(tenantId);
148 139 }
149   -
  140 +
150 141 private DataValidator<Customer> customerValidator =
151 142 new DataValidator<Customer>() {
152 143
... ... @@ -184,25 +175,25 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
184 175 if (customer.getTenantId() == null) {
185 176 throw new DataValidationException("Customer should be assigned to tenant!");
186 177 } else {
187   - TenantEntity tenant = tenantDao.findById(customer.getTenantId().getId());
  178 + Tenant tenant = tenantDao.findById(customer.getTenantId().getId());
188 179 if (tenant == null) {
189 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 15 */
16 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 18 import org.springframework.stereotype.Component;
32 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 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 30 @Override
45 31 protected Class<DashboardEntity> getColumnFamilyClass() {
... ... @@ -50,11 +36,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp
50 36 protected String getColumnFamilyName() {
51 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 17
18 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.stereotype.Component;
  20 +import org.thingsboard.server.common.data.DashboardInfo;
20 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 27 import java.util.Arrays;
25 28 import java.util.Collections;
... ... @@ -31,7 +34,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*;
31 34
32 35 @Component
33 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 40 @Override
37 41 protected Class<DashboardInfoEntity> getColumnFamilyClass() {
... ... @@ -44,18 +48,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt
44 48 }
45 49
46 50 @Override
47   - public List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) {
  51 + public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) {
48 52 log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
49 53 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
50 54 Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)),
51 55 pageLink);
52 56
53 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 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 63 log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
60 64 List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
61 65 Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId),
... ... @@ -63,7 +67,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt
63 67 pageLink);
64 68
65 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 15 */
16 16 package org.thingsboard.server.dao.dashboard;
17 17
18   -import java.util.List;
19   -import java.util.UUID;
20   -
21 18 import org.thingsboard.server.common.data.Dashboard;
22   -import org.thingsboard.server.common.data.page.TextPageLink;
23 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 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 27 * Save or update dashboard object
... ... @@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> {
37 29 * @param dashboard the dashboard object
38 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 15 */
16 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 19 import org.thingsboard.server.common.data.page.TextPageLink;
23 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 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 31 * Find dashboards by tenantId and page link.
... ... @@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
38 34 * @param pageLink the page link
39 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 40 * Find dashboards by tenantId, customerId and page link.
... ... @@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
48 44 * @param pageLink the page link
49 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 26
27 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 15 */
16 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 18 import com.google.common.util.concurrent.ListenableFuture;
27 19 import lombok.extern.slf4j.Slf4j;
28 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 24 import org.thingsboard.server.common.data.Dashboard;
30 25 import org.thingsboard.server.common.data.DashboardInfo;
  26 +import org.thingsboard.server.common.data.Tenant;
31 27 import org.thingsboard.server.common.data.id.CustomerId;
32 28 import org.thingsboard.server.common.data.id.DashboardId;
33 29 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -36,13 +32,15 @@ import org.thingsboard.server.common.data.page.TextPageLink;
36 32 import org.thingsboard.server.dao.customer.CustomerDao;
37 33 import org.thingsboard.server.dao.entity.AbstractEntityService;
38 34 import org.thingsboard.server.dao.exception.DataValidationException;
39   -import org.thingsboard.server.dao.model.*;
  35 +import org.thingsboard.server.dao.model.ModelConstants;
40 36 import org.thingsboard.server.dao.service.DataValidator;
41 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 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 45 @Service
48 46 @Slf4j
... ... @@ -64,40 +62,35 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
64 62 public Dashboard findDashboardById(DashboardId dashboardId) {
65 63 log.trace("Executing findDashboardById [{}]", dashboardId);
66 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 68 @Override
72 69 public ListenableFuture<Dashboard> findDashboardByIdAsync(DashboardId dashboardId) {
73 70 log.trace("Executing findDashboardByIdAsync [{}]", dashboardId);
74 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 75 @Override
80 76 public DashboardInfo findDashboardInfoById(DashboardId dashboardId) {
81 77 log.trace("Executing findDashboardInfoById [{}]", dashboardId);
82 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 82 @Override
88 83 public ListenableFuture<DashboardInfo> findDashboardInfoByIdAsync(DashboardId dashboardId) {
89 84 log.trace("Executing findDashboardInfoByIdAsync [{}]", dashboardId);
90 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 89 @Override
96 90 public Dashboard saveDashboard(Dashboard dashboard) {
97 91 log.trace("Executing saveDashboard [{}]", dashboard);
98 92 dashboardValidator.validate(dashboard);
99   - DashboardEntity dashboardEntity = dashboardDao.save(dashboard);
100   - return getData(dashboardEntity);
  93 + return dashboardDao.save(dashboard);
101 94 }
102 95
103 96 @Override
... ... @@ -127,16 +120,15 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
127 120 log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
128 121 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
129 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 127 @Override
136 128 public void deleteDashboardsByTenantId(TenantId tenantId) {
137 129 log.trace("Executing deleteDashboardsByTenantId, tenantId [{}]", tenantId);
138 130 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
139   - tenantDashboardsRemover.removeEntitites(tenantId);
  131 + tenantDashboardsRemover.removeEntities(tenantId);
140 132 }
141 133
142 134 @Override
... ... @@ -145,9 +137,8 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
145 137 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
146 138 Validator.validateId(customerId, "Incorrect customerId " + customerId);
147 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 144 @Override
... ... @@ -155,7 +146,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
155 146 log.trace("Executing unassignCustomerDashboards, tenantId [{}], customerId [{}]", tenantId, customerId);
156 147 Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
157 148 Validator.validateId(customerId, "Incorrect customerId " + customerId);
158   - new CustomerDashboardsUnassigner(tenantId).removeEntitites(customerId);
  149 + new CustomerDashboardsUnassigner(tenantId).removeEntities(customerId);
159 150 }
160 151
161 152 private DataValidator<Dashboard> dashboardValidator =
... ... @@ -168,7 +159,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
168 159 if (dashboard.getTenantId() == null) {
169 160 throw new DataValidationException("Dashboard should be assigned to tenant!");
170 161 } else {
171   - TenantEntity tenant = tenantDao.findById(dashboard.getTenantId().getId());
  162 + Tenant tenant = tenantDao.findById(dashboard.getTenantId().getId());
172 163 if (tenant == null) {
173 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 167 if (dashboard.getCustomerId() == null) {
177 168 dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID));
178 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 171 if (customer == null) {
181 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 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 184 @Override
194   - protected List<DashboardInfoEntity> findEntities(TenantId id, TextPageLink pageLink) {
  185 + protected List<DashboardInfo> findEntities(TenantId id, TextPageLink pageLink) {
195 186 return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
196 187 }
197 188
198 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 197 private TenantId tenantId;
207 198
... ... @@ -210,13 +201,13 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
210 201 }
211 202
212 203 @Override
213   - protected List<DashboardInfoEntity> findEntities(CustomerId id, TextPageLink pageLink) {
  204 + protected List<DashboardInfo> findEntities(CustomerId id, TextPageLink pageLink) {
214 205 return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
215 206 }
216 207
217 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 15 */
16 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 19 import lombok.extern.slf4j.Slf4j;
24 20 import org.springframework.stereotype.Component;
25 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 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 33 @Component
36 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 38 @Override
40 39 protected Class<DeviceCredentialsEntity> getColumnFamilyClass() {
... ... @@ -47,31 +46,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials
47 46 }
48 47
49 48 @Override
50   - public DeviceCredentialsEntity findByDeviceId(UUID deviceId) {
  49 + public DeviceCredentials findByDeviceId(UUID deviceId) {
51 50 log.debug("Try to find device credentials by deviceId [{}] ", deviceId);
52 51 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME)
53 52 .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId));
54 53 log.trace("Execute query {}", query);
55 54 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query);
56 55 log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId);
57   - return deviceCredentialsEntity;
  56 + return DaoUtil.getData(deviceCredentialsEntity);
58 57 }
59 58
60 59 @Override
61   - public DeviceCredentialsEntity findByCredentialsId(String credentialsId) {
  60 + public DeviceCredentials findByCredentialsId(String credentialsId) {
62 61 log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId);
63 62 Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME)
64 63 .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId));
65 64 log.trace("Execute query {}", query);
66 65 DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query);
67 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 15 */
16 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 18 import com.datastax.driver.core.ResultSet;
26 19 import com.datastax.driver.core.ResultSetFuture;
27 20 import com.datastax.driver.core.querybuilder.Select;
... ... @@ -32,18 +25,24 @@ import com.google.common.util.concurrent.ListenableFuture;
32 25 import lombok.extern.slf4j.Slf4j;
33 26 import org.springframework.stereotype.Component;
34 27 import org.thingsboard.server.common.data.Device;
  28 +import org.thingsboard.server.common.data.TenantDeviceType;
35 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 33 import org.thingsboard.server.dao.model.TenantDeviceTypeEntity;
  34 +import org.thingsboard.server.dao.model.nosql.DeviceEntity;
41 35
42 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 42 @Component
45 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 47 @Override
49 48 protected Class<DeviceEntity> getColumnFamilyClass() {
... ... @@ -56,33 +55,27 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
56 55 }
57 56
58 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 59 log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
67 60 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
68 61 Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink);
69 62
70 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 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 69 log.debug("Try to find devices by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink);
77 70 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
78 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 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 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 79 log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds);
87 80 Select select = select().from(getColumnFamilyName());
88 81 Select.Where query = select.where();
... ... @@ -92,32 +85,32 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
92 85 }
93 86
94 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 90 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
98 91 Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId),
99 92 eq(DEVICE_TENANT_ID_PROPERTY, tenantId)),
100 93 pageLink);
101 94
102 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 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 101 log.debug("Try to find devices by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink);
109 102 List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME,
110 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 106 pageLink);
114 107
115 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 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 114 log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds);
122 115 Select select = select().from(getColumnFamilyName());
123 116 Select.Where query = select.where();
... ... @@ -128,16 +121,16 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement
128 121 }
129 122
130 123 @Override
131   - public Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) {
  124 + public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String deviceName) {
132 125 Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME);
133 126 Select.Where query = select.where();
134 127 query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId));
135 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 132 @Override
140   - public ListenableFuture<List<TenantDeviceTypeEntity>> findTenantDeviceTypesAsync() {
  133 + public ListenableFuture<List<TenantDeviceType>> findTenantDeviceTypesAsync() {
141 134 Select statement = select().distinct().column(DEVICE_TYPE_PROPERTY).column(DEVICE_TENANT_ID_PROPERTY).from(DEVICE_TYPES_BY_TENANT_VIEW_NAME);
142 135 statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
143 136 ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
... ... @@ -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 15 */
16 16 package org.thingsboard.server.dao.device;
17 17
18   -import java.util.UUID;
19   -
20 18 import org.thingsboard.server.common.data.security.DeviceCredentials;
21 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 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 29 * Save or update device credentials object
... ... @@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
34 31 * @param deviceCredentials the device credentials object
35 32 * @return saved device credentials object
36 33 */
37   - DeviceCredentialsEntity save(DeviceCredentials deviceCredentials);
  34 + DeviceCredentials save(DeviceCredentials deviceCredentials);
38 35
39 36 /**
40 37 * Find device credentials by device id.
... ... @@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
42 39 * @param deviceId the device id
43 40 * @return the device credentials object
44 41 */
45   - DeviceCredentialsEntity findByDeviceId(UUID deviceId);
  42 + DeviceCredentials findByDeviceId(UUID deviceId);
46 43
47 44 /**
48 45 * Find device credentials by credentials id.
... ... @@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
50 47 * @param credentialsId the credentials id
51 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 15 */
16 16 package org.thingsboard.server.dao.device;
17 17
18   -import org.springframework.cache.annotation.CacheEvict;
19   -import org.springframework.cache.annotation.Cacheable;
20 18 import org.thingsboard.server.common.data.id.DeviceId;
21 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 21 public interface DeviceCredentialsService {
26 22
27 23 DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId);
28 24
29   - @Cacheable(cacheNames = DEVICE_CREDENTIALS_CACHE, unless="#result == null")
30 25 DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId);
31 26
32   - @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, keyGenerator="previousDeviceCredentialsId", beforeInvocation = true)
33 27 DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials);
34 28
35 29 DeviceCredentials createDeviceCredentials(DeviceCredentials deviceCredentials);
36 30
37   - @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, key="#deviceCredentials.credentialsId")
38 31 void deleteDeviceCredentials(DeviceCredentials deviceCredentials);
39 32 }
... ...
... ... @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.device;
18 18
19 19 import lombok.extern.slf4j.Slf4j;
20 20 import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.cache.annotation.CacheEvict;
  22 +import org.springframework.cache.annotation.Cacheable;
21 23 import org.springframework.stereotype.Service;
22 24 import org.springframework.util.StringUtils;
23 25 import org.thingsboard.server.common.data.Device;
... ... @@ -26,10 +28,9 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
26 28 import org.thingsboard.server.common.data.security.DeviceCredentialsType;
27 29 import org.thingsboard.server.dao.EncryptionUtil;
28 30 import org.thingsboard.server.dao.exception.DataValidationException;
29   -import org.thingsboard.server.dao.model.DeviceCredentialsEntity;
30 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 34 import static org.thingsboard.server.dao.service.Validator.validateId;
34 35 import static org.thingsboard.server.dao.service.Validator.validateString;
35 36
... ... @@ -47,19 +48,19 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
47 48 public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) {
48 49 log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId);
49 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 54 @Override
  55 + @Cacheable(cacheNames = DEVICE_CREDENTIALS_CACHE, unless="#result == null")
55 56 public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) {
56 57 log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId);
57 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 62 @Override
  63 + @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, keyGenerator="previousDeviceCredentialsId", beforeInvocation = true)
63 64 public DeviceCredentials updateDeviceCredentials(DeviceCredentials deviceCredentials) {
64 65 return saveOrUpdare(deviceCredentials);
65 66 }
... ... @@ -75,7 +76,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
75 76 }
76 77 log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials);
77 78 credentialsValidator.validate(deviceCredentials);
78   - return getData(deviceCredentialsDao.save(deviceCredentials));
  79 + return deviceCredentialsDao.save(deviceCredentials);
79 80 }
80 81
81 82 private void formatCertData(DeviceCredentials deviceCredentials) {
... ... @@ -86,6 +87,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
86 87 }
87 88
88 89 @Override
  90 + @CacheEvict(cacheNames = DEVICE_CREDENTIALS_CACHE, key="#deviceCredentials.credentialsId")
89 91 public void deleteDeviceCredentials(DeviceCredentials deviceCredentials) {
90 92 log.trace("Executing deleteDeviceCredentials [{}]", deviceCredentials);
91 93 deviceCredentialsDao.removeById(deviceCredentials.getUuidId());
... ... @@ -96,7 +98,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
96 98
97 99 @Override
98 100 protected void validateCreate(DeviceCredentials deviceCredentials) {
99   - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
  101 + DeviceCredentials existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
100 102 if (existingCredentialsEntity != null) {
101 103 throw new DataValidationException("Create of existent device credentials!");
102 104 }
... ... @@ -104,12 +106,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
104 106
105 107 @Override
106 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 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 115 throw new DataValidationException("Specified credentials are already registered!");
114 116 }
115 117 }
... ...
... ... @@ -15,22 +15,22 @@
15 15 */
16 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 18 import com.google.common.util.concurrent.ListenableFuture;
23 19 import org.thingsboard.server.common.data.Device;
  20 +import org.thingsboard.server.common.data.TenantDeviceType;
24 21 import org.thingsboard.server.common.data.page.TextPageLink;
25 22 import org.thingsboard.server.dao.Dao;
26   -import org.thingsboard.server.dao.model.DeviceEntity;
27 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 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 36 * Save or update device object
... ... @@ -38,7 +38,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
38 38 * @param device the device object
39 39 * @return saved device object
40 40 */
41   - DeviceEntity save(Device device);
  41 + Device save(Device device);
42 42
43 43 /**
44 44 * Find devices by tenantId and page link.
... ... @@ -47,7 +47,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
47 47 * @param pageLink the page link
48 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 53 * Find devices by tenantId, type and page link.
... ... @@ -57,7 +57,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
57 57 * @param pageLink the page link
58 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 63 * Find devices by tenantId and devices Ids.
... ... @@ -66,7 +66,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
66 66 * @param deviceIds the device Ids
67 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 72 * Find devices by tenantId, customerId and page link.
... ... @@ -76,7 +76,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
76 76 * @param pageLink the page link
77 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 82 * Find devices by tenantId, customerId, type and page link.
... ... @@ -87,7 +87,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
87 87 * @param pageLink the page link
88 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 98 * @param deviceIds the device Ids
99 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 104 * Find devices by tenantId and device name.
... ... @@ -107,12 +107,12 @@ public interface DeviceDao extends Dao<DeviceEntity> {
107 107 * @param name the device name
108 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 113 * Find tenants device types.
114 114 *
115 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 18 import lombok.Data;
19 19 import org.thingsboard.server.common.data.EntityType;
20 20 import org.thingsboard.server.common.data.relation.EntityRelation;
21   -import org.thingsboard.server.dao.relation.RelationsSearchParameters;
22 21 import org.thingsboard.server.dao.relation.EntityRelationsQuery;
23 22 import org.thingsboard.server.dao.relation.EntityTypeFilter;
  23 +import org.thingsboard.server.dao.relation.RelationsSearchParameters;
24 24
25 25 import javax.annotation.Nullable;
26 26 import java.util.Collections;
... ...
... ... @@ -24,9 +24,7 @@ import org.apache.commons.lang3.RandomStringUtils;
24 24 import org.springframework.beans.factory.annotation.Autowired;
25 25 import org.springframework.stereotype.Service;
26 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 28 import org.thingsboard.server.common.data.id.CustomerId;
31 29 import org.thingsboard.server.common.data.id.DeviceId;
32 30 import org.thingsboard.server.common.data.id.EntityId;
... ... @@ -39,20 +37,19 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType;
39 37 import org.thingsboard.server.dao.customer.CustomerDao;
40 38 import org.thingsboard.server.dao.entity.AbstractEntityService;
41 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 40 import org.thingsboard.server.dao.relation.EntitySearchDirection;
47 41 import org.thingsboard.server.dao.service.DataValidator;
48 42 import org.thingsboard.server.dao.service.PaginatedRemover;
49 43 import org.thingsboard.server.dao.tenant.TenantDao;
50 44
51 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 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 53 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
57 54 import static org.thingsboard.server.dao.service.Validator.*;
58 55
... ... @@ -76,25 +73,23 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
76 73 public Device findDeviceById(DeviceId deviceId) {
77 74 log.trace("Executing findDeviceById [{}]", deviceId);
78 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 79 @Override
84 80 public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) {
85 81 log.trace("Executing findDeviceById [{}]", deviceId);
86 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 86 @Override
92 87 public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) {
93 88 log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name);
94 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 93 } else {
99 94 return Optional.empty();
100 95 }
... ... @@ -104,15 +99,15 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
104 99 public Device saveDevice(Device device) {
105 100 log.trace("Executing saveDevice [{}]", device);
106 101 deviceValidator.validate(device);
107   - DeviceEntity deviceEntity = deviceDao.save(device);
  102 + Device savedDevice = deviceDao.save(device);
108 103 if (device.getId() == null) {
109 104 DeviceCredentials deviceCredentials = new DeviceCredentials();
110   - deviceCredentials.setDeviceId(new DeviceId(deviceEntity.getId()));
  105 + deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId()));
111 106 deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
112 107 deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
113 108 deviceCredentialsService.createDeviceCredentials(deviceCredentials);
114 109 }
115   - return getData(deviceEntity);
  110 + return savedDevice;
116 111 }
117 112
118 113 @Override
... ... @@ -146,8 +141,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
146 141 log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
147 142 validateId(tenantId, "Incorrect tenantId " + tenantId);
148 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 145 return new TextPageData<>(devices, pageLink);
152 146 }
153 147
... ... @@ -157,8 +151,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
157 151 validateId(tenantId, "Incorrect tenantId " + tenantId);
158 152 validateString(type, "Incorrect type " + type);
159 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 155 return new TextPageData<>(devices, pageLink);
163 156 }
164 157
... ... @@ -167,8 +160,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
167 160 log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds);
168 161 validateId(tenantId, "Incorrect tenantId " + tenantId);
169 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 168 public void deleteDevicesByTenantId(TenantId tenantId) {
177 169 log.trace("Executing deleteDevicesByTenantId, tenantId [{}]", tenantId);
178 170 validateId(tenantId, "Incorrect tenantId " + tenantId);
179   - tenantDevicesRemover.removeEntitites(tenantId);
  171 + tenantDevicesRemover.removeEntities(tenantId);
180 172 }
181 173
182 174 @Override
... ... @@ -185,8 +177,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
185 177 validateId(tenantId, "Incorrect tenantId " + tenantId);
186 178 validateId(customerId, "Incorrect customerId " + customerId);
187 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 181 return new TextPageData<>(devices, pageLink);
191 182 }
192 183
... ... @@ -197,8 +188,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
197 188 validateId(customerId, "Incorrect customerId " + customerId);
198 189 validateString(type, "Incorrect type " + type);
199 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 192 return new TextPageData<>(devices, pageLink);
203 193 }
204 194
... ... @@ -208,9 +198,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
208 198 validateId(tenantId, "Incorrect tenantId " + tenantId);
209 199 validateId(customerId, "Incorrect customerId " + customerId);
210 200 validateIds(deviceIds, "Incorrect deviceIds " + deviceIds);
211   - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),
  201 + return deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),
212 202 customerId.getId(), toUUIDs(deviceIds));
213   - return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input));
214 203 }
215 204
216 205 @Override
... ... @@ -218,7 +207,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
218 207 log.trace("Executing unassignCustomerDevices, tenantId [{}], customerId [{}]", tenantId, customerId);
219 208 validateId(tenantId, "Incorrect tenantId " + tenantId);
220 209 validateId(customerId, "Incorrect customerId " + customerId);
221   - new CustomerDevicesUnassigner(tenantId).removeEntitites(customerId);
  210 + new CustomerDevicesUnassigner(tenantId).removeEntities(customerId);
222 211 }
223 212
224 213 @Override
... ... @@ -251,16 +240,16 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
251 240 public ListenableFuture<List<TenantDeviceType>> findDeviceTypesByTenantId(TenantId tenantId) {
252 241 log.trace("Executing findDeviceTypesByTenantId, tenantId [{}]", tenantId);
253 242 validateId(tenantId, "Incorrect tenantId " + tenantId);
254   - ListenableFuture<List<TenantDeviceTypeEntity>> tenantDeviceTypeEntities = deviceDao.findTenantDeviceTypesAsync();
  243 + ListenableFuture<List<TenantDeviceType>> tenantDeviceTypeEntities = deviceDao.findTenantDeviceTypesAsync();
255 244 ListenableFuture<List<TenantDeviceType>> tenantDeviceTypes = Futures.transform(tenantDeviceTypeEntities,
256   - (Function<List<TenantDeviceTypeEntity>, List<TenantDeviceType>>) deviceTypeEntities -> {
  245 + (Function<List<TenantDeviceType>, List<TenantDeviceType>>) deviceTypeEntities -> {
257 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 253 return deviceTypes;
265 254 });
266 255 return tenantDeviceTypes;
... ... @@ -271,7 +260,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
271 260
272 261 @Override
273 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 264 d -> {
276 265 throw new DataValidationException("Device with such name already exists!");
277 266 }
... ... @@ -280,9 +269,9 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
280 269
281 270 @Override
282 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 273 d -> {
285   - if (!d.getId().equals(device.getUuidId())) {
  274 + if (!d.getUuidId().equals(device.getUuidId())) {
286 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 289 if (device.getTenantId() == null) {
301 290 throw new DataValidationException("Device should be assigned to tenant!");
302 291 } else {
303   - TenantEntity tenant = tenantDao.findById(device.getTenantId().getId());
  292 + Tenant tenant = tenantDao.findById(device.getTenantId().getId());
304 293 if (tenant == null) {
305 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 297 if (device.getCustomerId() == null) {
309 298 device.setCustomerId(new CustomerId(NULL_UUID));
310 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 301 if (customer == null) {
313 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 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 314 @Override
326   - protected List<DeviceEntity> findEntities(TenantId id, TextPageLink pageLink) {
  315 + protected List<Device> findEntities(TenantId id, TextPageLink pageLink) {
327 316 return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
328 317 }
329 318
330 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 327 private TenantId tenantId;
339 328
... ... @@ -342,13 +331,13 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
342 331 }
343 332
344 333 @Override
345   - protected List<DeviceEntity> findEntities(CustomerId id, TextPageLink pageLink) {
  334 + protected List<Device> findEntities(CustomerId id, TextPageLink pageLink) {
346 335 return deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
347 336 }
348 337
349 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 15 */
16 16 package org.thingsboard.server.dao.event;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19 18 import lombok.extern.slf4j.Slf4j;
20 19 import org.apache.commons.lang3.StringUtils;
21 20 import org.springframework.beans.factory.annotation.Autowired;
22 21 import org.springframework.stereotype.Service;
23 22 import org.thingsboard.server.common.data.Event;
24 23 import org.thingsboard.server.common.data.id.EntityId;
25   -import org.thingsboard.server.common.data.id.EventId;
26 24 import org.thingsboard.server.common.data.id.TenantId;
27 25 import org.thingsboard.server.common.data.page.TimePageData;
28 26 import org.thingsboard.server.common.data.page.TimePageLink;
29 27 import org.thingsboard.server.dao.exception.DataValidationException;
30   -import org.thingsboard.server.dao.model.EventEntity;
31 28 import org.thingsboard.server.dao.service.DataValidator;
32 29
33 30 import java.util.List;
34 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 33 @Service
41 34 @Slf4j
42 35 public class BaseEventService implements EventService {
43 36
44   - private final TenantId systemTenantId = new TenantId(NULL_UUID);
45   -
46 37 @Autowired
47 38 public EventDao eventDao;
48 39
49 40 @Override
50 41 public Event save(Event event) {
51 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 46 @Override
... ... @@ -68,15 +49,7 @@ public class BaseEventService implements EventService {
68 49 if (StringUtils.isEmpty(event.getUid())) {
69 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 55 @Override
... ... @@ -93,23 +66,20 @@ public class BaseEventService implements EventService {
93 66 if (StringUtils.isEmpty(eventUid)) {
94 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 73 @Override
101 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 79 @Override
109 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 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 21 import com.datastax.driver.core.querybuilder.Select;
22 22 import com.datastax.driver.core.utils.UUIDs;
23 23 import lombok.extern.slf4j.Slf4j;
  24 +import org.apache.commons.lang3.StringUtils;
24 25 import org.springframework.stereotype.Component;
25 26 import org.thingsboard.server.common.data.Event;
26 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 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 34 import org.thingsboard.server.dao.model.ModelConstants;
  35 +import org.thingsboard.server.dao.model.nosql.EventEntity;
31 36
32 37 import java.util.Arrays;
33 38 import java.util.List;
... ... @@ -36,13 +41,14 @@ import java.util.UUID;
36 41
37 42 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
38 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 46 @Component
44 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 53 @Override
48 54 protected Class<EventEntity> getColumnFamilyClass() {
... ... @@ -55,18 +61,35 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
55 61 }
56 62
57 63 @Override
58   - public EventEntity save(Event event) {
  64 + public Event save(Event event) {
59 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 76 return save(new EventEntity(event), false).orElse(null);
61 77 }
62 78
63 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 88 return save(new EventEntity(event), true);
66 89 }
67 90
68 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 93 log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid);
71 94 Select.Where query = select().from(getColumnFamilyName()).where(
72 95 eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId))
... ... @@ -81,11 +104,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
81 104 } else {
82 105 log.debug("Search result: [{}]", entity != null);
83 106 }
84   - return entity;
  107 + return DaoUtil.getData(entity);
85 108 }
86 109
87 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 112 log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink);
90 113 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME,
91 114 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId),
... ... @@ -93,11 +116,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
93 116 eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())),
94 117 pageLink);
95 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 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 124 log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink);
102 125 List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME,
103 126 Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId),
... ... @@ -108,10 +131,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
108 131 QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY),
109 132 pageLink);
110 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 138 if (entity.getId() == null) {
116 139 entity.setId(UUIDs.timeBased());
117 140 }
... ... @@ -121,14 +144,14 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements
121 144 .value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType())
122 145 .value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId())
123 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 148 .value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody());
126 149 if (ifNotExists) {
127 150 insert = insert.ifNotExists();
128 151 }
129 152 ResultSet rs = executeWrite(insert);
130 153 if (rs.wasApplied()) {
131   - return Optional.of(entity);
  154 + return Optional.of(DaoUtil.getData(entity));
132 155 } else {
133 156 return Optional.empty();
134 157 }
... ...
... ... @@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event;
19 19 import org.thingsboard.server.common.data.id.EntityId;
20 20 import org.thingsboard.server.common.data.page.TimePageLink;
21 21 import org.thingsboard.server.dao.Dao;
22   -import org.thingsboard.server.dao.model.EventEntity;
23 22
24 23 import java.util.List;
25 24 import java.util.Optional;
... ... @@ -27,10 +26,8 @@ import java.util.UUID;
27 26
28 27 /**
29 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 33 * Save or update event object
... ... @@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> {
38 35 * @param event the event object
39 36 * @return saved event object
40 37 */
41   - EventEntity save(Event event);
  38 + Event save(Event event);
42 39
43 40 /**
44 41 * Save event object if it is not yet saved
... ... @@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> {
46 43 * @param event the event object
47 44 * @return saved event object
48 45 */
49   - Optional<EventEntity> saveIfNotExists(Event event);
  46 + Optional<Event> saveIfNotExists(Event event);
50 47
51 48 /**
52 49 * Find event by tenantId, entityId and eventUid.
... ... @@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> {
57 54 * @param eventUid the eventUid
58 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 60 * Find events by tenantId, entityId and pageLink.
... ... @@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> {
67 64 * @param pageLink the pageLink
68 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 70 * Find events by tenantId, entityId, eventType and pageLink.
... ... @@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> {
78 75 * @param pageLink the pageLink
79 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 21 import org.thingsboard.server.common.data.page.TimePageData;
22 22 import org.thingsboard.server.common.data.page.TimePageLink;
23 23
24   -import java.util.List;
25 24 import java.util.Optional;
26 25
27 26 public interface EventService {
... ...
... ... @@ -17,22 +17,22 @@ package org.thingsboard.server.dao.exception;
17 17
18 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 18
19 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 24 super(message);
25 25 }
26 26
... ...
... ... @@ -33,7 +33,7 @@ public class ModelConstants {
33 33 */
34 34 public static final String ID_PROPERTY = "id";
35 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 37 public static final String CUSTOMER_ID_PROPERTY = "customer_id";
38 38 public static final String DEVICE_ID_PROPERTY = "device_id";
39 39 public static final String TITLE_PROPERTY = "title";
... ... @@ -45,7 +45,8 @@ public class ModelConstants {
45 45 * Cassandra user constants.
46 46 */
47 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 50 public static final String USER_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
50 51 public static final String USER_EMAIL_PROPERTY = "email";
51 52 public static final String USER_AUTHORITY_PROPERTY = "authority";
... ... @@ -106,7 +107,7 @@ public class ModelConstants {
106 107 * Cassandra customer constants.
107 108 */
108 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 111 public static final String CUSTOMER_TITLE_PROPERTY = TITLE_PROPERTY;
111 112 public static final String CUSTOMER_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
112 113
... ... @@ -117,7 +118,7 @@ public class ModelConstants {
117 118 * Cassandra device constants.
118 119 */
119 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 122 public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
122 123 public static final String DEVICE_NAME_PROPERTY = "name";
123 124 public static final String DEVICE_TYPE_PROPERTY = "type";
... ... @@ -134,7 +135,7 @@ public class ModelConstants {
134 135 * Cassandra asset constants.
135 136 */
136 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 139 public static final String ASSET_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
139 140 public static final String ASSET_NAME_PROPERTY = "name";
140 141 public static final String ASSET_TYPE_PROPERTY = "type";
... ... @@ -151,7 +152,7 @@ public class ModelConstants {
151 152 * Cassandra alarm constants.
152 153 */
153 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 156 public static final String ALARM_TYPE_PROPERTY = "type";
156 157 public static final String ALARM_DETAILS_PROPERTY = "details";
157 158 public static final String ALARM_ORIGINATOR_ID_PROPERTY = "originator_id";
... ... @@ -197,7 +198,7 @@ public class ModelConstants {
197 198 * Cassandra widgets_bundle constants.
198 199 */
199 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 202 public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY;
202 203 public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY;
203 204 public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image";
... ... @@ -209,7 +210,7 @@ public class ModelConstants {
209 210 * Cassandra widget_type constants.
210 211 */
211 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 214 public static final String WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY = "bundle_alias";
214 215 public static final String WIDGET_TYPE_ALIAS_PROPERTY = ALIAS_PROPERTY;
215 216 public static final String WIDGET_TYPE_NAME_PROPERTY = "name";
... ... @@ -221,7 +222,7 @@ public class ModelConstants {
221 222 * Cassandra dashboard constants.
222 223 */
223 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 226 public static final String DASHBOARD_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
226 227 public static final String DASHBOARD_TITLE_PROPERTY = TITLE_PROPERTY;
227 228 public static final String DASHBOARD_CONFIGURATION_PROPERTY = "configuration";
... ... @@ -234,7 +235,7 @@ public class ModelConstants {
234 235 * Cassandra plugin metadata constants.
235 236 */
236 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 239 public static final String PLUGIN_NAME_PROPERTY = "name";
239 240 public static final String PLUGIN_API_TOKEN_PROPERTY = "api_token";
240 241 public static final String PLUGIN_CLASS_PROPERTY = "plugin_class";
... ... @@ -264,7 +265,7 @@ public class ModelConstants {
264 265 * Cassandra rule metadata constants.
265 266 */
266 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 269 public static final String RULE_NAME_PROPERTY = "name";
269 270 public static final String RULE_STATE_PROPERTY = "state";
270 271 public static final String RULE_WEIGHT_PROPERTY = "weight";
... ... @@ -280,7 +281,7 @@ public class ModelConstants {
280 281 * Cassandra event constants.
281 282 */
282 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 285 public static final String EVENT_TYPE_PROPERTY = "event_type";
285 286 public static final String EVENT_UID_PROPERTY = "event_uid";
286 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 13 * See the License for the specific language governing permissions and
14 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 18 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
19 19 import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_JSON_VALUE_PROPERTY;
... ... @@ -24,6 +24,7 @@ import java.util.UUID;
24 24
25 25 import org.thingsboard.server.common.data.AdminSettings;
26 26 import org.thingsboard.server.common.data.id.AdminSettingsId;
  27 +import org.thingsboard.server.dao.model.BaseEntity;
27 28 import org.thingsboard.server.dao.model.type.JsonCodec;
28 29
29 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 13 * See the License for the specific language governing permissions and
14 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 18 import com.datastax.driver.core.utils.UUIDs;
19 19 import com.datastax.driver.mapping.annotations.*;
... ... @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSeverity;
25 25 import org.thingsboard.server.common.data.alarm.AlarmStatus;
26 26 import org.thingsboard.server.common.data.id.EntityIdFactory;
27 27 import org.thingsboard.server.common.data.id.TenantId;
  28 +import org.thingsboard.server.dao.model.BaseEntity;
28 29 import org.thingsboard.server.dao.model.type.AlarmSeverityCodec;
29 30 import org.thingsboard.server.dao.model.type.AlarmStatusCodec;
30 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 13 * See the License for the specific language governing permissions and
14 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 18 import com.datastax.driver.core.utils.UUIDs;
19 19 import com.datastax.driver.mapping.annotations.Column;
... ... @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.asset.Asset;
25 25 import org.thingsboard.server.common.data.id.AssetId;
26 26 import org.thingsboard.server.common.data.id.CustomerId;
27 27 import org.thingsboard.server.common.data.id.TenantId;
  28 +import org.thingsboard.server.dao.model.SearchTextEntity;
28 29 import org.thingsboard.server.dao.model.type.JsonCodec;
29 30
30 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 13 * See the License for the specific language governing permissions and
14 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 18 import com.datastax.driver.mapping.annotations.Column;
19 19 import com.datastax.driver.mapping.annotations.PartitionKey;
... ... @@ -23,41 +23,44 @@ import org.thingsboard.server.common.data.id.ComponentDescriptorId;
23 23 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
24 24 import org.thingsboard.server.common.data.plugin.ComponentScope;
25 25 import org.thingsboard.server.common.data.plugin.ComponentType;
  26 +import org.thingsboard.server.dao.model.SearchTextEntity;
26 27 import org.thingsboard.server.dao.model.type.JsonCodec;
27 28
28 29 import java.util.UUID;
29 30
  31 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  32 +
30 33 /**
31 34 * @author Andrew Shvayka
32 35 */
33   -@Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME)
  36 +@Table(name = COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME)
34 37 public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> {
35 38
36 39 private static final long serialVersionUID = 1L;
37 40
38 41 @PartitionKey
39   - @Column(name = ModelConstants.ID_PROPERTY)
  42 + @Column(name = ID_PROPERTY)
40 43 private UUID id;
41 44
42   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY)
  45 + @Column(name = COMPONENT_DESCRIPTOR_TYPE_PROPERTY)
43 46 private ComponentType type;
44 47
45   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY)
  48 + @Column(name = COMPONENT_DESCRIPTOR_SCOPE_PROPERTY)
46 49 private ComponentScope scope;
47 50
48   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY)
  51 + @Column(name = COMPONENT_DESCRIPTOR_NAME_PROPERTY)
49 52 private String name;
50 53
51   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY)
  54 + @Column(name = COMPONENT_DESCRIPTOR_CLASS_PROPERTY)
52 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 58 private JsonNode configurationDescriptor;
56 59
57   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
  60 + @Column(name = COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
58 61 private String actions;
59 62
60   - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
  63 + @Column(name = SEARCH_TEXT_PROPERTY)
61 64 private String searchText;
62 65
63 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 13 * See the License for the specific language governing permissions and
14 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 18 import java.util.UUID;
34 19
35 20 import org.thingsboard.server.common.data.Customer;
36 21 import org.thingsboard.server.common.data.id.CustomerId;
37 22 import org.thingsboard.server.common.data.id.TenantId;
  23 +import org.thingsboard.server.dao.model.SearchTextEntity;
38 24 import org.thingsboard.server.dao.model.type.JsonCodec;
39 25
40 26 import com.datastax.driver.core.utils.UUIDs;
... ... @@ -44,6 +30,8 @@ import com.datastax.driver.mapping.annotations.Table;
44 30 import com.datastax.driver.mapping.annotations.Transient;
45 31 import com.fasterxml.jackson.databind.JsonNode;
46 32
  33 +import static org.thingsboard.server.dao.model.ModelConstants.*;
  34 +
47 35 @Table(name = CUSTOMER_COLUMN_FAMILY_NAME)
48 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 13 * See the License for the specific language governing permissions and
14 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 18 import java.util.UUID;
19 19
... ... @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.Dashboard;
21 21 import org.thingsboard.server.common.data.id.CustomerId;
22 22 import org.thingsboard.server.common.data.id.DashboardId;
23 23 import org.thingsboard.server.common.data.id.TenantId;
  24 +import org.thingsboard.server.dao.model.SearchTextEntity;
24 25 import org.thingsboard.server.dao.model.type.JsonCodec;
25 26
26 27 import com.datastax.driver.core.utils.UUIDs;
... ... @@ -30,31 +31,33 @@ import com.datastax.driver.mapping.annotations.Table;
30 31 import com.datastax.driver.mapping.annotations.Transient;
31 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 37 public final class DashboardEntity implements SearchTextEntity<Dashboard> {
35 38
36 39 @Transient
37 40 private static final long serialVersionUID = 2998395951247446191L;
38 41
39 42 @PartitionKey(value = 0)
40   - @Column(name = ModelConstants.ID_PROPERTY)
  43 + @Column(name = ID_PROPERTY)
41 44 private UUID id;
42 45
43 46 @PartitionKey(value = 1)
44   - @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
  47 + @Column(name = DASHBOARD_TENANT_ID_PROPERTY)
45 48 private UUID tenantId;
46 49
47 50 @PartitionKey(value = 2)
48   - @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY)
  51 + @Column(name = DASHBOARD_CUSTOMER_ID_PROPERTY)
49 52 private UUID customerId;
50 53
51   - @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
  54 + @Column(name = DASHBOARD_TITLE_PROPERTY)
52 55 private String title;
53 56
54   - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
  57 + @Column(name = SEARCH_TEXT_PROPERTY)
55 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 61 private JsonNode configuration;
59 62
60 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 13 * See the License for the specific language governing permissions and
14 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 18 import java.util.UUID;
19 19
20   -import org.thingsboard.server.common.data.Dashboard;
21 20 import org.thingsboard.server.common.data.DashboardInfo;
22 21 import org.thingsboard.server.common.data.id.CustomerId;
23 22 import org.thingsboard.server.common.data.id.DashboardId;
24 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 26 import com.datastax.driver.core.utils.UUIDs;
28 27 import com.datastax.driver.mapping.annotations.Column;
29 28 import com.datastax.driver.mapping.annotations.PartitionKey;
30 29 import com.datastax.driver.mapping.annotations.Table;
31 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 35 public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
36 36
37 37 @Transient
38 38 private static final long serialVersionUID = 2998395951247446191L;
39 39
40 40 @PartitionKey(value = 0)
41   - @Column(name = ModelConstants.ID_PROPERTY)
  41 + @Column(name = ID_PROPERTY)
42 42 private UUID id;
43 43
44 44 @PartitionKey(value = 1)
45   - @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
  45 + @Column(name = DASHBOARD_TENANT_ID_PROPERTY)
46 46 private UUID tenantId;
47 47
48 48 @PartitionKey(value = 2)
49   - @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY)
  49 + @Column(name = DASHBOARD_CUSTOMER_ID_PROPERTY)
50 50 private UUID customerId;
51 51
52   - @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
  52 + @Column(name = DASHBOARD_TITLE_PROPERTY)
53 53 private String title;
54 54
55   - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
  55 + @Column(name = SEARCH_TEXT_PROPERTY)
56 56 private String searchText;
57 57
58 58 public DashboardInfoEntity() {
... ...