Search in sources :

Example 6 with RuleMetaData

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;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 7 with RuleMetaData

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);
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 8 with RuleMetaData

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());
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Example 9 with RuleMetaData

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);
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Example 10 with RuleMetaData

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();
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Aggregations

RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)43 Test (org.junit.Test)20 TenantId (org.thingsboard.server.common.data.id.TenantId)12 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)12 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)10 RuleId (org.thingsboard.server.common.data.id.RuleId)8 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)7 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)5 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)3 ActorRef (akka.actor.ActorRef)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 RuleActorMetaData (org.thingsboard.server.actors.rule.RuleActorMetaData)2 SimpleRuleActorChain (org.thingsboard.server.actors.rule.SimpleRuleActorChain)2 PageDataIterable (org.thingsboard.server.common.data.page.PageDataIterable)2