Commit d6965e946955a49a91960fa0e454a798e9b7b271
1 parent
68ad4445
Refactoring to introduce new DAO layer
Showing
73 changed files
with
668 additions
and
950 deletions
@@ -21,34 +21,29 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; | @@ -21,34 +21,29 @@ import com.datastax.driver.core.querybuilder.QueryBuilder; | ||
21 | import com.datastax.driver.core.querybuilder.Select; | 21 | import com.datastax.driver.core.querybuilder.Select; |
22 | import com.datastax.driver.core.querybuilder.Select.Where; | 22 | import com.datastax.driver.core.querybuilder.Select.Where; |
23 | import com.datastax.driver.core.utils.UUIDs; | 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 | import org.thingsboard.server.common.data.page.TimePageLink; | 24 | import org.thingsboard.server.common.data.page.TimePageLink; |
27 | import org.thingsboard.server.dao.model.BaseEntity; | 25 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | import org.thingsboard.server.dao.model.ModelConstants; | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | -import org.thingsboard.server.dao.model.SearchTextEntity; | ||
30 | 27 | ||
31 | import java.util.ArrayList; | 28 | import java.util.ArrayList; |
32 | import java.util.Collections; | 29 | import java.util.Collections; |
33 | import java.util.List; | 30 | import java.util.List; |
34 | import java.util.UUID; | 31 | import java.util.UUID; |
35 | 32 | ||
36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
37 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 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 AbstractSearchTimeDao<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 | return findPageWithTimeSearch(searchView, clauses, Collections.emptyList(), pageLink); | 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 | return findPageWithTimeSearch(searchView, clauses, Collections.singletonList(ordering), pageLink); | 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 | Select select = select().from(searchView); | 47 | Select select = select().from(searchView); |
53 | Where query = select.where(); | 48 | Where query = select.where(); |
54 | for (Clause clause : clauses) { | 49 | for (Clause clause : clauses) { |
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,7 +23,7 @@ import java.util.concurrent.Executors; | ||
23 | /** | 23 | /** |
24 | * Created by ashvayka on 21.02.17. | 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 | protected ExecutorService readResultsProcessingExecutor; | 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,7 +23,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster; | ||
23 | import org.thingsboard.server.dao.model.type.*; | 23 | import org.thingsboard.server.dao.model.type.*; |
24 | 24 | ||
25 | @Slf4j | 25 | @Slf4j |
26 | -public abstract class AbstractDao { | 26 | +public abstract class CassandraAbstractDao { |
27 | 27 | ||
28 | @Autowired | 28 | @Autowired |
29 | protected CassandraCluster cluster; | 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,8 @@ import com.google.common.util.concurrent.Futures; | @@ -28,8 +28,8 @@ import com.google.common.util.concurrent.Futures; | ||
28 | import com.google.common.util.concurrent.ListenableFuture; | 28 | import com.google.common.util.concurrent.ListenableFuture; |
29 | import lombok.extern.slf4j.Slf4j; | 29 | import lombok.extern.slf4j.Slf4j; |
30 | import org.thingsboard.server.dao.model.BaseEntity; | 30 | import org.thingsboard.server.dao.model.BaseEntity; |
31 | -import org.thingsboard.server.dao.model.wrapper.EntityResultSet; | ||
32 | import org.thingsboard.server.dao.model.ModelConstants; | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | +import org.thingsboard.server.dao.model.wrapper.EntityResultSet; | ||
33 | 33 | ||
34 | import javax.annotation.Nullable; | 34 | import javax.annotation.Nullable; |
35 | import java.util.Collections; | 35 | import java.util.Collections; |
@@ -37,26 +37,25 @@ import java.util.List; | @@ -37,26 +37,25 @@ import java.util.List; | ||
37 | import java.util.UUID; | 37 | import java.util.UUID; |
38 | 38 | ||
39 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 39 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
40 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.lt; | ||
41 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 40 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
42 | 41 | ||
43 | @Slf4j | 42 | @Slf4j |
44 | -public abstract class AbstractModelDao<T extends BaseEntity<?>> extends AbstractDao implements Dao<T> { | 43 | +public abstract class CassandraAbstractModelDao<E extends BaseEntity<D>, D> extends CassandraAbstractDao implements Dao<D> { |
45 | 44 | ||
46 | - protected abstract Class<T> getColumnFamilyClass(); | 45 | + protected abstract Class<E> getColumnFamilyClass(); |
47 | 46 | ||
48 | protected abstract String getColumnFamilyName(); | 47 | protected abstract String getColumnFamilyName(); |
49 | 48 | ||
50 | - protected Mapper<T> getMapper() { | 49 | + protected Mapper<E> getMapper() { |
51 | return cluster.getMapper(getColumnFamilyClass()); | 50 | return cluster.getMapper(getColumnFamilyClass()); |
52 | } | 51 | } |
53 | 52 | ||
54 | - protected List<T> findListByStatement(Statement statement) { | ||
55 | - List<T> list = Collections.emptyList(); | 53 | + protected List<E> findListByStatement(Statement statement) { |
54 | + List<E> list = Collections.emptyList(); | ||
56 | if (statement != null) { | 55 | if (statement != null) { |
57 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); | 56 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
58 | ResultSet resultSet = getSession().execute(statement); | 57 | ResultSet resultSet = getSession().execute(statement); |
59 | - Result<T> result = getMapper().map(resultSet); | 58 | + Result<E> result = getMapper().map(resultSet); |
60 | if (result != null) { | 59 | if (result != null) { |
61 | list = result.all(); | 60 | list = result.all(); |
62 | } | 61 | } |
@@ -64,33 +63,33 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | @@ -64,33 +63,33 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | ||
64 | return list; | 63 | return list; |
65 | } | 64 | } |
66 | 65 | ||
67 | - protected ListenableFuture<List<T>> findListByStatementAsync(Statement statement) { | 66 | + protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) { |
68 | if (statement != null) { | 67 | if (statement != null) { |
69 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); | 68 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
70 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); | 69 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); |
71 | - ListenableFuture<List<T>> result = Futures.transform(resultSetFuture, new Function<ResultSet, List<T>>() { | 70 | + return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() { |
72 | @Nullable | 71 | @Nullable |
73 | @Override | 72 | @Override |
74 | - public List<T> apply(@Nullable ResultSet resultSet) { | ||
75 | - Result<T> result = getMapper().map(resultSet); | 73 | + public List<D> apply(@Nullable ResultSet resultSet) { |
74 | + Result<E> result = getMapper().map(resultSet); | ||
76 | if (result != null) { | 75 | if (result != null) { |
77 | - return result.all(); | 76 | + List<E> entities = result.all(); |
77 | + return DaoUtil.convertDataList(entities); | ||
78 | } else { | 78 | } else { |
79 | return Collections.emptyList(); | 79 | return Collections.emptyList(); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | }); | 82 | }); |
83 | - return result; | ||
84 | } | 83 | } |
85 | return Futures.immediateFuture(Collections.emptyList()); | 84 | return Futures.immediateFuture(Collections.emptyList()); |
86 | } | 85 | } |
87 | 86 | ||
88 | - protected T findOneByStatement(Statement statement) { | ||
89 | - T object = null; | 87 | + protected E findOneByStatement(Statement statement) { |
88 | + E object = null; | ||
90 | if (statement != null) { | 89 | if (statement != null) { |
91 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); | 90 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
92 | ResultSet resultSet = getSession().execute(statement); | 91 | ResultSet resultSet = getSession().execute(statement); |
93 | - Result<T> result = getMapper().map(resultSet); | 92 | + Result<E> result = getMapper().map(resultSet); |
94 | if (result != null) { | 93 | if (result != null) { |
95 | object = result.one(); | 94 | object = result.one(); |
96 | } | 95 | } |
@@ -98,32 +97,32 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | @@ -98,32 +97,32 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | ||
98 | return object; | 97 | return object; |
99 | } | 98 | } |
100 | 99 | ||
101 | - protected ListenableFuture<T> findOneByStatementAsync(Statement statement) { | 100 | + protected ListenableFuture<D> findOneByStatementAsync(Statement statement) { |
102 | if (statement != null) { | 101 | if (statement != null) { |
103 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); | 102 | statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
104 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); | 103 | ResultSetFuture resultSetFuture = getSession().executeAsync(statement); |
105 | - ListenableFuture<T> result = Futures.transform(resultSetFuture, new Function<ResultSet, T>() { | 104 | + return Futures.transform(resultSetFuture, new Function<ResultSet, D>() { |
106 | @Nullable | 105 | @Nullable |
107 | @Override | 106 | @Override |
108 | - public T apply(@Nullable ResultSet resultSet) { | ||
109 | - Result<T> result = getMapper().map(resultSet); | 107 | + public D apply(@Nullable ResultSet resultSet) { |
108 | + Result<E> result = getMapper().map(resultSet); | ||
110 | if (result != null) { | 109 | if (result != null) { |
111 | - return result.one(); | 110 | + E entity = result.one(); |
111 | + return DaoUtil.getData(entity); | ||
112 | } else { | 112 | } else { |
113 | return null; | 113 | return null; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | }); | 116 | }); |
117 | - return result; | ||
118 | } | 117 | } |
119 | return Futures.immediateFuture(null); | 118 | return Futures.immediateFuture(null); |
120 | } | 119 | } |
121 | 120 | ||
122 | - protected Statement getSaveQuery(T dto) { | 121 | + protected Statement getSaveQuery(E dto) { |
123 | return getMapper().saveQuery(dto); | 122 | return getMapper().saveQuery(dto); |
124 | } | 123 | } |
125 | 124 | ||
126 | - protected EntityResultSet<T> saveWithResult(T entity) { | 125 | + protected EntityResultSet<E> saveWithResult(E entity) { |
127 | log.debug("Save entity {}", entity); | 126 | log.debug("Save entity {}", entity); |
128 | if (entity.getId() == null) { | 127 | if (entity.getId() == null) { |
129 | entity.setId(UUIDs.timeBased()); | 128 | entity.setId(UUIDs.timeBased()); |
@@ -136,34 +135,48 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | @@ -136,34 +135,48 @@ public abstract class AbstractModelDao<T extends BaseEntity<?>> extends Abstract | ||
136 | return new EntityResultSet<>(resultSet, entity); | 135 | return new EntityResultSet<>(resultSet, entity); |
137 | } | 136 | } |
138 | 137 | ||
139 | - public T save(T entity) { | ||
140 | - return saveWithResult(entity).getEntity(); | 138 | + @Override |
139 | + public D save(D domain) { | ||
140 | + E entity; | ||
141 | + try { | ||
142 | + entity = getColumnFamilyClass().getConstructor(domain.getClass()).newInstance(domain); | ||
143 | + } catch (Exception e) { | ||
144 | + log.error("Can't create entity for domain object {}", domain, e); | ||
145 | + throw new IllegalArgumentException("Can't create entity for domain object {" + domain + "}", e); | ||
146 | + } | ||
147 | + log.debug("Saving entity {}", entity); | ||
148 | + entity = saveWithResult(entity).getEntity(); | ||
149 | + return DaoUtil.getData(entity); | ||
141 | } | 150 | } |
142 | 151 | ||
143 | - public T findById(UUID key) { | 152 | + @Override |
153 | + public D findById(UUID key) { | ||
144 | log.debug("Get entity by key {}", key); | 154 | log.debug("Get entity by key {}", key); |
145 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); | 155 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
146 | log.trace("Execute query {}", query); | 156 | log.trace("Execute query {}", query); |
147 | - return findOneByStatement(query); | 157 | + E entity = findOneByStatement(query); |
158 | + return DaoUtil.getData(entity); | ||
148 | } | 159 | } |
149 | 160 | ||
150 | - public ListenableFuture<T> findByIdAsync(UUID key) { | 161 | + @Override |
162 | + public ListenableFuture<D> findByIdAsync(UUID key) { | ||
151 | log.debug("Get entity by key {}", key); | 163 | log.debug("Get entity by key {}", key); |
152 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); | 164 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
153 | log.trace("Execute query {}", query); | 165 | log.trace("Execute query {}", query); |
154 | return findOneByStatementAsync(query); | 166 | return findOneByStatementAsync(query); |
155 | } | 167 | } |
156 | 168 | ||
157 | - | ||
158 | - public ResultSet removeById(UUID key) { | 169 | + @Override |
170 | + public boolean removeById(UUID key) { | ||
159 | Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); | 171 | Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, key)); |
160 | log.debug("Remove request: {}", delete.toString()); | 172 | log.debug("Remove request: {}", delete.toString()); |
161 | - return getSession().execute(delete); | 173 | + return getSession().execute(delete).wasApplied(); |
162 | } | 174 | } |
163 | 175 | ||
164 | - | ||
165 | - public List<T> find() { | 176 | + @Override |
177 | + public List<D> find() { | ||
166 | log.debug("Get all entities from column family {}", getColumnFamilyName()); | 178 | log.debug("Get all entities from column family {}", getColumnFamilyName()); |
167 | - return findListByStatement(QueryBuilder.select().all().from(getColumnFamilyName()).setConsistencyLevel(cluster.getDefaultReadConsistencyLevel())); | 179 | + List<E> entities = findListByStatement(QueryBuilder.select().all().from(getColumnFamilyName()).setConsistencyLevel(cluster.getDefaultReadConsistencyLevel())); |
180 | + return DaoUtil.convertDataList(entities); | ||
168 | } | 181 | } |
169 | } | 182 | } |
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,28 @@ import com.datastax.driver.core.querybuilder.Clause; | @@ -19,27 +19,28 @@ import com.datastax.driver.core.querybuilder.Clause; | ||
19 | import com.datastax.driver.core.querybuilder.QueryBuilder; | 19 | import com.datastax.driver.core.querybuilder.QueryBuilder; |
20 | import com.datastax.driver.core.querybuilder.Select; | 20 | import com.datastax.driver.core.querybuilder.Select; |
21 | import com.datastax.driver.core.querybuilder.Select.Where; | 21 | import com.datastax.driver.core.querybuilder.Select.Where; |
22 | +import lombok.extern.slf4j.Slf4j; | ||
22 | import org.apache.commons.lang3.StringUtils; | 23 | import org.apache.commons.lang3.StringUtils; |
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 24 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | -import org.thingsboard.server.dao.model.SearchTextEntity; | ||
25 | import org.thingsboard.server.dao.model.ModelConstants; | 25 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | +import org.thingsboard.server.dao.model.SearchTextEntity; | ||
26 | 27 | ||
27 | import java.util.List; | 28 | import java.util.List; |
28 | 29 | ||
29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 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 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 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> { | ||
35 | + | ||
36 | + public D save(D domain) { | ||
36 | 37 | ||
37 | - public T save(T entity) { | ||
38 | entity.setSearchText(entity.getSearchTextSource().toLowerCase()); | 38 | entity.setSearchText(entity.getSearchTextSource().toLowerCase()); |
39 | + | ||
39 | return super.save(entity); | 40 | return super.save(entity); |
40 | } | 41 | } |
41 | - | ||
42 | - protected List<T> findPageWithTextSearch(String searchView, List<Clause> clauses, TextPageLink pageLink) { | 42 | + |
43 | + protected List<E> findPageWithTextSearch(String searchView, List<Clause> clauses, TextPageLink pageLink) { | ||
43 | Select select = select().from(searchView); | 44 | Select select = select().from(searchView); |
44 | Where query = select.where(); | 45 | Where query = select.where(); |
45 | for (Clause clause : clauses) { | 46 | for (Clause clause : clauses) { |
@@ -49,7 +50,7 @@ public abstract class AbstractSearchTextDao<T extends SearchTextEntity<?>> exten | @@ -49,7 +50,7 @@ public abstract class AbstractSearchTextDao<T extends SearchTextEntity<?>> exten | ||
49 | if (!StringUtils.isEmpty(pageLink.getTextOffset())) { | 50 | if (!StringUtils.isEmpty(pageLink.getTextOffset())) { |
50 | query.and(eq(ModelConstants.SEARCH_TEXT_PROPERTY, pageLink.getTextOffset())); | 51 | query.and(eq(ModelConstants.SEARCH_TEXT_PROPERTY, pageLink.getTextOffset())); |
51 | query.and(QueryBuilder.lt(ModelConstants.ID_PROPERTY, pageLink.getIdOffset())); | 52 | query.and(QueryBuilder.lt(ModelConstants.ID_PROPERTY, pageLink.getIdOffset())); |
52 | - List<T> result = findListByStatement(query); | 53 | + List<E> result = findListByStatement(query); |
53 | if (result.size() < pageLink.getLimit()) { | 54 | if (result.size() < pageLink.getLimit()) { |
54 | select = select().from(searchView); | 55 | select = select().from(searchView); |
55 | query = select.where(); | 56 | query = select.where(); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao; | 16 | package org.thingsboard.server.dao; |
17 | 17 | ||
18 | -import com.datastax.driver.core.ResultSet; | ||
19 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
20 | 19 | ||
21 | import java.util.List; | 20 | import java.util.List; |
@@ -31,6 +30,6 @@ public interface Dao<T> { | @@ -31,6 +30,6 @@ public interface Dao<T> { | ||
31 | 30 | ||
32 | T save(T t); | 31 | T save(T t); |
33 | 32 | ||
34 | - ResultSet removeById(UUID id); | 33 | + boolean removeById(UUID id); |
35 | 34 | ||
36 | } | 35 | } |
@@ -15,15 +15,11 @@ | @@ -15,15 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao; | 16 | package org.thingsboard.server.dao; |
17 | 17 | ||
18 | -import java.util.ArrayList; | ||
19 | -import java.util.Collection; | ||
20 | -import java.util.Collections; | ||
21 | -import java.util.List; | ||
22 | -import java.util.UUID; | ||
23 | - | ||
24 | import org.thingsboard.server.common.data.id.UUIDBased; | 18 | import org.thingsboard.server.common.data.id.UUIDBased; |
25 | import org.thingsboard.server.dao.model.ToData; | 19 | import org.thingsboard.server.dao.model.ToData; |
26 | 20 | ||
21 | +import java.util.*; | ||
22 | + | ||
27 | public abstract class DaoUtil { | 23 | public abstract class DaoUtil { |
28 | 24 | ||
29 | private DaoUtil() { | 25 | private DaoUtil() { |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao; | 16 | package org.thingsboard.server.dao; |
17 | 17 | ||
18 | -import com.google.common.base.CharMatcher; | ||
19 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
20 | import org.bouncycastle.crypto.digests.SHA3Digest; | 19 | import org.bouncycastle.crypto.digests.SHA3Digest; |
21 | import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; | 20 | import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.attributes; | 16 | package org.thingsboard.server.dao.attributes; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSet; | 19 | import com.datastax.driver.core.ResultSet; |
19 | import com.datastax.driver.core.ResultSetFuture; | 20 | import com.datastax.driver.core.ResultSetFuture; |
20 | import com.google.common.util.concurrent.ListenableFuture; | 21 | import com.google.common.util.concurrent.ListenableFuture; |
@@ -15,12 +15,10 @@ | @@ -15,12 +15,10 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.attributes; | 16 | package org.thingsboard.server.dao.attributes; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSet; | 19 | import com.datastax.driver.core.ResultSet; |
19 | -import com.datastax.driver.core.ResultSetFuture; | ||
20 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
21 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
22 | import org.thingsboard.server.common.data.id.EntityId; | 21 | import org.thingsboard.server.common.data.id.EntityId; |
23 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 22 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | 23 | ||
26 | import java.util.Collection; | 24 | import java.util.Collection; |
@@ -15,16 +15,17 @@ | @@ -15,16 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.attributes; | 16 | package org.thingsboard.server.dao.attributes; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSet; | 19 | import com.datastax.driver.core.ResultSet; |
19 | import com.datastax.driver.core.ResultSetFuture; | 20 | import com.datastax.driver.core.ResultSetFuture; |
20 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
21 | import com.google.common.util.concurrent.Futures; | 22 | import com.google.common.util.concurrent.Futures; |
22 | import com.google.common.util.concurrent.ListenableFuture; | 23 | import com.google.common.util.concurrent.ListenableFuture; |
24 | +import org.springframework.beans.factory.annotation.Autowired; | ||
25 | +import org.springframework.stereotype.Service; | ||
23 | import org.thingsboard.server.common.data.id.EntityId; | 26 | import org.thingsboard.server.common.data.id.EntityId; |
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 27 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 28 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
26 | -import org.springframework.beans.factory.annotation.Autowired; | ||
27 | -import org.springframework.stereotype.Service; | ||
28 | import org.thingsboard.server.dao.service.Validator; | 29 | import org.thingsboard.server.dao.service.Validator; |
29 | 30 | ||
30 | import java.util.Collection; | 31 | 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,10 +24,11 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
24 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
25 | import org.springframework.stereotype.Component; | 25 | import org.springframework.stereotype.Component; |
26 | import org.thingsboard.server.common.data.id.EntityId; | 26 | import org.thingsboard.server.common.data.id.EntityId; |
27 | -import org.thingsboard.server.dao.AbstractAsyncDao; | 27 | +import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
28 | +import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | ||
29 | +import org.thingsboard.server.dao.CassandraAbstractAsyncDao; | ||
28 | import org.thingsboard.server.dao.model.ModelConstants; | 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 | import javax.annotation.PostConstruct; | 33 | import javax.annotation.PostConstruct; |
33 | import javax.annotation.PreDestroy; | 34 | import javax.annotation.PreDestroy; |
@@ -37,15 +38,16 @@ import java.util.List; | @@ -37,15 +38,16 @@ import java.util.List; | ||
37 | import java.util.Optional; | 38 | import java.util.Optional; |
38 | import java.util.stream.Collectors; | 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 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 43 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
41 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | ||
42 | 44 | ||
43 | /** | 45 | /** |
44 | * @author Andrew Shvayka | 46 | * @author Andrew Shvayka |
45 | */ | 47 | */ |
46 | @Component | 48 | @Component |
47 | @Slf4j | 49 | @Slf4j |
48 | -public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao { | 50 | +public class CassandraBaseAttributesDao extends CassandraAbstractAsyncDao implements AttributesDao { |
49 | 51 | ||
50 | private PreparedStatement saveStmt; | 52 | private PreparedStatement saveStmt; |
51 | 53 | ||
@@ -161,7 +163,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao | @@ -161,7 +163,7 @@ public class BaseAttributesDao extends AbstractAsyncDao implements AttributesDao | ||
161 | AttributeKvEntry attributeEntry = null; | 163 | AttributeKvEntry attributeEntry = null; |
162 | if (row != null) { | 164 | if (row != null) { |
163 | long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class); | 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 | return attributeEntry; | 168 | return attributeEntry; |
167 | } | 169 | } |
@@ -16,13 +16,8 @@ | @@ -16,13 +16,8 @@ | ||
16 | package org.thingsboard.server.dao.cassandra; | 16 | package org.thingsboard.server.dao.cassandra; |
17 | 17 | ||
18 | 18 | ||
19 | -import com.datastax.driver.core.Cluster; | ||
20 | -import com.datastax.driver.core.ConsistencyLevel; | ||
21 | -import com.datastax.driver.core.HostDistance; | ||
22 | -import com.datastax.driver.core.PoolingOptions; | 19 | +import com.datastax.driver.core.*; |
23 | import com.datastax.driver.core.ProtocolOptions.Compression; | 20 | import com.datastax.driver.core.ProtocolOptions.Compression; |
24 | -import com.datastax.driver.core.Session; | ||
25 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | ||
26 | import com.datastax.driver.mapping.Mapper; | 21 | import com.datastax.driver.mapping.Mapper; |
27 | import com.datastax.driver.mapping.MappingManager; | 22 | import com.datastax.driver.mapping.MappingManager; |
28 | import lombok.Data; | 23 | import lombok.Data; |
@@ -31,16 +26,13 @@ import org.apache.commons.lang3.StringUtils; | @@ -31,16 +26,13 @@ import org.apache.commons.lang3.StringUtils; | ||
31 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
32 | import org.springframework.beans.factory.annotation.Value; | 27 | import org.springframework.beans.factory.annotation.Value; |
33 | import org.springframework.stereotype.Component; | 28 | import org.springframework.stereotype.Component; |
34 | -import org.thingsboard.server.dao.exception.DatabaseException; | ||
35 | 29 | ||
36 | import javax.annotation.PostConstruct; | 30 | import javax.annotation.PostConstruct; |
37 | import javax.annotation.PreDestroy; | 31 | import javax.annotation.PreDestroy; |
38 | -import java.io.Closeable; | ||
39 | import java.net.InetSocketAddress; | 32 | import java.net.InetSocketAddress; |
40 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
41 | import java.util.Collections; | 34 | import java.util.Collections; |
42 | import java.util.List; | 35 | import java.util.List; |
43 | -import java.util.StringTokenizer; | ||
44 | 36 | ||
45 | @Component | 37 | @Component |
46 | @Slf4j | 38 | @Slf4j |
@@ -21,12 +21,9 @@ import lombok.Data; | @@ -21,12 +21,9 @@ import lombok.Data; | ||
21 | import org.springframework.beans.factory.annotation.Value; | 21 | import org.springframework.beans.factory.annotation.Value; |
22 | import org.springframework.context.annotation.Configuration; | 22 | import org.springframework.context.annotation.Configuration; |
23 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
24 | -import org.springframework.util.StringUtils; | ||
25 | 24 | ||
26 | import javax.annotation.PostConstruct; | 25 | import javax.annotation.PostConstruct; |
27 | 26 | ||
28 | -import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
29 | - | ||
30 | @Component | 27 | @Component |
31 | @Configuration | 28 | @Configuration |
32 | @Data | 29 | @Data |
@@ -15,13 +15,12 @@ | @@ -15,13 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.cassandra; | 16 | package org.thingsboard.server.dao.cassandra; |
17 | 17 | ||
18 | +import com.datastax.driver.core.SocketOptions; | ||
18 | import lombok.Data; | 19 | import lombok.Data; |
19 | import org.springframework.beans.factory.annotation.Value; | 20 | import org.springframework.beans.factory.annotation.Value; |
20 | import org.springframework.context.annotation.Configuration; | 21 | import org.springframework.context.annotation.Configuration; |
21 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
22 | 23 | ||
23 | -import com.datastax.driver.core.SocketOptions; | ||
24 | - | ||
25 | import javax.annotation.PostConstruct; | 24 | import javax.annotation.PostConstruct; |
26 | 25 | ||
27 | @Component | 26 | @Component |
@@ -27,9 +27,10 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -27,9 +27,10 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
27 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 27 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
28 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 28 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
29 | import org.thingsboard.server.common.data.plugin.ComponentType; | 29 | import org.thingsboard.server.common.data.plugin.ComponentType; |
30 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | ||
31 | -import org.thingsboard.server.dao.model.ModelConstants; | 30 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
31 | +import org.thingsboard.server.dao.DaoUtil; | ||
32 | import org.thingsboard.server.dao.model.ComponentDescriptorEntity; | 32 | import org.thingsboard.server.dao.model.ComponentDescriptorEntity; |
33 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
33 | 34 | ||
34 | import java.util.Arrays; | 35 | import java.util.Arrays; |
35 | import java.util.List; | 36 | import java.util.List; |
@@ -44,7 +45,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | @@ -44,7 +45,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
44 | */ | 45 | */ |
45 | @Component | 46 | @Component |
46 | @Slf4j | 47 | @Slf4j |
47 | -public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentDescriptorEntity> implements ComponentDescriptorDao { | 48 | +public class BaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao { |
48 | 49 | ||
49 | @Override | 50 | @Override |
50 | protected Class<ComponentDescriptorEntity> getColumnFamilyClass() { | 51 | protected Class<ComponentDescriptorEntity> getColumnFamilyClass() { |
@@ -57,10 +58,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -57,10 +58,10 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
57 | } | 58 | } |
58 | 59 | ||
59 | @Override | 60 | @Override |
60 | - public Optional<ComponentDescriptorEntity> save(ComponentDescriptor component) { | 61 | + public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) { |
61 | ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component); | 62 | ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component); |
62 | log.debug("Save component entity [{}]", entity); | 63 | log.debug("Save component entity [{}]", entity); |
63 | - Optional<ComponentDescriptorEntity> result = saveIfNotExist(entity); | 64 | + Optional<ComponentDescriptor> result = saveIfNotExist(entity); |
64 | if (log.isTraceEnabled()) { | 65 | if (log.isTraceEnabled()) { |
65 | log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null)); | 66 | log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null)); |
66 | } else { | 67 | } else { |
@@ -70,19 +71,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -70,19 +71,19 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
70 | } | 71 | } |
71 | 72 | ||
72 | @Override | 73 | @Override |
73 | - public ComponentDescriptorEntity findById(ComponentDescriptorId componentId) { | 74 | + public ComponentDescriptor findById(ComponentDescriptorId componentId) { |
74 | log.debug("Search component entity by id [{}]", componentId); | 75 | log.debug("Search component entity by id [{}]", componentId); |
75 | - ComponentDescriptorEntity entity = super.findById(componentId.getId()); | 76 | + ComponentDescriptor componentDescriptor = super.findById(componentId.getId()); |
76 | if (log.isTraceEnabled()) { | 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 | } else { | 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 | @Override | 85 | @Override |
85 | - public ComponentDescriptorEntity findByClazz(String clazz) { | 86 | + public ComponentDescriptor findByClazz(String clazz) { |
86 | log.debug("Search component entity by clazz [{}]", clazz); | 87 | log.debug("Search component entity by clazz [{}]", clazz); |
87 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); | 88 | Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); |
88 | log.trace("Execute query [{}]", query); | 89 | log.trace("Execute query [{}]", query); |
@@ -92,11 +93,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -92,11 +93,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
92 | } else { | 93 | } else { |
93 | log.debug("Search result: [{}]", entity != null); | 94 | log.debug("Search result: [{}]", entity != null); |
94 | } | 95 | } |
95 | - return entity; | 96 | + return DaoUtil.getData(entity); |
96 | } | 97 | } |
97 | 98 | ||
98 | @Override | 99 | @Override |
99 | - public List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { | 100 | + public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { |
100 | log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink); | 101 | log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink); |
101 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 102 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
102 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name())), pageLink); | 103 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name())), pageLink); |
@@ -105,11 +106,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -105,11 +106,11 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
105 | } else { | 106 | } else { |
106 | log.debug("Search result: [{}]", entities.size()); | 107 | log.debug("Search result: [{}]", entities.size()); |
107 | } | 108 | } |
108 | - return entities; | 109 | + return DaoUtil.convertDataList(entities); |
109 | } | 110 | } |
110 | 111 | ||
111 | @Override | 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 | log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink); | 114 | log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink); |
114 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 115 | List<ComponentDescriptorEntity> entities = findPageWithTextSearch(ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
115 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name()), | 116 | Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type.name()), |
@@ -119,20 +120,20 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -119,20 +120,20 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
119 | } else { | 120 | } else { |
120 | log.debug("Search result: [{}]", entities.size()); | 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 | Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key)); | 127 | Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key)); |
127 | log.debug("Remove request: {}", delete.toString()); | 128 | log.debug("Remove request: {}", delete.toString()); |
128 | - return getSession().execute(delete); | 129 | + return getSession().execute(delete).wasApplied(); |
129 | } | 130 | } |
130 | 131 | ||
131 | @Override | 132 | @Override |
132 | public void deleteById(ComponentDescriptorId id) { | 133 | public void deleteById(ComponentDescriptorId id) { |
133 | log.debug("Delete plugin meta-data entity by id [{}]", id); | 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 | @Override | 139 | @Override |
@@ -144,7 +145,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -144,7 +145,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
144 | log.debug("Delete result: [{}]", resultSet.wasApplied()); | 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 | if (entity.getId() == null) { | 149 | if (entity.getId() == null) { |
149 | entity.setId(UUIDs.timeBased()); | 150 | entity.setId(UUIDs.timeBased()); |
150 | } | 151 | } |
@@ -161,7 +162,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | @@ -161,7 +162,7 @@ public class BaseComponentDescriptorDao extends AbstractSearchTextDao<ComponentD | ||
161 | .ifNotExists() | 162 | .ifNotExists() |
162 | ); | 163 | ); |
163 | if (rs.wasApplied()) { | 164 | if (rs.wasApplied()) { |
164 | - return Optional.of(entity); | 165 | + return Optional.of(DaoUtil.getData(entity)); |
165 | } else { | 166 | } else { |
166 | return Optional.empty(); | 167 | return Optional.empty(); |
167 | } | 168 | } |
@@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope; | @@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope; | ||
32 | import org.thingsboard.server.common.data.plugin.ComponentType; | 32 | import org.thingsboard.server.common.data.plugin.ComponentType; |
33 | import org.thingsboard.server.dao.exception.DataValidationException; | 33 | import org.thingsboard.server.dao.exception.DataValidationException; |
34 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 34 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
35 | -import org.thingsboard.server.dao.model.ComponentDescriptorEntity; | ||
36 | import org.thingsboard.server.dao.service.DataValidator; | 35 | import org.thingsboard.server.dao.service.DataValidator; |
37 | import org.thingsboard.server.dao.service.Validator; | 36 | import org.thingsboard.server.dao.service.Validator; |
38 | 37 | ||
39 | import java.util.List; | 38 | import java.util.List; |
40 | import java.util.Optional; | 39 | import java.util.Optional; |
41 | 40 | ||
42 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
43 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
44 | - | ||
45 | /** | 41 | /** |
46 | * @author Andrew Shvayka | 42 | * @author Andrew Shvayka |
47 | */ | 43 | */ |
@@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic | @@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic | ||
55 | @Override | 51 | @Override |
56 | public ComponentDescriptor saveComponent(ComponentDescriptor component) { | 52 | public ComponentDescriptor saveComponent(ComponentDescriptor component) { |
57 | componentValidator.validate(component); | 53 | componentValidator.validate(component); |
58 | - Optional<ComponentDescriptorEntity> result = componentDescriptorDao.save(component); | 54 | + Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(component); |
59 | if (result.isPresent()) { | 55 | if (result.isPresent()) { |
60 | - return getData(result.get()); | 56 | + return result.get(); |
61 | } else { | 57 | } else { |
62 | - return getData(componentDescriptorDao.findByClazz(component.getClazz())); | 58 | + return componentDescriptorDao.findByClazz(component.getClazz()); |
63 | } | 59 | } |
64 | } | 60 | } |
65 | 61 | ||
66 | @Override | 62 | @Override |
67 | public ComponentDescriptor findById(ComponentDescriptorId componentId) { | 63 | public ComponentDescriptor findById(ComponentDescriptorId componentId) { |
68 | Validator.validateId(componentId, "Incorrect component id for search request."); | 64 | Validator.validateId(componentId, "Incorrect component id for search request."); |
69 | - return getData(componentDescriptorDao.findById(componentId)); | 65 | + return componentDescriptorDao.findById(componentId); |
70 | } | 66 | } |
71 | 67 | ||
72 | @Override | 68 | @Override |
73 | public ComponentDescriptor findByClazz(String clazz) { | 69 | public ComponentDescriptor findByClazz(String clazz) { |
74 | Validator.validateString(clazz, "Incorrect clazz for search request."); | 70 | Validator.validateString(clazz, "Incorrect clazz for search request."); |
75 | - return getData(componentDescriptorDao.findByClazz(clazz)); | 71 | + return componentDescriptorDao.findByClazz(clazz); |
76 | } | 72 | } |
77 | 73 | ||
78 | @Override | 74 | @Override |
79 | public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { | 75 | public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { |
80 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); | 76 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); |
81 | - List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByTypeAndPageLink(type, pageLink); | ||
82 | - List<ComponentDescriptor> components = convertDataList(pluginEntities); | 77 | + List<ComponentDescriptor> components = componentDescriptorDao.findByTypeAndPageLink(type, pageLink); |
83 | return new TextPageData<>(components, pageLink); | 78 | return new TextPageData<>(components, pageLink); |
84 | } | 79 | } |
85 | 80 | ||
86 | @Override | 81 | @Override |
87 | public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { | 82 | public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) { |
88 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); | 83 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request."); |
89 | - List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink); | ||
90 | - List<ComponentDescriptor> components = convertDataList(pluginEntities); | 84 | + List<ComponentDescriptor> components = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink); |
91 | return new TextPageData<>(components, pageLink); | 85 | return new TextPageData<>(components, pageLink); |
92 | } | 86 | } |
93 | 87 |
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | ||
21 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 21 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
22 | import org.thingsboard.server.common.data.plugin.ComponentType; | 22 | import org.thingsboard.server.common.data.plugin.ComponentType; |
23 | import org.thingsboard.server.dao.Dao; | 23 | import org.thingsboard.server.dao.Dao; |
24 | -import org.thingsboard.server.dao.model.ComponentDescriptorEntity; | ||
25 | 24 | ||
26 | import java.util.List; | 25 | import java.util.List; |
27 | import java.util.Optional; | 26 | import java.util.Optional; |
@@ -29,17 +28,17 @@ import java.util.Optional; | @@ -29,17 +28,17 @@ import java.util.Optional; | ||
29 | /** | 28 | /** |
30 | * @author Andrew Shvayka | 29 | * @author Andrew Shvayka |
31 | */ | 30 | */ |
32 | -public interface ComponentDescriptorDao extends Dao<ComponentDescriptorEntity> { | 31 | +public interface ComponentDescriptorDao extends Dao<ComponentDescriptor> { |
33 | 32 | ||
34 | - Optional<ComponentDescriptorEntity> save(ComponentDescriptor component); | 33 | + Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component); |
35 | 34 | ||
36 | - ComponentDescriptorEntity findById(ComponentDescriptorId componentId); | 35 | + ComponentDescriptor findById(ComponentDescriptorId componentId); |
37 | 36 | ||
38 | - ComponentDescriptorEntity findByClazz(String clazz); | 37 | + ComponentDescriptor findByClazz(String clazz); |
39 | 38 | ||
40 | - List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink); | 39 | + List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink); |
41 | 40 | ||
42 | - List<ComponentDescriptorEntity> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink); | 41 | + List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink); |
43 | 42 | ||
44 | void deleteById(ComponentDescriptorId componentId); | 43 | void deleteById(ComponentDescriptorId componentId); |
45 | 44 |
dao/src/main/java/org/thingsboard/server/dao/customer/CassandraCustomerDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDaoImpl.java
@@ -15,24 +15,23 @@ | @@ -15,24 +15,23 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.customer; | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | - | ||
20 | -import java.util.Arrays; | ||
21 | -import java.util.List; | ||
22 | -import java.util.UUID; | ||
23 | - | ||
24 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
25 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
26 | import org.thingsboard.server.common.data.Customer; | 20 | import org.thingsboard.server.common.data.Customer; |
27 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
28 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
29 | import org.thingsboard.server.dao.model.CustomerEntity; | 24 | import org.thingsboard.server.dao.model.CustomerEntity; |
30 | -import org.slf4j.Logger; | ||
31 | -import org.slf4j.LoggerFactory; | ||
32 | import org.thingsboard.server.dao.model.ModelConstants; | 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 | @Component | 32 | @Component |
34 | @Slf4j | 33 | @Slf4j |
35 | -public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> implements CustomerDao { | 34 | +public class CassandraCustomerDao extends CassandraAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao { |
36 | 35 | ||
37 | @Override | 36 | @Override |
38 | protected Class<CustomerEntity> getColumnFamilyClass() { | 37 | protected Class<CustomerEntity> getColumnFamilyClass() { |
@@ -43,21 +42,15 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple | @@ -43,21 +42,15 @@ public class CustomerDaoImpl extends AbstractSearchTextDao<CustomerEntity> imple | ||
43 | protected String getColumnFamilyName() { | 42 | protected String getColumnFamilyName() { |
44 | return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; | 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 | @Override | 46 | @Override |
54 | - public List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { | 47 | + public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { |
55 | log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 48 | log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
56 | List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 49 | List<CustomerEntity> customerEntities = findPageWithTextSearch(ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
57 | Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)), | 50 | Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)), |
58 | pageLink); | 51 | pageLink); |
59 | log.trace("Found customers [{}] by tenantId [{}] and pageLink [{}]", customerEntities, tenantId, pageLink); | 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,18 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.customer; | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | -import java.util.UUID; | ||
20 | - | ||
21 | import org.thingsboard.server.common.data.Customer; | 18 | import org.thingsboard.server.common.data.Customer; |
22 | import org.thingsboard.server.common.data.page.TextPageLink; | 19 | import org.thingsboard.server.common.data.page.TextPageLink; |
23 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
24 | -import org.thingsboard.server.dao.model.CustomerEntity; | 21 | + |
22 | +import java.util.List; | ||
23 | +import java.util.UUID; | ||
25 | 24 | ||
26 | /** | 25 | /** |
27 | * The Interface CustomerDao. | 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 | * Save or update customer object | 31 | * Save or update customer object |
@@ -34,7 +33,7 @@ public interface CustomerDao extends Dao<CustomerEntity> { | @@ -34,7 +33,7 @@ public interface CustomerDao extends Dao<CustomerEntity> { | ||
34 | * @param customer the customer object | 33 | * @param customer the customer object |
35 | * @return saved customer object | 34 | * @return saved customer object |
36 | */ | 35 | */ |
37 | - CustomerEntity save(Customer customer); | 36 | + Customer save(Customer customer); |
38 | 37 | ||
39 | /** | 38 | /** |
40 | * Find customers by tenant id and page link. | 39 | * Find customers by tenant id and page link. |
@@ -43,6 +42,6 @@ public interface CustomerDao extends Dao<CustomerEntity> { | @@ -43,6 +42,6 @@ public interface CustomerDao extends Dao<CustomerEntity> { | ||
43 | * @param pageLink the page link | 42 | * @param pageLink the page link |
44 | * @return the list of customer objects | 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,14 +23,14 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
23 | 23 | ||
24 | public interface CustomerService { | 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,14 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.customer; | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
19 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
20 | - | ||
21 | -import java.util.List; | ||
22 | - | ||
23 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
24 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
21 | +import org.springframework.stereotype.Service; | ||
25 | import org.thingsboard.server.common.data.Customer; | 22 | import org.thingsboard.server.common.data.Customer; |
23 | +import org.thingsboard.server.common.data.Tenant; | ||
26 | import org.thingsboard.server.common.data.id.CustomerId; | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.common.data.page.TextPageData; | 26 | import org.thingsboard.server.common.data.page.TextPageData; |
@@ -31,17 +29,13 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | @@ -31,17 +29,13 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | ||
31 | import org.thingsboard.server.dao.device.DeviceService; | 29 | import org.thingsboard.server.dao.device.DeviceService; |
32 | import org.thingsboard.server.dao.exception.DataValidationException; | 30 | import org.thingsboard.server.dao.exception.DataValidationException; |
33 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 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 | import org.thingsboard.server.dao.service.DataValidator; | 32 | import org.thingsboard.server.dao.service.DataValidator; |
37 | import org.thingsboard.server.dao.service.PaginatedRemover; | 33 | import org.thingsboard.server.dao.service.PaginatedRemover; |
34 | +import org.thingsboard.server.dao.service.Validator; | ||
38 | import org.thingsboard.server.dao.tenant.TenantDao; | 35 | import org.thingsboard.server.dao.tenant.TenantDao; |
39 | import org.thingsboard.server.dao.user.UserService; | 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 | @Service | 39 | @Service |
46 | @Slf4j | 40 | @Slf4j |
47 | public class CustomerServiceImpl implements CustomerService { | 41 | public class CustomerServiceImpl implements CustomerService { |
@@ -65,16 +59,14 @@ public class CustomerServiceImpl implements CustomerService { | @@ -65,16 +59,14 @@ public class CustomerServiceImpl implements CustomerService { | ||
65 | public Customer findCustomerById(CustomerId customerId) { | 59 | public Customer findCustomerById(CustomerId customerId) { |
66 | log.trace("Executing findCustomerById [{}]", customerId); | 60 | log.trace("Executing findCustomerById [{}]", customerId); |
67 | Validator.validateId(customerId, "Incorrect customerId " + customerId); | 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 | @Override | 65 | @Override |
73 | public Customer saveCustomer(Customer customer) { | 66 | public Customer saveCustomer(Customer customer) { |
74 | log.trace("Executing saveCustomer [{}]", customer); | 67 | log.trace("Executing saveCustomer [{}]", customer); |
75 | customerValidator.validate(customer); | 68 | customerValidator.validate(customer); |
76 | - CustomerEntity customerEntity = customerDao.save(customer); | ||
77 | - return getData(customerEntity); | 69 | + return customerDao.save(customer); |
78 | } | 70 | } |
79 | 71 | ||
80 | @Override | 72 | @Override |
@@ -96,8 +88,7 @@ public class CustomerServiceImpl implements CustomerService { | @@ -96,8 +88,7 @@ public class CustomerServiceImpl implements CustomerService { | ||
96 | log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 88 | log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
97 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 89 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
98 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 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 | return new TextPageData<Customer>(customers, pageLink); | 92 | return new TextPageData<Customer>(customers, pageLink); |
102 | } | 93 | } |
103 | 94 | ||
@@ -121,7 +112,7 @@ public class CustomerServiceImpl implements CustomerService { | @@ -121,7 +112,7 @@ public class CustomerServiceImpl implements CustomerService { | ||
121 | if (customer.getTenantId() == null) { | 112 | if (customer.getTenantId() == null) { |
122 | throw new DataValidationException("Customer should be assigned to tenant!"); | 113 | throw new DataValidationException("Customer should be assigned to tenant!"); |
123 | } else { | 114 | } else { |
124 | - TenantEntity tenant = tenantDao.findById(customer.getTenantId().getId()); | 115 | + Tenant tenant = tenantDao.findById(customer.getTenantId().getId()); |
125 | if (tenant == null) { | 116 | if (tenant == null) { |
126 | throw new DataValidationException("Customer is referencing to non-existent tenant!"); | 117 | throw new DataValidationException("Customer is referencing to non-existent tenant!"); |
127 | } | 118 | } |
@@ -129,17 +120,17 @@ public class CustomerServiceImpl implements CustomerService { | @@ -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 | @Override | 126 | @Override |
136 | - protected List<CustomerEntity> findEntities(TenantId id, TextPageLink pageLink) { | 127 | + protected List<Customer> findEntities(TenantId id, TextPageLink pageLink) { |
137 | return customerDao.findCustomersByTenantId(id.getId(), pageLink); | 128 | return customerDao.findCustomersByTenantId(id.getId(), pageLink); |
138 | } | 129 | } |
139 | 130 | ||
140 | @Override | 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,31 +15,15 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.dashboard; | 16 | package org.thingsboard.server.dao.dashboard; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; | ||
20 | -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; | ||
21 | -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; | ||
22 | -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY; | ||
23 | -import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY; | ||
24 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | ||
25 | - | ||
26 | -import java.util.Arrays; | ||
27 | -import java.util.List; | ||
28 | -import java.util.UUID; | ||
29 | - | ||
30 | -import lombok.extern.slf4j.Slf4j; | ||
31 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
32 | import org.thingsboard.server.common.data.Dashboard; | 19 | import org.thingsboard.server.common.data.Dashboard; |
33 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
34 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 20 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
35 | import org.thingsboard.server.dao.model.DashboardEntity; | 21 | 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; | 22 | + |
23 | +import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; | ||
39 | 24 | ||
40 | @Component | 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 | @Override | 28 | @Override |
45 | protected Class<DashboardEntity> getColumnFamilyClass() { | 29 | protected Class<DashboardEntity> getColumnFamilyClass() { |
@@ -50,11 +34,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp | @@ -50,11 +34,4 @@ public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> imp | ||
50 | protected String getColumnFamilyName() { | 34 | protected String getColumnFamilyName() { |
51 | return DASHBOARD_COLUMN_FAMILY_NAME; | 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,8 +17,10 @@ package org.thingsboard.server.dao.dashboard; | @@ -17,8 +17,10 @@ package org.thingsboard.server.dao.dashboard; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
20 | +import org.thingsboard.server.common.data.DashboardInfo; | ||
20 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
21 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
22 | import org.thingsboard.server.dao.model.DashboardInfoEntity; | 24 | import org.thingsboard.server.dao.model.DashboardInfoEntity; |
23 | 25 | ||
24 | import java.util.Arrays; | 26 | import java.util.Arrays; |
@@ -31,7 +33,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | @@ -31,7 +33,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
31 | 33 | ||
32 | @Component | 34 | @Component |
33 | @Slf4j | 35 | @Slf4j |
34 | -public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEntity> implements DashboardInfoDao { | 36 | +public class CassandraDashboardInfoDao extends CassandraAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { |
35 | 37 | ||
36 | @Override | 38 | @Override |
37 | protected Class<DashboardInfoEntity> getColumnFamilyClass() { | 39 | protected Class<DashboardInfoEntity> getColumnFamilyClass() { |
@@ -44,18 +46,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt | @@ -44,18 +46,18 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt | ||
44 | } | 46 | } |
45 | 47 | ||
46 | @Override | 48 | @Override |
47 | - public List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { | 49 | + public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { |
48 | log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 50 | log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
49 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 51 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
50 | Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)), | 52 | Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)), |
51 | pageLink); | 53 | pageLink); |
52 | 54 | ||
53 | log.trace("Found dashboards [{}] by tenantId [{}] and pageLink [{}]", dashboardEntities, tenantId, pageLink); | 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 | @Override | 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 | log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); | 61 | log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
60 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 62 | List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
61 | Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId), | 63 | Arrays.asList(eq(DASHBOARD_CUSTOMER_ID_PROPERTY, customerId), |
@@ -63,7 +65,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt | @@ -63,7 +65,7 @@ public class DashboardInfoDaoImpl extends AbstractSearchTextDao<DashboardInfoEnt | ||
63 | pageLink); | 65 | pageLink); |
64 | 66 | ||
65 | log.trace("Found dashboards [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", dashboardEntities, tenantId, customerId, pageLink); | 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,21 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.dashboard; | 16 | package org.thingsboard.server.dao.dashboard; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | -import java.util.UUID; | ||
20 | - | ||
21 | import org.thingsboard.server.common.data.Dashboard; | 18 | import org.thingsboard.server.common.data.Dashboard; |
22 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
23 | import org.thingsboard.server.dao.Dao; | 19 | import org.thingsboard.server.dao.Dao; |
24 | -import org.thingsboard.server.dao.model.DashboardEntity; | ||
25 | -import org.thingsboard.server.dao.model.DashboardInfoEntity; | ||
26 | 20 | ||
27 | /** | 21 | /** |
28 | * The Interface DashboardDao. | 22 | * The Interface DashboardDao. |
29 | - * | ||
30 | - * @param <T> the generic type | ||
31 | */ | 23 | */ |
32 | -public interface DashboardDao extends Dao<DashboardEntity> { | 24 | +public interface DashboardDao extends Dao<Dashboard> { |
33 | 25 | ||
34 | /** | 26 | /** |
35 | * Save or update dashboard object | 27 | * Save or update dashboard object |
@@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> { | @@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> { | ||
37 | * @param dashboard the dashboard object | 29 | * @param dashboard the dashboard object |
38 | * @return saved dashboard object | 30 | * @return saved dashboard object |
39 | */ | 31 | */ |
40 | - DashboardEntity save(Dashboard dashboard); | 32 | + Dashboard save(Dashboard dashboard); |
41 | 33 | ||
42 | } | 34 | } |
@@ -15,21 +15,17 @@ | @@ -15,21 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.dashboard; | 16 | package org.thingsboard.server.dao.dashboard; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | -import java.util.UUID; | ||
20 | - | ||
21 | -import org.thingsboard.server.common.data.Dashboard; | 18 | +import org.thingsboard.server.common.data.DashboardInfo; |
22 | import org.thingsboard.server.common.data.page.TextPageLink; | 19 | import org.thingsboard.server.common.data.page.TextPageLink; |
23 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
24 | -import org.thingsboard.server.dao.model.DashboardEntity; | ||
25 | -import org.thingsboard.server.dao.model.DashboardInfoEntity; | 21 | + |
22 | +import java.util.List; | ||
23 | +import java.util.UUID; | ||
26 | 24 | ||
27 | /** | 25 | /** |
28 | * The Interface DashboardInfoDao. | 26 | * The Interface DashboardInfoDao. |
29 | - * | ||
30 | - * @param <T> the generic type | ||
31 | */ | 27 | */ |
32 | -public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { | 28 | +public interface DashboardInfoDao extends Dao<DashboardInfo> { |
33 | 29 | ||
34 | /** | 30 | /** |
35 | * Find dashboards by tenantId and page link. | 31 | * Find dashboards by tenantId and page link. |
@@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { | @@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { | ||
38 | * @param pageLink the page link | 34 | * @param pageLink the page link |
39 | * @return the list of dashboard objects | 35 | * @return the list of dashboard objects |
40 | */ | 36 | */ |
41 | - List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink); | 37 | + List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink); |
42 | 38 | ||
43 | /** | 39 | /** |
44 | * Find dashboards by tenantId, customerId and page link. | 40 | * Find dashboards by tenantId, customerId and page link. |
@@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { | @@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> { | ||
48 | * @param pageLink the page link | 44 | * @param pageLink the page link |
49 | * @return the list of dashboard objects | 45 | * @return the list of dashboard objects |
50 | */ | 46 | */ |
51 | - List<DashboardInfoEntity> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); | 47 | + List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); |
52 | 48 | ||
53 | } | 49 | } |
@@ -25,22 +25,22 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -25,22 +25,22 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
25 | 25 | ||
26 | public interface DashboardService { | 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 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.dashboard; | 16 | package org.thingsboard.server.dao.dashboard; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
19 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
20 | - | ||
21 | -import java.util.List; | ||
22 | - | ||
23 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
24 | import org.apache.commons.lang3.StringUtils; | 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 | import org.thingsboard.server.common.data.Dashboard; | 23 | import org.thingsboard.server.common.data.Dashboard; |
26 | import org.thingsboard.server.common.data.DashboardInfo; | 24 | import org.thingsboard.server.common.data.DashboardInfo; |
25 | +import org.thingsboard.server.common.data.Tenant; | ||
27 | import org.thingsboard.server.common.data.id.CustomerId; | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
28 | import org.thingsboard.server.common.data.id.DashboardId; | 27 | import org.thingsboard.server.common.data.id.DashboardId; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -31,15 +30,13 @@ import org.thingsboard.server.common.data.page.TextPageData; | @@ -31,15 +30,13 @@ import org.thingsboard.server.common.data.page.TextPageData; | ||
31 | import org.thingsboard.server.common.data.page.TextPageLink; | 30 | import org.thingsboard.server.common.data.page.TextPageLink; |
32 | import org.thingsboard.server.dao.customer.CustomerDao; | 31 | import org.thingsboard.server.dao.customer.CustomerDao; |
33 | import org.thingsboard.server.dao.exception.DataValidationException; | 32 | import org.thingsboard.server.dao.exception.DataValidationException; |
34 | -import org.thingsboard.server.dao.model.*; | 33 | +import org.thingsboard.server.dao.model.ModelConstants; |
35 | import org.thingsboard.server.dao.service.DataValidator; | 34 | import org.thingsboard.server.dao.service.DataValidator; |
36 | import org.thingsboard.server.dao.service.PaginatedRemover; | 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 | import org.thingsboard.server.dao.service.Validator; | 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 | @Service | 41 | @Service |
45 | @Slf4j | 42 | @Slf4j |
@@ -61,16 +58,14 @@ public class DashboardServiceImpl implements DashboardService { | @@ -61,16 +58,14 @@ public class DashboardServiceImpl implements DashboardService { | ||
61 | public Dashboard findDashboardById(DashboardId dashboardId) { | 58 | public Dashboard findDashboardById(DashboardId dashboardId) { |
62 | log.trace("Executing findDashboardById [{}]", dashboardId); | 59 | log.trace("Executing findDashboardById [{}]", dashboardId); |
63 | Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId); | 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 | @Override | 64 | @Override |
69 | public Dashboard saveDashboard(Dashboard dashboard) { | 65 | public Dashboard saveDashboard(Dashboard dashboard) { |
70 | log.trace("Executing saveDashboard [{}]", dashboard); | 66 | log.trace("Executing saveDashboard [{}]", dashboard); |
71 | dashboardValidator.validate(dashboard); | 67 | dashboardValidator.validate(dashboard); |
72 | - DashboardEntity dashboardEntity = dashboardDao.save(dashboard); | ||
73 | - return getData(dashboardEntity); | 68 | + return dashboardDao.save(dashboard); |
74 | } | 69 | } |
75 | 70 | ||
76 | @Override | 71 | @Override |
@@ -99,9 +94,8 @@ public class DashboardServiceImpl implements DashboardService { | @@ -99,9 +94,8 @@ public class DashboardServiceImpl implements DashboardService { | ||
99 | log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 94 | log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
100 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 95 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
101 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 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 | @Override | 101 | @Override |
@@ -117,9 +111,8 @@ public class DashboardServiceImpl implements DashboardService { | @@ -117,9 +111,8 @@ public class DashboardServiceImpl implements DashboardService { | ||
117 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 111 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
118 | Validator.validateId(customerId, "Incorrect customerId " + customerId); | 112 | Validator.validateId(customerId, "Incorrect customerId " + customerId); |
119 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 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 | @Override | 118 | @Override |
@@ -140,7 +133,7 @@ public class DashboardServiceImpl implements DashboardService { | @@ -140,7 +133,7 @@ public class DashboardServiceImpl implements DashboardService { | ||
140 | if (dashboard.getTenantId() == null) { | 133 | if (dashboard.getTenantId() == null) { |
141 | throw new DataValidationException("Dashboard should be assigned to tenant!"); | 134 | throw new DataValidationException("Dashboard should be assigned to tenant!"); |
142 | } else { | 135 | } else { |
143 | - TenantEntity tenant = tenantDao.findById(dashboard.getTenantId().getId()); | 136 | + Tenant tenant = tenantDao.findById(dashboard.getTenantId().getId()); |
144 | if (tenant == null) { | 137 | if (tenant == null) { |
145 | throw new DataValidationException("Dashboard is referencing to non-existent tenant!"); | 138 | throw new DataValidationException("Dashboard is referencing to non-existent tenant!"); |
146 | } | 139 | } |
@@ -148,32 +141,32 @@ public class DashboardServiceImpl implements DashboardService { | @@ -148,32 +141,32 @@ public class DashboardServiceImpl implements DashboardService { | ||
148 | if (dashboard.getCustomerId() == null) { | 141 | if (dashboard.getCustomerId() == null) { |
149 | dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID)); | 142 | dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID)); |
150 | } else if (!dashboard.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) { | 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 | if (customer == null) { | 145 | if (customer == null) { |
153 | throw new DataValidationException("Can't assign dashboard to non-existent customer!"); | 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 | throw new DataValidationException("Can't assign dashboard to customer from different tenant!"); | 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 | @Override | 158 | @Override |
166 | - protected List<DashboardInfoEntity> findEntities(TenantId id, TextPageLink pageLink) { | 159 | + protected List<DashboardInfo> findEntities(TenantId id, TextPageLink pageLink) { |
167 | return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink); | 160 | return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink); |
168 | } | 161 | } |
169 | 162 | ||
170 | @Override | 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 | private TenantId tenantId; | 171 | private TenantId tenantId; |
179 | 172 | ||
@@ -182,13 +175,13 @@ public class DashboardServiceImpl implements DashboardService { | @@ -182,13 +175,13 @@ public class DashboardServiceImpl implements DashboardService { | ||
182 | } | 175 | } |
183 | 176 | ||
184 | @Override | 177 | @Override |
185 | - protected List<DashboardInfoEntity> findEntities(CustomerId id, TextPageLink pageLink) { | 178 | + protected List<DashboardInfo> findEntities(CustomerId id, TextPageLink pageLink) { |
186 | return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); | 179 | return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink); |
187 | } | 180 | } |
188 | 181 | ||
189 | @Override | 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,26 +15,23 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.device; | 16 | package org.thingsboard.server.dao.device; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
20 | - | ||
21 | -import java.util.UUID; | ||
22 | - | 18 | +import com.datastax.driver.core.querybuilder.Select.Where; |
23 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
24 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
25 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 21 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
26 | -import org.thingsboard.server.dao.AbstractModelDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractModelDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
27 | import org.thingsboard.server.dao.model.DeviceCredentialsEntity; | 24 | 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; | ||
33 | import org.thingsboard.server.dao.model.ModelConstants; | 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 | @Component | 32 | @Component |
36 | @Slf4j | 33 | @Slf4j |
37 | -public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentialsEntity> implements DeviceCredentialsDao { | 34 | +public class CassandraDeviceCredentialsDao extends CassandraAbstractModelDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao { |
38 | 35 | ||
39 | @Override | 36 | @Override |
40 | protected Class<DeviceCredentialsEntity> getColumnFamilyClass() { | 37 | protected Class<DeviceCredentialsEntity> getColumnFamilyClass() { |
@@ -47,31 +44,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials | @@ -47,31 +44,24 @@ public class DeviceCredentialsDaoImpl extends AbstractModelDao<DeviceCredentials | ||
47 | } | 44 | } |
48 | 45 | ||
49 | @Override | 46 | @Override |
50 | - public DeviceCredentialsEntity findByDeviceId(UUID deviceId) { | 47 | + public DeviceCredentials findByDeviceId(UUID deviceId) { |
51 | log.debug("Try to find device credentials by deviceId [{}] ", deviceId); | 48 | log.debug("Try to find device credentials by deviceId [{}] ", deviceId); |
52 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME) | 49 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME) |
53 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId)); | 50 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId)); |
54 | log.trace("Execute query {}", query); | 51 | log.trace("Execute query {}", query); |
55 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); | 52 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); |
56 | log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId); | 53 | log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId); |
57 | - return deviceCredentialsEntity; | 54 | + return DaoUtil.getData(deviceCredentialsEntity); |
58 | } | 55 | } |
59 | 56 | ||
60 | @Override | 57 | @Override |
61 | - public DeviceCredentialsEntity findByCredentialsId(String credentialsId) { | 58 | + public DeviceCredentials findByCredentialsId(String credentialsId) { |
62 | log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId); | 59 | log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId); |
63 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME) | 60 | Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME) |
64 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId)); | 61 | .where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId)); |
65 | log.trace("Execute query {}", query); | 62 | log.trace("Execute query {}", query); |
66 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); | 63 | DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(query); |
67 | log.trace("Found device credentials [{}] by credentialsId [{}]", deviceCredentialsEntity, credentialsId); | 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,27 +15,24 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.device; | 16 | package org.thingsboard.server.dao.device; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.in; | ||
20 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
21 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
22 | - | ||
23 | -import java.util.*; | ||
24 | - | ||
25 | import com.datastax.driver.core.querybuilder.Select; | 18 | import com.datastax.driver.core.querybuilder.Select; |
26 | import com.google.common.util.concurrent.ListenableFuture; | 19 | import com.google.common.util.concurrent.ListenableFuture; |
27 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
28 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
29 | import org.thingsboard.server.common.data.Device; | 22 | import org.thingsboard.server.common.data.Device; |
30 | import org.thingsboard.server.common.data.page.TextPageLink; | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
31 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 24 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
25 | +import org.thingsboard.server.dao.DaoUtil; | ||
32 | import org.thingsboard.server.dao.model.DeviceEntity; | 26 | import org.thingsboard.server.dao.model.DeviceEntity; |
33 | -import org.slf4j.Logger; | ||
34 | -import org.slf4j.LoggerFactory; | 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 | @Component | 33 | @Component |
37 | @Slf4j | 34 | @Slf4j |
38 | -public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implements DeviceDao { | 35 | +public class CassandraDeviceDao extends CassandraAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao { |
39 | 36 | ||
40 | @Override | 37 | @Override |
41 | protected Class<DeviceEntity> getColumnFamilyClass() { | 38 | protected Class<DeviceEntity> getColumnFamilyClass() { |
@@ -48,23 +45,17 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | @@ -48,23 +45,17 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | ||
48 | } | 45 | } |
49 | 46 | ||
50 | @Override | 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 | log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 49 | log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
59 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 50 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
60 | Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); | 51 | Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); |
61 | 52 | ||
62 | log.trace("Found devices [{}] by tenantId [{}] and pageLink [{}]", deviceEntities, tenantId, pageLink); | 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 | @Override | 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 | log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds); | 59 | log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds); |
69 | Select select = select().from(getColumnFamilyName()); | 60 | Select select = select().from(getColumnFamilyName()); |
70 | Select.Where query = select.where(); | 61 | Select.Where query = select.where(); |
@@ -74,7 +65,7 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | @@ -74,7 +65,7 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | ||
74 | } | 65 | } |
75 | 66 | ||
76 | @Override | 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 | log.debug("Try to find devices by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); | 69 | log.debug("Try to find devices by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
79 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 70 | List<DeviceEntity> deviceEntities = findPageWithTextSearch(DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
80 | Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), | 71 | Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), |
@@ -82,11 +73,11 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | @@ -82,11 +73,11 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | ||
82 | pageLink); | 73 | pageLink); |
83 | 74 | ||
84 | log.trace("Found devices [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, pageLink); | 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 | @Override | 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 | log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds); | 81 | log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds); |
91 | Select select = select().from(getColumnFamilyName()); | 82 | Select select = select().from(getColumnFamilyName()); |
92 | Select.Where query = select.where(); | 83 | Select.Where query = select.where(); |
@@ -97,12 +88,12 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | @@ -97,12 +88,12 @@ public class DeviceDaoImpl extends AbstractSearchTextDao<DeviceEntity> implement | ||
97 | } | 88 | } |
98 | 89 | ||
99 | @Override | 90 | @Override |
100 | - public Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) { | 91 | + public Optional<Device> findDevicesByTenantIdAndName(UUID tenantId, String deviceName) { |
101 | Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME); | 92 | Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME); |
102 | Select.Where query = select.where(); | 93 | Select.Where query = select.where(); |
103 | query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); | 94 | query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); |
104 | query.and(eq(DEVICE_NAME_PROPERTY, deviceName)); | 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,18 +15,15 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.device; | 16 | package org.thingsboard.server.dao.device; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 18 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
21 | import org.thingsboard.server.dao.Dao; | 19 | import org.thingsboard.server.dao.Dao; |
22 | -import org.thingsboard.server.dao.model.DeviceCredentialsEntity; | 20 | + |
21 | +import java.util.UUID; | ||
23 | 22 | ||
24 | /** | 23 | /** |
25 | * The Interface DeviceCredentialsDao. | 24 | * The Interface DeviceCredentialsDao. |
26 | - * | ||
27 | - * @param <T> the generic type | ||
28 | */ | 25 | */ |
29 | -public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | 26 | +public interface DeviceCredentialsDao extends Dao<DeviceCredentials> { |
30 | 27 | ||
31 | /** | 28 | /** |
32 | * Save or update device credentials object | 29 | * Save or update device credentials object |
@@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | @@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | ||
34 | * @param deviceCredentials the device credentials object | 31 | * @param deviceCredentials the device credentials object |
35 | * @return saved device credentials object | 32 | * @return saved device credentials object |
36 | */ | 33 | */ |
37 | - DeviceCredentialsEntity save(DeviceCredentials deviceCredentials); | 34 | + DeviceCredentials save(DeviceCredentials deviceCredentials); |
38 | 35 | ||
39 | /** | 36 | /** |
40 | * Find device credentials by device id. | 37 | * Find device credentials by device id. |
@@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | @@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | ||
42 | * @param deviceId the device id | 39 | * @param deviceId the device id |
43 | * @return the device credentials object | 40 | * @return the device credentials object |
44 | */ | 41 | */ |
45 | - DeviceCredentialsEntity findByDeviceId(UUID deviceId); | 42 | + DeviceCredentials findByDeviceId(UUID deviceId); |
46 | 43 | ||
47 | /** | 44 | /** |
48 | * Find device credentials by credentials id. | 45 | * Find device credentials by credentials id. |
@@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | @@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> { | ||
50 | * @param credentialsId the credentials id | 47 | * @param credentialsId the credentials id |
51 | * @return the device credentials object | 48 | * @return the device credentials object |
52 | */ | 49 | */ |
53 | - DeviceCredentialsEntity findByCredentialsId(String credentialsId); | 50 | + DeviceCredentials findByCredentialsId(String credentialsId); |
54 | 51 | ||
55 | } | 52 | } |
@@ -26,10 +26,8 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; | @@ -26,10 +26,8 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
26 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; | 26 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
27 | import org.thingsboard.server.dao.EncryptionUtil; | 27 | import org.thingsboard.server.dao.EncryptionUtil; |
28 | import org.thingsboard.server.dao.exception.DataValidationException; | 28 | import org.thingsboard.server.dao.exception.DataValidationException; |
29 | -import org.thingsboard.server.dao.model.DeviceCredentialsEntity; | ||
30 | import org.thingsboard.server.dao.service.DataValidator; | 29 | import org.thingsboard.server.dao.service.DataValidator; |
31 | 30 | ||
32 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
33 | import static org.thingsboard.server.dao.service.Validator.validateId; | 31 | import static org.thingsboard.server.dao.service.Validator.validateId; |
34 | import static org.thingsboard.server.dao.service.Validator.validateString; | 32 | import static org.thingsboard.server.dao.service.Validator.validateString; |
35 | 33 | ||
@@ -47,16 +45,14 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | @@ -47,16 +45,14 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | ||
47 | public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) { | 45 | public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) { |
48 | log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId); | 46 | log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId); |
49 | validateId(deviceId, "Incorrect deviceId " + deviceId); | 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 | @Override | 51 | @Override |
55 | public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) { | 52 | public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) { |
56 | log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId); | 53 | log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId); |
57 | validateString(credentialsId, "Incorrect credentialsId " + credentialsId); | 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 | @Override | 58 | @Override |
@@ -75,7 +71,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | @@ -75,7 +71,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | ||
75 | } | 71 | } |
76 | log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials); | 72 | log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials); |
77 | credentialsValidator.validate(deviceCredentials); | 73 | credentialsValidator.validate(deviceCredentials); |
78 | - return getData(deviceCredentialsDao.save(deviceCredentials)); | 74 | + return deviceCredentialsDao.save(deviceCredentials); |
79 | } | 75 | } |
80 | 76 | ||
81 | private void formatCertData(DeviceCredentials deviceCredentials) { | 77 | private void formatCertData(DeviceCredentials deviceCredentials) { |
@@ -96,7 +92,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | @@ -96,7 +92,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | ||
96 | 92 | ||
97 | @Override | 93 | @Override |
98 | protected void validateCreate(DeviceCredentials deviceCredentials) { | 94 | protected void validateCreate(DeviceCredentials deviceCredentials) { |
99 | - DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); | 95 | + DeviceCredentials existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId()); |
100 | if (existingCredentialsEntity != null) { | 96 | if (existingCredentialsEntity != null) { |
101 | throw new DataValidationException("Create of existent device credentials!"); | 97 | throw new DataValidationException("Create of existent device credentials!"); |
102 | } | 98 | } |
@@ -104,12 +100,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | @@ -104,12 +100,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService { | ||
104 | 100 | ||
105 | @Override | 101 | @Override |
106 | protected void validateUpdate(DeviceCredentials deviceCredentials) { | 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 | throw new DataValidationException("Unable to update non-existent device credentials!"); | 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 | throw new DataValidationException("Specified credentials are already registered!"); | 109 | throw new DataValidationException("Specified credentials are already registered!"); |
114 | } | 110 | } |
115 | } | 111 | } |
@@ -15,21 +15,20 @@ | @@ -15,21 +15,20 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.device; | 16 | package org.thingsboard.server.dao.device; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | -import java.util.Optional; | ||
20 | -import java.util.UUID; | ||
21 | - | ||
22 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
23 | import org.thingsboard.server.common.data.Device; | 19 | import org.thingsboard.server.common.data.Device; |
24 | import org.thingsboard.server.common.data.page.TextPageLink; | 20 | import org.thingsboard.server.common.data.page.TextPageLink; |
25 | import org.thingsboard.server.dao.Dao; | 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 | * The Interface DeviceDao. | 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 | * Save or update device object | 34 | * Save or update device object |
@@ -37,7 +36,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -37,7 +36,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
37 | * @param device the device object | 36 | * @param device the device object |
38 | * @return saved device object | 37 | * @return saved device object |
39 | */ | 38 | */ |
40 | - DeviceEntity save(Device device); | 39 | + Device save(Device device); |
41 | 40 | ||
42 | /** | 41 | /** |
43 | * Find devices by tenantId and page link. | 42 | * Find devices by tenantId and page link. |
@@ -46,7 +45,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -46,7 +45,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
46 | * @param pageLink the page link | 45 | * @param pageLink the page link |
47 | * @return the list of device objects | 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 | * Find devices by tenantId and devices Ids. | 51 | * Find devices by tenantId and devices Ids. |
@@ -55,7 +54,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -55,7 +54,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
55 | * @param deviceIds the device Ids | 54 | * @param deviceIds the device Ids |
56 | * @return the list of device objects | 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 | * Find devices by tenantId, customerId and page link. | 60 | * Find devices by tenantId, customerId and page link. |
@@ -65,7 +64,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -65,7 +64,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
65 | * @param pageLink the page link | 64 | * @param pageLink the page link |
66 | * @return the list of device objects | 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 | * Find devices by tenantId, customerId and devices Ids. | 70 | * Find devices by tenantId, customerId and devices Ids. |
@@ -75,7 +74,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -75,7 +74,7 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
75 | * @param deviceIds the device Ids | 74 | * @param deviceIds the device Ids |
76 | * @return the list of device objects | 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 | * Find devices by tenantId and device name. | 80 | * Find devices by tenantId and device name. |
@@ -84,5 +83,5 @@ public interface DeviceDao extends Dao<DeviceEntity> { | @@ -84,5 +83,5 @@ public interface DeviceDao extends Dao<DeviceEntity> { | ||
84 | * @param name the device name | 83 | * @param name the device name |
85 | * @return the optional device object | 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 | } |
@@ -43,13 +43,9 @@ import org.thingsboard.server.dao.tenant.TenantDao; | @@ -43,13 +43,9 @@ import org.thingsboard.server.dao.tenant.TenantDao; | ||
43 | import java.util.List; | 43 | import java.util.List; |
44 | import java.util.Optional; | 44 | import java.util.Optional; |
45 | 45 | ||
46 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
47 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
48 | -import static org.thingsboard.server.dao.DaoUtil.toUUIDs; | 46 | +import static org.thingsboard.server.dao.DaoUtil.*; |
49 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 47 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
50 | -import static org.thingsboard.server.dao.service.Validator.validateId; | ||
51 | -import static org.thingsboard.server.dao.service.Validator.validateIds; | ||
52 | -import static org.thingsboard.server.dao.service.Validator.validatePageLink; | 48 | +import static org.thingsboard.server.dao.service.Validator.*; |
53 | 49 | ||
54 | @Service | 50 | @Service |
55 | @Slf4j | 51 | @Slf4j |
@@ -71,15 +67,14 @@ public class DeviceServiceImpl implements DeviceService { | @@ -71,15 +67,14 @@ public class DeviceServiceImpl implements DeviceService { | ||
71 | public Device findDeviceById(DeviceId deviceId) { | 67 | public Device findDeviceById(DeviceId deviceId) { |
72 | log.trace("Executing findDeviceById [{}]", deviceId); | 68 | log.trace("Executing findDeviceById [{}]", deviceId); |
73 | validateId(deviceId, "Incorrect deviceId " + deviceId); | 69 | validateId(deviceId, "Incorrect deviceId " + deviceId); |
74 | - DeviceEntity deviceEntity = deviceDao.findById(deviceId.getId()); | ||
75 | - return getData(deviceEntity); | 70 | + return deviceDao.findById(deviceId.getId()); |
76 | } | 71 | } |
77 | 72 | ||
78 | @Override | 73 | @Override |
79 | public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) { | 74 | public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) { |
80 | log.trace("Executing findDeviceById [{}]", deviceId); | 75 | log.trace("Executing findDeviceById [{}]", deviceId); |
81 | validateId(deviceId, "Incorrect deviceId " + deviceId); | 76 | validateId(deviceId, "Incorrect deviceId " + deviceId); |
82 | - ListenableFuture<DeviceEntity> deviceEntity = deviceDao.findByIdAsync(deviceId.getId()); | 77 | + ListenableFuture<Device> deviceEntity = deviceDao.findByIdAsync(deviceId.getId()); |
83 | return Futures.transform(deviceEntity, (Function<? super DeviceEntity, ? extends Device>) input -> getData(input)); | 78 | return Futures.transform(deviceEntity, (Function<? super DeviceEntity, ? extends Device>) input -> getData(input)); |
84 | } | 79 | } |
85 | 80 | ||
@@ -87,9 +82,9 @@ public class DeviceServiceImpl implements DeviceService { | @@ -87,9 +82,9 @@ public class DeviceServiceImpl implements DeviceService { | ||
87 | public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) { | 82 | public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) { |
88 | log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name); | 83 | log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name); |
89 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 84 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
90 | - Optional<DeviceEntity> deviceEntityOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name); | 85 | + Optional<Device> deviceEntityOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name); |
91 | if (deviceEntityOpt.isPresent()) { | 86 | if (deviceEntityOpt.isPresent()) { |
92 | - return Optional.of(getData(deviceEntityOpt.get())); | 87 | + return Optional.of(deviceEntityOpt.get()); |
93 | } else { | 88 | } else { |
94 | return Optional.empty(); | 89 | return Optional.empty(); |
95 | } | 90 | } |
@@ -99,15 +94,15 @@ public class DeviceServiceImpl implements DeviceService { | @@ -99,15 +94,15 @@ public class DeviceServiceImpl implements DeviceService { | ||
99 | public Device saveDevice(Device device) { | 94 | public Device saveDevice(Device device) { |
100 | log.trace("Executing saveDevice [{}]", device); | 95 | log.trace("Executing saveDevice [{}]", device); |
101 | deviceValidator.validate(device); | 96 | deviceValidator.validate(device); |
102 | - DeviceEntity deviceEntity = deviceDao.save(device); | 97 | + Device savedDevice = deviceDao.save(device); |
103 | if (device.getId() == null) { | 98 | if (device.getId() == null) { |
104 | DeviceCredentials deviceCredentials = new DeviceCredentials(); | 99 | DeviceCredentials deviceCredentials = new DeviceCredentials(); |
105 | - deviceCredentials.setDeviceId(new DeviceId(deviceEntity.getId())); | 100 | + deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); |
106 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); | 101 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); |
107 | deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); | 102 | deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); |
108 | deviceCredentialsService.createDeviceCredentials(deviceCredentials); | 103 | deviceCredentialsService.createDeviceCredentials(deviceCredentials); |
109 | } | 104 | } |
110 | - return getData(deviceEntity); | 105 | + return savedDevice; |
111 | } | 106 | } |
112 | 107 | ||
113 | @Override | 108 | @Override |
@@ -140,8 +135,7 @@ public class DeviceServiceImpl implements DeviceService { | @@ -140,8 +135,7 @@ public class DeviceServiceImpl implements DeviceService { | ||
140 | log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 135 | log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
141 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 136 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
142 | validatePageLink(pageLink, "Incorrect page link " + pageLink); | 137 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
143 | - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink); | ||
144 | - List<Device> devices = convertDataList(deviceEntities); | 138 | + List<Device> devices = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink); |
145 | return new TextPageData<Device>(devices, pageLink); | 139 | return new TextPageData<Device>(devices, pageLink); |
146 | } | 140 | } |
147 | 141 | ||
@@ -150,7 +144,7 @@ public class DeviceServiceImpl implements DeviceService { | @@ -150,7 +144,7 @@ public class DeviceServiceImpl implements DeviceService { | ||
150 | log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds); | 144 | log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds); |
151 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 145 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
152 | validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); | 146 | validateIds(deviceIds, "Incorrect deviceIds " + deviceIds); |
153 | - ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds)); | 147 | + ListenableFuture<List<Device>> devices = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds)); |
154 | return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input)); | 148 | return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input)); |
155 | } | 149 | } |
156 | 150 | ||
@@ -168,8 +162,7 @@ public class DeviceServiceImpl implements DeviceService { | @@ -168,8 +162,7 @@ public class DeviceServiceImpl implements DeviceService { | ||
168 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 162 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
169 | validateId(customerId, "Incorrect customerId " + customerId); | 163 | validateId(customerId, "Incorrect customerId " + customerId); |
170 | validatePageLink(pageLink, "Incorrect page link " + pageLink); | 164 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
171 | - List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); | ||
172 | - List<Device> devices = convertDataList(deviceEntities); | 165 | + List<Device> devices = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink); |
173 | return new TextPageData<Device>(devices, pageLink); | 166 | return new TextPageData<Device>(devices, pageLink); |
174 | } | 167 | } |
175 | 168 |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.event; | 16 | package org.thingsboard.server.dao.event; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 19 | import com.datastax.driver.core.utils.UUIDs; |
19 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
20 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
@@ -27,14 +28,11 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -27,14 +28,11 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
27 | import org.thingsboard.server.common.data.page.TimePageData; | 28 | import org.thingsboard.server.common.data.page.TimePageData; |
28 | import org.thingsboard.server.common.data.page.TimePageLink; | 29 | import org.thingsboard.server.common.data.page.TimePageLink; |
29 | import org.thingsboard.server.dao.exception.DataValidationException; | 30 | import org.thingsboard.server.dao.exception.DataValidationException; |
30 | -import org.thingsboard.server.dao.model.EventEntity; | ||
31 | import org.thingsboard.server.dao.service.DataValidator; | 31 | import org.thingsboard.server.dao.service.DataValidator; |
32 | 32 | ||
33 | import java.util.List; | 33 | import java.util.List; |
34 | import java.util.Optional; | 34 | import java.util.Optional; |
35 | 35 | ||
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; | 36 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
39 | 37 | ||
40 | @Service | 38 | @Service |
@@ -59,7 +57,7 @@ public class BaseEventService implements EventService { | @@ -59,7 +57,7 @@ public class BaseEventService implements EventService { | ||
59 | if (StringUtils.isEmpty(event.getUid())) { | 57 | if (StringUtils.isEmpty(event.getUid())) { |
60 | event.setUid(event.getId().toString()); | 58 | event.setUid(event.getId().toString()); |
61 | } | 59 | } |
62 | - return getData(eventDao.save(event)); | 60 | + return eventDao.save(event); |
63 | } | 61 | } |
64 | 62 | ||
65 | @Override | 63 | @Override |
@@ -75,8 +73,8 @@ public class BaseEventService implements EventService { | @@ -75,8 +73,8 @@ public class BaseEventService implements EventService { | ||
75 | if (event.getId() == null) { | 73 | if (event.getId() == null) { |
76 | event.setId(new EventId(UUIDs.timeBased())); | 74 | event.setId(new EventId(UUIDs.timeBased())); |
77 | } | 75 | } |
78 | - Optional<EventEntity> result = eventDao.saveIfNotExists(event); | ||
79 | - return result.isPresent() ? Optional.of(getData(result.get())) : Optional.empty(); | 76 | + Optional<Event> result = eventDao.saveIfNotExists(event); |
77 | + return result.isPresent() ? Optional.of(result.get()) : Optional.empty(); | ||
80 | } | 78 | } |
81 | 79 | ||
82 | @Override | 80 | @Override |
@@ -93,22 +91,19 @@ public class BaseEventService implements EventService { | @@ -93,22 +91,19 @@ public class BaseEventService implements EventService { | ||
93 | if (StringUtils.isEmpty(eventUid)) { | 91 | if (StringUtils.isEmpty(eventUid)) { |
94 | throw new DataValidationException("Event uid should be specified!."); | 92 | throw new DataValidationException("Event uid should be specified!."); |
95 | } | 93 | } |
96 | - EventEntity entity = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid); | ||
97 | - return entity != null ? Optional.of(getData(entity)) : Optional.empty(); | 94 | + Event event = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid); |
95 | + return event != null ? Optional.of(event) : Optional.empty(); | ||
98 | } | 96 | } |
99 | 97 | ||
100 | @Override | 98 | @Override |
101 | public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, TimePageLink pageLink) { | 99 | 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); | 100 | + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, pageLink); |
104 | return new TimePageData<Event>(events, pageLink); | 101 | return new TimePageData<Event>(events, pageLink); |
105 | } | 102 | } |
106 | 103 | ||
107 | - | ||
108 | @Override | 104 | @Override |
109 | public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { | 105 | 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); | 106 | + List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink); |
112 | return new TimePageData<Event>(events, pageLink); | 107 | return new TimePageData<Event>(events, pageLink); |
113 | } | 108 | } |
114 | 109 |
dao/src/main/java/org/thingsboard/server/dao/event/CassandraBaseEventDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/event/BaseEventDao.java
@@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.Event; | @@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.Event; | ||
26 | import org.thingsboard.server.common.data.id.EntityId; | 26 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.data.page.TimePageLink; | 27 | import org.thingsboard.server.common.data.page.TimePageLink; |
28 | import org.thingsboard.server.dao.AbstractSearchTimeDao; | 28 | import org.thingsboard.server.dao.AbstractSearchTimeDao; |
29 | +import org.thingsboard.server.dao.DaoUtil; | ||
29 | import org.thingsboard.server.dao.model.EventEntity; | 30 | import org.thingsboard.server.dao.model.EventEntity; |
30 | import org.thingsboard.server.dao.model.ModelConstants; | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
31 | 32 | ||
@@ -36,13 +37,11 @@ import java.util.UUID; | @@ -36,13 +37,11 @@ import java.util.UUID; | ||
36 | 37 | ||
37 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 38 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
38 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 39 | 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; | 40 | +import static org.thingsboard.server.dao.model.ModelConstants.*; |
42 | 41 | ||
43 | @Component | 42 | @Component |
44 | @Slf4j | 43 | @Slf4j |
45 | -public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements EventDao { | 44 | +public class CassandraBaseEventDao extends AbstractSearchTimeDao<EventEntity, Event> implements EventDao { |
46 | 45 | ||
47 | @Override | 46 | @Override |
48 | protected Class<EventEntity> getColumnFamilyClass() { | 47 | protected Class<EventEntity> getColumnFamilyClass() { |
@@ -55,18 +54,18 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | @@ -55,18 +54,18 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | ||
55 | } | 54 | } |
56 | 55 | ||
57 | @Override | 56 | @Override |
58 | - public EventEntity save(Event event) { | 57 | + public Event save(Event event) { |
59 | log.debug("Save event [{}] ", event); | 58 | log.debug("Save event [{}] ", event); |
60 | return save(new EventEntity(event), false).orElse(null); | 59 | return save(new EventEntity(event), false).orElse(null); |
61 | } | 60 | } |
62 | 61 | ||
63 | @Override | 62 | @Override |
64 | - public Optional<EventEntity> saveIfNotExists(Event event) { | 63 | + public Optional<Event> saveIfNotExists(Event event) { |
65 | return save(new EventEntity(event), true); | 64 | return save(new EventEntity(event), true); |
66 | } | 65 | } |
67 | 66 | ||
68 | @Override | 67 | @Override |
69 | - public EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { | 68 | + public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { |
70 | log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid); | 69 | log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid); |
71 | Select.Where query = select().from(getColumnFamilyName()).where( | 70 | Select.Where query = select().from(getColumnFamilyName()).where( |
72 | eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)) | 71 | eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)) |
@@ -81,11 +80,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | @@ -81,11 +80,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | ||
81 | } else { | 80 | } else { |
82 | log.debug("Search result: [{}]", entity != null); | 81 | log.debug("Search result: [{}]", entity != null); |
83 | } | 82 | } |
84 | - return entity; | 83 | + return DaoUtil.getData(entity); |
85 | } | 84 | } |
86 | 85 | ||
87 | @Override | 86 | @Override |
88 | - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { | 87 | + public List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { |
89 | log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink); | 88 | log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink); |
90 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME, | 89 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_ID_VIEW_NAME, |
91 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), | 90 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
@@ -93,11 +92,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | @@ -93,11 +92,11 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | ||
93 | eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())), | 92 | eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())), |
94 | pageLink); | 93 | pageLink); |
95 | log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); | 94 | log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); |
96 | - return entities; | 95 | + return DaoUtil.convertDataList(entities); |
97 | } | 96 | } |
98 | 97 | ||
99 | @Override | 98 | @Override |
100 | - public List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { | 99 | + public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { |
101 | log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); | 100 | log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
102 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME, | 101 | List<EventEntity> entities = findPageWithTimeSearch(EVENT_BY_TYPE_AND_ID_VIEW_NAME, |
103 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), | 102 | Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
@@ -108,10 +107,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | @@ -108,10 +107,10 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | ||
108 | QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), | 107 | QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), |
109 | pageLink); | 108 | pageLink); |
110 | log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); | 109 | log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
111 | - return entities; | 110 | + return DaoUtil.convertDataList(entities); |
112 | } | 111 | } |
113 | 112 | ||
114 | - private Optional<EventEntity> save(EventEntity entity, boolean ifNotExists) { | 113 | + private Optional<Event> save(EventEntity entity, boolean ifNotExists) { |
115 | if (entity.getId() == null) { | 114 | if (entity.getId() == null) { |
116 | entity.setId(UUIDs.timeBased()); | 115 | entity.setId(UUIDs.timeBased()); |
117 | } | 116 | } |
@@ -128,7 +127,7 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | @@ -128,7 +127,7 @@ public class BaseEventDao extends AbstractSearchTimeDao<EventEntity> implements | ||
128 | } | 127 | } |
129 | ResultSet rs = executeWrite(insert); | 128 | ResultSet rs = executeWrite(insert); |
130 | if (rs.wasApplied()) { | 129 | if (rs.wasApplied()) { |
131 | - return Optional.of(entity); | 130 | + return Optional.of(DaoUtil.getData(entity)); |
132 | } else { | 131 | } else { |
133 | return Optional.empty(); | 132 | return Optional.empty(); |
134 | } | 133 | } |
@@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event; | @@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event; | ||
19 | import org.thingsboard.server.common.data.id.EntityId; | 19 | import org.thingsboard.server.common.data.id.EntityId; |
20 | import org.thingsboard.server.common.data.page.TimePageLink; | 20 | import org.thingsboard.server.common.data.page.TimePageLink; |
21 | import org.thingsboard.server.dao.Dao; | 21 | import org.thingsboard.server.dao.Dao; |
22 | -import org.thingsboard.server.dao.model.EventEntity; | ||
23 | 22 | ||
24 | import java.util.List; | 23 | import java.util.List; |
25 | import java.util.Optional; | 24 | import java.util.Optional; |
@@ -27,10 +26,8 @@ import java.util.UUID; | @@ -27,10 +26,8 @@ import java.util.UUID; | ||
27 | 26 | ||
28 | /** | 27 | /** |
29 | * The Interface DeviceDao. | 28 | * The Interface DeviceDao. |
30 | - * | ||
31 | - * @param <T> the generic type | ||
32 | */ | 29 | */ |
33 | -public interface EventDao extends Dao<EventEntity> { | 30 | +public interface EventDao extends Dao<Event> { |
34 | 31 | ||
35 | /** | 32 | /** |
36 | * Save or update event object | 33 | * Save or update event object |
@@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> { | @@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> { | ||
38 | * @param event the event object | 35 | * @param event the event object |
39 | * @return saved event object | 36 | * @return saved event object |
40 | */ | 37 | */ |
41 | - EventEntity save(Event event); | 38 | + Event save(Event event); |
42 | 39 | ||
43 | /** | 40 | /** |
44 | * Save event object if it is not yet saved | 41 | * Save event object if it is not yet saved |
@@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> { | @@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> { | ||
46 | * @param event the event object | 43 | * @param event the event object |
47 | * @return saved event object | 44 | * @return saved event object |
48 | */ | 45 | */ |
49 | - Optional<EventEntity> saveIfNotExists(Event event); | 46 | + Optional<Event> saveIfNotExists(Event event); |
50 | 47 | ||
51 | /** | 48 | /** |
52 | * Find event by tenantId, entityId and eventUid. | 49 | * Find event by tenantId, entityId and eventUid. |
@@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> { | @@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> { | ||
57 | * @param eventUid the eventUid | 54 | * @param eventUid the eventUid |
58 | * @return the event | 55 | * @return the event |
59 | */ | 56 | */ |
60 | - EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid); | 57 | + Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid); |
61 | 58 | ||
62 | /** | 59 | /** |
63 | * Find events by tenantId, entityId and pageLink. | 60 | * Find events by tenantId, entityId and pageLink. |
@@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> { | @@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> { | ||
67 | * @param pageLink the pageLink | 64 | * @param pageLink the pageLink |
68 | * @return the event list | 65 | * @return the event list |
69 | */ | 66 | */ |
70 | - List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink); | 67 | + List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink); |
71 | 68 | ||
72 | /** | 69 | /** |
73 | * Find events by tenantId, entityId, eventType and pageLink. | 70 | * Find events by tenantId, entityId, eventType and pageLink. |
@@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> { | @@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> { | ||
78 | * @param pageLink the pageLink | 75 | * @param pageLink the pageLink |
79 | * @return the event list | 76 | * @return the event list |
80 | */ | 77 | */ |
81 | - List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink); | 78 | + List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink); |
82 | } | 79 | } |
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
21 | import org.thingsboard.server.common.data.page.TimePageData; | 21 | import org.thingsboard.server.common.data.page.TimePageData; |
22 | import org.thingsboard.server.common.data.page.TimePageLink; | 22 | import org.thingsboard.server.common.data.page.TimePageLink; |
23 | 23 | ||
24 | -import java.util.List; | ||
25 | import java.util.Optional; | 24 | import java.util.Optional; |
26 | 25 | ||
27 | public interface EventService { | 26 | public interface EventService { |
@@ -17,8 +17,6 @@ package org.thingsboard.server.dao.plugin; | @@ -17,8 +17,6 @@ package org.thingsboard.server.dao.plugin; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | -import org.slf4j.Logger; | ||
21 | -import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.server.common.data.id.PluginId; | 22 | import org.thingsboard.server.common.data.id.PluginId; |
@@ -29,13 +27,12 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | @@ -29,13 +27,12 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | ||
29 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | 27 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
30 | import org.thingsboard.server.common.data.plugin.ComponentType; | 28 | import org.thingsboard.server.common.data.plugin.ComponentType; |
31 | import org.thingsboard.server.common.data.plugin.PluginMetaData; | 29 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
30 | +import org.thingsboard.server.common.data.rule.RuleMetaData; | ||
32 | import org.thingsboard.server.dao.component.ComponentDescriptorService; | 31 | import org.thingsboard.server.dao.component.ComponentDescriptorService; |
33 | import org.thingsboard.server.dao.exception.DataValidationException; | 32 | import org.thingsboard.server.dao.exception.DataValidationException; |
34 | import org.thingsboard.server.dao.exception.DatabaseException; | 33 | import org.thingsboard.server.dao.exception.DatabaseException; |
35 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 34 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
36 | import org.thingsboard.server.dao.model.ModelConstants; | 35 | import org.thingsboard.server.dao.model.ModelConstants; |
37 | -import org.thingsboard.server.dao.model.PluginMetaDataEntity; | ||
38 | -import org.thingsboard.server.dao.model.RuleMetaDataEntity; | ||
39 | import org.thingsboard.server.dao.rule.RuleDao; | 36 | import org.thingsboard.server.dao.rule.RuleDao; |
40 | import org.thingsboard.server.dao.service.DataValidator; | 37 | import org.thingsboard.server.dao.service.DataValidator; |
41 | import org.thingsboard.server.dao.service.PaginatedRemover; | 38 | import org.thingsboard.server.dao.service.PaginatedRemover; |
@@ -46,9 +43,6 @@ import java.util.List; | @@ -46,9 +43,6 @@ import java.util.List; | ||
46 | import java.util.UUID; | 43 | import java.util.UUID; |
47 | import java.util.stream.Collectors; | 44 | import java.util.stream.Collectors; |
48 | 45 | ||
49 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
50 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
51 | - | ||
52 | @Service | 46 | @Service |
53 | @Slf4j | 47 | @Slf4j |
54 | public class BasePluginService implements PluginService { | 48 | public class BasePluginService implements PluginService { |
@@ -73,7 +67,7 @@ public class BasePluginService implements PluginService { | @@ -73,7 +67,7 @@ public class BasePluginService implements PluginService { | ||
73 | plugin.setTenantId(SYSTEM_TENANT); | 67 | plugin.setTenantId(SYSTEM_TENANT); |
74 | } | 68 | } |
75 | if (plugin.getId() != null) { | 69 | if (plugin.getId() != null) { |
76 | - PluginMetaData oldVersion = getData(pluginDao.findById(plugin.getId())); | 70 | + PluginMetaData oldVersion = pluginDao.findById(plugin.getId()); |
77 | if (plugin.getState() == null) { | 71 | if (plugin.getState() == null) { |
78 | plugin.setState(oldVersion.getState()); | 72 | plugin.setState(oldVersion.getState()); |
79 | } else if (plugin.getState() != oldVersion.getState()) { | 73 | } else if (plugin.getState() != oldVersion.getState()) { |
@@ -92,33 +86,32 @@ public class BasePluginService implements PluginService { | @@ -92,33 +86,32 @@ public class BasePluginService implements PluginService { | ||
92 | } else if (!ComponentType.PLUGIN.equals(descriptor.getType())) { | 86 | } else if (!ComponentType.PLUGIN.equals(descriptor.getType())) { |
93 | throw new IncorrectParameterException("Plugin class is actually " + descriptor.getType() + "!"); | 87 | throw new IncorrectParameterException("Plugin class is actually " + descriptor.getType() + "!"); |
94 | } | 88 | } |
95 | - PluginMetaDataEntity entity = pluginDao.findByApiToken(plugin.getApiToken()); | ||
96 | - if (entity != null && (plugin.getId() == null || !entity.getId().equals(plugin.getId().getId()))) { | 89 | + PluginMetaData savedPlugin = pluginDao.findByApiToken(plugin.getApiToken()); |
90 | + if (savedPlugin != null && (plugin.getId() == null || !savedPlugin.getId().getId().equals(plugin.getId().getId()))) { | ||
97 | throw new IncorrectParameterException("API token is already reserved!"); | 91 | throw new IncorrectParameterException("API token is already reserved!"); |
98 | } | 92 | } |
99 | if (!componentDescriptorService.validate(descriptor, plugin.getConfiguration())) { | 93 | if (!componentDescriptorService.validate(descriptor, plugin.getConfiguration())) { |
100 | throw new IncorrectParameterException("Filters configuration is not valid!"); | 94 | throw new IncorrectParameterException("Filters configuration is not valid!"); |
101 | } | 95 | } |
102 | - return getData(pluginDao.save(plugin)); | 96 | + return pluginDao.save(plugin); |
103 | } | 97 | } |
104 | 98 | ||
105 | @Override | 99 | @Override |
106 | public PluginMetaData findPluginById(PluginId pluginId) { | 100 | public PluginMetaData findPluginById(PluginId pluginId) { |
107 | Validator.validateId(pluginId, "Incorrect plugin id for search request."); | 101 | Validator.validateId(pluginId, "Incorrect plugin id for search request."); |
108 | - return getData(pluginDao.findById(pluginId)); | 102 | + return pluginDao.findById(pluginId); |
109 | } | 103 | } |
110 | 104 | ||
111 | @Override | 105 | @Override |
112 | public PluginMetaData findPluginByApiToken(String apiToken) { | 106 | public PluginMetaData findPluginByApiToken(String apiToken) { |
113 | Validator.validateString(apiToken, "Incorrect plugin apiToken for search request."); | 107 | Validator.validateString(apiToken, "Incorrect plugin apiToken for search request."); |
114 | - return getData(pluginDao.findByApiToken(apiToken)); | 108 | + return pluginDao.findByApiToken(apiToken); |
115 | } | 109 | } |
116 | 110 | ||
117 | @Override | 111 | @Override |
118 | public TextPageData<PluginMetaData> findSystemPlugins(TextPageLink pageLink) { | 112 | public TextPageData<PluginMetaData> findSystemPlugins(TextPageLink pageLink) { |
119 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search system plugin request."); | 113 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search system plugin request."); |
120 | - List<PluginMetaDataEntity> pluginEntities = pluginDao.findByTenantIdAndPageLink(SYSTEM_TENANT, pageLink); | ||
121 | - List<PluginMetaData> plugins = convertDataList(pluginEntities); | 114 | + List<PluginMetaData> plugins = pluginDao.findByTenantIdAndPageLink(SYSTEM_TENANT, pageLink); |
122 | return new TextPageData<>(plugins, pageLink); | 115 | return new TextPageData<>(plugins, pageLink); |
123 | } | 116 | } |
124 | 117 | ||
@@ -126,8 +119,7 @@ public class BasePluginService implements PluginService { | @@ -126,8 +119,7 @@ public class BasePluginService implements PluginService { | ||
126 | public TextPageData<PluginMetaData> findTenantPlugins(TenantId tenantId, TextPageLink pageLink) { | 119 | public TextPageData<PluginMetaData> findTenantPlugins(TenantId tenantId, TextPageLink pageLink) { |
127 | Validator.validateId(tenantId, "Incorrect tenant id for search plugins request."); | 120 | Validator.validateId(tenantId, "Incorrect tenant id for search plugins request."); |
128 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin request."); | 121 | Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin request."); |
129 | - List<PluginMetaDataEntity> pluginEntities = pluginDao.findByTenantIdAndPageLink(tenantId, pageLink); | ||
130 | - List<PluginMetaData> plugins = convertDataList(pluginEntities); | 122 | + List<PluginMetaData> plugins = pluginDao.findByTenantIdAndPageLink(tenantId, pageLink); |
131 | return new TextPageData<>(plugins, pageLink); | 123 | return new TextPageData<>(plugins, pageLink); |
132 | } | 124 | } |
133 | 125 | ||
@@ -152,8 +144,7 @@ public class BasePluginService implements PluginService { | @@ -152,8 +144,7 @@ public class BasePluginService implements PluginService { | ||
152 | log.trace("Executing findAllTenantPluginsByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 144 | log.trace("Executing findAllTenantPluginsByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
153 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 145 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
154 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 146 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
155 | - List<PluginMetaDataEntity> pluginsEntities = pluginDao.findAllTenantPluginsByTenantId(tenantId.getId(), pageLink); | ||
156 | - List<PluginMetaData> plugins = convertDataList(pluginsEntities); | 147 | + List<PluginMetaData> plugins = pluginDao.findAllTenantPluginsByTenantId(tenantId.getId(), pageLink); |
157 | return new TextPageData<>(plugins, pageLink); | 148 | return new TextPageData<>(plugins, pageLink); |
158 | } | 149 | } |
159 | 150 | ||
@@ -181,8 +172,8 @@ public class BasePluginService implements PluginService { | @@ -181,8 +172,8 @@ public class BasePluginService implements PluginService { | ||
181 | 172 | ||
182 | @Override | 173 | @Override |
183 | public void suspendPluginById(PluginId pluginId) { | 174 | public void suspendPluginById(PluginId pluginId) { |
184 | - PluginMetaDataEntity plugin = pluginDao.findById(pluginId); | ||
185 | - List<RuleMetaDataEntity> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()) | 175 | + PluginMetaData plugin = pluginDao.findById(pluginId); |
176 | + List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()) | ||
186 | .stream().filter(rule -> rule.getState() == ComponentLifecycleState.ACTIVE).collect(Collectors.toList()); | 177 | .stream().filter(rule -> rule.getState() == ComponentLifecycleState.ACTIVE).collect(Collectors.toList()); |
187 | if (affectedRules.isEmpty()) { | 178 | if (affectedRules.isEmpty()) { |
188 | updateLifeCycleState(pluginId, ComponentLifecycleState.SUSPENDED); | 179 | updateLifeCycleState(pluginId, ComponentLifecycleState.SUSPENDED); |
@@ -193,7 +184,7 @@ public class BasePluginService implements PluginService { | @@ -193,7 +184,7 @@ public class BasePluginService implements PluginService { | ||
193 | 184 | ||
194 | private void updateLifeCycleState(PluginId pluginId, ComponentLifecycleState state) { | 185 | private void updateLifeCycleState(PluginId pluginId, ComponentLifecycleState state) { |
195 | Validator.validateId(pluginId, "Incorrect plugin id for state change request."); | 186 | Validator.validateId(pluginId, "Incorrect plugin id for state change request."); |
196 | - PluginMetaDataEntity plugin = pluginDao.findById(pluginId); | 187 | + PluginMetaData plugin = pluginDao.findById(pluginId); |
197 | if (plugin != null) { | 188 | if (plugin != null) { |
198 | plugin.setState(state); | 189 | plugin.setState(state); |
199 | pluginDao.save(plugin); | 190 | pluginDao.save(plugin); |
@@ -209,8 +200,8 @@ public class BasePluginService implements PluginService { | @@ -209,8 +200,8 @@ public class BasePluginService implements PluginService { | ||
209 | } | 200 | } |
210 | 201 | ||
211 | private void checkRulesAndDelete(UUID pluginId) { | 202 | private void checkRulesAndDelete(UUID pluginId) { |
212 | - PluginMetaDataEntity plugin = pluginDao.findById(pluginId); | ||
213 | - List<RuleMetaDataEntity> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()); | 203 | + PluginMetaData plugin = pluginDao.findById(pluginId); |
204 | + List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()); | ||
214 | if (affectedRules.isEmpty()) { | 205 | if (affectedRules.isEmpty()) { |
215 | pluginDao.deleteById(pluginId); | 206 | pluginDao.deleteById(pluginId); |
216 | } else { | 207 | } else { |
@@ -244,17 +235,17 @@ public class BasePluginService implements PluginService { | @@ -244,17 +235,17 @@ public class BasePluginService implements PluginService { | ||
244 | } | 235 | } |
245 | }; | 236 | }; |
246 | 237 | ||
247 | - private PaginatedRemover<TenantId, PluginMetaDataEntity> tenantPluginRemover = | ||
248 | - new PaginatedRemover<TenantId, PluginMetaDataEntity>() { | 238 | + private PaginatedRemover<TenantId, PluginMetaData> tenantPluginRemover = |
239 | + new PaginatedRemover<TenantId, PluginMetaData>() { | ||
249 | 240 | ||
250 | @Override | 241 | @Override |
251 | - protected List<PluginMetaDataEntity> findEntities(TenantId id, TextPageLink pageLink) { | 242 | + protected List<PluginMetaData> findEntities(TenantId id, TextPageLink pageLink) { |
252 | return pluginDao.findByTenantIdAndPageLink(id, pageLink); | 243 | return pluginDao.findByTenantIdAndPageLink(id, pageLink); |
253 | } | 244 | } |
254 | 245 | ||
255 | @Override | 246 | @Override |
256 | - protected void removeEntity(PluginMetaDataEntity entity) { | ||
257 | - checkRulesAndDelete(entity.getId()); | 247 | + protected void removeEntity(PluginMetaData entity) { |
248 | + checkRulesAndDelete(entity.getUuidId()); | ||
258 | } | 249 | } |
259 | }; | 250 | }; |
260 | } | 251 | } |
dao/src/main/java/org/thingsboard/server/dao/plugin/CassandraBasePluginDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/plugin/BasePluginDao.java
@@ -15,17 +15,15 @@ | @@ -15,17 +15,15 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.plugin; | 16 | package org.thingsboard.server.dao.plugin; |
17 | 17 | ||
18 | -import com.datastax.driver.core.ResultSet; | ||
19 | import com.datastax.driver.core.querybuilder.Select; | 18 | import com.datastax.driver.core.querybuilder.Select; |
20 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
21 | -import org.slf4j.Logger; | ||
22 | -import org.slf4j.LoggerFactory; | ||
23 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
24 | import org.thingsboard.server.common.data.id.PluginId; | 21 | import org.thingsboard.server.common.data.id.PluginId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.data.page.TextPageLink; | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
27 | import org.thingsboard.server.common.data.plugin.PluginMetaData; | 24 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
28 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 25 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
26 | +import org.thingsboard.server.dao.DaoUtil; | ||
29 | import org.thingsboard.server.dao.model.ModelConstants; | 27 | import org.thingsboard.server.dao.model.ModelConstants; |
30 | import org.thingsboard.server.dao.model.PluginMetaDataEntity; | 28 | import org.thingsboard.server.dao.model.PluginMetaDataEntity; |
31 | 29 | ||
@@ -38,7 +36,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | @@ -38,7 +36,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | ||
38 | 36 | ||
39 | @Component | 37 | @Component |
40 | @Slf4j | 38 | @Slf4j |
41 | -public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> implements PluginDao { | 39 | +public class CassandraBasePluginDao extends CassandraAbstractSearchTextDao<PluginMetaDataEntity, PluginMetaData> implements PluginDao { |
42 | 40 | ||
43 | @Override | 41 | @Override |
44 | protected Class<PluginMetaDataEntity> getColumnFamilyClass() { | 42 | protected Class<PluginMetaDataEntity> getColumnFamilyClass() { |
@@ -51,24 +49,19 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | @@ -51,24 +49,19 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | ||
51 | } | 49 | } |
52 | 50 | ||
53 | @Override | 51 | @Override |
54 | - public PluginMetaDataEntity save(PluginMetaData plugin) { | ||
55 | - return save(new PluginMetaDataEntity(plugin)); | ||
56 | - } | ||
57 | - | ||
58 | - @Override | ||
59 | - public PluginMetaDataEntity findById(PluginId pluginId) { | 52 | + public PluginMetaData findById(PluginId pluginId) { |
60 | log.debug("Search plugin meta-data entity by id [{}]", pluginId); | 53 | log.debug("Search plugin meta-data entity by id [{}]", pluginId); |
61 | - PluginMetaDataEntity entity = super.findById(pluginId.getId()); | 54 | + PluginMetaData pluginMetaData = super.findById(pluginId.getId()); |
62 | if (log.isTraceEnabled()) { | 55 | if (log.isTraceEnabled()) { |
63 | - log.trace("Search result: [{}] for plugin entity [{}]", entity != null, entity); | 56 | + log.trace("Search result: [{}] for plugin entity [{}]", pluginMetaData != null, pluginMetaData); |
64 | } else { | 57 | } else { |
65 | - log.debug("Search result: [{}]", entity != null); | 58 | + log.debug("Search result: [{}]", pluginMetaData != null); |
66 | } | 59 | } |
67 | - return entity; | 60 | + return pluginMetaData; |
68 | } | 61 | } |
69 | 62 | ||
70 | @Override | 63 | @Override |
71 | - public PluginMetaDataEntity findByApiToken(String apiToken) { | 64 | + public PluginMetaData findByApiToken(String apiToken) { |
72 | log.debug("Search plugin meta-data entity by api token [{}]", apiToken); | 65 | log.debug("Search plugin meta-data entity by api token [{}]", apiToken); |
73 | Select.Where query = select().from(ModelConstants.PLUGIN_BY_API_TOKEN_COLUMN_FAMILY_NAME).where(eq(ModelConstants.PLUGIN_API_TOKEN_PROPERTY, apiToken)); | 66 | Select.Where query = select().from(ModelConstants.PLUGIN_BY_API_TOKEN_COLUMN_FAMILY_NAME).where(eq(ModelConstants.PLUGIN_API_TOKEN_PROPERTY, apiToken)); |
74 | log.trace("Execute query [{}]", query); | 67 | log.trace("Execute query [{}]", query); |
@@ -78,14 +71,14 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | @@ -78,14 +71,14 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | ||
78 | } else { | 71 | } else { |
79 | log.debug("Search result: [{}]", entity != null); | 72 | log.debug("Search result: [{}]", entity != null); |
80 | } | 73 | } |
81 | - return entity; | 74 | + return DaoUtil.getData(entity); |
82 | } | 75 | } |
83 | 76 | ||
84 | @Override | 77 | @Override |
85 | public void deleteById(UUID id) { | 78 | public void deleteById(UUID id) { |
86 | log.debug("Delete plugin meta-data entity by id [{}]", id); | 79 | log.debug("Delete plugin meta-data entity by id [{}]", id); |
87 | - ResultSet resultSet = removeById(id); | ||
88 | - log.debug("Delete result: [{}]", resultSet.wasApplied()); | 80 | + boolean result = removeById(id); |
81 | + log.debug("Delete result: [{}]", result); | ||
89 | } | 82 | } |
90 | 83 | ||
91 | @Override | 84 | @Override |
@@ -94,7 +87,7 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | @@ -94,7 +87,7 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | ||
94 | } | 87 | } |
95 | 88 | ||
96 | @Override | 89 | @Override |
97 | - public List<PluginMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { | 90 | + public List<PluginMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { |
98 | log.debug("Try to find plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 91 | log.debug("Try to find plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
99 | List<PluginMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.PLUGIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 92 | List<PluginMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.PLUGIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
100 | Arrays.asList(eq(ModelConstants.PLUGIN_TENANT_ID_PROPERTY, tenantId.getId())), pageLink); | 93 | Arrays.asList(eq(ModelConstants.PLUGIN_TENANT_ID_PROPERTY, tenantId.getId())), pageLink); |
@@ -103,11 +96,11 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | @@ -103,11 +96,11 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | ||
103 | } else { | 96 | } else { |
104 | log.debug("Search result: [{}]", entities.size()); | 97 | log.debug("Search result: [{}]", entities.size()); |
105 | } | 98 | } |
106 | - return entities; | 99 | + return DaoUtil.convertDataList(entities); |
107 | } | 100 | } |
108 | 101 | ||
109 | @Override | 102 | @Override |
110 | - public List<PluginMetaDataEntity> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink) { | 103 | + public List<PluginMetaData> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink) { |
111 | log.debug("Try to find all tenant plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 104 | log.debug("Try to find all tenant plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
112 | List<PluginMetaDataEntity> pluginEntities = findPageWithTextSearch(ModelConstants.PLUGIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 105 | List<PluginMetaDataEntity> pluginEntities = findPageWithTextSearch(ModelConstants.PLUGIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
113 | Arrays.asList(in(ModelConstants.PLUGIN_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), | 106 | Arrays.asList(in(ModelConstants.PLUGIN_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), |
@@ -117,7 +110,7 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | @@ -117,7 +110,7 @@ public class BasePluginDao extends AbstractSearchTextDao<PluginMetaDataEntity> i | ||
117 | } else { | 110 | } else { |
118 | log.debug("Search result: [{}]", pluginEntities.size()); | 111 | log.debug("Search result: [{}]", pluginEntities.size()); |
119 | } | 112 | } |
120 | - return pluginEntities; | 113 | + return DaoUtil.convertDataList(pluginEntities); |
121 | } | 114 | } |
122 | 115 | ||
123 | } | 116 | } |
@@ -20,24 +20,23 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -20,24 +20,23 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
20 | import org.thingsboard.server.common.data.page.TextPageLink; | 20 | import org.thingsboard.server.common.data.page.TextPageLink; |
21 | import org.thingsboard.server.common.data.plugin.PluginMetaData; | 21 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
22 | import org.thingsboard.server.dao.Dao; | 22 | import org.thingsboard.server.dao.Dao; |
23 | -import org.thingsboard.server.dao.model.PluginMetaDataEntity; | ||
24 | 23 | ||
25 | import java.util.List; | 24 | import java.util.List; |
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | -public interface PluginDao extends Dao<PluginMetaDataEntity> { | 27 | +public interface PluginDao extends Dao<PluginMetaData> { |
29 | 28 | ||
30 | - PluginMetaDataEntity save(PluginMetaData plugin); | 29 | + PluginMetaData save(PluginMetaData plugin); |
31 | 30 | ||
32 | - PluginMetaDataEntity findById(PluginId pluginId); | 31 | + PluginMetaData findById(PluginId pluginId); |
33 | 32 | ||
34 | - PluginMetaDataEntity findByApiToken(String apiToken); | 33 | + PluginMetaData findByApiToken(String apiToken); |
35 | 34 | ||
36 | void deleteById(UUID id); | 35 | void deleteById(UUID id); |
37 | 36 | ||
38 | void deleteById(PluginId pluginId); | 37 | void deleteById(PluginId pluginId); |
39 | 38 | ||
40 | - List<PluginMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); | 39 | + List<PluginMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); |
41 | 40 | ||
42 | /** | 41 | /** |
43 | * Find all tenant plugins (including system) by tenantId and page link. | 42 | * Find all tenant plugins (including system) by tenantId and page link. |
@@ -46,6 +45,6 @@ public interface PluginDao extends Dao<PluginMetaDataEntity> { | @@ -46,6 +45,6 @@ public interface PluginDao extends Dao<PluginMetaDataEntity> { | ||
46 | * @param pageLink the page link | 45 | * @param pageLink the page link |
47 | * @return the list of plugins objects | 46 | * @return the list of plugins objects |
48 | */ | 47 | */ |
49 | - List<PluginMetaDataEntity> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink); | 48 | + List<PluginMetaData> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink); |
50 | 49 | ||
51 | } | 50 | } |
@@ -34,7 +34,6 @@ import org.thingsboard.server.dao.component.ComponentDescriptorService; | @@ -34,7 +34,6 @@ import org.thingsboard.server.dao.component.ComponentDescriptorService; | ||
34 | import org.thingsboard.server.dao.exception.DataValidationException; | 34 | import org.thingsboard.server.dao.exception.DataValidationException; |
35 | import org.thingsboard.server.dao.exception.DatabaseException; | 35 | import org.thingsboard.server.dao.exception.DatabaseException; |
36 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 36 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
37 | -import org.thingsboard.server.dao.model.RuleMetaDataEntity; | ||
38 | import org.thingsboard.server.dao.plugin.PluginService; | 37 | import org.thingsboard.server.dao.plugin.PluginService; |
39 | import org.thingsboard.server.dao.service.DataValidator; | 38 | import org.thingsboard.server.dao.service.DataValidator; |
40 | import org.thingsboard.server.dao.service.PaginatedRemover; | 39 | import org.thingsboard.server.dao.service.PaginatedRemover; |
@@ -45,8 +44,6 @@ import java.util.Arrays; | @@ -45,8 +44,6 @@ import java.util.Arrays; | ||
45 | import java.util.List; | 44 | import java.util.List; |
46 | import java.util.function.Function; | 45 | import java.util.function.Function; |
47 | 46 | ||
48 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
49 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
50 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 47 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
51 | import static org.thingsboard.server.dao.service.Validator.validateId; | 48 | import static org.thingsboard.server.dao.service.Validator.validateId; |
52 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; | 49 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
@@ -74,7 +71,7 @@ public class BaseRuleService implements RuleService { | @@ -74,7 +71,7 @@ public class BaseRuleService implements RuleService { | ||
74 | rule.setTenantId(systemTenantId); | 71 | rule.setTenantId(systemTenantId); |
75 | } | 72 | } |
76 | if (rule.getId() != null) { | 73 | if (rule.getId() != null) { |
77 | - RuleMetaData oldVersion = getData(ruleDao.findById(rule.getId())); | 74 | + RuleMetaData oldVersion = ruleDao.findById(rule.getId()); |
78 | if (rule.getState() == null) { | 75 | if (rule.getState() == null) { |
79 | rule.setState(oldVersion.getState()); | 76 | rule.setState(oldVersion.getState()); |
80 | } else if (rule.getState() != oldVersion.getState()) { | 77 | } else if (rule.getState() != oldVersion.getState()) { |
@@ -94,7 +91,7 @@ public class BaseRuleService implements RuleService { | @@ -94,7 +91,7 @@ public class BaseRuleService implements RuleService { | ||
94 | } | 91 | } |
95 | validateComponentJson(rule.getAction(), ComponentType.ACTION); | 92 | validateComponentJson(rule.getAction(), ComponentType.ACTION); |
96 | validateRuleAndPluginState(rule); | 93 | validateRuleAndPluginState(rule); |
97 | - return getData(ruleDao.save(rule)); | 94 | + return ruleDao.save(rule); |
98 | } | 95 | } |
99 | 96 | ||
100 | private void validateFilters(JsonNode filtersJson) { | 97 | private void validateFilters(JsonNode filtersJson) { |
@@ -163,30 +160,27 @@ public class BaseRuleService implements RuleService { | @@ -163,30 +160,27 @@ public class BaseRuleService implements RuleService { | ||
163 | @Override | 160 | @Override |
164 | public RuleMetaData findRuleById(RuleId ruleId) { | 161 | public RuleMetaData findRuleById(RuleId ruleId) { |
165 | validateId(ruleId, "Incorrect rule id for search rule request."); | 162 | validateId(ruleId, "Incorrect rule id for search rule request."); |
166 | - return getData(ruleDao.findById(ruleId.getId())); | 163 | + return ruleDao.findById(ruleId.getId()); |
167 | } | 164 | } |
168 | 165 | ||
169 | @Override | 166 | @Override |
170 | public List<RuleMetaData> findPluginRules(String pluginToken) { | 167 | public List<RuleMetaData> findPluginRules(String pluginToken) { |
171 | - List<RuleMetaDataEntity> ruleEntities = ruleDao.findRulesByPlugin(pluginToken); | ||
172 | - return convertDataList(ruleEntities); | 168 | + return ruleDao.findRulesByPlugin(pluginToken); |
173 | } | 169 | } |
174 | 170 | ||
175 | @Override | 171 | @Override |
176 | public TextPageData<RuleMetaData> findSystemRules(TextPageLink pageLink) { | 172 | public TextPageData<RuleMetaData> findSystemRules(TextPageLink pageLink) { |
177 | validatePageLink(pageLink, "Incorrect PageLink object for search rule request."); | 173 | validatePageLink(pageLink, "Incorrect PageLink object for search rule request."); |
178 | - List<RuleMetaDataEntity> ruleEntities = ruleDao.findByTenantIdAndPageLink(systemTenantId, pageLink); | ||
179 | - List<RuleMetaData> plugins = convertDataList(ruleEntities); | ||
180 | - return new TextPageData<>(plugins, pageLink); | 174 | + List<RuleMetaData> rules = ruleDao.findByTenantIdAndPageLink(systemTenantId, pageLink); |
175 | + return new TextPageData<>(rules, pageLink); | ||
181 | } | 176 | } |
182 | 177 | ||
183 | @Override | 178 | @Override |
184 | public TextPageData<RuleMetaData> findTenantRules(TenantId tenantId, TextPageLink pageLink) { | 179 | public TextPageData<RuleMetaData> findTenantRules(TenantId tenantId, TextPageLink pageLink) { |
185 | validateId(tenantId, "Incorrect tenant id for search rule request."); | 180 | validateId(tenantId, "Incorrect tenant id for search rule request."); |
186 | validatePageLink(pageLink, "Incorrect PageLink object for search rule request."); | 181 | validatePageLink(pageLink, "Incorrect PageLink object for search rule request."); |
187 | - List<RuleMetaDataEntity> ruleEntities = ruleDao.findByTenantIdAndPageLink(tenantId, pageLink); | ||
188 | - List<RuleMetaData> plugins = convertDataList(ruleEntities); | ||
189 | - return new TextPageData<>(plugins, pageLink); | 182 | + List<RuleMetaData> rules = ruleDao.findByTenantIdAndPageLink(tenantId, pageLink); |
183 | + return new TextPageData<>(rules, pageLink); | ||
190 | } | 184 | } |
191 | 185 | ||
192 | @Override | 186 | @Override |
@@ -210,8 +204,7 @@ public class BaseRuleService implements RuleService { | @@ -210,8 +204,7 @@ public class BaseRuleService implements RuleService { | ||
210 | log.trace("Executing findAllTenantRulesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 204 | log.trace("Executing findAllTenantRulesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
211 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 205 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
212 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 206 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
213 | - List<RuleMetaDataEntity> rulesEntities = ruleDao.findAllTenantRulesByTenantId(tenantId.getId(), pageLink); | ||
214 | - List<RuleMetaData> rules = convertDataList(rulesEntities); | 207 | + List<RuleMetaData> rules = ruleDao.findAllTenantRulesByTenantId(tenantId.getId(), pageLink); |
215 | return new TextPageData<>(rules, pageLink); | 208 | return new TextPageData<>(rules, pageLink); |
216 | } | 209 | } |
217 | 210 | ||
@@ -251,10 +244,10 @@ public class BaseRuleService implements RuleService { | @@ -251,10 +244,10 @@ public class BaseRuleService implements RuleService { | ||
251 | 244 | ||
252 | private void updateLifeCycleState(RuleId ruleId, ComponentLifecycleState state) { | 245 | private void updateLifeCycleState(RuleId ruleId, ComponentLifecycleState state) { |
253 | Validator.validateId(ruleId, "Incorrect rule id for state change request."); | 246 | Validator.validateId(ruleId, "Incorrect rule id for state change request."); |
254 | - RuleMetaDataEntity rule = ruleDao.findById(ruleId); | 247 | + RuleMetaData rule = ruleDao.findById(ruleId); |
255 | if (rule != null) { | 248 | if (rule != null) { |
256 | rule.setState(state); | 249 | rule.setState(state); |
257 | - validateRuleAndPluginState(getData(rule)); | 250 | + validateRuleAndPluginState(rule); |
258 | ruleDao.save(rule); | 251 | ruleDao.save(rule); |
259 | } else { | 252 | } else { |
260 | throw new DatabaseException("Plugin not found!"); | 253 | throw new DatabaseException("Plugin not found!"); |
@@ -277,17 +270,17 @@ public class BaseRuleService implements RuleService { | @@ -277,17 +270,17 @@ public class BaseRuleService implements RuleService { | ||
277 | } | 270 | } |
278 | }; | 271 | }; |
279 | 272 | ||
280 | - private PaginatedRemover<TenantId, RuleMetaDataEntity> tenantRulesRemover = | ||
281 | - new PaginatedRemover<TenantId, RuleMetaDataEntity>() { | 273 | + private PaginatedRemover<TenantId, RuleMetaData> tenantRulesRemover = |
274 | + new PaginatedRemover<TenantId, RuleMetaData>() { | ||
282 | 275 | ||
283 | @Override | 276 | @Override |
284 | - protected List<RuleMetaDataEntity> findEntities(TenantId id, TextPageLink pageLink) { | 277 | + protected List<RuleMetaData> findEntities(TenantId id, TextPageLink pageLink) { |
285 | return ruleDao.findByTenantIdAndPageLink(id, pageLink); | 278 | return ruleDao.findByTenantIdAndPageLink(id, pageLink); |
286 | } | 279 | } |
287 | 280 | ||
288 | @Override | 281 | @Override |
289 | - protected void removeEntity(RuleMetaDataEntity entity) { | ||
290 | - ruleDao.deleteById(entity.getId()); | 282 | + protected void removeEntity(RuleMetaData entity) { |
283 | + ruleDao.deleteById(entity.getUuidId()); | ||
291 | } | 284 | } |
292 | }; | 285 | }; |
293 | 286 |
dao/src/main/java/org/thingsboard/server/dao/rule/CassandraBaseRuleDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleDao.java
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.rule; | 16 | package org.thingsboard.server.dao.rule; |
17 | 17 | ||
18 | -import com.datastax.driver.core.ResultSet; | ||
19 | import com.datastax.driver.core.querybuilder.Select; | 18 | import com.datastax.driver.core.querybuilder.Select; |
20 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
@@ -23,7 +22,8 @@ import org.thingsboard.server.common.data.id.RuleId; | @@ -23,7 +22,8 @@ import org.thingsboard.server.common.data.id.RuleId; | ||
23 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.data.page.TextPageLink; | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
25 | import org.thingsboard.server.common.data.rule.RuleMetaData; | 24 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
26 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 25 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
26 | +import org.thingsboard.server.dao.DaoUtil; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 27 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.model.RuleMetaDataEntity; | 28 | import org.thingsboard.server.dao.model.RuleMetaDataEntity; |
29 | 29 | ||
@@ -36,7 +36,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | @@ -36,7 +36,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | ||
36 | 36 | ||
37 | @Component | 37 | @Component |
38 | @Slf4j | 38 | @Slf4j |
39 | -public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> implements RuleDao { | 39 | +public class CassandraBaseRuleDao extends CassandraAbstractSearchTextDao<RuleMetaDataEntity, RuleMetaData> implements RuleDao { |
40 | 40 | ||
41 | @Override | 41 | @Override |
42 | protected Class<RuleMetaDataEntity> getColumnFamilyClass() { | 42 | protected Class<RuleMetaDataEntity> getColumnFamilyClass() { |
@@ -49,17 +49,12 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | @@ -49,17 +49,12 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | ||
49 | } | 49 | } |
50 | 50 | ||
51 | @Override | 51 | @Override |
52 | - public RuleMetaDataEntity findById(RuleId ruleId) { | 52 | + public RuleMetaData findById(RuleId ruleId) { |
53 | return findById(ruleId.getId()); | 53 | return findById(ruleId.getId()); |
54 | } | 54 | } |
55 | 55 | ||
56 | @Override | 56 | @Override |
57 | - public RuleMetaDataEntity save(RuleMetaData rule) { | ||
58 | - return save(new RuleMetaDataEntity(rule)); | ||
59 | - } | ||
60 | - | ||
61 | - @Override | ||
62 | - public List<RuleMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { | 57 | + public List<RuleMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { |
63 | log.debug("Try to find rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 58 | log.debug("Try to find rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
64 | List<RuleMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.RULE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 59 | List<RuleMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.RULE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
65 | Arrays.asList(eq(ModelConstants.RULE_TENANT_ID_PROPERTY, tenantId.getId())), pageLink); | 60 | Arrays.asList(eq(ModelConstants.RULE_TENANT_ID_PROPERTY, tenantId.getId())), pageLink); |
@@ -68,11 +63,11 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | @@ -68,11 +63,11 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | ||
68 | } else { | 63 | } else { |
69 | log.debug("Search result: [{}]", entities.size()); | 64 | log.debug("Search result: [{}]", entities.size()); |
70 | } | 65 | } |
71 | - return entities; | 66 | + return DaoUtil.convertDataList(entities); |
72 | } | 67 | } |
73 | 68 | ||
74 | @Override | 69 | @Override |
75 | - public List<RuleMetaDataEntity> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink) { | 70 | + public List<RuleMetaData> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink) { |
76 | log.debug("Try to find all tenant rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 71 | log.debug("Try to find all tenant rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
77 | List<RuleMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.RULE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 72 | List<RuleMetaDataEntity> entities = findPageWithTextSearch(ModelConstants.RULE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
78 | Arrays.asList(in(ModelConstants.RULE_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), | 73 | Arrays.asList(in(ModelConstants.RULE_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), |
@@ -82,23 +77,23 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | @@ -82,23 +77,23 @@ public class BaseRuleDao extends AbstractSearchTextDao<RuleMetaDataEntity> imple | ||
82 | } else { | 77 | } else { |
83 | log.debug("Search result: [{}]", entities.size()); | 78 | log.debug("Search result: [{}]", entities.size()); |
84 | } | 79 | } |
85 | - return entities; | 80 | + return DaoUtil.convertDataList(entities); |
86 | } | 81 | } |
87 | 82 | ||
88 | @Override | 83 | @Override |
89 | - public List<RuleMetaDataEntity> findRulesByPlugin(String pluginToken) { | 84 | + public List<RuleMetaData> findRulesByPlugin(String pluginToken) { |
90 | log.debug("Search rules by api token [{}]", pluginToken); | 85 | log.debug("Search rules by api token [{}]", pluginToken); |
91 | Select select = select().from(ModelConstants.RULE_BY_PLUGIN_TOKEN); | 86 | Select select = select().from(ModelConstants.RULE_BY_PLUGIN_TOKEN); |
92 | Select.Where query = select.where(); | 87 | Select.Where query = select.where(); |
93 | query.and(eq(ModelConstants.RULE_PLUGIN_TOKEN_PROPERTY, pluginToken)); | 88 | query.and(eq(ModelConstants.RULE_PLUGIN_TOKEN_PROPERTY, pluginToken)); |
94 | - return findListByStatement(query); | 89 | + return DaoUtil.convertDataList(findListByStatement(query)); |
95 | } | 90 | } |
96 | 91 | ||
97 | @Override | 92 | @Override |
98 | public void deleteById(UUID id) { | 93 | public void deleteById(UUID id) { |
99 | log.debug("Delete rule meta-data entity by id [{}]", id); | 94 | log.debug("Delete rule meta-data entity by id [{}]", id); |
100 | - ResultSet resultSet = removeById(id); | ||
101 | - log.debug("Delete result: [{}]", resultSet.wasApplied()); | 95 | + boolean result = removeById(id); |
96 | + log.debug("Delete result: [{}]", result); | ||
102 | } | 97 | } |
103 | 98 | ||
104 | @Override | 99 | @Override |
@@ -20,20 +20,19 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -20,20 +20,19 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
20 | import org.thingsboard.server.common.data.page.TextPageLink; | 20 | import org.thingsboard.server.common.data.page.TextPageLink; |
21 | import org.thingsboard.server.common.data.rule.RuleMetaData; | 21 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
22 | import org.thingsboard.server.dao.Dao; | 22 | import org.thingsboard.server.dao.Dao; |
23 | -import org.thingsboard.server.dao.model.RuleMetaDataEntity; | ||
24 | 23 | ||
25 | import java.util.List; | 24 | import java.util.List; |
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 | ||
28 | -public interface RuleDao extends Dao<RuleMetaDataEntity> { | 27 | +public interface RuleDao extends Dao<RuleMetaData> { |
29 | 28 | ||
30 | - RuleMetaDataEntity save(RuleMetaData rule); | 29 | + RuleMetaData save(RuleMetaData rule); |
31 | 30 | ||
32 | - RuleMetaDataEntity findById(RuleId ruleId); | 31 | + RuleMetaData findById(RuleId ruleId); |
33 | 32 | ||
34 | - List<RuleMetaDataEntity> findRulesByPlugin(String pluginToken); | 33 | + List<RuleMetaData> findRulesByPlugin(String pluginToken); |
35 | 34 | ||
36 | - List<RuleMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); | 35 | + List<RuleMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); |
37 | 36 | ||
38 | /** | 37 | /** |
39 | * Find all tenant rules (including system) by tenantId and page link. | 38 | * Find all tenant rules (including system) by tenantId and page link. |
@@ -42,7 +41,7 @@ public interface RuleDao extends Dao<RuleMetaDataEntity> { | @@ -42,7 +41,7 @@ public interface RuleDao extends Dao<RuleMetaDataEntity> { | ||
42 | * @param pageLink the page link | 41 | * @param pageLink the page link |
43 | * @return the list of rules objects | 42 | * @return the list of rules objects |
44 | */ | 43 | */ |
45 | - List<RuleMetaDataEntity> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink); | 44 | + List<RuleMetaData> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink); |
46 | 45 | ||
47 | void deleteById(UUID id); | 46 | void deleteById(UUID id); |
48 | 47 |
@@ -15,18 +15,15 @@ | @@ -15,18 +15,15 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.service; | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | ||
18 | -import java.util.HashSet; | ||
19 | -import java.util.Iterator; | ||
20 | -import java.util.Set; | ||
21 | - | 18 | +import com.fasterxml.jackson.databind.JsonNode; |
22 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
23 | import org.apache.commons.validator.routines.EmailValidator; | 20 | import org.apache.commons.validator.routines.EmailValidator; |
24 | import org.thingsboard.server.common.data.BaseData; | 21 | import org.thingsboard.server.common.data.BaseData; |
25 | import org.thingsboard.server.dao.exception.DataValidationException; | 22 | import org.thingsboard.server.dao.exception.DataValidationException; |
26 | -import org.slf4j.Logger; | ||
27 | -import org.slf4j.LoggerFactory; | ||
28 | 23 | ||
29 | -import com.fasterxml.jackson.databind.JsonNode; | 24 | +import java.util.HashSet; |
25 | +import java.util.Iterator; | ||
26 | +import java.util.Set; | ||
30 | 27 | ||
31 | @Slf4j | 28 | @Slf4j |
32 | public abstract class DataValidator<D extends BaseData<?>> { | 29 | public abstract class DataValidator<D extends BaseData<?>> { |
1 | /** | 1 | /** |
2 | * Copyright © 2016-2017 The Thingsboard Authors | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * | 3 | + * <p> |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with 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 | 6 | * You may obtain a copy of the License at |
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | 7 | + * <p> |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * <p> | ||
10 | * Unless required by applicable law or agreed to in writing, software | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -15,33 +15,35 @@ | @@ -15,33 +15,35 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.service; | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | ||
18 | +import org.thingsboard.server.common.data.id.IdBased; | ||
19 | +import org.thingsboard.server.common.data.page.TextPageLink; | ||
20 | + | ||
18 | import java.util.List; | 21 | import java.util.List; |
19 | import java.util.UUID; | 22 | import java.util.UUID; |
20 | 23 | ||
21 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
22 | -import org.thingsboard.server.dao.model.BaseEntity; | 24 | +public abstract class PaginatedRemover<I, D extends IdBased<?>> { |
23 | 25 | ||
24 | -public abstract class PaginatedRemover<I, E extends BaseEntity<?>> { | 26 | + private static final int DEFAULT_LIMIT = 100; |
25 | 27 | ||
26 | public void removeEntitites(I id) { | 28 | public void removeEntitites(I id) { |
27 | - TextPageLink pageLink = new TextPageLink(100); | 29 | + TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT); |
28 | boolean hasNext = true; | 30 | boolean hasNext = true; |
29 | while (hasNext) { | 31 | while (hasNext) { |
30 | - List<E> entities = findEntities(id, pageLink); | ||
31 | - for (E entity : entities) { | 32 | + List<D> entities = findEntities(id, pageLink); |
33 | + for (D entity : entities) { | ||
32 | removeEntity(entity); | 34 | removeEntity(entity); |
33 | } | 35 | } |
34 | hasNext = entities.size() == pageLink.getLimit(); | 36 | hasNext = entities.size() == pageLink.getLimit(); |
35 | if (hasNext) { | 37 | if (hasNext) { |
36 | - int index = entities.size()-1; | ||
37 | - UUID idOffset = entities.get(index).getId(); | 38 | + int index = entities.size() - 1; |
39 | + UUID idOffset = entities.get(index).getUuidId(); | ||
38 | pageLink.setIdOffset(idOffset); | 40 | pageLink.setIdOffset(idOffset); |
39 | } | 41 | } |
40 | - } | 42 | + } |
41 | } | 43 | } |
42 | - | ||
43 | - protected abstract List<E> findEntities(I id, TextPageLink pageLink); | ||
44 | - | ||
45 | - protected abstract void removeEntity(E entity); | ||
46 | - | 44 | + |
45 | + protected abstract List<D> findEntities(I id, TextPageLink pageLink); | ||
46 | + | ||
47 | + protected abstract void removeEntity(D entity); | ||
48 | + | ||
47 | } | 49 | } |
@@ -17,9 +17,8 @@ package org.thingsboard.server.dao.settings; | @@ -17,9 +17,8 @@ package org.thingsboard.server.dao.settings; | ||
17 | 17 | ||
18 | import org.thingsboard.server.common.data.AdminSettings; | 18 | import org.thingsboard.server.common.data.AdminSettings; |
19 | import org.thingsboard.server.dao.Dao; | 19 | import org.thingsboard.server.dao.Dao; |
20 | -import org.thingsboard.server.dao.model.AdminSettingsEntity; | ||
21 | 20 | ||
22 | -public interface AdminSettingsDao extends Dao<AdminSettingsEntity> { | 21 | +public interface AdminSettingsDao extends Dao<AdminSettings> { |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Save or update admin settings object | 24 | * Save or update admin settings object |
@@ -27,7 +26,7 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> { | @@ -27,7 +26,7 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> { | ||
27 | * @param adminSettings the admin settings object | 26 | * @param adminSettings the admin settings object |
28 | * @return saved admin settings object | 27 | * @return saved admin settings object |
29 | */ | 28 | */ |
30 | - AdminSettingsEntity save(AdminSettings adminSettings); | 29 | + AdminSettings save(AdminSettings adminSettings); |
31 | 30 | ||
32 | /** | 31 | /** |
33 | * Find admin settings by key. | 32 | * Find admin settings by key. |
@@ -35,6 +34,6 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> { | @@ -35,6 +34,6 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> { | ||
35 | * @param key the key | 34 | * @param key the key |
36 | * @return the admin settings object | 35 | * @return the admin settings object |
37 | */ | 36 | */ |
38 | - AdminSettingsEntity findByKey(String key); | 37 | + AdminSettings findByKey(String key); |
39 | 38 | ||
40 | } | 39 | } |
@@ -20,10 +20,10 @@ import org.thingsboard.server.common.data.id.AdminSettingsId; | @@ -20,10 +20,10 @@ import org.thingsboard.server.common.data.id.AdminSettingsId; | ||
20 | 20 | ||
21 | public interface AdminSettingsService { | 21 | public interface AdminSettingsService { |
22 | 22 | ||
23 | - public AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId); | 23 | + AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId); |
24 | 24 | ||
25 | - public AdminSettings findAdminSettingsByKey(String key); | 25 | + AdminSettings findAdminSettingsByKey(String key); |
26 | 26 | ||
27 | - public AdminSettings saveAdminSettings(AdminSettings adminSettings); | 27 | + AdminSettings saveAdminSettings(AdminSettings adminSettings); |
28 | 28 | ||
29 | } | 29 | } |
@@ -15,19 +15,14 @@ | @@ -15,19 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.settings; | 16 | package org.thingsboard.server.dao.settings; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
19 | - | ||
20 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
21 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
21 | +import org.springframework.stereotype.Service; | ||
22 | import org.thingsboard.server.common.data.AdminSettings; | 22 | import org.thingsboard.server.common.data.AdminSettings; |
23 | import org.thingsboard.server.common.data.id.AdminSettingsId; | 23 | import org.thingsboard.server.common.data.id.AdminSettingsId; |
24 | import org.thingsboard.server.dao.exception.DataValidationException; | 24 | import org.thingsboard.server.dao.exception.DataValidationException; |
25 | -import org.thingsboard.server.dao.model.AdminSettingsEntity; | ||
26 | import org.thingsboard.server.dao.service.DataValidator; | 25 | import org.thingsboard.server.dao.service.DataValidator; |
27 | -import org.slf4j.Logger; | ||
28 | -import org.slf4j.LoggerFactory; | ||
29 | -import org.springframework.beans.factory.annotation.Autowired; | ||
30 | -import org.springframework.stereotype.Service; | ||
31 | import org.thingsboard.server.dao.service.Validator; | 26 | import org.thingsboard.server.dao.service.Validator; |
32 | 27 | ||
33 | @Service | 28 | @Service |
@@ -41,24 +36,21 @@ public class AdminSettingsServiceImpl implements AdminSettingsService { | @@ -41,24 +36,21 @@ public class AdminSettingsServiceImpl implements AdminSettingsService { | ||
41 | public AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId) { | 36 | public AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId) { |
42 | log.trace("Executing findAdminSettingsById [{}]", adminSettingsId); | 37 | log.trace("Executing findAdminSettingsById [{}]", adminSettingsId); |
43 | Validator.validateId(adminSettingsId, "Incorrect adminSettingsId " + adminSettingsId); | 38 | Validator.validateId(adminSettingsId, "Incorrect adminSettingsId " + adminSettingsId); |
44 | - AdminSettingsEntity adminSettingsEntity = adminSettingsDao.findById(adminSettingsId.getId()); | ||
45 | - return getData(adminSettingsEntity); | 39 | + return adminSettingsDao.findById(adminSettingsId.getId()); |
46 | } | 40 | } |
47 | 41 | ||
48 | @Override | 42 | @Override |
49 | public AdminSettings findAdminSettingsByKey(String key) { | 43 | public AdminSettings findAdminSettingsByKey(String key) { |
50 | log.trace("Executing findAdminSettingsByKey [{}]", key); | 44 | log.trace("Executing findAdminSettingsByKey [{}]", key); |
51 | Validator.validateString(key, "Incorrect key " + key); | 45 | Validator.validateString(key, "Incorrect key " + key); |
52 | - AdminSettingsEntity adminSettingsEntity = adminSettingsDao.findByKey(key); | ||
53 | - return getData(adminSettingsEntity); | 46 | + return adminSettingsDao.findByKey(key); |
54 | } | 47 | } |
55 | 48 | ||
56 | @Override | 49 | @Override |
57 | public AdminSettings saveAdminSettings(AdminSettings adminSettings) { | 50 | public AdminSettings saveAdminSettings(AdminSettings adminSettings) { |
58 | log.trace("Executing saveAdminSettings [{}]", adminSettings); | 51 | log.trace("Executing saveAdminSettings [{}]", adminSettings); |
59 | adminSettingsValidator.validate(adminSettings); | 52 | adminSettingsValidator.validate(adminSettings); |
60 | - AdminSettingsEntity adminSettingsEntity = adminSettingsDao.save(adminSettings); | ||
61 | - return getData(adminSettingsEntity); | 53 | + return adminSettingsDao.save(adminSettings); |
62 | } | 54 | } |
63 | 55 | ||
64 | private DataValidator<AdminSettings> adminSettingsValidator = | 56 | private DataValidator<AdminSettings> adminSettingsValidator = |
dao/src/main/java/org/thingsboard/server/dao/settings/CassandraAdminSettingsDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsDaoImpl.java
@@ -15,26 +15,21 @@ | @@ -15,26 +15,21 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.settings; | 16 | package org.thingsboard.server.dao.settings; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
20 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_BY_KEY_COLUMN_FAMILY_NAME; | ||
21 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; | ||
22 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_KEY_PROPERTY; | ||
23 | - | 18 | +import com.datastax.driver.core.querybuilder.Select.Where; |
24 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
25 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
26 | import org.thingsboard.server.common.data.AdminSettings; | 21 | import org.thingsboard.server.common.data.AdminSettings; |
27 | -import org.thingsboard.server.dao.AbstractModelDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractModelDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
28 | import org.thingsboard.server.dao.model.AdminSettingsEntity; | 24 | import org.thingsboard.server.dao.model.AdminSettingsEntity; |
29 | -import org.slf4j.Logger; | ||
30 | -import org.slf4j.LoggerFactory; | ||
31 | -import org.springframework.stereotype.Repository; | ||
32 | 25 | ||
33 | -import com.datastax.driver.core.querybuilder.Select.Where; | 26 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
27 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
28 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
34 | 29 | ||
35 | @Component | 30 | @Component |
36 | @Slf4j | 31 | @Slf4j |
37 | -public class AdminSettingsDaoImpl extends AbstractModelDao<AdminSettingsEntity> implements AdminSettingsDao { | 32 | +public class CassandraAdminSettingsDao extends CassandraAbstractModelDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao { |
38 | 33 | ||
39 | @Override | 34 | @Override |
40 | protected Class<AdminSettingsEntity> getColumnFamilyClass() { | 35 | protected Class<AdminSettingsEntity> getColumnFamilyClass() { |
@@ -45,21 +40,15 @@ public class AdminSettingsDaoImpl extends AbstractModelDao<AdminSettingsEntity> | @@ -45,21 +40,15 @@ public class AdminSettingsDaoImpl extends AbstractModelDao<AdminSettingsEntity> | ||
45 | protected String getColumnFamilyName() { | 40 | protected String getColumnFamilyName() { |
46 | return ADMIN_SETTINGS_COLUMN_FAMILY_NAME; | 41 | return ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
47 | } | 42 | } |
48 | - | ||
49 | - @Override | ||
50 | - public AdminSettingsEntity save(AdminSettings adminSettings) { | ||
51 | - log.debug("Save admin settings [{}] ", adminSettings); | ||
52 | - return save(new AdminSettingsEntity(adminSettings)); | ||
53 | - } | ||
54 | 43 | ||
55 | @Override | 44 | @Override |
56 | - public AdminSettingsEntity findByKey(String key) { | 45 | + public AdminSettings findByKey(String key) { |
57 | log.debug("Try to find admin settings by key [{}] ", key); | 46 | log.debug("Try to find admin settings by key [{}] ", key); |
58 | Where query = select().from(ADMIN_SETTINGS_BY_KEY_COLUMN_FAMILY_NAME).where(eq(ADMIN_SETTINGS_KEY_PROPERTY, key)); | 47 | Where query = select().from(ADMIN_SETTINGS_BY_KEY_COLUMN_FAMILY_NAME).where(eq(ADMIN_SETTINGS_KEY_PROPERTY, key)); |
59 | log.trace("Execute query {}", query); | 48 | log.trace("Execute query {}", query); |
60 | AdminSettingsEntity adminSettingsEntity = findOneByStatement(query); | 49 | AdminSettingsEntity adminSettingsEntity = findOneByStatement(query); |
61 | log.trace("Found admin settings [{}] by key [{}]", adminSettingsEntity, key); | 50 | log.trace("Found admin settings [{}] by key [{}]", adminSettingsEntity, key); |
62 | - return adminSettingsEntity; | 51 | + return DaoUtil.getData(adminSettingsEntity); |
63 | } | 52 | } |
64 | 53 | ||
65 | } | 54 | } |
dao/src/main/java/org/thingsboard/server/dao/tenant/CassandraTenantDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantDaoImpl.java
@@ -15,26 +15,23 @@ | @@ -15,26 +15,23 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.tenant; | 16 | package org.thingsboard.server.dao.tenant; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_BY_REGION_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; | ||
20 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_COLUMN_FAMILY_NAME; | ||
21 | -import static org.thingsboard.server.dao.model.ModelConstants.TENANT_REGION_PROPERTY; | ||
22 | - | ||
23 | -import java.util.Arrays; | ||
24 | -import java.util.List; | ||
25 | - | ||
26 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
27 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
28 | import org.thingsboard.server.common.data.Tenant; | 20 | import org.thingsboard.server.common.data.Tenant; |
29 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
30 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
31 | import org.thingsboard.server.dao.model.TenantEntity; | 24 | import org.thingsboard.server.dao.model.TenantEntity; |
32 | -import org.slf4j.Logger; | ||
33 | -import org.slf4j.LoggerFactory; | 25 | + |
26 | +import java.util.Arrays; | ||
27 | +import java.util.List; | ||
28 | + | ||
29 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
30 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
34 | 31 | ||
35 | @Component | 32 | @Component |
36 | @Slf4j | 33 | @Slf4j |
37 | -public class TenantDaoImpl extends AbstractSearchTextDao<TenantEntity> implements TenantDao { | 34 | +public class CassandraTenantDao extends CassandraAbstractSearchTextDao<TenantEntity, Tenant> implements TenantDao { |
38 | 35 | ||
39 | @Override | 36 | @Override |
40 | protected Class<TenantEntity> getColumnFamilyClass() { | 37 | protected Class<TenantEntity> getColumnFamilyClass() { |
@@ -45,21 +42,15 @@ public class TenantDaoImpl extends AbstractSearchTextDao<TenantEntity> implement | @@ -45,21 +42,15 @@ public class TenantDaoImpl extends AbstractSearchTextDao<TenantEntity> implement | ||
45 | protected String getColumnFamilyName() { | 42 | protected String getColumnFamilyName() { |
46 | return TENANT_COLUMN_FAMILY_NAME; | 43 | return TENANT_COLUMN_FAMILY_NAME; |
47 | } | 44 | } |
48 | - | ||
49 | - @Override | ||
50 | - public TenantEntity save(Tenant tenant) { | ||
51 | - log.debug("Save tenant [{}] ", tenant); | ||
52 | - return save(new TenantEntity(tenant)); | ||
53 | - } | ||
54 | 45 | ||
55 | @Override | 46 | @Override |
56 | - public List<TenantEntity> findTenantsByRegion(String region, TextPageLink pageLink) { | 47 | + public List<Tenant> findTenantsByRegion(String region, TextPageLink pageLink) { |
57 | log.debug("Try to find tenants by region [{}] and pageLink [{}]", region, pageLink); | 48 | log.debug("Try to find tenants by region [{}] and pageLink [{}]", region, pageLink); |
58 | List<TenantEntity> tenantEntities = findPageWithTextSearch(TENANT_BY_REGION_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 49 | List<TenantEntity> tenantEntities = findPageWithTextSearch(TENANT_BY_REGION_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
59 | Arrays.asList(eq(TENANT_REGION_PROPERTY, region)), | 50 | Arrays.asList(eq(TENANT_REGION_PROPERTY, region)), |
60 | pageLink); | 51 | pageLink); |
61 | log.trace("Found tenants [{}] by region [{}] and pageLink [{}]", tenantEntities, region, pageLink); | 52 | log.trace("Found tenants [{}] by region [{}] and pageLink [{}]", tenantEntities, region, pageLink); |
62 | - return tenantEntities; | 53 | + return DaoUtil.convertDataList(tenantEntities); |
63 | } | 54 | } |
64 | 55 | ||
65 | } | 56 | } |
@@ -15,14 +15,13 @@ | @@ -15,14 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.tenant; | 16 | package org.thingsboard.server.dao.tenant; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | - | ||
20 | import org.thingsboard.server.common.data.Tenant; | 18 | import org.thingsboard.server.common.data.Tenant; |
21 | import org.thingsboard.server.common.data.page.TextPageLink; | 19 | import org.thingsboard.server.common.data.page.TextPageLink; |
22 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
23 | -import org.thingsboard.server.dao.model.TenantEntity; | ||
24 | 21 | ||
25 | -public interface TenantDao extends Dao<TenantEntity> { | 22 | +import java.util.List; |
23 | + | ||
24 | +public interface TenantDao extends Dao<Tenant> { | ||
26 | 25 | ||
27 | /** | 26 | /** |
28 | * Save or update tenant object | 27 | * Save or update tenant object |
@@ -30,7 +29,7 @@ public interface TenantDao extends Dao<TenantEntity> { | @@ -30,7 +29,7 @@ public interface TenantDao extends Dao<TenantEntity> { | ||
30 | * @param tenant the tenant object | 29 | * @param tenant the tenant object |
31 | * @return saved tenant object | 30 | * @return saved tenant object |
32 | */ | 31 | */ |
33 | - TenantEntity save(Tenant tenant); | 32 | + Tenant save(Tenant tenant); |
34 | 33 | ||
35 | /** | 34 | /** |
36 | * Find tenants by region and page link. | 35 | * Find tenants by region and page link. |
@@ -39,6 +38,6 @@ public interface TenantDao extends Dao<TenantEntity> { | @@ -39,6 +38,6 @@ public interface TenantDao extends Dao<TenantEntity> { | ||
39 | * @param pageLink the page link | 38 | * @param pageLink the page link |
40 | * @return the list of tenant objects | 39 | * @return the list of tenant objects |
41 | */ | 40 | */ |
42 | - List<TenantEntity> findTenantsByRegion(String region, TextPageLink pageLink); | 41 | + List<Tenant> findTenantsByRegion(String region, TextPageLink pageLink); |
43 | 42 | ||
44 | } | 43 | } |
@@ -22,16 +22,14 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -22,16 +22,14 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
22 | 22 | ||
23 | public interface TenantService { | 23 | public interface TenantService { |
24 | 24 | ||
25 | - public Tenant findTenantById(TenantId tenantId); | 25 | + Tenant findTenantById(TenantId tenantId); |
26 | 26 | ||
27 | - public Tenant saveTenant(Tenant tenant); | 27 | + Tenant saveTenant(Tenant tenant); |
28 | 28 | ||
29 | - public void deleteTenant(TenantId tenantId); | 29 | + void deleteTenant(TenantId tenantId); |
30 | 30 | ||
31 | - public TextPageData<Tenant> findTenants(TextPageLink pageLink); | 31 | + TextPageData<Tenant> findTenants(TextPageLink pageLink); |
32 | 32 | ||
33 | - //public TextPageData<Tenant> findTenantsByTitle(String title, PageLink pageLink); | ||
34 | - | ||
35 | - public void deleteTenants(); | 33 | + void deleteTenants(); |
36 | 34 | ||
37 | } | 35 | } |
@@ -15,13 +15,10 @@ | @@ -15,13 +15,10 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.tenant; | 16 | package org.thingsboard.server.dao.tenant; |
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 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
24 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
21 | +import org.springframework.stereotype.Service; | ||
25 | import org.thingsboard.server.common.data.Tenant; | 22 | import org.thingsboard.server.common.data.Tenant; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
27 | import org.thingsboard.server.common.data.page.TextPageData; | 24 | import org.thingsboard.server.common.data.page.TextPageData; |
@@ -30,19 +27,16 @@ import org.thingsboard.server.dao.customer.CustomerService; | @@ -30,19 +27,16 @@ import org.thingsboard.server.dao.customer.CustomerService; | ||
30 | import org.thingsboard.server.dao.dashboard.DashboardService; | 27 | import org.thingsboard.server.dao.dashboard.DashboardService; |
31 | import org.thingsboard.server.dao.device.DeviceService; | 28 | import org.thingsboard.server.dao.device.DeviceService; |
32 | import org.thingsboard.server.dao.exception.DataValidationException; | 29 | import org.thingsboard.server.dao.exception.DataValidationException; |
33 | -import org.thingsboard.server.dao.model.TenantEntity; | ||
34 | import org.thingsboard.server.dao.plugin.PluginService; | 30 | import org.thingsboard.server.dao.plugin.PluginService; |
35 | import org.thingsboard.server.dao.rule.RuleService; | 31 | import org.thingsboard.server.dao.rule.RuleService; |
36 | import org.thingsboard.server.dao.service.DataValidator; | 32 | import org.thingsboard.server.dao.service.DataValidator; |
37 | import org.thingsboard.server.dao.service.PaginatedRemover; | 33 | import org.thingsboard.server.dao.service.PaginatedRemover; |
38 | -import org.thingsboard.server.dao.user.UserService; | ||
39 | -import org.slf4j.Logger; | ||
40 | -import org.slf4j.LoggerFactory; | ||
41 | -import org.springframework.beans.factory.annotation.Autowired; | ||
42 | -import org.springframework.stereotype.Service; | ||
43 | import org.thingsboard.server.dao.service.Validator; | 34 | import org.thingsboard.server.dao.service.Validator; |
35 | +import org.thingsboard.server.dao.user.UserService; | ||
44 | import org.thingsboard.server.dao.widget.WidgetsBundleService; | 36 | import org.thingsboard.server.dao.widget.WidgetsBundleService; |
45 | 37 | ||
38 | +import java.util.List; | ||
39 | + | ||
46 | @Service | 40 | @Service |
47 | @Slf4j | 41 | @Slf4j |
48 | public class TenantServiceImpl implements TenantService { | 42 | public class TenantServiceImpl implements TenantService { |
@@ -77,8 +71,7 @@ public class TenantServiceImpl implements TenantService { | @@ -77,8 +71,7 @@ public class TenantServiceImpl implements TenantService { | ||
77 | public Tenant findTenantById(TenantId tenantId) { | 71 | public Tenant findTenantById(TenantId tenantId) { |
78 | log.trace("Executing findTenantById [{}]", tenantId); | 72 | log.trace("Executing findTenantById [{}]", tenantId); |
79 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 73 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
80 | - TenantEntity tenantEntity = tenantDao.findById(tenantId.getId()); | ||
81 | - return getData(tenantEntity); | 74 | + return tenantDao.findById(tenantId.getId()); |
82 | } | 75 | } |
83 | 76 | ||
84 | @Override | 77 | @Override |
@@ -86,8 +79,7 @@ public class TenantServiceImpl implements TenantService { | @@ -86,8 +79,7 @@ public class TenantServiceImpl implements TenantService { | ||
86 | log.trace("Executing saveTenant [{}]", tenant); | 79 | log.trace("Executing saveTenant [{}]", tenant); |
87 | tenant.setRegion(DEFAULT_TENANT_REGION); | 80 | tenant.setRegion(DEFAULT_TENANT_REGION); |
88 | tenantValidator.validate(tenant); | 81 | tenantValidator.validate(tenant); |
89 | - TenantEntity tenantEntity = tenantDao.save(tenant); | ||
90 | - return getData(tenantEntity); | 82 | + return tenantDao.save(tenant); |
91 | } | 83 | } |
92 | 84 | ||
93 | @Override | 85 | @Override |
@@ -108,9 +100,8 @@ public class TenantServiceImpl implements TenantService { | @@ -108,9 +100,8 @@ public class TenantServiceImpl implements TenantService { | ||
108 | public TextPageData<Tenant> findTenants(TextPageLink pageLink) { | 100 | public TextPageData<Tenant> findTenants(TextPageLink pageLink) { |
109 | log.trace("Executing findTenants pageLink [{}]", pageLink); | 101 | log.trace("Executing findTenants pageLink [{}]", pageLink); |
110 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 102 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
111 | - List<TenantEntity> tenantEntities = tenantDao.findTenantsByRegion(DEFAULT_TENANT_REGION, pageLink); | ||
112 | - List<Tenant> tenants = convertDataList(tenantEntities); | ||
113 | - return new TextPageData<Tenant>(tenants, pageLink); | 103 | + List<Tenant> tenants = tenantDao.findTenantsByRegion(DEFAULT_TENANT_REGION, pageLink); |
104 | + return new TextPageData<>(tenants, pageLink); | ||
114 | } | 105 | } |
115 | 106 | ||
116 | @Override | 107 | @Override |
@@ -132,17 +123,17 @@ public class TenantServiceImpl implements TenantService { | @@ -132,17 +123,17 @@ public class TenantServiceImpl implements TenantService { | ||
132 | } | 123 | } |
133 | }; | 124 | }; |
134 | 125 | ||
135 | - private PaginatedRemover<String, TenantEntity> tenantsRemover = | ||
136 | - new PaginatedRemover<String, TenantEntity>() { | 126 | + private PaginatedRemover<String, Tenant> tenantsRemover = |
127 | + new PaginatedRemover<String, Tenant>() { | ||
137 | 128 | ||
138 | @Override | 129 | @Override |
139 | - protected List<TenantEntity> findEntities(String region, TextPageLink pageLink) { | 130 | + protected List<Tenant> findEntities(String region, TextPageLink pageLink) { |
140 | return tenantDao.findTenantsByRegion(region, pageLink); | 131 | return tenantDao.findTenantsByRegion(region, pageLink); |
141 | } | 132 | } |
142 | 133 | ||
143 | @Override | 134 | @Override |
144 | - protected void removeEntity(TenantEntity entity) { | ||
145 | - deleteTenant(new TenantId(entity.getId())); | 135 | + protected void removeEntity(Tenant entity) { |
136 | + deleteTenant(new TenantId(entity.getUuidId())); | ||
146 | } | 137 | } |
147 | }; | 138 | }; |
148 | } | 139 | } |
@@ -15,34 +15,25 @@ | @@ -15,34 +15,25 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.timeseries; | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSet; | 19 | import com.datastax.driver.core.ResultSet; |
19 | import com.datastax.driver.core.ResultSetFuture; | 20 | import com.datastax.driver.core.ResultSetFuture; |
20 | import com.datastax.driver.core.Row; | 21 | import com.datastax.driver.core.Row; |
21 | -import com.google.common.base.Function; | ||
22 | import com.google.common.collect.Lists; | 22 | import com.google.common.collect.Lists; |
23 | import com.google.common.util.concurrent.Futures; | 23 | import com.google.common.util.concurrent.Futures; |
24 | import com.google.common.util.concurrent.ListenableFuture; | 24 | import com.google.common.util.concurrent.ListenableFuture; |
25 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
26 | +import org.springframework.beans.factory.annotation.Autowired; | ||
27 | +import org.springframework.stereotype.Service; | ||
26 | import org.thingsboard.server.common.data.id.UUIDBased; | 28 | import org.thingsboard.server.common.data.id.UUIDBased; |
27 | -import org.thingsboard.server.common.data.kv.BaseTsKvQuery; | ||
28 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 29 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
29 | import org.thingsboard.server.common.data.kv.TsKvQuery; | 30 | import org.thingsboard.server.common.data.kv.TsKvQuery; |
30 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 31 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
31 | -import org.springframework.beans.factory.annotation.Autowired; | ||
32 | -import org.springframework.beans.factory.annotation.Value; | ||
33 | -import org.springframework.stereotype.Service; | ||
34 | import org.thingsboard.server.dao.service.Validator; | 32 | import org.thingsboard.server.dao.service.Validator; |
35 | 33 | ||
36 | -import javax.annotation.Nullable; | ||
37 | -import javax.annotation.PostConstruct; | ||
38 | -import javax.annotation.PreDestroy; | ||
39 | -import java.time.Instant; | ||
40 | -import java.time.LocalDateTime; | ||
41 | -import java.time.ZoneOffset; | ||
42 | -import java.util.*; | ||
43 | -import java.util.concurrent.ExecutorService; | ||
44 | -import java.util.concurrent.Executors; | ||
45 | -import java.util.stream.Collectors; | 34 | +import java.util.Collection; |
35 | +import java.util.List; | ||
36 | +import java.util.UUID; | ||
46 | 37 | ||
47 | import static org.apache.commons.lang3.StringUtils.isBlank; | 38 | import static org.apache.commons.lang3.StringUtils.isBlank; |
48 | 39 |
dao/src/main/java/org/thingsboard/server/dao/timeseries/CassandraBaseTimeseriesDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/timeseries/BaseTimeseriesDao.java
@@ -28,8 +28,7 @@ import org.springframework.beans.factory.annotation.Value; | @@ -28,8 +28,7 @@ import org.springframework.beans.factory.annotation.Value; | ||
28 | import org.springframework.stereotype.Component; | 28 | import org.springframework.stereotype.Component; |
29 | import org.thingsboard.server.common.data.kv.*; | 29 | import org.thingsboard.server.common.data.kv.*; |
30 | import org.thingsboard.server.common.data.kv.DataType; | 30 | import org.thingsboard.server.common.data.kv.DataType; |
31 | -import org.thingsboard.server.dao.AbstractAsyncDao; | ||
32 | -import org.thingsboard.server.dao.AbstractDao; | 31 | +import org.thingsboard.server.dao.CassandraAbstractAsyncDao; |
33 | import org.thingsboard.server.dao.model.ModelConstants; | 32 | import org.thingsboard.server.dao.model.ModelConstants; |
34 | 33 | ||
35 | import javax.annotation.Nullable; | 34 | import javax.annotation.Nullable; |
@@ -38,20 +37,20 @@ import javax.annotation.PreDestroy; | @@ -38,20 +37,20 @@ import javax.annotation.PreDestroy; | ||
38 | import java.time.Instant; | 37 | import java.time.Instant; |
39 | import java.time.LocalDateTime; | 38 | import java.time.LocalDateTime; |
40 | import java.time.ZoneOffset; | 39 | import java.time.ZoneOffset; |
41 | -import java.util.*; | ||
42 | -import java.util.concurrent.ExecutorService; | ||
43 | -import java.util.concurrent.Executors; | 40 | +import java.util.ArrayList; |
41 | +import java.util.List; | ||
42 | +import java.util.Optional; | ||
43 | +import java.util.UUID; | ||
44 | import java.util.stream.Collectors; | 44 | import java.util.stream.Collectors; |
45 | 45 | ||
46 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 46 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
47 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
48 | 47 | ||
49 | /** | 48 | /** |
50 | * @author Andrew Shvayka | 49 | * @author Andrew Shvayka |
51 | */ | 50 | */ |
52 | @Component | 51 | @Component |
53 | @Slf4j | 52 | @Slf4j |
54 | -public class BaseTimeseriesDao extends AbstractAsyncDao implements TimeseriesDao { | 53 | +public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implements TimeseriesDao { |
55 | 54 | ||
56 | //@Value("${cassandra.query.min_aggregation_step_ms}") | 55 | //@Value("${cassandra.query.min_aggregation_step_ms}") |
57 | //TODO: | 56 | //TODO: |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.timeseries; | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSetFuture; | 19 | import com.datastax.driver.core.ResultSetFuture; |
19 | import com.datastax.driver.core.Row; | 20 | import com.datastax.driver.core.Row; |
20 | import com.google.common.util.concurrent.ListenableFuture; | 21 | import com.google.common.util.concurrent.ListenableFuture; |
@@ -22,8 +23,6 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | @@ -22,8 +23,6 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | ||
22 | import org.thingsboard.server.common.data.kv.TsKvQuery; | 23 | import org.thingsboard.server.common.data.kv.TsKvQuery; |
23 | 24 | ||
24 | import java.util.List; | 25 | import java.util.List; |
25 | -import java.util.Optional; | ||
26 | -import java.util.Set; | ||
27 | import java.util.UUID; | 26 | import java.util.UUID; |
28 | 27 | ||
29 | /** | 28 | /** |
@@ -15,18 +15,17 @@ | @@ -15,18 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.timeseries; | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | ||
18 | +// CASSANDRA ??? | ||
18 | import com.datastax.driver.core.ResultSet; | 19 | import com.datastax.driver.core.ResultSet; |
19 | import com.datastax.driver.core.ResultSetFuture; | 20 | import com.datastax.driver.core.ResultSetFuture; |
20 | import com.datastax.driver.core.Row; | 21 | import com.datastax.driver.core.Row; |
21 | import com.google.common.util.concurrent.ListenableFuture; | 22 | import com.google.common.util.concurrent.ListenableFuture; |
22 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
23 | import org.thingsboard.server.common.data.id.UUIDBased; | 23 | import org.thingsboard.server.common.data.id.UUIDBased; |
24 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 24 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
25 | import org.thingsboard.server.common.data.kv.TsKvQuery; | 25 | import org.thingsboard.server.common.data.kv.TsKvQuery; |
26 | 26 | ||
27 | import java.util.Collection; | 27 | import java.util.Collection; |
28 | import java.util.List; | 28 | import java.util.List; |
29 | -import java.util.Set; | ||
30 | 29 | ||
31 | /** | 30 | /** |
32 | * @author Andrew Shvayka | 31 | * @author Andrew Shvayka |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.timeseries; | 16 | package org.thingsboard.server.dao.timeseries; |
17 | 17 | ||
18 | -import lombok.Data; | ||
19 | import lombok.Getter; | 18 | import lombok.Getter; |
20 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 19 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
21 | import org.thingsboard.server.common.data.kv.TsKvQuery; | 20 | import org.thingsboard.server.common.data.kv.TsKvQuery; |
dao/src/main/java/org/thingsboard/server/dao/user/CassandraUserCredentialsDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/user/UserCredentialsDaoImpl.java
@@ -15,26 +15,23 @@ | @@ -15,26 +15,23 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.user; | 16 | package org.thingsboard.server.dao.user; |
17 | 17 | ||
18 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
19 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
20 | - | ||
21 | -import java.util.UUID; | ||
22 | - | 18 | +import com.datastax.driver.core.querybuilder.Select.Where; |
23 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
24 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
25 | import org.thingsboard.server.common.data.security.UserCredentials; | 21 | import org.thingsboard.server.common.data.security.UserCredentials; |
26 | -import org.thingsboard.server.dao.AbstractModelDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractModelDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
24 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
27 | import org.thingsboard.server.dao.model.UserCredentialsEntity; | 25 | import org.thingsboard.server.dao.model.UserCredentialsEntity; |
28 | -import org.slf4j.Logger; | ||
29 | -import org.slf4j.LoggerFactory; | ||
30 | -import org.springframework.stereotype.Repository; | ||
31 | 26 | ||
32 | -import com.datastax.driver.core.querybuilder.Select.Where; | ||
33 | -import org.thingsboard.server.dao.model.ModelConstants; | 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; | ||
34 | 31 | ||
35 | @Component | 32 | @Component |
36 | @Slf4j | 33 | @Slf4j |
37 | -public class UserCredentialsDaoImpl extends AbstractModelDao<UserCredentialsEntity> implements UserCredentialsDao { | 34 | +public class CassandraUserCredentialsDao extends CassandraAbstractModelDao<UserCredentialsEntity, UserCredentials> implements UserCredentialsDao { |
38 | 35 | ||
39 | @Override | 36 | @Override |
40 | protected Class<UserCredentialsEntity> getColumnFamilyClass() { | 37 | protected Class<UserCredentialsEntity> getColumnFamilyClass() { |
@@ -47,41 +44,35 @@ public class UserCredentialsDaoImpl extends AbstractModelDao<UserCredentialsEnti | @@ -47,41 +44,35 @@ public class UserCredentialsDaoImpl extends AbstractModelDao<UserCredentialsEnti | ||
47 | } | 44 | } |
48 | 45 | ||
49 | @Override | 46 | @Override |
50 | - public UserCredentialsEntity save(UserCredentials userCredentials) { | ||
51 | - log.debug("Save user credentials [{}] ", userCredentials); | ||
52 | - return save(new UserCredentialsEntity(userCredentials)); | ||
53 | - } | ||
54 | - | ||
55 | - @Override | ||
56 | - public UserCredentialsEntity findByUserId(UUID userId) { | 47 | + public UserCredentials findByUserId(UUID userId) { |
57 | log.debug("Try to find user credentials by userId [{}] ", userId); | 48 | log.debug("Try to find user credentials by userId [{}] ", userId); |
58 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_USER_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, userId)); | 49 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_USER_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, userId)); |
59 | log.trace("Execute query {}", query); | 50 | log.trace("Execute query {}", query); |
60 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); | 51 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); |
61 | log.trace("Found user credentials [{}] by userId [{}]", userCredentialsEntity, userId); | 52 | log.trace("Found user credentials [{}] by userId [{}]", userCredentialsEntity, userId); |
62 | - return userCredentialsEntity; | 53 | + return DaoUtil.getData(userCredentialsEntity); |
63 | } | 54 | } |
64 | 55 | ||
65 | @Override | 56 | @Override |
66 | - public UserCredentialsEntity findByActivateToken(String activateToken) { | 57 | + public UserCredentials findByActivateToken(String activateToken) { |
67 | log.debug("Try to find user credentials by activateToken [{}] ", activateToken); | 58 | log.debug("Try to find user credentials by activateToken [{}] ", activateToken); |
68 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_ACTIVATE_TOKEN_COLUMN_FAMILY_NAME) | 59 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_ACTIVATE_TOKEN_COLUMN_FAMILY_NAME) |
69 | .where(eq(ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY, activateToken)); | 60 | .where(eq(ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY, activateToken)); |
70 | log.trace("Execute query {}", query); | 61 | log.trace("Execute query {}", query); |
71 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); | 62 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); |
72 | log.trace("Found user credentials [{}] by activateToken [{}]", userCredentialsEntity, activateToken); | 63 | log.trace("Found user credentials [{}] by activateToken [{}]", userCredentialsEntity, activateToken); |
73 | - return userCredentialsEntity; | 64 | + return DaoUtil.getData(userCredentialsEntity); |
74 | } | 65 | } |
75 | 66 | ||
76 | @Override | 67 | @Override |
77 | - public UserCredentialsEntity findByResetToken(String resetToken) { | 68 | + public UserCredentials findByResetToken(String resetToken) { |
78 | log.debug("Try to find user credentials by resetToken [{}] ", resetToken); | 69 | log.debug("Try to find user credentials by resetToken [{}] ", resetToken); |
79 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_RESET_TOKEN_COLUMN_FAMILY_NAME) | 70 | Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_RESET_TOKEN_COLUMN_FAMILY_NAME) |
80 | .where(eq(ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY, resetToken)); | 71 | .where(eq(ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY, resetToken)); |
81 | log.trace("Execute query {}", query); | 72 | log.trace("Execute query {}", query); |
82 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); | 73 | UserCredentialsEntity userCredentialsEntity = findOneByStatement(query); |
83 | log.trace("Found user credentials [{}] by resetToken [{}]", userCredentialsEntity, resetToken); | 74 | log.trace("Found user credentials [{}] by resetToken [{}]", userCredentialsEntity, resetToken); |
84 | - return userCredentialsEntity; | 75 | + return DaoUtil.getData(userCredentialsEntity); |
85 | } | 76 | } |
86 | 77 | ||
87 | } | 78 | } |
dao/src/main/java/org/thingsboard/server/dao/user/CassandraUserDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/user/UserDaoImpl.java
@@ -15,29 +15,27 @@ | @@ -15,29 +15,27 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.user; | 16 | package org.thingsboard.server.dao.user; |
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.Arrays; | ||
22 | -import java.util.List; | ||
23 | -import java.util.UUID; | ||
24 | - | 18 | +import com.datastax.driver.core.querybuilder.Select.Where; |
25 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
26 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
27 | import org.thingsboard.server.common.data.User; | 21 | import org.thingsboard.server.common.data.User; |
28 | import org.thingsboard.server.common.data.page.TextPageLink; | 22 | import org.thingsboard.server.common.data.page.TextPageLink; |
29 | import org.thingsboard.server.common.data.security.Authority; | 23 | import org.thingsboard.server.common.data.security.Authority; |
30 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 24 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
25 | +import org.thingsboard.server.dao.DaoUtil; | ||
26 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
31 | import org.thingsboard.server.dao.model.UserEntity; | 27 | import org.thingsboard.server.dao.model.UserEntity; |
32 | -import org.slf4j.Logger; | ||
33 | -import org.slf4j.LoggerFactory; | ||
34 | 28 | ||
35 | -import com.datastax.driver.core.querybuilder.Select.Where; | ||
36 | -import org.thingsboard.server.dao.model.ModelConstants; | 29 | +import java.util.Arrays; |
30 | +import java.util.List; | ||
31 | +import java.util.UUID; | ||
32 | + | ||
33 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
34 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | ||
37 | 35 | ||
38 | @Component | 36 | @Component |
39 | @Slf4j | 37 | @Slf4j |
40 | -public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements UserDao { | 38 | +public class CassandraUserDao extends CassandraAbstractSearchTextDao<UserEntity, User> implements UserDao { |
41 | 39 | ||
42 | @Override | 40 | @Override |
43 | protected Class<UserEntity> getColumnFamilyClass() { | 41 | protected Class<UserEntity> getColumnFamilyClass() { |
@@ -50,23 +48,17 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | @@ -50,23 +48,17 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | ||
50 | } | 48 | } |
51 | 49 | ||
52 | @Override | 50 | @Override |
53 | - public UserEntity findByEmail(String email) { | 51 | + public User findByEmail(String email) { |
54 | log.debug("Try to find user by email [{}] ", email); | 52 | log.debug("Try to find user by email [{}] ", email); |
55 | Where query = select().from(ModelConstants.USER_BY_EMAIL_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_EMAIL_PROPERTY, email)); | 53 | Where query = select().from(ModelConstants.USER_BY_EMAIL_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_EMAIL_PROPERTY, email)); |
56 | log.trace("Execute query {}", query); | 54 | log.trace("Execute query {}", query); |
57 | UserEntity userEntity = findOneByStatement(query); | 55 | UserEntity userEntity = findOneByStatement(query); |
58 | log.trace("Found user [{}] by email [{}]", userEntity, email); | 56 | log.trace("Found user [{}] by email [{}]", userEntity, email); |
59 | - return userEntity; | ||
60 | - } | ||
61 | - | ||
62 | - @Override | ||
63 | - public UserEntity save(User user) { | ||
64 | - log.debug("Save user [{}] ", user); | ||
65 | - return save(new UserEntity(user)); | 57 | + return DaoUtil.getData(userEntity); |
66 | } | 58 | } |
67 | 59 | ||
68 | @Override | 60 | @Override |
69 | - public List<UserEntity> findTenantAdmins(UUID tenantId, TextPageLink pageLink) { | 61 | + public List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink) { |
70 | log.debug("Try to find tenant admin users by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 62 | log.debug("Try to find tenant admin users by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
71 | List<UserEntity> userEntities = findPageWithTextSearch(ModelConstants.USER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 63 | List<UserEntity> userEntities = findPageWithTextSearch(ModelConstants.USER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
72 | Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), | 64 | Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), |
@@ -74,11 +66,11 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | @@ -74,11 +66,11 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | ||
74 | eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.TENANT_ADMIN.name())), | 66 | eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.TENANT_ADMIN.name())), |
75 | pageLink); | 67 | pageLink); |
76 | log.trace("Found tenant admin users [{}] by tenantId [{}] and pageLink [{}]", userEntities, tenantId, pageLink); | 68 | log.trace("Found tenant admin users [{}] by tenantId [{}] and pageLink [{}]", userEntities, tenantId, pageLink); |
77 | - return userEntities; | 69 | + return DaoUtil.convertDataList(userEntities); |
78 | } | 70 | } |
79 | 71 | ||
80 | @Override | 72 | @Override |
81 | - public List<UserEntity> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink) { | 73 | + public List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
82 | log.debug("Try to find customer users by tenantId [{}], customerId [{}] and pageLink [{}]", tenantId, customerId, pageLink); | 74 | log.debug("Try to find customer users by tenantId [{}], customerId [{}] and pageLink [{}]", tenantId, customerId, pageLink); |
83 | List<UserEntity> userEntities = findPageWithTextSearch(ModelConstants.USER_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 75 | List<UserEntity> userEntities = findPageWithTextSearch(ModelConstants.USER_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
84 | Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), | 76 | Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), |
@@ -86,7 +78,7 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | @@ -86,7 +78,7 @@ public class UserDaoImpl extends AbstractSearchTextDao<UserEntity> implements Us | ||
86 | eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.CUSTOMER_USER.name())), | 78 | eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.CUSTOMER_USER.name())), |
87 | pageLink); | 79 | pageLink); |
88 | log.trace("Found customer users [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", userEntities, tenantId, customerId, pageLink); | 80 | log.trace("Found customer users [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", userEntities, tenantId, customerId, pageLink); |
89 | - return userEntities; | 81 | + return DaoUtil.convertDataList(userEntities); |
90 | } | 82 | } |
91 | 83 | ||
92 | } | 84 | } |
@@ -15,18 +15,15 @@ | @@ -15,18 +15,15 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.user; | 16 | package org.thingsboard.server.dao.user; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | import org.thingsboard.server.common.data.security.UserCredentials; | 18 | import org.thingsboard.server.common.data.security.UserCredentials; |
21 | import org.thingsboard.server.dao.Dao; | 19 | import org.thingsboard.server.dao.Dao; |
22 | -import org.thingsboard.server.dao.model.UserCredentialsEntity; | 20 | + |
21 | +import java.util.UUID; | ||
23 | 22 | ||
24 | /** | 23 | /** |
25 | * The Interface UserCredentialsDao. | 24 | * The Interface UserCredentialsDao. |
26 | - * | ||
27 | - * @param <T> the generic type | ||
28 | */ | 25 | */ |
29 | -public interface UserCredentialsDao extends Dao<UserCredentialsEntity> { | 26 | +public interface UserCredentialsDao extends Dao<UserCredentials> { |
30 | 27 | ||
31 | /** | 28 | /** |
32 | * Save or update user credentials object | 29 | * Save or update user credentials object |
@@ -34,7 +31,7 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> { | @@ -34,7 +31,7 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> { | ||
34 | * @param userCredentials the user credentials object | 31 | * @param userCredentials the user credentials object |
35 | * @return saved user credentials object | 32 | * @return saved user credentials object |
36 | */ | 33 | */ |
37 | - UserCredentialsEntity save(UserCredentials userCredentials); | 34 | + UserCredentials save(UserCredentials userCredentials); |
38 | 35 | ||
39 | /** | 36 | /** |
40 | * Find user credentials by user id. | 37 | * Find user credentials by user id. |
@@ -42,22 +39,22 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> { | @@ -42,22 +39,22 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> { | ||
42 | * @param userId the user id | 39 | * @param userId the user id |
43 | * @return the user credentials object | 40 | * @return the user credentials object |
44 | */ | 41 | */ |
45 | - UserCredentialsEntity findByUserId(UUID userId); | ||
46 | - | 42 | + UserCredentials findByUserId(UUID userId); |
43 | + | ||
47 | /** | 44 | /** |
48 | * Find user credentials by activate token. | 45 | * Find user credentials by activate token. |
49 | * | 46 | * |
50 | * @param activateToken the activate token | 47 | * @param activateToken the activate token |
51 | * @return the user credentials object | 48 | * @return the user credentials object |
52 | */ | 49 | */ |
53 | - UserCredentialsEntity findByActivateToken(String activateToken); | ||
54 | - | 50 | + UserCredentials findByActivateToken(String activateToken); |
51 | + | ||
55 | /** | 52 | /** |
56 | * Find user credentials by reset token. | 53 | * Find user credentials by reset token. |
57 | * | 54 | * |
58 | * @param resetToken the reset token | 55 | * @param resetToken the reset token |
59 | * @return the user credentials object | 56 | * @return the user credentials object |
60 | */ | 57 | */ |
61 | - UserCredentialsEntity findByResetToken(String resetToken); | ||
62 | - | 58 | + UserCredentials findByResetToken(String resetToken); |
59 | + | ||
63 | } | 60 | } |
@@ -15,15 +15,14 @@ | @@ -15,15 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.user; | 16 | package org.thingsboard.server.dao.user; |
17 | 17 | ||
18 | -import java.util.List; | ||
19 | -import java.util.UUID; | ||
20 | - | ||
21 | import org.thingsboard.server.common.data.User; | 18 | import org.thingsboard.server.common.data.User; |
22 | import org.thingsboard.server.common.data.page.TextPageLink; | 19 | import org.thingsboard.server.common.data.page.TextPageLink; |
23 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
24 | -import org.thingsboard.server.dao.model.UserEntity; | ||
25 | 21 | ||
26 | -public interface UserDao extends Dao<UserEntity> { | 22 | +import java.util.List; |
23 | +import java.util.UUID; | ||
24 | + | ||
25 | +public interface UserDao extends Dao<User> { | ||
27 | 26 | ||
28 | /** | 27 | /** |
29 | * Save or update user object | 28 | * Save or update user object |
@@ -31,7 +30,7 @@ public interface UserDao extends Dao<UserEntity> { | @@ -31,7 +30,7 @@ public interface UserDao extends Dao<UserEntity> { | ||
31 | * @param user the user object | 30 | * @param user the user object |
32 | * @return saved user entity | 31 | * @return saved user entity |
33 | */ | 32 | */ |
34 | - UserEntity save(User user); | 33 | + User save(User user); |
35 | 34 | ||
36 | /** | 35 | /** |
37 | * Find user by email. | 36 | * Find user by email. |
@@ -39,7 +38,7 @@ public interface UserDao extends Dao<UserEntity> { | @@ -39,7 +38,7 @@ public interface UserDao extends Dao<UserEntity> { | ||
39 | * @param email the email | 38 | * @param email the email |
40 | * @return the user entity | 39 | * @return the user entity |
41 | */ | 40 | */ |
42 | - UserEntity findByEmail(String email); | 41 | + User findByEmail(String email); |
43 | 42 | ||
44 | /** | 43 | /** |
45 | * Find tenant admin users by tenantId and page link. | 44 | * Find tenant admin users by tenantId and page link. |
@@ -48,7 +47,7 @@ public interface UserDao extends Dao<UserEntity> { | @@ -48,7 +47,7 @@ public interface UserDao extends Dao<UserEntity> { | ||
48 | * @param pageLink the page link | 47 | * @param pageLink the page link |
49 | * @return the list of user entities | 48 | * @return the list of user entities |
50 | */ | 49 | */ |
51 | - List<UserEntity> findTenantAdmins(UUID tenantId, TextPageLink pageLink); | 50 | + List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink); |
52 | 51 | ||
53 | /** | 52 | /** |
54 | * Find customer users by tenantId, customerId and page link. | 53 | * Find customer users by tenantId, customerId and page link. |
@@ -58,6 +57,6 @@ public interface UserDao extends Dao<UserEntity> { | @@ -58,6 +57,6 @@ public interface UserDao extends Dao<UserEntity> { | ||
58 | * @param pageLink the page link | 57 | * @param pageLink the page link |
59 | * @return the list of user entities | 58 | * @return the list of user entities |
60 | */ | 59 | */ |
61 | - List<UserEntity> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink); | 60 | + List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink); |
62 | 61 | ||
63 | } | 62 | } |
@@ -25,32 +25,32 @@ import org.thingsboard.server.common.data.security.UserCredentials; | @@ -25,32 +25,32 @@ import org.thingsboard.server.common.data.security.UserCredentials; | ||
25 | 25 | ||
26 | public interface UserService { | 26 | public interface UserService { |
27 | 27 | ||
28 | - public User findUserById(UserId userId); | 28 | + User findUserById(UserId userId); |
29 | 29 | ||
30 | - public User findUserByEmail(String email); | 30 | + User findUserByEmail(String email); |
31 | 31 | ||
32 | - public User saveUser(User user); | 32 | + User saveUser(User user); |
33 | 33 | ||
34 | - public UserCredentials findUserCredentialsByUserId(UserId userId); | 34 | + UserCredentials findUserCredentialsByUserId(UserId userId); |
35 | 35 | ||
36 | - public UserCredentials findUserCredentialsByActivateToken(String activateToken); | 36 | + UserCredentials findUserCredentialsByActivateToken(String activateToken); |
37 | 37 | ||
38 | - public UserCredentials findUserCredentialsByResetToken(String resetToken); | 38 | + UserCredentials findUserCredentialsByResetToken(String resetToken); |
39 | 39 | ||
40 | - public UserCredentials saveUserCredentials(UserCredentials userCredentials); | 40 | + UserCredentials saveUserCredentials(UserCredentials userCredentials); |
41 | 41 | ||
42 | - public UserCredentials activateUserCredentials(String activateToken, String password); | 42 | + UserCredentials activateUserCredentials(String activateToken, String password); |
43 | 43 | ||
44 | - public UserCredentials requestPasswordReset(String email); | 44 | + UserCredentials requestPasswordReset(String email); |
45 | 45 | ||
46 | - public void deleteUser(UserId userId); | 46 | + void deleteUser(UserId userId); |
47 | 47 | ||
48 | - public TextPageData<User> findTenantAdmins(TenantId tenantId, TextPageLink pageLink); | 48 | + TextPageData<User> findTenantAdmins(TenantId tenantId, TextPageLink pageLink); |
49 | 49 | ||
50 | - public void deleteTenantAdmins(TenantId tenantId); | 50 | + void deleteTenantAdmins(TenantId tenantId); |
51 | 51 | ||
52 | - public TextPageData<User> findCustomerUsers(TenantId tenantId, CustomerId customerId, TextPageLink pageLink); | 52 | + TextPageData<User> findCustomerUsers(TenantId tenantId, CustomerId customerId, TextPageLink pageLink); |
53 | 53 | ||
54 | - public void deleteCustomerUsers(TenantId tenantId, CustomerId customerId); | 54 | + void deleteCustomerUsers(TenantId tenantId, CustomerId customerId); |
55 | 55 | ||
56 | } | 56 | } |
@@ -15,17 +15,13 @@ | @@ -15,17 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.user; | 16 | package org.thingsboard.server.dao.user; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
19 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
20 | -import static org.thingsboard.server.dao.service.Validator.validateId; | ||
21 | -import static org.thingsboard.server.dao.service.Validator.validatePageLink; | ||
22 | -import static org.thingsboard.server.dao.service.Validator.validateString; | ||
23 | - | ||
24 | -import java.util.List; | ||
25 | - | ||
26 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
27 | import org.apache.commons.lang3.RandomStringUtils; | 19 | import org.apache.commons.lang3.RandomStringUtils; |
28 | import org.apache.commons.lang3.StringUtils; | 20 | import org.apache.commons.lang3.StringUtils; |
21 | +import org.springframework.beans.factory.annotation.Autowired; | ||
22 | +import org.springframework.stereotype.Service; | ||
23 | +import org.thingsboard.server.common.data.Customer; | ||
24 | +import org.thingsboard.server.common.data.Tenant; | ||
29 | import org.thingsboard.server.common.data.User; | 25 | import org.thingsboard.server.common.data.User; |
30 | import org.thingsboard.server.common.data.id.CustomerId; | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
31 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -37,19 +33,21 @@ import org.thingsboard.server.common.data.security.UserCredentials; | @@ -37,19 +33,21 @@ import org.thingsboard.server.common.data.security.UserCredentials; | ||
37 | import org.thingsboard.server.dao.customer.CustomerDao; | 33 | import org.thingsboard.server.dao.customer.CustomerDao; |
38 | import org.thingsboard.server.dao.exception.DataValidationException; | 34 | import org.thingsboard.server.dao.exception.DataValidationException; |
39 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 35 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
40 | -import org.thingsboard.server.dao.model.*; | 36 | +import org.thingsboard.server.dao.model.ModelConstants; |
41 | import org.thingsboard.server.dao.service.DataValidator; | 37 | import org.thingsboard.server.dao.service.DataValidator; |
42 | import org.thingsboard.server.dao.service.PaginatedRemover; | 38 | import org.thingsboard.server.dao.service.PaginatedRemover; |
43 | import org.thingsboard.server.dao.tenant.TenantDao; | 39 | import org.thingsboard.server.dao.tenant.TenantDao; |
44 | -import org.slf4j.Logger; | ||
45 | -import org.slf4j.LoggerFactory; | ||
46 | -import org.springframework.beans.factory.annotation.Autowired; | ||
47 | -import org.springframework.stereotype.Service; | 40 | + |
41 | +import java.util.List; | ||
42 | + | ||
43 | +import static org.thingsboard.server.dao.service.Validator.*; | ||
48 | 44 | ||
49 | @Service | 45 | @Service |
50 | @Slf4j | 46 | @Slf4j |
51 | public class UserServiceImpl implements UserService { | 47 | public class UserServiceImpl implements UserService { |
52 | 48 | ||
49 | + private static final int DEFAULT_TOKEN_LENGTH = 30; | ||
50 | + | ||
53 | @Autowired | 51 | @Autowired |
54 | private UserDao userDao; | 52 | private UserDao userDao; |
55 | 53 | ||
@@ -66,63 +64,57 @@ public class UserServiceImpl implements UserService { | @@ -66,63 +64,57 @@ public class UserServiceImpl implements UserService { | ||
66 | public User findUserByEmail(String email) { | 64 | public User findUserByEmail(String email) { |
67 | log.trace("Executing findUserByEmail [{}]", email); | 65 | log.trace("Executing findUserByEmail [{}]", email); |
68 | validateString(email, "Incorrect email " + email); | 66 | validateString(email, "Incorrect email " + email); |
69 | - UserEntity userEntity = userDao.findByEmail(email); | ||
70 | - return getData(userEntity); | 67 | + return userDao.findByEmail(email); |
71 | } | 68 | } |
72 | 69 | ||
73 | @Override | 70 | @Override |
74 | public User findUserById(UserId userId) { | 71 | public User findUserById(UserId userId) { |
75 | log.trace("Executing findUserById [{}]", userId); | 72 | log.trace("Executing findUserById [{}]", userId); |
76 | validateId(userId, "Incorrect userId " + userId); | 73 | validateId(userId, "Incorrect userId " + userId); |
77 | - UserEntity userEntity = userDao.findById(userId.getId()); | ||
78 | - return getData(userEntity); | 74 | + return userDao.findById(userId.getId()); |
79 | } | 75 | } |
80 | 76 | ||
81 | @Override | 77 | @Override |
82 | public User saveUser(User user) { | 78 | public User saveUser(User user) { |
83 | log.trace("Executing saveUser [{}]", user); | 79 | log.trace("Executing saveUser [{}]", user); |
84 | userValidator.validate(user); | 80 | userValidator.validate(user); |
85 | - UserEntity userEntity = userDao.save(user); | 81 | + User savedUser = userDao.save(user); |
86 | if (user.getId() == null) { | 82 | if (user.getId() == null) { |
87 | UserCredentials userCredentials = new UserCredentials(); | 83 | UserCredentials userCredentials = new UserCredentials(); |
88 | userCredentials.setEnabled(false); | 84 | userCredentials.setEnabled(false); |
89 | - userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(30)); | ||
90 | - userCredentials.setUserId(new UserId(userEntity.getId())); | 85 | + userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH)); |
86 | + userCredentials.setUserId(new UserId(savedUser.getUuidId())); | ||
91 | userCredentialsDao.save(userCredentials); | 87 | userCredentialsDao.save(userCredentials); |
92 | } | 88 | } |
93 | - return getData(userEntity); | 89 | + return savedUser; |
94 | } | 90 | } |
95 | 91 | ||
96 | @Override | 92 | @Override |
97 | public UserCredentials findUserCredentialsByUserId(UserId userId) { | 93 | public UserCredentials findUserCredentialsByUserId(UserId userId) { |
98 | log.trace("Executing findUserCredentialsByUserId [{}]", userId); | 94 | log.trace("Executing findUserCredentialsByUserId [{}]", userId); |
99 | validateId(userId, "Incorrect userId " + userId); | 95 | validateId(userId, "Incorrect userId " + userId); |
100 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userId.getId()); | ||
101 | - return getData(userCredentialsEntity); | 96 | + return userCredentialsDao.findByUserId(userId.getId()); |
102 | } | 97 | } |
103 | 98 | ||
104 | @Override | 99 | @Override |
105 | public UserCredentials findUserCredentialsByActivateToken(String activateToken) { | 100 | public UserCredentials findUserCredentialsByActivateToken(String activateToken) { |
106 | log.trace("Executing findUserCredentialsByActivateToken [{}]", activateToken); | 101 | log.trace("Executing findUserCredentialsByActivateToken [{}]", activateToken); |
107 | validateString(activateToken, "Incorrect activateToken " + activateToken); | 102 | validateString(activateToken, "Incorrect activateToken " + activateToken); |
108 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByActivateToken(activateToken); | ||
109 | - return getData(userCredentialsEntity); | 103 | + return userCredentialsDao.findByActivateToken(activateToken); |
110 | } | 104 | } |
111 | 105 | ||
112 | @Override | 106 | @Override |
113 | public UserCredentials findUserCredentialsByResetToken(String resetToken) { | 107 | public UserCredentials findUserCredentialsByResetToken(String resetToken) { |
114 | log.trace("Executing findUserCredentialsByResetToken [{}]", resetToken); | 108 | log.trace("Executing findUserCredentialsByResetToken [{}]", resetToken); |
115 | validateString(resetToken, "Incorrect resetToken " + resetToken); | 109 | validateString(resetToken, "Incorrect resetToken " + resetToken); |
116 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByResetToken(resetToken); | ||
117 | - return getData(userCredentialsEntity); | 110 | + return userCredentialsDao.findByResetToken(resetToken); |
118 | } | 111 | } |
119 | 112 | ||
120 | @Override | 113 | @Override |
121 | public UserCredentials saveUserCredentials(UserCredentials userCredentials) { | 114 | public UserCredentials saveUserCredentials(UserCredentials userCredentials) { |
122 | log.trace("Executing saveUserCredentials [{}]", userCredentials); | 115 | log.trace("Executing saveUserCredentials [{}]", userCredentials); |
123 | userCredentialsValidator.validate(userCredentials); | 116 | userCredentialsValidator.validate(userCredentials); |
124 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.save(userCredentials); | ||
125 | - return getData(userCredentialsEntity); | 117 | + return userCredentialsDao.save(userCredentials); |
126 | } | 118 | } |
127 | 119 | ||
128 | @Override | 120 | @Override |
@@ -130,11 +122,10 @@ public class UserServiceImpl implements UserService { | @@ -130,11 +122,10 @@ public class UserServiceImpl implements UserService { | ||
130 | log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password); | 122 | log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password); |
131 | validateString(activateToken, "Incorrect activateToken " + activateToken); | 123 | validateString(activateToken, "Incorrect activateToken " + activateToken); |
132 | validateString(password, "Incorrect password " + password); | 124 | validateString(password, "Incorrect password " + password); |
133 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByActivateToken(activateToken); | ||
134 | - if (userCredentialsEntity == null) { | 125 | + UserCredentials userCredentials = userCredentialsDao.findByActivateToken(activateToken); |
126 | + if (userCredentials == null) { | ||
135 | throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken)); | 127 | throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken)); |
136 | } | 128 | } |
137 | - UserCredentials userCredentials = getData(userCredentialsEntity); | ||
138 | if (userCredentials.isEnabled()) { | 129 | if (userCredentials.isEnabled()) { |
139 | throw new IncorrectParameterException("User credentials already activated"); | 130 | throw new IncorrectParameterException("User credentials already activated"); |
140 | } | 131 | } |
@@ -149,16 +140,15 @@ public class UserServiceImpl implements UserService { | @@ -149,16 +140,15 @@ public class UserServiceImpl implements UserService { | ||
149 | public UserCredentials requestPasswordReset(String email) { | 140 | public UserCredentials requestPasswordReset(String email) { |
150 | log.trace("Executing requestPasswordReset email [{}]", email); | 141 | log.trace("Executing requestPasswordReset email [{}]", email); |
151 | validateString(email, "Incorrect email " + email); | 142 | validateString(email, "Incorrect email " + email); |
152 | - UserEntity userEntity = userDao.findByEmail(email); | ||
153 | - if (userEntity == null) { | 143 | + User user = userDao.findByEmail(email); |
144 | + if (user == null) { | ||
154 | throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email)); | 145 | throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email)); |
155 | } | 146 | } |
156 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userEntity.getId()); | ||
157 | - UserCredentials userCredentials = getData(userCredentialsEntity); | 147 | + UserCredentials userCredentials = userCredentialsDao.findByUserId(user.getUuidId()); |
158 | if (!userCredentials.isEnabled()) { | 148 | if (!userCredentials.isEnabled()) { |
159 | throw new IncorrectParameterException("Unable to reset password for inactive user"); | 149 | throw new IncorrectParameterException("Unable to reset password for inactive user"); |
160 | } | 150 | } |
161 | - userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(30)); | 151 | + userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH)); |
162 | return saveUserCredentials(userCredentials); | 152 | return saveUserCredentials(userCredentials); |
163 | } | 153 | } |
164 | 154 | ||
@@ -167,8 +157,8 @@ public class UserServiceImpl implements UserService { | @@ -167,8 +157,8 @@ public class UserServiceImpl implements UserService { | ||
167 | public void deleteUser(UserId userId) { | 157 | public void deleteUser(UserId userId) { |
168 | log.trace("Executing deleteUser [{}]", userId); | 158 | log.trace("Executing deleteUser [{}]", userId); |
169 | validateId(userId, "Incorrect userId " + userId); | 159 | validateId(userId, "Incorrect userId " + userId); |
170 | - UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userId.getId()); | ||
171 | - userCredentialsDao.removeById(userCredentialsEntity.getId()); | 160 | + UserCredentials userCredentials = userCredentialsDao.findByUserId(userId.getId()); |
161 | + userCredentialsDao.removeById(userCredentials.getUuidId()); | ||
172 | userDao.removeById(userId.getId()); | 162 | userDao.removeById(userId.getId()); |
173 | } | 163 | } |
174 | 164 | ||
@@ -177,9 +167,8 @@ public class UserServiceImpl implements UserService { | @@ -177,9 +167,8 @@ public class UserServiceImpl implements UserService { | ||
177 | log.trace("Executing findTenantAdmins, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 167 | log.trace("Executing findTenantAdmins, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
178 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 168 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
179 | validatePageLink(pageLink, "Incorrect page link " + pageLink); | 169 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
180 | - List<UserEntity> userEntities = userDao.findTenantAdmins(tenantId.getId(), pageLink); | ||
181 | - List<User> users = convertDataList(userEntities); | ||
182 | - return new TextPageData<User>(users, pageLink); | 170 | + List<User> users = userDao.findTenantAdmins(tenantId.getId(), pageLink); |
171 | + return new TextPageData<>(users, pageLink); | ||
183 | } | 172 | } |
184 | 173 | ||
185 | @Override | 174 | @Override |
@@ -195,9 +184,8 @@ public class UserServiceImpl implements UserService { | @@ -195,9 +184,8 @@ public class UserServiceImpl implements UserService { | ||
195 | validateId(tenantId, "Incorrect tenantId " + tenantId); | 184 | validateId(tenantId, "Incorrect tenantId " + tenantId); |
196 | validateId(customerId, "Incorrect customerId " + customerId); | 185 | validateId(customerId, "Incorrect customerId " + customerId); |
197 | validatePageLink(pageLink, "Incorrect page link " + pageLink); | 186 | validatePageLink(pageLink, "Incorrect page link " + pageLink); |
198 | - List<UserEntity> userEntities = userDao.findCustomerUsers(tenantId.getId(), customerId.getId(), pageLink); | ||
199 | - List<User> users = convertDataList(userEntities); | ||
200 | - return new TextPageData<User>(users, pageLink); | 187 | + List<User> users = userDao.findCustomerUsers(tenantId.getId(), customerId.getId(), pageLink); |
188 | + return new TextPageData<>(users, pageLink); | ||
201 | } | 189 | } |
202 | 190 | ||
203 | @Override | 191 | @Override |
@@ -266,16 +254,16 @@ public class UserServiceImpl implements UserService { | @@ -266,16 +254,16 @@ public class UserServiceImpl implements UserService { | ||
266 | + " already present in database!"); | 254 | + " already present in database!"); |
267 | } | 255 | } |
268 | if (!tenantId.getId().equals(ModelConstants.NULL_UUID)) { | 256 | if (!tenantId.getId().equals(ModelConstants.NULL_UUID)) { |
269 | - TenantEntity tenant = tenantDao.findById(user.getTenantId().getId()); | 257 | + Tenant tenant = tenantDao.findById(user.getTenantId().getId()); |
270 | if (tenant == null) { | 258 | if (tenant == null) { |
271 | throw new DataValidationException("User is referencing to non-existent tenant!"); | 259 | throw new DataValidationException("User is referencing to non-existent tenant!"); |
272 | } | 260 | } |
273 | } | 261 | } |
274 | if (!customerId.getId().equals(ModelConstants.NULL_UUID)) { | 262 | if (!customerId.getId().equals(ModelConstants.NULL_UUID)) { |
275 | - CustomerEntity customer = customerDao.findById(user.getCustomerId().getId()); | 263 | + Customer customer = customerDao.findById(user.getCustomerId().getId()); |
276 | if (customer == null) { | 264 | if (customer == null) { |
277 | throw new DataValidationException("User is referencing to non-existent customer!"); | 265 | throw new DataValidationException("User is referencing to non-existent customer!"); |
278 | - } else if (!customer.getTenantId().equals(tenantId.getId())) { | 266 | + } else if (!customer.getTenantId().getId().equals(tenantId.getId())) { |
279 | throw new DataValidationException("User can't be assigned to customer from different tenant!"); | 267 | throw new DataValidationException("User can't be assigned to customer from different tenant!"); |
280 | } | 268 | } |
281 | } | 269 | } |
@@ -303,7 +291,7 @@ public class UserServiceImpl implements UserService { | @@ -303,7 +291,7 @@ public class UserServiceImpl implements UserService { | ||
303 | throw new DataValidationException("Enabled user credentials can't have activate token!"); | 291 | throw new DataValidationException("Enabled user credentials can't have activate token!"); |
304 | } | 292 | } |
305 | } | 293 | } |
306 | - UserCredentialsEntity existingUserCredentialsEntity = userCredentialsDao.findById(userCredentials.getId().getId()); | 294 | + UserCredentials existingUserCredentialsEntity = userCredentialsDao.findById(userCredentials.getId().getId()); |
307 | if (existingUserCredentialsEntity == null) { | 295 | if (existingUserCredentialsEntity == null) { |
308 | throw new DataValidationException("Unable to update non-existent user credentials!"); | 296 | throw new DataValidationException("Unable to update non-existent user credentials!"); |
309 | } | 297 | } |
@@ -314,21 +302,21 @@ public class UserServiceImpl implements UserService { | @@ -314,21 +302,21 @@ public class UserServiceImpl implements UserService { | ||
314 | } | 302 | } |
315 | }; | 303 | }; |
316 | 304 | ||
317 | - private PaginatedRemover<TenantId, UserEntity> tenantAdminsRemover = | ||
318 | - new PaginatedRemover<TenantId, UserEntity>() { | 305 | + private PaginatedRemover<TenantId, User> tenantAdminsRemover = |
306 | + new PaginatedRemover<TenantId, User>() { | ||
319 | 307 | ||
320 | @Override | 308 | @Override |
321 | - protected List<UserEntity> findEntities(TenantId id, TextPageLink pageLink) { | 309 | + protected List<User> findEntities(TenantId id, TextPageLink pageLink) { |
322 | return userDao.findTenantAdmins(id.getId(), pageLink); | 310 | return userDao.findTenantAdmins(id.getId(), pageLink); |
323 | } | 311 | } |
324 | 312 | ||
325 | @Override | 313 | @Override |
326 | - protected void removeEntity(UserEntity entity) { | ||
327 | - deleteUser(new UserId(entity.getId())); | 314 | + protected void removeEntity(User entity) { |
315 | + deleteUser(new UserId(entity.getUuidId())); | ||
328 | } | 316 | } |
329 | }; | 317 | }; |
330 | 318 | ||
331 | - class CustomerUsersRemover extends PaginatedRemover<CustomerId, UserEntity> { | 319 | + private class CustomerUsersRemover extends PaginatedRemover<CustomerId, User> { |
332 | 320 | ||
333 | private TenantId tenantId; | 321 | private TenantId tenantId; |
334 | 322 | ||
@@ -337,14 +325,14 @@ public class UserServiceImpl implements UserService { | @@ -337,14 +325,14 @@ public class UserServiceImpl implements UserService { | ||
337 | } | 325 | } |
338 | 326 | ||
339 | @Override | 327 | @Override |
340 | - protected List<UserEntity> findEntities(CustomerId id, TextPageLink pageLink) { | 328 | + protected List<User> findEntities(CustomerId id, TextPageLink pageLink) { |
341 | return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink); | 329 | return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink); |
342 | 330 | ||
343 | } | 331 | } |
344 | 332 | ||
345 | @Override | 333 | @Override |
346 | - protected void removeEntity(UserEntity entity) { | ||
347 | - deleteUser(new UserId(entity.getId())); | 334 | + protected void removeEntity(User entity) { |
335 | + deleteUser(new UserId(entity.getUuidId())); | ||
348 | } | 336 | } |
349 | 337 | ||
350 | } | 338 | } |
dao/src/main/java/org/thingsboard/server/dao/widget/CassandraWidgetTypeDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeDaoImpl.java
@@ -17,12 +17,10 @@ package org.thingsboard.server.dao.widget; | @@ -17,12 +17,10 @@ package org.thingsboard.server.dao.widget; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.querybuilder.Select.Where; | 18 | import com.datastax.driver.core.querybuilder.Select.Where; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | -import org.slf4j.Logger; | ||
21 | -import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
23 | -import org.springframework.stereotype.Repository; | ||
24 | import org.thingsboard.server.common.data.widget.WidgetType; | 21 | import org.thingsboard.server.common.data.widget.WidgetType; |
25 | -import org.thingsboard.server.dao.AbstractModelDao; | 22 | +import org.thingsboard.server.dao.CassandraAbstractModelDao; |
23 | +import org.thingsboard.server.dao.DaoUtil; | ||
26 | import org.thingsboard.server.dao.model.WidgetTypeEntity; | 24 | import org.thingsboard.server.dao.model.WidgetTypeEntity; |
27 | 25 | ||
28 | import java.util.List; | 26 | import java.util.List; |
@@ -34,7 +32,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | @@ -34,7 +32,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
34 | 32 | ||
35 | @Component | 33 | @Component |
36 | @Slf4j | 34 | @Slf4j |
37 | -public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implements WidgetTypeDao { | 35 | +public class CassandraWidgetTypeDao extends CassandraAbstractModelDao<WidgetTypeEntity, WidgetType> implements WidgetTypeDao { |
38 | 36 | ||
39 | @Override | 37 | @Override |
40 | protected Class<WidgetTypeEntity> getColumnFamilyClass() { | 38 | protected Class<WidgetTypeEntity> getColumnFamilyClass() { |
@@ -47,13 +45,7 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | @@ -47,13 +45,7 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | ||
47 | } | 45 | } |
48 | 46 | ||
49 | @Override | 47 | @Override |
50 | - public WidgetTypeEntity save(WidgetType widgetType) { | ||
51 | - log.debug("Save widget type [{}] ", widgetType); | ||
52 | - return save(new WidgetTypeEntity(widgetType)); | ||
53 | - } | ||
54 | - | ||
55 | - @Override | ||
56 | - public List<WidgetTypeEntity> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias) { | 48 | + public List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias) { |
57 | log.debug("Try to find widget types by tenantId [{}] and bundleAlias [{}]", tenantId, bundleAlias); | 49 | log.debug("Try to find widget types by tenantId [{}] and bundleAlias [{}]", tenantId, bundleAlias); |
58 | Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) | 50 | Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) |
59 | .where() | 51 | .where() |
@@ -61,11 +53,11 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | @@ -61,11 +53,11 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | ||
61 | .and(eq(WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY, bundleAlias)); | 53 | .and(eq(WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY, bundleAlias)); |
62 | List<WidgetTypeEntity> widgetTypesEntities = findListByStatement(query); | 54 | List<WidgetTypeEntity> widgetTypesEntities = findListByStatement(query); |
63 | log.trace("Found widget types [{}] by tenantId [{}] and bundleAlias [{}]", widgetTypesEntities, tenantId, bundleAlias); | 55 | log.trace("Found widget types [{}] by tenantId [{}] and bundleAlias [{}]", widgetTypesEntities, tenantId, bundleAlias); |
64 | - return widgetTypesEntities; | 56 | + return DaoUtil.convertDataList(widgetTypesEntities); |
65 | } | 57 | } |
66 | 58 | ||
67 | @Override | 59 | @Override |
68 | - public WidgetTypeEntity findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias) { | 60 | + public WidgetType findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias) { |
69 | log.debug("Try to find widget type by tenantId [{}], bundleAlias [{}] and alias [{}]", tenantId, bundleAlias, alias); | 61 | log.debug("Try to find widget type by tenantId [{}], bundleAlias [{}] and alias [{}]", tenantId, bundleAlias, alias); |
70 | Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) | 62 | Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) |
71 | .where() | 63 | .where() |
@@ -76,7 +68,7 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | @@ -76,7 +68,7 @@ public class WidgetTypeDaoImpl extends AbstractModelDao<WidgetTypeEntity> implem | ||
76 | WidgetTypeEntity widgetTypeEntity = findOneByStatement(query); | 68 | WidgetTypeEntity widgetTypeEntity = findOneByStatement(query); |
77 | log.trace("Found widget type [{}] by tenantId [{}], bundleAlias [{}] and alias [{}]", | 69 | log.trace("Found widget type [{}] by tenantId [{}], bundleAlias [{}] and alias [{}]", |
78 | widgetTypeEntity, tenantId, bundleAlias, alias); | 70 | widgetTypeEntity, tenantId, bundleAlias, alias); |
79 | - return widgetTypeEntity; | 71 | + return DaoUtil.getData(widgetTypeEntity); |
80 | } | 72 | } |
81 | 73 | ||
82 | } | 74 | } |
dao/src/main/java/org/thingsboard/server/dao/widget/CassandraWidgetsBundleDao.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDaoImpl.java
@@ -17,26 +17,23 @@ package org.thingsboard.server.dao.widget; | @@ -17,26 +17,23 @@ package org.thingsboard.server.dao.widget; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.querybuilder.Select; | 18 | import com.datastax.driver.core.querybuilder.Select; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | -import org.slf4j.Logger; | ||
21 | -import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 22 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
25 | -import org.thingsboard.server.dao.AbstractSearchTextDao; | 23 | +import org.thingsboard.server.dao.CassandraAbstractSearchTextDao; |
24 | +import org.thingsboard.server.dao.DaoUtil; | ||
26 | import org.thingsboard.server.dao.model.WidgetsBundleEntity; | 25 | import org.thingsboard.server.dao.model.WidgetsBundleEntity; |
27 | 26 | ||
28 | import java.util.Arrays; | 27 | import java.util.Arrays; |
29 | import java.util.List; | 28 | import java.util.List; |
30 | import java.util.UUID; | 29 | import java.util.UUID; |
31 | 30 | ||
32 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | ||
33 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.in; | ||
34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 31 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
35 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 32 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
36 | 33 | ||
37 | @Component | 34 | @Component |
38 | @Slf4j | 35 | @Slf4j |
39 | -public class WidgetsBundleDaoImpl extends AbstractSearchTextDao<WidgetsBundleEntity> implements WidgetsBundleDao { | 36 | +public class CassandraWidgetsBundleDao extends CassandraAbstractSearchTextDao<WidgetsBundleEntity, WidgetsBundle> implements WidgetsBundleDao { |
40 | 37 | ||
41 | @Override | 38 | @Override |
42 | protected Class<WidgetsBundleEntity> getColumnFamilyClass() { | 39 | protected Class<WidgetsBundleEntity> getColumnFamilyClass() { |
@@ -49,13 +46,7 @@ public class WidgetsBundleDaoImpl extends AbstractSearchTextDao<WidgetsBundleEnt | @@ -49,13 +46,7 @@ public class WidgetsBundleDaoImpl extends AbstractSearchTextDao<WidgetsBundleEnt | ||
49 | } | 46 | } |
50 | 47 | ||
51 | @Override | 48 | @Override |
52 | - public WidgetsBundleEntity save(WidgetsBundle widgetsBundle) { | ||
53 | - log.debug("Save widgets bundle [{}] ", widgetsBundle); | ||
54 | - return save(new WidgetsBundleEntity(widgetsBundle)); | ||
55 | - } | ||
56 | - | ||
57 | - @Override | ||
58 | - public WidgetsBundleEntity findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias) { | 49 | + public WidgetsBundle findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias) { |
59 | log.debug("Try to find widgets bundle by tenantId [{}] and alias [{}]", tenantId, alias); | 50 | log.debug("Try to find widgets bundle by tenantId [{}] and alias [{}]", tenantId, alias); |
60 | Select.Where query = select().from(WIDGETS_BUNDLE_BY_TENANT_AND_ALIAS_COLUMN_FAMILY_NAME) | 51 | Select.Where query = select().from(WIDGETS_BUNDLE_BY_TENANT_AND_ALIAS_COLUMN_FAMILY_NAME) |
61 | .where() | 52 | .where() |
@@ -65,37 +56,37 @@ public class WidgetsBundleDaoImpl extends AbstractSearchTextDao<WidgetsBundleEnt | @@ -65,37 +56,37 @@ public class WidgetsBundleDaoImpl extends AbstractSearchTextDao<WidgetsBundleEnt | ||
65 | WidgetsBundleEntity widgetsBundleEntity = findOneByStatement(query); | 56 | WidgetsBundleEntity widgetsBundleEntity = findOneByStatement(query); |
66 | log.trace("Found widgets bundle [{}] by tenantId [{}] and alias [{}]", | 57 | log.trace("Found widgets bundle [{}] by tenantId [{}] and alias [{}]", |
67 | widgetsBundleEntity, tenantId, alias); | 58 | widgetsBundleEntity, tenantId, alias); |
68 | - return widgetsBundleEntity; | 59 | + return DaoUtil.getData(widgetsBundleEntity); |
69 | } | 60 | } |
70 | 61 | ||
71 | @Override | 62 | @Override |
72 | - public List<WidgetsBundleEntity> findSystemWidgetsBundles(TextPageLink pageLink) { | 63 | + public List<WidgetsBundle> findSystemWidgetsBundles(TextPageLink pageLink) { |
73 | log.debug("Try to find system widgets bundles by pageLink [{}]", pageLink); | 64 | log.debug("Try to find system widgets bundles by pageLink [{}]", pageLink); |
74 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 65 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
75 | Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, NULL_UUID)), | 66 | Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, NULL_UUID)), |
76 | pageLink); | 67 | pageLink); |
77 | log.trace("Found system widgets bundles [{}] by pageLink [{}]", widgetsBundlesEntities, pageLink); | 68 | log.trace("Found system widgets bundles [{}] by pageLink [{}]", widgetsBundlesEntities, pageLink); |
78 | - return widgetsBundlesEntities; | 69 | + return DaoUtil.convertDataList(widgetsBundlesEntities); |
79 | } | 70 | } |
80 | 71 | ||
81 | @Override | 72 | @Override |
82 | - public List<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { | 73 | + public List<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { |
83 | log.debug("Try to find tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 74 | log.debug("Try to find tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
84 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 75 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
85 | Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, tenantId)), | 76 | Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, tenantId)), |
86 | pageLink); | 77 | pageLink); |
87 | log.trace("Found tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); | 78 | log.trace("Found tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); |
88 | - return widgetsBundlesEntities; | 79 | + return DaoUtil.convertDataList(widgetsBundlesEntities); |
89 | } | 80 | } |
90 | 81 | ||
91 | @Override | 82 | @Override |
92 | - public List<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { | 83 | + public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { |
93 | log.debug("Try to find all tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | 84 | log.debug("Try to find all tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
94 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, | 85 | List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
95 | Arrays.asList(in(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), | 86 | Arrays.asList(in(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), |
96 | pageLink); | 87 | pageLink); |
97 | log.trace("Found all tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); | 88 | log.trace("Found all tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); |
98 | - return widgetsBundlesEntities; | 89 | + return DaoUtil.convertDataList(widgetsBundlesEntities); |
99 | } | 90 | } |
100 | 91 | ||
101 | } | 92 | } |
@@ -17,17 +17,14 @@ package org.thingsboard.server.dao.widget; | @@ -17,17 +17,14 @@ package org.thingsboard.server.dao.widget; | ||
17 | 17 | ||
18 | import org.thingsboard.server.common.data.widget.WidgetType; | 18 | import org.thingsboard.server.common.data.widget.WidgetType; |
19 | import org.thingsboard.server.dao.Dao; | 19 | import org.thingsboard.server.dao.Dao; |
20 | -import org.thingsboard.server.dao.model.WidgetTypeEntity; | ||
21 | 20 | ||
22 | import java.util.List; | 21 | import java.util.List; |
23 | import java.util.UUID; | 22 | import java.util.UUID; |
24 | 23 | ||
25 | /** | 24 | /** |
26 | * The Interface WidgetTypeDao. | 25 | * The Interface WidgetTypeDao. |
27 | - * | ||
28 | - * @param <T> the generic type | ||
29 | */ | 26 | */ |
30 | -public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | 27 | +public interface WidgetTypeDao extends Dao<WidgetType> { |
31 | 28 | ||
32 | /** | 29 | /** |
33 | * Save or update widget type object | 30 | * Save or update widget type object |
@@ -35,7 +32,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | @@ -35,7 +32,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | ||
35 | * @param widgetType the widget type object | 32 | * @param widgetType the widget type object |
36 | * @return saved widget type object | 33 | * @return saved widget type object |
37 | */ | 34 | */ |
38 | - WidgetTypeEntity save(WidgetType widgetType); | 35 | + WidgetType save(WidgetType widgetType); |
39 | 36 | ||
40 | /** | 37 | /** |
41 | * Find widget types by tenantId and bundleAlias. | 38 | * Find widget types by tenantId and bundleAlias. |
@@ -44,7 +41,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | @@ -44,7 +41,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | ||
44 | * @param bundleAlias the bundle alias | 41 | * @param bundleAlias the bundle alias |
45 | * @return the list of widget types objects | 42 | * @return the list of widget types objects |
46 | */ | 43 | */ |
47 | - List<WidgetTypeEntity> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias); | 44 | + List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias); |
48 | 45 | ||
49 | /** | 46 | /** |
50 | * Find widget type by tenantId, bundleAlias and alias. | 47 | * Find widget type by tenantId, bundleAlias and alias. |
@@ -54,6 +51,6 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | @@ -54,6 +51,6 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> { | ||
54 | * @param alias the alias | 51 | * @param alias the alias |
55 | * @return the widget type object | 52 | * @return the widget type object |
56 | */ | 53 | */ |
57 | - WidgetTypeEntity findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias); | 54 | + WidgetType findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias); |
58 | 55 | ||
59 | } | 56 | } |
@@ -23,16 +23,16 @@ import java.util.List; | @@ -23,16 +23,16 @@ import java.util.List; | ||
23 | 23 | ||
24 | public interface WidgetTypeService { | 24 | public interface WidgetTypeService { |
25 | 25 | ||
26 | - public WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId); | 26 | + WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId); |
27 | 27 | ||
28 | - public WidgetType saveWidgetType(WidgetType widgetType); | 28 | + WidgetType saveWidgetType(WidgetType widgetType); |
29 | 29 | ||
30 | - public void deleteWidgetType(WidgetTypeId widgetTypeId); | 30 | + void deleteWidgetType(WidgetTypeId widgetTypeId); |
31 | 31 | ||
32 | - public List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias); | 32 | + List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias); |
33 | 33 | ||
34 | - public WidgetType findWidgetTypeByTenantIdBundleAliasAndAlias(TenantId tenantId, String bundleAlias, String alias); | 34 | + WidgetType findWidgetTypeByTenantIdBundleAliasAndAlias(TenantId tenantId, String bundleAlias, String alias); |
35 | 35 | ||
36 | - public void deleteWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias); | 36 | + void deleteWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias); |
37 | 37 | ||
38 | } | 38 | } |
@@ -17,8 +17,6 @@ package org.thingsboard.server.dao.widget; | @@ -17,8 +17,6 @@ package org.thingsboard.server.dao.widget; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | -import org.slf4j.Logger; | ||
21 | -import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.server.common.data.Tenant; | 22 | import org.thingsboard.server.common.data.Tenant; |
@@ -28,19 +26,12 @@ import org.thingsboard.server.common.data.widget.WidgetType; | @@ -28,19 +26,12 @@ import org.thingsboard.server.common.data.widget.WidgetType; | ||
28 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 26 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
29 | import org.thingsboard.server.dao.exception.DataValidationException; | 27 | import org.thingsboard.server.dao.exception.DataValidationException; |
30 | import org.thingsboard.server.dao.model.ModelConstants; | 28 | import org.thingsboard.server.dao.model.ModelConstants; |
31 | -import org.thingsboard.server.dao.model.TenantEntity; | ||
32 | -import org.thingsboard.server.dao.model.WidgetTypeEntity; | ||
33 | -import org.thingsboard.server.dao.model.WidgetsBundleEntity; | ||
34 | import org.thingsboard.server.dao.service.DataValidator; | 29 | import org.thingsboard.server.dao.service.DataValidator; |
35 | import org.thingsboard.server.dao.service.Validator; | 30 | import org.thingsboard.server.dao.service.Validator; |
36 | import org.thingsboard.server.dao.tenant.TenantDao; | 31 | import org.thingsboard.server.dao.tenant.TenantDao; |
37 | -import org.thingsboard.server.dao.tenant.TenantService; | ||
38 | 32 | ||
39 | import java.util.List; | 33 | import java.util.List; |
40 | 34 | ||
41 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
42 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
43 | - | ||
44 | @Service | 35 | @Service |
45 | @Slf4j | 36 | @Slf4j |
46 | public class WidgetTypeServiceImpl implements WidgetTypeService { | 37 | public class WidgetTypeServiceImpl implements WidgetTypeService { |
@@ -58,16 +49,14 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -58,16 +49,14 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
58 | public WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId) { | 49 | public WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId) { |
59 | log.trace("Executing findWidgetTypeById [{}]", widgetTypeId); | 50 | log.trace("Executing findWidgetTypeById [{}]", widgetTypeId); |
60 | Validator.validateId(widgetTypeId, "Incorrect widgetTypeId " + widgetTypeId); | 51 | Validator.validateId(widgetTypeId, "Incorrect widgetTypeId " + widgetTypeId); |
61 | - WidgetTypeEntity widgetTypeEntity = widgetTypeDao.findById(widgetTypeId.getId()); | ||
62 | - return getData(widgetTypeEntity); | 52 | + return widgetTypeDao.findById(widgetTypeId.getId()); |
63 | } | 53 | } |
64 | 54 | ||
65 | @Override | 55 | @Override |
66 | public WidgetType saveWidgetType(WidgetType widgetType) { | 56 | public WidgetType saveWidgetType(WidgetType widgetType) { |
67 | log.trace("Executing saveWidgetType [{}]", widgetType); | 57 | log.trace("Executing saveWidgetType [{}]", widgetType); |
68 | widgetTypeValidator.validate(widgetType); | 58 | widgetTypeValidator.validate(widgetType); |
69 | - WidgetTypeEntity widgetTypeEntity = widgetTypeDao.save(widgetType); | ||
70 | - return getData(widgetTypeEntity); | 59 | + return widgetTypeDao.save(widgetType); |
71 | } | 60 | } |
72 | 61 | ||
73 | @Override | 62 | @Override |
@@ -82,8 +71,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -82,8 +71,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
82 | log.trace("Executing findWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias); | 71 | log.trace("Executing findWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias); |
83 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 72 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
84 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); | 73 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); |
85 | - List<WidgetTypeEntity> widgetTypesEntities = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias); | ||
86 | - return convertDataList(widgetTypesEntities); | 74 | + return widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias); |
87 | } | 75 | } |
88 | 76 | ||
89 | @Override | 77 | @Override |
@@ -92,8 +80,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -92,8 +80,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
92 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 80 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
93 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); | 81 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); |
94 | Validator.validateString(alias, "Incorrect alias " + alias); | 82 | Validator.validateString(alias, "Incorrect alias " + alias); |
95 | - WidgetTypeEntity widgetTypeEntity = widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId.getId(), bundleAlias, alias); | ||
96 | - return getData(widgetTypeEntity); | 83 | + return widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId.getId(), bundleAlias, alias); |
97 | } | 84 | } |
98 | 85 | ||
99 | @Override | 86 | @Override |
@@ -101,9 +88,9 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -101,9 +88,9 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
101 | log.trace("Executing deleteWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias); | 88 | log.trace("Executing deleteWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias); |
102 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 89 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
103 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); | 90 | Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias); |
104 | - List<WidgetTypeEntity> widgetTypesEntities = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias); | ||
105 | - for (WidgetTypeEntity widgetTypeEntity : widgetTypesEntities) { | ||
106 | - deleteWidgetType(new WidgetTypeId(widgetTypeEntity.getId())); | 91 | + List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias); |
92 | + for (WidgetType widgetType : widgetTypes) { | ||
93 | + deleteWidgetType(new WidgetTypeId(widgetType.getUuidId())); | ||
107 | } | 94 | } |
108 | } | 95 | } |
109 | 96 | ||
@@ -124,7 +111,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -124,7 +111,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
124 | widgetType.setTenantId(new TenantId(ModelConstants.NULL_UUID)); | 111 | widgetType.setTenantId(new TenantId(ModelConstants.NULL_UUID)); |
125 | } | 112 | } |
126 | if (!widgetType.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { | 113 | if (!widgetType.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { |
127 | - TenantEntity tenant = tenantDao.findById(widgetType.getTenantId().getId()); | 114 | + Tenant tenant = tenantDao.findById(widgetType.getTenantId().getId()); |
128 | if (tenant == null) { | 115 | if (tenant == null) { |
129 | throw new DataValidationException("Widget type is referencing to non-existent tenant!"); | 116 | throw new DataValidationException("Widget type is referencing to non-existent tenant!"); |
130 | } | 117 | } |
@@ -133,8 +120,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -133,8 +120,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
133 | 120 | ||
134 | @Override | 121 | @Override |
135 | protected void validateCreate(WidgetType widgetType) { | 122 | protected void validateCreate(WidgetType widgetType) { |
136 | - | ||
137 | - WidgetsBundleEntity widgetsBundle = widgetsBundleService.findWidgetsBundleByTenantIdAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias()); | 123 | + WidgetsBundle widgetsBundle = widgetsBundleService.findWidgetsBundleByTenantIdAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias()); |
138 | if (widgetsBundle == null) { | 124 | if (widgetsBundle == null) { |
139 | throw new DataValidationException("Widget type is referencing to non-existent widgets bundle!"); | 125 | throw new DataValidationException("Widget type is referencing to non-existent widgets bundle!"); |
140 | } | 126 | } |
@@ -142,7 +128,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -142,7 +128,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
142 | String alias = widgetType.getName().toLowerCase().replaceAll("\\W+", "_"); | 128 | String alias = widgetType.getName().toLowerCase().replaceAll("\\W+", "_"); |
143 | String originalAlias = alias; | 129 | String originalAlias = alias; |
144 | int c = 1; | 130 | int c = 1; |
145 | - WidgetTypeEntity withSameAlias; | 131 | + WidgetType withSameAlias; |
146 | do { | 132 | do { |
147 | withSameAlias = widgetTypeDao.findByTenantIdBundleAliasAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias(), alias); | 133 | withSameAlias = widgetTypeDao.findByTenantIdBundleAliasAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias(), alias); |
148 | if (withSameAlias != null) { | 134 | if (withSameAlias != null) { |
@@ -154,8 +140,8 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | @@ -154,8 +140,8 @@ public class WidgetTypeServiceImpl implements WidgetTypeService { | ||
154 | 140 | ||
155 | @Override | 141 | @Override |
156 | protected void validateUpdate(WidgetType widgetType) { | 142 | protected void validateUpdate(WidgetType widgetType) { |
157 | - WidgetTypeEntity storedWidgetType = widgetTypeDao.findById(widgetType.getId().getId()); | ||
158 | - if (!storedWidgetType.getTenantId().equals(widgetType.getTenantId().getId())) { | 143 | + WidgetType storedWidgetType = widgetTypeDao.findById(widgetType.getId().getId()); |
144 | + if (!storedWidgetType.getTenantId().getId().equals(widgetType.getTenantId().getId())) { | ||
159 | throw new DataValidationException("Can't move existing widget type to different tenant!"); | 145 | throw new DataValidationException("Can't move existing widget type to different tenant!"); |
160 | } | 146 | } |
161 | if (!storedWidgetType.getBundleAlias().equals(widgetType.getBundleAlias())) { | 147 | if (!storedWidgetType.getBundleAlias().equals(widgetType.getBundleAlias())) { |
@@ -18,17 +18,14 @@ package org.thingsboard.server.dao.widget; | @@ -18,17 +18,14 @@ package org.thingsboard.server.dao.widget; | ||
18 | import org.thingsboard.server.common.data.page.TextPageLink; | 18 | import org.thingsboard.server.common.data.page.TextPageLink; |
19 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 19 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
20 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
21 | -import org.thingsboard.server.dao.model.WidgetsBundleEntity; | ||
22 | 21 | ||
23 | import java.util.List; | 22 | import java.util.List; |
24 | import java.util.UUID; | 23 | import java.util.UUID; |
25 | 24 | ||
26 | /** | 25 | /** |
27 | * The Interface WidgetsBundleDao. | 26 | * The Interface WidgetsBundleDao. |
28 | - * | ||
29 | - * @param <T> the generic type | ||
30 | */ | 27 | */ |
31 | -public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | 28 | +public interface WidgetsBundleDao extends Dao<WidgetsBundle> { |
32 | 29 | ||
33 | /** | 30 | /** |
34 | * Save or update widgets bundle object | 31 | * Save or update widgets bundle object |
@@ -36,7 +33,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | @@ -36,7 +33,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | ||
36 | * @param widgetsBundle the widgets bundle object | 33 | * @param widgetsBundle the widgets bundle object |
37 | * @return saved widgets bundle object | 34 | * @return saved widgets bundle object |
38 | */ | 35 | */ |
39 | - WidgetsBundleEntity save(WidgetsBundle widgetsBundle); | 36 | + WidgetsBundle save(WidgetsBundle widgetsBundle); |
40 | 37 | ||
41 | /** | 38 | /** |
42 | * Find widgets bundle by tenantId and alias. | 39 | * Find widgets bundle by tenantId and alias. |
@@ -45,7 +42,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | @@ -45,7 +42,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | ||
45 | * @param alias the alias | 42 | * @param alias the alias |
46 | * @return the widgets bundle object | 43 | * @return the widgets bundle object |
47 | */ | 44 | */ |
48 | - WidgetsBundleEntity findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias); | 45 | + WidgetsBundle findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias); |
49 | 46 | ||
50 | /** | 47 | /** |
51 | * Find system widgets bundles by page link. | 48 | * Find system widgets bundles by page link. |
@@ -53,7 +50,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | @@ -53,7 +50,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | ||
53 | * @param pageLink the page link | 50 | * @param pageLink the page link |
54 | * @return the list of widgets bundles objects | 51 | * @return the list of widgets bundles objects |
55 | */ | 52 | */ |
56 | - List<WidgetsBundleEntity> findSystemWidgetsBundles(TextPageLink pageLink); | 53 | + List<WidgetsBundle> findSystemWidgetsBundles(TextPageLink pageLink); |
57 | 54 | ||
58 | /** | 55 | /** |
59 | * Find tenant widgets bundles by tenantId and page link. | 56 | * Find tenant widgets bundles by tenantId and page link. |
@@ -62,7 +59,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | @@ -62,7 +59,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | ||
62 | * @param pageLink the page link | 59 | * @param pageLink the page link |
63 | * @return the list of widgets bundles objects | 60 | * @return the list of widgets bundles objects |
64 | */ | 61 | */ |
65 | - List<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink); | 62 | + List<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink); |
66 | 63 | ||
67 | /** | 64 | /** |
68 | * Find all tenant widgets bundles (including system) by tenantId and page link. | 65 | * Find all tenant widgets bundles (including system) by tenantId and page link. |
@@ -71,7 +68,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | @@ -71,7 +68,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> { | ||
71 | * @param pageLink the page link | 68 | * @param pageLink the page link |
72 | * @return the list of widgets bundles objects | 69 | * @return the list of widgets bundles objects |
73 | */ | 70 | */ |
74 | - List<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink); | 71 | + List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink); |
75 | 72 | ||
76 | } | 73 | } |
77 | 74 |
@@ -25,24 +25,24 @@ import java.util.List; | @@ -25,24 +25,24 @@ import java.util.List; | ||
25 | 25 | ||
26 | public interface WidgetsBundleService { | 26 | public interface WidgetsBundleService { |
27 | 27 | ||
28 | - public WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId); | 28 | + WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId); |
29 | 29 | ||
30 | - public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle); | 30 | + WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle); |
31 | 31 | ||
32 | - public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId); | 32 | + void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId); |
33 | 33 | ||
34 | - public WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias); | 34 | + WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias); |
35 | 35 | ||
36 | - public TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink); | 36 | + TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink); |
37 | 37 | ||
38 | - public List<WidgetsBundle> findSystemWidgetsBundles(); | 38 | + List<WidgetsBundle> findSystemWidgetsBundles(); |
39 | 39 | ||
40 | - public TextPageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, TextPageLink pageLink); | 40 | + TextPageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, TextPageLink pageLink); |
41 | 41 | ||
42 | - public TextPageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); | 42 | + TextPageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink); |
43 | 43 | ||
44 | - public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId); | 44 | + List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId); |
45 | 45 | ||
46 | - public void deleteWidgetsBundlesByTenantId(TenantId tenantId); | 46 | + void deleteWidgetsBundlesByTenantId(TenantId tenantId); |
47 | 47 | ||
48 | } | 48 | } |
@@ -17,10 +17,9 @@ package org.thingsboard.server.dao.widget; | @@ -17,10 +17,9 @@ package org.thingsboard.server.dao.widget; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | -import org.slf4j.Logger; | ||
21 | -import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
22 | +import org.thingsboard.server.common.data.Tenant; | ||
24 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
25 | import org.thingsboard.server.common.data.id.WidgetsBundleId; | 24 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
26 | import org.thingsboard.server.common.data.page.TextPageData; | 25 | import org.thingsboard.server.common.data.page.TextPageData; |
@@ -29,8 +28,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle; | @@ -29,8 +28,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle; | ||
29 | import org.thingsboard.server.dao.exception.DataValidationException; | 28 | import org.thingsboard.server.dao.exception.DataValidationException; |
30 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 29 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
31 | import org.thingsboard.server.dao.model.ModelConstants; | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | -import org.thingsboard.server.dao.model.TenantEntity; | ||
33 | -import org.thingsboard.server.dao.model.WidgetsBundleEntity; | ||
34 | import org.thingsboard.server.dao.service.DataValidator; | 31 | import org.thingsboard.server.dao.service.DataValidator; |
35 | import org.thingsboard.server.dao.service.PaginatedRemover; | 32 | import org.thingsboard.server.dao.service.PaginatedRemover; |
36 | import org.thingsboard.server.dao.service.Validator; | 33 | import org.thingsboard.server.dao.service.Validator; |
@@ -39,13 +36,12 @@ import org.thingsboard.server.dao.tenant.TenantDao; | @@ -39,13 +36,12 @@ import org.thingsboard.server.dao.tenant.TenantDao; | ||
39 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
40 | import java.util.List; | 37 | import java.util.List; |
41 | 38 | ||
42 | -import static org.thingsboard.server.dao.DaoUtil.convertDataList; | ||
43 | -import static org.thingsboard.server.dao.DaoUtil.getData; | ||
44 | - | ||
45 | @Service | 39 | @Service |
46 | @Slf4j | 40 | @Slf4j |
47 | public class WidgetsBundleServiceImpl implements WidgetsBundleService { | 41 | public class WidgetsBundleServiceImpl implements WidgetsBundleService { |
48 | 42 | ||
43 | + private static final int DEFAULT_WIDGETS_BUNDLE_LIMIT = 300; | ||
44 | + | ||
49 | @Autowired | 45 | @Autowired |
50 | private WidgetsBundleDao widgetsBundleDao; | 46 | private WidgetsBundleDao widgetsBundleDao; |
51 | 47 | ||
@@ -59,16 +55,14 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -59,16 +55,14 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
59 | public WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId) { | 55 | public WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId) { |
60 | log.trace("Executing findWidgetsBundleById [{}]", widgetsBundleId); | 56 | log.trace("Executing findWidgetsBundleById [{}]", widgetsBundleId); |
61 | Validator.validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId); | 57 | Validator.validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId); |
62 | - WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.findById(widgetsBundleId.getId()); | ||
63 | - return getData(widgetsBundleEntity); | 58 | + return widgetsBundleDao.findById(widgetsBundleId.getId()); |
64 | } | 59 | } |
65 | 60 | ||
66 | @Override | 61 | @Override |
67 | public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle) { | 62 | public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle) { |
68 | log.trace("Executing saveWidgetsBundle [{}]", widgetsBundle); | 63 | log.trace("Executing saveWidgetsBundle [{}]", widgetsBundle); |
69 | widgetsBundleValidator.validate(widgetsBundle); | 64 | widgetsBundleValidator.validate(widgetsBundle); |
70 | - WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.save(widgetsBundle); | ||
71 | - return getData(widgetsBundleEntity); | 65 | + return widgetsBundleDao.save(widgetsBundle); |
72 | } | 66 | } |
73 | 67 | ||
74 | @Override | 68 | @Override |
@@ -88,25 +82,22 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -88,25 +82,22 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
88 | log.trace("Executing findWidgetsBundleByTenantIdAndAlias, tenantId [{}], alias [{}]", tenantId, alias); | 82 | log.trace("Executing findWidgetsBundleByTenantIdAndAlias, tenantId [{}], alias [{}]", tenantId, alias); |
89 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 83 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
90 | Validator.validateString(alias, "Incorrect alias " + alias); | 84 | Validator.validateString(alias, "Incorrect alias " + alias); |
91 | - WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(tenantId.getId(), alias); | ||
92 | - return getData(widgetsBundleEntity); | 85 | + return widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(tenantId.getId(), alias); |
93 | } | 86 | } |
94 | 87 | ||
95 | @Override | 88 | @Override |
96 | public TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink) { | 89 | public TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink) { |
97 | log.trace("Executing findSystemWidgetsBundles, pageLink [{}]", pageLink); | 90 | log.trace("Executing findSystemWidgetsBundles, pageLink [{}]", pageLink); |
98 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 91 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
99 | - List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findSystemWidgetsBundles(pageLink); | ||
100 | - List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities); | ||
101 | - return new TextPageData<>(widgetsBundles, pageLink); | 92 | + return new TextPageData<>(widgetsBundleDao.findSystemWidgetsBundles(pageLink), pageLink); |
102 | } | 93 | } |
103 | 94 | ||
104 | @Override | 95 | @Override |
105 | public List<WidgetsBundle> findSystemWidgetsBundles() { | 96 | public List<WidgetsBundle> findSystemWidgetsBundles() { |
106 | log.trace("Executing findSystemWidgetsBundles"); | 97 | log.trace("Executing findSystemWidgetsBundles"); |
107 | List<WidgetsBundle> widgetsBundles = new ArrayList<>(); | 98 | List<WidgetsBundle> widgetsBundles = new ArrayList<>(); |
108 | - TextPageLink pageLink = new TextPageLink(300); | ||
109 | - TextPageData<WidgetsBundle> pageData = null; | 99 | + TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT); |
100 | + TextPageData<WidgetsBundle> pageData; | ||
110 | do { | 101 | do { |
111 | pageData = findSystemWidgetsBundlesByPageLink(pageLink); | 102 | pageData = findSystemWidgetsBundlesByPageLink(pageLink); |
112 | widgetsBundles.addAll(pageData.getData()); | 103 | widgetsBundles.addAll(pageData.getData()); |
@@ -122,9 +113,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -122,9 +113,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
122 | log.trace("Executing findTenantWidgetsBundlesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 113 | log.trace("Executing findTenantWidgetsBundlesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
123 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 114 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
124 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 115 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
125 | - List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink); | ||
126 | - List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities); | ||
127 | - return new TextPageData<>(widgetsBundles, pageLink); | 116 | + return new TextPageData<>(widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink), pageLink); |
128 | } | 117 | } |
129 | 118 | ||
130 | @Override | 119 | @Override |
@@ -132,9 +121,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -132,9 +121,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
132 | log.trace("Executing findAllTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); | 121 | log.trace("Executing findAllTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink); |
133 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 122 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
134 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); | 123 | Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink); |
135 | - List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink); | ||
136 | - List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities); | ||
137 | - return new TextPageData<>(widgetsBundles, pageLink); | 124 | + return new TextPageData<>(widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink), pageLink); |
138 | } | 125 | } |
139 | 126 | ||
140 | @Override | 127 | @Override |
@@ -142,8 +129,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -142,8 +129,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
142 | log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId); | 129 | log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId); |
143 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); | 130 | Validator.validateId(tenantId, "Incorrect tenantId " + tenantId); |
144 | List<WidgetsBundle> widgetsBundles = new ArrayList<>(); | 131 | List<WidgetsBundle> widgetsBundles = new ArrayList<>(); |
145 | - TextPageLink pageLink = new TextPageLink(300); | ||
146 | - TextPageData<WidgetsBundle> pageData = null; | 132 | + TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT); |
133 | + TextPageData<WidgetsBundle> pageData; | ||
147 | do { | 134 | do { |
148 | pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink); | 135 | pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink); |
149 | widgetsBundles.addAll(pageData.getData()); | 136 | widgetsBundles.addAll(pageData.getData()); |
@@ -173,7 +160,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -173,7 +160,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
173 | widgetsBundle.setTenantId(new TenantId(ModelConstants.NULL_UUID)); | 160 | widgetsBundle.setTenantId(new TenantId(ModelConstants.NULL_UUID)); |
174 | } | 161 | } |
175 | if (!widgetsBundle.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { | 162 | if (!widgetsBundle.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { |
176 | - TenantEntity tenant = tenantDao.findById(widgetsBundle.getTenantId().getId()); | 163 | + Tenant tenant = tenantDao.findById(widgetsBundle.getTenantId().getId()); |
177 | if (tenant == null) { | 164 | if (tenant == null) { |
178 | throw new DataValidationException("Widgets bundle is referencing to non-existent tenant!"); | 165 | throw new DataValidationException("Widgets bundle is referencing to non-existent tenant!"); |
179 | } | 166 | } |
@@ -185,7 +172,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -185,7 +172,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
185 | String alias = widgetsBundle.getTitle().toLowerCase().replaceAll("\\W+", "_"); | 172 | String alias = widgetsBundle.getTitle().toLowerCase().replaceAll("\\W+", "_"); |
186 | String originalAlias = alias; | 173 | String originalAlias = alias; |
187 | int c = 1; | 174 | int c = 1; |
188 | - WidgetsBundleEntity withSameAlias; | 175 | + WidgetsBundle withSameAlias; |
189 | do { | 176 | do { |
190 | withSameAlias = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(widgetsBundle.getTenantId().getId(), alias); | 177 | withSameAlias = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(widgetsBundle.getTenantId().getId(), alias); |
191 | if (withSameAlias != null) { | 178 | if (withSameAlias != null) { |
@@ -197,8 +184,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -197,8 +184,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
197 | 184 | ||
198 | @Override | 185 | @Override |
199 | protected void validateUpdate(WidgetsBundle widgetsBundle) { | 186 | protected void validateUpdate(WidgetsBundle widgetsBundle) { |
200 | - WidgetsBundleEntity storedWidgetsBundle = widgetsBundleDao.findById(widgetsBundle.getId().getId()); | ||
201 | - if (!storedWidgetsBundle.getTenantId().equals(widgetsBundle.getTenantId().getId())) { | 187 | + WidgetsBundle storedWidgetsBundle = widgetsBundleDao.findById(widgetsBundle.getId().getId()); |
188 | + if (!storedWidgetsBundle.getTenantId().getId().equals(widgetsBundle.getTenantId().getId())) { | ||
202 | throw new DataValidationException("Can't move existing widgets bundle to different tenant!"); | 189 | throw new DataValidationException("Can't move existing widgets bundle to different tenant!"); |
203 | } | 190 | } |
204 | if (!storedWidgetsBundle.getAlias().equals(widgetsBundle.getAlias())) { | 191 | if (!storedWidgetsBundle.getAlias().equals(widgetsBundle.getAlias())) { |
@@ -208,17 +195,17 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | @@ -208,17 +195,17 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService { | ||
208 | 195 | ||
209 | }; | 196 | }; |
210 | 197 | ||
211 | - private PaginatedRemover<TenantId, WidgetsBundleEntity> tenantWidgetsBundleRemover = | ||
212 | - new PaginatedRemover<TenantId, WidgetsBundleEntity>() { | 198 | + private PaginatedRemover<TenantId, WidgetsBundle> tenantWidgetsBundleRemover = |
199 | + new PaginatedRemover<TenantId, WidgetsBundle>() { | ||
213 | 200 | ||
214 | @Override | 201 | @Override |
215 | - protected List<WidgetsBundleEntity> findEntities(TenantId id, TextPageLink pageLink) { | 202 | + protected List<WidgetsBundle> findEntities(TenantId id, TextPageLink pageLink) { |
216 | return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(id.getId(), pageLink); | 203 | return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(id.getId(), pageLink); |
217 | } | 204 | } |
218 | 205 | ||
219 | @Override | 206 | @Override |
220 | - protected void removeEntity(WidgetsBundleEntity entity) { | ||
221 | - deleteWidgetsBundle(new WidgetsBundleId(entity.getId())); | 207 | + protected void removeEntity(WidgetsBundle entity) { |
208 | + deleteWidgetsBundle(new WidgetsBundleId(entity.getUuidId())); | ||
222 | } | 209 | } |
223 | }; | 210 | }; |
224 | 211 |