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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations