Search in sources :

Example 71 with ThingsboardException

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

the class PluginController method getPlugins.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugins", method = RequestMethod.GET)
@ResponseBody
public List<PluginMetaData> getPlugins() throws ThingsboardException {
    try {
        if (getCurrentUser().getAuthority() == Authority.SYS_ADMIN) {
            return checkNotNull(pluginService.findSystemPlugins());
        } else {
            TenantId tenantId = getCurrentUser().getTenantId();
            List<PluginMetaData> plugins = checkNotNull(pluginService.findAllTenantPluginsByTenantId(tenantId));
            plugins.stream().filter(plugin -> plugin.getTenantId().getId().equals(ModelConstants.NULL_UUID)).forEach(plugin -> plugin.setConfiguration(null));
            return plugins;
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) TextPageData(org.thingsboard.server.common.data.page.TextPageData) Authority(org.thingsboard.server.common.data.security.Authority) TenantId(org.thingsboard.server.common.data.id.TenantId) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ActionType(org.thingsboard.server.common.data.audit.ActionType) PluginId(org.thingsboard.server.common.data.id.PluginId) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) EntityType(org.thingsboard.server.common.data.EntityType) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 72 with ThingsboardException

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

the class PluginController method suspendPluginById.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}/suspend", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void suspendPluginById(@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.suspendPluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.SUSPENDED);
        logEntityAction(plugin.getId(), plugin, null, ActionType.SUSPENDED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.SUSPENDED, 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 73 with ThingsboardException

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

the class RuleController method suspendRuleById.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/rule/{ruleId}/suspend", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void suspendRuleById(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException {
    checkParameter(RULE_ID, strRuleId);
    try {
        RuleId ruleId = new RuleId(toUUID(strRuleId));
        RuleMetaData rule = checkRule(ruleService.findRuleById(ruleId));
        ruleService.suspendRuleById(ruleId);
        actorService.onRuleStateChange(rule.getTenantId(), rule.getId(), ComponentLifecycleEvent.SUSPENDED);
        logEntityAction(rule.getId(), rule, null, ActionType.SUSPENDED, null, strRuleId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.RULE), null, null, ActionType.SUSPENDED, e, strRuleId);
        throw handleException(e);
    }
}
Also used : RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 74 with ThingsboardException

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

the class RuleController method saveRule.

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

Example 75 with ThingsboardException

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

the class CustomerController method getShortCustomerInfoById.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/shortInfo", method = RequestMethod.GET)
@ResponseBody
public JsonNode getShortCustomerInfoById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException {
    checkParameter(CUSTOMER_ID, strCustomerId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId);
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode infoObject = objectMapper.createObjectNode();
        infoObject.put("title", customer.getTitle());
        infoObject.put(IS_PUBLIC, customer.isPublic());
        return infoObject;
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Customer(org.thingsboard.server.common.data.Customer) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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