Search in sources :

Example 1 with EdgeInfo

use of org.thingsboard.server.common.data.edge.EdgeInfo in project thingsboard by thingsboard.

the class EdgeController method getCustomerEdgeInfos.

@ApiOperation(value = "Get Customer Edge Infos (getCustomerEdgeInfos)", notes = "Returns a page of edges info objects assigned to customer. " + PAGE_DATA_PARAMETERS + EDGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/edgeInfos", params = { "pageSize", "page" }, method = RequestMethod.GET)
@ResponseBody
public PageData<EdgeInfo> getCustomerEdgeInfos(@ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) @PathVariable("customerId") String strCustomerId, @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true) @RequestParam int pageSize, @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) @RequestParam int page, @ApiParam(value = EDGE_TYPE_DESCRIPTION) @RequestParam(required = false) String type, @ApiParam(value = EDGE_TEXT_SEARCH_DESCRIPTION) @RequestParam(required = false) String textSearch, @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = EDGE_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 {
        SecurityUser user = getCurrentUser();
        TenantId tenantId = user.getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId, Operation.READ);
        PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
        PageData<EdgeInfo> result;
        if (type != null && type.trim().length() > 0) {
            result = edgeService.findEdgeInfosByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink);
        } else {
            result = edgeService.findEdgeInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
        }
        return checkNotNull(result);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) PageLink(org.thingsboard.server.common.data.page.PageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EdgeInfo(org.thingsboard.server.common.data.edge.EdgeInfo) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) IOException(java.io.IOException) 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 2 with EdgeInfo

use of org.thingsboard.server.common.data.edge.EdgeInfo in project thingsboard by thingsboard.

the class BaseController method checkEdgeInfoId.

EdgeInfo checkEdgeInfoId(EdgeId edgeId, Operation operation) throws ThingsboardException {
    try {
        validateId(edgeId, "Incorrect edgeId " + edgeId);
        EdgeInfo edge = edgeService.findEdgeInfoById(getCurrentUser().getTenantId(), edgeId);
        checkNotNull(edge, "Edge with id [" + edgeId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.EDGE, operation, edgeId, edge);
        return edge;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : EdgeInfo(org.thingsboard.server.common.data.edge.EdgeInfo) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

EdgeInfo (org.thingsboard.server.common.data.edge.EdgeInfo)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 PageLink (org.thingsboard.server.common.data.page.PageLink)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1