added notification entities to the TenantIdLoader

This commit is contained in:
YevhenBondarenko 2023-03-23 23:39:57 +01:00
parent b10e162b19
commit b53f656f72
5 changed files with 122 additions and 1 deletions

View File

@ -70,6 +70,11 @@ import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.event.EventService;
import org.thingsboard.server.dao.nosql.CassandraBufferedRateReadExecutor;
import org.thingsboard.server.dao.nosql.CassandraBufferedRateWriteExecutor;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleProcessingService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.relation.RelationService;
@ -95,7 +100,6 @@ import org.thingsboard.server.service.executors.ExternalCallExecutorService;
import org.thingsboard.server.service.executors.NotificationExecutorService;
import org.thingsboard.server.service.executors.SharedEventLoopGroupService;
import org.thingsboard.server.service.mail.MailExecutorService;
import org.thingsboard.server.dao.notification.NotificationRuleProcessingService;
import org.thingsboard.server.service.profile.TbAssetProfileCache;
import org.thingsboard.server.service.profile.TbDeviceProfileCache;
import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService;
@ -339,6 +343,22 @@ public class ActorSystemContext {
@Getter
private NotificationRuleProcessingService notificationRuleProcessingService;
@Autowired
@Getter
private NotificationTargetService notificationTargetService;
@Autowired
@Getter
private NotificationTemplateService notificationTemplateService;
@Autowired
@Getter
private NotificationRequestService notificationRequestService;
@Autowired
@Getter
private NotificationRuleService notificationRuleService;
@Autowired
@Getter
private SlackService slackService;

View File

@ -88,6 +88,10 @@ import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.nosql.CassandraStatementTask;
import org.thingsboard.server.dao.nosql.TbResultSetFuture;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.relation.RelationService;
@ -698,6 +702,26 @@ class DefaultTbContext implements TbContext {
return mainCtx.getNotificationCenter();
}
@Override
public NotificationTargetService getNotificationTargetService() {
return mainCtx.getNotificationTargetService();
}
@Override
public NotificationTemplateService getNotificationTemplateService() {
return mainCtx.getNotificationTemplateService();
}
@Override
public NotificationRequestService getNotificationRequestService() {
return mainCtx.getNotificationRequestService();
}
@Override
public NotificationRuleService getNotificationRuleService() {
return mainCtx.getNotificationRuleService();
}
@Override
public SlackService getSlackService() {
return mainCtx.getSlackService();

View File

@ -58,6 +58,10 @@ import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.nosql.CassandraStatementTask;
import org.thingsboard.server.dao.nosql.TbResultSetFuture;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.relation.RelationService;
@ -288,6 +292,14 @@ public interface TbContext {
NotificationCenter getNotificationCenter();
NotificationTargetService getNotificationTargetService();
NotificationTemplateService getNotificationTemplateService();
NotificationRequestService getNotificationRequestService();
NotificationRuleService getNotificationRuleService();
SlackService getSlackService();
/**

View File

@ -29,6 +29,10 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityViewId;
import org.thingsboard.server.common.data.id.NotificationRequestId;
import org.thingsboard.server.common.data.id.NotificationRuleId;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.NotificationTemplateId;
import org.thingsboard.server.common.data.id.OtaPackageId;
import org.thingsboard.server.common.data.id.QueueId;
import org.thingsboard.server.common.data.id.RpcId;
@ -123,6 +127,20 @@ public class TenantIdLoader {
tenantEntity = null;
}
break;
case NOTIFICATION_TARGET:
tenantEntity = ctx.getNotificationTargetService().findNotificationTargetById(ctxTenantId, new NotificationTargetId(id));
break;
case NOTIFICATION_TEMPLATE:
tenantEntity = ctx.getNotificationTemplateService().findNotificationTemplateById(ctxTenantId, new NotificationTemplateId(id));
break;
case NOTIFICATION_REQUEST:
tenantEntity = ctx.getNotificationRequestService().findNotificationRequestById(ctxTenantId, new NotificationRequestId(id));
break;
case NOTIFICATION:
return ctxTenantId;
case NOTIFICATION_RULE:
tenantEntity = ctx.getNotificationRuleService().findNotificationRuleById(ctxTenantId, new NotificationRuleId(id));
break;
default:
throw new RuntimeException("Unexpected entity type: " + entityId.getEntityType());
}

View File

@ -48,8 +48,13 @@ import org.thingsboard.server.common.data.id.AssetProfileId;
import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.NotificationId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.TenantProfileId;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.common.data.notification.rule.NotificationRule;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.notification.template.NotificationTemplate;
import org.thingsboard.server.common.data.queue.Queue;
import org.thingsboard.server.common.data.rpc.Rpc;
import org.thingsboard.server.common.data.rule.RuleChain;
@ -63,6 +68,11 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.resource.ResourceService;
@ -121,9 +131,20 @@ public class TenantIdLoaderTest {
private RuleEngineRpcService rpcService;
@Mock
private RuleEngineApiUsageStateService ruleEngineApiUsageStateService;
@Mock
private NotificationTargetService notificationTargetService;
@Mock
private NotificationTemplateService notificationTemplateService;
@Mock
private NotificationRequestService notificationRequestService;
@Mock
private NotificationService notificationService;
@Mock
private NotificationRuleService notificationRuleService;
private TenantId tenantId;
private TenantProfileId tenantProfileId;
private NotificationId notificationId;
private AbstractListeningExecutor dbExecutor;
@Before
@ -137,6 +158,7 @@ public class TenantIdLoaderTest {
dbExecutor.init();
this.tenantId = new TenantId(UUID.randomUUID());
this.tenantProfileId = new TenantProfileId(UUID.randomUUID());
this.notificationId = new NotificationId(UUID.randomUUID());
when(ctx.getTenantId()).thenReturn(tenantId);
@ -153,6 +175,7 @@ public class TenantIdLoaderTest {
private void initMocks(EntityType entityType, TenantId tenantId) {
switch (entityType) {
case TENANT:
case NOTIFICATION:
break;
case CUSTOMER:
Customer customer = new Customer();
@ -310,6 +333,30 @@ public class TenantIdLoaderTest {
when(ctx.getTenantProfile()).thenReturn(tenantProfile);
break;
case NOTIFICATION_TARGET:
NotificationTarget notificationTarget = new NotificationTarget();
notificationTarget.setTenantId(tenantId);
when(ctx.getNotificationTargetService()).thenReturn(notificationTargetService);
doReturn(notificationTarget).when(notificationTargetService).findNotificationTargetById(eq(tenantId), any());
break;
case NOTIFICATION_TEMPLATE:
NotificationTemplate notificationTemplate = new NotificationTemplate();
notificationTemplate.setTenantId(tenantId);
when(ctx.getNotificationTemplateService()).thenReturn(notificationTemplateService);
doReturn(notificationTemplate).when(notificationTemplateService).findNotificationTemplateById(eq(tenantId), any());
break;
case NOTIFICATION_REQUEST:
NotificationRequest notificationRequest = new NotificationRequest();
notificationRequest.setTenantId(tenantId);
when(ctx.getNotificationRequestService()).thenReturn(notificationRequestService);
doReturn(notificationRequest).when(notificationRequestService).findNotificationRequestById(eq(tenantId), any());
break;
case NOTIFICATION_RULE:
NotificationRule notificationRule = new NotificationRule();
notificationRule.setTenantId(tenantId);
when(ctx.getNotificationRuleService()).thenReturn(notificationRuleService);
doReturn(notificationRule).when(notificationRuleService).findNotificationRuleById(eq(tenantId), any());
break;
default:
throw new RuntimeException("Unexpected original EntityType " + entityType);