Enum persistence changed to string

This commit is contained in:
mp-loki 2017-05-25 22:13:03 -04:00
parent 60e44725c3
commit e37e436978
14 changed files with 54 additions and 50 deletions

View File

@ -58,9 +58,11 @@ public final class AlarmEntity implements BaseEntity<Alarm> {
@Column(name = ALARM_TYPE_PROPERTY)
private String type;
@Enumerated(EnumType.STRING)
@Column(name = ALARM_SEVERITY_PROPERTY)
private AlarmSeverity severity;
@Enumerated(EnumType.STRING)
@Column(name = ALARM_STATUS_PROPERTY)
private AlarmStatus status;

View File

@ -15,11 +15,8 @@
*/
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 javax.persistence.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
@ -50,9 +47,11 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
@Column(name = ModelConstants.ID_PROPERTY)
private UUID id;
@Enumerated(EnumType.STRING)
@Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY)
private ComponentType type;
@Enumerated(EnumType.STRING)
@Column(name = ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY)
private ComponentScope scope;

View File

@ -16,11 +16,8 @@
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 javax.persistence.*;
import lombok.Data;
import org.thingsboard.server.common.data.id.DeviceCredentialsId;
@ -45,7 +42,8 @@ public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentia
@Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
private UUID deviceId;
@Enumerated(EnumType.STRING)
@Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY)
private DeviceCredentialsType credentialsType;

View File

@ -16,11 +16,9 @@
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 javax.persistence.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
@ -56,6 +54,7 @@ public class EventEntity implements BaseEntity<Event> {
@Column(name = EVENT_TENANT_ID_PROPERTY)
private UUID tenantId;
@Enumerated(EnumType.STRING)
@Column(name = EVENT_ENTITY_TYPE_PROPERTY)
private EntityType entityType;

View File

@ -16,11 +16,9 @@
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 javax.persistence.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
@ -66,6 +64,7 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> {
@Column(name = ModelConstants.PLUGIN_ACCESS_PROPERTY)
private boolean publicAccess;
@Enumerated(EnumType.STRING)
@Column(name = ModelConstants.PLUGIN_STATE_PROPERTY)
private ComponentLifecycleState state;

View File

@ -17,11 +17,7 @@ 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 javax.persistence.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -53,27 +49,38 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> {
@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;
@Enumerated(EnumType.STRING)
@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;
@Type(type = "jsonb")
@Column(name = ModelConstants.RULE_FILTERS, columnDefinition = "jsonb")
private JsonNode filters;
@Type(type = "jsonb")
@Column(name = ModelConstants.RULE_PROCESSOR, columnDefinition = "jsonb")
private JsonNode processor;
@Type(type = "jsonb")
@Column(name = ModelConstants.RULE_ACTION, columnDefinition = "jsonb")
private JsonNode action;
@Type(type = "jsonb")
@Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY, columnDefinition = "jsonb")
private JsonNode additionalInfo;

View File

@ -56,6 +56,7 @@ public class UserEntity implements SearchTextEntity<User> {
@Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY)
private UUID customerId;
@Enumerated(EnumType.STRING)
@Column(name = ModelConstants.USER_AUTHORITY_PROPERTY)
private Authority authority;

View File

@ -39,22 +39,22 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD
@Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
"ORDER BY ID LIMIT ?1")
List<ComponentDescriptorEntity> findByTypeFirstPage(int limit, int type, String textSearch);
List<ComponentDescriptorEntity> findByTypeFirstPage(int limit, String type, String textSearch);
@Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
"AND ID > ?4 ORDER BY ID LIMIT ?1")
List<ComponentDescriptorEntity> findByTypeNextPage(int limit, int type, String textSearch, UUID idOffset);
List<ComponentDescriptorEntity> findByTypeNextPage(int limit, String type, String textSearch, UUID idOffset);
@Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
"AND SCOPE = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
"ORDER BY ID LIMIT ?1")
List<ComponentDescriptorEntity> findByScopeAndTypeFirstPage(int limit, int type, int scope, String textSearch);
List<ComponentDescriptorEntity> findByScopeAndTypeFirstPage(int limit, String type, String scope, String textSearch);
@Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
"AND SCOPE = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
"AND ID > ?5 ORDER BY ID LIMIT ?1")
List<ComponentDescriptorEntity> findByScopeAndTypeNextPage(int limit, int type, int scope, String textSearch, UUID idOffset);
List<ComponentDescriptorEntity> findByScopeAndTypeNextPage(int limit, String type, String scope, String textSearch, UUID idOffset);
void deleteByClazz(String clazz);
}

View File

@ -78,10 +78,10 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
if (pageLink.getIdOffset() == null) {
return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeFirstPage(pageLink.getLimit(),
type.ordinal(), pageLink.getTextSearch()));
type.toString(), pageLink.getTextSearch()));
} else {
return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeNextPage(pageLink.getLimit(),
type.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset()));
type.toString(), pageLink.getTextSearch(), pageLink.getIdOffset()));
}
}
@ -89,10 +89,10 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
if (pageLink.getIdOffset() == null) {
return DaoUtil.convertDataList(componentDescriptorRepository.findByScopeAndTypeFirstPage(pageLink.getLimit(),
type.ordinal(), scope.ordinal(), pageLink.getTextSearch()));
type.toString(), scope.toString(), pageLink.getTextSearch()));
} else {
return DaoUtil.convertDataList(componentDescriptorRepository.findByScopeAndTypeNextPage(pageLink.getLimit(),
type.ordinal(), scope.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset()));
type.toString(), scope.toString(), pageLink.getTextSearch(), pageLink.getIdOffset()));
}
}

View File

@ -32,22 +32,22 @@ public interface UserRepository extends CrudRepository<UserEntity, UUID> {
UserEntity findByEmail(String email);
@Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
"AND CUSTOMER_ID IS NULL AND AUTHORITY = 1 " +
"AND CUSTOMER_ID IS NULL AND AUTHORITY = 'TENANT_ADMIN' " +
"ORDER BY ID LIMIT ?1")
List<UserEntity> findTenantAdminsFirstPage(int limit, UUID tenantId);
@Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
"AND CUSTOMER_ID IS NULL AND AUTHORITY = 1 " +
"AND CUSTOMER_ID IS NULL AND AUTHORITY = 'TENANT_ADMIN' " +
"AND ID > ?3 ORDER BY ID LIMIT ?1")
List<UserEntity> findTenantAdminsNextPage(int limit, UUID tenantId, UUID idOffset);
@Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
"AND CUSTOMER_ID = ?3 AND AUTHORITY = 2 " +
"AND CUSTOMER_ID = ?3 AND AUTHORITY = 'CUSTOMER_USER' " +
"ORDER BY ID LIMIT ?1")
List<UserEntity> findCustomerUsersFirstPage(int limit, UUID tenantId, UUID customerId);
@Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
"AND CUSTOMER_ID = ?3 AND AUTHORITY = 2 " +
"AND CUSTOMER_ID = ?3 AND AUTHORITY = 'CUSTOMER_USER' " +
"AND ID > ?4 ORDER BY ID LIMIT ?1")
List<UserEntity> findCustomerUsersNextPage(int limit, UUID tenantId, UUID customerId, UUID idOffset);

View File

@ -113,7 +113,6 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
userDao.save(user);
assertEquals(6, userDao.find().size());
User savedUser = userDao.findByEmail("user@thingsboard.org");
//User savedUser = userDao.findById(UUID.fromString("cd481534-27cc-11e7-93ae-92361f002671"));
assertNotNull(savedUser);
assertEquals(additionalInfo, savedUser.getAdditionalInfo().toString());
}

View File

@ -2,14 +2,14 @@
<device_credentials
id="958e3314-3215-11e7-93ae-92361f002671"
device_id="958e3a30-3215-11e7-93ae-92361f002671"
credentials_type="0"
credentials_type="ACCESS_TOKEN"
credentials_id="ID_1"
credentials_value="ACCESS_TOKEN_1"
/>
<device_credentials
id="958e3c74-3215-11e7-93ae-92361f002671"
device_id="958e3e5e-3215-11e7-93ae-92361f002671"
credentials_type="0"
credentials_type="ACCESS_TOKEN"
credentials_id="ID_2"
credentials_value="ACCESS_TOKEN_2"
/>

View File

@ -3,7 +3,7 @@
id="be41c7a2-31f5-11e7-9cfd-2786e6aa2046"
tenant_id="be41c7a0-31f5-11e7-9cfd-2786e6aa2046"
entity_id="be41c7a1-31f5-11e7-9cfd-2786e6aa2046"
entity_type="7"
entity_type="DEVICE"
event_type="STATS"
event_uid="be41c7a3-31f5-11e7-9cfd-2786e6aa2046"
/>
@ -11,7 +11,7 @@
id="be41c7a4-31f5-11e7-9cfd-2786e6aa2046"
tenant_id="be41c7a0-31f5-11e7-9cfd-2786e6aa2046"
entity_id="be41c7a1-31f5-11e7-9cfd-2786e6aa2046"
entity_type="7"
entity_type="DEVICE"
event_type="STATS"
event_uid="be41c7a5-31f5-11e7-9cfd-2786e6aa2046"
/>

View File

@ -2,7 +2,7 @@
<tb_user id="9cb58ba0-27c1-11e7-93ae-92361f002671"
tenant_id="c97ea14e-27c1-11e7-93ae-92361f002671"
customer_id="cdf9c79e-27c1-11e7-93ae-92361f002671"
authority="0"
authority="SYS_ADMIN"
email="sysadm@thingsboard.org"
search_text="SYSADM SEARCH TEXT"
first_name="John"
@ -10,7 +10,7 @@
/>
<tb_user id="1312f328-27c7-11e7-93ae-92361f002671"
tenant_id="1e1cd4c8-27c7-11e7-93ae-92361f002671"
authority="1"
authority="TENANT_ADMIN"
email="tenantadm1@thingsboard.org"
search_text="TENANTADM1 SEARCH TEXT"
first_name="Samuel"
@ -18,7 +18,7 @@
/>
<tb_user id="2b090dde-27ca-11e7-93ae-92361f002671"
tenant_id="1e1cd4c8-27c7-11e7-93ae-92361f002671"
authority="1"
authority="TENANT_ADMIN"
email="tenantadm2@thingsboard.org"
search_text="TENANTADM2 SEARCH TEXT"
first_name="Penny"
@ -27,7 +27,7 @@
<tb_user id="cc8c1ca8-27c7-11e7-93ae-92361f002671"
tenant_id="d2e27caa-27c7-11e7-93ae-92361f002671"
customer_id="d89e128a-27c7-11e7-93ae-92361f002671"
authority="2"
authority="CUSTOMER_USER"
email="customeruser@thingsboard.org"
search_text="CUSTOMER USER SEARCH TEXT"
first_name="Norman"
@ -36,10 +36,10 @@
<tb_user id="edb2de58-27c7-11e7-93ae-92361f002671"
tenant_id="f229675e-27c7-11e7-93ae-92361f002671"
customer_id="f7a3d4e4-27c7-11e7-93ae-92361f002671"
authority="3"
authority="REFRESH_TOKEN"
email="refreshtoken@thingsboard.org"
search_text="REFRESH TOKEN SEARCH TEXT"
first_name="Dianne"
last_name="Wensleydale"
first_name="Refresh"
last_name="Token"
/>
</dataset>