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(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.Customer in project thingsboard by thingsboard.
the class CassandraCustomerDao method findCustomersByTenantIdAndTitle.
@Override
public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) {
Select select = select().from(CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME);
Select.Where query = select.where();
query.and(eq(CUSTOMER_TENANT_ID_PROPERTY, tenantId));
query.and(eq(CUSTOMER_TITLE_PROPERTY, title));
CustomerEntity customerEntity = findOneByStatement(query);
Customer customer = DaoUtil.getData(customerEntity);
return Optional.ofNullable(customer);
}
use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class CustomerServiceImpl method saveCustomer.
@Override
public Customer saveCustomer(Customer customer) {
log.trace("Executing saveCustomer [{}]", customer);
customerValidator.validate(customer);
Customer savedCustomer = customerDao.save(customer);
dashboardService.updateCustomerDashboards(savedCustomer.getId());
return savedCustomer;
}
use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class CustomerServiceImpl method findOrCreatePublicCustomer.
@Override
public Customer findOrCreatePublicCustomer(TenantId tenantId) {
log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
Validator.validateId(tenantId, INCORRECT_CUSTOMER_ID + tenantId);
Optional<Customer> publicCustomerOpt = customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);
if (publicCustomerOpt.isPresent()) {
return publicCustomerOpt.get();
} else {
Customer publicCustomer = new Customer();
publicCustomer.setTenantId(tenantId);
publicCustomer.setTitle(PUBLIC_CUSTOMER_TITLE);
try {
publicCustomer.setAdditionalInfo(new ObjectMapper().readValue("{ \"isPublic\": true }", JsonNode.class));
} catch (IOException e) {
throw new IncorrectParameterException("Unable to create public customer.", e);
}
return customerDao.save(publicCustomer);
}
}
use of org.thingsboard.server.common.data.Customer in project thingsboard by thingsboard.
the class CustomerServiceImpl method deleteCustomer.
@Override
public void deleteCustomer(CustomerId customerId) {
log.trace("Executing deleteCustomer [{}]", customerId);
Validator.validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
Customer customer = findCustomerById(customerId);
if (customer == null) {
throw new IncorrectParameterException("Unable to delete non-existent customer.");
}
dashboardService.unassignCustomerDashboards(customerId);
assetService.unassignCustomerAssets(customer.getTenantId(), customerId);
deviceService.unassignCustomerDevices(customer.getTenantId(), customerId);
userService.deleteCustomerUsers(customer.getTenantId(), customerId);
deleteEntityRelations(customerId);
customerDao.removeById(customerId.getId());
}
Aggregations