use of org.thingsboard.server.common.data.rule.RuleMetaData 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.common.data.rule.RuleMetaData 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.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleService method updateLifeCycleState.
private void updateLifeCycleState(RuleId ruleId, ComponentLifecycleState state) {
Validator.validateId(ruleId, "Incorrect rule id for state change request.");
RuleMetaData rule = ruleDao.findById(ruleId);
if (rule != null) {
rule.setState(state);
validateRuleAndPluginState(rule);
ruleDao.save(rule);
} else {
throw new DatabaseException("Plugin not found!");
}
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleService method findAllTenantRulesByTenantId.
@Override
public List<RuleMetaData> findAllTenantRulesByTenantId(TenantId tenantId) {
log.trace("Executing findAllTenantRulesByTenantId, tenantId [{}]", tenantId);
Validator.validateId(tenantId, "Incorrect tenantId " + tenantId);
List<RuleMetaData> rules = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(300);
TextPageData<RuleMetaData> pageData = null;
do {
pageData = findAllTenantRulesByTenantIdAndPageLink(tenantId, pageLink);
rules.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
return rules;
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BasePluginService method checkRulesAndDelete.
private void checkRulesAndDelete(UUID pluginId) {
PluginMetaData plugin = pluginDao.findById(pluginId);
List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken());
if (affectedRules.isEmpty()) {
pluginDao.deleteById(pluginId);
} else {
throw new DataValidationException("Plugin deletion will affect existing rules!");
}
}
Aggregations