Create public customer during edge sync and push to edge
This commit is contained in:
parent
fa6d395ffa
commit
59b4049560
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.service.edge.rpc;
|
package org.thingsboard.server.service.edge.rpc;
|
||||||
|
|
||||||
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.edge.Edge;
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.service.edge.EdgeContextComponent;
|
import org.thingsboard.server.service.edge.EdgeContextComponent;
|
||||||
@ -53,8 +54,8 @@ public class EdgeSyncCursor {
|
|||||||
fetchers.add(new DeviceProfilesEdgeEventFetcher(ctx.getDeviceProfileService()));
|
fetchers.add(new DeviceProfilesEdgeEventFetcher(ctx.getDeviceProfileService()));
|
||||||
fetchers.add(new AssetProfilesEdgeEventFetcher(ctx.getAssetProfileService()));
|
fetchers.add(new AssetProfilesEdgeEventFetcher(ctx.getAssetProfileService()));
|
||||||
fetchers.add(new TenantAdminUsersEdgeEventFetcher(ctx.getUserService()));
|
fetchers.add(new TenantAdminUsersEdgeEventFetcher(ctx.getUserService()));
|
||||||
ctx.getCustomerService().findPublicCustomer(edge.getTenantId())
|
Customer publicCustomer = ctx.getCustomerService().findOrCreatePublicCustomer(edge.getTenantId());
|
||||||
.ifPresent(publicCustomer -> fetchers.add(new CustomerEdgeEventFetcher(publicCustomer.getId())));
|
fetchers.add(new CustomerEdgeEventFetcher(publicCustomer.getId()));
|
||||||
if (edge.getCustomerId() != null && !EntityId.NULL_UUID.equals(edge.getCustomerId().getId())) {
|
if (edge.getCustomerId() != null && !EntityId.NULL_UUID.equals(edge.getCustomerId().getId())) {
|
||||||
fetchers.add(new CustomerEdgeEventFetcher(edge.getCustomerId()));
|
fetchers.add(new CustomerEdgeEventFetcher(edge.getCustomerId()));
|
||||||
fetchers.add(new CustomerUsersEdgeEventFetcher(ctx.getUserService(), edge.getCustomerId()));
|
fetchers.add(new CustomerUsersEdgeEventFetcher(ctx.getUserService(), edge.getCustomerId()));
|
||||||
|
|||||||
@ -155,7 +155,7 @@ public class DefaultTbDeviceService extends AbstractTbEntityService implements T
|
|||||||
Device savedDevice = checkNotNull(deviceService.assignDeviceToCustomer(tenantId, deviceId, publicCustomer.getId()));
|
Device savedDevice = checkNotNull(deviceService.assignDeviceToCustomer(tenantId, deviceId, publicCustomer.getId()));
|
||||||
|
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, deviceId, savedDevice.getCustomerId(), savedDevice,
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, deviceId, savedDevice.getCustomerId(), savedDevice,
|
||||||
actionType, user, false, deviceId.toString(),
|
actionType, user, true, deviceId.toString(),
|
||||||
publicCustomer.getId().toString(), publicCustomer.getName());
|
publicCustomer.getId().toString(), publicCustomer.getName());
|
||||||
|
|
||||||
return savedDevice;
|
return savedDevice;
|
||||||
|
|||||||
@ -37,8 +37,6 @@ public interface CustomerService extends EntityDaoService {
|
|||||||
|
|
||||||
void deleteCustomer(TenantId tenantId, CustomerId customerId);
|
void deleteCustomer(TenantId tenantId, CustomerId customerId);
|
||||||
|
|
||||||
Optional<Customer> findPublicCustomer(TenantId tenantId);
|
|
||||||
|
|
||||||
Customer findOrCreatePublicCustomer(TenantId tenantId);
|
Customer findOrCreatePublicCustomer(TenantId tenantId);
|
||||||
|
|
||||||
PageData<Customer> findCustomersByTenantId(TenantId tenantId, PageLink pageLink);
|
PageData<Customer> findCustomersByTenantId(TenantId tenantId, PageLink pageLink);
|
||||||
|
|||||||
@ -133,18 +133,11 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
|
|||||||
customerDao.removeById(tenantId, customerId.getId());
|
customerDao.removeById(tenantId, customerId.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Customer> findPublicCustomer(TenantId tenantId) {
|
|
||||||
log.trace("Executing findPublicCustomer, tenantId [{}]", tenantId);
|
|
||||||
Validator.validateId(tenantId, INCORRECT_CUSTOMER_ID + tenantId);
|
|
||||||
return customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Customer findOrCreatePublicCustomer(TenantId tenantId) {
|
public Customer findOrCreatePublicCustomer(TenantId tenantId) {
|
||||||
log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
|
log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
|
||||||
Validator.validateId(tenantId, INCORRECT_CUSTOMER_ID + tenantId);
|
Validator.validateId(tenantId, INCORRECT_CUSTOMER_ID + tenantId);
|
||||||
Optional<Customer> publicCustomerOpt = findPublicCustomer(tenantId);
|
Optional<Customer> publicCustomerOpt = customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);
|
||||||
if (publicCustomerOpt.isPresent()) {
|
if (publicCustomerOpt.isPresent()) {
|
||||||
return publicCustomerOpt.get();
|
return publicCustomerOpt.get();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user