Search in sources :

Example 76 with PageLink

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

the class DashboardController method getEdgeDashboards.

@ApiOperation(value = "Get Edge Dashboards (getEdgeDashboards)", notes = "Returns a page of dashboard info objects assigned to the specified edge. " + DASHBOARD_INFO_DEFINITION + " " + PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<DashboardInfo> getEdgeDashboards(@ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true) @PathVariable(EDGE_ID) String strEdgeId, @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = DASHBOARD_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = DASHBOARD_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("edgeId", strEdgeId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
        checkEdgeId(edgeId, Operation.READ);
        PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
        PageData<DashboardInfo> nonFilteredResult = dashboardService.findDashboardsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
        List<DashboardInfo> filteredDashboards = nonFilteredResult.getData().stream().filter(dashboardInfo -> {
            try {
                accessControlService.checkPermission(getCurrentUser(), Resource.DASHBOARD, Operation.READ, dashboardInfo.getId(), dashboardInfo);
                return true;
            } catch (ThingsboardException e) {
                return false;
            }
        }).collect(Collectors.toList());
        PageData<DashboardInfo> filteredResult = new PageData<>(filteredDashboards, nonFilteredResult.getTotalPages(), nonFilteredResult.getTotalElements(), nonFilteredResult.hasNext());
        return checkNotNull(filteredResult);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Edge(org.thingsboard.server.common.data.edge.Edge) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Customer(org.thingsboard.server.common.data.Customer) DASHBOARD_SORT_PROPERTY_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.DASHBOARD_SORT_PROPERTY_ALLOWABLE_VALUES) SORT_ORDER_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_ALLOWABLE_VALUES) ApiParam(io.swagger.annotations.ApiParam) CUSTOMER_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID_PARAM_DESCRIPTION) TenantId(org.thingsboard.server.common.data.id.TenantId) ApiOperation(io.swagger.annotations.ApiOperation) EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION) Example(io.swagger.annotations.Example) EntityType(org.thingsboard.server.common.data.EntityType) CUSTOMER_ID(org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID) JsonNode(com.fasterxml.jackson.databind.JsonNode) EdgeId(org.thingsboard.server.common.data.id.EdgeId) Dashboard(org.thingsboard.server.common.data.Dashboard) TENANT_ID(org.thingsboard.server.controller.ControllerConstants.TENANT_ID) PageLink(org.thingsboard.server.common.data.page.PageLink) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) TENANT_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.TENANT_AUTHORITY_PARAGRAPH) MediaType(org.springframework.http.MediaType) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) EDGE_ID(org.thingsboard.server.controller.ControllerConstants.EDGE_ID) PAGE_DATA_PARAMETERS(org.thingsboard.server.controller.ControllerConstants.PAGE_DATA_PARAMETERS) UUID_WIKI_LINK(org.thingsboard.server.controller.ControllerConstants.UUID_WIKI_LINK) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) EdgeEventActionType(org.thingsboard.server.common.data.edge.EdgeEventActionType) List(java.util.List) EDGE_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_ID_PARAM_DESCRIPTION) Operation(org.thingsboard.server.service.security.permission.Operation) SORT_ORDER_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_DESCRIPTION) TENANT_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.TENANT_ID_PARAM_DESCRIPTION) PAGE_NUMBER_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION) CustomerId(org.thingsboard.server.common.data.id.CustomerId) SORT_PROPERTY_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.SORT_PROPERTY_DESCRIPTION) JacksonUtil(org.thingsboard.common.util.JacksonUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ShortCustomerInfo(org.thingsboard.server.common.data.ShortCustomerInfo) Tenant(org.thingsboard.server.common.data.Tenant) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) HashSet(java.util.HashSet) DASHBOARD_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.DASHBOARD_ID_PARAM_DESCRIPTION) User(org.thingsboard.server.common.data.User) HomeDashboard(org.thingsboard.server.common.data.HomeDashboard) ActionType(org.thingsboard.server.common.data.audit.ActionType) TbCoreComponent(org.thingsboard.server.queue.util.TbCoreComponent) PAGE_SIZE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) HomeDashboardInfo(org.thingsboard.server.common.data.HomeDashboardInfo) DashboardId(org.thingsboard.server.common.data.id.DashboardId) DASHBOARD_TEXT_SEARCH_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.DASHBOARD_TEXT_SEARCH_DESCRIPTION) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) EDGE_ASSIGN_ASYNC_FIRST_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_ASSIGN_ASYNC_FIRST_STEP_DESCRIPTION) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) SYSTEM_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.SYSTEM_AUTHORITY_PARAGRAPH) HttpStatus(org.springframework.http.HttpStatus) EDGE_ASSIGN_RECEIVE_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_ASSIGN_RECEIVE_STEP_DESCRIPTION) EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION) ApiResponse(io.swagger.annotations.ApiResponse) ExampleProperty(io.swagger.annotations.ExampleProperty) PageData(org.thingsboard.server.common.data.page.PageData) Resource(org.thingsboard.server.service.security.permission.Resource) TenantId(org.thingsboard.server.common.data.id.TenantId) PageData(org.thingsboard.server.common.data.page.PageData) EdgeId(org.thingsboard.server.common.data.id.EdgeId) PageLink(org.thingsboard.server.common.data.page.PageLink) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) HomeDashboardInfo(org.thingsboard.server.common.data.HomeDashboardInfo) 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 77 with PageLink

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

the class DeviceController method getCustomerDevices.

@ApiOperation(value = "Get Customer Devices (getCustomerDevices)", notes = "Returns a page of devices objects assigned to customer. " + PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/devices", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<Device> getCustomerDevices(@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 = DEVICE_TYPE_DESCRIPTION) @RequestParam(required = false) String type, @ApiParam(value = DEVICE_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = DEVICE_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("customerId", 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(deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
        } else {
            return checkNotNull(deviceService.findDevicesByTenantIdAndCustomerId(tenantId, customerId, 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) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IOException(java.io.IOException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) 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 78 with PageLink

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

the class DashboardController method getTenantDashboards.

@ApiOperation(value = "Get Tenant Dashboards (getTenantDashboards)", notes = "Returns a page of dashboard info objects owned by the tenant of a current user. " + DASHBOARD_INFO_DEFINITION + " " + PAGE_DATA_PARAMETERS + TENANT_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/tenant/dashboards", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<DashboardInfo> getTenantDashboards(@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = HIDDEN_FOR_MOBILE) @RequestParam(required = false) Boolean mobile, @ApiParam(value = DASHBOARD_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = DASHBOARD_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 (mobile != null && mobile) {
            return checkNotNull(dashboardService.findMobileDashboardsByTenantId(tenantId, pageLink));
        } else {
            return checkNotNull(dashboardService.findDashboardsByTenantId(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 79 with PageLink

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

the class BaseController method createPageLink.

PageLink createPageLink(int pageSize, int page, String textSearch, String sortProperty, String sortOrder) throws ThingsboardException {
    if (!StringUtils.isEmpty(sortProperty)) {
        SortOrder.Direction direction = SortOrder.Direction.ASC;
        if (!StringUtils.isEmpty(sortOrder)) {
            try {
                direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase());
            } catch (IllegalArgumentException e) {
                throw new ThingsboardException("Unsupported sort order '" + sortOrder + "'! Only 'ASC' or 'DESC' types are allowed.", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
            }
        }
        SortOrder sort = new SortOrder(sortProperty, direction);
        return new PageLink(pageSize, page, textSearch, sort);
    } else {
        return new PageLink(pageSize, page, textSearch);
    }
}
Also used : ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) PageLink(org.thingsboard.server.common.data.page.PageLink) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) SortOrder(org.thingsboard.server.common.data.page.SortOrder)

Example 80 with PageLink

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

the class EdgeServiceImpl method findEdgeRuleChains.

private List<RuleChain> findEdgeRuleChains(TenantId tenantId, EdgeId edgeId) {
    List<RuleChain> result = new ArrayList<>();
    PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
    PageData<RuleChain> pageData;
    do {
        pageData = ruleChainService.findRuleChainsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
        if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
            result.addAll(pageData.getData());
            if (pageData.hasNext()) {
                pageLink = pageLink.nextPageLink();
            }
        }
    } while (pageData != null && pageData.hasNext());
    return result;
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Validator.validatePageLink(org.thingsboard.server.dao.service.Validator.validatePageLink)

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