Search in sources :

Example 31 with Customer

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;
}
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 32 with 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);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) CustomerEntity(org.thingsboard.server.dao.model.nosql.CustomerEntity) Select(com.datastax.driver.core.querybuilder.Select)

Example 33 with 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;
}
Also used : Customer(org.thingsboard.server.common.data.Customer)

Example 34 with Customer

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);
    }
}
Also used : Customer(org.thingsboard.server.common.data.Customer) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 35 with Customer

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());
}
Also used : Customer(org.thingsboard.server.common.data.Customer) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException)

Aggregations

Customer (org.thingsboard.server.common.data.Customer)59 Test (org.junit.Test)37 CustomerId (org.thingsboard.server.common.data.id.CustomerId)24 Tenant (org.thingsboard.server.common.data.Tenant)21 ArrayList (java.util.ArrayList)18 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)18 User (org.thingsboard.server.common.data.User)16 TenantId (org.thingsboard.server.common.data.id.TenantId)14 Asset (org.thingsboard.server.common.data.asset.Asset)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)10 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)8 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 Device (org.thingsboard.server.common.data.Device)7 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AssetId (org.thingsboard.server.common.data.id.AssetId)3 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 UUID (java.util.UUID)2 Before (org.junit.Before)2