Search in sources :

Example 31 with ThingsboardException

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

the class DeviceController method getCustomerDevices.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/devices", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<Device> getCustomerDevices(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) String type, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        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) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 32 with ThingsboardException

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

the class DeviceController method assignDeviceToPublicCustomer.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/public/device/{deviceId}", method = RequestMethod.POST)
@ResponseBody
public Device assignDeviceToPublicCustomer(@PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException {
    checkParameter(DEVICE_ID, strDeviceId);
    try {
        DeviceId deviceId = new DeviceId(toUUID(strDeviceId));
        Device device = checkDeviceId(deviceId);
        Customer publicCustomer = customerService.findOrCreatePublicCustomer(device.getTenantId());
        Device savedDevice = checkNotNull(deviceService.assignDeviceToCustomer(deviceId, publicCustomer.getId()));
        logEntityAction(deviceId, savedDevice, savedDevice.getCustomerId(), ActionType.ASSIGNED_TO_CUSTOMER, null, strDeviceId, publicCustomer.getId().toString(), publicCustomer.getName());
        return savedDevice;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DEVICE), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDeviceId);
        throw handleException(e);
    }
}
Also used : Customer(org.thingsboard.server.common.data.Customer) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 33 with ThingsboardException

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

the class DeviceController method saveDeviceCredentials.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/device/credentials", method = RequestMethod.POST)
@ResponseBody
public DeviceCredentials saveDeviceCredentials(@RequestBody DeviceCredentials deviceCredentials) throws ThingsboardException {
    checkNotNull(deviceCredentials);
    try {
        Device device = checkDeviceId(deviceCredentials.getDeviceId());
        DeviceCredentials result = checkNotNull(deviceCredentialsService.updateDeviceCredentials(deviceCredentials));
        actorService.onCredentialsUpdate(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId());
        logEntityAction(device.getId(), device, device.getCustomerId(), ActionType.CREDENTIALS_UPDATED, null, deviceCredentials);
        return result;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DEVICE), null, null, ActionType.CREDENTIALS_UPDATED, e, deviceCredentials);
        throw handleException(e);
    }
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 34 with ThingsboardException

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

the class EntityRelationController method getRelation.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relation", method = RequestMethod.GET, params = { FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE })
@ResponseBody
public EntityRelation getRelation(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @RequestParam(RELATION_TYPE) String strRelationType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup, @RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
    try {
        checkParameter(FROM_ID, strFromId);
        checkParameter(FROM_TYPE, strFromType);
        checkParameter(RELATION_TYPE, strRelationType);
        checkParameter(TO_ID, strToId);
        checkParameter(TO_TYPE, strToType);
        EntityId fromId = EntityIdFactory.getByTypeAndId(strFromType, strFromId);
        EntityId toId = EntityIdFactory.getByTypeAndId(strToType, strToId);
        checkEntityId(fromId);
        checkEntityId(toId);
        RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
        return checkNotNull(relationService.getRelation(fromId, toId, strRelationType, typeGroup));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 35 with ThingsboardException

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

the class PluginController method getTenantPlugins.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/plugin", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<PluginMetaData> getTenantPlugins(@RequestParam int limit, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        return checkNotNull(pluginService.findTenantPlugins(tenantId, pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ThingsboardException (org.thingsboard.server.exception.ThingsboardException)88 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)72 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)39 TenantId (org.thingsboard.server.common.data.id.TenantId)23 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)18 CustomerId (org.thingsboard.server.common.data.id.CustomerId)17 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 Customer (org.thingsboard.server.common.data.Customer)10 MessagingException (javax.mail.MessagingException)8 DashboardId (org.thingsboard.server.common.data.id.DashboardId)8 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)8 Device (org.thingsboard.server.common.data.Device)7 EntityId (org.thingsboard.server.common.data.id.EntityId)7 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)7 User (org.thingsboard.server.common.data.User)6 Asset (org.thingsboard.server.common.data.asset.Asset)6 DeviceId (org.thingsboard.server.common.data.id.DeviceId)6 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)6 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)6 List (java.util.List)5