Use TbNotificationEntityService in VC services
This commit is contained in:
parent
9484d62a93
commit
60deed2a73
@ -128,7 +128,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event) {
|
public void notifyCreateOrUpdateTenant(Tenant tenant, ComponentLifecycleEvent event) {
|
||||||
tbClusterService.onTenantChange(tenant, null);
|
tbClusterService.onTenantChange(tenant, null);
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), event);
|
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), event);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public interface TbNotificationEntityService {
|
|||||||
E entity, ActionType actionType,
|
E entity, ActionType actionType,
|
||||||
SecurityUser user, Object... additionalInfo);
|
SecurityUser user, Object... additionalInfo);
|
||||||
|
|
||||||
void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event);
|
void notifyCreateOrUpdateTenant(Tenant tenant, ComponentLifecycleEvent event);
|
||||||
|
|
||||||
|
|
||||||
void notifyDeleteTenant(Tenant tenant);
|
void notifyDeleteTenant(Tenant tenant);
|
||||||
|
|||||||
@ -54,7 +54,7 @@ public class DefaultTbTenantService extends AbstractTbEntityService implements T
|
|||||||
installScripts.createDefaultEdgeRuleChains(savedTenant.getId());
|
installScripts.createDefaultEdgeRuleChains(savedTenant.getId());
|
||||||
}
|
}
|
||||||
tenantProfileCache.evict(savedTenant.getId());
|
tenantProfileCache.evict(savedTenant.getId());
|
||||||
notificationEntityService.notifyCreateOruUpdateTenant(savedTenant, created ?
|
notificationEntityService.notifyCreateOrUpdateTenant(savedTenant, created ?
|
||||||
ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
|
|
||||||
TenantProfile oldTenantProfile = oldTenant != null ? tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, oldTenant.getTenantProfileId()) : null;
|
TenantProfile oldTenantProfile = oldTenant != null ? tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, oldTenant.getTenantProfileId()) : null;
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import org.thingsboard.server.dao.relation.RelationService;
|
|||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
import org.thingsboard.server.service.action.EntityActionService;
|
import org.thingsboard.server.service.action.EntityActionService;
|
||||||
import org.thingsboard.server.service.apiusage.RateLimitService;
|
import org.thingsboard.server.service.apiusage.RateLimitService;
|
||||||
|
import org.thingsboard.server.service.entitiy.TbNotificationEntityService;
|
||||||
import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
|
import org.thingsboard.server.service.sync.ie.exporting.EntityExportService;
|
||||||
import org.thingsboard.server.service.sync.ie.exporting.impl.BaseEntityExportService;
|
import org.thingsboard.server.service.sync.ie.exporting.impl.BaseEntityExportService;
|
||||||
import org.thingsboard.server.service.sync.ie.exporting.impl.DefaultEntityExportService;
|
import org.thingsboard.server.service.sync.ie.exporting.impl.DefaultEntityExportService;
|
||||||
@ -57,9 +58,9 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
|||||||
private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
|
private final Map<EntityType, EntityExportService<?, ?, ?>> exportServices = new HashMap<>();
|
||||||
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
|
private final Map<EntityType, EntityImportService<?, ?, ?>> importServices = new HashMap<>();
|
||||||
|
|
||||||
private final EntityActionService entityActionService;
|
|
||||||
private final RelationService relationService;
|
private final RelationService relationService;
|
||||||
private final RateLimitService rateLimitService;
|
private final RateLimitService rateLimitService;
|
||||||
|
private final TbNotificationEntityService entityNotificationService;
|
||||||
|
|
||||||
protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
|
protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
|
||||||
EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
|
EntityType.CUSTOMER, EntityType.ASSET, EntityType.RULE_CHAIN,
|
||||||
@ -109,10 +110,8 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
|||||||
relationService.saveRelations(ctx.getTenantId(), new ArrayList<>(ctx.getRelations()));
|
relationService.saveRelations(ctx.getTenantId(), new ArrayList<>(ctx.getRelations()));
|
||||||
|
|
||||||
for (EntityRelation relation : ctx.getRelations()) {
|
for (EntityRelation relation : ctx.getRelations()) {
|
||||||
entityActionService.logEntityAction(ctx.getUser(), relation.getFrom(), null, null,
|
entityNotificationService.notifyCreateOrUpdateOrDeleteRelation(ctx.getTenantId(), null,
|
||||||
ActionType.RELATION_ADD_OR_UPDATE, null, relation);
|
relation, ctx.getUser(), ActionType.RELATION_ADD_OR_UPDATE, null, relation);
|
||||||
entityActionService.logEntityAction(ctx.getUser(), relation.getTo(), null, null,
|
|
||||||
ActionType.RELATION_ADD_OR_UPDATE, null, relation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,14 +19,11 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.asset.Asset;
|
import org.thingsboard.server.common.data.asset.Asset;
|
||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
|
||||||
import org.thingsboard.server.common.data.id.AssetId;
|
import org.thingsboard.server.common.data.id.AssetId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
||||||
import org.thingsboard.server.dao.asset.AssetService;
|
import org.thingsboard.server.dao.asset.AssetService;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
|
||||||
import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
|
import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -52,14 +49,6 @@ public class AssetImportService extends BaseEntityImportService<AssetId, Asset,
|
|||||||
return assetService.saveAsset(asset);
|
return assetService.saveAsset(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEntitySaved(SecurityUser user, Asset savedAsset, Asset oldAsset) throws ThingsboardException {
|
|
||||||
super.onEntitySaved(user, savedAsset, oldAsset);
|
|
||||||
if (oldAsset != null) {
|
|
||||||
entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Asset deepCopy(Asset asset) {
|
protected Asset deepCopy(Asset asset) {
|
||||||
return new Asset(asset);
|
return new Asset(asset);
|
||||||
|
|||||||
@ -269,9 +269,8 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onEntitySaved(SecurityUser user, E savedEntity, E oldEntity) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, E savedEntity, E oldEntity) throws ThingsboardException {
|
||||||
entityActionService.logEntityAction(user, savedEntity.getId(), savedEntity,
|
entityNotificationService.notifyCreateOrUpdateEntity(user.getTenantId(), savedEntity.getId(), savedEntity,
|
||||||
savedEntity instanceof HasCustomerId ? ((HasCustomerId) savedEntity).getCustomerId() : user.getCustomerId(),
|
null, oldEntity == null ? ActionType.ADDED : ActionType.UPDATED, user);
|
||||||
oldEntity == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -68,14 +68,6 @@ public class CustomerImportService extends BaseEntityImportService<CustomerId, C
|
|||||||
return new Customer(customer);
|
return new Customer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEntitySaved(SecurityUser user, Customer savedCustomer, Customer oldCustomer) throws ThingsboardException {
|
|
||||||
super.onEntitySaved(user, savedCustomer, oldCustomer);
|
|
||||||
if (oldCustomer != null) {
|
|
||||||
entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.CUSTOMER;
|
return EntityType.CUSTOMER;
|
||||||
|
|||||||
@ -122,14 +122,6 @@ public class DashboardImportService extends BaseEntityImportService<DashboardId,
|
|||||||
return super.compare(ctx, exportData, prepared, existing) || !prepared.getConfiguration().equals(existing.getConfiguration());
|
return super.compare(ctx, exportData, prepared, existing) || !prepared.getConfiguration().equals(existing.getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEntitySaved(SecurityUser user, Dashboard savedDashboard, Dashboard oldDashboard) throws ThingsboardException {
|
|
||||||
super.onEntitySaved(user, savedDashboard, oldDashboard);
|
|
||||||
if (oldDashboard != null) {
|
|
||||||
entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return EntityType.DASHBOARD;
|
return EntityType.DASHBOARD;
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
@ -93,8 +94,8 @@ public class DeviceImportService extends BaseEntityImportService<DeviceId, Devic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEntitySaved(SecurityUser user, Device savedDevice, Device oldDevice) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, Device savedDevice, Device oldDevice) throws ThingsboardException {
|
||||||
super.onEntitySaved(user, savedDevice, oldDevice);
|
entityNotificationService.notifyCreateOrUpdateDevice(user.getTenantId(), savedDevice.getId(), savedDevice.getCustomerId(),
|
||||||
clusterService.onDeviceUpdated(savedDevice, oldDevice);
|
savedDevice, oldDevice, oldDevice == null ? ActionType.ADDED : ActionType.UPDATED, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -63,15 +63,13 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEntitySaved(SecurityUser user, DeviceProfile savedDeviceProfile, DeviceProfile oldDeviceProfile) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, DeviceProfile savedDeviceProfile, DeviceProfile oldDeviceProfile) throws ThingsboardException {
|
||||||
super.onEntitySaved(user, savedDeviceProfile, oldDeviceProfile);
|
|
||||||
clusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
clusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
||||||
clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedDeviceProfile.getId(),
|
clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedDeviceProfile.getId(),
|
||||||
oldDeviceProfile == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
oldDeviceProfile == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedDeviceProfile.getId(),
|
|
||||||
oldDeviceProfile == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
|
||||||
otaPackageStateService.update(savedDeviceProfile,
|
otaPackageStateService.update(savedDeviceProfile,
|
||||||
oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getFirmwareId(), savedDeviceProfile.getFirmwareId()),
|
oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getFirmwareId(), savedDeviceProfile.getFirmwareId()),
|
||||||
oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getSoftwareId(), savedDeviceProfile.getSoftwareId()));
|
oldDeviceProfile != null && !Objects.equals(oldDeviceProfile.getSoftwareId(), savedDeviceProfile.getSoftwareId()));
|
||||||
|
super.onEntitySaved(user, savedDeviceProfile, oldDeviceProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
|||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
|
||||||
import org.thingsboard.server.dao.entityview.EntityViewService;
|
import org.thingsboard.server.dao.entityview.EntityViewService;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
@ -64,9 +65,8 @@ public class EntityViewImportService extends BaseEntityImportService<EntityViewI
|
|||||||
protected void onEntitySaved(SecurityUser user, EntityView savedEntityView, EntityView oldEntityView) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, EntityView savedEntityView, EntityView oldEntityView) throws ThingsboardException {
|
||||||
tbEntityViewService.updateEntityViewAttributes(user, savedEntityView, oldEntityView);
|
tbEntityViewService.updateEntityViewAttributes(user, savedEntityView, oldEntityView);
|
||||||
super.onEntitySaved(user, savedEntityView, oldEntityView);
|
super.onEntitySaved(user, savedEntityView, oldEntityView);
|
||||||
if (oldEntityView != null) {
|
clusterService.broadcastEntityStateChangeEvent(savedEntityView.getTenantId(), savedEntityView.getId(),
|
||||||
entityActionService.sendEntityNotificationMsgToEdge(user.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
|
oldEntityView == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
@ -126,7 +127,8 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEntitySaved(SecurityUser user, RuleChain savedRuleChain, RuleChain oldRuleChain) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, RuleChain savedRuleChain, RuleChain oldRuleChain) throws ThingsboardException {
|
||||||
super.onEntitySaved(user, savedRuleChain, oldRuleChain);
|
entityActionService.logEntityAction(user, savedRuleChain.getId(), savedRuleChain, null,
|
||||||
|
oldRuleChain == null ? ActionType.ADDED : ActionType.UPDATED, null);
|
||||||
if (savedRuleChain.getType() == RuleChainType.CORE) {
|
if (savedRuleChain.getType() == RuleChainType.CORE) {
|
||||||
clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedRuleChain.getId(),
|
clusterService.broadcastEntityStateChangeEvent(user.getTenantId(), savedRuleChain.getId(),
|
||||||
oldRuleChain == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
oldRuleChain == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
||||||
|
|||||||
@ -93,7 +93,6 @@ public class WidgetsBundleImportService extends BaseEntityImportService<WidgetsB
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEntitySaved(SecurityUser user, WidgetsBundle savedWidgetsBundle, WidgetsBundle oldWidgetsBundle) throws ThingsboardException {
|
protected void onEntitySaved(SecurityUser user, WidgetsBundle savedWidgetsBundle, WidgetsBundle oldWidgetsBundle) throws ThingsboardException {
|
||||||
super.onEntitySaved(user, savedWidgetsBundle, oldWidgetsBundle);
|
|
||||||
entityNotificationService.notifySendMsgToEdgeService(user.getTenantId(), savedWidgetsBundle.getId(),
|
entityNotificationService.notifySendMsgToEdgeService(user.getTenantId(), savedWidgetsBundle.getId(),
|
||||||
oldWidgetsBundle == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
oldWidgetsBundle == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user