Browse Source

Merge pull request #6624 from ViacheslavKlimov/vc-improvements

Fix import of public customer
pull/6641/head
Andrew Shvayka 4 years ago
committed by GitHub
parent
commit
2492b856f9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/CustomerImportService.java
  2. 2
      application/src/main/java/org/thingsboard/server/service/sync/vc/DefaultEntitiesVersionControlService.java

10
application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/CustomerImportService.java

@ -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);
}
}

2
application/src/main/java/org/thingsboard/server/service/sync/vc/DefaultEntitiesVersionControlService.java

@ -340,7 +340,7 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
DaoUtil.processInBatches(pageLink -> {
return exportableEntitiesService.findEntitiesByTenantId(user.getTenantId(), entityType, pageLink);
}, 100, entity -> {
if (!importedEntities.get(entityType).contains(entity.getId())) {
if (importedEntities.get(entityType) == null || !importedEntities.get(entityType).contains(entity.getId())) {
try {
exportableEntitiesService.checkPermission(user, entity, entityType, Operation.DELETE);
} catch (ThingsboardException e) {

Loading…
Cancel
Save