Search in sources :

Example 21 with PageLink

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

the class UserController method getTenantAdmins.

@ApiOperation(value = "Get Tenant Users (getTenantAdmins)", notes = "Returns a page of users owned by tenant. " + PAGE_DATA_PARAMETERS + SYSTEM_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('SYS_ADMIN')")
@RequestMapping(value = "/tenant/{tenantId}/users", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<User> getTenantAdmins(@ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true) @PathVariable(TENANT_ID) String strTenantId, @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = USER_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = USER_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("tenantId", strTenantId);
    try {
        TenantId tenantId = TenantId.fromUUID(toUUID(strTenantId));
        PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
        return checkNotNull(userService.findTenantAdmins(tenantId, pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PageLink(org.thingsboard.server.common.data.page.PageLink) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) 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 22 with PageLink

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

the class DefaultOtaPackageStateService method update.

private void update(TenantId tenantId, DeviceProfile deviceProfile, OtaPackageType otaPackageType) {
    Consumer<Device> updateConsumer;
    if (deviceProfile.getFirmwareId() != null) {
        long ts = System.currentTimeMillis();
        updateConsumer = d -> send(d.getTenantId(), d.getId(), deviceProfile.getFirmwareId(), ts, otaPackageType);
    } else {
        updateConsumer = d -> remove(d, otaPackageType);
    }
    PageLink pageLink = new PageLink(100);
    PageData<Device> pageData;
    do {
        pageData = deviceService.findDevicesByTenantIdAndTypeAndEmptyOtaPackage(tenantId, deviceProfile.getId(), otaPackageType, pageLink);
        pageData.getData().forEach(updateConsumer);
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
}
Also used : Device(org.thingsboard.server.common.data.Device) PageLink(org.thingsboard.server.common.data.page.PageLink)

Example 23 with PageLink

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

the class PaginatedUpdater method updateEntities.

public void updateEntities(I id) {
    updated = 0;
    PageLink pageLink = new PageLink(DEFAULT_LIMIT);
    boolean hasNext = true;
    while (hasNext) {
        PageData<D> entities = findEntities(id, pageLink);
        for (D entity : entities.getData()) {
            updateEntity(entity);
        }
        updated += entities.getData().size();
        hasNext = entities.hasNext();
        if (hasNext) {
            log.info("{}: {} entities updated so far...", getName(), updated);
            pageLink = pageLink.nextPageLink();
        } else {
            if (updated > DEFAULT_LIMIT || forceReportTotal()) {
                log.info("{}: {} total entities updated.", getName(), updated);
            }
        }
    }
}
Also used : PageLink(org.thingsboard.server.common.data.page.PageLink)

Example 24 with PageLink

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

the class BaseRuleChainService method deleteRuleChainById.

@Override
@Transactional
public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) {
    Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request.");
    RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId());
    if (ruleChain != null) {
        if (ruleChain.isRoot()) {
            throw new DataValidationException("Deletion of Root Tenant Rule Chain is prohibited!");
        }
        if (RuleChainType.EDGE.equals(ruleChain.getType())) {
            PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
            PageData<Edge> pageData;
            do {
                pageData = edgeService.findEdgesByTenantIdAndEntityId(tenantId, ruleChainId, pageLink);
                if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
                    for (Edge edge : pageData.getData()) {
                        if (edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) {
                            throw new DataValidationException("Can't delete rule chain that is root for edge [" + edge.getName() + "]. Please assign another root rule chain first to the edge!");
                        }
                    }
                    if (pageData.hasNext()) {
                        pageLink = pageLink.nextPageLink();
                    }
                }
            } while (pageData != null && pageData.hasNext());
        }
    }
    checkRuleNodesAndDelete(tenantId, ruleChainId);
}
Also used : DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) PageLink(org.thingsboard.server.common.data.page.PageLink) Edge(org.thingsboard.server.common.data.edge.Edge) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with PageLink

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

the class BaseRuleChainService method exportTenantRuleChains.

@Override
public RuleChainData exportTenantRuleChains(TenantId tenantId, PageLink pageLink) {
    Validator.validateId(tenantId, "Incorrect tenant id for search rule chain request.");
    Validator.validatePageLink(pageLink);
    PageData<RuleChain> ruleChainData = ruleChainDao.findRuleChainsByTenantId(tenantId.getId(), pageLink);
    List<RuleChain> ruleChains = ruleChainData.getData();
    List<RuleChainMetaData> metadata = ruleChains.stream().map(rc -> loadRuleChainMetaData(tenantId, rc.getId())).collect(Collectors.toList());
    RuleChainData rcData = new RuleChainData();
    rcData.setRuleChains(ruleChains);
    rcData.setMetadata(metadata);
    setRandomRuleChainIds(rcData);
    resetRuleNodeIds(metadata);
    return rcData;
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) BaseData(org.thingsboard.server.common.data.BaseData) RuleChainMetaData(org.thingsboard.server.common.data.rule.RuleChainMetaData) Autowired(org.springframework.beans.factory.annotation.Autowired) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) TenantId(org.thingsboard.server.common.data.id.TenantId) DataValidator(org.thingsboard.server.dao.service.DataValidator) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) Map(java.util.Map) EntityType(org.thingsboard.server.common.data.EntityType) RuleChainConnectionInfo(org.thingsboard.server.common.data.rule.RuleChainConnectionInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) EdgeId(org.thingsboard.server.common.data.id.EdgeId) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) PageLink(org.thingsboard.server.common.data.page.PageLink) Collection(java.util.Collection) Set(java.util.Set) RuleChainData(org.thingsboard.server.common.data.rule.RuleChainData) Collectors(java.util.stream.Collectors) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Slf4j(lombok.extern.slf4j.Slf4j) AbstractEntityService(org.thingsboard.server.dao.entity.AbstractEntityService) List(java.util.List) PaginatedRemover(org.thingsboard.server.dao.service.PaginatedRemover) Optional(java.util.Optional) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) TENANT(org.thingsboard.server.common.data.DataConstants.TENANT) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) RuleChainImportResult(org.thingsboard.server.common.data.rule.RuleChainImportResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) JacksonUtil(org.thingsboard.common.util.JacksonUtil) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RuleChainUpdateResult(org.thingsboard.server.common.data.rule.RuleChainUpdateResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Validator.validateId(org.thingsboard.server.dao.service.Validator.validateId) Validator.validateString(org.thingsboard.server.dao.service.Validator.validateString) RuleNodeUpdateResult(org.thingsboard.server.common.data.rule.RuleNodeUpdateResult) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) EntityId(org.thingsboard.server.common.data.id.EntityId) Iterator(java.util.Iterator) RuleChainType(org.thingsboard.server.common.data.rule.RuleChainType) RuleNode(org.thingsboard.server.common.data.rule.RuleNode) ConstraintValidator(org.thingsboard.server.dao.service.ConstraintValidator) Validator(org.thingsboard.server.dao.service.Validator) PageData(org.thingsboard.server.common.data.page.PageData) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) NodeConnectionInfo(org.thingsboard.server.common.data.rule.NodeConnectionInfo) Transactional(org.springframework.transaction.annotation.Transactional) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainMetaData(org.thingsboard.server.common.data.rule.RuleChainMetaData) RuleChainData(org.thingsboard.server.common.data.rule.RuleChainData)

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