Search in sources :

Example 86 with ThingsboardException

use of org.thingsboard.server.common.data.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkOtaPackageInfoId.

OtaPackageInfo checkOtaPackageInfoId(OtaPackageId otaPackageId, Operation operation) throws ThingsboardException {
    try {
        validateId(otaPackageId, "Incorrect otaPackageId " + otaPackageId);
        OtaPackageInfo otaPackageIn = otaPackageService.findOtaPackageInfoById(getCurrentUser().getTenantId(), otaPackageId);
        checkNotNull(otaPackageIn, "OTA package with id [" + otaPackageId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.OTA_PACKAGE, operation, otaPackageId, otaPackageIn);
        return otaPackageIn;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) 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)

Example 87 with ThingsboardException

use of org.thingsboard.server.common.data.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkRpcId.

Rpc checkRpcId(RpcId rpcId, Operation operation) throws ThingsboardException {
    try {
        validateId(rpcId, "Incorrect rpcId " + rpcId);
        Rpc rpc = rpcService.findById(getCurrentUser().getTenantId(), rpcId);
        checkNotNull(rpc, "RPC with id [" + rpcId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.RPC, operation, rpcId, rpc);
        return rpc;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : Rpc(org.thingsboard.server.common.data.rpc.Rpc) 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)

Example 88 with ThingsboardException

use of org.thingsboard.server.common.data.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkAssetId.

Asset checkAssetId(AssetId assetId, Operation operation) throws ThingsboardException {
    try {
        validateId(assetId, "Incorrect assetId " + assetId);
        Asset asset = assetService.findAssetById(getCurrentUser().getTenantId(), assetId);
        checkNotNull(asset, "Asset with id [" + assetId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.ASSET, operation, assetId, asset);
        return asset;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : Asset(org.thingsboard.server.common.data.asset.Asset) 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)

Example 89 with ThingsboardException

use of org.thingsboard.server.common.data.exception.ThingsboardException 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)

Example 90 with ThingsboardException

use of org.thingsboard.server.common.data.exception.ThingsboardException in project thingsboard by thingsboard.

the class BaseController method checkResourceId.

TbResource checkResourceId(TbResourceId resourceId, Operation operation) throws ThingsboardException {
    try {
        validateId(resourceId, "Incorrect resourceId " + resourceId);
        TbResource resource = resourceService.findResourceById(getCurrentUser().getTenantId(), resourceId);
        checkNotNull(resource, "Resource with id [" + resourceId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.TB_RESOURCE, operation, resourceId, resource);
        return resource;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource) 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

ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)225 ApiOperation (io.swagger.annotations.ApiOperation)176 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)176 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)172 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)150 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)102 TenantId (org.thingsboard.server.common.data.id.TenantId)75 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)48 CustomerId (org.thingsboard.server.common.data.id.CustomerId)42 EdgeId (org.thingsboard.server.common.data.id.EdgeId)42 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)42 Customer (org.thingsboard.server.common.data.Customer)39 IOException (java.io.IOException)38 Edge (org.thingsboard.server.common.data.edge.Edge)34 PageLink (org.thingsboard.server.common.data.page.PageLink)34 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)30 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)25 MessagingException (javax.mail.MessagingException)25 EntityId (org.thingsboard.server.common.data.id.EntityId)25 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)25