use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleService method findSystemRules.
@Override
public List<RuleMetaData> findSystemRules() {
log.trace("Executing findSystemRules");
List<RuleMetaData> rules = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(300);
TextPageData<RuleMetaData> pageData = null;
do {
pageData = findSystemRules(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 BaseRuleService method saveRule.
@Override
public RuleMetaData saveRule(RuleMetaData rule) {
ruleValidator.validate(rule);
if (rule.getTenantId() == null) {
log.trace("Save system rule metadata with predefined id {}", systemTenantId);
rule.setTenantId(systemTenantId);
}
if (rule.getId() != null) {
RuleMetaData oldVersion = ruleDao.findById(rule.getId());
if (rule.getState() == null) {
rule.setState(oldVersion.getState());
} else if (rule.getState() != oldVersion.getState()) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
}
} else {
if (rule.getState() == null) {
rule.setState(ComponentLifecycleState.SUSPENDED);
} else if (rule.getState() != ComponentLifecycleState.SUSPENDED) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
}
}
validateFilters(rule.getFilters());
if (rule.getProcessor() != null && !rule.getProcessor().isNull()) {
validateComponentJson(rule.getProcessor(), ComponentType.PROCESSOR);
}
if (rule.getAction() != null && !rule.getAction().isNull()) {
validateComponentJson(rule.getAction(), ComponentType.ACTION);
}
validateRuleAndPluginState(rule);
return ruleDao.save(rule);
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testSuspendRule.
@Test
public void testSuspendRule() throws Exception {
RuleMetaData rule = createRuleMetaData(tenantPlugin);
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
doPost("/api/plugin/" + tenantPlugin.getId().getId().toString() + "/activate").andExpect(status().isOk());
doPost("/api/rule/" + savedRule.getId().getId().toString() + "/activate").andExpect(status().isOk());
doPost("/api/rule/" + savedRule.getId().getId().toString() + "/suspend").andExpect(status().isOk());
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testFindRuleById.
@Test
public void testFindRuleById() throws Exception {
RuleMetaData rule = createRuleMetaData(tenantPlugin);
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
RuleMetaData foundRule = doGet("/api/rule/" + savedRule.getId().getId().toString(), RuleMetaData.class);
Assert.assertNotNull(foundRule);
Assert.assertEquals(savedRule, foundRule);
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testFindSystemRules.
@Test
public void testFindSystemRules() throws Exception {
loginSysAdmin();
List<RuleMetaData> rules = testRulesCreation("/api/rule/system", sysPlugin);
for (RuleMetaData rule : rules) {
doDelete("/api/rule/" + rule.getId().getId()).andExpect(status().isOk());
}
loginTenantAdmin();
}
Aggregations