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(id));
dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id));
if (tenantId != null) {
dashboardInfo.setTenantId(new TenantId(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;
}
use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.
the class BaseDashboardServiceTest method testFindDashboardsByTenantId.
@Test
public void testFindDashboardsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<DashboardInfo> dashboards = new ArrayList<>();
for (int i = 0; i < 165; i++) {
Dashboard dashboard = new Dashboard();
dashboard.setTenantId(tenantId);
dashboard.setTitle("Dashboard" + i);
dashboards.add(new DashboardInfo(dashboardService.saveDashboard(dashboard)));
}
List<DashboardInfo> loadedDashboards = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(16);
TextPageData<DashboardInfo> pageData = null;
do {
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
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.deleteDashboardsByTenantId(tenantId);
pageLink = new TextPageLink(31);
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.
the class BaseDashboardServiceTest method testFindDashboardsByTenantIdAndTitle.
@Test
public void testFindDashboardsByTenantIdAndTitle() {
String title1 = "Dashboard title 1";
List<DashboardInfo> dashboardsTitle1 = new ArrayList<>();
for (int i = 0; i < 123; i++) {
Dashboard dashboard = new Dashboard();
dashboard.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 17));
String title = title1 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
dashboard.setTitle(title);
dashboardsTitle1.add(new DashboardInfo(dashboardService.saveDashboard(dashboard)));
}
String title2 = "Dashboard title 2";
List<DashboardInfo> dashboardsTitle2 = new ArrayList<>();
for (int i = 0; i < 193; i++) {
Dashboard dashboard = new Dashboard();
dashboard.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 15));
String title = title2 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
dashboard.setTitle(title);
dashboardsTitle2.add(new DashboardInfo(dashboardService.saveDashboard(dashboard)));
}
List<DashboardInfo> loadedDashboardsTitle1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(19, title1);
TextPageData<DashboardInfo> pageData = null;
do {
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
loadedDashboardsTitle1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(dashboardsTitle1, idComparator);
Collections.sort(loadedDashboardsTitle1, idComparator);
Assert.assertEquals(dashboardsTitle1, loadedDashboardsTitle1);
List<DashboardInfo> loadedDashboardsTitle2 = new ArrayList<>();
pageLink = new TextPageLink(4, title2);
do {
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
loadedDashboardsTitle2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(dashboardsTitle2, idComparator);
Collections.sort(loadedDashboardsTitle2, idComparator);
Assert.assertEquals(dashboardsTitle2, loadedDashboardsTitle2);
for (DashboardInfo dashboard : loadedDashboardsTitle1) {
dashboardService.deleteDashboard(dashboard.getId());
}
pageLink = new TextPageLink(4, title1);
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (DashboardInfo dashboard : loadedDashboardsTitle2) {
dashboardService.deleteDashboard(dashboard.getId());
}
pageLink = new TextPageLink(4, title2);
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.DashboardInfo in project thingsboard by thingsboard.
the class JpaDashboardInfoDaoTest method createDashboard.
private void createDashboard(UUID tenantId, int index) {
DashboardInfo dashboardInfo = new DashboardInfo();
dashboardInfo.setId(new DashboardId(UUIDs.timeBased()));
dashboardInfo.setTenantId(new TenantId(tenantId));
dashboardInfo.setTitle("DASHBOARD_" + index);
dashboardInfoDao.save(dashboardInfo);
}
Aggregations