Search in sources :

Example 31 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class JpaUserDaoTest method saveUser.

private void saveUser(UUID tenantId, UUID customerId) {
    User user = new User();
    UUID id = UUIDs.timeBased();
    user.setId(new UserId(id));
    user.setTenantId(new TenantId(tenantId));
    user.setCustomerId(new CustomerId(customerId));
    if (customerId == NULL_UUID) {
        user.setAuthority(Authority.TENANT_ADMIN);
    } else {
        user.setAuthority(Authority.CUSTOMER_USER);
    }
    String idString = id.toString();
    String email = idString.substring(0, idString.indexOf('-')) + "@thingsboard.org";
    user.setEmail(email);
    userDao.save(user);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) User(org.thingsboard.server.common.data.User) UserId(org.thingsboard.server.common.data.id.UserId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID)

Example 32 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class BasePluginServiceTest method findPluginByTenantIdAndApiToken.

@Test
public void findPluginByTenantIdAndApiToken() throws Exception {
    String token = UUID.randomUUID().toString();
    TenantId tenantId = new TenantId(UUIDs.timeBased());
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    PluginMetaData expected = pluginService.savePlugin(generatePlugin(tenantId, token));
    Assert.assertNotNull(expected.getId());
    PluginMetaData found = pluginService.findPluginByApiToken(token);
    Assert.assertEquals(expected, found);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 33 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class BasePluginServiceTest method findSystemPlugins.

@Test
public void findSystemPlugins() throws Exception {
    // system tenant id
    TenantId systemTenant = new TenantId(ModelConstants.NULL_UUID);
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(systemTenant, null));
    pluginService.savePlugin(generatePlugin(systemTenant, null));
    TextPageData<PluginMetaData> found = pluginService.findSystemPlugins(new TextPageLink(100));
    Assert.assertEquals(2, found.getData().size());
    Assert.assertFalse(found.hasNext());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 34 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class BaseRuleServiceTest method findTenantRules.

@Test
public void findTenantRules() throws Exception {
    TenantId tenantIdA = new TenantId(UUIDs.timeBased());
    TenantId tenantIdB = new TenantId(UUIDs.timeBased());
    PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(pluginA);
    pluginService.savePlugin(pluginB);
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) 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)

Example 35 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class BaseRuleServiceTest method deleteRulesByTenantId.

@Test
public void deleteRulesByTenantId() throws Exception {
    TenantId tenantIdA = new TenantId(UUIDs.timeBased());
    TenantId tenantIdB = new TenantId(UUIDs.timeBased());
    PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(pluginA);
    pluginService.savePlugin(pluginB);
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
    ruleService.deleteRulesByTenantId(tenantIdA);
    foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(0, foundA.getData().size());
    foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) 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

TenantId (org.thingsboard.server.common.data.id.TenantId)119 Test (org.junit.Test)44 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)38 CustomerId (org.thingsboard.server.common.data.id.CustomerId)30 ArrayList (java.util.ArrayList)26 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Tenant (org.thingsboard.server.common.data.Tenant)23 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)23 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)16 Customer (org.thingsboard.server.common.data.Customer)14 User (org.thingsboard.server.common.data.User)14 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)13 DeviceId (org.thingsboard.server.common.data.id.DeviceId)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)10 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)10 UserId (org.thingsboard.server.common.data.id.UserId)8 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)8 IOException (java.io.IOException)7 PluginId (org.thingsboard.server.common.data.id.PluginId)7