use of org.thingsboard.server.common.data.id.CustomerId in project thingsboard by thingsboard.
the class AssetEntity method toData.
@Override
public Asset toData() {
Asset asset = new Asset(new AssetId(id));
asset.setCreatedTime(UUIDs.unixTimestamp(id));
if (tenantId != null) {
asset.setTenantId(new TenantId(tenantId));
}
if (customerId != null) {
asset.setCustomerId(new CustomerId(customerId));
}
asset.setName(name);
asset.setType(type);
asset.setAdditionalInfo(additionalInfo);
return asset;
}
use of org.thingsboard.server.common.data.id.CustomerId in project thingsboard by thingsboard.
the class CustomerEntity method toData.
@Override
public Customer toData() {
Customer customer = new Customer(new CustomerId(id));
customer.setCreatedTime(UUIDs.unixTimestamp(id));
customer.setTenantId(new TenantId(tenantId));
customer.setTitle(title);
customer.setCountry(country);
customer.setState(state);
customer.setCity(city);
customer.setAddress(address);
customer.setAddress2(address2);
customer.setZip(zip);
customer.setPhone(phone);
customer.setEmail(email);
customer.setAdditionalInfo(additionalInfo);
return customer;
}
use of org.thingsboard.server.common.data.id.CustomerId in project thingsboard by thingsboard.
the class DeviceEntity method toData.
@Override
public Device toData() {
Device device = new Device(new DeviceId(getId()));
device.setCreatedTime(UUIDs.unixTimestamp(getId()));
if (tenantId != null) {
device.setTenantId(new TenantId(toUUID(tenantId)));
}
if (customerId != null) {
device.setCustomerId(new CustomerId(toUUID(customerId)));
}
device.setName(name);
device.setType(type);
device.setAdditionalInfo(additionalInfo);
return device;
}
use of org.thingsboard.server.common.data.id.CustomerId 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;
}
use of org.thingsboard.server.common.data.id.CustomerId in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindCustomerUsersByEmail.
@Test
public void testFindCustomerUsersByEmail() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
String email1 = "testEmail1";
List<User> customerUsersEmail1 = new ArrayList<>();
for (int i = 0; i < 124; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setTenantId(tenantId);
user.setCustomerId(customerId);
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);
customerUsersEmail1.add(userService.saveUser(user));
}
String email2 = "testEmail2";
List<User> customerUsersEmail2 = new ArrayList<>();
for (int i = 0; i < 132; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setTenantId(tenantId);
user.setCustomerId(customerId);
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);
customerUsersEmail2.add(userService.saveUser(user));
}
List<User> loadedCustomerUsersEmail1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(33, email1);
TextPageData<User> pageData = null;
do {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
loadedCustomerUsersEmail1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsersEmail1, idComparator);
Collections.sort(loadedCustomerUsersEmail1, idComparator);
Assert.assertEquals(customerUsersEmail1, loadedCustomerUsersEmail1);
List<User> loadedCustomerUsersEmail2 = new ArrayList<>();
pageLink = new TextPageLink(16, email2);
do {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
loadedCustomerUsersEmail2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsersEmail2, idComparator);
Collections.sort(loadedCustomerUsersEmail2, idComparator);
Assert.assertEquals(customerUsersEmail2, loadedCustomerUsersEmail2);
for (User user : loadedCustomerUsersEmail1) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email1);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (User user : loadedCustomerUsersEmail2) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email2);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
tenantService.deleteTenant(tenantId);
}
Aggregations