|
|
|
@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.sync.ie.EntityImportSettings; |
|
|
|
import org.thingsboard.server.dao.customer.CustomerDao; |
|
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
import org.thingsboard.server.service.security.model.SecurityUser; |
|
|
|
@ -35,6 +36,7 @@ import org.thingsboard.server.common.data.sync.ie.EntityExportData; |
|
|
|
public class CustomerImportService extends BaseEntityImportService<CustomerId, Customer, EntityExportData<Customer>> { |
|
|
|
|
|
|
|
private final CustomerService customerService; |
|
|
|
private final CustomerDao customerDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void setOwner(TenantId tenantId, Customer customer, IdProvider idProvider) { |
|
|
|
@ -43,10 +45,12 @@ public class CustomerImportService extends BaseEntityImportService<CustomerId, C |
|
|
|
|
|
|
|
@Override |
|
|
|
protected Customer prepareAndSave(TenantId tenantId, Customer customer, EntityExportData<Customer> exportData, IdProvider idProvider, EntityImportSettings importSettings) { |
|
|
|
if (customer.isPublic()) { |
|
|
|
return customerService.findOrCreatePublicCustomer(tenantId); |
|
|
|
} else { |
|
|
|
if (!customer.isPublic()) { |
|
|
|
return customerService.saveCustomer(customer); |
|
|
|
} else { |
|
|
|
Customer publicCustomer = customerService.findOrCreatePublicCustomer(tenantId); |
|
|
|
publicCustomer.setExternalId(customer.getExternalId()); |
|
|
|
return customerDao.save(tenantId, publicCustomer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|