Search in sources :

Example 16 with TenantId

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

the class EntitySubtypeEntity method toEntitySubtype.

public EntitySubtype toEntitySubtype() {
    EntitySubtype entitySubtype = new EntitySubtype();
    entitySubtype.setTenantId(new TenantId(tenantId));
    entitySubtype.setEntityType(entityType);
    entitySubtype.setType(type);
    return entitySubtype;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 17 with TenantId

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

the class BaseUserControllerTest method testFindTenantAdminsByEmail.

@Test
public void testFindTenantAdminsByEmail() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    TenantId tenantId = savedTenant.getId();
    String email1 = "testEmail1";
    List<User> tenantAdminsEmail1 = new ArrayList<>();
    for (int i = 0; i < 124; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email1 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail1.add(doPost("/api/user", user, User.class));
    }
    String email2 = "testEmail2";
    List<User> tenantAdminsEmail2 = new ArrayList<>();
    for (int i = 0; i < 112; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email2 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail2.add(doPost("/api/user", user, User.class));
    }
    List<User> loadedTenantAdminsEmail1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33, email1);
    TextPageData<User> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail1, idComparator);
    Collections.sort(loadedTenantAdminsEmail1, idComparator);
    Assert.assertEquals(tenantAdminsEmail1, loadedTenantAdminsEmail1);
    List<User> loadedTenantAdminsEmail2 = new ArrayList<>();
    pageLink = new TextPageLink(16, email2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail2, idComparator);
    Collections.sort(loadedTenantAdminsEmail2, idComparator);
    Assert.assertEquals(tenantAdminsEmail2, loadedTenantAdminsEmail2);
    for (User user : loadedTenantAdminsEmail1) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, email1);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (User user : loadedTenantAdminsEmail2) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, email2);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 18 with TenantId

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

the class BaseUserControllerTest method testFindCustomerUsers.

@Test
public void testFindCustomerUsers() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    TenantId tenantId = savedTenant.getId();
    User tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(tenantId);
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
    Customer customer = new Customer();
    customer.setTitle("My customer");
    Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = savedCustomer.getId();
    List<User> customerUsers = new ArrayList<>();
    for (int i = 0; i < 56; i++) {
        User user = new User();
        user.setAuthority(Authority.CUSTOMER_USER);
        user.setCustomerId(customerId);
        user.setEmail("testCustomer" + i + "@thingsboard.org");
        customerUsers.add(doPost("/api/user", user, User.class));
    }
    List<User> loadedCustomerUsers = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33);
    TextPageData<User> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedCustomerUsers.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customerUsers, idComparator);
    Collections.sort(loadedCustomerUsers, idComparator);
    Assert.assertEquals(customerUsers, loadedCustomerUsers);
    doDelete("/api/customer/" + customerId.getId().toString()).andExpect(status().isOk());
    loginSysAdmin();
    doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 19 with TenantId

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

the class JpaCustomerDaoTest method createCustomer.

private void createCustomer(UUID tenantId, int index) {
    Customer customer = new Customer();
    customer.setId(new CustomerId(UUIDs.timeBased()));
    customer.setTenantId(new TenantId(tenantId));
    customer.setTitle("CUSTOMER_" + index);
    customerDao.save(customer);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Customer(org.thingsboard.server.common.data.Customer) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Example 20 with TenantId

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

the class JpaDeviceDaoTest method getDevice.

private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
    Device device = new Device();
    device.setId(new DeviceId(deviceId));
    device.setTenantId(new TenantId(tenantId));
    device.setCustomerId(new CustomerId(customerID));
    device.setName("SEARCH_TEXT");
    return device;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

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