Search in sources :

Example 81 with TenantId

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

the class UserEntity method toData.

@Override
public User toData() {
    User user = new User(new UserId(getId()));
    user.setCreatedTime(UUIDs.unixTimestamp(getId()));
    user.setAuthority(authority);
    if (tenantId != null) {
        user.setTenantId(new TenantId(fromString(tenantId)));
    }
    if (customerId != null) {
        user.setCustomerId(new CustomerId(fromString(customerId)));
    }
    user.setEmail(email);
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setAdditionalInfo(additionalInfo);
    return 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)

Example 82 with TenantId

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

the class BaseCustomerServiceTest method testSaveCustomerWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveCustomerWithInvalidTenant() {
    Customer customer = new Customer();
    customer.setTitle("My customer");
    customer.setTenantId(new TenantId(UUIDs.timeBased()));
    customerService.saveCustomer(customer);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Customer(org.thingsboard.server.common.data.Customer) Test(org.junit.Test)

Example 83 with TenantId

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

the class BaseDashboardServiceTest method testSaveDashboardWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveDashboardWithInvalidTenant() {
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("My dashboard");
    dashboard.setTenantId(new TenantId(UUIDs.timeBased()));
    dashboardService.saveDashboard(dashboard);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Dashboard(org.thingsboard.server.common.data.Dashboard) Test(org.junit.Test)

Example 84 with TenantId

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

the class BaseDashboardServiceTest method testFindDashboardsByTenantId.

@Test
public void testFindDashboardsByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<DashboardInfo> dashboards = new ArrayList<>();
    for (int i = 0; i < 165; i++) {
        Dashboard dashboard = new Dashboard();
        dashboard.setTenantId(tenantId);
        dashboard.setTitle("Dashboard" + i);
        dashboards.add(new DashboardInfo(dashboardService.saveDashboard(dashboard)));
    }
    List<DashboardInfo> loadedDashboards = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(16);
    TextPageData<DashboardInfo> pageData = null;
    do {
        pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
        loadedDashboards.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(dashboards, idComparator);
    Collections.sort(loadedDashboards, idComparator);
    Assert.assertEquals(dashboards, loadedDashboards);
    dashboardService.deleteDashboardsByTenantId(tenantId);
    pageLink = new TextPageLink(31);
    pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 85 with TenantId

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

the class BaseDeviceServiceTest method testSaveDeviceWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveDeviceWithInvalidTenant() {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    device.setTenantId(new TenantId(UUIDs.timeBased()));
    deviceService.saveDevice(device);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) 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