Search in sources :

Example 46 with TextPageLink

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

the class UserController method getCustomerUsers.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/users", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<User> getCustomerUsers(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        TenantId tenantId = getCurrentUser().getTenantId();
        return checkNotNull(userService.findCustomerUsers(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) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 47 with TextPageLink

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

the class WidgetsBundleServiceImpl method findSystemWidgetsBundles.

@Override
public List<WidgetsBundle> findSystemWidgetsBundles() {
    log.trace("Executing findSystemWidgetsBundles");
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = findSystemWidgetsBundlesByPageLink(pageLink);
        widgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return widgetsBundles;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 48 with TextPageLink

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

the class WidgetsBundleServiceImpl method findAllTenantWidgetsBundlesByTenantId.

@Override
public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId) {
    log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
    Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
        widgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return widgetsBundles;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 49 with TextPageLink

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

the class BaseRuleService method findAllTenantRulesByTenantId.

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

Example 50 with TextPageLink

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

the class PaginatedRemover method removeEntities.

public void removeEntities(I id) {
    TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT);
    boolean hasNext = true;
    while (hasNext) {
        List<D> entities = findEntities(id, pageLink);
        for (D entity : entities) {
            removeEntity(entity);
        }
        hasNext = entities.size() == pageLink.getLimit();
        if (hasNext) {
            int index = entities.size() - 1;
            UUID idOffset = entities.get(index).getUuidId();
            pageLink.setIdOffset(idOffset);
        }
    }
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) UUID(java.util.UUID) UUID(java.util.UUID)

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