use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class CustomerEntity method toData.
@Override
public Customer toData() {
Customer customer = new Customer(new CustomerId(getId()));
customer.setCreatedTime(UUIDs.unixTimestamp(getId()));
customer.setTenantId(new TenantId(UUIDConverter.fromString(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.Customer in project thingsboard by thingsboard.
the class BaseAssetControllerTest method testAssignAssetToCustomerFromDifferentTenant.
@Test
public void testAssignAssetToCustomerFromDifferentTenant() throws Exception {
loginSysAdmin();
Tenant tenant2 = new Tenant();
tenant2.setTitle("Different tenant");
Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class);
Assert.assertNotNull(savedTenant2);
User tenantAdmin2 = new User();
tenantAdmin2.setAuthority(Authority.TENANT_ADMIN);
tenantAdmin2.setTenantId(savedTenant2.getId());
tenantAdmin2.setEmail("tenant3@thingsboard.org");
tenantAdmin2.setFirstName("Joe");
tenantAdmin2.setLastName("Downs");
tenantAdmin2 = createUserAndLogin(tenantAdmin2, "testPassword1");
Customer customer = new Customer();
customer.setTitle("Different customer");
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
login(tenantAdmin.getEmail(), "testPassword1");
Asset asset = new Asset();
asset.setName("My asset");
asset.setType("default");
Asset savedAsset = doPost("/api/asset", asset, Asset.class);
doPost("/api/customer/" + savedCustomer.getId().getId().toString() + "/asset/" + savedAsset.getId().getId().toString()).andExpect(status().isForbidden());
loginSysAdmin();
doDelete("/api/tenant/" + savedTenant2.getId().getId().toString()).andExpect(status().isOk());
}
use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class BaseAssetControllerTest method testFindCustomerAssetsByType.
@Test
public void testFindCustomerAssetsByType() throws Exception {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer = doPost("/api/customer", customer, Customer.class);
CustomerId customerId = customer.getId();
String title1 = "Asset title 1";
String type1 = "typeC";
List<Asset> assetsType1 = new ArrayList<>();
for (int i = 0; i < 125; i++) {
Asset asset = new Asset();
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type1);
asset = doPost("/api/asset", asset, Asset.class);
assetsType1.add(doPost("/api/customer/" + customerId.getId().toString() + "/asset/" + asset.getId().getId().toString(), Asset.class));
}
String title2 = "Asset title 2";
String type2 = "typeD";
List<Asset> assetsType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
Asset asset = new Asset();
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type2);
asset = doPost("/api/asset", asset, Asset.class);
assetsType2.add(doPost("/api/customer/" + customerId.getId().toString() + "/asset/" + asset.getId().getId().toString(), Asset.class));
}
List<Asset> loadedAssetsType1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15);
TextPageData<Asset> pageData = null;
do {
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type1);
loadedAssetsType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType1, idComparator);
Collections.sort(loadedAssetsType1, idComparator);
Assert.assertEquals(assetsType1, loadedAssetsType1);
List<Asset> loadedAssetsType2 = new ArrayList<>();
pageLink = new TextPageLink(4);
do {
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type2);
loadedAssetsType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType2, idComparator);
Collections.sort(loadedAssetsType2, idComparator);
Assert.assertEquals(assetsType2, loadedAssetsType2);
for (Asset asset : loadedAssetsType1) {
doDelete("/api/customer/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new TextPageLink(4);
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type1);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Asset asset : loadedAssetsType2) {
doDelete("/api/customer/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new TextPageLink(4);
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type2);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class BaseCustomerControllerTest method testFindCustomerById.
@Test
public void testFindCustomerById() throws Exception {
loginSysAdmin();
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
Assert.assertNotNull(savedTenant);
User tenantAdmin = new User();
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
tenantAdmin.setTenantId(savedTenant.getId());
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);
Customer foundCustomer = doGet("/api/customer/" + savedCustomer.getId().getId().toString(), Customer.class);
Assert.assertNotNull(foundCustomer);
Assert.assertEquals(savedCustomer, foundCustomer);
doDelete("/api/customer/" + savedCustomer.getId().getId().toString()).andExpect(status().isOk());
loginSysAdmin();
doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
use of org.thingsboard.server.common.data.Customer 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());
}
Aggregations