use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseTenantServiceTest method testFindTenantInfos.
@Test
public void testFindTenantInfos() {
List<TenantInfo> tenants = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<TenantInfo> pageData = tenantService.findTenantInfos(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenants.addAll(pageData.getData());
for (int i = 0; i < 156; i++) {
Tenant tenant = new Tenant();
tenant.setTitle("Tenant" + i);
tenants.add(new TenantInfo(tenantService.saveTenant(tenant), "Default"));
}
List<TenantInfo> loadedTenants = new ArrayList<>();
pageLink = new PageLink(17);
do {
pageData = tenantService.findTenantInfos(pageLink);
loadedTenants.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenants, idComparator);
Collections.sort(loadedTenants, idComparator);
Assert.assertEquals(tenants, loadedTenants);
for (TenantInfo tenant : loadedTenants) {
tenantService.deleteTenant(tenant.getId());
}
pageLink = new PageLink(17);
pageData = tenantService.findTenantInfos(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseTenantServiceTest method testFindTenantsByTitle.
@Test
public void testFindTenantsByTitle() {
String title1 = "Tenant title 1";
List<Tenant> tenantsTitle1 = new ArrayList<>();
for (int i = 0; i < 134; i++) {
Tenant tenant = new Tenant();
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 15));
String title = title1 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
tenant.setTitle(title);
tenantsTitle1.add(tenantService.saveTenant(tenant));
}
String title2 = "Tenant title 2";
List<Tenant> tenantsTitle2 = new ArrayList<>();
for (int i = 0; i < 127; i++) {
Tenant tenant = new Tenant();
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 15));
String title = title2 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
tenant.setTitle(title);
tenantsTitle2.add(tenantService.saveTenant(tenant));
}
List<Tenant> loadedTenantsTitle1 = new ArrayList<>();
PageLink pageLink = new PageLink(15, 0, title1);
PageData<Tenant> pageData = null;
do {
pageData = tenantService.findTenants(pageLink);
loadedTenantsTitle1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantsTitle1, idComparator);
Collections.sort(loadedTenantsTitle1, idComparator);
Assert.assertEquals(tenantsTitle1, loadedTenantsTitle1);
List<Tenant> loadedTenantsTitle2 = new ArrayList<>();
pageLink = new PageLink(4, 0, title2);
do {
pageData = tenantService.findTenants(pageLink);
loadedTenantsTitle2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantsTitle2, idComparator);
Collections.sort(loadedTenantsTitle2, idComparator);
Assert.assertEquals(tenantsTitle2, loadedTenantsTitle2);
for (Tenant tenant : loadedTenantsTitle1) {
tenantService.deleteTenant(tenant.getId());
}
pageLink = new PageLink(4, 0, title1);
pageData = tenantService.findTenants(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Tenant tenant : loadedTenantsTitle2) {
tenantService.deleteTenant(tenant.getId());
}
pageLink = new PageLink(4, 0, title2);
pageData = tenantService.findTenants(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class DeviceActorMessageProcessor method init.
void init(TbActorCtx ctx) {
PageLink pageLink = new PageLink(1024, 0, null, new SortOrder("createdTime"));
PageData<Rpc> pageData;
do {
pageData = systemContext.getTbRpcService().findAllByDeviceIdAndStatus(tenantId, deviceId, RpcStatus.QUEUED, pageLink);
pageData.getData().forEach(rpc -> {
ToDeviceRpcRequest msg = JacksonUtil.convertValue(rpc.getRequest(), ToDeviceRpcRequest.class);
long timeout = rpc.getExpirationTime() - System.currentTimeMillis();
if (timeout <= 0) {
rpc.setStatus(RpcStatus.EXPIRED);
systemContext.getTbRpcService().save(tenantId, rpc);
} else {
registerPendingRpcRequest(ctx, new ToDeviceRpcRequestActorMsg(systemContext.getServiceId(), msg), false, creteToDeviceRpcRequestMsg(msg), timeout);
}
});
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class EntityViewController method getTenantEntityViewInfos.
@ApiOperation(value = "Get Tenant Entity Views (getTenantEntityViews)", notes = "Returns a page of entity views info owned by tenant. " + ENTITY_VIEW_DESCRIPTION + PAGE_DATA_PARAMETERS + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/tenant/entityViewInfos", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<EntityViewInfo> getTenantEntityViewInfos(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = ENTITY_VIEW_TYPE) @RequestParam(required = false) String type, @ApiParam(value = ENTITY_VIEW_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = ENTITY_VIEW_INFO_SORT_PROPERTY_ALLOWABLE_VALUES) @RequestParam(required = false) String sortProperty, @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) @RequestParam(required = false) String sortOrder) throws ThingsboardException {
try {
TenantId tenantId = getCurrentUser().getTenantId();
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
if (type != null && type.trim().length() > 0) {
return checkNotNull(entityViewService.findEntityViewInfosByTenantIdAndType(tenantId, type, pageLink));
} else {
return checkNotNull(entityViewService.findEntityViewInfosByTenantId(tenantId, pageLink));
}
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class EntityViewController method getCustomerEntityViews.
@ApiOperation(value = "Get Customer Entity Views (getCustomerEntityViews)", notes = "Returns a page of Entity View objects assigned to customer. " + PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/entityViews", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<EntityView> getCustomerEntityViews(@ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION, required = true) @PathVariable(CUSTOMER_ID) String strCustomerId, @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = ENTITY_VIEW_TYPE) @RequestParam(required = false) String type, @ApiParam(value = ENTITY_VIEW_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = ENTITY_VIEW_SORT_PROPERTY_ALLOWABLE_VALUES) @RequestParam(required = false) String sortProperty, @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) @RequestParam(required = false) String sortOrder) throws ThingsboardException {
checkParameter(CUSTOMER_ID, strCustomerId);
try {
TenantId tenantId = getCurrentUser().getTenantId();
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
checkCustomerId(customerId, Operation.READ);
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
if (type != null && type.trim().length() > 0) {
return checkNotNull(entityViewService.findEntityViewsByTenantIdAndCustomerIdAndType(tenantId, customerId, pageLink, type));
} else {
return checkNotNull(entityViewService.findEntityViewsByTenantIdAndCustomerId(tenantId, customerId, pageLink));
}
} catch (Exception e) {
throw handleException(e);
}
}
Aggregations