Search in sources :

Example 51 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BasePluginService method findSystemPlugins.

@Override
public List<PluginMetaData> findSystemPlugins() {
    log.trace("Executing findSystemPlugins");
    List<PluginMetaData> plugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(300);
    TextPageData<PluginMetaData> pageData = null;
    do {
        pageData = findSystemPlugins(pageLink);
        plugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return plugins;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList)

Example 52 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BasePluginService method findAllTenantPluginsByTenantId.

@Override
public List<PluginMetaData> findAllTenantPluginsByTenantId(TenantId tenantId) {
    log.trace("Executing findAllTenantPluginsByTenantId, tenantId [{}]", tenantId);
    Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
    List<PluginMetaData> plugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(300);
    TextPageData<PluginMetaData> pageData = null;
    do {
        pageData = findAllTenantPluginsByTenantIdAndPageLink(tenantId, pageLink);
        plugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return plugins;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList)

Example 53 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseCustomerServiceTest method testFindCustomersByTenantIdAndTitle.

@Test
public void testFindCustomersByTenantIdAndTitle() {
    String title1 = "Customer title 1";
    List<Customer> customersTitle1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        Customer customer = new Customer();
        customer.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title1 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        customer.setTitle(title);
        customersTitle1.add(customerService.saveCustomer(customer));
    }
    String title2 = "Customer title 2";
    List<Customer> customersTitle2 = new ArrayList<>();
    for (int i = 0; i < 175; i++) {
        Customer customer = new Customer();
        customer.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title2 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        customer.setTitle(title);
        customersTitle2.add(customerService.saveCustomer(customer));
    }
    List<Customer> loadedCustomersTitle1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(15, title1);
    TextPageData<Customer> pageData = null;
    do {
        pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
        loadedCustomersTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customersTitle1, idComparator);
    Collections.sort(loadedCustomersTitle1, idComparator);
    Assert.assertEquals(customersTitle1, loadedCustomersTitle1);
    List<Customer> loadedCustomersTitle2 = new ArrayList<>();
    pageLink = new TextPageLink(4, title2);
    do {
        pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
        loadedCustomersTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customersTitle2, idComparator);
    Collections.sort(loadedCustomersTitle2, idComparator);
    Assert.assertEquals(customersTitle2, loadedCustomersTitle2);
    for (Customer customer : loadedCustomersTitle1) {
        customerService.deleteCustomer(customer.getId());
    }
    pageLink = new TextPageLink(4, title1);
    pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Customer customer : loadedCustomersTitle2) {
        customerService.deleteCustomer(customer.getId());
    }
    pageLink = new TextPageLink(4, title2);
    pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 54 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink 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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 55 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink 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());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Aggregations

TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)93 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)58 TenantId (org.thingsboard.server.common.data.id.TenantId)37 TypeReference (com.fasterxml.jackson.core.type.TypeReference)27 Tenant (org.thingsboard.server.common.data.Tenant)24 CustomerId (org.thingsboard.server.common.data.id.CustomerId)19 Customer (org.thingsboard.server.common.data.Customer)18 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)18 UUID (java.util.UUID)15 Asset (org.thingsboard.server.common.data.asset.Asset)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 User (org.thingsboard.server.common.data.User)13 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)11 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)11 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)11 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)10 Device (org.thingsboard.server.common.data.Device)7