Browse Source

TbTenantService improvements

pull/6483/head
YevhenBondarenko 4 years ago
parent
commit
7cda81ef86
  1. 3
      application/src/main/java/org/thingsboard/server/service/entitiy/AbstractTbEntityService.java
  2. 14
      application/src/main/java/org/thingsboard/server/service/entitiy/DefaultTbNotificationEntityService.java
  3. 5
      application/src/main/java/org/thingsboard/server/service/entitiy/TbNotificationEntityService.java
  4. 8
      application/src/main/java/org/thingsboard/server/service/entitiy/tenant/DefaultTbTenantService.java

3
application/src/main/java/org/thingsboard/server/service/entitiy/AbstractTbEntityService.java

@ -88,9 +88,6 @@ public abstract class AbstractTbEntityService {
protected AlarmService alarmService;
@Autowired
protected EntityActionService entityActionService;
@Autowired
protected TbClusterService tbClusterService;
@Autowired
protected DeviceService deviceService;
@Autowired
protected AssetService assetService;

14
application/src/main/java/org/thingsboard/server/service/entitiy/DefaultTbNotificationEntityService.java

@ -42,6 +42,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.msg.TbMsg;
import org.thingsboard.server.common.msg.TbMsgDataType;
import org.thingsboard.server.common.msg.TbMsgMetaData;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.action.EntityActionService;
import org.thingsboard.server.service.gateway_device.GatewayNotificationsService;
import org.thingsboard.server.service.security.model.SecurityUser;
@ -50,6 +51,7 @@ import java.util.List;
@Slf4j
@Service
@TbCoreComponent
@RequiredArgsConstructor
public class DefaultTbNotificationEntityService implements TbNotificationEntityService {
private static final ObjectMapper json = new ObjectMapper();
@ -97,6 +99,18 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
sendEntityAssignToEdgeNotificationMsg(tenantId, edgeId, entityId, edgeActionType);
}
@Override
public void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event) {
tbClusterService.onTenantChange(tenant, null);
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), event);
}
@Override
public void notifyDeleteTenant(Tenant tenant) {
tbClusterService.onTenantDelete(tenant, null);
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), ComponentLifecycleEvent.DELETED);
}
@Override
public void notifyCreateOrUpdateDevice(TenantId tenantId, DeviceId deviceId, CustomerId customerId,
Device device, Device oldDevice, ActionType actionType,

5
application/src/main/java/org/thingsboard/server/service/entitiy/TbNotificationEntityService.java

@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.service.security.model.SecurityUser;
@ -56,6 +57,10 @@ public interface TbNotificationEntityService {
EdgeEventActionType edgeActionType,
SecurityUser user, Object... additionalInfo);
void notifyCreateOruUpdateTenant(Tenant tenant, ComponentLifecycleEvent event);
void notifyDeleteTenant(Tenant tenant);
void notifyCreateOrUpdateDevice(TenantId tenantId, DeviceId deviceId, CustomerId customerId, Device device,
Device oldDevice, ActionType actionType, SecurityUser user, Object... additionalInfo);

8
application/src/main/java/org/thingsboard/server/service/entitiy/tenant/DefaultTbTenantService.java

@ -44,9 +44,8 @@ public class DefaultTbTenantService extends AbstractTbEntityService implements T
installScripts.createDefaultEdgeRuleChains(savedTenant.getId());
}
tenantProfileCache.evict(savedTenant.getId());
tbClusterService.onTenantChange(savedTenant, null);
tbClusterService.broadcastEntityStateChangeEvent(savedTenant.getId(), savedTenant.getId(),
newTenant ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
notificationEntityService.notifyCreateOruUpdateTenant(tenant, newTenant ?
ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
return savedTenant;
} catch (Exception e) {
throw handleException(e);
@ -59,8 +58,7 @@ public class DefaultTbTenantService extends AbstractTbEntityService implements T
TenantId tenantId = tenant.getId();
tenantService.deleteTenant(tenantId);
tenantProfileCache.evict(tenantId);
tbClusterService.onTenantDelete(tenant, null);
tbClusterService.broadcastEntityStateChangeEvent(tenantId, tenantId, ComponentLifecycleEvent.DELETED);
notificationEntityService.notifyDeleteTenant(tenant);
} catch (Exception e) {
throw handleException(e);
}

Loading…
Cancel
Save