Search in sources :

Example 91 with ThingsboardException

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

the class BaseController method checkAssetInfoId.

AssetInfo checkAssetInfoId(AssetId assetId, Operation operation) throws ThingsboardException {
    try {
        validateId(assetId, "Incorrect assetId " + assetId);
        AssetInfo asset = assetService.findAssetInfoById(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 : AssetInfo(org.thingsboard.server.common.data.asset.AssetInfo) 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 92 with ThingsboardException

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

the class BaseController method checkEdgeId.

Edge checkEdgeId(EdgeId edgeId, Operation operation) throws ThingsboardException {
    try {
        validateId(edgeId, "Incorrect edgeId " + edgeId);
        Edge edge = edgeService.findEdgeById(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 : Edge(org.thingsboard.server.common.data.edge.Edge) 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 93 with ThingsboardException

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

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

the class BaseController method checkCustomerId.

Customer checkCustomerId(CustomerId customerId, Operation operation) throws ThingsboardException {
    try {
        validateId(customerId, "Incorrect customerId " + customerId);
        Customer customer = customerService.findCustomerById(getTenantId(), customerId);
        checkNotNull(customer, "Customer with id [" + customerId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.CUSTOMER, operation, customerId, customer);
        return customer;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : Customer(org.thingsboard.server.common.data.Customer) 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 95 with ThingsboardException

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

the class BaseController method checkTenantProfileId.

TenantProfile checkTenantProfileId(TenantProfileId tenantProfileId, Operation operation) throws ThingsboardException {
    try {
        validateId(tenantProfileId, "Incorrect tenantProfileId " + tenantProfileId);
        TenantProfile tenantProfile = tenantProfileService.findTenantProfileById(getTenantId(), tenantProfileId);
        checkNotNull(tenantProfile, "Tenant profile with id [" + tenantProfileId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.TENANT_PROFILE, operation);
        return tenantProfile;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) 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