Search in sources :

Example 91 with PageLink

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());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantInfo(org.thingsboard.server.common.data.TenantInfo) Test(org.junit.Test)

Example 92 with PageLink

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());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Test(org.junit.Test)

Example 93 with PageLink

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());
}
Also used : Rpc(org.thingsboard.server.common.data.rpc.Rpc) ToDeviceRpcRequest(org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest) ToDeviceRpcRequestActorMsg(org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg) PageLink(org.thingsboard.server.common.data.page.PageLink) SortOrder(org.thingsboard.server.common.data.page.SortOrder)

Example 94 with PageLink

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);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) PageLink(org.thingsboard.server.common.data.page.PageLink) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ExecutionException(java.util.concurrent.ExecutionException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 95 with PageLink

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);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) PageLink(org.thingsboard.server.common.data.page.PageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ExecutionException(java.util.concurrent.ExecutionException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PageLink (org.thingsboard.server.common.data.page.PageLink)187 Test (org.junit.Test)117 ArrayList (java.util.ArrayList)106 TenantId (org.thingsboard.server.common.data.id.TenantId)67 TypeReference (com.fasterxml.jackson.core.type.TypeReference)54 CustomerId (org.thingsboard.server.common.data.id.CustomerId)47 Tenant (org.thingsboard.server.common.data.Tenant)45 Customer (org.thingsboard.server.common.data.Customer)43 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)34 ApiOperation (io.swagger.annotations.ApiOperation)33 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)33 Edge (org.thingsboard.server.common.data.edge.Edge)32 Device (org.thingsboard.server.common.data.Device)28 PageData (org.thingsboard.server.common.data.page.PageData)28 Matchers.containsString (org.hamcrest.Matchers.containsString)22 UUID (java.util.UUID)20 Asset (org.thingsboard.server.common.data.asset.Asset)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20