Commit 8450ca1454c064153223ac790fd59b5c54c9ea8a
Committed by
GitHub
Merge pull request #101 from volodymyr-babak/master
DAO refactoring
Showing
73 changed files
with
2168 additions
and
680 deletions
Too many changes to show.
To preserve performance only 73 of 133 files are displayed.
... | ... | @@ -15,16 +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.ExecutionException; | |
21 | -import java.util.concurrent.Executor; | |
22 | -import java.util.concurrent.Executors; | |
23 | -import java.util.stream.Collectors; | |
24 | - | |
25 | -import com.datastax.driver.core.ResultSet; | |
26 | -import com.datastax.driver.core.ResultSetFuture; | |
27 | -import com.datastax.driver.core.Row; | |
18 | +import akka.actor.ActorRef; | |
28 | 19 | import com.google.common.base.Function; |
29 | 20 | import com.google.common.util.concurrent.FutureCallback; |
30 | 21 | import com.google.common.util.concurrent.Futures; |
... | ... | @@ -32,18 +23,20 @@ import com.google.common.util.concurrent.ListenableFuture; |
32 | 23 | import lombok.extern.slf4j.Slf4j; |
33 | 24 | import org.thingsboard.server.common.data.DataConstants; |
34 | 25 | import org.thingsboard.server.common.data.Device; |
35 | -import org.thingsboard.server.common.data.id.*; | |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | |
27 | +import org.thingsboard.server.common.data.id.DeviceId; | |
28 | +import org.thingsboard.server.common.data.id.PluginId; | |
29 | +import org.thingsboard.server.common.data.id.TenantId; | |
36 | 30 | import org.thingsboard.server.common.data.kv.AttributeKey; |
37 | 31 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
38 | 32 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
39 | 33 | import org.thingsboard.server.common.data.kv.TsKvQuery; |
40 | -import org.thingsboard.server.common.data.page.TextPageData; | |
41 | 34 | import org.thingsboard.server.common.data.page.TextPageLink; |
42 | 35 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
43 | 36 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
44 | 37 | import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; |
45 | -import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
46 | 38 | import org.thingsboard.server.extensions.api.plugins.PluginCallback; |
39 | +import org.thingsboard.server.extensions.api.plugins.PluginContext; | |
47 | 40 | import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; |
48 | 41 | import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; |
49 | 42 | import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest; |
... | ... | @@ -52,10 +45,12 @@ import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
52 | 45 | import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; |
53 | 46 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; |
54 | 47 | |
55 | -import akka.actor.ActorRef; | |
56 | -import org.w3c.dom.Attr; | |
57 | - | |
58 | 48 | import javax.annotation.Nullable; |
49 | +import java.io.IOException; | |
50 | +import java.util.*; | |
51 | +import java.util.concurrent.Executor; | |
52 | +import java.util.concurrent.Executors; | |
53 | +import java.util.stream.Collectors; | |
59 | 54 | |
60 | 55 | @Slf4j |
61 | 56 | public final class PluginProcessingContext implements PluginContext { | ... | ... |
... | ... | @@ -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; | ... | ... |
... | ... | @@ -23,19 +23,16 @@ import org.thingsboard.server.common.data.Device; |
23 | 23 | import org.thingsboard.server.common.data.id.CustomerId; |
24 | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
25 | 25 | import org.thingsboard.server.common.data.id.TenantId; |
26 | -import org.thingsboard.server.common.data.id.UUIDBased; | |
27 | 26 | import org.thingsboard.server.common.data.page.TextPageData; |
28 | 27 | import org.thingsboard.server.common.data.page.TextPageLink; |
29 | 28 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
30 | 29 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
31 | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | 31 | import org.thingsboard.server.exception.ThingsboardException; |
33 | -import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; | |
34 | 32 | import org.thingsboard.server.service.security.model.SecurityUser; |
35 | 33 | |
36 | 34 | import java.util.ArrayList; |
37 | 35 | import java.util.List; |
38 | -import java.util.UUID; | |
39 | 36 | |
40 | 37 | @RestController |
41 | 38 | @RequestMapping("/api") | ... | ... |
... | ... | @@ -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 | ... | ... |
... | ... | @@ -188,3 +188,15 @@ cache: |
188 | 188 | updates: |
189 | 189 | # Enable/disable updates checking. |
190 | 190 | enabled: "${UPDATES_ENABLED:true}" |
191 | + | |
192 | +cassandra: | |
193 | + enabled: "${CASSANDRA_ENABLED:true}" | |
194 | + | |
195 | +# SQL DAO Configuration | |
196 | + | |
197 | +sql: | |
198 | + enabled: "${SQL_ENABLED:false}" | |
199 | + datasource: | |
200 | + url: "${SQL_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}" | |
201 | + username: "${SQL_DATASOURCE_USERNAME:postgres}" | |
202 | + password: "${SQL_DATASOURCE_PASSWORD:postgres}" | ... | ... |
... | ... | @@ -35,7 +35,6 @@ import org.junit.Assert; |
35 | 35 | import org.junit.Before; |
36 | 36 | import org.junit.Test; |
37 | 37 | |
38 | -import com.datastax.driver.core.utils.UUIDs; | |
39 | 38 | import com.fasterxml.jackson.core.type.TypeReference; |
40 | 39 | |
41 | 40 | public class DashboardControllerTest extends AbstractControllerTest { | ... | ... |
... | ... | @@ -42,7 +42,6 @@ import org.junit.Assert; |
42 | 42 | import org.junit.Before; |
43 | 43 | import org.junit.Test; |
44 | 44 | |
45 | -import com.datastax.driver.core.utils.UUIDs; | |
46 | 45 | import com.fasterxml.jackson.core.type.TypeReference; |
47 | 46 | |
48 | 47 | public class DeviceControllerTest extends AbstractControllerTest { | ... | ... |
... | ... | @@ -15,14 +15,11 @@ |
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.SearchTextBased; |
21 | -import org.thingsboard.server.common.data.id.CustomerId; | |
22 | 21 | import org.thingsboard.server.common.data.id.RuleId; |
23 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
24 | - | |
25 | -import com.fasterxml.jackson.databind.JsonNode; | |
26 | 23 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
27 | 24 | |
28 | 25 | @Data | ... | ... |
... | ... | @@ -150,6 +150,10 @@ |
150 | 150 | <groupId>org.bouncycastle</groupId> |
151 | 151 | <artifactId>bcprov-jdk15on</artifactId> |
152 | 152 | </dependency> |
153 | + <dependency> | |
154 | + <groupId>org.springframework.boot</groupId> | |
155 | + <artifactId>spring-boot-starter-data-jpa</artifactId> | |
156 | + </dependency> | |
153 | 157 | </dependencies> |
154 | 158 | <build> |
155 | 159 | <plugins> | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/CassandraAbstractAsyncDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/AbstractAsyncDao.java
... | ... | @@ -23,7 +23,7 @@ import java.util.concurrent.Executors; |
23 | 23 | /** |
24 | 24 | * Created by ashvayka on 21.02.17. |
25 | 25 | */ |
26 | -public abstract class AbstractAsyncDao extends AbstractDao { | |
26 | +public abstract class CassandraAbstractAsyncDao extends CassandraAbstractDao { | |
27 | 27 | |
28 | 28 | protected ExecutorService readResultsProcessingExecutor; |
29 | 29 | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/CassandraAbstractDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/AbstractDao.java
... | ... | @@ -23,7 +23,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster; |
23 | 23 | import org.thingsboard.server.dao.model.type.*; |
24 | 24 | |
25 | 25 | @Slf4j |
26 | -public abstract class AbstractDao { | |
26 | +public abstract class CassandraAbstractDao { | |
27 | 27 | |
28 | 28 | @Autowired |
29 | 29 | protected CassandraCluster cluster; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/CassandraAbstractModelDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/AbstractModelDao.java
... | ... | @@ -28,8 +28,9 @@ import com.google.common.util.concurrent.Futures; |
28 | 28 | import com.google.common.util.concurrent.ListenableFuture; |
29 | 29 | import lombok.extern.slf4j.Slf4j; |
30 | 30 | import org.thingsboard.server.dao.model.BaseEntity; |
31 | -import org.thingsboard.server.dao.model.wrapper.EntityResultSet; | |
32 | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
33 | +import org.thingsboard.server.dao.model.wrapper.EntityResultSet; | |
33 | 34 | |
34 | 35 | import javax.annotation.Nullable; |
35 | 36 | import java.util.Collections; |
... | ... | @@ -37,26 +38,29 @@ import java.util.List; |
37 | 38 | import java.util.UUID; |
38 | 39 | |
39 | 40 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
40 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.lt; | |
41 | 41 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
42 | 42 | |
43 | 43 | @Slf4j |
44 | -public abstract class AbstractModelDao<T extends BaseEntity<?>> extends AbstractDao implements Dao<T> { | |
44 | +public abstract class CassandraAbstractModelDao<E extends BaseEntity<D>, D> extends CassandraAbstractDao implements Dao<D> { | |
45 | 45 | |
46 | - protected abstract Class<T> getColumnFamilyClass(); | |
46 | + protected abstract Class<E> getColumnFamilyClass(); | |
47 | 47 | |
48 | 48 | protected abstract String getColumnFamilyName(); |
49 | 49 | |
50 | - protected Mapper<T> getMapper() { | |
50 | + protected boolean isSearchTextDao() { | |
51 | + return false; | |
52 | + } | |
53 | + | |
54 | + protected Mapper<E> getMapper() { | |
51 | 55 | return cluster.getMapper(getColumnFamilyClass()); |
52 | 56 | } |
53 | 57 | |
54 | - protected List<T> findListByStatement(Statement statement) { | |
55 | - List<T> list = Collections.emptyList(); | |
58 | + protected List<E> findListByStatement(Statement statement) { | |
59 | + List<E> list = Collections.emptyList(); | |
56 | 60 | if (statement != null) { |
57 | 61 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
58 | 62 | ResultSet resultSet = getSession().execute(statement); |
59 | - Result<T> result = getMapper().map(resultSet); | |
63 | + Result<E> result = getMapper().map(resultSet); | |
60 | 64 | if (result != null) { |
61 | 65 | list = result.all(); |
62 | 66 | } |
... | ... | @@ -64,33 +68,33 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract |
64 | 68 | return list; |
65 | 69 | } |
66 | 70 | |
67 | - protected ListenableFuture<List<T>> findListByStatementAsync(Statement statement) { | |
71 | + protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) { | |
68 | 72 | if (statement != null) { |
69 | 73 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
70 | 74 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); |
71 | - ListenableFuture<List<T>> result = Futures.transform(resultSetFuture, new Function<ResultSet, List<T>>() { | |
75 | + return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() { | |
72 | 76 | @Nullable |
73 | 77 | @Override |
74 | - public List<T> apply(@Nullable ResultSet resultSet) { | |
75 | - Result<T> result = getMapper().map(resultSet); | |
78 | + public List<D> apply(@Nullable ResultSet resultSet) { | |
79 | + Result<E> result = getMapper().map(resultSet); | |
76 | 80 | if (result != null) { |
77 | - return result.all(); | |
81 | + List<E> entities = result.all(); | |
82 | + return DaoUtil.convertDataList(entities); | |
78 | 83 | } else { |
79 | 84 | return Collections.emptyList(); |
80 | 85 | } |
81 | 86 | } |
82 | 87 | }); |
83 | - return result; | |
84 | 88 | } |
85 | 89 | return Futures.immediateFuture(Collections.emptyList()); |
86 | 90 | } |
87 | 91 | |
88 | - protected T findOneByStatement(Statement statement) { | |
89 | - T object = null; | |
92 | + protected E findOneByStatement(Statement statement) { | |
93 | + E object = null; | |
90 | 94 | if (statement != null) { |
91 | 95 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
92 | 96 | ResultSet resultSet = getSession().execute(statement); |
93 | - Result<T> result = getMapper().map(resultSet); | |
97 | + Result<E> result = getMapper().map(resultSet); | |
94 | 98 | if (result != null) { |
95 | 99 | object = result.one(); |
96 | 100 | } |
... | ... | @@ -98,32 +102,32 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract |
98 | 102 | return object; |
99 | 103 | } |
100 | 104 | |
101 | - protected ListenableFuture<T> findOneByStatementAsync(Statement statement) { | |
105 | + protected ListenableFuture<D> findOneByStatementAsync(Statement statement) { | |
102 | 106 | if (statement != null) { |
103 | 107 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
104 | 108 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); |
105 | - ListenableFuture<T> result = Futures.transform(resultSetFuture, new Function<ResultSet, T>() { | |
109 | + return Futures.transform(resultSetFuture, new Function<ResultSet, D>() { | |
106 | 110 | @Nullable |
107 | 111 | @Override |
108 | - public T apply(@Nullable ResultSet resultSet) { | |
109 | - Result<T> result = getMapper().map(resultSet); | |
112 | + public D apply(@Nullable ResultSet resultSet) { | |
113 | + Result<E> result = getMapper().map(resultSet); | |
110 | 114 | if (result != null) { |
111 | - return result.one(); | |
115 | + E entity = result.one(); | |
116 | + return DaoUtil.getData(entity); | |
112 | 117 | } else { |
113 | 118 | return null; |
114 | 119 | } |
115 | 120 | } |
116 | 121 | }); |
117 | - return result; | |
118 | 122 | } |
119 | 123 | return Futures.immediateFuture(null); |
120 | 124 | } |
121 | 125 | |
122 | - protected Statement getSaveQuery(T dto) { | |
126 | + protected Statement getSaveQuery(E dto) { | |
123 | 127 | return getMapper().saveQuery(dto); |
124 | 128 | } |
125 | 129 | |
126 | - protected EntityResultSet<T> saveWithResult(T entity) { | |
130 | + protected EntityResultSet<E> saveWithResult(E entity) { | |
127 | 131 | log.debug("Save entity {}", entity); |
128 | 132 | if (entity.getId() == null) { |
129 | 133 | entity.setId(UUIDs.timeBased()); |
... | ... | @@ -136,34 +140,51 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract |
136 | 140 | return new EntityResultSet<>(resultSet, entity); |
137 | 141 | } |
138 | 142 | |
139 | - public T save(T entity) { | |
140 | - return saveWithResult(entity).getEntity(); | |
143 | + @Override | |
144 | + public D save(D domain) { | |
145 | + E entity; | |
146 | + try { | |
147 | + entity = getColumnFamilyClass().getConstructor(domain.getClass()).newInstance(domain); | |
148 | + } catch (Exception e) { | |
149 | + log.error("Can't create entity for domain object {}", domain, e); | |
150 | + throw new IllegalArgumentException("Can't create entity for domain object {" + domain + "}", e); | |
151 | + } | |
152 | + if (isSearchTextDao()) { | |
153 | + ((SearchTextEntity) entity).setSearchText(((SearchTextEntity) entity).getSearchTextSource().toLowerCase()); | |
154 | + } | |
155 | + log.debug("Saving entity {}", entity); | |
156 | + entity = saveWithResult(entity).getEntity(); | |
157 | + return DaoUtil.getData(entity); | |
141 | 158 | } |
142 | 159 | |
143 | - public T findById(UUID key) { | |
160 | + @Override | |
161 | + public D findById(UUID key) { | |
144 | 162 | log.debug("Get entity by key {}", key); |
145 | 163 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
146 | 164 | log.trace("Execute query {}", query); |
147 | - return findOneByStatement(query); | |
165 | + E entity = findOneByStatement(query); | |
166 | + return DaoUtil.getData(entity); | |
148 | 167 | } |
149 | 168 | |
150 | - public ListenableFuture<T> findByIdAsync(UUID key) { | |
169 | + @Override | |
170 | + public ListenableFuture<D> findByIdAsync(UUID key) { | |
151 | 171 | log.debug("Get entity by key {}", key); |
152 | 172 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
153 | 173 | log.trace("Execute query {}", query); |
154 | 174 | return findOneByStatementAsync(query); |
155 | 175 | } |
156 | 176 | |
157 | - | |
158 | - public ResultSet removeById(UUID key) { | |
177 | + @Override | |
178 | + public boolean removeById(UUID key) { | |
159 | 179 | Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
160 | 180 | log.debug("Remove request: {}", delete.toString()); |
161 | - return getSession().execute(delete); | |
181 | + return getSession().execute(delete).wasApplied(); | |
162 | 182 | } |
163 | 183 | |
164 | - | |
165 | - public List<T> find() { | |
184 | + @Override | |
185 | + public List<D> find() { | |
166 | 186 | log.debug("Get all entities from column family {}", getColumnFamilyName()); |
167 | - return findListByStatement(QueryBuilder.select().all().from(getColumnFamilyName()).setConsistencyLevel(cluster.getDefaultReadConsistencyLevel())); | |
187 | + List<E> entities = findListByStatement(QueryBuilder.select().all().from(getColumnFamilyName()).setConsistencyLevel(cluster.getDefaultReadConsistencyLevel())); | |
188 | + return DaoUtil.convertDataList(entities); | |
168 | 189 | } |
169 | 190 | } | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/CassandraAbstractSearchTextDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/AbstractSearchTextDao.java
... | ... | @@ -19,27 +19,26 @@ import com.datastax.driver.core.querybuilder.Clause; |
19 | 19 | import com.datastax.driver.core.querybuilder.QueryBuilder; |
20 | 20 | import com.datastax.driver.core.querybuilder.Select; |
21 | 21 | import com.datastax.driver.core.querybuilder.Select.Where; |
22 | +import lombok.extern.slf4j.Slf4j; | |
22 | 23 | import org.apache.commons.lang3.StringUtils; |
23 | 24 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | -import org.thingsboard.server.dao.model.SearchTextEntity; | |
25 | 25 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
26 | 27 | |
27 | 28 | import java.util.List; |
28 | 29 | |
29 | 30 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
30 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.gt; | |
31 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.gte; | |
32 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.lt; | |
33 | 31 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
34 | 32 | |
35 | -public abstract class AbstractSearchTextDao<T extends SearchTextEntity<?>> extends AbstractModelDao<T> { | |
33 | +@Slf4j | |
34 | +public abstract class CassandraAbstractSearchTextDao<E extends SearchTextEntity<D>, D> extends CassandraAbstractModelDao<E, D> { | |
36 | 35 | |
37 | - public T save(T entity) { | |
38 | - entity.setSearchText(entity.getSearchTextSource().toLowerCase()); | |
39 | - return super.save(entity); | |
36 | + @Override | |
37 | + protected boolean isSearchTextDao() { | |
38 | + return true; | |
40 | 39 | } |
41 | - | |
42 | - protected List<T> findPageWithTextSearch(String searchView, List<Clause> clauses, TextPageLink pageLink) { | |
40 | + | |
41 | + protected List<E> findPageWithTextSearch(String searchView, List<Clause> clauses, TextPageLink pageLink) { | |
43 | 42 | Select select = select().from(searchView); |
44 | 43 | Where query = select.where(); |
45 | 44 | for (Clause clause : clauses) { |
... | ... | @@ -49,7 +48,7 @@ public abstract class AbstractSearchTextDao<T extends SearchTextEntity<?>> exten |
49 | 48 | if (!StringUtils.isEmpty(pageLink.getTextOffset())) { |
50 | 49 | query.and(eq(ModelConstants.SEARCH_TEXT_PROPERTY, pageLink.getTextOffset())); |
51 | 50 | query.and(QueryBuilder.lt(ModelConstants.ID_PROPERTY, pageLink.getIdOffset())); |
52 | - List<T> result = findListByStatement(query); | |
51 | + List<E> result = findListByStatement(query); | |
53 | 52 | if (result.size() < pageLink.getLimit()) { |
54 | 53 | select = select().from(searchView); |
55 | 54 | query = select.where(); | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/CassandraAbstractSearchTimeDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/AbstractSearchTimeDao.java
... | ... | @@ -21,34 +21,29 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; |
21 | 21 | import com.datastax.driver.core.querybuilder.Select; |
22 | 22 | import com.datastax.driver.core.querybuilder.Select.Where; |
23 | 23 | import com.datastax.driver.core.utils.UUIDs; |
24 | -import org.apache.commons.lang3.StringUtils; | |
25 | -import org.thingsboard.server.common.data.page.TextPageLink; | |
26 | 24 | import org.thingsboard.server.common.data.page.TimePageLink; |
27 | 25 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | -import org.thingsboard.server.dao.model.SearchTextEntity; | |
30 | 27 | |
31 | 28 | import java.util.ArrayList; |
32 | 29 | import java.util.Collections; |
33 | 30 | import java.util.List; |
34 | 31 | import java.util.UUID; |
35 | 32 | |
36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
37 | 33 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
38 | 34 | |
39 | -public abstract class AbstractSearchTimeDao<T extends BaseEntity<?>> extends AbstractModelDao<T> { | |
35 | +public abstract class CassandraAbstractSearchTimeDao<E extends BaseEntity<D>, D> extends CassandraAbstractModelDao<E, D> { | |
40 | 36 | |
41 | 37 | |
42 | - protected List<T> findPageWithTimeSearch(String searchView, List<Clause> clauses, TimePageLink pageLink) { | |
38 | + protected List<E> findPageWithTimeSearch(String searchView, List<Clause> clauses, TimePageLink pageLink) { | |
43 | 39 | return findPageWithTimeSearch(searchView, clauses, Collections.emptyList(), pageLink); |
44 | 40 | } |
45 | 41 | |
46 | - protected List<T> findPageWithTimeSearch(String searchView, List<Clause> clauses, Ordering ordering, TimePageLink pageLink) { | |
42 | + protected List<E> findPageWithTimeSearch(String searchView, List<Clause> clauses, Ordering ordering, TimePageLink pageLink) { | |
47 | 43 | return findPageWithTimeSearch(searchView, clauses, Collections.singletonList(ordering), pageLink); |
48 | 44 | } |
49 | 45 | |
50 | - | |
51 | - protected List<T> findPageWithTimeSearch(String searchView, List<Clause> clauses, List<Ordering> topLevelOrderings, TimePageLink pageLink) { | |
46 | + protected List<E> findPageWithTimeSearch(String searchView, List<Clause> clauses, List<Ordering> topLevelOrderings, TimePageLink pageLink) { | |
52 | 47 | Select select = select().from(searchView); |
53 | 48 | Where query = select.where(); |
54 | 49 | for (Clause clause : clauses) { | ... | ... |
... | ... | @@ -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() { | ... | ... |
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.beans.factory.annotation.Value; | |
19 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
20 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; | |
21 | +import org.springframework.context.annotation.Configuration; | |
22 | + | |
23 | +import javax.sql.DataSource; | |
24 | + | |
25 | +/** | |
26 | + * @author Valerii Sosliuk | |
27 | + */ | |
28 | +@Configuration | |
29 | +@ConditionalOnProperty(prefix="sql", value="enabled",havingValue = "true", matchIfMissing = false) | |
30 | +public class JpaDaoConfig { | |
31 | + | |
32 | + @Value("sql.datasource.url") | |
33 | + private String url; | |
34 | + @Value("sql.datasource.username") | |
35 | + private String username; | |
36 | + @Value("sql.datasource.password") | |
37 | + private String password; | |
38 | + | |
39 | + public DataSource dataSource() { | |
40 | + return DataSourceBuilder.create().url(url).username(username).password(password).build(); | |
41 | + } | |
42 | +} | ... | ... |
... | ... | @@ -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; | ... | ... |
... | ... | @@ -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; | ... | ... |
... | ... | @@ -15,16 +15,14 @@ |
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.collect.Lists; |
21 | 19 | import com.google.common.util.concurrent.Futures; |
22 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
21 | +import org.springframework.beans.factory.annotation.Autowired; | |
22 | +import org.springframework.stereotype.Service; | |
23 | 23 | import org.thingsboard.server.common.data.id.EntityId; |
24 | 24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | 25 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
26 | -import org.springframework.beans.factory.annotation.Autowired; | |
27 | -import org.springframework.stereotype.Service; | |
28 | 26 | import org.thingsboard.server.dao.service.Validator; |
29 | 27 | |
30 | 28 | import java.util.Collection; | ... | ... |
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,11 @@ 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.CassandraAbstractAsyncDao; | |
28 | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | -import org.thingsboard.server.common.data.kv.*; | |
30 | -import org.thingsboard.server.dao.timeseries.BaseTimeseriesDao; | |
31 | +import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; | |
31 | 32 | |
32 | 33 | import javax.annotation.PostConstruct; |
33 | 34 | import javax.annotation.PreDestroy; |
... | ... | @@ -37,15 +38,16 @@ import java.util.List; |
37 | 38 | import java.util.Optional; |
38 | 39 | import java.util.stream.Collectors; |
39 | 40 | |
41 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
42 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
40 | 43 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
41 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
42 | 44 | |
43 | 45 | /** |
44 | 46 | * @author Andrew Shvayka |
45 | 47 | */ |
46 | 48 | @Component |
47 | 49 | @Slf4j |
48 | -public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao { | |
50 | +public class CassandraBaseAttributesDao extends CassandraAbstractAsyncDao implements AttributesDao { | |
49 | 51 | |
50 | 52 | private PreparedStatement saveStmt; |
51 | 53 | |
... | ... | @@ -161,7 +163,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao |
161 | 163 | AttributeKvEntry attributeEntry = null; |
162 | 164 | if (row != null) { |
163 | 165 | long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class); |
164 | - attributeEntry = new BaseAttributeKvEntry(BaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs); | |
166 | + attributeEntry = new BaseAttributeKvEntry(CassandraBaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs); | |
165 | 167 | } |
166 | 168 | return attributeEntry; |
167 | 169 | } | ... | ... |
... | ... | @@ -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,16 +26,13 @@ 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; | |
35 | 29 | |
36 | 30 | import javax.annotation.PostConstruct; |
37 | 31 | import javax.annotation.PreDestroy; |
38 | -import java.io.Closeable; | |
39 | 32 | import java.net.InetSocketAddress; |
40 | 33 | import java.util.ArrayList; |
41 | 34 | import java.util.Collections; |
42 | 35 | import java.util.List; |
43 | -import java.util.StringTokenizer; | |
44 | 36 | |
45 | 37 | @Component |
46 | 38 | @Slf4j | ... | ... |
... | ... | @@ -21,12 +21,9 @@ 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; | |
25 | 24 | |
26 | 25 | import javax.annotation.PostConstruct; |
27 | 26 | |
28 | -import static org.apache.commons.lang3.StringUtils.isNotBlank; | |
29 | - | |
30 | 27 | @Component |
31 | 28 | @Configuration |
32 | 29 | @Data | ... | ... |
... | ... | @@ -15,13 +15,12 @@ |
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 | |
23 | -import com.datastax.driver.core.SocketOptions; | |
24 | - | |
25 | 24 | import javax.annotation.PostConstruct; |
26 | 25 | |
27 | 26 | @Component | ... | ... |
... | ... | @@ -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,10 @@ 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.CassandraAbstractSearchTextDao; | |
31 | +import org.thingsboard.server.dao.DaoUtil; | |
32 | +import org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity; | |
31 | 33 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | -import org.thingsboard.server.dao.model.ComponentDescriptorEntity; | |
33 | 34 | |
34 | 35 | import java.util.Arrays; |
35 | 36 | import java.util.List; |
... | ... | @@ -44,7 +45,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
44 | 45 | */ |
45 | 46 | @Component |
46 | 47 | @Slf4j |
47 | -public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentDescriptorEntity> implements ComponentDescriptorDao { | |
48 | +public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao { | |
48 | 49 | |
49 | 50 | @Override |
50 | 51 | protected Class<ComponentDescriptorEntity> getColumnFamilyClass() { |
... | ... | @@ -57,10 +58,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
57 | 58 | } |
58 | 59 | |
59 | 60 | @Override |
60 | - public Optional<ComponentDescriptorEntity> save(ComponentDescriptor component) { | |
61 | + public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) { | |
61 | 62 | ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component); |
62 | 63 | log.debug("Save component entity [{}]", entity); |
63 | - Optional<ComponentDescriptorEntity> result = saveIfNotExist(entity); | |
64 | + Optional<ComponentDescriptor> result = saveIfNotExist(entity); | |
64 | 65 | if (log.isTraceEnabled()) { |
65 | 66 | log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null)); |
66 | 67 | } else { |
... | ... | @@ -70,19 +71,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
70 | 71 | } |
71 | 72 | |
72 | 73 | @Override |
73 | - public ComponentDescriptorEntity findById(ComponentDescriptorId componentId) { | |
74 | + public ComponentDescriptor findById(ComponentDescriptorId componentId) { | |
74 | 75 | log.debug("Search component entity by id [{}]", componentId); |
75 | - ComponentDescriptorEntity entity = super.findById(componentId.getId()); | |
76 | + ComponentDescriptor componentDescriptor = super.findById(componentId.getId()); | |
76 | 77 | if (log.isTraceEnabled()) { |
77 | - log.trace("Search result: [{}] for component entity [{}]", entity != null, entity); | |
78 | + log.trace("Search result: [{}] for component entity [{}]", componentDescriptor != null, componentDescriptor); | |
78 | 79 | } else { |
79 | - log.debug("Search result: [{}]", entity != null); | |
80 | + log.debug("Search result: [{}]", componentDescriptor != null); | |
80 | 81 | } |
81 | - return entity; | |
82 | + return componentDescriptor; | |
82 | 83 | } |
83 | 84 | |
84 | 85 | @Override |
85 | - public ComponentDescriptorEntity findByClazz(String clazz) { | |
86 | + public ComponentDescriptor findByClazz(String clazz) { | |
86 | 87 | log.debug("Search component entity by clazz [{}]", clazz); |
87 | 88 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); |
88 | 89 | log.trace("Execute query [{}]", query); |
... | ... | @@ -92,11 +93,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
92 | 93 | } else { |
93 | 94 | log.debug("Search result: [{}]", entity != null); |
94 | 95 | } |
95 | - return entity; | |
96 | + return DaoUtil.getData(entity); | |
96 | 97 | } |
97 | 98 | |
98 | 99 | @Override |
99 | - public List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { | |
100 | + public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { | |
100 | 101 | log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink); |
101 | 102 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
102 | 103 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name())), pageLink); |
... | ... | @@ -105,11 +106,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
105 | 106 | } else { |
106 | 107 | log.debug("Search result: [{}]", entities.size()); |
107 | 108 | } |
108 | - return entities; | |
109 | + return DaoUtil.convertDataList(entities); | |
109 | 110 | } |
110 | 111 | |
111 | 112 | @Override |
112 | - public List<ComponentDescriptorEntity> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { | |
113 | + public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { | |
113 | 114 | log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink); |
114 | 115 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
115 | 116 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name()), |
... | ... | @@ -119,20 +120,20 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
119 | 120 | } else { |
120 | 121 | log.debug("Search result: [{}]", entities.size()); |
121 | 122 | } |
122 | - return entities; | |
123 | + return DaoUtil.convertDataList(entities); | |
123 | 124 | } |
124 | 125 | |
125 | - public ResultSet removeById(UUID key) { | |
126 | + public boolean removeById(UUID key) { | |
126 | 127 | Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key)); |
127 | 128 | log.debug("Remove request: {}", delete.toString()); |
128 | - return getSession().execute(delete); | |
129 | + return getSession().execute(delete).wasApplied(); | |
129 | 130 | } |
130 | 131 | |
131 | 132 | @Override |
132 | 133 | public void deleteById(ComponentDescriptorId id) { |
133 | 134 | log.debug("Delete plugin meta-data entity by id [{}]", id); |
134 | - ResultSet resultSet = removeById(id.getId()); | |
135 | - log.debug("Delete result: [{}]", resultSet.wasApplied()); | |
135 | + boolean result = removeById(id.getId()); | |
136 | + log.debug("Delete result: [{}]", result); | |
136 | 137 | } |
137 | 138 | |
138 | 139 | @Override |
... | ... | @@ -144,7 +145,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
144 | 145 | log.debug("Delete result: [{}]", resultSet.wasApplied()); |
145 | 146 | } |
146 | 147 | |
147 | - private Optional<ComponentDescriptorEntity> saveIfNotExist(ComponentDescriptorEntity entity) { | |
148 | + private Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptorEntity entity) { | |
148 | 149 | if (entity.getId() == null) { |
149 | 150 | entity.setId(UUIDs.timeBased()); |
150 | 151 | } |
... | ... | @@ -161,7 +162,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD |
161 | 162 | .ifNotExists() |
162 | 163 | ); |
163 | 164 | if (rs.wasApplied()) { |
164 | - return Optional.of(entity); | |
165 | + return Optional.of(DaoUtil.getData(entity)); | |
165 | 166 | } else { |
166 | 167 | return Optional.empty(); |
167 | 168 | } | ... | ... |
... | ... | @@ -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,24 +15,23 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | |
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
19 | - | |
20 | -import java.util.Arrays; | |
21 | -import java.util.List; | |
22 | -import java.util.UUID; | |
23 | - | |
24 | 18 | import lombok.extern.slf4j.Slf4j; |
25 | 19 | import org.springframework.stereotype.Component; |
26 | 20 | import org.thingsboard.server.common.data.Customer; |
27 | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
28 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | |
29 | -import org.thingsboard.server.dao.model.CustomerEntity; | |
30 | -import org.slf4j.Logger; | |
31 | -import org.slf4j.LoggerFactory; | |
22 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; | |
23 | +import org.thingsboard.server.dao.DaoUtil; | |
24 | +import org.thingsboard.server.dao.model.nosql.CustomerEntity; | |
32 | 25 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | + | |
27 | +import java.util.Arrays; | |
28 | +import java.util.List; | |
29 | +import java.util.UUID; | |
30 | + | |
31 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
33 | 32 | @Component |
34 | 33 | @Slf4j |
35 | -public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> implements CustomerDao { | |
34 | +public class CassandraCustomerDao extends CassandraAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao { | |
36 | 35 | |
37 | 36 | @Override |
38 | 37 | protected Class<CustomerEntity> getColumnFamilyClass() { |
... | ... | @@ -43,21 +42,15 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple |
43 | 42 | protected String getColumnFamilyName() { |
44 | 43 | return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; |
45 | 44 | } |
46 | - | |
47 | - @Override | |
48 | - public CustomerEntity save(Customer customer) { | |
49 | - log.debug("Save customer [{}] ", customer); | |
50 | - return save(new CustomerEntity(customer)); | |
51 | - } | |
52 | 45 | |
53 | 46 | @Override |
54 | - public List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { | |
47 | + public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { | |
55 | 48 | log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
56 | 49 | List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
57 | 50 | Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)), |
58 | 51 | pageLink); |
59 | 52 | log.trace("Found customers [{}] by tenantId [{}] and pageLink [{}]", customerEntities, tenantId, pageLink); |
60 | - return customerEntities; | |
53 | + return DaoUtil.convertDataList(customerEntities); | |
61 | 54 | } |
62 | 55 | |
63 | 56 | } | ... | ... |
... | ... | @@ -15,18 +15,17 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | |
18 | -import java.util.List; | |
19 | -import java.util.UUID; | |
20 | - | |
21 | 18 | import org.thingsboard.server.common.data.Customer; |
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.CustomerEntity; | |
21 | + | |
22 | +import java.util.List; | |
23 | +import java.util.UUID; | |
25 | 24 | |
26 | 25 | /** |
27 | 26 | * The Interface CustomerDao. |
28 | 27 | */ |
29 | -public interface CustomerDao extends Dao<CustomerEntity> { | |
28 | +public interface CustomerDao extends Dao<Customer> { | |
30 | 29 | |
31 | 30 | /** |
32 | 31 | * Save or update customer object |
... | ... | @@ -34,7 +33,7 @@ public interface CustomerDao extends Dao<CustomerEntity> { |
34 | 33 | * @param customer the customer object |
35 | 34 | * @return saved customer object |
36 | 35 | */ |
37 | - CustomerEntity save(Customer customer); | |
36 | + Customer save(Customer customer); | |
38 | 37 | |
39 | 38 | /** |
40 | 39 | * Find customers by tenant id and page link. |
... | ... | @@ -43,6 +42,6 @@ public interface CustomerDao extends Dao<CustomerEntity> { |
43 | 42 | * @param pageLink the page link |
44 | 43 | * @return the list of customer objects |
45 | 44 | */ |
46 | - List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink); | |
45 | + List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink); | |
47 | 46 | |
48 | 47 | } | ... | ... |
... | ... | @@ -23,14 +23,14 @@ import org.thingsboard.server.common.data.page.TextPageLink; |
23 | 23 | |
24 | 24 | public interface CustomerService { |
25 | 25 | |
26 | - public Customer findCustomerById(CustomerId customerId); | |
26 | + Customer findCustomerById(CustomerId customerId); | |
27 | 27 | |
28 | - public Customer saveCustomer(Customer customer); | |
28 | + Customer saveCustomer(Customer customer); | |
29 | 29 | |
30 | - public void deleteCustomer(CustomerId customerId); | |
30 | + void deleteCustomer(CustomerId customerId); | |
31 | 31 | |
32 | - public TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink); | |
32 | + TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink); | |
33 | 33 | |
34 | - public void deleteCustomersByTenantId(TenantId tenantId); | |
34 | + void deleteCustomersByTenantId(TenantId tenantId); | |
35 | 35 | |
36 | 36 | } | ... | ... |
... | ... | @@ -15,14 +15,12 @@ |
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 | - | |
21 | -import java.util.List; | |
22 | - | |
23 | 18 | import lombok.extern.slf4j.Slf4j; |
24 | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | |
21 | +import org.springframework.stereotype.Service; | |
25 | 22 | import org.thingsboard.server.common.data.Customer; |
23 | +import org.thingsboard.server.common.data.Tenant; | |
26 | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | 25 | import org.thingsboard.server.common.data.id.TenantId; |
28 | 26 | import org.thingsboard.server.common.data.page.TextPageData; |
... | ... | @@ -31,17 +29,13 @@ import org.thingsboard.server.dao.dashboard.DashboardService; |
31 | 29 | import org.thingsboard.server.dao.device.DeviceService; |
32 | 30 | import org.thingsboard.server.dao.exception.DataValidationException; |
33 | 31 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
34 | -import org.thingsboard.server.dao.model.CustomerEntity; | |
35 | -import org.thingsboard.server.dao.model.TenantEntity; | |
36 | 32 | import org.thingsboard.server.dao.service.DataValidator; |
37 | 33 | import org.thingsboard.server.dao.service.PaginatedRemover; |
34 | +import org.thingsboard.server.dao.service.Validator; | |
38 | 35 | import org.thingsboard.server.dao.tenant.TenantDao; |
39 | 36 | import org.thingsboard.server.dao.user.UserService; |
40 | -import org.slf4j.Logger; | |
41 | -import org.slf4j.LoggerFactory; | |
42 | -import org.springframework.beans.factory.annotation.Autowired; | |
43 | -import org.springframework.stereotype.Service; | |
44 | -import org.thingsboard.server.dao.service.Validator; | |
37 | + | |
38 | +import java.util.List; | |
45 | 39 | @Service |
46 | 40 | @Slf4j |
47 | 41 | public class CustomerServiceImpl implements CustomerService { |
... | ... | @@ -65,16 +59,14 @@ public class CustomerServiceImpl implements CustomerService { |
65 | 59 | public Customer findCustomerById(CustomerId customerId) { |
66 | 60 | log.trace("Executing findCustomerById [{}]", customerId); |
67 | 61 | Validator.validateId(customerId, "Incorrect customerId " + customerId); |
68 | - CustomerEntity customerEntity = customerDao.findById(customerId.getId()); | |
69 | - return getData(customerEntity); | |
62 | + return customerDao.findById(customerId.getId()); | |
70 | 63 | } |
71 | 64 | |
72 | 65 | @Override |
73 | 66 | public Customer saveCustomer(Customer customer) { |
74 | 67 | log.trace("Executing saveCustomer [{}]", customer); |
75 | 68 | customerValidator.validate(customer); |
76 | - CustomerEntity customerEntity = customerDao.save(customer); | |
77 | - return getData(customerEntity); | |
69 | + return customerDao.save(customer); | |
78 | 70 | } |
79 | 71 | |
80 | 72 | @Override |
... | ... | @@ -96,8 +88,7 @@ public class CustomerServiceImpl implements CustomerService { |
96 | 88 | log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
97 | 89 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
98 | 90 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
99 | - List<CustomerEntity> customerEntities = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink); | |
100 | - List<Customer> customers = convertDataList(customerEntities); | |
91 | + List<Customer> customers = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink); | |
101 | 92 | return new TextPageData<Customer>(customers, pageLink); |
102 | 93 | } |
103 | 94 | |
... | ... | @@ -121,7 +112,7 @@ public class CustomerServiceImpl implements CustomerService { |
121 | 112 | if (customer.getTenantId() == null) { |
122 | 113 | throw new DataValidationException("Customer should be assigned to tenant!"); |
123 | 114 | } else { |
124 | - TenantEntity tenant = tenantDao.findById(customer.getTenantId().getId()); | |
115 | + Tenant tenant = tenantDao.findById(customer.getTenantId().getId()); | |
125 | 116 | if (tenant == null) { |
126 | 117 | throw new DataValidationException("Customer is referencing to non-existent tenant!"); |
127 | 118 | } |
... | ... | @@ -129,17 +120,17 @@ public class CustomerServiceImpl implements CustomerService { |
129 | 120 | } |
130 | 121 | }; |
131 | 122 | |
132 | - private PaginatedRemover<TenantId, CustomerEntity> customersByTenantRemover = | |
133 | - new PaginatedRemover<TenantId, CustomerEntity>() { | |
123 | + private PaginatedRemover<TenantId, Customer> customersByTenantRemover = | |
124 | + new PaginatedRemover<TenantId, Customer>() { | |
134 | 125 | |
135 | 126 | @Override |
136 | - protected List<CustomerEntity> findEntities(TenantId id, TextPageLink pageLink) { | |
127 | + protected List<Customer> findEntities(TenantId id, TextPageLink pageLink) { | |
137 | 128 | return customerDao.findCustomersByTenantId(id.getId(), pageLink); |
138 | 129 | } |
139 | 130 | |
140 | 131 | @Override |
141 | - protected void removeEntity(CustomerEntity entity) { | |
142 | - deleteCustomer(new CustomerId(entity.getId())); | |
132 | + protected void removeEntity(Customer entity) { | |
133 | + deleteCustomer(new CustomerId(entity.getUuidId())); | |
143 | 134 | } |
144 | 135 | }; |
145 | 136 | } | ... | ... |
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,15 @@ |
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.CassandraAbstractSearchTextDao; | |
21 | +import org.thingsboard.server.dao.model.nosql.DashboardEntity; | |
22 | + | |
23 | +import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; | |
39 | 24 | |
40 | 25 | @Component |
41 | -@Slf4j | |
42 | -public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> implements DashboardDao { | |
26 | +public class CassandraDashboardDao extends CassandraAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao { | |
43 | 27 | |
44 | 28 | @Override |
45 | 29 | protected Class<DashboardEntity> getColumnFamilyClass() { |
... | ... | @@ -50,11 +34,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp |
50 | 34 | protected String getColumnFamilyName() { |
51 | 35 | return DASHBOARD_COLUMN_FAMILY_NAME; |
52 | 36 | } |
53 | - | |
54 | - @Override | |
55 | - public DashboardEntity save(Dashboard dashboard) { | |
56 | - log.debug("Save dashboard [{}] ", dashboard); | |
57 | - return save(new DashboardEntity(dashboard)); | |
58 | - } | |
59 | - | |
60 | 37 | } | ... | ... |
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,11 @@ 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.CassandraAbstractSearchTextDao; | |
23 | +import org.thingsboard.server.dao.DaoUtil; | |
24 | +import org.thingsboard.server.dao.model.nosql.DashboardInfoEntity; | |
23 | 25 | |
24 | 26 | import java.util.Arrays; |
25 | 27 | import java.util.Collections; |
... | ... | @@ -31,7 +33,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; |
31 | 33 | |
32 | 34 | @Component |
33 | 35 | @Slf4j |
34 | -public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEntity> implements DashboardInfoDao { | |
36 | +public class CassandraDashboardInfoDao extends CassandraAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { | |
35 | 37 | |
36 | 38 | @Override |
37 | 39 | protected Class<DashboardInfoEntity> getColumnFamilyClass() { |
... | ... | @@ -44,18 +46,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt |
44 | 46 | } |
45 | 47 | |
46 | 48 | @Override |
47 | - public List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { | |
49 | + public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { | |
48 | 50 | log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
49 | 51 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
50 | 52 | Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)), |
51 | 53 | pageLink); |
52 | 54 | |
53 | 55 | log.trace("Found dashboards [{}] by tenantId [{}] and pageLink [{}]", dashboardEntities, tenantId, pageLink); |
54 | - return dashboardEntities; | |
56 | + return DaoUtil.convertDataList(dashboardEntities); | |
55 | 57 | } |
56 | 58 | |
57 | 59 | @Override |
58 | - public List<DashboardInfoEntity> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | |
60 | + public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | |
59 | 61 | log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
60 | 62 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
61 | 63 | Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId), |
... | ... | @@ -63,7 +65,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt |
63 | 65 | pageLink); |
64 | 66 | |
65 | 67 | log.trace("Found dashboards [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", dashboardEntities, tenantId, customerId, pageLink); |
66 | - return dashboardEntities; | |
68 | + return DaoUtil.convertDataList(dashboardEntities); | |
67 | 69 | } |
68 | 70 | |
69 | 71 | } | ... | ... |
... | ... | @@ -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 | } | ... | ... |
... | ... | @@ -25,22 +25,22 @@ import org.thingsboard.server.common.data.page.TextPageLink; |
25 | 25 | |
26 | 26 | public interface DashboardService { |
27 | 27 | |
28 | - public Dashboard findDashboardById(DashboardId dashboardId); | |
29 | - | |
30 | - public Dashboard saveDashboard(Dashboard dashboard); | |
31 | - | |
32 | - public Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId); | |
28 | + Dashboard findDashboardById(DashboardId dashboardId); | |
33 | 29 | |
34 | - public Dashboard unassignDashboardFromCustomer(DashboardId dashboardId); | |
30 | + Dashboard saveDashboard(Dashboard dashboard); | |
35 | 31 | |
36 | - public void deleteDashboard(DashboardId dashboardId); | |
37 | - | |
38 | - public TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink); | |
32 | + Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId); | |
39 | 33 | |
40 | - public void deleteDashboardsByTenantId(TenantId tenantId); | |
41 | - | |
42 | - public TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink); | |
34 | + Dashboard unassignDashboardFromCustomer(DashboardId dashboardId); | |
35 | + | |
36 | + void deleteDashboard(DashboardId dashboardId); | |
37 | + | |
38 | + TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink); | |
39 | + | |
40 | + void deleteDashboardsByTenantId(TenantId tenantId); | |
41 | + | |
42 | + TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink); | |
43 | + | |
44 | + void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId); | |
43 | 45 | |
44 | - public void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId); | |
45 | - | |
46 | 46 | } | ... | ... |
... | ... | @@ -15,15 +15,14 @@ |
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 | - | |
21 | -import java.util.List; | |
22 | - | |
23 | 18 | import lombok.extern.slf4j.Slf4j; |
24 | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | |
21 | +import org.springframework.stereotype.Service; | |
22 | +import org.thingsboard.server.common.data.Customer; | |
25 | 23 | import org.thingsboard.server.common.data.Dashboard; |
26 | 24 | import org.thingsboard.server.common.data.DashboardInfo; |
25 | +import org.thingsboard.server.common.data.Tenant; | |
27 | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
28 | 27 | import org.thingsboard.server.common.data.id.DashboardId; |
29 | 28 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -31,15 +30,13 @@ import org.thingsboard.server.common.data.page.TextPageData; |
31 | 30 | import org.thingsboard.server.common.data.page.TextPageLink; |
32 | 31 | import org.thingsboard.server.dao.customer.CustomerDao; |
33 | 32 | import org.thingsboard.server.dao.exception.DataValidationException; |
34 | -import org.thingsboard.server.dao.model.*; | |
33 | +import org.thingsboard.server.dao.model.ModelConstants; | |
35 | 34 | import org.thingsboard.server.dao.service.DataValidator; |
36 | 35 | import org.thingsboard.server.dao.service.PaginatedRemover; |
37 | -import org.thingsboard.server.dao.tenant.TenantDao; | |
38 | -import org.slf4j.Logger; | |
39 | -import org.slf4j.LoggerFactory; | |
40 | -import org.springframework.beans.factory.annotation.Autowired; | |
41 | -import org.springframework.stereotype.Service; | |
42 | 36 | import org.thingsboard.server.dao.service.Validator; |
37 | +import org.thingsboard.server.dao.tenant.TenantDao; | |
38 | + | |
39 | +import java.util.List; | |
43 | 40 | |
44 | 41 | @Service |
45 | 42 | @Slf4j |
... | ... | @@ -61,16 +58,14 @@ public class DashboardServiceImpl implements DashboardService { |
61 | 58 | public Dashboard findDashboardById(DashboardId dashboardId) { |
62 | 59 | log.trace("Executing findDashboardById [{}]", dashboardId); |
63 | 60 | Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId); |
64 | - DashboardEntity dashboardEntity = dashboardDao.findById(dashboardId.getId()); | |
65 | - return getData(dashboardEntity); | |
61 | + return dashboardDao.findById(dashboardId.getId()); | |
66 | 62 | } |
67 | 63 | |
68 | 64 | @Override |
69 | 65 | public Dashboard saveDashboard(Dashboard dashboard) { |
70 | 66 | log.trace("Executing saveDashboard [{}]", dashboard); |
71 | 67 | dashboardValidator.validate(dashboard); |
72 | - DashboardEntity dashboardEntity = dashboardDao.save(dashboard); | |
73 | - return getData(dashboardEntity); | |
68 | + return dashboardDao.save(dashboard); | |
74 | 69 | } |
75 | 70 | |
76 | 71 | @Override |
... | ... | @@ -99,9 +94,8 @@ public class DashboardServiceImpl implements DashboardService { |
99 | 94 | log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
100 | 95 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
101 | 96 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
102 | - List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink); | |
103 | - List<DashboardInfo> dashboards = convertDataList(dashboardEntities); | |
104 | - return new TextPageData<DashboardInfo>(dashboards, pageLink); | |
97 | + List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink); | |
98 | + return new TextPageData<>(dashboards, pageLink); | |
105 | 99 | } |
106 | 100 | |
107 | 101 | @Override |
... | ... | @@ -117,9 +111,8 @@ public class DashboardServiceImpl implements DashboardService { |
117 | 111 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
118 | 112 | Validator.validateId(customerId, "Incorrect customerId " + customerId); |
119 | 113 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
120 | - List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); | |
121 | - List<DashboardInfo> dashboards = convertDataList(dashboardEntities); | |
122 | - return new TextPageData<DashboardInfo>(dashboards, pageLink); | |
114 | + List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); | |
115 | + return new TextPageData<>(dashboards, pageLink); | |
123 | 116 | } |
124 | 117 | |
125 | 118 | @Override |
... | ... | @@ -140,7 +133,7 @@ public class DashboardServiceImpl implements DashboardService { |
140 | 133 | if (dashboard.getTenantId() == null) { |
141 | 134 | throw new DataValidationException("Dashboard should be assigned to tenant!"); |
142 | 135 | } else { |
143 | - TenantEntity tenant = tenantDao.findById(dashboard.getTenantId().getId()); | |
136 | + Tenant tenant = tenantDao.findById(dashboard.getTenantId().getId()); | |
144 | 137 | if (tenant == null) { |
145 | 138 | throw new DataValidationException("Dashboard is referencing to non-existent tenant!"); |
146 | 139 | } |
... | ... | @@ -148,32 +141,32 @@ public class DashboardServiceImpl implements DashboardService { |
148 | 141 | if (dashboard.getCustomerId() == null) { |
149 | 142 | dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID)); |
150 | 143 | } else if (!dashboard.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) { |
151 | - CustomerEntity customer = customerDao.findById(dashboard.getCustomerId().getId()); | |
144 | + Customer customer = customerDao.findById(dashboard.getCustomerId().getId()); | |
152 | 145 | if (customer == null) { |
153 | 146 | throw new DataValidationException("Can't assign dashboard to non-existent customer!"); |
154 | 147 | } |
155 | - if (!customer.getTenantId().equals(dashboard.getTenantId().getId())) { | |
148 | + if (!customer.getTenantId().getId().equals(dashboard.getTenantId().getId())) { | |
156 | 149 | throw new DataValidationException("Can't assign dashboard to customer from different tenant!"); |
157 | 150 | } |
158 | 151 | } |
159 | 152 | } |
160 | 153 | }; |
161 | 154 | |
162 | - private PaginatedRemover<TenantId, DashboardInfoEntity> tenantDashboardsRemover = | |
163 | - new PaginatedRemover<TenantId, DashboardInfoEntity>() { | |
155 | + private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover = | |
156 | + new PaginatedRemover<TenantId, DashboardInfo>() { | |
164 | 157 | |
165 | 158 | @Override |
166 | - protected List<DashboardInfoEntity> findEntities(TenantId id, TextPageLink pageLink) { | |
159 | + protected List<DashboardInfo> findEntities(TenantId id, TextPageLink pageLink) { | |
167 | 160 | return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink); |
168 | 161 | } |
169 | 162 | |
170 | 163 | @Override |
171 | - protected void removeEntity(DashboardInfoEntity entity) { | |
172 | - deleteDashboard(new DashboardId(entity.getId())); | |
164 | + protected void removeEntity(DashboardInfo entity) { | |
165 | + deleteDashboard(new DashboardId(entity.getUuidId())); | |
173 | 166 | } |
174 | 167 | }; |
175 | 168 | |
176 | - class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfoEntity> { | |
169 | + private class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfo> { | |
177 | 170 | |
178 | 171 | private TenantId tenantId; |
179 | 172 | |
... | ... | @@ -182,13 +175,13 @@ public class DashboardServiceImpl implements DashboardService { |
182 | 175 | } |
183 | 176 | |
184 | 177 | @Override |
185 | - protected List<DashboardInfoEntity> findEntities(CustomerId id, TextPageLink pageLink) { | |
178 | + protected List<DashboardInfo> findEntities(CustomerId id, TextPageLink pageLink) { | |
186 | 179 | return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); |
187 | 180 | } |
188 | 181 | |
189 | 182 | @Override |
190 | - protected void removeEntity(DashboardInfoEntity entity) { | |
191 | - unassignDashboardFromCustomer(new DashboardId(entity.getId())); | |
183 | + protected void removeEntity(DashboardInfo entity) { | |
184 | + unassignDashboardFromCustomer(new DashboardId(entity.getUuidId())); | |
192 | 185 | } |
193 | 186 | |
194 | 187 | } | ... | ... |
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,23 @@ |
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.CassandraAbstractModelDao; | |
23 | +import org.thingsboard.server.dao.DaoUtil; | |
24 | +import org.thingsboard.server.dao.model.nosql.DeviceCredentialsEntity; | |
33 | 25 | import org.thingsboard.server.dao.model.ModelConstants; |
34 | 26 | |
27 | +import java.util.UUID; | |
28 | + | |
29 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
31 | + | |
35 | 32 | @Component |
36 | 33 | @Slf4j |
37 | -public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentialsEntity> implements DeviceCredentialsDao { | |
34 | +public class CassandraDeviceCredentialsDao extends CassandraAbstractModelDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao { | |
38 | 35 | |
39 | 36 | @Override |
40 | 37 | protected Class<DeviceCredentialsEntity> getColumnFamilyClass() { |
... | ... | @@ -47,31 +44,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials |
47 | 44 | } |
48 | 45 | |
49 | 46 | @Override |
50 | - public DeviceCredentialsEntity findByDeviceId(UUID deviceId) { | |
47 | + public DeviceCredentials findByDeviceId(UUID deviceId) { | |
51 | 48 | log.debug("Try to find device credentials by deviceId [{}] ", deviceId); |
52 | 49 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME) |
53 | 50 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId)); |
54 | 51 | log.trace("Execute query {}", query); |
55 | 52 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); |
56 | 53 | log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId); |
57 | - return deviceCredentialsEntity; | |
54 | + return DaoUtil.getData(deviceCredentialsEntity); | |
58 | 55 | } |
59 | 56 | |
60 | 57 | @Override |
61 | - public DeviceCredentialsEntity findByCredentialsId(String credentialsId) { | |
58 | + public DeviceCredentials findByCredentialsId(String credentialsId) { | |
62 | 59 | log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId); |
63 | 60 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME) |
64 | 61 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId)); |
65 | 62 | log.trace("Execute query {}", query); |
66 | 63 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); |
67 | 64 | log.trace("Found device credentials [{}] by credentialsId [{}]", deviceCredentialsEntity, credentialsId); |
68 | - return deviceCredentialsEntity; | |
65 | + return DaoUtil.getData(deviceCredentialsEntity); | |
69 | 66 | } |
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 | 67 | } | ... | ... |
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,27 +15,24 @@ |
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.querybuilder.Select; |
26 | 19 | import com.google.common.util.concurrent.ListenableFuture; |
27 | 20 | import lombok.extern.slf4j.Slf4j; |
28 | 21 | import org.springframework.stereotype.Component; |
29 | 22 | import org.thingsboard.server.common.data.Device; |
30 | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
31 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | |
32 | -import org.thingsboard.server.dao.model.DeviceEntity; | |
33 | -import org.slf4j.Logger; | |
34 | -import org.slf4j.LoggerFactory; | |
24 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; | |
25 | +import org.thingsboard.server.dao.DaoUtil; | |
26 | +import org.thingsboard.server.dao.model.nosql.DeviceEntity; | |
27 | + | |
28 | +import java.util.*; | |
29 | + | |
30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
31 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | |
35 | 32 | |
36 | 33 | @Component |
37 | 34 | @Slf4j |
38 | -public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implements DeviceDao { | |
35 | +public class CassandraDeviceDao extends CassandraAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao { | |
39 | 36 | |
40 | 37 | @Override |
41 | 38 | protected Class<DeviceEntity> getColumnFamilyClass() { |
... | ... | @@ -48,23 +45,17 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement |
48 | 45 | } |
49 | 46 | |
50 | 47 | @Override |
51 | - public DeviceEntity save(Device device) { | |
52 | - log.debug("Save device [{}] ", device); | |
53 | - return save(new DeviceEntity(device)); | |
54 | - } | |
55 | - | |
56 | - @Override | |
57 | - public List<DeviceEntity> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { | |
48 | + public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { | |
58 | 49 | log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
59 | 50 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
60 | 51 | Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); |
61 | 52 | |
62 | 53 | log.trace("Found devices [{}] by tenantId [{}] and pageLink [{}]", deviceEntities, tenantId, pageLink); |
63 | - return deviceEntities; | |
54 | + return DaoUtil.convertDataList(deviceEntities); | |
64 | 55 | } |
65 | 56 | |
66 | 57 | @Override |
67 | - public ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { | |
58 | + public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { | |
68 | 59 | log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds); |
69 | 60 | Select select = select().from(getColumnFamilyName()); |
70 | 61 | Select.Where query = select.where(); |
... | ... | @@ -74,7 +65,7 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement |
74 | 65 | } |
75 | 66 | |
76 | 67 | @Override |
77 | - public List<DeviceEntity> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | |
68 | + public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | |
78 | 69 | log.debug("Try to find devices by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
79 | 70 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
80 | 71 | Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), |
... | ... | @@ -82,11 +73,11 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement |
82 | 73 | pageLink); |
83 | 74 | |
84 | 75 | log.trace("Found devices [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, pageLink); |
85 | - return deviceEntities; | |
76 | + return DaoUtil.convertDataList(deviceEntities); | |
86 | 77 | } |
87 | 78 | |
88 | 79 | @Override |
89 | - public ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { | |
80 | + public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { | |
90 | 81 | log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds); |
91 | 82 | Select select = select().from(getColumnFamilyName()); |
92 | 83 | Select.Where query = select.where(); |
... | ... | @@ -97,12 +88,12 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement |
97 | 88 | } |
98 | 89 | |
99 | 90 | @Override |
100 | - public Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) { | |
91 | + public Optional<Device> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) { | |
101 | 92 | Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME); |
102 | 93 | Select.Where query = select.where(); |
103 | 94 | query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); |
104 | 95 | query.and(eq(DEVICE_NAME_PROPERTY, deviceName)); |
105 | - return Optional.ofNullable(findOneByStatement(query)); | |
96 | + return Optional.ofNullable(DaoUtil.getData(findOneByStatement(query))); | |
106 | 97 | } |
107 | 98 | |
108 | 99 | } | ... | ... |
... | ... | @@ -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 | } | ... | ... |
... | ... | @@ -26,10 +26,8 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
26 | 26 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
27 | 27 | import org.thingsboard.server.dao.EncryptionUtil; |
28 | 28 | import org.thingsboard.server.dao.exception.DataValidationException; |
29 | -import org.thingsboard.server.dao.model.DeviceCredentialsEntity; | |
30 | 29 | import org.thingsboard.server.dao.service.DataValidator; |
31 | 30 | |
32 | -import static org.thingsboard.server.dao.DaoUtil.getData; | |
33 | 31 | import static org.thingsboard.server.dao.service.Validator.validateId; |
34 | 32 | import static org.thingsboard.server.dao.service.Validator.validateString; |
35 | 33 | |
... | ... | @@ -47,16 +45,14 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { |
47 | 45 | public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) { |
48 | 46 | log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId); |
49 | 47 | validateId(deviceId, "Incorrect deviceId " + deviceId); |
50 | - DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByDeviceId(deviceId.getId()); | |
51 | - return getData(deviceCredentialsEntity); | |
48 | + return deviceCredentialsDao.findByDeviceId(deviceId.getId()); | |
52 | 49 | } |
53 | 50 | |
54 | 51 | @Override |
55 | 52 | public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) { |
56 | 53 | log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId); |
57 | 54 | validateString(credentialsId, "Incorrect credentialsId " + credentialsId); |
58 | - DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByCredentialsId(credentialsId); | |
59 | - return getData(deviceCredentialsEntity); | |
55 | + return deviceCredentialsDao.findByCredentialsId(credentialsId); | |
60 | 56 | } |
61 | 57 | |
62 | 58 | @Override |
... | ... | @@ -75,7 +71,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { |
75 | 71 | } |
76 | 72 | log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials); |
77 | 73 | credentialsValidator.validate(deviceCredentials); |
78 | - return getData(deviceCredentialsDao.save(deviceCredentials)); | |
74 | + return deviceCredentialsDao.save(deviceCredentials); | |
79 | 75 | } |
80 | 76 | |
81 | 77 | private void formatCertData(DeviceCredentials deviceCredentials) { |
... | ... | @@ -96,7 +92,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { |
96 | 92 | |
97 | 93 | @Override |
98 | 94 | protected void validateCreate(DeviceCredentials deviceCredentials) { |
99 | - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); | |
95 | + DeviceCredentials existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); | |
100 | 96 | if (existingCredentialsEntity != null) { |
101 | 97 | throw new DataValidationException("Create of existent device credentials!"); |
102 | 98 | } |
... | ... | @@ -104,12 +100,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { |
104 | 100 | |
105 | 101 | @Override |
106 | 102 | protected void validateUpdate(DeviceCredentials deviceCredentials) { |
107 | - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findById(deviceCredentials.getUuidId()); | |
108 | - if (existingCredentialsEntity == null) { | |
103 | + DeviceCredentials existingCredentials = deviceCredentialsDao.findById(deviceCredentials.getUuidId()); | |
104 | + if (existingCredentials == null) { | |
109 | 105 | throw new DataValidationException("Unable to update non-existent device credentials!"); |
110 | 106 | } |
111 | - DeviceCredentialsEntity sameCredentialsIdEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); | |
112 | - if (sameCredentialsIdEntity != null && !sameCredentialsIdEntity.getId().equals(deviceCredentials.getUuidId())) { | |
107 | + DeviceCredentials sameCredentialsId = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); | |
108 | + if (sameCredentialsId != null && !sameCredentialsId.getUuidId().equals(deviceCredentials.getUuidId())) { | |
113 | 109 | throw new DataValidationException("Specified credentials are already registered!"); |
114 | 110 | } |
115 | 111 | } | ... | ... |
... | ... | @@ -15,21 +15,20 @@ |
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; |
24 | 20 | import org.thingsboard.server.common.data.page.TextPageLink; |
25 | 21 | import org.thingsboard.server.dao.Dao; |
26 | -import org.thingsboard.server.dao.model.DeviceEntity; | |
22 | + | |
23 | +import java.util.List; | |
24 | +import java.util.Optional; | |
25 | +import java.util.UUID; | |
27 | 26 | |
28 | 27 | /** |
29 | 28 | * The Interface DeviceDao. |
30 | 29 | * |
31 | 30 | */ |
32 | -public interface DeviceDao extends Dao<DeviceEntity> { | |
31 | +public interface DeviceDao extends Dao<Device> { | |
33 | 32 | |
34 | 33 | /** |
35 | 34 | * Save or update device object |
... | ... | @@ -37,7 +36,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
37 | 36 | * @param device the device object |
38 | 37 | * @return saved device object |
39 | 38 | */ |
40 | - DeviceEntity save(Device device); | |
39 | + Device save(Device device); | |
41 | 40 | |
42 | 41 | /** |
43 | 42 | * Find devices by tenantId and page link. |
... | ... | @@ -46,7 +45,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
46 | 45 | * @param pageLink the page link |
47 | 46 | * @return the list of device objects |
48 | 47 | */ |
49 | - List<DeviceEntity> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink); | |
48 | + List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink); | |
50 | 49 | |
51 | 50 | /** |
52 | 51 | * Find devices by tenantId and devices Ids. |
... | ... | @@ -55,7 +54,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
55 | 54 | * @param deviceIds the device Ids |
56 | 55 | * @return the list of device objects |
57 | 56 | */ |
58 | - ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds); | |
57 | + ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds); | |
59 | 58 | |
60 | 59 | /** |
61 | 60 | * Find devices by tenantId, customerId and page link. |
... | ... | @@ -65,7 +64,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
65 | 64 | * @param pageLink the page link |
66 | 65 | * @return the list of device objects |
67 | 66 | */ |
68 | - List<DeviceEntity> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); | |
67 | + List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); | |
69 | 68 | |
70 | 69 | /** |
71 | 70 | * Find devices by tenantId, customerId and devices Ids. |
... | ... | @@ -75,7 +74,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
75 | 74 | * @param deviceIds the device Ids |
76 | 75 | * @return the list of device objects |
77 | 76 | */ |
78 | - ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds); | |
77 | + ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds); | |
79 | 78 | |
80 | 79 | /** |
81 | 80 | * Find devices by tenantId and device name. |
... | ... | @@ -84,5 +83,5 @@ public interface DeviceDao extends Dao<DeviceEntity> { |
84 | 83 | * @param name the device name |
85 | 84 | * @return the optional device object |
86 | 85 | */ |
87 | - Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String name); | |
86 | + Optional<Device> findDevicesByTenantIdAndName(UUID tenantId, String name); | |
88 | 87 | } | ... | ... |
... | ... | @@ -15,15 +15,15 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.device; |
17 | 17 | |
18 | -import com.google.common.base.Function; | |
19 | -import com.google.common.util.concurrent.Futures; | |
20 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
21 | 19 | import lombok.extern.slf4j.Slf4j; |
22 | 20 | import org.apache.commons.lang3.RandomStringUtils; |
23 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
24 | 22 | import org.springframework.stereotype.Service; |
25 | 23 | import org.springframework.util.StringUtils; |
24 | +import org.thingsboard.server.common.data.Customer; | |
26 | 25 | import org.thingsboard.server.common.data.Device; |
26 | +import org.thingsboard.server.common.data.Tenant; | |
27 | 27 | import org.thingsboard.server.common.data.id.CustomerId; |
28 | 28 | import org.thingsboard.server.common.data.id.DeviceId; |
29 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -33,9 +33,6 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
33 | 33 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
34 | 34 | import org.thingsboard.server.dao.customer.CustomerDao; |
35 | 35 | import org.thingsboard.server.dao.exception.DataValidationException; |
36 | -import org.thingsboard.server.dao.model.CustomerEntity; | |
37 | -import org.thingsboard.server.dao.model.DeviceEntity; | |
38 | -import org.thingsboard.server.dao.model.TenantEntity; | |
39 | 36 | import org.thingsboard.server.dao.service.DataValidator; |
40 | 37 | import org.thingsboard.server.dao.service.PaginatedRemover; |
41 | 38 | import org.thingsboard.server.dao.tenant.TenantDao; |
... | ... | @@ -43,8 +40,6 @@ import org.thingsboard.server.dao.tenant.TenantDao; |
43 | 40 | import java.util.List; |
44 | 41 | import java.util.Optional; |
45 | 42 | |
46 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | |
47 | -import static org.thingsboard.server.dao.DaoUtil.getData; | |
48 | 43 | import static org.thingsboard.server.dao.DaoUtil.toUUIDs; |
49 | 44 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
50 | 45 | import static org.thingsboard.server.dao.service.Validator.validateId; |
... | ... | @@ -71,25 +66,23 @@ public class DeviceServiceImpl implements DeviceService { |
71 | 66 | public Device findDeviceById(DeviceId deviceId) { |
72 | 67 | log.trace("Executing findDeviceById [{}]", deviceId); |
73 | 68 | validateId(deviceId, "Incorrect deviceId " + deviceId); |
74 | - DeviceEntity deviceEntity = deviceDao.findById(deviceId.getId()); | |
75 | - return getData(deviceEntity); | |
69 | + return deviceDao.findById(deviceId.getId()); | |
76 | 70 | } |
77 | 71 | |
78 | 72 | @Override |
79 | 73 | public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) { |
80 | 74 | log.trace("Executing findDeviceById [{}]", deviceId); |
81 | 75 | validateId(deviceId, "Incorrect deviceId " + deviceId); |
82 | - ListenableFuture<DeviceEntity> deviceEntity = deviceDao.findByIdAsync(deviceId.getId()); | |
83 | - return Futures.transform(deviceEntity, (Function<? super DeviceEntity, ? extends Device>) input -> getData(input)); | |
76 | + return deviceDao.findByIdAsync(deviceId.getId()); | |
84 | 77 | } |
85 | 78 | |
86 | 79 | @Override |
87 | 80 | public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) { |
88 | 81 | log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name); |
89 | 82 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
90 | - Optional<DeviceEntity> deviceEntityOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name); | |
91 | - if (deviceEntityOpt.isPresent()) { | |
92 | - return Optional.of(getData(deviceEntityOpt.get())); | |
83 | + Optional<Device> deviceOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name); | |
84 | + if (deviceOpt.isPresent()) { | |
85 | + return Optional.of(deviceOpt.get()); | |
93 | 86 | } else { |
94 | 87 | return Optional.empty(); |
95 | 88 | } |
... | ... | @@ -99,15 +92,15 @@ public class DeviceServiceImpl implements DeviceService { |
99 | 92 | public Device saveDevice(Device device) { |
100 | 93 | log.trace("Executing saveDevice [{}]", device); |
101 | 94 | deviceValidator.validate(device); |
102 | - DeviceEntity deviceEntity = deviceDao.save(device); | |
95 | + Device savedDevice = deviceDao.save(device); | |
103 | 96 | if (device.getId() == null) { |
104 | 97 | DeviceCredentials deviceCredentials = new DeviceCredentials(); |
105 | - deviceCredentials.setDeviceId(new DeviceId(deviceEntity.getId())); | |
98 | + deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); | |
106 | 99 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); |
107 | 100 | deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); |
108 | 101 | deviceCredentialsService.createDeviceCredentials(deviceCredentials); |
109 | 102 | } |
110 | - return getData(deviceEntity); | |
103 | + return savedDevice; | |
111 | 104 | } |
112 | 105 | |
113 | 106 | @Override |
... | ... | @@ -140,9 +133,8 @@ public class DeviceServiceImpl implements DeviceService { |
140 | 133 | log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
141 | 134 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
142 | 135 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
143 | - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink); | |
144 | - List<Device> devices = convertDataList(deviceEntities); | |
145 | - return new TextPageData<Device>(devices, pageLink); | |
136 | + List<Device> devices = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink); | |
137 | + return new TextPageData<>(devices, pageLink); | |
146 | 138 | } |
147 | 139 | |
148 | 140 | @Override |
... | ... | @@ -150,8 +142,7 @@ public class DeviceServiceImpl implements DeviceService { |
150 | 142 | log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds); |
151 | 143 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
152 | 144 | validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); |
153 | - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds)); | |
154 | - return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input)); | |
145 | + return deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds)); | |
155 | 146 | } |
156 | 147 | |
157 | 148 | |
... | ... | @@ -168,9 +159,8 @@ public class DeviceServiceImpl implements DeviceService { |
168 | 159 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
169 | 160 | validateId(customerId, "Incorrect customerId " + customerId); |
170 | 161 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
171 | - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); | |
172 | - List<Device> devices = convertDataList(deviceEntities); | |
173 | - return new TextPageData<Device>(devices, pageLink); | |
162 | + List<Device> devices = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); | |
163 | + return new TextPageData<>(devices, pageLink); | |
174 | 164 | } |
175 | 165 | |
176 | 166 | @Override |
... | ... | @@ -179,9 +169,8 @@ public class DeviceServiceImpl implements DeviceService { |
179 | 169 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
180 | 170 | validateId(customerId, "Incorrect customerId " + customerId); |
181 | 171 | validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); |
182 | - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(), | |
172 | + return deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(), | |
183 | 173 | customerId.getId(), toUUIDs(deviceIds)); |
184 | - return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input)); | |
185 | 174 | } |
186 | 175 | |
187 | 176 | @Override |
... | ... | @@ -208,7 +197,7 @@ public class DeviceServiceImpl implements DeviceService { |
208 | 197 | protected void validateUpdate(Device device) { |
209 | 198 | deviceDao.findDevicesByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent( |
210 | 199 | d -> { |
211 | - if (!d.getId().equals(device.getUuidId())) { | |
200 | + if (!d.getUuidId().equals(device.getUuidId())) { | |
212 | 201 | throw new DataValidationException("Device with such name already exists!"); |
213 | 202 | } |
214 | 203 | } |
... | ... | @@ -223,7 +212,7 @@ public class DeviceServiceImpl implements DeviceService { |
223 | 212 | if (device.getTenantId() == null) { |
224 | 213 | throw new DataValidationException("Device should be assigned to tenant!"); |
225 | 214 | } else { |
226 | - TenantEntity tenant = tenantDao.findById(device.getTenantId().getId()); | |
215 | + Tenant tenant = tenantDao.findById(device.getTenantId().getId()); | |
227 | 216 | if (tenant == null) { |
228 | 217 | throw new DataValidationException("Device is referencing to non-existent tenant!"); |
229 | 218 | } |
... | ... | @@ -231,32 +220,32 @@ public class DeviceServiceImpl implements DeviceService { |
231 | 220 | if (device.getCustomerId() == null) { |
232 | 221 | device.setCustomerId(new CustomerId(NULL_UUID)); |
233 | 222 | } else if (!device.getCustomerId().getId().equals(NULL_UUID)) { |
234 | - CustomerEntity customer = customerDao.findById(device.getCustomerId().getId()); | |
223 | + Customer customer = customerDao.findById(device.getCustomerId().getId()); | |
235 | 224 | if (customer == null) { |
236 | 225 | throw new DataValidationException("Can't assign device to non-existent customer!"); |
237 | 226 | } |
238 | - if (!customer.getTenantId().equals(device.getTenantId().getId())) { | |
227 | + if (!customer.getTenantId().getId().equals(device.getTenantId().getId())) { | |
239 | 228 | throw new DataValidationException("Can't assign device to customer from different tenant!"); |
240 | 229 | } |
241 | 230 | } |
242 | 231 | } |
243 | 232 | }; |
244 | 233 | |
245 | - private PaginatedRemover<TenantId, DeviceEntity> tenantDevicesRemover = | |
246 | - new PaginatedRemover<TenantId, DeviceEntity>() { | |
234 | + private PaginatedRemover<TenantId, Device> tenantDevicesRemover = | |
235 | + new PaginatedRemover<TenantId, Device>() { | |
247 | 236 | |
248 | 237 | @Override |
249 | - protected List<DeviceEntity> findEntities(TenantId id, TextPageLink pageLink) { | |
238 | + protected List<Device> findEntities(TenantId id, TextPageLink pageLink) { | |
250 | 239 | return deviceDao.findDevicesByTenantId(id.getId(), pageLink); |
251 | 240 | } |
252 | 241 | |
253 | 242 | @Override |
254 | - protected void removeEntity(DeviceEntity entity) { | |
255 | - deleteDevice(new DeviceId(entity.getId())); | |
243 | + protected void removeEntity(Device entity) { | |
244 | + deleteDevice(new DeviceId(entity.getUuidId())); | |
256 | 245 | } |
257 | 246 | }; |
258 | 247 | |
259 | - class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, DeviceEntity> { | |
248 | + private class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, Device> { | |
260 | 249 | |
261 | 250 | private TenantId tenantId; |
262 | 251 | |
... | ... | @@ -265,13 +254,13 @@ public class DeviceServiceImpl implements DeviceService { |
265 | 254 | } |
266 | 255 | |
267 | 256 | @Override |
268 | - protected List<DeviceEntity> findEntities(CustomerId id, TextPageLink pageLink) { | |
257 | + protected List<Device> findEntities(CustomerId id, TextPageLink pageLink) { | |
269 | 258 | return deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); |
270 | 259 | } |
271 | 260 | |
272 | 261 | @Override |
273 | - protected void removeEntity(DeviceEntity entity) { | |
274 | - unassignDeviceFromCustomer(new DeviceId(entity.getId())); | |
262 | + protected void removeEntity(Device entity) { | |
263 | + unassignDeviceFromCustomer(new DeviceId(entity.getUuidId())); | |
275 | 264 | } |
276 | 265 | |
277 | 266 | } | ... | ... |
... | ... | @@ -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,8 @@ 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 | + Optional<Event> result = eventDao.saveIfNotExists(event); | |
53 | + return result.isPresent() ? Optional.of(result.get()) : Optional.empty(); | |
80 | 54 | } |
81 | 55 | |
82 | 56 | @Override |
... | ... | @@ -93,23 +67,20 @@ public class BaseEventService implements EventService { |
93 | 67 | if (StringUtils.isEmpty(eventUid)) { |
94 | 68 | throw new DataValidationException("Event uid should be specified!."); |
95 | 69 | } |
96 | - EventEntity entity = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid); | |
97 | - return entity != null ? Optional.of(getData(entity)) : Optional.empty(); | |
70 | + Event event = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid); | |
71 | + return event != null ? Optional.of(event) : Optional.empty(); | |
98 | 72 | } |
99 | 73 | |
100 | 74 | @Override |
101 | 75 | 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); | |
76 | + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, pageLink); | |
77 | + return new TimePageData<>(events, pageLink); | |
105 | 78 | } |
106 | 79 | |
107 | - | |
108 | 80 | @Override |
109 | 81 | 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); | |
82 | + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink); | |
83 | + return new TimePageData<>(events, pageLink); | |
113 | 84 | } |
114 | 85 | |
115 | 86 | 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,12 +21,16 @@ 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.CassandraAbstractSearchTimeDao; | |
32 | +import org.thingsboard.server.dao.DaoUtil; | |
33 | +import org.thingsboard.server.dao.model.nosql.EventEntity; | |
30 | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
31 | 35 | |
32 | 36 | import java.util.Arrays; |
... | ... | @@ -36,13 +40,13 @@ import java.util.UUID; |
36 | 40 | |
37 | 41 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
38 | 42 | 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; | |
43 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | |
42 | 44 | |
43 | 45 | @Component |
44 | 46 | @Slf4j |
45 | -public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements EventDao { | |
47 | +public class CassandraBaseEventDao extends CassandraAbstractSearchTimeDao<EventEntity, Event> implements EventDao { | |
48 | + | |
49 | + private final TenantId systemTenantId = new TenantId(NULL_UUID); | |
46 | 50 | |
47 | 51 | @Override |
48 | 52 | protected Class<EventEntity> getColumnFamilyClass() { |
... | ... | @@ -55,18 +59,35 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements |
55 | 59 | } |
56 | 60 | |
57 | 61 | @Override |
58 | - public EventEntity save(Event event) { | |
62 | + public Event save(Event event) { | |
59 | 63 | log.debug("Save event [{}] ", event); |
64 | + if (event.getTenantId() == null) { | |
65 | + log.trace("Save system event with predefined id {}", systemTenantId); | |
66 | + event.setTenantId(systemTenantId); | |
67 | + } | |
68 | + if (event.getId() == null) { | |
69 | + event.setId(new EventId(UUIDs.timeBased())); | |
70 | + } | |
71 | + if (StringUtils.isEmpty(event.getUid())) { | |
72 | + event.setUid(event.getId().toString()); | |
73 | + } | |
60 | 74 | return save(new EventEntity(event), false).orElse(null); |
61 | 75 | } |
62 | 76 | |
63 | 77 | @Override |
64 | - public Optional<EventEntity> saveIfNotExists(Event event) { | |
78 | + public Optional<Event> saveIfNotExists(Event event) { | |
79 | + if (event.getTenantId() == null) { | |
80 | + log.trace("Save system event with predefined id {}", systemTenantId); | |
81 | + event.setTenantId(systemTenantId); | |
82 | + } | |
83 | + if (event.getId() == null) { | |
84 | + event.setId(new EventId(UUIDs.timeBased())); | |
85 | + } | |
65 | 86 | return save(new EventEntity(event), true); |
66 | 87 | } |
67 | 88 | |
68 | 89 | @Override |
69 | - public EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { | |
90 | + public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { | |
70 | 91 | log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid); |
71 | 92 | Select.Where query = select().from(getColumnFamilyName()).where( |
72 | 93 | eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)) |
... | ... | @@ -81,11 +102,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements |
81 | 102 | } else { |
82 | 103 | log.debug("Search result: [{}]", entity != null); |
83 | 104 | } |
84 | - return entity; | |
105 | + return DaoUtil.getData(entity); | |
85 | 106 | } |
86 | 107 | |
87 | 108 | @Override |
88 | - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { | |
109 | + public List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { | |
89 | 110 | log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink); |
90 | 111 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME, |
91 | 112 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
... | ... | @@ -93,11 +114,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements |
93 | 114 | eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())), |
94 | 115 | pageLink); |
95 | 116 | log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); |
96 | - return entities; | |
117 | + return DaoUtil.convertDataList(entities); | |
97 | 118 | } |
98 | 119 | |
99 | 120 | @Override |
100 | - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { | |
121 | + public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { | |
101 | 122 | log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
102 | 123 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME, |
103 | 124 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
... | ... | @@ -108,10 +129,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements |
108 | 129 | QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), |
109 | 130 | pageLink); |
110 | 131 | log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
111 | - return entities; | |
132 | + return DaoUtil.convertDataList(entities); | |
112 | 133 | } |
113 | 134 | |
114 | - private Optional<EventEntity> save(EventEntity entity, boolean ifNotExists) { | |
135 | + private Optional<Event> save(EventEntity entity, boolean ifNotExists) { | |
115 | 136 | if (entity.getId() == null) { |
116 | 137 | entity.setId(UUIDs.timeBased()); |
117 | 138 | } |
... | ... | @@ -128,7 +149,7 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements |
128 | 149 | } |
129 | 150 | ResultSet rs = executeWrite(insert); |
130 | 151 | if (rs.wasApplied()) { |
131 | - return Optional.of(entity); | |
152 | + return Optional.of(DaoUtil.getData(entity)); | |
132 | 153 | } else { |
133 | 154 | return Optional.empty(); |
134 | 155 | } | ... | ... |
... | ... | @@ -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 | ... | ... |
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/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,6 +23,8 @@ 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.ModelConstants; | |
27 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
26 | 28 | import org.thingsboard.server.dao.model.type.JsonCodec; |
27 | 29 | |
28 | 30 | import java.util.UUID; | ... | ... |
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,15 @@ |
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.ModelConstants; | |
24 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
38 | 25 | import org.thingsboard.server.dao.model.type.JsonCodec; |
39 | 26 | |
40 | 27 | import com.datastax.driver.core.utils.UUIDs; |
... | ... | @@ -44,51 +31,51 @@ import com.datastax.driver.mapping.annotations.Table; |
44 | 31 | import com.datastax.driver.mapping.annotations.Transient; |
45 | 32 | import com.fasterxml.jackson.databind.JsonNode; |
46 | 33 | |
47 | -@Table(name = CUSTOMER_COLUMN_FAMILY_NAME) | |
34 | +@Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME) | |
48 | 35 | public final class CustomerEntity implements SearchTextEntity<Customer> { |
49 | 36 | |
50 | 37 | @Transient |
51 | 38 | private static final long serialVersionUID = -7732527103760948490L; |
52 | 39 | |
53 | 40 | @PartitionKey(value = 0) |
54 | - @Column(name = ID_PROPERTY) | |
41 | + @Column(name = ModelConstants.ID_PROPERTY) | |
55 | 42 | private UUID id; |
56 | 43 | |
57 | 44 | @PartitionKey(value = 1) |
58 | - @Column(name = CUSTOMER_TENANT_ID_PROPERTY) | |
45 | + @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) | |
59 | 46 | private UUID tenantId; |
60 | 47 | |
61 | - @Column(name = CUSTOMER_TITLE_PROPERTY) | |
48 | + @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) | |
62 | 49 | private String title; |
63 | 50 | |
64 | - @Column(name = SEARCH_TEXT_PROPERTY) | |
51 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
65 | 52 | private String searchText; |
66 | 53 | |
67 | - @Column(name = COUNTRY_PROPERTY) | |
54 | + @Column(name = ModelConstants.COUNTRY_PROPERTY) | |
68 | 55 | private String country; |
69 | 56 | |
70 | - @Column(name = STATE_PROPERTY) | |
57 | + @Column(name = ModelConstants.STATE_PROPERTY) | |
71 | 58 | private String state; |
72 | 59 | |
73 | - @Column(name = CITY_PROPERTY) | |
60 | + @Column(name = ModelConstants.CITY_PROPERTY) | |
74 | 61 | private String city; |
75 | 62 | |
76 | - @Column(name = ADDRESS_PROPERTY) | |
63 | + @Column(name = ModelConstants.ADDRESS_PROPERTY) | |
77 | 64 | private String address; |
78 | 65 | |
79 | - @Column(name = ADDRESS2_PROPERTY) | |
66 | + @Column(name = ModelConstants.ADDRESS2_PROPERTY) | |
80 | 67 | private String address2; |
81 | 68 | |
82 | - @Column(name = ZIP_PROPERTY) | |
69 | + @Column(name = ModelConstants.ZIP_PROPERTY) | |
83 | 70 | private String zip; |
84 | 71 | |
85 | - @Column(name = PHONE_PROPERTY) | |
72 | + @Column(name = ModelConstants.PHONE_PROPERTY) | |
86 | 73 | private String phone; |
87 | 74 | |
88 | - @Column(name = EMAIL_PROPERTY) | |
75 | + @Column(name = ModelConstants.EMAIL_PROPERTY) | |
89 | 76 | private String email; |
90 | 77 | |
91 | - @Column(name = CUSTOMER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
78 | + @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
92 | 79 | private JsonNode additionalInfo; |
93 | 80 | |
94 | 81 | public CustomerEntity() { | ... | ... |
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,8 @@ 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.ModelConstants; | |
25 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
24 | 26 | import org.thingsboard.server.dao.model.type.JsonCodec; |
25 | 27 | |
26 | 28 | import com.datastax.driver.core.utils.UUIDs; | ... | ... |
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,23 +13,22 @@ |
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.ModelConstants; | |
25 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
26 | 26 | |
27 | 27 | import com.datastax.driver.core.utils.UUIDs; |
28 | 28 | import com.datastax.driver.mapping.annotations.Column; |
29 | 29 | import com.datastax.driver.mapping.annotations.PartitionKey; |
30 | 30 | import com.datastax.driver.mapping.annotations.Table; |
31 | 31 | import com.datastax.driver.mapping.annotations.Transient; |
32 | -import com.fasterxml.jackson.databind.JsonNode; | |
33 | 32 | |
34 | 33 | @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) |
35 | 34 | public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceCredentialsEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/DeviceCredentialsEntity.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,8 @@ import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
21 | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | 22 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
23 | 23 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
24 | +import org.thingsboard.server.dao.model.BaseEntity; | |
25 | +import org.thingsboard.server.dao.model.ModelConstants; | |
24 | 26 | import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec; |
25 | 27 | |
26 | 28 | import com.datastax.driver.core.utils.UUIDs; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/DeviceEntity.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,37 +25,37 @@ import org.thingsboard.server.common.data.Device; |
25 | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
26 | 26 | import org.thingsboard.server.common.data.id.DeviceId; |
27 | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
28 | 30 | import org.thingsboard.server.dao.model.type.JsonCodec; |
29 | 31 | |
30 | 32 | import java.util.UUID; |
31 | 33 | |
32 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | |
33 | - | |
34 | -@Table(name = DEVICE_COLUMN_FAMILY_NAME) | |
34 | +@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) | |
35 | 35 | public final class DeviceEntity implements SearchTextEntity<Device> { |
36 | 36 | |
37 | 37 | @Transient |
38 | 38 | private static final long serialVersionUID = -1265181166886910152L; |
39 | 39 | |
40 | 40 | @PartitionKey(value = 0) |
41 | - @Column(name = ID_PROPERTY) | |
41 | + @Column(name = ModelConstants.ID_PROPERTY) | |
42 | 42 | private UUID id; |
43 | 43 | |
44 | 44 | @PartitionKey(value = 1) |
45 | - @Column(name = DEVICE_TENANT_ID_PROPERTY) | |
45 | + @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY) | |
46 | 46 | private UUID tenantId; |
47 | 47 | |
48 | 48 | @PartitionKey(value = 2) |
49 | - @Column(name = DEVICE_CUSTOMER_ID_PROPERTY) | |
49 | + @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY) | |
50 | 50 | private UUID customerId; |
51 | 51 | |
52 | - @Column(name = DEVICE_NAME_PROPERTY) | |
52 | + @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) | |
53 | 53 | private String name; |
54 | 54 | |
55 | - @Column(name = SEARCH_TEXT_PROPERTY) | |
55 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
56 | 56 | private String searchText; |
57 | 57 | |
58 | - @Column(name = DEVICE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
58 | + @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
59 | 59 | private JsonNode additionalInfo; |
60 | 60 | |
61 | 61 | public DeviceEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/EventEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/EventEntity.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.*; |
... | ... | @@ -23,48 +23,48 @@ import lombok.NoArgsConstructor; |
23 | 23 | import org.thingsboard.server.common.data.EntityType; |
24 | 24 | import org.thingsboard.server.common.data.Event; |
25 | 25 | import org.thingsboard.server.common.data.id.*; |
26 | +import org.thingsboard.server.dao.model.BaseEntity; | |
27 | +import org.thingsboard.server.dao.model.ModelConstants; | |
26 | 28 | import org.thingsboard.server.dao.model.type.EntityTypeCodec; |
27 | 29 | import org.thingsboard.server.dao.model.type.JsonCodec; |
28 | 30 | |
29 | 31 | import java.util.UUID; |
30 | 32 | |
31 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | |
32 | - | |
33 | 33 | /** |
34 | 34 | * @author Andrew Shvayka |
35 | 35 | */ |
36 | 36 | @Data |
37 | 37 | @NoArgsConstructor |
38 | -@Table(name = DEVICE_COLUMN_FAMILY_NAME) | |
38 | +@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) | |
39 | 39 | public class EventEntity implements BaseEntity<Event> { |
40 | 40 | |
41 | 41 | @Transient |
42 | 42 | private static final long serialVersionUID = -1265181166886910153L; |
43 | 43 | |
44 | - @Column(name = ID_PROPERTY) | |
44 | + @Column(name = ModelConstants.ID_PROPERTY) | |
45 | 45 | private UUID id; |
46 | 46 | |
47 | 47 | @PartitionKey() |
48 | - @Column(name = EVENT_TENANT_ID_PROPERTY) | |
48 | + @Column(name = ModelConstants.EVENT_TENANT_ID_PROPERTY) | |
49 | 49 | private UUID tenantId; |
50 | 50 | |
51 | 51 | @PartitionKey(value = 1) |
52 | - @Column(name = EVENT_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class) | |
52 | + @Column(name = ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class) | |
53 | 53 | private EntityType entityType; |
54 | 54 | |
55 | 55 | @PartitionKey(value = 2) |
56 | - @Column(name = EVENT_ENTITY_ID_PROPERTY) | |
56 | + @Column(name = ModelConstants.EVENT_ENTITY_ID_PROPERTY) | |
57 | 57 | private UUID entityId; |
58 | 58 | |
59 | 59 | @ClusteringColumn() |
60 | - @Column(name = EVENT_TYPE_PROPERTY) | |
60 | + @Column(name = ModelConstants.EVENT_TYPE_PROPERTY) | |
61 | 61 | private String eventType; |
62 | 62 | |
63 | 63 | @ClusteringColumn(value = 1) |
64 | - @Column(name = EVENT_UID_PROPERTY) | |
64 | + @Column(name = ModelConstants.EVENT_UID_PROPERTY) | |
65 | 65 | private String eventUId; |
66 | 66 | |
67 | - @Column(name = EVENT_BODY_PROPERTY, codec = JsonCodec.class) | |
67 | + @Column(name = ModelConstants.EVENT_BODY_PROPERTY, codec = JsonCodec.class) | |
68 | 68 | private JsonNode body; |
69 | 69 | |
70 | 70 | public EventEntity(Event event) { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/PluginMetaDataEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/PluginMetaDataEntity.java
... | ... | @@ -13,31 +13,28 @@ |
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 | -import com.datastax.driver.mapping.annotations.ClusteringColumn; | |
20 | -import com.datastax.driver.mapping.annotations.Column; | |
21 | -import com.datastax.driver.mapping.annotations.PartitionKey; | |
22 | -import com.datastax.driver.mapping.annotations.Table; | |
19 | +import com.datastax.driver.mapping.annotations.*; | |
23 | 20 | import com.fasterxml.jackson.databind.JsonNode; |
24 | 21 | import org.thingsboard.server.common.data.id.PluginId; |
25 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
26 | 23 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
27 | 24 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
25 | +import org.thingsboard.server.dao.model.ModelConstants; | |
26 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
28 | 27 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; |
29 | 28 | import org.thingsboard.server.dao.model.type.JsonCodec; |
30 | 29 | |
31 | 30 | import java.util.Objects; |
32 | 31 | import java.util.UUID; |
33 | 32 | |
34 | -import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY; | |
35 | -import static org.thingsboard.server.dao.model.ModelConstants.RULE_ACTION; | |
36 | - | |
37 | 33 | @Table(name = ModelConstants.PLUGIN_COLUMN_FAMILY_NAME) |
38 | 34 | public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
39 | 35 | |
40 | - private static final long serialVersionUID = 1L; | |
36 | + @Transient | |
37 | + private static final long serialVersionUID = -5231612734979707866L; | |
41 | 38 | |
42 | 39 | @PartitionKey |
43 | 40 | @Column(name = ModelConstants.ID_PROPERTY) |
... | ... | @@ -68,7 +65,7 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
68 | 65 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
69 | 66 | private String searchText; |
70 | 67 | |
71 | - @Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
68 | + @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
72 | 69 | private JsonNode additionalInfo; |
73 | 70 | |
74 | 71 | public PluginMetaDataEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/RuleMetaDataEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/RuleMetaDataEntity.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.ClusteringColumn; |
... | ... | @@ -26,40 +26,43 @@ import org.thingsboard.server.common.data.id.TenantId; |
26 | 26 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
27 | 27 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
28 | 28 | import org.thingsboard.server.dao.DaoUtil; |
29 | +import org.thingsboard.server.dao.model.ModelConstants; | |
30 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
29 | 31 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; |
30 | 32 | import org.thingsboard.server.dao.model.type.JsonCodec; |
31 | 33 | |
34 | +import javax.persistence.Transient; | |
32 | 35 | import java.util.Objects; |
33 | 36 | import java.util.UUID; |
34 | 37 | |
35 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | |
36 | - | |
37 | -@Table(name = RULE_COLUMN_FAMILY_NAME) | |
38 | +@Table(name = ModelConstants.RULE_COLUMN_FAMILY_NAME) | |
38 | 39 | public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
39 | 40 | |
41 | + @Transient | |
42 | + private static final long serialVersionUID = 4011728715100800304L; | |
40 | 43 | @PartitionKey |
41 | - @Column(name = ID_PROPERTY) | |
44 | + @Column(name = ModelConstants.ID_PROPERTY) | |
42 | 45 | private UUID id; |
43 | 46 | @ClusteringColumn |
44 | - @Column(name = RULE_TENANT_ID_PROPERTY) | |
47 | + @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY) | |
45 | 48 | private UUID tenantId; |
46 | - @Column(name = RULE_NAME_PROPERTY) | |
49 | + @Column(name = ModelConstants.RULE_NAME_PROPERTY) | |
47 | 50 | private String name; |
48 | 51 | @Column(name = ModelConstants.RULE_STATE_PROPERTY, codec = ComponentLifecycleStateCodec.class) |
49 | 52 | private ComponentLifecycleState state; |
50 | - @Column(name = RULE_WEIGHT_PROPERTY) | |
53 | + @Column(name = ModelConstants.RULE_WEIGHT_PROPERTY) | |
51 | 54 | private int weight; |
52 | - @Column(name = SEARCH_TEXT_PROPERTY) | |
55 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
53 | 56 | private String searchText; |
54 | - @Column(name = RULE_PLUGIN_TOKEN_PROPERTY) | |
57 | + @Column(name = ModelConstants.RULE_PLUGIN_TOKEN_PROPERTY) | |
55 | 58 | private String pluginToken; |
56 | - @Column(name = RULE_FILTERS, codec = JsonCodec.class) | |
59 | + @Column(name = ModelConstants.RULE_FILTERS, codec = JsonCodec.class) | |
57 | 60 | private JsonNode filters; |
58 | - @Column(name = RULE_PROCESSOR, codec = JsonCodec.class) | |
61 | + @Column(name = ModelConstants.RULE_PROCESSOR, codec = JsonCodec.class) | |
59 | 62 | private JsonNode processor; |
60 | - @Column(name = RULE_ACTION, codec = JsonCodec.class) | |
63 | + @Column(name = ModelConstants.RULE_ACTION, codec = JsonCodec.class) | |
61 | 64 | private JsonNode action; |
62 | - @Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
65 | + @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
63 | 66 | private JsonNode additionalInfo; |
64 | 67 | |
65 | 68 | public RuleMetaDataEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/TenantEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/TenantEntity.java
... | ... | @@ -13,27 +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.EMAIL_PROPERTY; | |
23 | -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | |
24 | -import static org.thingsboard.server.dao.model.ModelConstants.PHONE_PROPERTY; | |
25 | -import static org.thingsboard.server.dao.model.ModelConstants.STATE_PROPERTY; | |
26 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY; | |
27 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_COLUMN_FAMILY_NAME; | |
28 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_REGION_PROPERTY; | |
29 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_TITLE_PROPERTY; | |
30 | -import static org.thingsboard.server.dao.model.ModelConstants.ZIP_PROPERTY; | |
31 | -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_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.Tenant; |
36 | 21 | import org.thingsboard.server.common.data.id.TenantId; |
22 | +import org.thingsboard.server.dao.model.ModelConstants; | |
23 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
37 | 24 | import org.thingsboard.server.dao.model.type.JsonCodec; |
38 | 25 | |
39 | 26 | import com.datastax.driver.core.utils.UUIDs; |
... | ... | @@ -43,50 +30,50 @@ import com.datastax.driver.mapping.annotations.Table; |
43 | 30 | import com.datastax.driver.mapping.annotations.Transient; |
44 | 31 | import com.fasterxml.jackson.databind.JsonNode; |
45 | 32 | |
46 | -@Table(name = TENANT_COLUMN_FAMILY_NAME) | |
33 | +@Table(name = ModelConstants.TENANT_COLUMN_FAMILY_NAME) | |
47 | 34 | public final class TenantEntity implements SearchTextEntity<Tenant> { |
48 | 35 | |
49 | 36 | @Transient |
50 | 37 | private static final long serialVersionUID = -6198635547142409206L; |
51 | 38 | |
52 | 39 | @PartitionKey(value = 0) |
53 | - @Column(name = ID_PROPERTY) | |
40 | + @Column(name = ModelConstants.ID_PROPERTY) | |
54 | 41 | private UUID id; |
55 | 42 | |
56 | - @Column(name = TENANT_TITLE_PROPERTY) | |
43 | + @Column(name = ModelConstants.TENANT_TITLE_PROPERTY) | |
57 | 44 | private String title; |
58 | 45 | |
59 | - @Column(name = SEARCH_TEXT_PROPERTY) | |
46 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
60 | 47 | private String searchText; |
61 | 48 | |
62 | - @Column(name = TENANT_REGION_PROPERTY) | |
49 | + @Column(name = ModelConstants.TENANT_REGION_PROPERTY) | |
63 | 50 | private String region; |
64 | 51 | |
65 | - @Column(name = COUNTRY_PROPERTY) | |
52 | + @Column(name = ModelConstants.COUNTRY_PROPERTY) | |
66 | 53 | private String country; |
67 | 54 | |
68 | - @Column(name = STATE_PROPERTY) | |
55 | + @Column(name = ModelConstants.STATE_PROPERTY) | |
69 | 56 | private String state; |
70 | 57 | |
71 | - @Column(name = CITY_PROPERTY) | |
58 | + @Column(name = ModelConstants.CITY_PROPERTY) | |
72 | 59 | private String city; |
73 | 60 | |
74 | - @Column(name = ADDRESS_PROPERTY) | |
61 | + @Column(name = ModelConstants.ADDRESS_PROPERTY) | |
75 | 62 | private String address; |
76 | 63 | |
77 | - @Column(name = ADDRESS2_PROPERTY) | |
64 | + @Column(name = ModelConstants.ADDRESS2_PROPERTY) | |
78 | 65 | private String address2; |
79 | 66 | |
80 | - @Column(name = ZIP_PROPERTY) | |
67 | + @Column(name = ModelConstants.ZIP_PROPERTY) | |
81 | 68 | private String zip; |
82 | 69 | |
83 | - @Column(name = PHONE_PROPERTY) | |
70 | + @Column(name = ModelConstants.PHONE_PROPERTY) | |
84 | 71 | private String phone; |
85 | 72 | |
86 | - @Column(name = EMAIL_PROPERTY) | |
73 | + @Column(name = ModelConstants.EMAIL_PROPERTY) | |
87 | 74 | private String email; |
88 | 75 | |
89 | - @Column(name = TENANT_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
76 | + @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
90 | 77 | private JsonNode additionalInfo; |
91 | 78 | |
92 | 79 | public TenantEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/UserCredentialsEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/UserCredentialsEntity.java
... | ... | @@ -13,15 +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; | |
17 | - | |
18 | -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | |
19 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY; | |
20 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME; | |
21 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_PASSWORD_PROPERTY; | |
22 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY; | |
23 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY; | |
24 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY; | |
16 | +package org.thingsboard.server.dao.model.nosql; | |
25 | 17 | |
26 | 18 | import java.util.UUID; |
27 | 19 | |
... | ... | @@ -34,30 +26,32 @@ import com.datastax.driver.mapping.annotations.Column; |
34 | 26 | import com.datastax.driver.mapping.annotations.PartitionKey; |
35 | 27 | import com.datastax.driver.mapping.annotations.Table; |
36 | 28 | import com.datastax.driver.mapping.annotations.Transient; |
29 | +import org.thingsboard.server.dao.model.BaseEntity; | |
30 | +import org.thingsboard.server.dao.model.ModelConstants; | |
37 | 31 | |
38 | -@Table(name = USER_CREDENTIALS_COLUMN_FAMILY_NAME) | |
32 | +@Table(name = ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME) | |
39 | 33 | public final class UserCredentialsEntity implements BaseEntity<UserCredentials> { |
40 | 34 | |
41 | 35 | @Transient |
42 | 36 | private static final long serialVersionUID = 1348221414123438374L; |
43 | 37 | |
44 | 38 | @PartitionKey(value = 0) |
45 | - @Column(name = ID_PROPERTY) | |
39 | + @Column(name = ModelConstants.ID_PROPERTY) | |
46 | 40 | private UUID id; |
47 | 41 | |
48 | - @Column(name = USER_CREDENTIALS_USER_ID_PROPERTY) | |
42 | + @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY) | |
49 | 43 | private UUID userId; |
50 | 44 | |
51 | - @Column(name = USER_CREDENTIALS_ENABLED_PROPERTY) | |
45 | + @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY) | |
52 | 46 | private boolean enabled; |
53 | 47 | |
54 | - @Column(name = USER_CREDENTIALS_PASSWORD_PROPERTY) | |
48 | + @Column(name = ModelConstants.USER_CREDENTIALS_PASSWORD_PROPERTY) | |
55 | 49 | private String password; |
56 | 50 | |
57 | - @Column(name = USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY) | |
51 | + @Column(name = ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY) | |
58 | 52 | private String activateToken; |
59 | 53 | |
60 | - @Column(name = USER_CREDENTIALS_RESET_TOKEN_PROPERTY) | |
54 | + @Column(name = ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY) | |
61 | 55 | private String resetToken; |
62 | 56 | |
63 | 57 | public UserCredentialsEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/UserEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/UserEntity.java
... | ... | @@ -13,18 +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; | |
17 | - | |
18 | -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | |
19 | -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; | |
20 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_ADDITIONAL_INFO_PROPERTY; | |
21 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_AUTHORITY_PROPERTY; | |
22 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_COLUMN_FAMILY_NAME; | |
23 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_CUSTOMER_ID_PROPERTY; | |
24 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_EMAIL_PROPERTY; | |
25 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_FIRST_NAME_PROPERTY; | |
26 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_LAST_NAME_PROPERTY; | |
27 | -import static org.thingsboard.server.dao.model.ModelConstants.USER_TENANT_ID_PROPERTY; | |
16 | +package org.thingsboard.server.dao.model.nosql; | |
28 | 17 | |
29 | 18 | import java.util.UUID; |
30 | 19 | |
... | ... | @@ -33,6 +22,8 @@ import org.thingsboard.server.common.data.id.CustomerId; |
33 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
34 | 23 | import org.thingsboard.server.common.data.id.UserId; |
35 | 24 | import org.thingsboard.server.common.data.security.Authority; |
25 | +import org.thingsboard.server.dao.model.ModelConstants; | |
26 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
36 | 27 | import org.thingsboard.server.dao.model.type.AuthorityCodec; |
37 | 28 | import org.thingsboard.server.dao.model.type.JsonCodec; |
38 | 29 | |
... | ... | @@ -43,41 +34,41 @@ import com.datastax.driver.mapping.annotations.Table; |
43 | 34 | import com.datastax.driver.mapping.annotations.Transient; |
44 | 35 | import com.fasterxml.jackson.databind.JsonNode; |
45 | 36 | |
46 | -@Table(name = USER_COLUMN_FAMILY_NAME) | |
37 | +@Table(name = ModelConstants.USER_COLUMN_FAMILY_NAME) | |
47 | 38 | public final class UserEntity implements SearchTextEntity<User> { |
48 | 39 | |
49 | 40 | @Transient |
50 | 41 | private static final long serialVersionUID = -7740338274987723489L; |
51 | 42 | |
52 | 43 | @PartitionKey(value = 0) |
53 | - @Column(name = ID_PROPERTY) | |
44 | + @Column(name = ModelConstants.ID_PROPERTY) | |
54 | 45 | private UUID id; |
55 | 46 | |
56 | 47 | @PartitionKey(value = 1) |
57 | - @Column(name = USER_TENANT_ID_PROPERTY) | |
48 | + @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) | |
58 | 49 | private UUID tenantId; |
59 | 50 | |
60 | 51 | @PartitionKey(value = 2) |
61 | - @Column(name = USER_CUSTOMER_ID_PROPERTY) | |
52 | + @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY) | |
62 | 53 | private UUID customerId; |
63 | 54 | |
64 | 55 | @PartitionKey(value = 3) |
65 | - @Column(name = USER_AUTHORITY_PROPERTY, codec = AuthorityCodec.class) | |
56 | + @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY, codec = AuthorityCodec.class) | |
66 | 57 | private Authority authority; |
67 | 58 | |
68 | - @Column(name = USER_EMAIL_PROPERTY) | |
59 | + @Column(name = ModelConstants.USER_EMAIL_PROPERTY) | |
69 | 60 | private String email; |
70 | 61 | |
71 | - @Column(name = SEARCH_TEXT_PROPERTY) | |
62 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
72 | 63 | private String searchText; |
73 | 64 | |
74 | - @Column(name = USER_FIRST_NAME_PROPERTY) | |
65 | + @Column(name = ModelConstants.USER_FIRST_NAME_PROPERTY) | |
75 | 66 | private String firstName; |
76 | 67 | |
77 | - @Column(name = USER_LAST_NAME_PROPERTY) | |
68 | + @Column(name = ModelConstants.USER_LAST_NAME_PROPERTY) | |
78 | 69 | private String lastName; |
79 | 70 | |
80 | - @Column(name = USER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
71 | + @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) | |
81 | 72 | private JsonNode additionalInfo; |
82 | 73 | |
83 | 74 | public UserEntity() { | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/WidgetTypeEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/WidgetTypeEntity.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; |
... | ... | @@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.JsonNode; |
24 | 24 | import org.thingsboard.server.common.data.id.TenantId; |
25 | 25 | import org.thingsboard.server.common.data.id.WidgetTypeId; |
26 | 26 | import org.thingsboard.server.common.data.widget.WidgetType; |
27 | +import org.thingsboard.server.dao.model.BaseEntity; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
27 | 29 | import org.thingsboard.server.dao.model.type.JsonCodec; |
28 | 30 | |
29 | 31 | import java.util.UUID; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/nosql/WidgetsBundleEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/WidgetsBundleEntity.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 | |
19 | 19 | import com.datastax.driver.core.utils.UUIDs; |
... | ... | @@ -24,6 +24,8 @@ import com.datastax.driver.mapping.annotations.Transient; |
24 | 24 | import org.thingsboard.server.common.data.id.TenantId; |
25 | 25 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
26 | 26 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
27 | +import org.thingsboard.server.dao.model.ModelConstants; | |
28 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
27 | 29 | |
28 | 30 | import java.nio.ByteBuffer; |
29 | 31 | import java.util.UUID; | ... | ... |
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.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import com.fasterxml.jackson.databind.JsonNode; | |
25 | +import org.thingsboard.server.common.data.AdminSettings; | |
26 | +import org.thingsboard.server.common.data.id.AdminSettingsId; | |
27 | +import org.thingsboard.server.dao.model.BaseEntity; | |
28 | + | |
29 | +import java.util.UUID; | |
30 | + | |
31 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | |
32 | + | |
33 | +@Entity | |
34 | +@Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) | |
35 | +public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { | |
36 | + | |
37 | + @Transient | |
38 | + private static final long serialVersionUID = 842759712850362147L; | |
39 | + | |
40 | + @Id | |
41 | + @Column(name = ID_PROPERTY) | |
42 | + private UUID id; | |
43 | + | |
44 | + @Column(name = ADMIN_SETTINGS_KEY_PROPERTY) | |
45 | + private String key; | |
46 | + | |
47 | + @Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY) | |
48 | + private JsonNode jsonValue; | |
49 | + | |
50 | + public AdminSettingsEntity() { | |
51 | + super(); | |
52 | + } | |
53 | + | |
54 | + public AdminSettingsEntity(AdminSettings adminSettings) { | |
55 | + if (adminSettings.getId() != null) { | |
56 | + this.id = adminSettings.getId().getId(); | |
57 | + } | |
58 | + this.key = adminSettings.getKey(); | |
59 | + this.jsonValue = adminSettings.getJsonValue(); | |
60 | + } | |
61 | + | |
62 | + public UUID getId() { | |
63 | + return id; | |
64 | + } | |
65 | + | |
66 | + public void setId(UUID id) { | |
67 | + this.id = id; | |
68 | + } | |
69 | + | |
70 | + public String getKey() { | |
71 | + return key; | |
72 | + } | |
73 | + | |
74 | + public void setKey(String key) { | |
75 | + this.key = key; | |
76 | + } | |
77 | + | |
78 | + public JsonNode getJsonValue() { | |
79 | + return jsonValue; | |
80 | + } | |
81 | + | |
82 | + public void setJsonValue(JsonNode jsonValue) { | |
83 | + this.jsonValue = jsonValue; | |
84 | + } | |
85 | + | |
86 | + @Override | |
87 | + public int hashCode() { | |
88 | + final int prime = 31; | |
89 | + int result = 1; | |
90 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
91 | + result = prime * result + ((jsonValue == null) ? 0 : jsonValue.hashCode()); | |
92 | + result = prime * result + ((key == null) ? 0 : key.hashCode()); | |
93 | + return result; | |
94 | + } | |
95 | + | |
96 | + @Override | |
97 | + public boolean equals(Object obj) { | |
98 | + if (this == obj) | |
99 | + return true; | |
100 | + if (obj == null) | |
101 | + return false; | |
102 | + if (getClass() != obj.getClass()) | |
103 | + return false; | |
104 | + AdminSettingsEntity other = (AdminSettingsEntity) obj; | |
105 | + if (id == null) { | |
106 | + if (other.id != null) | |
107 | + return false; | |
108 | + } else if (!id.equals(other.id)) | |
109 | + return false; | |
110 | + if (jsonValue == null) { | |
111 | + if (other.jsonValue != null) | |
112 | + return false; | |
113 | + } else if (!jsonValue.equals(other.jsonValue)) | |
114 | + return false; | |
115 | + if (key == null) { | |
116 | + if (other.key != null) | |
117 | + return false; | |
118 | + } else if (!key.equals(other.key)) | |
119 | + return false; | |
120 | + return true; | |
121 | + } | |
122 | + | |
123 | + @Override | |
124 | + public String toString() { | |
125 | + StringBuilder builder = new StringBuilder(); | |
126 | + builder.append("AdminSettingsEntity [id="); | |
127 | + builder.append(id); | |
128 | + builder.append(", key="); | |
129 | + builder.append(key); | |
130 | + builder.append(", jsonValue="); | |
131 | + builder.append(jsonValue); | |
132 | + builder.append("]"); | |
133 | + return builder.toString(); | |
134 | + } | |
135 | + | |
136 | + @Override | |
137 | + public AdminSettings toData() { | |
138 | + AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id)); | |
139 | + adminSettings.setCreatedTime(UUIDs.unixTimestamp(id)); | |
140 | + adminSettings.setKey(key); | |
141 | + adminSettings.setJsonValue(jsonValue); | |
142 | + return adminSettings; | |
143 | + } | |
144 | + | |
145 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import javax.persistence.Column; | |
19 | +import javax.persistence.Entity; | |
20 | +import javax.persistence.Id; | |
21 | +import javax.persistence.Table; | |
22 | +import javax.persistence.Transient; | |
23 | +import com.fasterxml.jackson.databind.JsonNode; | |
24 | +import org.thingsboard.server.common.data.id.ComponentDescriptorId; | |
25 | +import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | |
26 | +import org.thingsboard.server.common.data.plugin.ComponentScope; | |
27 | +import org.thingsboard.server.common.data.plugin.ComponentType; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
30 | + | |
31 | +import java.util.UUID; | |
32 | + | |
33 | +@Entity | |
34 | +@Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME) | |
35 | +public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> { | |
36 | + | |
37 | + @Transient | |
38 | + private static final long serialVersionUID = 253590350877992402L; | |
39 | + | |
40 | + @Id | |
41 | + @Column(name = ModelConstants.ID_PROPERTY) | |
42 | + private UUID id; | |
43 | + | |
44 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY) | |
45 | + private ComponentType type; | |
46 | + | |
47 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY) | |
48 | + private ComponentScope scope; | |
49 | + | |
50 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY) | |
51 | + private String name; | |
52 | + | |
53 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY) | |
54 | + private String clazz; | |
55 | + | |
56 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY) | |
57 | + private JsonNode configurationDescriptor; | |
58 | + | |
59 | + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY) | |
60 | + private String actions; | |
61 | + | |
62 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
63 | + private String searchText; | |
64 | + | |
65 | + public ComponentDescriptorEntity() { | |
66 | + } | |
67 | + | |
68 | + public ComponentDescriptorEntity(ComponentDescriptor component) { | |
69 | + if (component.getId() != null) { | |
70 | + this.id = component.getId().getId(); | |
71 | + } | |
72 | + this.actions = component.getActions(); | |
73 | + this.type = component.getType(); | |
74 | + this.scope = component.getScope(); | |
75 | + this.name = component.getName(); | |
76 | + this.clazz = component.getClazz(); | |
77 | + this.configurationDescriptor = component.getConfigurationDescriptor(); | |
78 | + this.searchText = component.getName(); | |
79 | + } | |
80 | + | |
81 | + @Override | |
82 | + public ComponentDescriptor toData() { | |
83 | + ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(id)); | |
84 | + data.setType(type); | |
85 | + data.setScope(scope); | |
86 | + data.setName(this.getName()); | |
87 | + data.setClazz(this.getClazz()); | |
88 | + data.setActions(this.getActions()); | |
89 | + data.setConfigurationDescriptor(this.getConfigurationDescriptor()); | |
90 | + return data; | |
91 | + } | |
92 | + | |
93 | + @Override | |
94 | + public UUID getId() { | |
95 | + return id; | |
96 | + } | |
97 | + | |
98 | + @Override | |
99 | + public void setId(UUID id) { | |
100 | + this.id = id; | |
101 | + } | |
102 | + | |
103 | + public String getActions() { | |
104 | + return actions; | |
105 | + } | |
106 | + | |
107 | + public void setActions(String actions) { | |
108 | + this.actions = actions; | |
109 | + } | |
110 | + | |
111 | + public ComponentType getType() { | |
112 | + return type; | |
113 | + } | |
114 | + | |
115 | + public void setType(ComponentType type) { | |
116 | + this.type = type; | |
117 | + } | |
118 | + | |
119 | + public ComponentScope getScope() { | |
120 | + return scope; | |
121 | + } | |
122 | + | |
123 | + public void setScope(ComponentScope scope) { | |
124 | + this.scope = scope; | |
125 | + } | |
126 | + | |
127 | + public String getName() { | |
128 | + return name; | |
129 | + } | |
130 | + | |
131 | + public void setName(String name) { | |
132 | + this.name = name; | |
133 | + } | |
134 | + | |
135 | + public String getClazz() { | |
136 | + return clazz; | |
137 | + } | |
138 | + | |
139 | + public void setClazz(String clazz) { | |
140 | + this.clazz = clazz; | |
141 | + } | |
142 | + | |
143 | + public JsonNode getConfigurationDescriptor() { | |
144 | + return configurationDescriptor; | |
145 | + } | |
146 | + | |
147 | + public void setConfigurationDescriptor(JsonNode configurationDescriptor) { | |
148 | + this.configurationDescriptor = configurationDescriptor; | |
149 | + } | |
150 | + | |
151 | + public String getSearchText() { | |
152 | + return searchText; | |
153 | + } | |
154 | + | |
155 | + @Override | |
156 | + public void setSearchText(String searchText) { | |
157 | + this.searchText = searchText; | |
158 | + } | |
159 | + | |
160 | + @Override | |
161 | + public String getSearchTextSource() { | |
162 | + return searchText; | |
163 | + } | |
164 | +} | ... | ... |
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.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import com.fasterxml.jackson.databind.JsonNode; | |
25 | +import org.thingsboard.server.common.data.Customer; | |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | |
27 | +import org.thingsboard.server.common.data.id.TenantId; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
30 | + | |
31 | +import java.util.UUID; | |
32 | + | |
33 | +@Entity | |
34 | +@Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME) | |
35 | +public final class CustomerEntity implements SearchTextEntity<Customer> { | |
36 | + | |
37 | + @Transient | |
38 | + private static final long serialVersionUID = 8951342124082981556L; | |
39 | + | |
40 | + @Id | |
41 | + @Column(name = ModelConstants.ID_PROPERTY) | |
42 | + private UUID id; | |
43 | + | |
44 | + @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) | |
45 | + private UUID tenantId; | |
46 | + | |
47 | + @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) | |
48 | + private String title; | |
49 | + | |
50 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
51 | + private String searchText; | |
52 | + | |
53 | + @Column(name = ModelConstants.COUNTRY_PROPERTY) | |
54 | + private String country; | |
55 | + | |
56 | + @Column(name = ModelConstants.STATE_PROPERTY) | |
57 | + private String state; | |
58 | + | |
59 | + @Column(name = ModelConstants.CITY_PROPERTY) | |
60 | + private String city; | |
61 | + | |
62 | + @Column(name = ModelConstants.ADDRESS_PROPERTY) | |
63 | + private String address; | |
64 | + | |
65 | + @Column(name = ModelConstants.ADDRESS2_PROPERTY) | |
66 | + private String address2; | |
67 | + | |
68 | + @Column(name = ModelConstants.ZIP_PROPERTY) | |
69 | + private String zip; | |
70 | + | |
71 | + @Column(name = ModelConstants.PHONE_PROPERTY) | |
72 | + private String phone; | |
73 | + | |
74 | + @Column(name = ModelConstants.EMAIL_PROPERTY) | |
75 | + private String email; | |
76 | + | |
77 | + @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY) | |
78 | + private JsonNode additionalInfo; | |
79 | + | |
80 | + public CustomerEntity() { | |
81 | + super(); | |
82 | + } | |
83 | + | |
84 | + public CustomerEntity(Customer customer) { | |
85 | + if (customer.getId() != null) { | |
86 | + this.id = customer.getId().getId(); | |
87 | + } | |
88 | + this.tenantId = customer.getTenantId().getId(); | |
89 | + this.title = customer.getTitle(); | |
90 | + this.country = customer.getCountry(); | |
91 | + this.state = customer.getState(); | |
92 | + this.city = customer.getCity(); | |
93 | + this.address = customer.getAddress(); | |
94 | + this.address2 = customer.getAddress2(); | |
95 | + this.zip = customer.getZip(); | |
96 | + this.phone = customer.getPhone(); | |
97 | + this.email = customer.getEmail(); | |
98 | + this.additionalInfo = customer.getAdditionalInfo(); | |
99 | + } | |
100 | + | |
101 | + public UUID getId() { | |
102 | + return id; | |
103 | + } | |
104 | + | |
105 | + public void setId(UUID id) { | |
106 | + this.id = id; | |
107 | + } | |
108 | + | |
109 | + public UUID getTenantId() { | |
110 | + return tenantId; | |
111 | + } | |
112 | + | |
113 | + public void setTenantId(UUID tenantId) { | |
114 | + this.tenantId = tenantId; | |
115 | + } | |
116 | + | |
117 | + public String getTitle() { | |
118 | + return title; | |
119 | + } | |
120 | + | |
121 | + public void setTitle(String title) { | |
122 | + this.title = title; | |
123 | + } | |
124 | + | |
125 | + public String getCountry() { | |
126 | + return country; | |
127 | + } | |
128 | + | |
129 | + public void setCountry(String country) { | |
130 | + this.country = country; | |
131 | + } | |
132 | + | |
133 | + public String getState() { | |
134 | + return state; | |
135 | + } | |
136 | + | |
137 | + public void setState(String state) { | |
138 | + this.state = state; | |
139 | + } | |
140 | + | |
141 | + public String getCity() { | |
142 | + return city; | |
143 | + } | |
144 | + | |
145 | + public void setCity(String city) { | |
146 | + this.city = city; | |
147 | + } | |
148 | + | |
149 | + public String getAddress() { | |
150 | + return address; | |
151 | + } | |
152 | + | |
153 | + public void setAddress(String address) { | |
154 | + this.address = address; | |
155 | + } | |
156 | + | |
157 | + public String getAddress2() { | |
158 | + return address2; | |
159 | + } | |
160 | + | |
161 | + public void setAddress2(String address2) { | |
162 | + this.address2 = address2; | |
163 | + } | |
164 | + | |
165 | + public String getZip() { | |
166 | + return zip; | |
167 | + } | |
168 | + | |
169 | + public void setZip(String zip) { | |
170 | + this.zip = zip; | |
171 | + } | |
172 | + | |
173 | + public String getPhone() { | |
174 | + return phone; | |
175 | + } | |
176 | + | |
177 | + public void setPhone(String phone) { | |
178 | + this.phone = phone; | |
179 | + } | |
180 | + | |
181 | + public String getEmail() { | |
182 | + return email; | |
183 | + } | |
184 | + | |
185 | + public void setEmail(String email) { | |
186 | + this.email = email; | |
187 | + } | |
188 | + | |
189 | + public JsonNode getAdditionalInfo() { | |
190 | + return additionalInfo; | |
191 | + } | |
192 | + | |
193 | + public void setAdditionalInfo(JsonNode additionalInfo) { | |
194 | + this.additionalInfo = additionalInfo; | |
195 | + } | |
196 | + | |
197 | + @Override | |
198 | + public String getSearchTextSource() { | |
199 | + return title; | |
200 | + } | |
201 | + | |
202 | + @Override | |
203 | + public void setSearchText(String searchText) { | |
204 | + this.searchText = searchText; | |
205 | + } | |
206 | + | |
207 | + public String getSearchText() { | |
208 | + return searchText; | |
209 | + } | |
210 | + | |
211 | + @Override | |
212 | + public int hashCode() { | |
213 | + final int prime = 31; | |
214 | + int result = 1; | |
215 | + result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode()); | |
216 | + result = prime * result + ((address == null) ? 0 : address.hashCode()); | |
217 | + result = prime * result + ((address2 == null) ? 0 : address2.hashCode()); | |
218 | + result = prime * result + ((city == null) ? 0 : city.hashCode()); | |
219 | + result = prime * result + ((country == null) ? 0 : country.hashCode()); | |
220 | + result = prime * result + ((email == null) ? 0 : email.hashCode()); | |
221 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
222 | + result = prime * result + ((phone == null) ? 0 : phone.hashCode()); | |
223 | + result = prime * result + ((state == null) ? 0 : state.hashCode()); | |
224 | + result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); | |
225 | + result = prime * result + ((title == null) ? 0 : title.hashCode()); | |
226 | + result = prime * result + ((zip == null) ? 0 : zip.hashCode()); | |
227 | + return result; | |
228 | + } | |
229 | + | |
230 | + @Override | |
231 | + public boolean equals(Object obj) { | |
232 | + if (this == obj) | |
233 | + return true; | |
234 | + if (obj == null) | |
235 | + return false; | |
236 | + if (getClass() != obj.getClass()) | |
237 | + return false; | |
238 | + CustomerEntity other = (CustomerEntity) obj; | |
239 | + if (additionalInfo == null) { | |
240 | + if (other.additionalInfo != null) | |
241 | + return false; | |
242 | + } else if (!additionalInfo.equals(other.additionalInfo)) | |
243 | + return false; | |
244 | + if (address == null) { | |
245 | + if (other.address != null) | |
246 | + return false; | |
247 | + } else if (!address.equals(other.address)) | |
248 | + return false; | |
249 | + if (address2 == null) { | |
250 | + if (other.address2 != null) | |
251 | + return false; | |
252 | + } else if (!address2.equals(other.address2)) | |
253 | + return false; | |
254 | + if (city == null) { | |
255 | + if (other.city != null) | |
256 | + return false; | |
257 | + } else if (!city.equals(other.city)) | |
258 | + return false; | |
259 | + if (country == null) { | |
260 | + if (other.country != null) | |
261 | + return false; | |
262 | + } else if (!country.equals(other.country)) | |
263 | + return false; | |
264 | + if (email == null) { | |
265 | + if (other.email != null) | |
266 | + return false; | |
267 | + } else if (!email.equals(other.email)) | |
268 | + return false; | |
269 | + if (id == null) { | |
270 | + if (other.id != null) | |
271 | + return false; | |
272 | + } else if (!id.equals(other.id)) | |
273 | + return false; | |
274 | + if (phone == null) { | |
275 | + if (other.phone != null) | |
276 | + return false; | |
277 | + } else if (!phone.equals(other.phone)) | |
278 | + return false; | |
279 | + if (state == null) { | |
280 | + if (other.state != null) | |
281 | + return false; | |
282 | + } else if (!state.equals(other.state)) | |
283 | + return false; | |
284 | + if (tenantId == null) { | |
285 | + if (other.tenantId != null) | |
286 | + return false; | |
287 | + } else if (!tenantId.equals(other.tenantId)) | |
288 | + return false; | |
289 | + if (title == null) { | |
290 | + if (other.title != null) | |
291 | + return false; | |
292 | + } else if (!title.equals(other.title)) | |
293 | + return false; | |
294 | + if (zip == null) { | |
295 | + if (other.zip != null) | |
296 | + return false; | |
297 | + } else if (!zip.equals(other.zip)) | |
298 | + return false; | |
299 | + return true; | |
300 | + } | |
301 | + | |
302 | + @Override | |
303 | + public String toString() { | |
304 | + StringBuilder builder = new StringBuilder(); | |
305 | + builder.append("CustomerEntity [id="); | |
306 | + builder.append(id); | |
307 | + builder.append(", tenantId="); | |
308 | + builder.append(tenantId); | |
309 | + builder.append(", title="); | |
310 | + builder.append(title); | |
311 | + builder.append(", country="); | |
312 | + builder.append(country); | |
313 | + builder.append(", state="); | |
314 | + builder.append(state); | |
315 | + builder.append(", city="); | |
316 | + builder.append(city); | |
317 | + builder.append(", address="); | |
318 | + builder.append(address); | |
319 | + builder.append(", address2="); | |
320 | + builder.append(address2); | |
321 | + builder.append(", zip="); | |
322 | + builder.append(zip); | |
323 | + builder.append(", phone="); | |
324 | + builder.append(phone); | |
325 | + builder.append(", email="); | |
326 | + builder.append(email); | |
327 | + builder.append(", additionalInfo="); | |
328 | + builder.append(additionalInfo); | |
329 | + builder.append("]"); | |
330 | + return builder.toString(); | |
331 | + } | |
332 | + | |
333 | + @Override | |
334 | + public Customer toData() { | |
335 | + Customer customer = new Customer(new CustomerId(id)); | |
336 | + customer.setCreatedTime(UUIDs.unixTimestamp(id)); | |
337 | + customer.setTenantId(new TenantId(tenantId)); | |
338 | + customer.setTitle(title); | |
339 | + customer.setCountry(country); | |
340 | + customer.setState(state); | |
341 | + customer.setCity(city); | |
342 | + customer.setAddress(address); | |
343 | + customer.setAddress2(address2); | |
344 | + customer.setZip(zip); | |
345 | + customer.setPhone(phone); | |
346 | + customer.setEmail(email); | |
347 | + customer.setAdditionalInfo(additionalInfo); | |
348 | + return customer; | |
349 | + } | |
350 | + | |
351 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import com.fasterxml.jackson.databind.JsonNode; | |
25 | +import org.thingsboard.server.common.data.Dashboard; | |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | |
27 | +import org.thingsboard.server.common.data.id.DashboardId; | |
28 | +import org.thingsboard.server.common.data.id.TenantId; | |
29 | +import org.thingsboard.server.dao.model.ModelConstants; | |
30 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
31 | + | |
32 | +import java.util.UUID; | |
33 | + | |
34 | +@Entity | |
35 | +@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) | |
36 | +public final class DashboardEntity implements SearchTextEntity<Dashboard> { | |
37 | + | |
38 | + @Transient | |
39 | + private static final long serialVersionUID = -4838084363113078898L; | |
40 | + | |
41 | + @Id | |
42 | + @Column(name = ModelConstants.ID_PROPERTY) | |
43 | + private UUID id; | |
44 | + | |
45 | + @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | |
46 | + private UUID tenantId; | |
47 | + | |
48 | + @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) | |
49 | + private UUID customerId; | |
50 | + | |
51 | + @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | |
52 | + private String title; | |
53 | + | |
54 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
55 | + private String searchText; | |
56 | + | |
57 | + @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY) | |
58 | + private JsonNode configuration; | |
59 | + | |
60 | + public DashboardEntity() { | |
61 | + super(); | |
62 | + } | |
63 | + | |
64 | + public DashboardEntity(Dashboard dashboard) { | |
65 | + if (dashboard.getId() != null) { | |
66 | + this.id = dashboard.getId().getId(); | |
67 | + } | |
68 | + if (dashboard.getTenantId() != null) { | |
69 | + this.tenantId = dashboard.getTenantId().getId(); | |
70 | + } | |
71 | + if (dashboard.getCustomerId() != null) { | |
72 | + this.customerId = dashboard.getCustomerId().getId(); | |
73 | + } | |
74 | + this.title = dashboard.getTitle(); | |
75 | + this.configuration = dashboard.getConfiguration(); | |
76 | + } | |
77 | + | |
78 | + public UUID getId() { | |
79 | + return id; | |
80 | + } | |
81 | + | |
82 | + public void setId(UUID id) { | |
83 | + this.id = id; | |
84 | + } | |
85 | + | |
86 | + public UUID getTenantId() { | |
87 | + return tenantId; | |
88 | + } | |
89 | + | |
90 | + public void setTenantId(UUID tenantId) { | |
91 | + this.tenantId = tenantId; | |
92 | + } | |
93 | + | |
94 | + public UUID getCustomerId() { | |
95 | + return customerId; | |
96 | + } | |
97 | + | |
98 | + public void setCustomerId(UUID customerId) { | |
99 | + this.customerId = customerId; | |
100 | + } | |
101 | + | |
102 | + public String getTitle() { | |
103 | + return title; | |
104 | + } | |
105 | + | |
106 | + public void setTitle(String title) { | |
107 | + this.title = title; | |
108 | + } | |
109 | + | |
110 | + public JsonNode getConfiguration() { | |
111 | + return configuration; | |
112 | + } | |
113 | + | |
114 | + public void setConfiguration(JsonNode configuration) { | |
115 | + this.configuration = configuration; | |
116 | + } | |
117 | + | |
118 | + @Override | |
119 | + public String getSearchTextSource() { | |
120 | + return title; | |
121 | + } | |
122 | + | |
123 | + @Override | |
124 | + public void setSearchText(String searchText) { | |
125 | + this.searchText = searchText; | |
126 | + } | |
127 | + | |
128 | + public String getSearchText() { | |
129 | + return searchText; | |
130 | + } | |
131 | + | |
132 | + @Override | |
133 | + public int hashCode() { | |
134 | + final int prime = 31; | |
135 | + int result = 1; | |
136 | + result = prime * result + ((configuration == null) ? 0 : configuration.hashCode()); | |
137 | + result = prime * result + ((customerId == null) ? 0 : customerId.hashCode()); | |
138 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
139 | + result = prime * result + ((searchText == null) ? 0 : searchText.hashCode()); | |
140 | + result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); | |
141 | + result = prime * result + ((title == null) ? 0 : title.hashCode()); | |
142 | + return result; | |
143 | + } | |
144 | + | |
145 | + @Override | |
146 | + public boolean equals(Object obj) { | |
147 | + if (this == obj) | |
148 | + return true; | |
149 | + if (obj == null) | |
150 | + return false; | |
151 | + if (getClass() != obj.getClass()) | |
152 | + return false; | |
153 | + DashboardEntity other = (DashboardEntity) obj; | |
154 | + if (configuration == null) { | |
155 | + if (other.configuration != null) | |
156 | + return false; | |
157 | + } else if (!configuration.equals(other.configuration)) | |
158 | + return false; | |
159 | + if (customerId == null) { | |
160 | + if (other.customerId != null) | |
161 | + return false; | |
162 | + } else if (!customerId.equals(other.customerId)) | |
163 | + return false; | |
164 | + if (id == null) { | |
165 | + if (other.id != null) | |
166 | + return false; | |
167 | + } else if (!id.equals(other.id)) | |
168 | + return false; | |
169 | + if (searchText == null) { | |
170 | + if (other.searchText != null) | |
171 | + return false; | |
172 | + } else if (!searchText.equals(other.searchText)) | |
173 | + return false; | |
174 | + if (tenantId == null) { | |
175 | + if (other.tenantId != null) | |
176 | + return false; | |
177 | + } else if (!tenantId.equals(other.tenantId)) | |
178 | + return false; | |
179 | + if (title == null) { | |
180 | + if (other.title != null) | |
181 | + return false; | |
182 | + } else if (!title.equals(other.title)) | |
183 | + return false; | |
184 | + return true; | |
185 | + } | |
186 | + | |
187 | + @Override | |
188 | + public String toString() { | |
189 | + StringBuilder builder = new StringBuilder(); | |
190 | + builder.append("DashboardEntity [id="); | |
191 | + builder.append(id); | |
192 | + builder.append(", tenantId="); | |
193 | + builder.append(tenantId); | |
194 | + builder.append(", customerId="); | |
195 | + builder.append(customerId); | |
196 | + builder.append(", title="); | |
197 | + builder.append(title); | |
198 | + builder.append(", searchText="); | |
199 | + builder.append(searchText); | |
200 | + builder.append(", configuration="); | |
201 | + builder.append(configuration); | |
202 | + builder.append("]"); | |
203 | + return builder.toString(); | |
204 | + } | |
205 | + | |
206 | + @Override | |
207 | + public Dashboard toData() { | |
208 | + Dashboard dashboard = new Dashboard(new DashboardId(id)); | |
209 | + dashboard.setCreatedTime(UUIDs.unixTimestamp(id)); | |
210 | + if (tenantId != null) { | |
211 | + dashboard.setTenantId(new TenantId(tenantId)); | |
212 | + } | |
213 | + if (customerId != null) { | |
214 | + dashboard.setCustomerId(new CustomerId(customerId)); | |
215 | + } | |
216 | + dashboard.setTitle(title); | |
217 | + dashboard.setConfiguration(configuration); | |
218 | + return dashboard; | |
219 | + } | |
220 | + | |
221 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import org.thingsboard.server.common.data.DashboardInfo; | |
25 | +import org.thingsboard.server.common.data.id.CustomerId; | |
26 | +import org.thingsboard.server.common.data.id.DashboardId; | |
27 | +import org.thingsboard.server.common.data.id.TenantId; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
30 | + | |
31 | +import java.util.UUID; | |
32 | + | |
33 | +@Entity | |
34 | +@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) | |
35 | +public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | |
36 | + | |
37 | + @Transient | |
38 | + private static final long serialVersionUID = -5525675905528050250L; | |
39 | + | |
40 | + @Id | |
41 | + @Column(name = ModelConstants.ID_PROPERTY) | |
42 | + private UUID id; | |
43 | + | |
44 | + @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | |
45 | + private UUID tenantId; | |
46 | + | |
47 | + @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) | |
48 | + private UUID customerId; | |
49 | + | |
50 | + @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | |
51 | + private String title; | |
52 | + | |
53 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
54 | + private String searchText; | |
55 | + | |
56 | + public DashboardInfoEntity() { | |
57 | + super(); | |
58 | + } | |
59 | + | |
60 | + public DashboardInfoEntity(DashboardInfo dashboardInfo) { | |
61 | + if (dashboardInfo.getId() != null) { | |
62 | + this.id = dashboardInfo.getId().getId(); | |
63 | + } | |
64 | + if (dashboardInfo.getTenantId() != null) { | |
65 | + this.tenantId = dashboardInfo.getTenantId().getId(); | |
66 | + } | |
67 | + if (dashboardInfo.getCustomerId() != null) { | |
68 | + this.customerId = dashboardInfo.getCustomerId().getId(); | |
69 | + } | |
70 | + this.title = dashboardInfo.getTitle(); | |
71 | + } | |
72 | + | |
73 | + public UUID getId() { | |
74 | + return id; | |
75 | + } | |
76 | + | |
77 | + public void setId(UUID id) { | |
78 | + this.id = id; | |
79 | + } | |
80 | + | |
81 | + public UUID getTenantId() { | |
82 | + return tenantId; | |
83 | + } | |
84 | + | |
85 | + public void setTenantId(UUID tenantId) { | |
86 | + this.tenantId = tenantId; | |
87 | + } | |
88 | + | |
89 | + public UUID getCustomerId() { | |
90 | + return customerId; | |
91 | + } | |
92 | + | |
93 | + public void setCustomerId(UUID customerId) { | |
94 | + this.customerId = customerId; | |
95 | + } | |
96 | + | |
97 | + public String getTitle() { | |
98 | + return title; | |
99 | + } | |
100 | + | |
101 | + public void setTitle(String title) { | |
102 | + this.title = title; | |
103 | + } | |
104 | + | |
105 | + @Override | |
106 | + public String getSearchTextSource() { | |
107 | + return title; | |
108 | + } | |
109 | + | |
110 | + @Override | |
111 | + public void setSearchText(String searchText) { | |
112 | + this.searchText = searchText; | |
113 | + } | |
114 | + | |
115 | + public String getSearchText() { | |
116 | + return searchText; | |
117 | + } | |
118 | + | |
119 | + @Override | |
120 | + public int hashCode() { | |
121 | + final int prime = 31; | |
122 | + int result = 1; | |
123 | + result = prime * result + ((customerId == null) ? 0 : customerId.hashCode()); | |
124 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
125 | + result = prime * result + ((searchText == null) ? 0 : searchText.hashCode()); | |
126 | + result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); | |
127 | + result = prime * result + ((title == null) ? 0 : title.hashCode()); | |
128 | + return result; | |
129 | + } | |
130 | + | |
131 | + @Override | |
132 | + public boolean equals(Object obj) { | |
133 | + if (this == obj) | |
134 | + return true; | |
135 | + if (obj == null) | |
136 | + return false; | |
137 | + if (getClass() != obj.getClass()) | |
138 | + return false; | |
139 | + DashboardInfoEntity other = (DashboardInfoEntity) obj; | |
140 | + if (customerId == null) { | |
141 | + if (other.customerId != null) | |
142 | + return false; | |
143 | + } else if (!customerId.equals(other.customerId)) | |
144 | + return false; | |
145 | + if (id == null) { | |
146 | + if (other.id != null) | |
147 | + return false; | |
148 | + } else if (!id.equals(other.id)) | |
149 | + return false; | |
150 | + if (searchText == null) { | |
151 | + if (other.searchText != null) | |
152 | + return false; | |
153 | + } else if (!searchText.equals(other.searchText)) | |
154 | + return false; | |
155 | + if (tenantId == null) { | |
156 | + if (other.tenantId != null) | |
157 | + return false; | |
158 | + } else if (!tenantId.equals(other.tenantId)) | |
159 | + return false; | |
160 | + if (title == null) { | |
161 | + if (other.title != null) | |
162 | + return false; | |
163 | + } else if (!title.equals(other.title)) | |
164 | + return false; | |
165 | + return true; | |
166 | + } | |
167 | + | |
168 | + @Override | |
169 | + public String toString() { | |
170 | + StringBuilder builder = new StringBuilder(); | |
171 | + builder.append("DashboardInfoEntity [id="); | |
172 | + builder.append(id); | |
173 | + builder.append(", tenantId="); | |
174 | + builder.append(tenantId); | |
175 | + builder.append(", customerId="); | |
176 | + builder.append(customerId); | |
177 | + builder.append(", title="); | |
178 | + builder.append(title); | |
179 | + builder.append(", searchText="); | |
180 | + builder.append(searchText); | |
181 | + builder.append("]"); | |
182 | + return builder.toString(); | |
183 | + } | |
184 | + | |
185 | + @Override | |
186 | + public DashboardInfo toData() { | |
187 | + DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(id)); | |
188 | + dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id)); | |
189 | + if (tenantId != null) { | |
190 | + dashboardInfo.setTenantId(new TenantId(tenantId)); | |
191 | + } | |
192 | + if (customerId != null) { | |
193 | + dashboardInfo.setCustomerId(new CustomerId(customerId)); | |
194 | + } | |
195 | + dashboardInfo.setTitle(title); | |
196 | + return dashboardInfo; | |
197 | + } | |
198 | + | |
199 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import org.thingsboard.server.common.data.id.DeviceCredentialsId; | |
25 | +import org.thingsboard.server.common.data.id.DeviceId; | |
26 | +import org.thingsboard.server.common.data.security.DeviceCredentials; | |
27 | +import org.thingsboard.server.common.data.security.DeviceCredentialsType; | |
28 | +import org.thingsboard.server.dao.model.BaseEntity; | |
29 | +import org.thingsboard.server.dao.model.ModelConstants; | |
30 | + | |
31 | +import java.util.UUID; | |
32 | + | |
33 | +@Entity | |
34 | +@Table(name = ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME) | |
35 | +public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentials> { | |
36 | + | |
37 | + @Transient | |
38 | + private static final long serialVersionUID = -2512362753385470464L; | |
39 | + @Id | |
40 | + @Column(name = ModelConstants.ID_PROPERTY) | |
41 | + private UUID id; | |
42 | + | |
43 | + @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) | |
44 | + private UUID deviceId; | |
45 | + | |
46 | + @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY) | |
47 | + private DeviceCredentialsType credentialsType; | |
48 | + | |
49 | + @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY) | |
50 | + private String credentialsId; | |
51 | + | |
52 | + @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_VALUE_PROPERTY) | |
53 | + private String credentialsValue; | |
54 | + | |
55 | + public DeviceCredentialsEntity() { | |
56 | + super(); | |
57 | + } | |
58 | + | |
59 | + public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) { | |
60 | + if (deviceCredentials.getId() != null) { | |
61 | + this.id = deviceCredentials.getId().getId(); | |
62 | + } | |
63 | + if (deviceCredentials.getDeviceId() != null) { | |
64 | + this.deviceId = deviceCredentials.getDeviceId().getId(); | |
65 | + } | |
66 | + this.credentialsType = deviceCredentials.getCredentialsType(); | |
67 | + this.credentialsId = deviceCredentials.getCredentialsId(); | |
68 | + this.credentialsValue = deviceCredentials.getCredentialsValue(); | |
69 | + } | |
70 | + | |
71 | + public UUID getId() { | |
72 | + return id; | |
73 | + } | |
74 | + | |
75 | + public void setId(UUID id) { | |
76 | + this.id = id; | |
77 | + } | |
78 | + | |
79 | + public UUID getDeviceId() { | |
80 | + return deviceId; | |
81 | + } | |
82 | + | |
83 | + public void setDeviceId(UUID deviceId) { | |
84 | + this.deviceId = deviceId; | |
85 | + } | |
86 | + | |
87 | + public DeviceCredentialsType getCredentialsType() { | |
88 | + return credentialsType; | |
89 | + } | |
90 | + | |
91 | + public void setCredentialsType(DeviceCredentialsType credentialsType) { | |
92 | + this.credentialsType = credentialsType; | |
93 | + } | |
94 | + | |
95 | + public String getCredentialsId() { | |
96 | + return credentialsId; | |
97 | + } | |
98 | + | |
99 | + public void setCredentialsId(String credentialsId) { | |
100 | + this.credentialsId = credentialsId; | |
101 | + } | |
102 | + | |
103 | + public String getCredentialsValue() { | |
104 | + return credentialsValue; | |
105 | + } | |
106 | + | |
107 | + public void setCredentialsValue(String credentialsValue) { | |
108 | + this.credentialsValue = credentialsValue; | |
109 | + } | |
110 | + | |
111 | + @Override | |
112 | + public int hashCode() { | |
113 | + final int prime = 31; | |
114 | + int result = 1; | |
115 | + result = prime * result + ((credentialsId == null) ? 0 : credentialsId.hashCode()); | |
116 | + result = prime * result + ((credentialsType == null) ? 0 : credentialsType.hashCode()); | |
117 | + result = prime * result + ((credentialsValue == null) ? 0 : credentialsValue.hashCode()); | |
118 | + result = prime * result + ((deviceId == null) ? 0 : deviceId.hashCode()); | |
119 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
120 | + return result; | |
121 | + } | |
122 | + | |
123 | + @Override | |
124 | + public boolean equals(Object obj) { | |
125 | + if (this == obj) | |
126 | + return true; | |
127 | + if (obj == null) | |
128 | + return false; | |
129 | + if (getClass() != obj.getClass()) | |
130 | + return false; | |
131 | + DeviceCredentialsEntity other = (DeviceCredentialsEntity) obj; | |
132 | + if (credentialsId == null) { | |
133 | + if (other.credentialsId != null) | |
134 | + return false; | |
135 | + } else if (!credentialsId.equals(other.credentialsId)) | |
136 | + return false; | |
137 | + if (credentialsType != other.credentialsType) | |
138 | + return false; | |
139 | + if (credentialsValue == null) { | |
140 | + if (other.credentialsValue != null) | |
141 | + return false; | |
142 | + } else if (!credentialsValue.equals(other.credentialsValue)) | |
143 | + return false; | |
144 | + if (deviceId == null) { | |
145 | + if (other.deviceId != null) | |
146 | + return false; | |
147 | + } else if (!deviceId.equals(other.deviceId)) | |
148 | + return false; | |
149 | + if (id == null) { | |
150 | + if (other.id != null) | |
151 | + return false; | |
152 | + } else if (!id.equals(other.id)) | |
153 | + return false; | |
154 | + return true; | |
155 | + } | |
156 | + | |
157 | + @Override | |
158 | + public String toString() { | |
159 | + StringBuilder builder = new StringBuilder(); | |
160 | + builder.append("DeviceCredentialsEntity [id="); | |
161 | + builder.append(id); | |
162 | + builder.append(", deviceId="); | |
163 | + builder.append(deviceId); | |
164 | + builder.append(", credentialsType="); | |
165 | + builder.append(credentialsType); | |
166 | + builder.append(", credentialsId="); | |
167 | + builder.append(credentialsId); | |
168 | + builder.append(", credentialsValue="); | |
169 | + builder.append(credentialsValue); | |
170 | + builder.append("]"); | |
171 | + return builder.toString(); | |
172 | + } | |
173 | + | |
174 | + @Override | |
175 | + public DeviceCredentials toData() { | |
176 | + DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id)); | |
177 | + deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id)); | |
178 | + if (deviceId != null) { | |
179 | + deviceCredentials.setDeviceId(new DeviceId(deviceId)); | |
180 | + } | |
181 | + deviceCredentials.setCredentialsType(credentialsType); | |
182 | + deviceCredentials.setCredentialsId(credentialsId); | |
183 | + deviceCredentials.setCredentialsValue(credentialsValue); | |
184 | + return deviceCredentials; | |
185 | + } | |
186 | + | |
187 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import com.fasterxml.jackson.databind.JsonNode; | |
25 | +import org.thingsboard.server.common.data.Device; | |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | |
27 | +import org.thingsboard.server.common.data.id.DeviceId; | |
28 | +import org.thingsboard.server.common.data.id.TenantId; | |
29 | +import org.thingsboard.server.dao.model.ModelConstants; | |
30 | +import org.thingsboard.server.dao.model.SearchTextEntity; | |
31 | + | |
32 | +import java.util.UUID; | |
33 | + | |
34 | +@Entity | |
35 | +@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) | |
36 | +public final class DeviceEntity implements SearchTextEntity<Device> { | |
37 | + | |
38 | + @Transient | |
39 | + private static final long serialVersionUID = 8050086401213322856L; | |
40 | + | |
41 | + @Id | |
42 | + @Column(name = ModelConstants.ID_PROPERTY) | |
43 | + private UUID id; | |
44 | + | |
45 | + @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY) | |
46 | + private UUID tenantId; | |
47 | + | |
48 | + @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY) | |
49 | + private UUID customerId; | |
50 | + | |
51 | + @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) | |
52 | + private String name; | |
53 | + | |
54 | + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | |
55 | + private String searchText; | |
56 | + | |
57 | + @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY) | |
58 | + private JsonNode additionalInfo; | |
59 | + | |
60 | + public DeviceEntity() { | |
61 | + super(); | |
62 | + } | |
63 | + | |
64 | + public DeviceEntity(Device device) { | |
65 | + if (device.getId() != null) { | |
66 | + this.id = device.getId().getId(); | |
67 | + } | |
68 | + if (device.getTenantId() != null) { | |
69 | + this.tenantId = device.getTenantId().getId(); | |
70 | + } | |
71 | + if (device.getCustomerId() != null) { | |
72 | + this.customerId = device.getCustomerId().getId(); | |
73 | + } | |
74 | + this.name = device.getName(); | |
75 | + this.additionalInfo = device.getAdditionalInfo(); | |
76 | + } | |
77 | + | |
78 | + public UUID getId() { | |
79 | + return id; | |
80 | + } | |
81 | + | |
82 | + public void setId(UUID id) { | |
83 | + this.id = id; | |
84 | + } | |
85 | + | |
86 | + public UUID getTenantId() { | |
87 | + return tenantId; | |
88 | + } | |
89 | + | |
90 | + public void setTenantId(UUID tenantId) { | |
91 | + this.tenantId = tenantId; | |
92 | + } | |
93 | + | |
94 | + public UUID getCustomerId() { | |
95 | + return customerId; | |
96 | + } | |
97 | + | |
98 | + public void setCustomerId(UUID customerId) { | |
99 | + this.customerId = customerId; | |
100 | + } | |
101 | + | |
102 | + public String getName() { | |
103 | + return name; | |
104 | + } | |
105 | + | |
106 | + public void setName(String name) { | |
107 | + this.name = name; | |
108 | + } | |
109 | + | |
110 | + public JsonNode getAdditionalInfo() { | |
111 | + return additionalInfo; | |
112 | + } | |
113 | + | |
114 | + public void setAdditionalInfo(JsonNode additionalInfo) { | |
115 | + this.additionalInfo = additionalInfo; | |
116 | + } | |
117 | + | |
118 | + @Override | |
119 | + public String getSearchTextSource() { | |
120 | + return name; | |
121 | + } | |
122 | + | |
123 | + @Override | |
124 | + public void setSearchText(String searchText) { | |
125 | + this.searchText = searchText; | |
126 | + } | |
127 | + | |
128 | + public String getSearchText() { | |
129 | + return searchText; | |
130 | + } | |
131 | + | |
132 | + @Override | |
133 | + public int hashCode() { | |
134 | + final int prime = 31; | |
135 | + int result = 1; | |
136 | + result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode()); | |
137 | + result = prime * result + ((customerId == null) ? 0 : customerId.hashCode()); | |
138 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
139 | + result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
140 | + result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); | |
141 | + return result; | |
142 | + } | |
143 | + | |
144 | + @Override | |
145 | + public boolean equals(Object obj) { | |
146 | + if (this == obj) | |
147 | + return true; | |
148 | + if (obj == null) | |
149 | + return false; | |
150 | + if (getClass() != obj.getClass()) | |
151 | + return false; | |
152 | + DeviceEntity other = (DeviceEntity) obj; | |
153 | + if (additionalInfo == null) { | |
154 | + if (other.additionalInfo != null) | |
155 | + return false; | |
156 | + } else if (!additionalInfo.equals(other.additionalInfo)) | |
157 | + return false; | |
158 | + if (customerId == null) { | |
159 | + if (other.customerId != null) | |
160 | + return false; | |
161 | + } else if (!customerId.equals(other.customerId)) | |
162 | + return false; | |
163 | + if (id == null) { | |
164 | + if (other.id != null) | |
165 | + return false; | |
166 | + } else if (!id.equals(other.id)) | |
167 | + return false; | |
168 | + if (name == null) { | |
169 | + if (other.name != null) | |
170 | + return false; | |
171 | + } else if (!name.equals(other.name)) | |
172 | + return false; | |
173 | + if (tenantId == null) { | |
174 | + if (other.tenantId != null) | |
175 | + return false; | |
176 | + } else if (!tenantId.equals(other.tenantId)) | |
177 | + return false; | |
178 | + return true; | |
179 | + } | |
180 | + | |
181 | + @Override | |
182 | + public String toString() { | |
183 | + StringBuilder builder = new StringBuilder(); | |
184 | + builder.append("DeviceEntity [id="); | |
185 | + builder.append(id); | |
186 | + builder.append(", tenantId="); | |
187 | + builder.append(tenantId); | |
188 | + builder.append(", customerId="); | |
189 | + builder.append(customerId); | |
190 | + builder.append(", name="); | |
191 | + builder.append(name); | |
192 | + builder.append(", additionalInfo="); | |
193 | + builder.append(additionalInfo); | |
194 | + builder.append("]"); | |
195 | + return builder.toString(); | |
196 | + } | |
197 | + | |
198 | + @Override | |
199 | + public Device toData() { | |
200 | + Device device = new Device(new DeviceId(id)); | |
201 | + device.setCreatedTime(UUIDs.unixTimestamp(id)); | |
202 | + if (tenantId != null) { | |
203 | + device.setTenantId(new TenantId(tenantId)); | |
204 | + } | |
205 | + if (customerId != null) { | |
206 | + device.setCustomerId(new CustomerId(customerId)); | |
207 | + } | |
208 | + device.setName(name); | |
209 | + device.setAdditionalInfo(additionalInfo); | |
210 | + return device; | |
211 | + } | |
212 | + | |
213 | +} | |
\ 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.dao.model.sql; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import javax.persistence.Column; | |
20 | +import javax.persistence.Entity; | |
21 | +import javax.persistence.Id; | |
22 | +import javax.persistence.Table; | |
23 | +import javax.persistence.Transient; | |
24 | +import com.fasterxml.jackson.databind.JsonNode; | |
25 | +import lombok.Data; | |
26 | +import lombok.NoArgsConstructor; | |
27 | +import org.thingsboard.server.common.data.EntityType; | |
28 | +import org.thingsboard.server.common.data.Event; | |
29 | +import org.thingsboard.server.common.data.id.*; | |
30 | +import org.thingsboard.server.dao.model.BaseEntity; | |
31 | +import org.thingsboard.server.dao.model.ModelConstants; | |
32 | + | |
33 | +import java.util.UUID; | |
34 | + | |
35 | +@Data | |
36 | +@NoArgsConstructor | |
37 | +@Entity | |
38 | +@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) | |
39 | +public class EventEntity implements BaseEntity<Event> { | |
40 | + | |
41 | + @Transient | |
42 | + private static final long serialVersionUID = -5717830061727466727L; | |
43 | + | |
44 | + @Column(name = ModelConstants.ID_PROPERTY) | |
45 | + private UUID id; | |
46 | + | |
47 | + @Id | |
48 | + @Column(name = ModelConstants.EVENT_TENANT_ID_PROPERTY) | |
49 | + private UUID tenantId; | |
50 | + | |
51 | + @Column(name = ModelConstants.EVENT_ENTITY_TYPE_PROPERTY) | |
52 | + private EntityType entityType; | |
53 | + | |
54 | + @Column(name = ModelConstants.EVENT_ENTITY_ID_PROPERTY) | |
55 | + private UUID entityId; | |
56 | + | |
57 | + @Column(name = ModelConstants.EVENT_TYPE_PROPERTY) | |
58 | + private String eventType; | |
59 | + | |
60 | + @Column(name = ModelConstants.EVENT_UID_PROPERTY) | |
61 | + private String eventUId; | |
62 | + | |
63 | + @Column(name = ModelConstants.EVENT_BODY_PROPERTY) | |
64 | + private JsonNode body; | |
65 | + | |
66 | + public EventEntity(Event event) { | |
67 | + if (event.getId() != null) { | |
68 | + this.id = event.getId().getId(); | |
69 | + } | |
70 | + if (event.getTenantId() != null) { | |
71 | + this.tenantId = event.getTenantId().getId(); | |
72 | + } | |
73 | + if (event.getEntityId() != null) { | |
74 | + this.entityType = event.getEntityId().getEntityType(); | |
75 | + this.entityId = event.getEntityId().getId(); | |
76 | + } | |
77 | + this.eventType = event.getType(); | |
78 | + this.eventUId = event.getUid(); | |
79 | + this.body = event.getBody(); | |
80 | + } | |
81 | + | |
82 | + @Override | |
83 | + public UUID getId() { | |
84 | + return id; | |
85 | + } | |
86 | + | |
87 | + @Override | |
88 | + public void setId(UUID id) { | |
89 | + this.id = id; | |
90 | + } | |
91 | + | |
92 | + @Override | |
93 | + public Event toData() { | |
94 | + Event event = new Event(new EventId(id)); | |
95 | + event.setCreatedTime(UUIDs.unixTimestamp(id)); | |
96 | + event.setTenantId(new TenantId(tenantId)); | |
97 | + switch (entityType) { | |
98 | + case TENANT: | |
99 | + event.setEntityId(new TenantId(entityId)); | |
100 | + break; | |
101 | + case DEVICE: | |
102 | + event.setEntityId(new DeviceId(entityId)); | |
103 | + break; | |
104 | + case CUSTOMER: | |
105 | + event.setEntityId(new CustomerId(entityId)); | |
106 | + break; | |
107 | + case RULE: | |
108 | + event.setEntityId(new RuleId(entityId)); | |
109 | + break; | |
110 | + case PLUGIN: | |
111 | + event.setEntityId(new PluginId(entityId)); | |
112 | + break; | |
113 | + } | |
114 | + event.setBody(body); | |
115 | + event.setType(eventType); | |
116 | + event.setUid(eventUId); | |
117 | + return event; | |
118 | + } | |
119 | +} | ... | ... |