Search in sources :

Example 86 with TextPageLink

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

the class BaseDeviceControllerTest method testFindCustomerDevices.

@Test
public void testFindCustomerDevices() throws Exception {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = customer.getId();
    List<Device> devices = new ArrayList<>();
    for (int i = 0; i < 128; i++) {
        Device device = new Device();
        device.setName("Device" + i);
        device.setType("default");
        device = doPost("/api/device", device, Device.class);
        devices.add(doPost("/api/customer/" + customerId.getId().toString() + "/device/" + device.getId().getId().toString(), Device.class));
    }
    List<Device> loadedDevices = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Device> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/devices?", new TypeReference<TextPageData<Device>>() {
        }, pageLink);
        loadedDevices.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devices, idComparator);
    Collections.sort(loadedDevices, idComparator);
    Assert.assertEquals(devices, loadedDevices);
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 87 with TextPageLink

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

the class BasePluginControllerTest method testPluginsCreation.

private List<PluginMetaData> testPluginsCreation(String url) throws Exception {
    List<PluginMetaData> plugins = new ArrayList<>();
    for (int i = 0; i < 111; i++) {
        PluginMetaData plugin = new PluginMetaData();
        plugin.setName("My plugin");
        plugin.setApiToken("myplugin" + i);
        plugin.setConfiguration(mapper.readTree("{}"));
        plugin.setClazz(TelemetryStoragePlugin.class.getName());
        plugins.add(doPost("/api/plugin", plugin, PluginMetaData.class));
    }
    List<PluginMetaData> loadedPlugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<PluginMetaData> pageData;
    do {
        pageData = doGetTypedWithPageLink(url + "?", new TypeReference<TextPageData<PluginMetaData>>() {
        }, pageLink);
        loadedPlugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    loadedPlugins = loadedPlugins.stream().filter(p -> !p.getName().equals("System Telemetry Plugin")).filter(p -> !p.getName().equals("Mail Sender Plugin")).filter(p -> !p.getName().equals("System RPC Plugin")).collect(Collectors.toList());
    Collections.sort(plugins, idComparator);
    Collections.sort(loadedPlugins, idComparator);
    Assert.assertEquals(plugins, loadedPlugins);
    return loadedPlugins;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tenant(org.thingsboard.server.common.data.Tenant) Test(org.junit.Test) TextPageData(org.thingsboard.server.common.data.page.TextPageData) Authority(org.thingsboard.server.common.data.security.Authority) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) User(org.thingsboard.server.common.data.User) List(java.util.List) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) After(org.junit.After) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Assert(org.junit.Assert) Collections(java.util.Collections) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Before(org.junit.Before) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 88 with TextPageLink

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

the class BaseRuleControllerTest method testRulesCreation.

private List<RuleMetaData> testRulesCreation(String url, PluginMetaData plugin) throws Exception {
    List<RuleMetaData> rules = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        RuleMetaData rule = createRuleMetaData(plugin);
        rule.setPluginToken(plugin.getApiToken());
        rule.setName(rule.getName() + i);
        rules.add(doPost("/api/rule", rule, RuleMetaData.class));
    }
    List<RuleMetaData> loadedRules = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(3);
    TextPageData<RuleMetaData> pageData;
    do {
        pageData = doGetTypedWithPageLink(url + "?", new TypeReference<TextPageData<RuleMetaData>>() {
        }, pageLink);
        loadedRules.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    loadedRules = loadedRules.stream().filter(p -> !p.getName().equals("System Telemetry Rule")).collect(Collectors.toList());
    Collections.sort(rules, idComparator);
    Collections.sort(loadedRules, idComparator);
    Assert.assertEquals(rules, loadedRules);
    return loadedRules;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 89 with TextPageLink

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

the class AssetController method getTenantAssets.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/tenant/assets", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<Asset> getTenantAssets(@RequestParam int limit, @RequestParam(required = false) String type, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        if (type != null && type.trim().length() > 0) {
            return checkNotNull(assetService.findAssetsByTenantIdAndType(tenantId, type, pageLink));
        } else {
            return checkNotNull(assetService.findAssetsByTenantId(tenantId, pageLink));
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 90 with TextPageLink

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

the class AssetController method getCustomerAssets.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/assets", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<Asset> getCustomerAssets(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) String type, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        if (type != null && type.trim().length() > 0) {
            return checkNotNull(assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
        } else {
            return checkNotNull(assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink));
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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