thingsboard-memoizeit
Changes
application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java 27(+11 -16)
dao/pom.xml 4(+4 -0)
dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorService.java 20(+7 -13)
dao/src/main/java/org/thingsboard/server/dao/component/CassandraBaseComponentDescriptorDao.java 45(+23 -22)
pom.xml 5(+5 -0)
Details
diff --git a/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java b/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java
index 876b525..ed75b10 100644
--- a/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java
+++ b/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java
@@ -15,16 +15,7 @@
*/
package org.thingsboard.server.actors.plugin;
-import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
-
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
-import com.datastax.driver.core.Row;
+import akka.actor.ActorRef;
import com.google.common.base.Function;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
@@ -32,18 +23,20 @@ import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Device;
-import org.thingsboard.server.common.data.id.*;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.DeviceId;
+import org.thingsboard.server.common.data.id.PluginId;
+import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.kv.AttributeKey;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.kv.TsKvQuery;
-import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.msg.cluster.ServerAddress;
import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg;
import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext;
-import org.thingsboard.server.extensions.api.plugins.PluginContext;
import org.thingsboard.server.extensions.api.plugins.PluginCallback;
+import org.thingsboard.server.extensions.api.plugins.PluginContext;
import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg;
import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg;
import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest;
@@ -52,10 +45,12 @@ import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg;
import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef;
import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg;
-import akka.actor.ActorRef;
-import org.w3c.dom.Attr;
-
import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
@Slf4j
public final class PluginProcessingContext implements PluginContext {
diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java
index 1b6696f..034206f 100644
--- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java
+++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java
@@ -15,8 +15,6 @@
*/
package org.thingsboard.server.controller;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
index b08a964..3df1bae 100644
--- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
+++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
@@ -23,19 +23,16 @@ import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
-import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.exception.ThingsboardException;
-import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg;
import org.thingsboard.server.service.security.model.SecurityUser;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
@RestController
@RequestMapping("/api")
diff --git a/application/src/main/java/org/thingsboard/server/controller/PluginController.java b/application/src/main/java/org/thingsboard/server/controller/PluginController.java
index 5132664..5dd14cc 100644
--- a/application/src/main/java/org/thingsboard/server/controller/PluginController.java
+++ b/application/src/main/java/org/thingsboard/server/controller/PluginController.java
@@ -25,7 +25,6 @@ import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.common.data.plugin.PluginMetaData;
import org.thingsboard.server.common.data.security.Authority;
-import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.exception.ThingsboardException;
diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml
index 778406a..8766e57 100644
--- a/application/src/main/resources/thingsboard.yml
+++ b/application/src/main/resources/thingsboard.yml
@@ -188,3 +188,15 @@ cache:
updates:
# Enable/disable updates checking.
enabled: "${UPDATES_ENABLED:true}"
+
+cassandra:
+ enabled: "${CASSANDRA_ENABLED:true}"
+
+# SQL DAO Configuration
+
+sql:
+ enabled: "${SQL_ENABLED:false}"
+ datasource:
+ url: "${SQL_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"
+ username: "${SQL_DATASOURCE_USERNAME:postgres}"
+ password: "${SQL_DATASOURCE_PASSWORD:postgres}"
diff --git a/application/src/test/java/org/thingsboard/server/controller/DashboardControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/DashboardControllerTest.java
index e6eb243..329b42d 100644
--- a/application/src/test/java/org/thingsboard/server/controller/DashboardControllerTest.java
+++ b/application/src/test/java/org/thingsboard/server/controller/DashboardControllerTest.java
@@ -35,7 +35,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.core.type.TypeReference;
public class DashboardControllerTest extends AbstractControllerTest {
diff --git a/application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java
index 69bb761..0f2fa12 100644
--- a/application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java
+++ b/application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java
@@ -42,7 +42,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.core.type.TypeReference;
public class DeviceControllerTest extends AbstractControllerTest {
diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleMetaData.java b/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleMetaData.java
index ecbc86c..ececfdd 100644
--- a/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleMetaData.java
+++ b/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleMetaData.java
@@ -15,14 +15,11 @@
*/
package org.thingsboard.server.common.data.rule;
+import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
-import lombok.ToString;
import org.thingsboard.server.common.data.SearchTextBased;
-import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.RuleId;
import org.thingsboard.server.common.data.id.TenantId;
-
-import com.fasterxml.jackson.databind.JsonNode;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
@Data
dao/pom.xml 4(+4 -0)
diff --git a/dao/pom.xml b/dao/pom.xml
index 146b8c1..977be95 100644
--- a/dao/pom.xml
+++ b/dao/pom.xml
@@ -150,6 +150,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java
index ae58d4d..6696f39 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesDao.java
@@ -15,8 +15,6 @@
*/
package org.thingsboard.server.dao.attributes;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java
index 6bf9fb2..222ffa3 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/attributes/AttributesService.java
@@ -15,12 +15,8 @@
*/
package org.thingsboard.server.dao.attributes;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
import com.google.common.util.concurrent.ListenableFuture;
-import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.EntityId;
-import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import java.util.Collection;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java b/dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java
index 4361241..5ed231b 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/attributes/BaseAttributesService.java
@@ -15,16 +15,14 @@
*/
package org.thingsboard.server.dao.attributes;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.service.Validator;
import java.util.Collection;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
index 62e3762..efe05f8 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraCluster.java
@@ -16,13 +16,8 @@
package org.thingsboard.server.dao.cassandra;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.HostDistance;
-import com.datastax.driver.core.PoolingOptions;
+import com.datastax.driver.core.*;
import com.datastax.driver.core.ProtocolOptions.Compression;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.MappingManager;
import lombok.Data;
@@ -31,16 +26,13 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import org.thingsboard.server.dao.exception.DatabaseException;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import java.io.Closeable;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.StringTokenizer;
@Component
@Slf4j
diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraQueryOptions.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraQueryOptions.java
index d5460b0..27ac661 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraQueryOptions.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraQueryOptions.java
@@ -21,12 +21,9 @@ import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
-
@Component
@Configuration
@Data
diff --git a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraSocketOptions.java b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraSocketOptions.java
index c6f51d1..b4cb7ba 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraSocketOptions.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/cassandra/CassandraSocketOptions.java
@@ -15,13 +15,12 @@
*/
package org.thingsboard.server.dao.cassandra;
+import com.datastax.driver.core.SocketOptions;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
-import com.datastax.driver.core.SocketOptions;
-
import javax.annotation.PostConstruct;
@Component
diff --git a/dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorService.java b/dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorService.java
index 22fa19d..3a89e55 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/component/BaseComponentDescriptorService.java
@@ -32,16 +32,12 @@ import org.thingsboard.server.common.data.plugin.ComponentScope;
import org.thingsboard.server.common.data.plugin.ComponentType;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.thingsboard.server.dao.model.ComponentDescriptorEntity;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.Validator;
import java.util.List;
import java.util.Optional;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
/**
* @author Andrew Shvayka
*/
@@ -55,39 +51,37 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic
@Override
public ComponentDescriptor saveComponent(ComponentDescriptor component) {
componentValidator.validate(component);
- Optional<ComponentDescriptorEntity> result = componentDescriptorDao.save(component);
+ Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(component);
if (result.isPresent()) {
- return getData(result.get());
+ return result.get();
} else {
- return getData(componentDescriptorDao.findByClazz(component.getClazz()));
+ return componentDescriptorDao.findByClazz(component.getClazz());
}
}
@Override
public ComponentDescriptor findById(ComponentDescriptorId componentId) {
Validator.validateId(componentId, "Incorrect component id for search request.");
- return getData(componentDescriptorDao.findById(componentId));
+ return componentDescriptorDao.findById(componentId);
}
@Override
public ComponentDescriptor findByClazz(String clazz) {
Validator.validateString(clazz, "Incorrect clazz for search request.");
- return getData(componentDescriptorDao.findByClazz(clazz));
+ return componentDescriptorDao.findByClazz(clazz);
}
@Override
public TextPageData<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request.");
- List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByTypeAndPageLink(type, pageLink);
- List<ComponentDescriptor> components = convertDataList(pluginEntities);
+ List<ComponentDescriptor> components = componentDescriptorDao.findByTypeAndPageLink(type, pageLink);
return new TextPageData<>(components, pageLink);
}
@Override
public TextPageData<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin components request.");
- List<ComponentDescriptorEntity> pluginEntities = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink);
- List<ComponentDescriptor> components = convertDataList(pluginEntities);
+ List<ComponentDescriptor> components = componentDescriptorDao.findByScopeAndTypeAndPageLink(scope, type, pageLink);
return new TextPageData<>(components, pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/component/ComponentDescriptorDao.java b/dao/src/main/java/org/thingsboard/server/dao/component/ComponentDescriptorDao.java
index 0496068..cfbcaae 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/component/ComponentDescriptorDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/component/ComponentDescriptorDao.java
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
import org.thingsboard.server.common.data.plugin.ComponentScope;
import org.thingsboard.server.common.data.plugin.ComponentType;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.ComponentDescriptorEntity;
import java.util.List;
import java.util.Optional;
@@ -29,17 +28,17 @@ import java.util.Optional;
/**
* @author Andrew Shvayka
*/
-public interface ComponentDescriptorDao extends Dao<ComponentDescriptorEntity> {
+public interface ComponentDescriptorDao extends Dao<ComponentDescriptor> {
- Optional<ComponentDescriptorEntity> save(ComponentDescriptor component);
+ Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component);
- ComponentDescriptorEntity findById(ComponentDescriptorId componentId);
+ ComponentDescriptor findById(ComponentDescriptorId componentId);
- ComponentDescriptorEntity findByClazz(String clazz);
+ ComponentDescriptor findByClazz(String clazz);
- List<ComponentDescriptorEntity> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink);
+ List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink);
- List<ComponentDescriptorEntity> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink);
+ List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink);
void deleteById(ComponentDescriptorId componentId);
diff --git a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java
index 6d7247b..e26fc98 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerDao.java
@@ -15,18 +15,17 @@
*/
package org.thingsboard.server.dao.customer;
-import java.util.List;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.CustomerEntity;
+
+import java.util.List;
+import java.util.UUID;
/**
* The Interface CustomerDao.
*/
-public interface CustomerDao extends Dao<CustomerEntity> {
+public interface CustomerDao extends Dao<Customer> {
/**
* Save or update customer object
@@ -34,7 +33,7 @@ public interface CustomerDao extends Dao<CustomerEntity> {
* @param customer the customer object
* @return saved customer object
*/
- CustomerEntity save(Customer customer);
+ Customer save(Customer customer);
/**
* Find customers by tenant id and page link.
@@ -43,6 +42,6 @@ public interface CustomerDao extends Dao<CustomerEntity> {
* @param pageLink the page link
* @return the list of customer objects
*/
- List<CustomerEntity> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerService.java b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerService.java
index 70321a2..566d718 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerService.java
@@ -23,14 +23,14 @@ import org.thingsboard.server.common.data.page.TextPageLink;
public interface CustomerService {
- public Customer findCustomerById(CustomerId customerId);
+ Customer findCustomerById(CustomerId customerId);
- public Customer saveCustomer(Customer customer);
+ Customer saveCustomer(Customer customer);
- public void deleteCustomer(CustomerId customerId);
+ void deleteCustomer(CustomerId customerId);
- public TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink);
+ TextPageData<Customer> findCustomersByTenantId(TenantId tenantId, TextPageLink pageLink);
- public void deleteCustomersByTenantId(TenantId tenantId);
+ void deleteCustomersByTenantId(TenantId tenantId);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
index 18ead42..3e9e472 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
@@ -15,14 +15,12 @@
*/
package org.thingsboard.server.dao.customer;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
-import java.util.List;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Customer;
+import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageData;
@@ -31,17 +29,13 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.thingsboard.server.dao.model.CustomerEntity;
-import org.thingsboard.server.dao.model.TenantEntity;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
+import org.thingsboard.server.dao.service.Validator;
import org.thingsboard.server.dao.tenant.TenantDao;
import org.thingsboard.server.dao.user.UserService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.thingsboard.server.dao.service.Validator;
+
+import java.util.List;
@Service
@Slf4j
public class CustomerServiceImpl implements CustomerService {
@@ -65,16 +59,14 @@ public class CustomerServiceImpl implements CustomerService {
public Customer findCustomerById(CustomerId customerId) {
log.trace("Executing findCustomerById [{}]", customerId);
Validator.validateId(customerId, "Incorrect customerId " + customerId);
- CustomerEntity customerEntity = customerDao.findById(customerId.getId());
- return getData(customerEntity);
+ return customerDao.findById(customerId.getId());
}
@Override
public Customer saveCustomer(Customer customer) {
log.trace("Executing saveCustomer [{}]", customer);
customerValidator.validate(customer);
- CustomerEntity customerEntity = customerDao.save(customer);
- return getData(customerEntity);
+ return customerDao.save(customer);
}
@Override
@@ -96,8 +88,7 @@ public class CustomerServiceImpl implements CustomerService {
log.trace("Executing findCustomersByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<CustomerEntity> customerEntities = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink);
- List<Customer> customers = convertDataList(customerEntities);
+ List<Customer> customers = customerDao.findCustomersByTenantId(tenantId.getId(), pageLink);
return new TextPageData<Customer>(customers, pageLink);
}
@@ -121,7 +112,7 @@ public class CustomerServiceImpl implements CustomerService {
if (customer.getTenantId() == null) {
throw new DataValidationException("Customer should be assigned to tenant!");
} else {
- TenantEntity tenant = tenantDao.findById(customer.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(customer.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("Customer is referencing to non-existent tenant!");
}
@@ -129,17 +120,17 @@ public class CustomerServiceImpl implements CustomerService {
}
};
- private PaginatedRemover<TenantId, CustomerEntity> customersByTenantRemover =
- new PaginatedRemover<TenantId, CustomerEntity>() {
+ private PaginatedRemover<TenantId, Customer> customersByTenantRemover =
+ new PaginatedRemover<TenantId, Customer>() {
@Override
- protected List<CustomerEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<Customer> findEntities(TenantId id, TextPageLink pageLink) {
return customerDao.findCustomersByTenantId(id.getId(), pageLink);
}
@Override
- protected void removeEntity(CustomerEntity entity) {
- deleteCustomer(new CustomerId(entity.getId()));
+ protected void removeEntity(Customer entity) {
+ deleteCustomer(new CustomerId(entity.getUuidId()));
}
};
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/Dao.java b/dao/src/main/java/org/thingsboard/server/dao/Dao.java
index 2703cdc..f0580eb 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/Dao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/Dao.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao;
-import com.datastax.driver.core.ResultSet;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
@@ -31,6 +30,6 @@ public interface Dao<T> {
T save(T t);
- ResultSet removeById(UUID id);
+ boolean removeById(UUID id);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java
index 27499bb..42823a1 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java
@@ -15,15 +15,11 @@
*/
package org.thingsboard.server.dao;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.dao.model.ToData;
+import java.util.*;
+
public abstract class DaoUtil {
private DaoUtil() {
diff --git a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java
index 2b9920a..f2563ca 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardDao.java
@@ -15,21 +15,13 @@
*/
package org.thingsboard.server.dao.dashboard;
-import java.util.List;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.Dashboard;
-import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.DashboardEntity;
-import org.thingsboard.server.dao.model.DashboardInfoEntity;
/**
* The Interface DashboardDao.
- *
- * @param <T> the generic type
*/
-public interface DashboardDao extends Dao<DashboardEntity> {
+public interface DashboardDao extends Dao<Dashboard> {
/**
* Save or update dashboard object
@@ -37,6 +29,6 @@ public interface DashboardDao extends Dao<DashboardEntity> {
* @param dashboard the dashboard object
* @return saved dashboard object
*/
- DashboardEntity save(Dashboard dashboard);
+ Dashboard save(Dashboard dashboard);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardInfoDao.java b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardInfoDao.java
index 9852b35..a26bd14 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardInfoDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardInfoDao.java
@@ -15,21 +15,17 @@
*/
package org.thingsboard.server.dao.dashboard;
-import java.util.List;
-import java.util.UUID;
-
-import org.thingsboard.server.common.data.Dashboard;
+import org.thingsboard.server.common.data.DashboardInfo;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.DashboardEntity;
-import org.thingsboard.server.dao.model.DashboardInfoEntity;
+
+import java.util.List;
+import java.util.UUID;
/**
* The Interface DashboardInfoDao.
- *
- * @param <T> the generic type
*/
-public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
+public interface DashboardInfoDao extends Dao<DashboardInfo> {
/**
* Find dashboards by tenantId and page link.
@@ -38,7 +34,7 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
* @param pageLink the page link
* @return the list of dashboard objects
*/
- List<DashboardInfoEntity> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink);
/**
* Find dashboards by tenantId, customerId and page link.
@@ -48,6 +44,6 @@ public interface DashboardInfoDao extends Dao<DashboardInfoEntity> {
* @param pageLink the page link
* @return the list of dashboard objects
*/
- List<DashboardInfoEntity> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
+ List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardService.java b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardService.java
index 8c86064..b49b5b4 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardService.java
@@ -25,22 +25,22 @@ import org.thingsboard.server.common.data.page.TextPageLink;
public interface DashboardService {
- public Dashboard findDashboardById(DashboardId dashboardId);
-
- public Dashboard saveDashboard(Dashboard dashboard);
-
- public Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId);
+ Dashboard findDashboardById(DashboardId dashboardId);
- public Dashboard unassignDashboardFromCustomer(DashboardId dashboardId);
+ Dashboard saveDashboard(Dashboard dashboard);
- public void deleteDashboard(DashboardId dashboardId);
-
- public TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink);
+ Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId);
- public void deleteDashboardsByTenantId(TenantId tenantId);
-
- public TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink);
+ Dashboard unassignDashboardFromCustomer(DashboardId dashboardId);
+
+ void deleteDashboard(DashboardId dashboardId);
+
+ TextPageData<DashboardInfo> findDashboardsByTenantId(TenantId tenantId, TextPageLink pageLink);
+
+ void deleteDashboardsByTenantId(TenantId tenantId);
+
+ TextPageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, TextPageLink pageLink);
+
+ void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId);
- public void unassignCustomerDashboards(TenantId tenantId, CustomerId customerId);
-
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java
index 2e0abfb..fca73c4 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java
@@ -15,15 +15,14 @@
*/
package org.thingsboard.server.dao.dashboard;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
-import java.util.List;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.DashboardInfo;
+import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId;
@@ -31,15 +30,13 @@ import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.*;
+import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
-import org.thingsboard.server.dao.tenant.TenantDao;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.service.Validator;
+import org.thingsboard.server.dao.tenant.TenantDao;
+
+import java.util.List;
@Service
@Slf4j
@@ -61,16 +58,14 @@ public class DashboardServiceImpl implements DashboardService {
public Dashboard findDashboardById(DashboardId dashboardId) {
log.trace("Executing findDashboardById [{}]", dashboardId);
Validator.validateId(dashboardId, "Incorrect dashboardId " + dashboardId);
- DashboardEntity dashboardEntity = dashboardDao.findById(dashboardId.getId());
- return getData(dashboardEntity);
+ return dashboardDao.findById(dashboardId.getId());
}
@Override
public Dashboard saveDashboard(Dashboard dashboard) {
log.trace("Executing saveDashboard [{}]", dashboard);
dashboardValidator.validate(dashboard);
- DashboardEntity dashboardEntity = dashboardDao.save(dashboard);
- return getData(dashboardEntity);
+ return dashboardDao.save(dashboard);
}
@Override
@@ -99,9 +94,8 @@ public class DashboardServiceImpl implements DashboardService {
log.trace("Executing findDashboardsByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink);
- List<DashboardInfo> dashboards = convertDataList(dashboardEntities);
- return new TextPageData<DashboardInfo>(dashboards, pageLink);
+ List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantId(tenantId.getId(), pageLink);
+ return new TextPageData<>(dashboards, pageLink);
}
@Override
@@ -117,9 +111,8 @@ public class DashboardServiceImpl implements DashboardService {
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validateId(customerId, "Incorrect customerId " + customerId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<DashboardInfoEntity> dashboardEntities = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
- List<DashboardInfo> dashboards = convertDataList(dashboardEntities);
- return new TextPageData<DashboardInfo>(dashboards, pageLink);
+ List<DashboardInfo> dashboards = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
+ return new TextPageData<>(dashboards, pageLink);
}
@Override
@@ -140,7 +133,7 @@ public class DashboardServiceImpl implements DashboardService {
if (dashboard.getTenantId() == null) {
throw new DataValidationException("Dashboard should be assigned to tenant!");
} else {
- TenantEntity tenant = tenantDao.findById(dashboard.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(dashboard.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("Dashboard is referencing to non-existent tenant!");
}
@@ -148,32 +141,32 @@ public class DashboardServiceImpl implements DashboardService {
if (dashboard.getCustomerId() == null) {
dashboard.setCustomerId(new CustomerId(ModelConstants.NULL_UUID));
} else if (!dashboard.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
- CustomerEntity customer = customerDao.findById(dashboard.getCustomerId().getId());
+ Customer customer = customerDao.findById(dashboard.getCustomerId().getId());
if (customer == null) {
throw new DataValidationException("Can't assign dashboard to non-existent customer!");
}
- if (!customer.getTenantId().equals(dashboard.getTenantId().getId())) {
+ if (!customer.getTenantId().getId().equals(dashboard.getTenantId().getId())) {
throw new DataValidationException("Can't assign dashboard to customer from different tenant!");
}
}
}
};
- private PaginatedRemover<TenantId, DashboardInfoEntity> tenantDashboardsRemover =
- new PaginatedRemover<TenantId, DashboardInfoEntity>() {
+ private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover =
+ new PaginatedRemover<TenantId, DashboardInfo>() {
@Override
- protected List<DashboardInfoEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<DashboardInfo> findEntities(TenantId id, TextPageLink pageLink) {
return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
}
@Override
- protected void removeEntity(DashboardInfoEntity entity) {
- deleteDashboard(new DashboardId(entity.getId()));
+ protected void removeEntity(DashboardInfo entity) {
+ deleteDashboard(new DashboardId(entity.getUuidId()));
}
};
- class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfoEntity> {
+ private class CustomerDashboardsUnassigner extends PaginatedRemover<CustomerId, DashboardInfo> {
private TenantId tenantId;
@@ -182,13 +175,13 @@ public class DashboardServiceImpl implements DashboardService {
}
@Override
- protected List<DashboardInfoEntity> findEntities(CustomerId id, TextPageLink pageLink) {
+ protected List<DashboardInfo> findEntities(CustomerId id, TextPageLink pageLink) {
return dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
}
@Override
- protected void removeEntity(DashboardInfoEntity entity) {
- unassignDashboardFromCustomer(new DashboardId(entity.getId()));
+ protected void removeEntity(DashboardInfo entity) {
+ unassignDashboardFromCustomer(new DashboardId(entity.getUuidId()));
}
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsDao.java
index 89a4a02..c13129a 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsDao.java
@@ -15,18 +15,15 @@
*/
package org.thingsboard.server.dao.device;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.DeviceCredentialsEntity;
+
+import java.util.UUID;
/**
* The Interface DeviceCredentialsDao.
- *
- * @param <T> the generic type
*/
-public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
+public interface DeviceCredentialsDao extends Dao<DeviceCredentials> {
/**
* Save or update device credentials object
@@ -34,7 +31,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
* @param deviceCredentials the device credentials object
* @return saved device credentials object
*/
- DeviceCredentialsEntity save(DeviceCredentials deviceCredentials);
+ DeviceCredentials save(DeviceCredentials deviceCredentials);
/**
* Find device credentials by device id.
@@ -42,7 +39,7 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
* @param deviceId the device id
* @return the device credentials object
*/
- DeviceCredentialsEntity findByDeviceId(UUID deviceId);
+ DeviceCredentials findByDeviceId(UUID deviceId);
/**
* Find device credentials by credentials id.
@@ -50,6 +47,6 @@ public interface DeviceCredentialsDao extends Dao<DeviceCredentialsEntity> {
* @param credentialsId the credentials id
* @return the device credentials object
*/
- DeviceCredentialsEntity findByCredentialsId(String credentialsId);
+ DeviceCredentials findByCredentialsId(String credentialsId);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java
index 10e329a..ae23221 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java
@@ -26,10 +26,8 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.EncryptionUtil;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.DeviceCredentialsEntity;
import org.thingsboard.server.dao.service.DataValidator;
-import static org.thingsboard.server.dao.DaoUtil.getData;
import static org.thingsboard.server.dao.service.Validator.validateId;
import static org.thingsboard.server.dao.service.Validator.validateString;
@@ -47,16 +45,14 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
public DeviceCredentials findDeviceCredentialsByDeviceId(DeviceId deviceId) {
log.trace("Executing findDeviceCredentialsByDeviceId [{}]", deviceId);
validateId(deviceId, "Incorrect deviceId " + deviceId);
- DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByDeviceId(deviceId.getId());
- return getData(deviceCredentialsEntity);
+ return deviceCredentialsDao.findByDeviceId(deviceId.getId());
}
@Override
public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) {
log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId);
validateString(credentialsId, "Incorrect credentialsId " + credentialsId);
- DeviceCredentialsEntity deviceCredentialsEntity = deviceCredentialsDao.findByCredentialsId(credentialsId);
- return getData(deviceCredentialsEntity);
+ return deviceCredentialsDao.findByCredentialsId(credentialsId);
}
@Override
@@ -75,7 +71,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
}
log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials);
credentialsValidator.validate(deviceCredentials);
- return getData(deviceCredentialsDao.save(deviceCredentials));
+ return deviceCredentialsDao.save(deviceCredentials);
}
private void formatCertData(DeviceCredentials deviceCredentials) {
@@ -96,7 +92,7 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
@Override
protected void validateCreate(DeviceCredentials deviceCredentials) {
- DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
+ DeviceCredentials existingCredentialsEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
if (existingCredentialsEntity != null) {
throw new DataValidationException("Create of existent device credentials!");
}
@@ -104,12 +100,12 @@ public class DeviceCredentialsServiceImpl implements DeviceCredentialsService {
@Override
protected void validateUpdate(DeviceCredentials deviceCredentials) {
- DeviceCredentialsEntity existingCredentialsEntity = deviceCredentialsDao.findById(deviceCredentials.getUuidId());
- if (existingCredentialsEntity == null) {
+ DeviceCredentials existingCredentials = deviceCredentialsDao.findById(deviceCredentials.getUuidId());
+ if (existingCredentials == null) {
throw new DataValidationException("Unable to update non-existent device credentials!");
}
- DeviceCredentialsEntity sameCredentialsIdEntity = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
- if (sameCredentialsIdEntity != null && !sameCredentialsIdEntity.getId().equals(deviceCredentials.getUuidId())) {
+ DeviceCredentials sameCredentialsId = deviceCredentialsDao.findByCredentialsId(deviceCredentials.getCredentialsId());
+ if (sameCredentialsId != null && !sameCredentialsId.getUuidId().equals(deviceCredentials.getUuidId())) {
throw new DataValidationException("Specified credentials are already registered!");
}
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java
index b8d395c..86d2f8f 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java
@@ -15,21 +15,20 @@
*/
package org.thingsboard.server.dao.device;
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
-
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.DeviceEntity;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
/**
* The Interface DeviceDao.
*
*/
-public interface DeviceDao extends Dao<DeviceEntity> {
+public interface DeviceDao extends Dao<Device> {
/**
* Save or update device object
@@ -37,7 +36,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param device the device object
* @return saved device object
*/
- DeviceEntity save(Device device);
+ Device save(Device device);
/**
* Find devices by tenantId and page link.
@@ -46,7 +45,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param pageLink the page link
* @return the list of device objects
*/
- List<DeviceEntity> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink);
/**
* Find devices by tenantId and devices Ids.
@@ -55,7 +54,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param deviceIds the device Ids
* @return the list of device objects
*/
- ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds);
+ ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds);
/**
* Find devices by tenantId, customerId and page link.
@@ -65,7 +64,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param pageLink the page link
* @return the list of device objects
*/
- List<DeviceEntity> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
+ List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink);
/**
* Find devices by tenantId, customerId and devices Ids.
@@ -75,7 +74,7 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param deviceIds the device Ids
* @return the list of device objects
*/
- ListenableFuture<List<DeviceEntity>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds);
+ ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds);
/**
* Find devices by tenantId and device name.
@@ -84,5 +83,5 @@ public interface DeviceDao extends Dao<DeviceEntity> {
* @param name the device name
* @return the optional device object
*/
- Optional<DeviceEntity> findDevicesByTenantIdAndName(UUID tenantId, String name);
+ Optional<Device> findDevicesByTenantIdAndName(UUID tenantId, String name);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
index 3d1ce31..a5707ce 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
@@ -15,15 +15,15 @@
*/
package org.thingsboard.server.dao.device;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
+import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
+import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
@@ -33,9 +33,6 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.CustomerEntity;
-import org.thingsboard.server.dao.model.DeviceEntity;
-import org.thingsboard.server.dao.model.TenantEntity;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.tenant.TenantDao;
@@ -43,8 +40,6 @@ import org.thingsboard.server.dao.tenant.TenantDao;
import java.util.List;
import java.util.Optional;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
import static org.thingsboard.server.dao.service.Validator.validateId;
@@ -71,25 +66,23 @@ public class DeviceServiceImpl implements DeviceService {
public Device findDeviceById(DeviceId deviceId) {
log.trace("Executing findDeviceById [{}]", deviceId);
validateId(deviceId, "Incorrect deviceId " + deviceId);
- DeviceEntity deviceEntity = deviceDao.findById(deviceId.getId());
- return getData(deviceEntity);
+ return deviceDao.findById(deviceId.getId());
}
@Override
public ListenableFuture<Device> findDeviceByIdAsync(DeviceId deviceId) {
log.trace("Executing findDeviceById [{}]", deviceId);
validateId(deviceId, "Incorrect deviceId " + deviceId);
- ListenableFuture<DeviceEntity> deviceEntity = deviceDao.findByIdAsync(deviceId.getId());
- return Futures.transform(deviceEntity, (Function<? super DeviceEntity, ? extends Device>) input -> getData(input));
+ return deviceDao.findByIdAsync(deviceId.getId());
}
@Override
public Optional<Device> findDeviceByTenantIdAndName(TenantId tenantId, String name) {
log.trace("Executing findDeviceByTenantIdAndName [{}][{}]", tenantId, name);
validateId(tenantId, "Incorrect tenantId " + tenantId);
- Optional<DeviceEntity> deviceEntityOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name);
- if (deviceEntityOpt.isPresent()) {
- return Optional.of(getData(deviceEntityOpt.get()));
+ Optional<Device> deviceOpt = deviceDao.findDevicesByTenantIdAndName(tenantId.getId(), name);
+ if (deviceOpt.isPresent()) {
+ return Optional.of(deviceOpt.get());
} else {
return Optional.empty();
}
@@ -99,15 +92,15 @@ public class DeviceServiceImpl implements DeviceService {
public Device saveDevice(Device device) {
log.trace("Executing saveDevice [{}]", device);
deviceValidator.validate(device);
- DeviceEntity deviceEntity = deviceDao.save(device);
+ Device savedDevice = deviceDao.save(device);
if (device.getId() == null) {
DeviceCredentials deviceCredentials = new DeviceCredentials();
- deviceCredentials.setDeviceId(new DeviceId(deviceEntity.getId()));
+ deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId()));
deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
deviceCredentialsService.createDeviceCredentials(deviceCredentials);
}
- return getData(deviceEntity);
+ return savedDevice;
}
@Override
@@ -140,9 +133,8 @@ public class DeviceServiceImpl implements DeviceService {
log.trace("Executing findDevicesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
validateId(tenantId, "Incorrect tenantId " + tenantId);
validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink);
- List<Device> devices = convertDataList(deviceEntities);
- return new TextPageData<Device>(devices, pageLink);
+ List<Device> devices = deviceDao.findDevicesByTenantId(tenantId.getId(), pageLink);
+ return new TextPageData<>(devices, pageLink);
}
@Override
@@ -150,8 +142,7 @@ public class DeviceServiceImpl implements DeviceService {
log.trace("Executing findDevicesByTenantIdAndIdsAsync, tenantId [{}], deviceIds [{}]", tenantId, deviceIds);
validateId(tenantId, "Incorrect tenantId " + tenantId);
validateIds(deviceIds, "Incorrect deviceIds " + deviceIds);
- ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds));
- return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input));
+ return deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId.getId(), toUUIDs(deviceIds));
}
@@ -168,9 +159,8 @@ public class DeviceServiceImpl implements DeviceService {
validateId(tenantId, "Incorrect tenantId " + tenantId);
validateId(customerId, "Incorrect customerId " + customerId);
validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<DeviceEntity> deviceEntities = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
- List<Device> devices = convertDataList(deviceEntities);
- return new TextPageData<Device>(devices, pageLink);
+ List<Device> devices = deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
+ return new TextPageData<>(devices, pageLink);
}
@Override
@@ -179,9 +169,8 @@ public class DeviceServiceImpl implements DeviceService {
validateId(tenantId, "Incorrect tenantId " + tenantId);
validateId(customerId, "Incorrect customerId " + customerId);
validateIds(deviceIds, "Incorrect deviceIds " + deviceIds);
- ListenableFuture<List<DeviceEntity>> deviceEntities = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),
+ return deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId.getId(),
customerId.getId(), toUUIDs(deviceIds));
- return Futures.transform(deviceEntities, (Function<List<DeviceEntity>, List<Device>>) input -> convertDataList(input));
}
@Override
@@ -208,7 +197,7 @@ public class DeviceServiceImpl implements DeviceService {
protected void validateUpdate(Device device) {
deviceDao.findDevicesByTenantIdAndName(device.getTenantId().getId(), device.getName()).ifPresent(
d -> {
- if (!d.getId().equals(device.getUuidId())) {
+ if (!d.getUuidId().equals(device.getUuidId())) {
throw new DataValidationException("Device with such name already exists!");
}
}
@@ -223,7 +212,7 @@ public class DeviceServiceImpl implements DeviceService {
if (device.getTenantId() == null) {
throw new DataValidationException("Device should be assigned to tenant!");
} else {
- TenantEntity tenant = tenantDao.findById(device.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(device.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("Device is referencing to non-existent tenant!");
}
@@ -231,32 +220,32 @@ public class DeviceServiceImpl implements DeviceService {
if (device.getCustomerId() == null) {
device.setCustomerId(new CustomerId(NULL_UUID));
} else if (!device.getCustomerId().getId().equals(NULL_UUID)) {
- CustomerEntity customer = customerDao.findById(device.getCustomerId().getId());
+ Customer customer = customerDao.findById(device.getCustomerId().getId());
if (customer == null) {
throw new DataValidationException("Can't assign device to non-existent customer!");
}
- if (!customer.getTenantId().equals(device.getTenantId().getId())) {
+ if (!customer.getTenantId().getId().equals(device.getTenantId().getId())) {
throw new DataValidationException("Can't assign device to customer from different tenant!");
}
}
}
};
- private PaginatedRemover<TenantId, DeviceEntity> tenantDevicesRemover =
- new PaginatedRemover<TenantId, DeviceEntity>() {
+ private PaginatedRemover<TenantId, Device> tenantDevicesRemover =
+ new PaginatedRemover<TenantId, Device>() {
@Override
- protected List<DeviceEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<Device> findEntities(TenantId id, TextPageLink pageLink) {
return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
}
@Override
- protected void removeEntity(DeviceEntity entity) {
- deleteDevice(new DeviceId(entity.getId()));
+ protected void removeEntity(Device entity) {
+ deleteDevice(new DeviceId(entity.getUuidId()));
}
};
- class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, DeviceEntity> {
+ private class CustomerDevicesUnassigner extends PaginatedRemover<CustomerId, Device> {
private TenantId tenantId;
@@ -265,13 +254,13 @@ public class DeviceServiceImpl implements DeviceService {
}
@Override
- protected List<DeviceEntity> findEntities(CustomerId id, TextPageLink pageLink) {
+ protected List<Device> findEntities(CustomerId id, TextPageLink pageLink) {
return deviceDao.findDevicesByTenantIdAndCustomerId(tenantId.getId(), id.getId(), pageLink);
}
@Override
- protected void removeEntity(DeviceEntity entity) {
- unassignDeviceFromCustomer(new DeviceId(entity.getId()));
+ protected void removeEntity(Device entity) {
+ unassignDeviceFromCustomer(new DeviceId(entity.getUuidId()));
}
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/EncryptionUtil.java b/dao/src/main/java/org/thingsboard/server/dao/EncryptionUtil.java
index 9a4e592..1d74d30 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/EncryptionUtil.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/EncryptionUtil.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao;
-import com.google.common.base.CharMatcher;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.crypto.digests.SHA3Digest;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/event/BaseEventService.java b/dao/src/main/java/org/thingsboard/server/dao/event/BaseEventService.java
index 625f1f5..c5c4e47 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/event/BaseEventService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/event/BaseEventService.java
@@ -15,51 +15,32 @@
*/
package org.thingsboard.server.dao.event;
-import com.datastax.driver.core.utils.UUIDs;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.id.EntityId;
-import org.thingsboard.server.common.data.id.EventId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TimePageData;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.EventEntity;
import org.thingsboard.server.dao.service.DataValidator;
import java.util.List;
import java.util.Optional;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
-
@Service
@Slf4j
public class BaseEventService implements EventService {
- private final TenantId systemTenantId = new TenantId(NULL_UUID);
-
@Autowired
public EventDao eventDao;
@Override
public Event save(Event event) {
eventValidator.validate(event);
- if (event.getTenantId() == null) {
- log.trace("Save system event with predefined id {}", systemTenantId);
- event.setTenantId(systemTenantId);
- }
- if (event.getId() == null) {
- event.setId(new EventId(UUIDs.timeBased()));
- }
- if (StringUtils.isEmpty(event.getUid())) {
- event.setUid(event.getId().toString());
- }
- return getData(eventDao.save(event));
+ return eventDao.save(event);
}
@Override
@@ -68,15 +49,8 @@ public class BaseEventService implements EventService {
if (StringUtils.isEmpty(event.getUid())) {
throw new DataValidationException("Event uid should be specified!.");
}
- if (event.getTenantId() == null) {
- log.trace("Save system event with predefined id {}", systemTenantId);
- event.setTenantId(systemTenantId);
- }
- if (event.getId() == null) {
- event.setId(new EventId(UUIDs.timeBased()));
- }
- Optional<EventEntity> result = eventDao.saveIfNotExists(event);
- return result.isPresent() ? Optional.of(getData(result.get())) : Optional.empty();
+ Optional<Event> result = eventDao.saveIfNotExists(event);
+ return result.isPresent() ? Optional.of(result.get()) : Optional.empty();
}
@Override
@@ -93,23 +67,20 @@ public class BaseEventService implements EventService {
if (StringUtils.isEmpty(eventUid)) {
throw new DataValidationException("Event uid should be specified!.");
}
- EventEntity entity = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid);
- return entity != null ? Optional.of(getData(entity)) : Optional.empty();
+ Event event = eventDao.findEvent(tenantId.getId(), entityId, eventType, eventUid);
+ return event != null ? Optional.of(event) : Optional.empty();
}
@Override
public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, TimePageLink pageLink) {
- List<EventEntity> entities = eventDao.findEvents(tenantId.getId(), entityId, pageLink);
- List<Event> events = convertDataList(entities);
- return new TimePageData<Event>(events, pageLink);
+ List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, pageLink);
+ return new TimePageData<>(events, pageLink);
}
-
@Override
public TimePageData<Event> findEvents(TenantId tenantId, EntityId entityId, String eventType, TimePageLink pageLink) {
- List<EventEntity> entities = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink);
- List<Event> events = convertDataList(entities);
- return new TimePageData<Event>(events, pageLink);
+ List<Event> events = eventDao.findEvents(tenantId.getId(), entityId, eventType, pageLink);
+ return new TimePageData<>(events, pageLink);
}
private DataValidator<Event> eventValidator =
diff --git a/dao/src/main/java/org/thingsboard/server/dao/event/EventDao.java b/dao/src/main/java/org/thingsboard/server/dao/event/EventDao.java
index 1556a5c..846c476 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/event/EventDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/event/EventDao.java
@@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.EventEntity;
import java.util.List;
import java.util.Optional;
@@ -27,10 +26,8 @@ import java.util.UUID;
/**
* The Interface DeviceDao.
- *
- * @param <T> the generic type
*/
-public interface EventDao extends Dao<EventEntity> {
+public interface EventDao extends Dao<Event> {
/**
* Save or update event object
@@ -38,7 +35,7 @@ public interface EventDao extends Dao<EventEntity> {
* @param event the event object
* @return saved event object
*/
- EventEntity save(Event event);
+ Event save(Event event);
/**
* Save event object if it is not yet saved
@@ -46,7 +43,7 @@ public interface EventDao extends Dao<EventEntity> {
* @param event the event object
* @return saved event object
*/
- Optional<EventEntity> saveIfNotExists(Event event);
+ Optional<Event> saveIfNotExists(Event event);
/**
* Find event by tenantId, entityId and eventUid.
@@ -57,7 +54,7 @@ public interface EventDao extends Dao<EventEntity> {
* @param eventUid the eventUid
* @return the event
*/
- EventEntity findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid);
+ Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid);
/**
* Find events by tenantId, entityId and pageLink.
@@ -67,7 +64,7 @@ public interface EventDao extends Dao<EventEntity> {
* @param pageLink the pageLink
* @return the event list
*/
- List<EventEntity> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink);
+ List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink);
/**
* Find events by tenantId, entityId, eventType and pageLink.
@@ -78,5 +75,5 @@ public interface EventDao extends Dao<EventEntity> {
* @param pageLink the pageLink
* @return the event list
*/
- List<EventEntity> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink);
+ List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/event/EventService.java b/dao/src/main/java/org/thingsboard/server/dao/event/EventService.java
index 9237c89..1fb40f1 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/event/EventService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/event/EventService.java
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TimePageData;
import org.thingsboard.server.common.data.page.TimePageLink;
-import java.util.List;
import java.util.Optional;
public interface EventService {
diff --git a/dao/src/main/java/org/thingsboard/server/dao/exception/DatabaseException.java b/dao/src/main/java/org/thingsboard/server/dao/exception/DatabaseException.java
index bb5586d..aa322f6 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/exception/DatabaseException.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/exception/DatabaseException.java
@@ -17,22 +17,22 @@ package org.thingsboard.server.dao.exception;
public class DatabaseException extends RuntimeException {
- private static final long serialVersionUID = 3463762014441887103L;
+ private static final long serialVersionUID = 3463762014441887103L;
- public DatabaseException() {
- super();
- }
+ public DatabaseException() {
+ super();
+ }
- public DatabaseException(String message, Throwable cause) {
- super(message, cause);
- }
+ public DatabaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
- public DatabaseException(String message) {
- super(message);
- }
+ public DatabaseException(String message) {
+ super(message);
+ }
- public DatabaseException(Throwable cause) {
- super(cause);
- }
+ public DatabaseException(Throwable cause) {
+ super(cause);
+ }
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/exception/IncorrectParameterException.java b/dao/src/main/java/org/thingsboard/server/dao/exception/IncorrectParameterException.java
index 3d6450f..6600dc8 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/exception/IncorrectParameterException.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/exception/IncorrectParameterException.java
@@ -18,9 +18,9 @@ package org.thingsboard.server.dao.exception;
public class IncorrectParameterException extends RuntimeException {
- private static final long serialVersionUID = 601995650578985289L;
+ private static final long serialVersionUID = 601995650578985289L;
- public IncorrectParameterException(String message) {
+ public IncorrectParameterException(String message) {
super(message);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/JpaDaoConfig.java b/dao/src/main/java/org/thingsboard/server/dao/JpaDaoConfig.java
new file mode 100644
index 0000000..167518a
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/JpaDaoConfig.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Valerii Sosliuk
+ */
+@Configuration
+@ConditionalOnProperty(prefix="sql", value="enabled",havingValue = "true", matchIfMissing = false)
+public class JpaDaoConfig {
+
+ @Value("sql.datasource.url")
+ private String url;
+ @Value("sql.datasource.username")
+ private String username;
+ @Value("sql.datasource.password")
+ private String password;
+
+ public DataSource dataSource() {
+ return DataSourceBuilder.create().url(url).username(username).password(password).build();
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/AdminSettingsEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/AdminSettingsEntity.java
new file mode 100644
index 0000000..40580ee
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/AdminSettingsEntity.java
@@ -0,0 +1,145 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.AdminSettings;
+import org.thingsboard.server.common.data.id.AdminSettingsId;
+import org.thingsboard.server.dao.model.BaseEntity;
+
+import java.util.UUID;
+
+import static org.thingsboard.server.dao.model.ModelConstants.*;
+
+@Entity
+@Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME)
+public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
+
+ @Transient
+ private static final long serialVersionUID = 842759712850362147L;
+
+ @Id
+ @Column(name = ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ADMIN_SETTINGS_KEY_PROPERTY)
+ private String key;
+
+ @Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY)
+ private JsonNode jsonValue;
+
+ public AdminSettingsEntity() {
+ super();
+ }
+
+ public AdminSettingsEntity(AdminSettings adminSettings) {
+ if (adminSettings.getId() != null) {
+ this.id = adminSettings.getId().getId();
+ }
+ this.key = adminSettings.getKey();
+ this.jsonValue = adminSettings.getJsonValue();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public JsonNode getJsonValue() {
+ return jsonValue;
+ }
+
+ public void setJsonValue(JsonNode jsonValue) {
+ this.jsonValue = jsonValue;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((jsonValue == null) ? 0 : jsonValue.hashCode());
+ result = prime * result + ((key == null) ? 0 : key.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ AdminSettingsEntity other = (AdminSettingsEntity) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (jsonValue == null) {
+ if (other.jsonValue != null)
+ return false;
+ } else if (!jsonValue.equals(other.jsonValue))
+ return false;
+ if (key == null) {
+ if (other.key != null)
+ return false;
+ } else if (!key.equals(other.key))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("AdminSettingsEntity [id=");
+ builder.append(id);
+ builder.append(", key=");
+ builder.append(key);
+ builder.append(", jsonValue=");
+ builder.append(jsonValue);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public AdminSettings toData() {
+ AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id));
+ adminSettings.setCreatedTime(UUIDs.unixTimestamp(id));
+ adminSettings.setKey(key);
+ adminSettings.setJsonValue(jsonValue);
+ return adminSettings;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/ComponentDescriptorEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/ComponentDescriptorEntity.java
new file mode 100644
index 0000000..53bac76
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/ComponentDescriptorEntity.java
@@ -0,0 +1,164 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.id.ComponentDescriptorId;
+import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
+import org.thingsboard.server.common.data.plugin.ComponentScope;
+import org.thingsboard.server.common.data.plugin.ComponentType;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME)
+public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> {
+
+ @Transient
+ private static final long serialVersionUID = 253590350877992402L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY)
+ private ComponentType type;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY)
+ private ComponentScope scope;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY)
+ private String name;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY)
+ private String clazz;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY)
+ private JsonNode configurationDescriptor;
+
+ @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
+ private String actions;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ public ComponentDescriptorEntity() {
+ }
+
+ public ComponentDescriptorEntity(ComponentDescriptor component) {
+ if (component.getId() != null) {
+ this.id = component.getId().getId();
+ }
+ this.actions = component.getActions();
+ this.type = component.getType();
+ this.scope = component.getScope();
+ this.name = component.getName();
+ this.clazz = component.getClazz();
+ this.configurationDescriptor = component.getConfigurationDescriptor();
+ this.searchText = component.getName();
+ }
+
+ @Override
+ public ComponentDescriptor toData() {
+ ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(id));
+ data.setType(type);
+ data.setScope(scope);
+ data.setName(this.getName());
+ data.setClazz(this.getClazz());
+ data.setActions(this.getActions());
+ data.setConfigurationDescriptor(this.getConfigurationDescriptor());
+ return data;
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getActions() {
+ return actions;
+ }
+
+ public void setActions(String actions) {
+ this.actions = actions;
+ }
+
+ public ComponentType getType() {
+ return type;
+ }
+
+ public void setType(ComponentType type) {
+ this.type = type;
+ }
+
+ public ComponentScope getScope() {
+ return scope;
+ }
+
+ public void setScope(ComponentScope scope) {
+ this.scope = scope;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getClazz() {
+ return clazz;
+ }
+
+ public void setClazz(String clazz) {
+ this.clazz = clazz;
+ }
+
+ public JsonNode getConfigurationDescriptor() {
+ return configurationDescriptor;
+ }
+
+ public void setConfigurationDescriptor(JsonNode configurationDescriptor) {
+ this.configurationDescriptor = configurationDescriptor;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return searchText;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java
new file mode 100644
index 0000000..bf7404f
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java
@@ -0,0 +1,351 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.Customer;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME)
+public final class CustomerEntity implements SearchTextEntity<Customer> {
+
+ @Transient
+ private static final long serialVersionUID = 8951342124082981556L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY)
+ private String title;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.COUNTRY_PROPERTY)
+ private String country;
+
+ @Column(name = ModelConstants.STATE_PROPERTY)
+ private String state;
+
+ @Column(name = ModelConstants.CITY_PROPERTY)
+ private String city;
+
+ @Column(name = ModelConstants.ADDRESS_PROPERTY)
+ private String address;
+
+ @Column(name = ModelConstants.ADDRESS2_PROPERTY)
+ private String address2;
+
+ @Column(name = ModelConstants.ZIP_PROPERTY)
+ private String zip;
+
+ @Column(name = ModelConstants.PHONE_PROPERTY)
+ private String phone;
+
+ @Column(name = ModelConstants.EMAIL_PROPERTY)
+ private String email;
+
+ @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public CustomerEntity() {
+ super();
+ }
+
+ public CustomerEntity(Customer customer) {
+ if (customer.getId() != null) {
+ this.id = customer.getId().getId();
+ }
+ this.tenantId = customer.getTenantId().getId();
+ this.title = customer.getTitle();
+ this.country = customer.getCountry();
+ this.state = customer.getState();
+ this.city = customer.getCity();
+ this.address = customer.getAddress();
+ this.address2 = customer.getAddress2();
+ this.zip = customer.getZip();
+ this.phone = customer.getPhone();
+ this.email = customer.getEmail();
+ this.additionalInfo = customer.getAdditionalInfo();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getAddress2() {
+ return address2;
+ }
+
+ public void setAddress2(String address2) {
+ this.address2 = address2;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return title;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode());
+ result = prime * result + ((address == null) ? 0 : address.hashCode());
+ result = prime * result + ((address2 == null) ? 0 : address2.hashCode());
+ result = prime * result + ((city == null) ? 0 : city.hashCode());
+ result = prime * result + ((country == null) ? 0 : country.hashCode());
+ result = prime * result + ((email == null) ? 0 : email.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((phone == null) ? 0 : phone.hashCode());
+ result = prime * result + ((state == null) ? 0 : state.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ result = prime * result + ((zip == null) ? 0 : zip.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CustomerEntity other = (CustomerEntity) obj;
+ if (additionalInfo == null) {
+ if (other.additionalInfo != null)
+ return false;
+ } else if (!additionalInfo.equals(other.additionalInfo))
+ return false;
+ if (address == null) {
+ if (other.address != null)
+ return false;
+ } else if (!address.equals(other.address))
+ return false;
+ if (address2 == null) {
+ if (other.address2 != null)
+ return false;
+ } else if (!address2.equals(other.address2))
+ return false;
+ if (city == null) {
+ if (other.city != null)
+ return false;
+ } else if (!city.equals(other.city))
+ return false;
+ if (country == null) {
+ if (other.country != null)
+ return false;
+ } else if (!country.equals(other.country))
+ return false;
+ if (email == null) {
+ if (other.email != null)
+ return false;
+ } else if (!email.equals(other.email))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (phone == null) {
+ if (other.phone != null)
+ return false;
+ } else if (!phone.equals(other.phone))
+ return false;
+ if (state == null) {
+ if (other.state != null)
+ return false;
+ } else if (!state.equals(other.state))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ if (zip == null) {
+ if (other.zip != null)
+ return false;
+ } else if (!zip.equals(other.zip))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("CustomerEntity [id=");
+ builder.append(id);
+ builder.append(", tenantId=");
+ builder.append(tenantId);
+ builder.append(", title=");
+ builder.append(title);
+ builder.append(", country=");
+ builder.append(country);
+ builder.append(", state=");
+ builder.append(state);
+ builder.append(", city=");
+ builder.append(city);
+ builder.append(", address=");
+ builder.append(address);
+ builder.append(", address2=");
+ builder.append(address2);
+ builder.append(", zip=");
+ builder.append(zip);
+ builder.append(", phone=");
+ builder.append(phone);
+ builder.append(", email=");
+ builder.append(email);
+ builder.append(", additionalInfo=");
+ builder.append(additionalInfo);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public Customer toData() {
+ Customer customer = new Customer(new CustomerId(id));
+ customer.setCreatedTime(UUIDs.unixTimestamp(id));
+ customer.setTenantId(new TenantId(tenantId));
+ customer.setTitle(title);
+ customer.setCountry(country);
+ customer.setState(state);
+ customer.setCity(city);
+ customer.setAddress(address);
+ customer.setAddress2(address2);
+ customer.setZip(zip);
+ customer.setPhone(phone);
+ customer.setEmail(email);
+ customer.setAdditionalInfo(additionalInfo);
+ return customer;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java
new file mode 100644
index 0000000..12a12c1
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java
@@ -0,0 +1,221 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.Dashboard;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.DashboardId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME)
+public final class DashboardEntity implements SearchTextEntity<Dashboard> {
+
+ @Transient
+ private static final long serialVersionUID = -4838084363113078898L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY)
+ private UUID customerId;
+
+ @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
+ private String title;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY)
+ private JsonNode configuration;
+
+ public DashboardEntity() {
+ super();
+ }
+
+ public DashboardEntity(Dashboard dashboard) {
+ if (dashboard.getId() != null) {
+ this.id = dashboard.getId().getId();
+ }
+ if (dashboard.getTenantId() != null) {
+ this.tenantId = dashboard.getTenantId().getId();
+ }
+ if (dashboard.getCustomerId() != null) {
+ this.customerId = dashboard.getCustomerId().getId();
+ }
+ this.title = dashboard.getTitle();
+ this.configuration = dashboard.getConfiguration();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public UUID getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(UUID customerId) {
+ this.customerId = customerId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public JsonNode getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(JsonNode configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return title;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((configuration == null) ? 0 : configuration.hashCode());
+ result = prime * result + ((customerId == null) ? 0 : customerId.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((searchText == null) ? 0 : searchText.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DashboardEntity other = (DashboardEntity) obj;
+ if (configuration == null) {
+ if (other.configuration != null)
+ return false;
+ } else if (!configuration.equals(other.configuration))
+ return false;
+ if (customerId == null) {
+ if (other.customerId != null)
+ return false;
+ } else if (!customerId.equals(other.customerId))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (searchText == null) {
+ if (other.searchText != null)
+ return false;
+ } else if (!searchText.equals(other.searchText))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("DashboardEntity [id=");
+ builder.append(id);
+ builder.append(", tenantId=");
+ builder.append(tenantId);
+ builder.append(", customerId=");
+ builder.append(customerId);
+ builder.append(", title=");
+ builder.append(title);
+ builder.append(", searchText=");
+ builder.append(searchText);
+ builder.append(", configuration=");
+ builder.append(configuration);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public Dashboard toData() {
+ Dashboard dashboard = new Dashboard(new DashboardId(id));
+ dashboard.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (tenantId != null) {
+ dashboard.setTenantId(new TenantId(tenantId));
+ }
+ if (customerId != null) {
+ dashboard.setCustomerId(new CustomerId(customerId));
+ }
+ dashboard.setTitle(title);
+ dashboard.setConfiguration(configuration);
+ return dashboard;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardInfoEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardInfoEntity.java
new file mode 100644
index 0000000..5fb052b
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardInfoEntity.java
@@ -0,0 +1,199 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import org.thingsboard.server.common.data.DashboardInfo;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.DashboardId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME)
+public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
+
+ @Transient
+ private static final long serialVersionUID = -5525675905528050250L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY)
+ private UUID customerId;
+
+ @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
+ private String title;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ public DashboardInfoEntity() {
+ super();
+ }
+
+ public DashboardInfoEntity(DashboardInfo dashboardInfo) {
+ if (dashboardInfo.getId() != null) {
+ this.id = dashboardInfo.getId().getId();
+ }
+ if (dashboardInfo.getTenantId() != null) {
+ this.tenantId = dashboardInfo.getTenantId().getId();
+ }
+ if (dashboardInfo.getCustomerId() != null) {
+ this.customerId = dashboardInfo.getCustomerId().getId();
+ }
+ this.title = dashboardInfo.getTitle();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public UUID getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(UUID customerId) {
+ this.customerId = customerId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return title;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((customerId == null) ? 0 : customerId.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((searchText == null) ? 0 : searchText.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DashboardInfoEntity other = (DashboardInfoEntity) obj;
+ if (customerId == null) {
+ if (other.customerId != null)
+ return false;
+ } else if (!customerId.equals(other.customerId))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (searchText == null) {
+ if (other.searchText != null)
+ return false;
+ } else if (!searchText.equals(other.searchText))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("DashboardInfoEntity [id=");
+ builder.append(id);
+ builder.append(", tenantId=");
+ builder.append(tenantId);
+ builder.append(", customerId=");
+ builder.append(customerId);
+ builder.append(", title=");
+ builder.append(title);
+ builder.append(", searchText=");
+ builder.append(searchText);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public DashboardInfo toData() {
+ DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(id));
+ dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (tenantId != null) {
+ dashboardInfo.setTenantId(new TenantId(tenantId));
+ }
+ if (customerId != null) {
+ dashboardInfo.setCustomerId(new CustomerId(customerId));
+ }
+ dashboardInfo.setTitle(title);
+ return dashboardInfo;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceCredentialsEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceCredentialsEntity.java
new file mode 100644
index 0000000..de43994
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceCredentialsEntity.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import org.thingsboard.server.common.data.id.DeviceCredentialsId;
+import org.thingsboard.server.common.data.id.DeviceId;
+import org.thingsboard.server.common.data.security.DeviceCredentials;
+import org.thingsboard.server.common.data.security.DeviceCredentialsType;
+import org.thingsboard.server.dao.model.BaseEntity;
+import org.thingsboard.server.dao.model.ModelConstants;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME)
+public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentials> {
+
+ @Transient
+ private static final long serialVersionUID = -2512362753385470464L;
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
+ private UUID deviceId;
+
+ @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY)
+ private DeviceCredentialsType credentialsType;
+
+ @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY)
+ private String credentialsId;
+
+ @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_VALUE_PROPERTY)
+ private String credentialsValue;
+
+ public DeviceCredentialsEntity() {
+ super();
+ }
+
+ public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) {
+ if (deviceCredentials.getId() != null) {
+ this.id = deviceCredentials.getId().getId();
+ }
+ if (deviceCredentials.getDeviceId() != null) {
+ this.deviceId = deviceCredentials.getDeviceId().getId();
+ }
+ this.credentialsType = deviceCredentials.getCredentialsType();
+ this.credentialsId = deviceCredentials.getCredentialsId();
+ this.credentialsValue = deviceCredentials.getCredentialsValue();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(UUID deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public DeviceCredentialsType getCredentialsType() {
+ return credentialsType;
+ }
+
+ public void setCredentialsType(DeviceCredentialsType credentialsType) {
+ this.credentialsType = credentialsType;
+ }
+
+ public String getCredentialsId() {
+ return credentialsId;
+ }
+
+ public void setCredentialsId(String credentialsId) {
+ this.credentialsId = credentialsId;
+ }
+
+ public String getCredentialsValue() {
+ return credentialsValue;
+ }
+
+ public void setCredentialsValue(String credentialsValue) {
+ this.credentialsValue = credentialsValue;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((credentialsId == null) ? 0 : credentialsId.hashCode());
+ result = prime * result + ((credentialsType == null) ? 0 : credentialsType.hashCode());
+ result = prime * result + ((credentialsValue == null) ? 0 : credentialsValue.hashCode());
+ result = prime * result + ((deviceId == null) ? 0 : deviceId.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DeviceCredentialsEntity other = (DeviceCredentialsEntity) obj;
+ if (credentialsId == null) {
+ if (other.credentialsId != null)
+ return false;
+ } else if (!credentialsId.equals(other.credentialsId))
+ return false;
+ if (credentialsType != other.credentialsType)
+ return false;
+ if (credentialsValue == null) {
+ if (other.credentialsValue != null)
+ return false;
+ } else if (!credentialsValue.equals(other.credentialsValue))
+ return false;
+ if (deviceId == null) {
+ if (other.deviceId != null)
+ return false;
+ } else if (!deviceId.equals(other.deviceId))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("DeviceCredentialsEntity [id=");
+ builder.append(id);
+ builder.append(", deviceId=");
+ builder.append(deviceId);
+ builder.append(", credentialsType=");
+ builder.append(credentialsType);
+ builder.append(", credentialsId=");
+ builder.append(credentialsId);
+ builder.append(", credentialsValue=");
+ builder.append(credentialsValue);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public DeviceCredentials toData() {
+ DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id));
+ deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (deviceId != null) {
+ deviceCredentials.setDeviceId(new DeviceId(deviceId));
+ }
+ deviceCredentials.setCredentialsType(credentialsType);
+ deviceCredentials.setCredentialsId(credentialsId);
+ deviceCredentials.setCredentialsValue(credentialsValue);
+ return deviceCredentials;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java
new file mode 100644
index 0000000..72c2dd5
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java
@@ -0,0 +1,213 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.Device;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.DeviceId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME)
+public final class DeviceEntity implements SearchTextEntity<Device> {
+
+ @Transient
+ private static final long serialVersionUID = 8050086401213322856L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY)
+ private UUID customerId;
+
+ @Column(name = ModelConstants.DEVICE_NAME_PROPERTY)
+ private String name;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public DeviceEntity() {
+ super();
+ }
+
+ public DeviceEntity(Device device) {
+ if (device.getId() != null) {
+ this.id = device.getId().getId();
+ }
+ if (device.getTenantId() != null) {
+ this.tenantId = device.getTenantId().getId();
+ }
+ if (device.getCustomerId() != null) {
+ this.customerId = device.getCustomerId().getId();
+ }
+ this.name = device.getName();
+ this.additionalInfo = device.getAdditionalInfo();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public UUID getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(UUID customerId) {
+ this.customerId = customerId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return name;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode());
+ result = prime * result + ((customerId == null) ? 0 : customerId.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DeviceEntity other = (DeviceEntity) obj;
+ if (additionalInfo == null) {
+ if (other.additionalInfo != null)
+ return false;
+ } else if (!additionalInfo.equals(other.additionalInfo))
+ return false;
+ if (customerId == null) {
+ if (other.customerId != null)
+ return false;
+ } else if (!customerId.equals(other.customerId))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("DeviceEntity [id=");
+ builder.append(id);
+ builder.append(", tenantId=");
+ builder.append(tenantId);
+ builder.append(", customerId=");
+ builder.append(customerId);
+ builder.append(", name=");
+ builder.append(name);
+ builder.append(", additionalInfo=");
+ builder.append(additionalInfo);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public Device toData() {
+ Device device = new Device(new DeviceId(id));
+ device.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (tenantId != null) {
+ device.setTenantId(new TenantId(tenantId));
+ }
+ if (customerId != null) {
+ device.setCustomerId(new CustomerId(customerId));
+ }
+ device.setName(name);
+ device.setAdditionalInfo(additionalInfo);
+ return device;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/EventEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/EventEntity.java
new file mode 100644
index 0000000..4618f42
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/EventEntity.java
@@ -0,0 +1,119 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.thingsboard.server.common.data.EntityType;
+import org.thingsboard.server.common.data.Event;
+import org.thingsboard.server.common.data.id.*;
+import org.thingsboard.server.dao.model.BaseEntity;
+import org.thingsboard.server.dao.model.ModelConstants;
+
+import java.util.UUID;
+
+@Data
+@NoArgsConstructor
+@Entity
+@Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME)
+public class EventEntity implements BaseEntity<Event> {
+
+ @Transient
+ private static final long serialVersionUID = -5717830061727466727L;
+
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Id
+ @Column(name = ModelConstants.EVENT_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.EVENT_ENTITY_TYPE_PROPERTY)
+ private EntityType entityType;
+
+ @Column(name = ModelConstants.EVENT_ENTITY_ID_PROPERTY)
+ private UUID entityId;
+
+ @Column(name = ModelConstants.EVENT_TYPE_PROPERTY)
+ private String eventType;
+
+ @Column(name = ModelConstants.EVENT_UID_PROPERTY)
+ private String eventUId;
+
+ @Column(name = ModelConstants.EVENT_BODY_PROPERTY)
+ private JsonNode body;
+
+ public EventEntity(Event event) {
+ if (event.getId() != null) {
+ this.id = event.getId().getId();
+ }
+ if (event.getTenantId() != null) {
+ this.tenantId = event.getTenantId().getId();
+ }
+ if (event.getEntityId() != null) {
+ this.entityType = event.getEntityId().getEntityType();
+ this.entityId = event.getEntityId().getId();
+ }
+ this.eventType = event.getType();
+ this.eventUId = event.getUid();
+ this.body = event.getBody();
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ @Override
+ public Event toData() {
+ Event event = new Event(new EventId(id));
+ event.setCreatedTime(UUIDs.unixTimestamp(id));
+ event.setTenantId(new TenantId(tenantId));
+ switch (entityType) {
+ case TENANT:
+ event.setEntityId(new TenantId(entityId));
+ break;
+ case DEVICE:
+ event.setEntityId(new DeviceId(entityId));
+ break;
+ case CUSTOMER:
+ event.setEntityId(new CustomerId(entityId));
+ break;
+ case RULE:
+ event.setEntityId(new RuleId(entityId));
+ break;
+ case PLUGIN:
+ event.setEntityId(new PluginId(entityId));
+ break;
+ }
+ event.setBody(body);
+ event.setType(eventType);
+ event.setUid(eventUId);
+ return event;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/PluginMetaDataEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/PluginMetaDataEntity.java
new file mode 100644
index 0000000..fc58f90
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/PluginMetaDataEntity.java
@@ -0,0 +1,216 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.id.PluginId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
+import org.thingsboard.server.common.data.plugin.PluginMetaData;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.Objects;
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.PLUGIN_COLUMN_FAMILY_NAME)
+public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> {
+
+ @Transient
+ private static final long serialVersionUID = -6164321050824823149L;
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.PLUGIN_API_TOKEN_PROPERTY)
+ private String apiToken;
+
+ @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.PLUGIN_NAME_PROPERTY)
+ private String name;
+
+ @Column(name = ModelConstants.PLUGIN_CLASS_PROPERTY)
+ private String clazz;
+
+ @Column(name = ModelConstants.PLUGIN_ACCESS_PROPERTY)
+ private boolean publicAccess;
+
+ @Column(name = ModelConstants.PLUGIN_STATE_PROPERTY)
+ private ComponentLifecycleState state;
+
+ @Column(name = ModelConstants.PLUGIN_CONFIGURATION_PROPERTY)
+ private JsonNode configuration;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public PluginMetaDataEntity() {
+ }
+
+ public PluginMetaDataEntity(PluginMetaData pluginMetaData) {
+ if (pluginMetaData.getId() != null) {
+ this.id = pluginMetaData.getId().getId();
+ }
+ this.tenantId = pluginMetaData.getTenantId().getId();
+ this.apiToken = pluginMetaData.getApiToken();
+ this.clazz = pluginMetaData.getClazz();
+ this.name = pluginMetaData.getName();
+ this.publicAccess = pluginMetaData.isPublicAccess();
+ this.state = pluginMetaData.getState();
+ this.configuration = pluginMetaData.getConfiguration();
+ this.searchText = pluginMetaData.getName();
+ this.additionalInfo = pluginMetaData.getAdditionalInfo();
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return searchText;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getApiToken() {
+ return apiToken;
+ }
+
+ public void setApiToken(String apiToken) {
+ this.apiToken = apiToken;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getClazz() {
+ return clazz;
+ }
+
+ public void setClazz(String clazz) {
+ this.clazz = clazz;
+ }
+
+ public JsonNode getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(JsonNode configuration) {
+ this.configuration = configuration;
+ }
+
+ public boolean isPublicAccess() {
+ return publicAccess;
+ }
+
+ public void setPublicAccess(boolean publicAccess) {
+ this.publicAccess = publicAccess;
+ }
+
+ public ComponentLifecycleState getState() {
+ return state;
+ }
+
+ public void setState(ComponentLifecycleState state) {
+ this.state = state;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public PluginMetaData toData() {
+ PluginMetaData data = new PluginMetaData(new PluginId(id));
+ data.setTenantId(new TenantId(tenantId));
+ data.setCreatedTime(UUIDs.unixTimestamp(id));
+ data.setName(name);
+ data.setConfiguration(configuration);
+ data.setClazz(clazz);
+ data.setPublicAccess(publicAccess);
+ data.setState(state);
+ data.setApiToken(apiToken);
+ data.setAdditionalInfo(additionalInfo);
+ return data;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ PluginMetaDataEntity entity = (PluginMetaDataEntity) o;
+ return Objects.equals(id, entity.id) && Objects.equals(apiToken, entity.apiToken) && Objects.equals(tenantId, entity.tenantId)
+ && Objects.equals(name, entity.name) && Objects.equals(clazz, entity.clazz) && Objects.equals(state, entity.state)
+ && Objects.equals(configuration, entity.configuration)
+ && Objects.equals(searchText, entity.searchText);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, apiToken, tenantId, name, clazz, state, configuration, searchText);
+ }
+
+ @Override
+ public String toString() {
+ return "PluginMetaDataEntity{" + "id=" + id + ", apiToken='" + apiToken + '\'' + ", tenantId=" + tenantId + ", name='" + name + '\'' + ", clazz='"
+ + clazz + '\'' + ", state=" + state + ", configuration=" + configuration + ", searchText='" + searchText + '\'' + '}';
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleMetaDataEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleMetaDataEntity.java
new file mode 100644
index 0000000..506b74a
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleMetaDataEntity.java
@@ -0,0 +1,228 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.id.RuleId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
+import org.thingsboard.server.common.data.rule.RuleMetaData;
+import org.thingsboard.server.dao.DaoUtil;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.util.Objects;
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.RULE_COLUMN_FAMILY_NAME)
+public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> {
+
+ @Transient
+ private static final long serialVersionUID = -1506905644259463884L;
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+ @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+ @Column(name = ModelConstants.RULE_NAME_PROPERTY)
+ private String name;
+ @Column(name = ModelConstants.RULE_STATE_PROPERTY)
+ private ComponentLifecycleState state;
+ @Column(name = ModelConstants.RULE_WEIGHT_PROPERTY)
+ private int weight;
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+ @Column(name = ModelConstants.RULE_PLUGIN_TOKEN_PROPERTY)
+ private String pluginToken;
+ @Column(name = ModelConstants.RULE_FILTERS)
+ private JsonNode filters;
+ @Column(name = ModelConstants.RULE_PROCESSOR)
+ private JsonNode processor;
+ @Column(name = ModelConstants.RULE_ACTION)
+ private JsonNode action;
+ @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public RuleMetaDataEntity() {
+ }
+
+ public RuleMetaDataEntity(RuleMetaData rule) {
+ if (rule.getId() != null) {
+ this.id = rule.getUuidId();
+ }
+ this.tenantId = DaoUtil.getId(rule.getTenantId());
+ this.name = rule.getName();
+ this.pluginToken = rule.getPluginToken();
+ this.state = rule.getState();
+ this.weight = rule.getWeight();
+ this.searchText = rule.getName();
+ this.filters = rule.getFilters();
+ this.processor = rule.getProcessor();
+ this.action = rule.getAction();
+ this.additionalInfo = rule.getAdditionalInfo();
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return searchText;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ComponentLifecycleState getState() {
+ return state;
+ }
+
+ public void setState(ComponentLifecycleState state) {
+ this.state = state;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public String getPluginToken() {
+ return pluginToken;
+ }
+
+ public void setPluginToken(String pluginToken) {
+ this.pluginToken = pluginToken;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ public JsonNode getFilters() {
+ return filters;
+ }
+
+ public void setFilters(JsonNode filters) {
+ this.filters = filters;
+ }
+
+ public JsonNode getProcessor() {
+ return processor;
+ }
+
+ public void setProcessor(JsonNode processor) {
+ this.processor = processor;
+ }
+
+ public JsonNode getAction() {
+ return action;
+ }
+
+ public void setAction(JsonNode action) {
+ this.action = action;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public RuleMetaData toData() {
+ RuleMetaData rule = new RuleMetaData(new RuleId(id));
+ rule.setTenantId(new TenantId(tenantId));
+ rule.setName(name);
+ rule.setState(state);
+ rule.setWeight(weight);
+ rule.setCreatedTime(UUIDs.unixTimestamp(id));
+ rule.setPluginToken(pluginToken);
+ rule.setFilters(filters);
+ rule.setProcessor(processor);
+ rule.setAction(action);
+ rule.setAdditionalInfo(additionalInfo);
+ return rule;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RuleMetaDataEntity that = (RuleMetaDataEntity) o;
+ return weight == that.weight &&
+ Objects.equals(id, that.id) &&
+ Objects.equals(tenantId, that.tenantId) &&
+ Objects.equals(name, that.name) &&
+ Objects.equals(pluginToken, that.pluginToken) &&
+ Objects.equals(state, that.state) &&
+ Objects.equals(searchText, that.searchText);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, tenantId, name, pluginToken, state, weight, searchText);
+ }
+
+ @Override
+ public String toString() {
+ return "RuleMetaDataEntity{" +
+ "id=" + id +
+ ", tenantId=" + tenantId +
+ ", name='" + name + '\'' +
+ ", pluginToken='" + pluginToken + '\'' +
+ ", state='" + state + '\'' +
+ ", weight=" + weight +
+ ", searchText='" + searchText + '\'' +
+ '}';
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/TenantEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/TenantEntity.java
new file mode 100644
index 0000000..06b6131
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/TenantEntity.java
@@ -0,0 +1,351 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import org.thingsboard.server.common.data.Tenant;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.TENANT_COLUMN_FAMILY_NAME)
+public final class TenantEntity implements SearchTextEntity<Tenant> {
+
+ @Transient
+ private static final long serialVersionUID = -4330655990232136337L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.TENANT_TITLE_PROPERTY)
+ private String title;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.TENANT_REGION_PROPERTY)
+ private String region;
+
+ @Column(name = ModelConstants.COUNTRY_PROPERTY)
+ private String country;
+
+ @Column(name = ModelConstants.STATE_PROPERTY)
+ private String state;
+
+ @Column(name = ModelConstants.CITY_PROPERTY)
+ private String city;
+
+ @Column(name = ModelConstants.ADDRESS_PROPERTY)
+ private String address;
+
+ @Column(name = ModelConstants.ADDRESS2_PROPERTY)
+ private String address2;
+
+ @Column(name = ModelConstants.ZIP_PROPERTY)
+ private String zip;
+
+ @Column(name = ModelConstants.PHONE_PROPERTY)
+ private String phone;
+
+ @Column(name = ModelConstants.EMAIL_PROPERTY)
+ private String email;
+
+ @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public TenantEntity() {
+ super();
+ }
+
+ public TenantEntity(Tenant tenant) {
+ if (tenant.getId() != null) {
+ this.id = tenant.getId().getId();
+ }
+ this.title = tenant.getTitle();
+ this.region = tenant.getRegion();
+ this.country = tenant.getCountry();
+ this.state = tenant.getState();
+ this.city = tenant.getCity();
+ this.address = tenant.getAddress();
+ this.address2 = tenant.getAddress2();
+ this.zip = tenant.getZip();
+ this.phone = tenant.getPhone();
+ this.email = tenant.getEmail();
+ this.additionalInfo = tenant.getAdditionalInfo();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getAddress2() {
+ return address2;
+ }
+
+ public void setAddress2(String address2) {
+ this.address2 = address2;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return title;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode());
+ result = prime * result + ((address == null) ? 0 : address.hashCode());
+ result = prime * result + ((address2 == null) ? 0 : address2.hashCode());
+ result = prime * result + ((city == null) ? 0 : city.hashCode());
+ result = prime * result + ((country == null) ? 0 : country.hashCode());
+ result = prime * result + ((email == null) ? 0 : email.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((phone == null) ? 0 : phone.hashCode());
+ result = prime * result + ((region == null) ? 0 : region.hashCode());
+ result = prime * result + ((state == null) ? 0 : state.hashCode());
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ result = prime * result + ((zip == null) ? 0 : zip.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TenantEntity other = (TenantEntity) obj;
+ if (additionalInfo == null) {
+ if (other.additionalInfo != null)
+ return false;
+ } else if (!additionalInfo.equals(other.additionalInfo))
+ return false;
+ if (address == null) {
+ if (other.address != null)
+ return false;
+ } else if (!address.equals(other.address))
+ return false;
+ if (address2 == null) {
+ if (other.address2 != null)
+ return false;
+ } else if (!address2.equals(other.address2))
+ return false;
+ if (city == null) {
+ if (other.city != null)
+ return false;
+ } else if (!city.equals(other.city))
+ return false;
+ if (country == null) {
+ if (other.country != null)
+ return false;
+ } else if (!country.equals(other.country))
+ return false;
+ if (email == null) {
+ if (other.email != null)
+ return false;
+ } else if (!email.equals(other.email))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (phone == null) {
+ if (other.phone != null)
+ return false;
+ } else if (!phone.equals(other.phone))
+ return false;
+ if (region == null) {
+ if (other.region != null)
+ return false;
+ } else if (!region.equals(other.region))
+ return false;
+ if (state == null) {
+ if (other.state != null)
+ return false;
+ } else if (!state.equals(other.state))
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ if (zip == null) {
+ if (other.zip != null)
+ return false;
+ } else if (!zip.equals(other.zip))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("TenantEntity [id=");
+ builder.append(id);
+ builder.append(", title=");
+ builder.append(title);
+ builder.append(", region=");
+ builder.append(region);
+ builder.append(", country=");
+ builder.append(country);
+ builder.append(", state=");
+ builder.append(state);
+ builder.append(", city=");
+ builder.append(city);
+ builder.append(", address=");
+ builder.append(address);
+ builder.append(", address2=");
+ builder.append(address2);
+ builder.append(", zip=");
+ builder.append(zip);
+ builder.append(", phone=");
+ builder.append(phone);
+ builder.append(", email=");
+ builder.append(email);
+ builder.append(", additionalInfo=");
+ builder.append(additionalInfo);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public Tenant toData() {
+ Tenant tenant = new Tenant(new TenantId(id));
+ tenant.setCreatedTime(UUIDs.unixTimestamp(id));
+ tenant.setTitle(title);
+ tenant.setRegion(region);
+ tenant.setCountry(country);
+ tenant.setState(state);
+ tenant.setCity(city);
+ tenant.setAddress(address);
+ tenant.setAddress2(address2);
+ tenant.setZip(zip);
+ tenant.setPhone(phone);
+ tenant.setEmail(email);
+ tenant.setAdditionalInfo(additionalInfo);
+ return tenant;
+ }
+
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserCredentialsEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserCredentialsEntity.java
new file mode 100644
index 0000000..42d4e92
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserCredentialsEntity.java
@@ -0,0 +1,189 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import org.thingsboard.server.common.data.id.UserCredentialsId;
+import org.thingsboard.server.common.data.id.UserId;
+import org.thingsboard.server.common.data.security.UserCredentials;
+import org.thingsboard.server.dao.model.BaseEntity;
+import org.thingsboard.server.dao.model.ModelConstants;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME)
+public final class UserCredentialsEntity implements BaseEntity<UserCredentials> {
+
+ @Transient
+ private static final long serialVersionUID = 1348221414123438374L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY)
+ private UUID userId;
+
+ @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY)
+ private boolean enabled;
+
+ @Column(name = ModelConstants.USER_CREDENTIALS_PASSWORD_PROPERTY)
+ private String password;
+
+ @Column(name = ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY)
+ private String activateToken;
+
+ @Column(name = ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY)
+ private String resetToken;
+
+ public UserCredentialsEntity() {
+ super();
+ }
+
+ public UserCredentialsEntity(UserCredentials userCredentials) {
+ if (userCredentials.getId() != null) {
+ this.id = userCredentials.getId().getId();
+ }
+ if (userCredentials.getUserId() != null) {
+ this.userId = userCredentials.getUserId().getId();
+ }
+ this.enabled = userCredentials.isEnabled();
+ this.password = userCredentials.getPassword();
+ this.activateToken = userCredentials.getActivateToken();
+ this.resetToken = userCredentials.getResetToken();
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getUserId() {
+ return userId;
+ }
+
+ public void setUserId(UUID userId) {
+ this.userId = userId;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getActivateToken() {
+ return activateToken;
+ }
+
+ public void setActivateToken(String activateToken) {
+ this.activateToken = activateToken;
+ }
+
+ public String getResetToken() {
+ return resetToken;
+ }
+
+ public void setResetToken(String resetToken) {
+ this.resetToken = resetToken;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((activateToken == null) ? 0 : activateToken.hashCode());
+ result = prime * result + (enabled ? 1231 : 1237);
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((password == null) ? 0 : password.hashCode());
+ result = prime * result + ((resetToken == null) ? 0 : resetToken.hashCode());
+ result = prime * result + ((userId == null) ? 0 : userId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ UserCredentialsEntity other = (UserCredentialsEntity) obj;
+ if (activateToken == null) {
+ if (other.activateToken != null)
+ return false;
+ } else if (!activateToken.equals(other.activateToken))
+ return false;
+ if (enabled != other.enabled)
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (password == null) {
+ if (other.password != null)
+ return false;
+ } else if (!password.equals(other.password))
+ return false;
+ if (resetToken == null) {
+ if (other.resetToken != null)
+ return false;
+ } else if (!resetToken.equals(other.resetToken))
+ return false;
+ if (userId == null) {
+ if (other.userId != null)
+ return false;
+ } else if (!userId.equals(other.userId))
+ return false;
+ return true;
+ }
+
+ @Override
+ public UserCredentials toData() {
+ UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(id));
+ userCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (userId != null) {
+ userCredentials.setUserId(new UserId(userId));
+ }
+ userCredentials.setEnabled(enabled);
+ userCredentials.setPassword(password);
+ userCredentials.setActivateToken(activateToken);
+ userCredentials.setResetToken(resetToken);
+ return userCredentials;
+ }
+
+}
\ No newline at end of file
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserEntity.java
new file mode 100644
index 0000000..a02341d
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/UserEntity.java
@@ -0,0 +1,274 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.User;
+import org.thingsboard.server.common.data.id.CustomerId;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.common.data.id.UserId;
+import org.thingsboard.server.common.data.security.Authority;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+import org.thingsboard.server.dao.model.ModelConstants;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import java.util.UUID;
+
+/**
+ * @author Valerii Sosliuk
+ */
+@Entity
+@Table(name= ModelConstants.USER_COLUMN_FAMILY_NAME)
+public class UserEntity implements SearchTextEntity<User> {
+
+ @Transient
+ private static final long serialVersionUID = 4349485207981226785L;
+
+ @Id
+ @Column(name=ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY)
+ private UUID customerId;
+
+ @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY)
+ private Authority authority;
+
+ @Column(name = ModelConstants.USER_EMAIL_PROPERTY)
+ private String email;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.USER_FIRST_NAME_PROPERTY)
+ private String firstName;
+
+ @Column(name = ModelConstants.USER_LAST_NAME_PROPERTY)
+ private String lastName;
+
+ @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY)
+ private JsonNode additionalInfo;
+
+ public UserEntity(User user) {
+ if (user.getId() != null) {
+ this.id = user.getId().getId();
+ }
+ this.authority = user.getAuthority();
+ if (user.getTenantId() != null) {
+ this.tenantId = user.getTenantId().getId();
+ }
+ if (user.getCustomerId() != null) {
+ this.customerId = user.getCustomerId().getId();
+ }
+ this.email = user.getEmail();
+ this.firstName = user.getFirstName();
+ this.lastName = user.getLastName();
+ this.additionalInfo = user.getAdditionalInfo();
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return searchText;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public UUID getCustomerId() {
+ return customerId;
+ }
+
+ public void setCustomerId(UUID customerId) {
+ this.customerId = customerId;
+ }
+
+ public Authority getAuthority() {
+ return authority;
+ }
+
+ public void setAuthority(Authority authority) {
+ this.authority = authority;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public JsonNode getAdditionalInfo() {
+ return additionalInfo;
+ }
+
+ public void setAdditionalInfo(JsonNode additionalInfo) {
+ this.additionalInfo = additionalInfo;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("UserEntity [id=");
+ builder.append(id);
+ builder.append(", authority=");
+ builder.append(authority);
+ builder.append(", tenantId=");
+ builder.append(tenantId);
+ builder.append(", customerId=");
+ builder.append(customerId);
+ builder.append(", email=");
+ builder.append(email);
+ builder.append(", firstName=");
+ builder.append(firstName);
+ builder.append(", lastName=");
+ builder.append(lastName);
+ builder.append(", additionalInfo=");
+ builder.append(additionalInfo);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public User toData() {
+ User user = new User(new UserId(id));
+ user.setCreatedTime(UUIDs.unixTimestamp(id));
+ user.setAuthority(authority);
+ if (tenantId != null) {
+ user.setTenantId(new TenantId(tenantId));
+ }
+ if (customerId != null) {
+ user.setCustomerId(new CustomerId(customerId));
+ }
+ user.setEmail(email);
+ user.setFirstName(firstName);
+ user.setLastName(lastName);
+ user.setAdditionalInfo(additionalInfo);
+ return user;
+ }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((additionalInfo == null) ? 0 : additionalInfo.hashCode());
+ result = prime * result + ((authority == null) ? 0 : authority.hashCode());
+ result = prime * result + ((customerId == null) ? 0 : customerId.hashCode());
+ result = prime * result + ((email == null) ? 0 : email.hashCode());
+ result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ UserEntity other = (UserEntity) obj;
+ if (additionalInfo == null) {
+ if (other.additionalInfo != null)
+ return false;
+ } else if (!additionalInfo.equals(other.additionalInfo))
+ return false;
+ if (authority != other.authority)
+ return false;
+ if (customerId == null) {
+ if (other.customerId != null)
+ return false;
+ } else if (!customerId.equals(other.customerId))
+ return false;
+ if (email == null) {
+ if (other.email != null)
+ return false;
+ } else if (!email.equals(other.email))
+ return false;
+ if (firstName == null) {
+ if (other.firstName != null)
+ return false;
+ } else if (!firstName.equals(other.firstName))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (lastName == null) {
+ if (other.lastName != null)
+ return false;
+ } else if (!lastName.equals(other.lastName))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ return true;
+ }
+
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java
new file mode 100644
index 0000000..c972709
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java
@@ -0,0 +1,190 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.common.data.id.WidgetsBundleId;
+import org.thingsboard.server.common.data.widget.WidgetsBundle;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.WIDGETS_BUNDLE_COLUMN_FAMILY_NAME)
+public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle> {
+
+ @Transient
+ private static final long serialVersionUID = 6897035686422298096L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY)
+ private String alias;
+
+ @Column(name = ModelConstants.WIDGETS_BUNDLE_TITLE_PROPERTY)
+ private String title;
+
+ @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
+ private String searchText;
+
+ @Column(name = ModelConstants.WIDGETS_BUNDLE_IMAGE_PROPERTY)
+ private ByteBuffer image;
+
+ public WidgetsBundleEntity() {
+ super();
+ }
+
+ public WidgetsBundleEntity(WidgetsBundle widgetsBundle) {
+ if (widgetsBundle.getId() != null) {
+ this.id = widgetsBundle.getId().getId();
+ }
+ if (widgetsBundle.getTenantId() != null) {
+ this.tenantId = widgetsBundle.getTenantId().getId();
+ }
+ this.alias = widgetsBundle.getAlias();
+ this.title = widgetsBundle.getTitle();
+ if (widgetsBundle.getImage() != null) {
+ this.image = ByteBuffer.wrap(widgetsBundle.getImage());
+ }
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public ByteBuffer getImage() {
+ return image;
+ }
+
+ public void setImage(ByteBuffer image) {
+ this.image = image;
+ }
+
+ @Override
+ public String getSearchTextSource() {
+ return title;
+ }
+
+ @Override
+ public void setSearchText(String searchText) {
+ this.searchText = searchText;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);
+ result = 31 * result + (alias != null ? alias.hashCode() : 0);
+ result = 31 * result + (title != null ? title.hashCode() : 0);
+ result = 31 * result + (searchText != null ? searchText.hashCode() : 0);
+ result = 31 * result + (image != null ? image.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ WidgetsBundleEntity that = (WidgetsBundleEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false;
+ if (alias != null ? !alias.equals(that.alias) : that.alias != null) return false;
+ if (title != null ? !title.equals(that.title) : that.title != null) return false;
+ if (searchText != null ? !searchText.equals(that.searchText) : that.searchText != null) return false;
+ return image != null ? image.equals(that.image) : that.image == null;
+
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("WidgetsBundleEntity{");
+ sb.append("id=").append(id);
+ sb.append(", tenantId=").append(tenantId);
+ sb.append(", alias='").append(alias).append('\'');
+ sb.append(", title='").append(title).append('\'');
+ sb.append(", searchText='").append(searchText).append('\'');
+ sb.append(", image=").append(image);
+ sb.append('}');
+ return sb.toString();
+ }
+
+ @Override
+ public WidgetsBundle toData() {
+ WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id));
+ widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (tenantId != null) {
+ widgetsBundle.setTenantId(new TenantId(tenantId));
+ }
+ widgetsBundle.setAlias(alias);
+ widgetsBundle.setTitle(title);
+ if (image != null) {
+ byte[] imageByteArray = new byte[image.remaining()];
+ image.get(imageByteArray);
+ widgetsBundle.setImage(imageByteArray);
+ }
+ return widgetsBundle;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetTypeEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetTypeEntity.java
new file mode 100644
index 0000000..6c1b949
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetTypeEntity.java
@@ -0,0 +1,183 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.model.sql;
+
+import com.datastax.driver.core.utils.UUIDs;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.thingsboard.server.common.data.id.TenantId;
+import org.thingsboard.server.common.data.id.WidgetTypeId;
+import org.thingsboard.server.common.data.widget.WidgetType;
+import org.thingsboard.server.dao.model.BaseEntity;
+import org.thingsboard.server.dao.model.ModelConstants;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME)
+public final class WidgetTypeEntity implements BaseEntity<WidgetType> {
+
+ @Transient
+ private static final long serialVersionUID = -5436279069884988630L;
+
+ @Id
+ @Column(name = ModelConstants.ID_PROPERTY)
+ private UUID id;
+
+ @PartitionKey(value = 1)
+ @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
+ private UUID tenantId;
+
+ @PartitionKey(value = 2)
+ @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY)
+ private String bundleAlias;
+
+ @Column(name = ModelConstants.WIDGET_TYPE_ALIAS_PROPERTY)
+ private String alias;
+
+ @Column(name = ModelConstants.WIDGET_TYPE_NAME_PROPERTY)
+ private String name;
+
+ @Column(name = ModelConstants.WIDGET_TYPE_DESCRIPTOR_PROPERTY)
+ private JsonNode descriptor;
+
+ public WidgetTypeEntity() {
+ super();
+ }
+
+ public WidgetTypeEntity(WidgetType widgetType) {
+ if (widgetType.getId() != null) {
+ this.id = widgetType.getId().getId();
+ }
+ if (widgetType.getTenantId() != null) {
+ this.tenantId = widgetType.getTenantId().getId();
+ }
+ this.bundleAlias = widgetType.getBundleAlias();
+ this.alias = widgetType.getAlias();
+ this.name = widgetType.getName();
+ this.descriptor = widgetType.getDescriptor();
+ }
+
+ @Override
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(UUID tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getBundleAlias() {
+ return bundleAlias;
+ }
+
+ public void setBundleAlias(String bundleAlias) {
+ this.bundleAlias = bundleAlias;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public JsonNode getDescriptor() {
+ return descriptor;
+ }
+
+ public void setDescriptor(JsonNode descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);
+ result = 31 * result + (bundleAlias != null ? bundleAlias.hashCode() : 0);
+ result = 31 * result + (alias != null ? alias.hashCode() : 0);
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (descriptor != null ? descriptor.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ WidgetTypeEntity that = (WidgetTypeEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false;
+ if (bundleAlias != null ? !bundleAlias.equals(that.bundleAlias) : that.bundleAlias != null) return false;
+ if (alias != null ? !alias.equals(that.alias) : that.alias != null) return false;
+ if (name != null ? !name.equals(that.name) : that.name != null) return false;
+ return descriptor != null ? descriptor.equals(that.descriptor) : that.descriptor == null;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("WidgetTypeEntity{");
+ sb.append("id=").append(id);
+ sb.append(", tenantId=").append(tenantId);
+ sb.append(", bundleAlias='").append(bundleAlias).append('\'');
+ sb.append(", alias='").append(alias).append('\'');
+ sb.append(", name='").append(name).append('\'');
+ sb.append(", descriptor=").append(descriptor);
+ sb.append('}');
+ return sb.toString();
+ }
+
+ @Override
+ public WidgetType toData() {
+ WidgetType widgetType = new WidgetType(new WidgetTypeId(id));
+ widgetType.setCreatedTime(UUIDs.unixTimestamp(id));
+ if (tenantId != null) {
+ widgetType.setTenantId(new TenantId(tenantId));
+ }
+ widgetType.setBundleAlias(bundleAlias);
+ widgetType.setAlias(alias);
+ widgetType.setName(name);
+ widgetType.setDescriptor(descriptor);
+ return widgetType;
+ }
+
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/plugin/BasePluginService.java b/dao/src/main/java/org/thingsboard/server/dao/plugin/BasePluginService.java
index 99560d2..b9b73c6 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/plugin/BasePluginService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/plugin/BasePluginService.java
@@ -17,8 +17,6 @@ package org.thingsboard.server.dao.plugin;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.id.PluginId;
@@ -29,13 +27,12 @@ import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
import org.thingsboard.server.common.data.plugin.ComponentType;
import org.thingsboard.server.common.data.plugin.PluginMetaData;
+import org.thingsboard.server.common.data.rule.RuleMetaData;
import org.thingsboard.server.dao.component.ComponentDescriptorService;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.DatabaseException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
import org.thingsboard.server.dao.model.ModelConstants;
-import org.thingsboard.server.dao.model.PluginMetaDataEntity;
-import org.thingsboard.server.dao.model.RuleMetaDataEntity;
import org.thingsboard.server.dao.rule.RuleDao;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
@@ -46,9 +43,6 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
@Service
@Slf4j
public class BasePluginService implements PluginService {
@@ -73,7 +67,7 @@ public class BasePluginService implements PluginService {
plugin.setTenantId(SYSTEM_TENANT);
}
if (plugin.getId() != null) {
- PluginMetaData oldVersion = getData(pluginDao.findById(plugin.getId()));
+ PluginMetaData oldVersion = pluginDao.findById(plugin.getId());
if (plugin.getState() == null) {
plugin.setState(oldVersion.getState());
} else if (plugin.getState() != oldVersion.getState()) {
@@ -92,33 +86,32 @@ public class BasePluginService implements PluginService {
} else if (!ComponentType.PLUGIN.equals(descriptor.getType())) {
throw new IncorrectParameterException("Plugin class is actually " + descriptor.getType() + "!");
}
- PluginMetaDataEntity entity = pluginDao.findByApiToken(plugin.getApiToken());
- if (entity != null && (plugin.getId() == null || !entity.getId().equals(plugin.getId().getId()))) {
+ PluginMetaData savedPlugin = pluginDao.findByApiToken(plugin.getApiToken());
+ if (savedPlugin != null && (plugin.getId() == null || !savedPlugin.getId().getId().equals(plugin.getId().getId()))) {
throw new IncorrectParameterException("API token is already reserved!");
}
if (!componentDescriptorService.validate(descriptor, plugin.getConfiguration())) {
throw new IncorrectParameterException("Filters configuration is not valid!");
}
- return getData(pluginDao.save(plugin));
+ return pluginDao.save(plugin);
}
@Override
public PluginMetaData findPluginById(PluginId pluginId) {
Validator.validateId(pluginId, "Incorrect plugin id for search request.");
- return getData(pluginDao.findById(pluginId));
+ return pluginDao.findById(pluginId);
}
@Override
public PluginMetaData findPluginByApiToken(String apiToken) {
Validator.validateString(apiToken, "Incorrect plugin apiToken for search request.");
- return getData(pluginDao.findByApiToken(apiToken));
+ return pluginDao.findByApiToken(apiToken);
}
@Override
public TextPageData<PluginMetaData> findSystemPlugins(TextPageLink pageLink) {
Validator.validatePageLink(pageLink, "Incorrect PageLink object for search system plugin request.");
- List<PluginMetaDataEntity> pluginEntities = pluginDao.findByTenantIdAndPageLink(SYSTEM_TENANT, pageLink);
- List<PluginMetaData> plugins = convertDataList(pluginEntities);
+ List<PluginMetaData> plugins = pluginDao.findByTenantIdAndPageLink(SYSTEM_TENANT, pageLink);
return new TextPageData<>(plugins, pageLink);
}
@@ -126,8 +119,7 @@ public class BasePluginService implements PluginService {
public TextPageData<PluginMetaData> findTenantPlugins(TenantId tenantId, TextPageLink pageLink) {
Validator.validateId(tenantId, "Incorrect tenant id for search plugins request.");
Validator.validatePageLink(pageLink, "Incorrect PageLink object for search plugin request.");
- List<PluginMetaDataEntity> pluginEntities = pluginDao.findByTenantIdAndPageLink(tenantId, pageLink);
- List<PluginMetaData> plugins = convertDataList(pluginEntities);
+ List<PluginMetaData> plugins = pluginDao.findByTenantIdAndPageLink(tenantId, pageLink);
return new TextPageData<>(plugins, pageLink);
}
@@ -152,8 +144,7 @@ public class BasePluginService implements PluginService {
log.trace("Executing findAllTenantPluginsByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<PluginMetaDataEntity> pluginsEntities = pluginDao.findAllTenantPluginsByTenantId(tenantId.getId(), pageLink);
- List<PluginMetaData> plugins = convertDataList(pluginsEntities);
+ List<PluginMetaData> plugins = pluginDao.findAllTenantPluginsByTenantId(tenantId.getId(), pageLink);
return new TextPageData<>(plugins, pageLink);
}
@@ -181,8 +172,8 @@ public class BasePluginService implements PluginService {
@Override
public void suspendPluginById(PluginId pluginId) {
- PluginMetaDataEntity plugin = pluginDao.findById(pluginId);
- List<RuleMetaDataEntity> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken())
+ PluginMetaData plugin = pluginDao.findById(pluginId);
+ List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken())
.stream().filter(rule -> rule.getState() == ComponentLifecycleState.ACTIVE).collect(Collectors.toList());
if (affectedRules.isEmpty()) {
updateLifeCycleState(pluginId, ComponentLifecycleState.SUSPENDED);
@@ -193,7 +184,7 @@ public class BasePluginService implements PluginService {
private void updateLifeCycleState(PluginId pluginId, ComponentLifecycleState state) {
Validator.validateId(pluginId, "Incorrect plugin id for state change request.");
- PluginMetaDataEntity plugin = pluginDao.findById(pluginId);
+ PluginMetaData plugin = pluginDao.findById(pluginId);
if (plugin != null) {
plugin.setState(state);
pluginDao.save(plugin);
@@ -209,8 +200,8 @@ public class BasePluginService implements PluginService {
}
private void checkRulesAndDelete(UUID pluginId) {
- PluginMetaDataEntity plugin = pluginDao.findById(pluginId);
- List<RuleMetaDataEntity> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken());
+ PluginMetaData plugin = pluginDao.findById(pluginId);
+ List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken());
if (affectedRules.isEmpty()) {
pluginDao.deleteById(pluginId);
} else {
@@ -244,17 +235,17 @@ public class BasePluginService implements PluginService {
}
};
- private PaginatedRemover<TenantId, PluginMetaDataEntity> tenantPluginRemover =
- new PaginatedRemover<TenantId, PluginMetaDataEntity>() {
+ private PaginatedRemover<TenantId, PluginMetaData> tenantPluginRemover =
+ new PaginatedRemover<TenantId, PluginMetaData>() {
@Override
- protected List<PluginMetaDataEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<PluginMetaData> findEntities(TenantId id, TextPageLink pageLink) {
return pluginDao.findByTenantIdAndPageLink(id, pageLink);
}
@Override
- protected void removeEntity(PluginMetaDataEntity entity) {
- checkRulesAndDelete(entity.getId());
+ protected void removeEntity(PluginMetaData entity) {
+ checkRulesAndDelete(entity.getUuidId());
}
};
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/plugin/PluginDao.java b/dao/src/main/java/org/thingsboard/server/dao/plugin/PluginDao.java
index 0adf125..1a48b20 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/plugin/PluginDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/plugin/PluginDao.java
@@ -20,24 +20,23 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.plugin.PluginMetaData;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.PluginMetaDataEntity;
import java.util.List;
import java.util.UUID;
-public interface PluginDao extends Dao<PluginMetaDataEntity> {
+public interface PluginDao extends Dao<PluginMetaData> {
- PluginMetaDataEntity save(PluginMetaData plugin);
+ PluginMetaData save(PluginMetaData plugin);
- PluginMetaDataEntity findById(PluginId pluginId);
+ PluginMetaData findById(PluginId pluginId);
- PluginMetaDataEntity findByApiToken(String apiToken);
+ PluginMetaData findByApiToken(String apiToken);
void deleteById(UUID id);
void deleteById(PluginId pluginId);
- List<PluginMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
+ List<PluginMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
/**
* Find all tenant plugins (including system) by tenantId and page link.
@@ -46,6 +45,6 @@ public interface PluginDao extends Dao<PluginMetaDataEntity> {
* @param pageLink the page link
* @return the list of plugins objects
*/
- List<PluginMetaDataEntity> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<PluginMetaData> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleService.java b/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleService.java
index e57c9f9..87e35ed 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleService.java
@@ -34,7 +34,6 @@ import org.thingsboard.server.dao.component.ComponentDescriptorService;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.DatabaseException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.thingsboard.server.dao.model.RuleMetaDataEntity;
import org.thingsboard.server.dao.plugin.PluginService;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
@@ -45,8 +44,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
import static org.thingsboard.server.dao.service.Validator.validateId;
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
@@ -74,7 +71,7 @@ public class BaseRuleService implements RuleService {
rule.setTenantId(systemTenantId);
}
if (rule.getId() != null) {
- RuleMetaData oldVersion = getData(ruleDao.findById(rule.getId()));
+ RuleMetaData oldVersion = ruleDao.findById(rule.getId());
if (rule.getState() == null) {
rule.setState(oldVersion.getState());
} else if (rule.getState() != oldVersion.getState()) {
@@ -94,7 +91,7 @@ public class BaseRuleService implements RuleService {
}
validateComponentJson(rule.getAction(), ComponentType.ACTION);
validateRuleAndPluginState(rule);
- return getData(ruleDao.save(rule));
+ return ruleDao.save(rule);
}
private void validateFilters(JsonNode filtersJson) {
@@ -163,30 +160,27 @@ public class BaseRuleService implements RuleService {
@Override
public RuleMetaData findRuleById(RuleId ruleId) {
validateId(ruleId, "Incorrect rule id for search rule request.");
- return getData(ruleDao.findById(ruleId.getId()));
+ return ruleDao.findById(ruleId.getId());
}
@Override
public List<RuleMetaData> findPluginRules(String pluginToken) {
- List<RuleMetaDataEntity> ruleEntities = ruleDao.findRulesByPlugin(pluginToken);
- return convertDataList(ruleEntities);
+ return ruleDao.findRulesByPlugin(pluginToken);
}
@Override
public TextPageData<RuleMetaData> findSystemRules(TextPageLink pageLink) {
validatePageLink(pageLink, "Incorrect PageLink object for search rule request.");
- List<RuleMetaDataEntity> ruleEntities = ruleDao.findByTenantIdAndPageLink(systemTenantId, pageLink);
- List<RuleMetaData> plugins = convertDataList(ruleEntities);
- return new TextPageData<>(plugins, pageLink);
+ List<RuleMetaData> rules = ruleDao.findByTenantIdAndPageLink(systemTenantId, pageLink);
+ return new TextPageData<>(rules, pageLink);
}
@Override
public TextPageData<RuleMetaData> findTenantRules(TenantId tenantId, TextPageLink pageLink) {
validateId(tenantId, "Incorrect tenant id for search rule request.");
validatePageLink(pageLink, "Incorrect PageLink object for search rule request.");
- List<RuleMetaDataEntity> ruleEntities = ruleDao.findByTenantIdAndPageLink(tenantId, pageLink);
- List<RuleMetaData> plugins = convertDataList(ruleEntities);
- return new TextPageData<>(plugins, pageLink);
+ List<RuleMetaData> rules = ruleDao.findByTenantIdAndPageLink(tenantId, pageLink);
+ return new TextPageData<>(rules, pageLink);
}
@Override
@@ -210,8 +204,7 @@ public class BaseRuleService implements RuleService {
log.trace("Executing findAllTenantRulesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<RuleMetaDataEntity> rulesEntities = ruleDao.findAllTenantRulesByTenantId(tenantId.getId(), pageLink);
- List<RuleMetaData> rules = convertDataList(rulesEntities);
+ List<RuleMetaData> rules = ruleDao.findAllTenantRulesByTenantId(tenantId.getId(), pageLink);
return new TextPageData<>(rules, pageLink);
}
@@ -251,10 +244,10 @@ public class BaseRuleService implements RuleService {
private void updateLifeCycleState(RuleId ruleId, ComponentLifecycleState state) {
Validator.validateId(ruleId, "Incorrect rule id for state change request.");
- RuleMetaDataEntity rule = ruleDao.findById(ruleId);
+ RuleMetaData rule = ruleDao.findById(ruleId);
if (rule != null) {
rule.setState(state);
- validateRuleAndPluginState(getData(rule));
+ validateRuleAndPluginState(rule);
ruleDao.save(rule);
} else {
throw new DatabaseException("Plugin not found!");
@@ -277,17 +270,17 @@ public class BaseRuleService implements RuleService {
}
};
- private PaginatedRemover<TenantId, RuleMetaDataEntity> tenantRulesRemover =
- new PaginatedRemover<TenantId, RuleMetaDataEntity>() {
+ private PaginatedRemover<TenantId, RuleMetaData> tenantRulesRemover =
+ new PaginatedRemover<TenantId, RuleMetaData>() {
@Override
- protected List<RuleMetaDataEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<RuleMetaData> findEntities(TenantId id, TextPageLink pageLink) {
return ruleDao.findByTenantIdAndPageLink(id, pageLink);
}
@Override
- protected void removeEntity(RuleMetaDataEntity entity) {
- ruleDao.deleteById(entity.getId());
+ protected void removeEntity(RuleMetaData entity) {
+ ruleDao.deleteById(entity.getUuidId());
}
};
diff --git a/dao/src/main/java/org/thingsboard/server/dao/rule/RuleDao.java b/dao/src/main/java/org/thingsboard/server/dao/rule/RuleDao.java
index c2d09c7..ea12b74 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/rule/RuleDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/rule/RuleDao.java
@@ -20,20 +20,19 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.rule.RuleMetaData;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.RuleMetaDataEntity;
import java.util.List;
import java.util.UUID;
-public interface RuleDao extends Dao<RuleMetaDataEntity> {
+public interface RuleDao extends Dao<RuleMetaData> {
- RuleMetaDataEntity save(RuleMetaData rule);
+ RuleMetaData save(RuleMetaData rule);
- RuleMetaDataEntity findById(RuleId ruleId);
+ RuleMetaData findById(RuleId ruleId);
- List<RuleMetaDataEntity> findRulesByPlugin(String pluginToken);
+ List<RuleMetaData> findRulesByPlugin(String pluginToken);
- List<RuleMetaDataEntity> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
+ List<RuleMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
/**
* Find all tenant rules (including system) by tenantId and page link.
@@ -42,7 +41,7 @@ public interface RuleDao extends Dao<RuleMetaDataEntity> {
* @param pageLink the page link
* @return the list of rules objects
*/
- List<RuleMetaDataEntity> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<RuleMetaData> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink);
void deleteById(UUID id);
diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/DataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/DataValidator.java
index 2f3aef7..e460cd0 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/service/DataValidator.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/service/DataValidator.java
@@ -15,18 +15,15 @@
*/
package org.thingsboard.server.dao.service;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
+import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.validator.routines.EmailValidator;
import org.thingsboard.server.common.data.BaseData;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
@Slf4j
public abstract class DataValidator<D extends BaseData<?>> {
diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/PaginatedRemover.java b/dao/src/main/java/org/thingsboard/server/dao/service/PaginatedRemover.java
index 554a3c1..8bdefd9 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/service/PaginatedRemover.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/service/PaginatedRemover.java
@@ -15,33 +15,35 @@
*/
package org.thingsboard.server.dao.service;
+import org.thingsboard.server.common.data.id.IdBased;
+import org.thingsboard.server.common.data.page.TextPageLink;
+
import java.util.List;
import java.util.UUID;
-import org.thingsboard.server.common.data.page.TextPageLink;
-import org.thingsboard.server.dao.model.BaseEntity;
+public abstract class PaginatedRemover<I, D extends IdBased<?>> {
-public abstract class PaginatedRemover<I, E extends BaseEntity<?>> {
+ private static final int DEFAULT_LIMIT = 100;
public void removeEntitites(I id) {
- TextPageLink pageLink = new TextPageLink(100);
+ TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT);
boolean hasNext = true;
while (hasNext) {
- List<E> entities = findEntities(id, pageLink);
- for (E entity : entities) {
+ List<D> entities = findEntities(id, pageLink);
+ for (D entity : entities) {
removeEntity(entity);
}
hasNext = entities.size() == pageLink.getLimit();
if (hasNext) {
- int index = entities.size()-1;
- UUID idOffset = entities.get(index).getId();
+ int index = entities.size() - 1;
+ UUID idOffset = entities.get(index).getUuidId();
pageLink.setIdOffset(idOffset);
}
- }
+ }
}
-
- protected abstract List<E> findEntities(I id, TextPageLink pageLink);
-
- protected abstract void removeEntity(E entity);
-
+
+ protected abstract List<D> findEntities(I id, TextPageLink pageLink);
+
+ protected abstract void removeEntity(D entity);
+
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsDao.java b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsDao.java
index c5c6768..b0ed852 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsDao.java
@@ -17,9 +17,8 @@ package org.thingsboard.server.dao.settings;
import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.AdminSettingsEntity;
-public interface AdminSettingsDao extends Dao<AdminSettingsEntity> {
+public interface AdminSettingsDao extends Dao<AdminSettings> {
/**
* Save or update admin settings object
@@ -27,7 +26,7 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> {
* @param adminSettings the admin settings object
* @return saved admin settings object
*/
- AdminSettingsEntity save(AdminSettings adminSettings);
+ AdminSettings save(AdminSettings adminSettings);
/**
* Find admin settings by key.
@@ -35,6 +34,6 @@ public interface AdminSettingsDao extends Dao<AdminSettingsEntity> {
* @param key the key
* @return the admin settings object
*/
- AdminSettingsEntity findByKey(String key);
+ AdminSettings findByKey(String key);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsService.java b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsService.java
index 4c6e7ce..49576b1 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsService.java
@@ -20,10 +20,10 @@ import org.thingsboard.server.common.data.id.AdminSettingsId;
public interface AdminSettingsService {
- public AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId);
+ AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId);
- public AdminSettings findAdminSettingsByKey(String key);
+ AdminSettings findAdminSettingsByKey(String key);
- public AdminSettings saveAdminSettings(AdminSettings adminSettings);
+ AdminSettings saveAdminSettings(AdminSettings adminSettings);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java
index c6d1a6b..6bfa293 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java
@@ -15,19 +15,14 @@
*/
package org.thingsboard.server.dao.settings;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.common.data.id.AdminSettingsId;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.AdminSettingsEntity;
import org.thingsboard.server.dao.service.DataValidator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.service.Validator;
@Service
@@ -41,24 +36,21 @@ public class AdminSettingsServiceImpl implements AdminSettingsService {
public AdminSettings findAdminSettingsById(AdminSettingsId adminSettingsId) {
log.trace("Executing findAdminSettingsById [{}]", adminSettingsId);
Validator.validateId(adminSettingsId, "Incorrect adminSettingsId " + adminSettingsId);
- AdminSettingsEntity adminSettingsEntity = adminSettingsDao.findById(adminSettingsId.getId());
- return getData(adminSettingsEntity);
+ return adminSettingsDao.findById(adminSettingsId.getId());
}
@Override
public AdminSettings findAdminSettingsByKey(String key) {
log.trace("Executing findAdminSettingsByKey [{}]", key);
Validator.validateString(key, "Incorrect key " + key);
- AdminSettingsEntity adminSettingsEntity = adminSettingsDao.findByKey(key);
- return getData(adminSettingsEntity);
+ return adminSettingsDao.findByKey(key);
}
@Override
public AdminSettings saveAdminSettings(AdminSettings adminSettings) {
log.trace("Executing saveAdminSettings [{}]", adminSettings);
adminSettingsValidator.validate(adminSettings);
- AdminSettingsEntity adminSettingsEntity = adminSettingsDao.save(adminSettings);
- return getData(adminSettingsEntity);
+ return adminSettingsDao.save(adminSettings);
}
private DataValidator<AdminSettings> adminSettingsValidator =
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDao.java
new file mode 100644
index 0000000..a92e607
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDao.java
@@ -0,0 +1,90 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.sql;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.ListenableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.thingsboard.server.dao.Dao;
+import org.thingsboard.server.dao.DaoUtil;
+import org.thingsboard.server.dao.model.BaseEntity;
+import org.thingsboard.server.dao.model.SearchTextEntity;
+import org.thingsboard.server.dao.sql.user.JpaRepository;
+
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author Valerii Sosliuk
+ */
+@Slf4j
+public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao<D> {
+
+ protected abstract Class<E> getColumnFamilyClass();
+
+ protected abstract String getColumnFamilyName();
+
+ protected abstract JpaRepository<E, UUID> getCrudRepository();
+
+ protected boolean isSearchTextDao() {
+ return false;
+ }
+
+ @Override
+ public D save(D domain) {
+ E entity;
+ try {
+ entity = getColumnFamilyClass().getConstructor(domain.getClass()).newInstance(domain);
+ } catch (Exception e) {
+ log.error("Can't create entity for domain object {}", domain, e);
+ throw new IllegalArgumentException("Can't create entity for domain object {" + domain + "}", e);
+ } if (isSearchTextDao()) {
+ ((SearchTextEntity) entity).setSearchText(((SearchTextEntity) entity).getSearchTextSource().toLowerCase());
+ }
+ log.debug("Saving entity {}", entity);
+ entity = getCrudRepository().save(entity);
+ return DaoUtil.getData(entity);
+ }
+
+ @Override
+ public D findById(UUID key) {
+ log.debug("Get entity by key {}", key);
+ E entity = getCrudRepository().findOne(key);
+ return DaoUtil.getData(entity);
+ }
+
+ @Override
+ public ListenableFuture<D> findByIdAsync(UUID key) {
+ log.debug("Get entity by key {}", key);
+ org.springframework.util.concurrent.ListenableFuture<E> entityFuture = getCrudRepository().findByIdAsync(key);
+ // TODO: vsosliuk implement
+ return null;
+ }
+
+ @Override
+ public boolean removeById(UUID key) {
+ getCrudRepository().delete(key);
+ log.debug("Remove request: {}", key);
+ return getCrudRepository().equals(key);
+ }
+
+ @Override
+ public List<D> find() {
+ log.debug("Get all entities from column family {}", getColumnFamilyName());
+ List<E> entities = Lists.newArrayList(getCrudRepository().findAll());
+ return DaoUtil.convertDataList(entities);
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaRepository.java
new file mode 100644
index 0000000..0af2bf8
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaRepository.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.sql.user;
+
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.util.concurrent.ListenableFuture;
+
+import java.io.Serializable;
+
+/**
+ * @author Valerii Sosliuk
+ */
+public interface JpaRepository<E, ID extends Serializable> extends CrudRepository<E, ID> {
+
+ @Async
+ ListenableFuture<E> findByIdAsync(ID key);
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaUserDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaUserDao.java
new file mode 100644
index 0000000..8fb14d7
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/user/JpaUserDao.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.sql.user;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.thingsboard.server.common.data.User;
+import org.thingsboard.server.dao.model.ModelConstants;
+import org.thingsboard.server.dao.model.sql.UserEntity;
+import org.thingsboard.server.dao.sql.JpaAbstractDao;
+
+import java.util.UUID;
+
+/**
+ * @author Valerii Sosliuk
+ */
+@Component
+@ConditionalOnProperty(prefix="sql", value="enabled",havingValue = "true", matchIfMissing = false)
+public class JpaUserDao extends JpaAbstractDao<UserEntity, User> {
+
+ @Autowired
+ private UserRepository userRepository;
+
+ @Override
+ protected Class<UserEntity> getColumnFamilyClass() {
+ return UserEntity.class;
+ }
+
+ @Override
+ protected String getColumnFamilyName() {
+ return ModelConstants.USER_COLUMN_FAMILY_NAME;
+ }
+
+ @Override
+ protected JpaRepository<UserEntity, UUID> getCrudRepository() {
+ return userRepository;
+ }
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/user/UserRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/user/UserRepository.java
new file mode 100644
index 0000000..51364c7
--- /dev/null
+++ b/dao/src/main/java/org/thingsboard/server/dao/sql/user/UserRepository.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright © 2016-2017 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.server.dao.sql.user;
+
+import org.thingsboard.server.dao.model.sql.UserEntity;
+
+import java.util.UUID;
+
+/**
+ * @author Valerii Sosliuk
+ */
+public interface UserRepository extends JpaRepository<UserEntity, UUID> {
+}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantDao.java b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantDao.java
index c1b71fc..9c230d9 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantDao.java
@@ -15,14 +15,13 @@
*/
package org.thingsboard.server.dao.tenant;
-import java.util.List;
-
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.TenantEntity;
-public interface TenantDao extends Dao<TenantEntity> {
+import java.util.List;
+
+public interface TenantDao extends Dao<Tenant> {
/**
* Save or update tenant object
@@ -30,7 +29,7 @@ public interface TenantDao extends Dao<TenantEntity> {
* @param tenant the tenant object
* @return saved tenant object
*/
- TenantEntity save(Tenant tenant);
+ Tenant save(Tenant tenant);
/**
* Find tenants by region and page link.
@@ -39,6 +38,6 @@ public interface TenantDao extends Dao<TenantEntity> {
* @param pageLink the page link
* @return the list of tenant objects
*/
- List<TenantEntity> findTenantsByRegion(String region, TextPageLink pageLink);
+ List<Tenant> findTenantsByRegion(String region, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantService.java b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantService.java
index 7e56e19..13b5090 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantService.java
@@ -22,16 +22,14 @@ import org.thingsboard.server.common.data.page.TextPageLink;
public interface TenantService {
- public Tenant findTenantById(TenantId tenantId);
+ Tenant findTenantById(TenantId tenantId);
- public Tenant saveTenant(Tenant tenant);
+ Tenant saveTenant(Tenant tenant);
- public void deleteTenant(TenantId tenantId);
+ void deleteTenant(TenantId tenantId);
- public TextPageData<Tenant> findTenants(TextPageLink pageLink);
+ TextPageData<Tenant> findTenants(TextPageLink pageLink);
- //public TextPageData<Tenant> findTenantsByTitle(String title, PageLink pageLink);
-
- public void deleteTenants();
+ void deleteTenants();
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java
index 9deb828..976cb71 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java
@@ -15,13 +15,10 @@
*/
package org.thingsboard.server.dao.tenant;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
-import java.util.List;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageData;
@@ -30,19 +27,16 @@ import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.thingsboard.server.dao.model.TenantEntity;
import org.thingsboard.server.dao.plugin.PluginService;
import org.thingsboard.server.dao.rule.RuleService;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
-import org.thingsboard.server.dao.user.UserService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.service.Validator;
+import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
+import java.util.List;
+
@Service
@Slf4j
public class TenantServiceImpl implements TenantService {
@@ -77,8 +71,7 @@ public class TenantServiceImpl implements TenantService {
public Tenant findTenantById(TenantId tenantId) {
log.trace("Executing findTenantById [{}]", tenantId);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
- TenantEntity tenantEntity = tenantDao.findById(tenantId.getId());
- return getData(tenantEntity);
+ return tenantDao.findById(tenantId.getId());
}
@Override
@@ -86,8 +79,7 @@ public class TenantServiceImpl implements TenantService {
log.trace("Executing saveTenant [{}]", tenant);
tenant.setRegion(DEFAULT_TENANT_REGION);
tenantValidator.validate(tenant);
- TenantEntity tenantEntity = tenantDao.save(tenant);
- return getData(tenantEntity);
+ return tenantDao.save(tenant);
}
@Override
@@ -108,9 +100,8 @@ public class TenantServiceImpl implements TenantService {
public TextPageData<Tenant> findTenants(TextPageLink pageLink) {
log.trace("Executing findTenants pageLink [{}]", pageLink);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<TenantEntity> tenantEntities = tenantDao.findTenantsByRegion(DEFAULT_TENANT_REGION, pageLink);
- List<Tenant> tenants = convertDataList(tenantEntities);
- return new TextPageData<Tenant>(tenants, pageLink);
+ List<Tenant> tenants = tenantDao.findTenantsByRegion(DEFAULT_TENANT_REGION, pageLink);
+ return new TextPageData<>(tenants, pageLink);
}
@Override
@@ -132,17 +123,17 @@ public class TenantServiceImpl implements TenantService {
}
};
- private PaginatedRemover<String, TenantEntity> tenantsRemover =
- new PaginatedRemover<String, TenantEntity>() {
+ private PaginatedRemover<String, Tenant> tenantsRemover =
+ new PaginatedRemover<String, Tenant>() {
@Override
- protected List<TenantEntity> findEntities(String region, TextPageLink pageLink) {
+ protected List<Tenant> findEntities(String region, TextPageLink pageLink) {
return tenantDao.findTenantsByRegion(region, pageLink);
}
@Override
- protected void removeEntity(TenantEntity entity) {
- deleteTenant(new TenantId(entity.getId()));
+ protected void removeEntity(Tenant entity) {
+ deleteTenant(new TenantId(entity.getUuidId()));
}
};
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/timeseries/BaseTimeseriesService.java b/dao/src/main/java/org/thingsboard/server/dao/timeseries/BaseTimeseriesService.java
index f27ed6e..d58815f 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/timeseries/BaseTimeseriesService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/timeseries/BaseTimeseriesService.java
@@ -15,34 +15,21 @@
*/
package org.thingsboard.server.dao.timeseries;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
-import com.datastax.driver.core.Row;
-import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.id.UUIDBased;
-import org.thingsboard.server.common.data.kv.BaseTsKvQuery;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.kv.TsKvQuery;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.service.Validator;
-import javax.annotation.Nullable;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
import static org.apache.commons.lang3.StringUtils.isBlank;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesDao.java b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesDao.java
index 177003d..733200d 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesDao.java
@@ -15,15 +15,11 @@
*/
package org.thingsboard.server.dao.timeseries;
-import com.datastax.driver.core.ResultSetFuture;
-import com.datastax.driver.core.Row;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.kv.TsKvQuery;
import java.util.List;
-import java.util.Optional;
-import java.util.Set;
import java.util.UUID;
/**
diff --git a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesService.java b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesService.java
index cd53e94..b2bf2e0 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TimeseriesService.java
@@ -15,18 +15,13 @@
*/
package org.thingsboard.server.dao.timeseries;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
-import com.datastax.driver.core.Row;
import com.google.common.util.concurrent.ListenableFuture;
-import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.kv.TsKvQuery;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
/**
* @author Andrew Shvayka
diff --git a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TsKvQueryCursor.java b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TsKvQueryCursor.java
index cad1232..ed53733 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/timeseries/TsKvQueryCursor.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/timeseries/TsKvQueryCursor.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.timeseries;
-import lombok.Data;
import lombok.Getter;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.kv.TsKvQuery;
diff --git a/dao/src/main/java/org/thingsboard/server/dao/user/UserCredentialsDao.java b/dao/src/main/java/org/thingsboard/server/dao/user/UserCredentialsDao.java
index 52045bc..5861fa1 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/user/UserCredentialsDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/user/UserCredentialsDao.java
@@ -15,18 +15,15 @@
*/
package org.thingsboard.server.dao.user;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.UserCredentialsEntity;
+
+import java.util.UUID;
/**
* The Interface UserCredentialsDao.
- *
- * @param <T> the generic type
*/
-public interface UserCredentialsDao extends Dao<UserCredentialsEntity> {
+public interface UserCredentialsDao extends Dao<UserCredentials> {
/**
* Save or update user credentials object
@@ -34,7 +31,7 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> {
* @param userCredentials the user credentials object
* @return saved user credentials object
*/
- UserCredentialsEntity save(UserCredentials userCredentials);
+ UserCredentials save(UserCredentials userCredentials);
/**
* Find user credentials by user id.
@@ -42,22 +39,22 @@ public interface UserCredentialsDao extends Dao<UserCredentialsEntity> {
* @param userId the user id
* @return the user credentials object
*/
- UserCredentialsEntity findByUserId(UUID userId);
-
+ UserCredentials findByUserId(UUID userId);
+
/**
* Find user credentials by activate token.
*
* @param activateToken the activate token
* @return the user credentials object
*/
- UserCredentialsEntity findByActivateToken(String activateToken);
-
+ UserCredentials findByActivateToken(String activateToken);
+
/**
* Find user credentials by reset token.
*
* @param resetToken the reset token
* @return the user credentials object
*/
- UserCredentialsEntity findByResetToken(String resetToken);
-
+ UserCredentials findByResetToken(String resetToken);
+
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/user/UserDao.java b/dao/src/main/java/org/thingsboard/server/dao/user/UserDao.java
index e84d68b..292099a 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/user/UserDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/user/UserDao.java
@@ -15,15 +15,14 @@
*/
package org.thingsboard.server.dao.user;
-import java.util.List;
-import java.util.UUID;
-
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.UserEntity;
-public interface UserDao extends Dao<UserEntity> {
+import java.util.List;
+import java.util.UUID;
+
+public interface UserDao extends Dao<User> {
/**
* Save or update user object
@@ -31,7 +30,7 @@ public interface UserDao extends Dao<UserEntity> {
* @param user the user object
* @return saved user entity
*/
- UserEntity save(User user);
+ User save(User user);
/**
* Find user by email.
@@ -39,7 +38,7 @@ public interface UserDao extends Dao<UserEntity> {
* @param email the email
* @return the user entity
*/
- UserEntity findByEmail(String email);
+ User findByEmail(String email);
/**
* Find tenant admin users by tenantId and page link.
@@ -48,7 +47,7 @@ public interface UserDao extends Dao<UserEntity> {
* @param pageLink the page link
* @return the list of user entities
*/
- List<UserEntity> findTenantAdmins(UUID tenantId, TextPageLink pageLink);
+ List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink);
/**
* Find customer users by tenantId, customerId and page link.
@@ -58,6 +57,6 @@ public interface UserDao extends Dao<UserEntity> {
* @param pageLink the page link
* @return the list of user entities
*/
- List<UserEntity> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink);
+ List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/user/UserService.java b/dao/src/main/java/org/thingsboard/server/dao/user/UserService.java
index f4043a0..92380c6 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/user/UserService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/user/UserService.java
@@ -25,32 +25,32 @@ import org.thingsboard.server.common.data.security.UserCredentials;
public interface UserService {
- public User findUserById(UserId userId);
+ User findUserById(UserId userId);
- public User findUserByEmail(String email);
+ User findUserByEmail(String email);
- public User saveUser(User user);
+ User saveUser(User user);
- public UserCredentials findUserCredentialsByUserId(UserId userId);
+ UserCredentials findUserCredentialsByUserId(UserId userId);
- public UserCredentials findUserCredentialsByActivateToken(String activateToken);
+ UserCredentials findUserCredentialsByActivateToken(String activateToken);
- public UserCredentials findUserCredentialsByResetToken(String resetToken);
+ UserCredentials findUserCredentialsByResetToken(String resetToken);
- public UserCredentials saveUserCredentials(UserCredentials userCredentials);
+ UserCredentials saveUserCredentials(UserCredentials userCredentials);
- public UserCredentials activateUserCredentials(String activateToken, String password);
+ UserCredentials activateUserCredentials(String activateToken, String password);
- public UserCredentials requestPasswordReset(String email);
+ UserCredentials requestPasswordReset(String email);
- public void deleteUser(UserId userId);
+ void deleteUser(UserId userId);
- public TextPageData<User> findTenantAdmins(TenantId tenantId, TextPageLink pageLink);
+ TextPageData<User> findTenantAdmins(TenantId tenantId, TextPageLink pageLink);
- public void deleteTenantAdmins(TenantId tenantId);
+ void deleteTenantAdmins(TenantId tenantId);
- public TextPageData<User> findCustomerUsers(TenantId tenantId, CustomerId customerId, TextPageLink pageLink);
+ TextPageData<User> findCustomerUsers(TenantId tenantId, CustomerId customerId, TextPageLink pageLink);
- public void deleteCustomerUsers(TenantId tenantId, CustomerId customerId);
+ void deleteCustomerUsers(TenantId tenantId, CustomerId customerId);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java
index 9ad9102..7f4d6c0 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java
@@ -15,17 +15,13 @@
*/
package org.thingsboard.server.dao.user;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-import static org.thingsboard.server.dao.service.Validator.validateId;
-import static org.thingsboard.server.dao.service.Validator.validatePageLink;
-import static org.thingsboard.server.dao.service.Validator.validateString;
-
-import java.util.List;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.thingsboard.server.common.data.Customer;
+import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId;
@@ -37,19 +33,21 @@ import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.server.dao.customer.CustomerDao;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
-import org.thingsboard.server.dao.model.*;
+import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.tenant.TenantDao;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+import static org.thingsboard.server.dao.service.Validator.*;
@Service
@Slf4j
public class UserServiceImpl implements UserService {
+ private static final int DEFAULT_TOKEN_LENGTH = 30;
+
@Autowired
private UserDao userDao;
@@ -66,63 +64,57 @@ public class UserServiceImpl implements UserService {
public User findUserByEmail(String email) {
log.trace("Executing findUserByEmail [{}]", email);
validateString(email, "Incorrect email " + email);
- UserEntity userEntity = userDao.findByEmail(email);
- return getData(userEntity);
+ return userDao.findByEmail(email);
}
@Override
public User findUserById(UserId userId) {
log.trace("Executing findUserById [{}]", userId);
validateId(userId, "Incorrect userId " + userId);
- UserEntity userEntity = userDao.findById(userId.getId());
- return getData(userEntity);
+ return userDao.findById(userId.getId());
}
@Override
public User saveUser(User user) {
log.trace("Executing saveUser [{}]", user);
userValidator.validate(user);
- UserEntity userEntity = userDao.save(user);
+ User savedUser = userDao.save(user);
if (user.getId() == null) {
UserCredentials userCredentials = new UserCredentials();
userCredentials.setEnabled(false);
- userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(30));
- userCredentials.setUserId(new UserId(userEntity.getId()));
+ userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
+ userCredentials.setUserId(new UserId(savedUser.getUuidId()));
userCredentialsDao.save(userCredentials);
}
- return getData(userEntity);
+ return savedUser;
}
@Override
public UserCredentials findUserCredentialsByUserId(UserId userId) {
log.trace("Executing findUserCredentialsByUserId [{}]", userId);
validateId(userId, "Incorrect userId " + userId);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userId.getId());
- return getData(userCredentialsEntity);
+ return userCredentialsDao.findByUserId(userId.getId());
}
@Override
public UserCredentials findUserCredentialsByActivateToken(String activateToken) {
log.trace("Executing findUserCredentialsByActivateToken [{}]", activateToken);
validateString(activateToken, "Incorrect activateToken " + activateToken);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByActivateToken(activateToken);
- return getData(userCredentialsEntity);
+ return userCredentialsDao.findByActivateToken(activateToken);
}
@Override
public UserCredentials findUserCredentialsByResetToken(String resetToken) {
log.trace("Executing findUserCredentialsByResetToken [{}]", resetToken);
validateString(resetToken, "Incorrect resetToken " + resetToken);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByResetToken(resetToken);
- return getData(userCredentialsEntity);
+ return userCredentialsDao.findByResetToken(resetToken);
}
@Override
public UserCredentials saveUserCredentials(UserCredentials userCredentials) {
log.trace("Executing saveUserCredentials [{}]", userCredentials);
userCredentialsValidator.validate(userCredentials);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.save(userCredentials);
- return getData(userCredentialsEntity);
+ return userCredentialsDao.save(userCredentials);
}
@Override
@@ -130,11 +122,10 @@ public class UserServiceImpl implements UserService {
log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password);
validateString(activateToken, "Incorrect activateToken " + activateToken);
validateString(password, "Incorrect password " + password);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByActivateToken(activateToken);
- if (userCredentialsEntity == null) {
+ UserCredentials userCredentials = userCredentialsDao.findByActivateToken(activateToken);
+ if (userCredentials == null) {
throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken));
}
- UserCredentials userCredentials = getData(userCredentialsEntity);
if (userCredentials.isEnabled()) {
throw new IncorrectParameterException("User credentials already activated");
}
@@ -149,16 +140,15 @@ public class UserServiceImpl implements UserService {
public UserCredentials requestPasswordReset(String email) {
log.trace("Executing requestPasswordReset email [{}]", email);
validateString(email, "Incorrect email " + email);
- UserEntity userEntity = userDao.findByEmail(email);
- if (userEntity == null) {
+ User user = userDao.findByEmail(email);
+ if (user == null) {
throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email));
}
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userEntity.getId());
- UserCredentials userCredentials = getData(userCredentialsEntity);
+ UserCredentials userCredentials = userCredentialsDao.findByUserId(user.getUuidId());
if (!userCredentials.isEnabled()) {
throw new IncorrectParameterException("Unable to reset password for inactive user");
}
- userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(30));
+ userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
return saveUserCredentials(userCredentials);
}
@@ -167,8 +157,8 @@ public class UserServiceImpl implements UserService {
public void deleteUser(UserId userId) {
log.trace("Executing deleteUser [{}]", userId);
validateId(userId, "Incorrect userId " + userId);
- UserCredentialsEntity userCredentialsEntity = userCredentialsDao.findByUserId(userId.getId());
- userCredentialsDao.removeById(userCredentialsEntity.getId());
+ UserCredentials userCredentials = userCredentialsDao.findByUserId(userId.getId());
+ userCredentialsDao.removeById(userCredentials.getUuidId());
userDao.removeById(userId.getId());
}
@@ -177,9 +167,8 @@ public class UserServiceImpl implements UserService {
log.trace("Executing findTenantAdmins, tenantId [{}], pageLink [{}]", tenantId, pageLink);
validateId(tenantId, "Incorrect tenantId " + tenantId);
validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<UserEntity> userEntities = userDao.findTenantAdmins(tenantId.getId(), pageLink);
- List<User> users = convertDataList(userEntities);
- return new TextPageData<User>(users, pageLink);
+ List<User> users = userDao.findTenantAdmins(tenantId.getId(), pageLink);
+ return new TextPageData<>(users, pageLink);
}
@Override
@@ -195,9 +184,8 @@ public class UserServiceImpl implements UserService {
validateId(tenantId, "Incorrect tenantId " + tenantId);
validateId(customerId, "Incorrect customerId " + customerId);
validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<UserEntity> userEntities = userDao.findCustomerUsers(tenantId.getId(), customerId.getId(), pageLink);
- List<User> users = convertDataList(userEntities);
- return new TextPageData<User>(users, pageLink);
+ List<User> users = userDao.findCustomerUsers(tenantId.getId(), customerId.getId(), pageLink);
+ return new TextPageData<>(users, pageLink);
}
@Override
@@ -266,16 +254,16 @@ public class UserServiceImpl implements UserService {
+ " already present in database!");
}
if (!tenantId.getId().equals(ModelConstants.NULL_UUID)) {
- TenantEntity tenant = tenantDao.findById(user.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(user.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("User is referencing to non-existent tenant!");
}
}
if (!customerId.getId().equals(ModelConstants.NULL_UUID)) {
- CustomerEntity customer = customerDao.findById(user.getCustomerId().getId());
+ Customer customer = customerDao.findById(user.getCustomerId().getId());
if (customer == null) {
throw new DataValidationException("User is referencing to non-existent customer!");
- } else if (!customer.getTenantId().equals(tenantId.getId())) {
+ } else if (!customer.getTenantId().getId().equals(tenantId.getId())) {
throw new DataValidationException("User can't be assigned to customer from different tenant!");
}
}
@@ -303,7 +291,7 @@ public class UserServiceImpl implements UserService {
throw new DataValidationException("Enabled user credentials can't have activate token!");
}
}
- UserCredentialsEntity existingUserCredentialsEntity = userCredentialsDao.findById(userCredentials.getId().getId());
+ UserCredentials existingUserCredentialsEntity = userCredentialsDao.findById(userCredentials.getId().getId());
if (existingUserCredentialsEntity == null) {
throw new DataValidationException("Unable to update non-existent user credentials!");
}
@@ -314,21 +302,21 @@ public class UserServiceImpl implements UserService {
}
};
- private PaginatedRemover<TenantId, UserEntity> tenantAdminsRemover =
- new PaginatedRemover<TenantId, UserEntity>() {
+ private PaginatedRemover<TenantId, User> tenantAdminsRemover =
+ new PaginatedRemover<TenantId, User>() {
@Override
- protected List<UserEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<User> findEntities(TenantId id, TextPageLink pageLink) {
return userDao.findTenantAdmins(id.getId(), pageLink);
}
@Override
- protected void removeEntity(UserEntity entity) {
- deleteUser(new UserId(entity.getId()));
+ protected void removeEntity(User entity) {
+ deleteUser(new UserId(entity.getUuidId()));
}
};
- class CustomerUsersRemover extends PaginatedRemover<CustomerId, UserEntity> {
+ private class CustomerUsersRemover extends PaginatedRemover<CustomerId, User> {
private TenantId tenantId;
@@ -337,14 +325,14 @@ public class UserServiceImpl implements UserService {
}
@Override
- protected List<UserEntity> findEntities(CustomerId id, TextPageLink pageLink) {
+ protected List<User> findEntities(CustomerId id, TextPageLink pageLink) {
return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink);
}
@Override
- protected void removeEntity(UserEntity entity) {
- deleteUser(new UserId(entity.getId()));
+ protected void removeEntity(User entity) {
+ deleteUser(new UserId(entity.getUuidId()));
}
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java
index 0e04f91..d8c6044 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java
@@ -18,17 +18,14 @@ package org.thingsboard.server.dao.widget;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.WidgetsBundleEntity;
import java.util.List;
import java.util.UUID;
/**
* The Interface WidgetsBundleDao.
- *
- * @param <T> the generic type
*/
-public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
+public interface WidgetsBundleDao extends Dao<WidgetsBundle> {
/**
* Save or update widgets bundle object
@@ -36,7 +33,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
* @param widgetsBundle the widgets bundle object
* @return saved widgets bundle object
*/
- WidgetsBundleEntity save(WidgetsBundle widgetsBundle);
+ WidgetsBundle save(WidgetsBundle widgetsBundle);
/**
* Find widgets bundle by tenantId and alias.
@@ -45,7 +42,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
* @param alias the alias
* @return the widgets bundle object
*/
- WidgetsBundleEntity findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias);
+ WidgetsBundle findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias);
/**
* Find system widgets bundles by page link.
@@ -53,7 +50,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
* @param pageLink the page link
* @return the list of widgets bundles objects
*/
- List<WidgetsBundleEntity> findSystemWidgetsBundles(TextPageLink pageLink);
+ List<WidgetsBundle> findSystemWidgetsBundles(TextPageLink pageLink);
/**
* Find tenant widgets bundles by tenantId and page link.
@@ -62,7 +59,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
* @param pageLink the page link
* @return the list of widgets bundles objects
*/
- List<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink);
/**
* Find all tenant widgets bundles (including system) by tenantId and page link.
@@ -71,7 +68,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundleEntity> {
* @param pageLink the page link
* @return the list of widgets bundles objects
*/
- List<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink);
+ List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java
index 4b91c26..27f9211 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java
@@ -25,24 +25,24 @@ import java.util.List;
public interface WidgetsBundleService {
- public WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId);
+ WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId);
- public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle);
+ WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle);
- public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId);
+ void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId);
- public WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias);
+ WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias);
- public TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink);
+ TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink);
- public List<WidgetsBundle> findSystemWidgetsBundles();
+ List<WidgetsBundle> findSystemWidgetsBundles();
- public TextPageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, TextPageLink pageLink);
+ TextPageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, TextPageLink pageLink);
- public TextPageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
+ TextPageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink);
- public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId);
+ List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId);
- public void deleteWidgetsBundlesByTenantId(TenantId tenantId);
+ void deleteWidgetsBundlesByTenantId(TenantId tenantId);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java
index 2262e14..9e90aca 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java
@@ -17,10 +17,9 @@ package org.thingsboard.server.dao.widget;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.page.TextPageData;
@@ -29,8 +28,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.IncorrectParameterException;
import org.thingsboard.server.dao.model.ModelConstants;
-import org.thingsboard.server.dao.model.TenantEntity;
-import org.thingsboard.server.dao.model.WidgetsBundleEntity;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.service.Validator;
@@ -39,13 +36,12 @@ import org.thingsboard.server.dao.tenant.TenantDao;
import java.util.ArrayList;
import java.util.List;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
@Service
@Slf4j
public class WidgetsBundleServiceImpl implements WidgetsBundleService {
+ private static final int DEFAULT_WIDGETS_BUNDLE_LIMIT = 300;
+
@Autowired
private WidgetsBundleDao widgetsBundleDao;
@@ -59,16 +55,14 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
public WidgetsBundle findWidgetsBundleById(WidgetsBundleId widgetsBundleId) {
log.trace("Executing findWidgetsBundleById [{}]", widgetsBundleId);
Validator.validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId);
- WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.findById(widgetsBundleId.getId());
- return getData(widgetsBundleEntity);
+ return widgetsBundleDao.findById(widgetsBundleId.getId());
}
@Override
public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle) {
log.trace("Executing saveWidgetsBundle [{}]", widgetsBundle);
widgetsBundleValidator.validate(widgetsBundle);
- WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.save(widgetsBundle);
- return getData(widgetsBundleEntity);
+ return widgetsBundleDao.save(widgetsBundle);
}
@Override
@@ -88,25 +82,22 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
log.trace("Executing findWidgetsBundleByTenantIdAndAlias, tenantId [{}], alias [{}]", tenantId, alias);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validateString(alias, "Incorrect alias " + alias);
- WidgetsBundleEntity widgetsBundleEntity = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(tenantId.getId(), alias);
- return getData(widgetsBundleEntity);
+ return widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(tenantId.getId(), alias);
}
@Override
public TextPageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TextPageLink pageLink) {
log.trace("Executing findSystemWidgetsBundles, pageLink [{}]", pageLink);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findSystemWidgetsBundles(pageLink);
- List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities);
- return new TextPageData<>(widgetsBundles, pageLink);
+ return new TextPageData<>(widgetsBundleDao.findSystemWidgetsBundles(pageLink), pageLink);
}
@Override
public List<WidgetsBundle> findSystemWidgetsBundles() {
log.trace("Executing findSystemWidgetsBundles");
List<WidgetsBundle> widgetsBundles = new ArrayList<>();
- TextPageLink pageLink = new TextPageLink(300);
- TextPageData<WidgetsBundle> pageData = null;
+ TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
+ TextPageData<WidgetsBundle> pageData;
do {
pageData = findSystemWidgetsBundlesByPageLink(pageLink);
widgetsBundles.addAll(pageData.getData());
@@ -122,9 +113,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
log.trace("Executing findTenantWidgetsBundlesByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink);
- List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities);
- return new TextPageData<>(widgetsBundles, pageLink);
+ return new TextPageData<>(widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink), pageLink);
}
@Override
@@ -132,9 +121,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
log.trace("Executing findAllTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validatePageLink(pageLink, "Incorrect page link " + pageLink);
- List<WidgetsBundleEntity> widgetsBundlesEntities = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink);
- List<WidgetsBundle> widgetsBundles = convertDataList(widgetsBundlesEntities);
- return new TextPageData<>(widgetsBundles, pageLink);
+ return new TextPageData<>(widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), pageLink), pageLink);
}
@Override
@@ -142,8 +129,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
List<WidgetsBundle> widgetsBundles = new ArrayList<>();
- TextPageLink pageLink = new TextPageLink(300);
- TextPageData<WidgetsBundle> pageData = null;
+ TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
+ TextPageData<WidgetsBundle> pageData;
do {
pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
widgetsBundles.addAll(pageData.getData());
@@ -173,7 +160,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
widgetsBundle.setTenantId(new TenantId(ModelConstants.NULL_UUID));
}
if (!widgetsBundle.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
- TenantEntity tenant = tenantDao.findById(widgetsBundle.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(widgetsBundle.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("Widgets bundle is referencing to non-existent tenant!");
}
@@ -185,7 +172,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
String alias = widgetsBundle.getTitle().toLowerCase().replaceAll("\\W+", "_");
String originalAlias = alias;
int c = 1;
- WidgetsBundleEntity withSameAlias;
+ WidgetsBundle withSameAlias;
do {
withSameAlias = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(widgetsBundle.getTenantId().getId(), alias);
if (withSameAlias != null) {
@@ -197,8 +184,8 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
@Override
protected void validateUpdate(WidgetsBundle widgetsBundle) {
- WidgetsBundleEntity storedWidgetsBundle = widgetsBundleDao.findById(widgetsBundle.getId().getId());
- if (!storedWidgetsBundle.getTenantId().equals(widgetsBundle.getTenantId().getId())) {
+ WidgetsBundle storedWidgetsBundle = widgetsBundleDao.findById(widgetsBundle.getId().getId());
+ if (!storedWidgetsBundle.getTenantId().getId().equals(widgetsBundle.getTenantId().getId())) {
throw new DataValidationException("Can't move existing widgets bundle to different tenant!");
}
if (!storedWidgetsBundle.getAlias().equals(widgetsBundle.getAlias())) {
@@ -208,17 +195,17 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
};
- private PaginatedRemover<TenantId, WidgetsBundleEntity> tenantWidgetsBundleRemover =
- new PaginatedRemover<TenantId, WidgetsBundleEntity>() {
+ private PaginatedRemover<TenantId, WidgetsBundle> tenantWidgetsBundleRemover =
+ new PaginatedRemover<TenantId, WidgetsBundle>() {
@Override
- protected List<WidgetsBundleEntity> findEntities(TenantId id, TextPageLink pageLink) {
+ protected List<WidgetsBundle> findEntities(TenantId id, TextPageLink pageLink) {
return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(id.getId(), pageLink);
}
@Override
- protected void removeEntity(WidgetsBundleEntity entity) {
- deleteWidgetsBundle(new WidgetsBundleId(entity.getId()));
+ protected void removeEntity(WidgetsBundle entity) {
+ deleteWidgetsBundle(new WidgetsBundleId(entity.getUuidId()));
}
};
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeDao.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeDao.java
index dd85c10..dce7064 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeDao.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeDao.java
@@ -17,17 +17,14 @@ package org.thingsboard.server.dao.widget;
import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.dao.Dao;
-import org.thingsboard.server.dao.model.WidgetTypeEntity;
import java.util.List;
import java.util.UUID;
/**
* The Interface WidgetTypeDao.
- *
- * @param <T> the generic type
*/
-public interface WidgetTypeDao extends Dao<WidgetTypeEntity> {
+public interface WidgetTypeDao extends Dao<WidgetType> {
/**
* Save or update widget type object
@@ -35,7 +32,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> {
* @param widgetType the widget type object
* @return saved widget type object
*/
- WidgetTypeEntity save(WidgetType widgetType);
+ WidgetType save(WidgetType widgetType);
/**
* Find widget types by tenantId and bundleAlias.
@@ -44,7 +41,7 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> {
* @param bundleAlias the bundle alias
* @return the list of widget types objects
*/
- List<WidgetTypeEntity> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias);
+ List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias);
/**
* Find widget type by tenantId, bundleAlias and alias.
@@ -54,6 +51,6 @@ public interface WidgetTypeDao extends Dao<WidgetTypeEntity> {
* @param alias the alias
* @return the widget type object
*/
- WidgetTypeEntity findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias);
+ WidgetType findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeService.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeService.java
index 5ff931c..dcc70f7 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeService.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeService.java
@@ -23,16 +23,16 @@ import java.util.List;
public interface WidgetTypeService {
- public WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId);
+ WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId);
- public WidgetType saveWidgetType(WidgetType widgetType);
+ WidgetType saveWidgetType(WidgetType widgetType);
- public void deleteWidgetType(WidgetTypeId widgetTypeId);
+ void deleteWidgetType(WidgetTypeId widgetTypeId);
- public List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias);
+ List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias);
- public WidgetType findWidgetTypeByTenantIdBundleAliasAndAlias(TenantId tenantId, String bundleAlias, String alias);
+ WidgetType findWidgetTypeByTenantIdBundleAliasAndAlias(TenantId tenantId, String bundleAlias, String alias);
- public void deleteWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias);
+ void deleteWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias);
}
diff --git a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java
index 45a0c71..f533f71 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java
@@ -17,8 +17,6 @@ package org.thingsboard.server.dao.widget;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.Tenant;
@@ -28,19 +26,12 @@ import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.model.ModelConstants;
-import org.thingsboard.server.dao.model.TenantEntity;
-import org.thingsboard.server.dao.model.WidgetTypeEntity;
-import org.thingsboard.server.dao.model.WidgetsBundleEntity;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.Validator;
import org.thingsboard.server.dao.tenant.TenantDao;
-import org.thingsboard.server.dao.tenant.TenantService;
import java.util.List;
-import static org.thingsboard.server.dao.DaoUtil.convertDataList;
-import static org.thingsboard.server.dao.DaoUtil.getData;
-
@Service
@Slf4j
public class WidgetTypeServiceImpl implements WidgetTypeService {
@@ -58,16 +49,14 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
public WidgetType findWidgetTypeById(WidgetTypeId widgetTypeId) {
log.trace("Executing findWidgetTypeById [{}]", widgetTypeId);
Validator.validateId(widgetTypeId, "Incorrect widgetTypeId " + widgetTypeId);
- WidgetTypeEntity widgetTypeEntity = widgetTypeDao.findById(widgetTypeId.getId());
- return getData(widgetTypeEntity);
+ return widgetTypeDao.findById(widgetTypeId.getId());
}
@Override
public WidgetType saveWidgetType(WidgetType widgetType) {
log.trace("Executing saveWidgetType [{}]", widgetType);
widgetTypeValidator.validate(widgetType);
- WidgetTypeEntity widgetTypeEntity = widgetTypeDao.save(widgetType);
- return getData(widgetTypeEntity);
+ return widgetTypeDao.save(widgetType);
}
@Override
@@ -82,8 +71,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
log.trace("Executing findWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias);
- List<WidgetTypeEntity> widgetTypesEntities = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias);
- return convertDataList(widgetTypesEntities);
+ return widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias);
}
@Override
@@ -92,8 +80,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias);
Validator.validateString(alias, "Incorrect alias " + alias);
- WidgetTypeEntity widgetTypeEntity = widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId.getId(), bundleAlias, alias);
- return getData(widgetTypeEntity);
+ return widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId.getId(), bundleAlias, alias);
}
@Override
@@ -101,9 +88,9 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
log.trace("Executing deleteWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
Validator.validateString(bundleAlias, "Incorrect bundleAlias " + bundleAlias);
- List<WidgetTypeEntity> widgetTypesEntities = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias);
- for (WidgetTypeEntity widgetTypeEntity : widgetTypesEntities) {
- deleteWidgetType(new WidgetTypeId(widgetTypeEntity.getId()));
+ List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias);
+ for (WidgetType widgetType : widgetTypes) {
+ deleteWidgetType(new WidgetTypeId(widgetType.getUuidId()));
}
}
@@ -124,7 +111,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
widgetType.setTenantId(new TenantId(ModelConstants.NULL_UUID));
}
if (!widgetType.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
- TenantEntity tenant = tenantDao.findById(widgetType.getTenantId().getId());
+ Tenant tenant = tenantDao.findById(widgetType.getTenantId().getId());
if (tenant == null) {
throw new DataValidationException("Widget type is referencing to non-existent tenant!");
}
@@ -133,8 +120,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
@Override
protected void validateCreate(WidgetType widgetType) {
-
- WidgetsBundleEntity widgetsBundle = widgetsBundleService.findWidgetsBundleByTenantIdAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias());
+ WidgetsBundle widgetsBundle = widgetsBundleService.findWidgetsBundleByTenantIdAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias());
if (widgetsBundle == null) {
throw new DataValidationException("Widget type is referencing to non-existent widgets bundle!");
}
@@ -142,7 +128,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
String alias = widgetType.getName().toLowerCase().replaceAll("\\W+", "_");
String originalAlias = alias;
int c = 1;
- WidgetTypeEntity withSameAlias;
+ WidgetType withSameAlias;
do {
withSameAlias = widgetTypeDao.findByTenantIdBundleAliasAndAlias(widgetType.getTenantId().getId(), widgetType.getBundleAlias(), alias);
if (withSameAlias != null) {
@@ -154,8 +140,8 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
@Override
protected void validateUpdate(WidgetType widgetType) {
- WidgetTypeEntity storedWidgetType = widgetTypeDao.findById(widgetType.getId().getId());
- if (!storedWidgetType.getTenantId().equals(widgetType.getTenantId().getId())) {
+ WidgetType storedWidgetType = widgetTypeDao.findById(widgetType.getId().getId());
+ if (!storedWidgetType.getTenantId().getId().equals(widgetType.getTenantId().getId())) {
throw new DataValidationException("Can't move existing widget type to different tenant!");
}
if (!storedWidgetType.getBundleAlias().equals(widgetType.getBundleAlias())) {
diff --git a/dao/src/test/java/org/thingsboard/server/dao/attributes/BaseAttributesServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/attributes/BaseAttributesServiceTest.java
index 559a313..a9835cb 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/attributes/BaseAttributesServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/attributes/BaseAttributesServiceTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.attributes;
-import com.datastax.driver.core.utils.UUIDs;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/event/BaseEventServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/event/BaseEventServiceTest.java
index bdabcf4..b185d2c 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/event/BaseEventServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/event/BaseEventServiceTest.java
@@ -15,8 +15,6 @@
*/
package org.thingsboard.server.dao.event;
-import com.datastax.driver.core.utils.UUIDs;
-import org.apache.cassandra.utils.UUIDGen;
import org.junit.Assert;
import org.junit.Test;
import org.thingsboard.server.common.data.DataConstants;
@@ -34,7 +32,6 @@ import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
-import java.util.List;
import java.util.Optional;
public class BaseEventServiceTest extends AbstractServiceTest {
diff --git a/dao/src/test/java/org/thingsboard/server/dao/plugin/BasePluginServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/plugin/BasePluginServiceTest.java
index 4367c87..80acec7 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/plugin/BasePluginServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/plugin/BasePluginServiceTest.java
@@ -15,22 +15,19 @@
*/
package org.thingsboard.server.dao.plugin;
-import java.util.UUID;
-
import lombok.extern.slf4j.Slf4j;
+import org.junit.Assert;
+import org.junit.Test;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.common.data.plugin.PluginMetaData;
-import org.thingsboard.server.common.data.rule.RuleMetaData;
+import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.service.AbstractServiceTest;
import org.junit.Assert;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.datastax.driver.core.utils.UUIDs;
-import org.thingsboard.server.dao.model.ModelConstants;
+import java.util.UUID;
@Slf4j
public class BasePluginServiceTest extends AbstractServiceTest {
diff --git a/dao/src/test/java/org/thingsboard/server/dao/rule/BaseRuleServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/rule/BaseRuleServiceTest.java
index f62f26c..fe40b84 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/rule/BaseRuleServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/rule/BaseRuleServiceTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.rule;
-import com.datastax.driver.core.utils.UUIDs;
import org.junit.Assert;
import org.junit.Test;
import org.thingsboard.server.common.data.id.TenantId;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java
index f66e6ee..01de94f 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/CustomerServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/CustomerServiceImplTest.java
index fd0b20f..67ff8b0 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/CustomerServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/CustomerServiceImplTest.java
@@ -15,23 +15,21 @@
*/
package org.thingsboard.server.dao.service;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
import org.thingsboard.server.dao.exception.DataValidationException;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import com.datastax.driver.core.utils.UUIDs;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
public class CustomerServiceImplTest extends AbstractServiceTest {
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/DashboardServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/DashboardServiceImplTest.java
index 949198c..95f9430 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/DashboardServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/DashboardServiceImplTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
import org.junit.Assert;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsCacheTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsCacheTest.java
index 6dfa3bb..f9068ed 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsCacheTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsCacheTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import com.hazelcast.core.HazelcastInstance;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
@@ -36,7 +35,6 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.device.DeviceCredentialsDao;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceService;
-import org.thingsboard.server.dao.model.DeviceCredentialsEntity;
import java.util.UUID;
@@ -140,9 +138,8 @@ public class DeviceCredentialsCacheTest extends AbstractServiceTest {
return null;
}
- private DeviceCredentialsEntity createDummyDeviceCredentialsEntity(String deviceCredentialsId) {
- DeviceCredentialsEntity result = new DeviceCredentialsEntity();
- result.setId(UUIDs.timeBased());
+ private DeviceCredentials createDummyDeviceCredentialsEntity(String deviceCredentialsId) {
+ DeviceCredentials result = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased()));
result.setCredentialsId(deviceCredentialsId);
return result;
}
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsServiceImplTest.java
index efdab8a..c31fd2b 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceCredentialsServiceImplTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
import org.junit.Assert;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceServiceImplTest.java
index e9113d4..8126bfa 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/DeviceServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/DeviceServiceImplTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
import org.junit.Assert;
@@ -25,8 +24,6 @@ import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.CustomerId;
-import org.thingsboard.server.common.data.id.DeviceCredentialsId;
-import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TextPageData;
import org.thingsboard.server.common.data.page.TextPageLink;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceImplTest.java
index 6345567..f779462 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceImplTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/WidgetTypeServiceImplTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/WidgetTypeServiceImplTest.java
index cf3fd4b..9c5fb64 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/service/WidgetTypeServiceImplTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/service/WidgetTypeServiceImplTest.java
@@ -15,7 +15,6 @@
*/
package org.thingsboard.server.dao.service;
-import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
@@ -23,7 +22,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.thingsboard.server.common.data.Tenant;
-import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
diff --git a/dao/src/test/java/org/thingsboard/server/dao/timeseries/TimeseriesServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/timeseries/TimeseriesServiceTest.java
index 134f471..49b77c2 100644
--- a/dao/src/test/java/org/thingsboard/server/dao/timeseries/TimeseriesServiceTest.java
+++ b/dao/src/test/java/org/thingsboard/server/dao/timeseries/TimeseriesServiceTest.java
@@ -15,21 +15,14 @@
*/
package org.thingsboard.server.dao.timeseries;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.ResultSetFuture;
-import com.datastax.driver.core.utils.UUIDs;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
+import org.junit.Test;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.id.DeviceId;
-import org.thingsboard.server.dao.service.AbstractServiceTest;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.thingsboard.server.common.data.kv.*;
+import org.thingsboard.server.dao.service.AbstractServiceTest;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
pom.xml 5(+5 -0)
diff --git a/pom.xml b/pom.xml
index 6324712..64017d7 100755
--- a/pom.xml
+++ b/pom.xml
@@ -412,6 +412,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <version>${spring-boot.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>