Search in sources :

Example 1 with Dashboard

use of org.thingsboard.server.common.data.Dashboard 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 Dashboard

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

the class BaseDashboardServiceTest method testAssignDashboardToNonExistentCustomer.

@Test(expected = DataValidationException.class)
public void testAssignDashboardToNonExistentCustomer() {
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("My dashboard");
    dashboard.setTenantId(tenantId);
    dashboard = dashboardService.saveDashboard(dashboard);
    try {
        dashboardService.assignDashboardToCustomer(dashboard.getId(), new CustomerId(UUIDs.timeBased()));
    } finally {
        dashboardService.deleteDashboard(dashboard.getId());
    }
}
Also used : Dashboard(org.thingsboard.server.common.data.Dashboard) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Example 3 with Dashboard

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

the class BaseDashboardServiceTest method testAssignDashboardToCustomerFromDifferentTenant.

@Test(expected = DataValidationException.class)
public void testAssignDashboardToCustomerFromDifferentTenant() {
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("My dashboard");
    dashboard.setTenantId(tenantId);
    dashboard = dashboardService.saveDashboard(dashboard);
    Tenant tenant = new Tenant();
    tenant.setTitle("Test different tenant");
    tenant = tenantService.saveTenant(tenant);
    Customer customer = new Customer();
    customer.setTenantId(tenant.getId());
    customer.setTitle("Test different customer");
    customer = customerService.saveCustomer(customer);
    try {
        dashboardService.assignDashboardToCustomer(dashboard.getId(), customer.getId());
    } finally {
        dashboardService.deleteDashboard(dashboard.getId());
        tenantService.deleteTenant(tenant.getId());
    }
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) Dashboard(org.thingsboard.server.common.data.Dashboard) Test(org.junit.Test)

Example 4 with Dashboard

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

the class DashboardEntity method toData.

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

Example 5 with Dashboard

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

the class DashboardEntity method toData.

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

Aggregations

Dashboard (org.thingsboard.server.common.data.Dashboard)13 Test (org.junit.Test)11 TenantId (org.thingsboard.server.common.data.id.TenantId)5 ArrayList (java.util.ArrayList)3 DashboardInfo (org.thingsboard.server.common.data.DashboardInfo)3 Tenant (org.thingsboard.server.common.data.Tenant)3 IOException (java.io.IOException)2 Customer (org.thingsboard.server.common.data.Customer)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DashboardId (org.thingsboard.server.common.data.id.DashboardId)2 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)2 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)1