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