Search in sources :

Example 31 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class RuleMetaDataEntity method toData.

@Override
public RuleMetaData toData() {
    RuleMetaData rule = new RuleMetaData(new RuleId(id));
    rule.setTenantId(new TenantId(tenantId));
    rule.setName(name);
    rule.setState(state);
    rule.setWeight(weight);
    rule.setCreatedTime(UUIDs.unixTimestamp(id));
    rule.setPluginToken(pluginToken);
    rule.setFilters(filters);
    rule.setProcessor(processor);
    rule.setAction(action);
    rule.setAdditionalInfo(additionalInfo);
    return rule;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 32 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class RuleMetaDataEntity method toData.

@Override
public RuleMetaData toData() {
    RuleMetaData rule = new RuleMetaData(new RuleId(getId()));
    rule.setTenantId(new TenantId(toUUID(tenantId)));
    rule.setName(name);
    rule.setState(state);
    rule.setWeight(weight);
    rule.setCreatedTime(UUIDs.unixTimestamp(getId()));
    rule.setPluginToken(pluginToken);
    rule.setFilters(filters);
    rule.setProcessor(processor);
    rule.setAction(action);
    rule.setAdditionalInfo(additionalInfo);
    return rule;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 33 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method getRuleMetaData.

private RuleMetaData getRuleMetaData(UUID id) throws IOException {
    RuleMetaData ruleMetaData = new RuleMetaData();
    ruleMetaData.setId(new RuleId(id));
    ruleMetaData.setTenantId(new TenantId(UUIDs.timeBased()));
    ruleMetaData.setName("test");
    return ruleMetaData;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 34 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method testFindAllTenantRulesByTenantId.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindAllTenantRulesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createTenantsAndSystemRules(tenantId1, tenantId2, "name_", "token");
    List<RuleMetaData> rules1 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_"));
    assertEquals(40, rules1.size());
    List<RuleMetaData> rules2 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_", rules1.get(19).getId().getId(), null));
    assertEquals(20, rules2.size());
    List<RuleMetaData> rules3 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_", rules2.get(19).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 35 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleServiceTest method saveRule.

@Test
public void saveRule() throws Exception {
    PluginMetaData plugin = generatePlugin(null, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(plugin);
    RuleMetaData ruleMetaData = ruleService.saveRule(generateRule(plugin.getTenantId(), null, plugin.getApiToken()));
    Assert.assertNotNull(ruleMetaData.getId());
    Assert.assertNotNull(ruleMetaData.getAdditionalInfo());
    ruleMetaData.setAdditionalInfo(mapper.readTree("{\"description\":\"test\"}"));
    RuleMetaData newRuleMetaData = ruleService.saveRule(ruleMetaData);
    Assert.assertEquals(ruleMetaData.getAdditionalInfo(), newRuleMetaData.getAdditionalInfo());
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) 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