Search in sources :

Example 46 with ThingsboardException

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

the class PluginController method deletePlugin.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deletePlugin(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException {
    checkParameter(PLUGIN_ID, strPluginId);
    try {
        PluginId pluginId = new PluginId(toUUID(strPluginId));
        PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId));
        pluginService.deletePluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.DELETED);
        logEntityAction(pluginId, plugin, null, ActionType.DELETED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.DELETED, e, strPluginId);
        throw handleException(e);
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 47 with ThingsboardException

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

the class PluginController method savePlugin.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin", method = RequestMethod.POST)
@ResponseBody
public PluginMetaData savePlugin(@RequestBody PluginMetaData source) throws ThingsboardException {
    try {
        boolean created = source.getId() == null;
        source.setTenantId(getCurrentUser().getTenantId());
        PluginMetaData plugin = checkNotNull(pluginService.savePlugin(source));
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
        logEntityAction(plugin.getId(), plugin, null, created ? ActionType.ADDED : ActionType.UPDATED, null);
        return plugin;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), source, null, source.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e);
        throw handleException(e);
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with ThingsboardException

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

the class EntityRelationController method findByTo.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations", method = RequestMethod.GET, params = { TO_ID, TO_TYPE })
@ResponseBody
public List<EntityRelation> findByTo(@RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
    checkParameter(TO_ID, strToId);
    checkParameter(TO_TYPE, strToType);
    EntityId entityId = EntityIdFactory.getByTypeAndId(strToType, strToId);
    checkEntityId(entityId);
    RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
    try {
        return checkNotNull(relationService.findByTo(entityId, 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 49 with ThingsboardException

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

the class EntityRelationController method findInfoByTo.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = { TO_ID, TO_TYPE })
@ResponseBody
public List<EntityRelationInfo> findInfoByTo(@RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
    checkParameter(TO_ID, strToId);
    checkParameter(TO_TYPE, strToType);
    EntityId entityId = EntityIdFactory.getByTypeAndId(strToType, strToId);
    checkEntityId(entityId);
    RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
    try {
        return checkNotNull(relationService.findInfoByTo(entityId, typeGroup).get());
    } 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 50 with ThingsboardException

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

the class EntityRelationController method findInfoByFrom.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = { FROM_ID, FROM_TYPE })
@ResponseBody
public List<EntityRelationInfo> findInfoByFrom(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
    checkParameter(FROM_ID, strFromId);
    checkParameter(FROM_TYPE, strFromType);
    EntityId entityId = EntityIdFactory.getByTypeAndId(strFromType, strFromId);
    checkEntityId(entityId);
    RelationTypeGroup typeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
    try {
        return checkNotNull(relationService.findInfoByFrom(entityId, typeGroup).get());
    } 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)

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