20 changed files with 737 additions and 265 deletions
@ -0,0 +1,45 @@ |
|||
package org.thingsboard.server.dao.sql.component; |
|||
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.plugin.ComponentScope; |
|||
import org.thingsboard.server.common.data.plugin.ComponentType; |
|||
import org.thingsboard.server.dao.model.ToData; |
|||
import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
|||
|
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public interface ComponentDescriptorRepository extends CrudRepository<ComponentDescriptorEntity, UUID> { |
|||
|
|||
ComponentDescriptorEntity findByClazz(String clazz); |
|||
|
|||
@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); |
|||
|
|||
@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); |
|||
|
|||
@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); |
|||
|
|||
@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); |
|||
|
|||
void deleteByClazz(String clazz); |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
package org.thingsboard.server.dao.sql.component; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
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.DaoUtil; |
|||
import org.thingsboard.server.dao.component.ComponentDescriptorDao; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@Component |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> |
|||
implements ComponentDescriptorDao { |
|||
|
|||
@Autowired |
|||
private ComponentDescriptorRepository componentDescriptorRepository; |
|||
|
|||
@Override |
|||
protected Class<ComponentDescriptorEntity> getEntityClass() { |
|||
return ComponentDescriptorEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<ComponentDescriptorEntity, UUID> getCrudRepository() { |
|||
return componentDescriptorRepository; |
|||
} |
|||
|
|||
@Override |
|||
public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) { |
|||
boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null; |
|||
if (exists) { |
|||
return Optional.empty(); |
|||
} |
|||
return Optional.of(save(component)); |
|||
} |
|||
|
|||
@Override |
|||
public ComponentDescriptor findById(ComponentDescriptorId componentId) { |
|||
return findById(componentId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public ComponentDescriptor findByClazz(String clazz) { |
|||
return DaoUtil.getData(componentDescriptorRepository.findByClazz(clazz)); |
|||
} |
|||
|
|||
@Override |
|||
public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) { |
|||
if (pageLink.getIdOffset() == null) { |
|||
return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeFirstPage(pageLink.getLimit(), |
|||
type.ordinal(), pageLink.getTextSearch())); |
|||
} else { |
|||
return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeNextPage(pageLink.getLimit(), |
|||
type.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset())); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
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())); |
|||
} else { |
|||
return DaoUtil.convertDataList(componentDescriptorRepository.findByScopeAndTypeNextPage(pageLink.getLimit(), |
|||
type.ordinal(), scope.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset())); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void deleteById(ComponentDescriptorId componentId) { |
|||
removeById(componentId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteByClazz(String clazz) { |
|||
componentDescriptorRepository.deleteByClazz(clazz); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
package org.thingsboard.server.dao.sql.customer; |
|||
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.dao.model.sql.CustomerEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public interface CustomerRepository extends CrudRepository<CustomerEntity, UUID> { |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?2 " + |
|||
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + |
|||
"ORDER BY ID LIMIT ?1") |
|||
List<CustomerEntity> findByTenantIdFirstPage(int limit, UUID tenantId, String textSearch); |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?2 " + |
|||
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + |
|||
"AND ID > ?4 ORDER BY ID LIMIT ?1") |
|||
List<CustomerEntity> findByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?1") |
|||
List<CustomerEntity> findByTenantId(UUID tenantId); |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
package org.thingsboard.server.dao.sql.customer; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.customer.CustomerDao; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.sql.CustomerEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@Component |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao{ |
|||
|
|||
@Autowired |
|||
private CustomerRepository customerRepository; |
|||
|
|||
@Override |
|||
protected Class<CustomerEntity> getEntityClass() { |
|||
return CustomerEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<CustomerEntity, UUID> getCrudRepository() { |
|||
return customerRepository; |
|||
} |
|||
|
|||
@Override |
|||
public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
if (pageLink.getIdOffset() == null) { |
|||
return DaoUtil.convertDataList(customerRepository.findByTenantIdFirstPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch())); |
|||
} else { |
|||
return DaoUtil.convertDataList(customerRepository.findByTenantIdNextPage(pageLink.getLimit(), tenantId, |
|||
pageLink.getTextSearch(), pageLink.getIdOffset())); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
package org.thingsboard.server.dao.sql.dashboard; |
|||
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public interface DashboardInfoRepository extends CrudRepository<DashboardInfoEntity, UUID> { |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " + |
|||
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + |
|||
"ORDER BY ID LIMIT ?1") |
|||
List<DashboardInfoEntity> findByTenantIdFirstPage(int limit, UUID tenantId, String textSearch); |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " + |
|||
"AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + |
|||
"AND ID > ?4 ORDER BY ID LIMIT ?1") |
|||
List<DashboardInfoEntity> findByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " + |
|||
"AND CUSTOMER_ID = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " + |
|||
"ORDER BY ID LIMIT ?1") |
|||
List<DashboardInfoEntity> findByTenantIdAndCustomerIdFirstPage(int limit, UUID tenantId, UUID customerId, String textSearch); |
|||
|
|||
@Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " + |
|||
"AND CUSTOMER_ID = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " + |
|||
"AND ID > ?5 ORDER BY ID LIMIT ?1") |
|||
List<DashboardInfoEntity> findByTenantIdAndCustomerIdNextPage(int limit, UUID tenantId, UUID customerId, String textSearch, UUID idOffset); |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package org.thingsboard.server.dao.sql.dashboard; |
|||
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.dao.model.sql.DashboardEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> { |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
package org.thingsboard.server.dao.sql.dashboard; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.dao.dashboard.DashboardDao; |
|||
import org.thingsboard.server.dao.model.sql.DashboardEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@Component |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao { |
|||
|
|||
@Autowired |
|||
DashboardRepository dashboardRepository; |
|||
|
|||
@Override |
|||
protected Class<DashboardEntity> getEntityClass() { |
|||
return DashboardEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DASHBOARD_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<DashboardEntity, UUID> getCrudRepository() { |
|||
return dashboardRepository; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
package org.thingsboard.server.dao.sql.dashboard; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DashboardInfo; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.dashboard.DashboardInfoDao; |
|||
import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
@Component |
|||
@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
|||
public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { |
|||
|
|||
@Autowired |
|||
private DashboardInfoRepository dashboardInfoRepository; |
|||
|
|||
@Override |
|||
protected Class getEntityClass() { |
|||
return DashboardInfoEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DASHBOARD_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository getCrudRepository() { |
|||
return dashboardInfoRepository; |
|||
} |
|||
|
|||
@Override |
|||
public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
if (pageLink.getIdOffset() == null) { |
|||
return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdFirstPage( |
|||
pageLink.getLimit(), tenantId, pageLink.getTextSearch())); |
|||
} else { |
|||
return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdNextPage( |
|||
pageLink.getLimit(), tenantId, pageLink.getTextSearch(), pageLink.getIdOffset())); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
|||
if (pageLink.getIdOffset() == null) { |
|||
return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdAndCustomerIdFirstPage( |
|||
pageLink.getLimit(), tenantId, customerId, pageLink.getTextSearch())); |
|||
} else { |
|||
return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdAndCustomerIdNextPage( |
|||
pageLink.getLimit(), tenantId, customerId, pageLink.getTextSearch(), pageLink.getIdOffset())); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package org.thingsboard.server.dao.sql.settings; |
|||
|
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.dao.model.ToData; |
|||
import org.thingsboard.server.dao.model.sql.AdminSettingsEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
public interface AdminSettingsRepository extends CrudRepository<AdminSettingsEntity, UUID> { |
|||
|
|||
AdminSettingsEntity findByKey(String key); |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
package org.thingsboard.server.dao.sql.settings; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.common.data.AdminSettings; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.AdminSettingsEntity; |
|||
import org.thingsboard.server.dao.settings.AdminSettingsDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{ |
|||
|
|||
@Autowired |
|||
private AdminSettingsRepository adminSettingsRepository; |
|||
|
|||
@Override |
|||
protected Class<AdminSettingsEntity> getEntityClass() { |
|||
return AdminSettingsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<AdminSettingsEntity, UUID> getCrudRepository() { |
|||
return adminSettingsRepository; |
|||
} |
|||
|
|||
@Override |
|||
public AdminSettings findByKey(String key) { |
|||
return DaoUtil.getData(adminSettingsRepository.findByKey(key)); |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
package org.thingsboard.server.dao.sql.component; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import org.junit.Test; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
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.AbstractJpaDaoTest; |
|||
import org.thingsboard.server.dao.component.ComponentDescriptorDao; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static org.junit.Assert.assertEquals; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
public class JpaBaseComponentDescriptorDaoTest extends AbstractJpaDaoTest { |
|||
|
|||
@Autowired |
|||
private ComponentDescriptorDao componentDescriptorDao; |
|||
|
|||
@Test |
|||
public void findByType() { |
|||
for (int i = 0; i < 20; i++) { |
|||
createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i); |
|||
createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20); |
|||
} |
|||
|
|||
TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_"); |
|||
List<ComponentDescriptor> components1 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink1); |
|||
assertEquals(15, components1.size()); |
|||
|
|||
TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null); |
|||
List<ComponentDescriptor> components2 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink2); |
|||
assertEquals(5, components2.size()); |
|||
} |
|||
|
|||
@Test |
|||
public void findByTypeAndSocpe() { |
|||
for (int i = 0; i < 20; i++) { |
|||
createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i); |
|||
createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20); |
|||
createComponentDescriptor(ComponentType.FILTER, ComponentScope.SYSTEM, i + 40); |
|||
} |
|||
|
|||
TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_"); |
|||
List<ComponentDescriptor> components1 = componentDescriptorDao.findByScopeAndTypeAndPageLink( |
|||
ComponentScope.SYSTEM, ComponentType.FILTER, pageLink1); |
|||
assertEquals(15, components1.size()); |
|||
|
|||
TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null); |
|||
List<ComponentDescriptor> components2 = componentDescriptorDao.findByScopeAndTypeAndPageLink( |
|||
ComponentScope.SYSTEM, ComponentType.FILTER, pageLink2); |
|||
assertEquals(5, components2.size()); |
|||
} |
|||
|
|||
private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) { |
|||
ComponentDescriptor component = new ComponentDescriptor(); |
|||
component.setId(new ComponentDescriptorId(UUIDs.timeBased())); |
|||
component.setType(type); |
|||
component.setScope(scope); |
|||
component.setName("COMPONENT_" + index); |
|||
componentDescriptorDao.save(component); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
package org.thingsboard.server.dao.sql.customer; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import org.junit.Test; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
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.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.AbstractJpaDaoTest; |
|||
import org.thingsboard.server.dao.customer.CustomerDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static org.junit.Assert.assertEquals; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
public class JpaCustomerDaoTest extends AbstractJpaDaoTest { |
|||
|
|||
@Autowired |
|||
private CustomerDao customerDao; |
|||
|
|||
@Test |
|||
public void testFindByTenantId() { |
|||
UUID tenantId1 = UUIDs.timeBased(); |
|||
UUID tenantId2 = UUIDs.timeBased(); |
|||
|
|||
for (int i = 0; i < 20; i++) { |
|||
createCustomer(tenantId1, i); |
|||
createCustomer(tenantId2, i * 2); |
|||
} |
|||
|
|||
TextPageLink pageLink1 = new TextPageLink(15, "CUSTOMER"); |
|||
List<Customer> customers1 = customerDao.findCustomersByTenantId(tenantId1, pageLink1); |
|||
assertEquals(15, customers1.size()); |
|||
|
|||
TextPageLink pageLink2 = new TextPageLink(15, "CUSTOMER", customers1.get(14).getId().getId(), null); |
|||
List<Customer> customers2 = customerDao.findCustomersByTenantId(tenantId1, pageLink2); |
|||
assertEquals(5, customers2.size()); |
|||
} |
|||
|
|||
private void createCustomer(UUID tenantId, int index) { |
|||
Customer customer = new Customer(); |
|||
customer.setId(new CustomerId(UUIDs.timeBased())); |
|||
customer.setTenantId(new TenantId(tenantId)); |
|||
customer.setTitle("CUSTOMER_" + index); |
|||
customerDao.save(customer); |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
package org.thingsboard.server.dao.sql.dashboard; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import org.junit.Test; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
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.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.AbstractJpaDaoTest; |
|||
import org.thingsboard.server.dao.dashboard.DashboardInfoDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 5/6/2017. |
|||
*/ |
|||
public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest { |
|||
|
|||
@Autowired |
|||
private DashboardInfoDao dashboardInfoDao; |
|||
|
|||
@Test |
|||
public void testFindDashboardsByTenantId() { |
|||
UUID tenantId1 = UUIDs.timeBased(); |
|||
UUID customerId1 = UUIDs.timeBased(); |
|||
UUID tenantId2 = UUIDs.timeBased(); |
|||
UUID customerId2 = UUIDs.timeBased(); |
|||
|
|||
for (int i = 0; i < 20; i++) { |
|||
createDashboard(tenantId1, customerId1, i); |
|||
createDashboard(tenantId2, customerId2, i * 2); |
|||
} |
|||
|
|||
TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD"); |
|||
List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink1); |
|||
assertEquals(15, dashboardInfos1.size()); |
|||
|
|||
TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null); |
|||
List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink2); |
|||
assertEquals(5, dashboardInfos2.size()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDashboardsByTenantAndCustomerId() { |
|||
UUID tenantId1 = UUIDs.timeBased(); |
|||
UUID customerId1 = UUIDs.timeBased(); |
|||
UUID tenantId2 = UUIDs.timeBased(); |
|||
UUID customerId2 = UUIDs.timeBased(); |
|||
|
|||
for (int i = 0; i < 20; i++) { |
|||
createDashboard(tenantId1, customerId1, i); |
|||
createDashboard(tenantId2, customerId2, i * 2); |
|||
} |
|||
|
|||
TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD"); |
|||
List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink1); |
|||
assertEquals(15, dashboardInfos1.size()); |
|||
|
|||
TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null); |
|||
List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink2); |
|||
assertEquals(5, dashboardInfos2.size()); |
|||
} |
|||
|
|||
private void assertEquals(int i, int size) { |
|||
} |
|||
|
|||
private void createDashboard(UUID tenantId, UUID customerId, int index) { |
|||
DashboardInfo dashboardInfo = new DashboardInfo(); |
|||
dashboardInfo.setId(new DashboardId(UUIDs.timeBased())); |
|||
dashboardInfo.setTenantId(new TenantId(tenantId)); |
|||
dashboardInfo.setCustomerId(new CustomerId(customerId)); |
|||
dashboardInfo.setTitle("DASHBOARD_" + index); |
|||
dashboardInfoDao.save(dashboardInfo); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue