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);
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations