Search in sources :

Example 1 with DashboardInfo

use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.

the class BaseDashboardServiceTest method testFindDashboardsByTenantIdAndCustomerId.

@Test
public void testFindDashboardsByTenantIdAndCustomerId() throws ExecutionException, InterruptedException {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    CustomerId customerId = customer.getId();
    List<DashboardInfo> dashboards = new ArrayList<>();
    for (int i = 0; i < 223; i++) {
        Dashboard dashboard = new Dashboard();
        dashboard.setTenantId(tenantId);
        dashboard.setTitle("Dashboard" + i);
        dashboard = dashboardService.saveDashboard(dashboard);
        dashboards.add(new DashboardInfo(dashboardService.assignDashboardToCustomer(dashboard.getId(), customerId)));
    }
    List<DashboardInfo> loadedDashboards = new ArrayList<>();
    TimePageLink pageLink = new TimePageLink(23);
    TimePageData<DashboardInfo> pageData = null;
    do {
        pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
        loadedDashboards.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(dashboards, idComparator);
    Collections.sort(loadedDashboards, idComparator);
    Assert.assertEquals(dashboards, loadedDashboards);
    dashboardService.unassignCustomerDashboards(customerId);
    pageLink = new TimePageLink(42);
    pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 2 with DashboardInfo

use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.

the class JpaDashboardInfoDao method findDashboardsByTenantIdAndCustomerId.

@Override
public ListenableFuture<List<DashboardInfo>> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TimePageLink pageLink) {
    log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
    ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(new CustomerId(customerId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD, EntityType.DASHBOARD, pageLink);
    return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<DashboardInfo>>) input -> {
        List<ListenableFuture<DashboardInfo>> dashboardFutures = new ArrayList<>(input.size());
        for (EntityRelation relation : input) {
            dashboardFutures.add(findByIdAsync(relation.getTo().getId()));
        }
        return Futures.successfulAsList(dashboardFutures);
    });
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Time(java.sql.Time) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Autowired(org.springframework.beans.factory.annotation.Autowired) CrudRepository(org.springframework.data.repository.CrudRepository) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) ArrayList(java.util.ArrayList) NULL_UUID_STR(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR) EntityType(org.thingsboard.server.common.data.EntityType) SqlDao(org.thingsboard.server.dao.util.SqlDao) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) RelationDao(org.thingsboard.server.dao.relation.RelationDao) Objects(java.util.Objects) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) JpaAbstractSearchTextDao(org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao) List(java.util.List) DaoUtil(org.thingsboard.server.dao.DaoUtil) DashboardInfoDao(org.thingsboard.server.dao.dashboard.DashboardInfoDao) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) UUIDConverter(org.thingsboard.server.common.data.UUIDConverter) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) DashboardInfoEntity(org.thingsboard.server.dao.model.sql.DashboardInfoEntity) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) ArrayList(java.util.ArrayList) List(java.util.List) CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo)

Example 3 with DashboardInfo

use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.

the class CassandraDashboardInfoDao method findDashboardsByTenantIdAndCustomerId.

@Override
public ListenableFuture<List<DashboardInfo>> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TimePageLink pageLink) {
    log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink);
    ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(new CustomerId(customerId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD, EntityType.DASHBOARD, pageLink);
    return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<DashboardInfo>>) input -> {
        List<ListenableFuture<DashboardInfo>> dashboardFutures = new ArrayList<>(input.size());
        for (EntityRelation relation : input) {
            dashboardFutures.add(findByIdAsync(relation.getTo().getId()));
        }
        return Futures.successfulAsList(dashboardFutures);
    });
}
Also used : DashboardInfoEntity(org.thingsboard.server.dao.model.nosql.DashboardInfoEntity) CassandraAbstractSearchTextDao(org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) QueryBuilder.eq(com.datastax.driver.core.querybuilder.QueryBuilder.eq) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) NoSqlDao(org.thingsboard.server.dao.util.NoSqlDao) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) ArrayList(java.util.ArrayList) RelationDao(org.thingsboard.server.dao.relation.RelationDao) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) EntityType(org.thingsboard.server.common.data.EntityType) DaoUtil(org.thingsboard.server.dao.DaoUtil) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) Collections(java.util.Collections) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) ArrayList(java.util.ArrayList) List(java.util.List) CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo)

Example 4 with DashboardInfo

use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.

the class DashboardInfoEntity method toData.

@Override
public DashboardInfo toData() {
    DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(getId()));
    dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(getId()));
    if (tenantId != null) {
        dashboardInfo.setTenantId(new TenantId(toUUID(tenantId)));
    }
    dashboardInfo.setTitle(title);
    if (!StringUtils.isEmpty(assignedCustomers)) {
        try {
            dashboardInfo.setAssignedCustomers(objectMapper.readValue(assignedCustomers, assignedCustomersType));
        } catch (IOException e) {
            log.warn("Unable to parse assigned customers!", e);
        }
    }
    return dashboardInfo;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) IOException(java.io.IOException) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo)

Example 5 with DashboardInfo

use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.

the class JpaDashboardInfoDaoTest method testFindDashboardsByTenantId.

@Test
public void testFindDashboardsByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    for (int i = 0; i < 20; i++) {
        createDashboard(tenantId1, i);
        createDashboard(tenantId2, i * 2);
    }
    TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD");
    List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink1);
    Assert.assertEquals(15, dashboardInfos1.size());
    TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null);
    List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink2);
    Assert.assertEquals(5, dashboardInfos2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) UUID(java.util.UUID) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Aggregations

DashboardInfo (org.thingsboard.server.common.data.DashboardInfo)9 ArrayList (java.util.ArrayList)5 TenantId (org.thingsboard.server.common.data.id.TenantId)5 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)5 Test (org.junit.Test)4 UUID (java.util.UUID)3 Dashboard (org.thingsboard.server.common.data.Dashboard)3 CustomerId (org.thingsboard.server.common.data.id.CustomerId)3 DashboardId (org.thingsboard.server.common.data.id.DashboardId)3 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)3 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 IOException (java.io.IOException)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 EntityType (org.thingsboard.server.common.data.EntityType)2 Tenant (org.thingsboard.server.common.data.Tenant)2