Fix tenant not found error for notification rules
This commit is contained in:
parent
2c2273d15b
commit
02dc49fd3a
@ -17,6 +17,7 @@ package org.thingsboard.server.service.notification.rule.cache;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -29,7 +30,6 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||
import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg;
|
||||
import org.thingsboard.server.dao.notification.NotificationRuleService;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -71,7 +71,14 @@ public class DefaultNotificationRulesCache implements NotificationRulesCache {
|
||||
if (event.getEvent() == ComponentLifecycleEvent.DELETED) {
|
||||
lock.writeLock().lock(); // locking in case rules for tenant are fetched while evicting
|
||||
try {
|
||||
evict(event.getTenantId());
|
||||
for (var triggerType : NotificationRuleTriggerType.values()) {
|
||||
String key = key(event.getTenantId(), triggerType);
|
||||
/*
|
||||
* temporarily putting empty value because right after tenant deletion
|
||||
* the rules are still in the db, we don't want them to be fetched
|
||||
* */
|
||||
cache.put(key, Collections.emptyList());
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
@ -39,8 +39,6 @@ import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
||||
import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent;
|
||||
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
|
||||
import org.thingsboard.server.dao.mobile.MobileAppSettingsService;
|
||||
import org.thingsboard.server.dao.notification.NotificationRequestService;
|
||||
import org.thingsboard.server.dao.notification.NotificationRuleService;
|
||||
import org.thingsboard.server.dao.notification.NotificationSettingsService;
|
||||
import org.thingsboard.server.dao.service.PaginatedRemover;
|
||||
import org.thingsboard.server.dao.service.Validator;
|
||||
@ -168,8 +166,10 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
||||
adminSettingsService.deleteAdminSettingsByTenantId(tenantId);
|
||||
mobileAppSettingsService.deleteByTenantId(tenantId);
|
||||
notificationSettingsService.deleteNotificationSettings(tenantId);
|
||||
|
||||
tenantDao.removeById(tenantId, tenantId.getId());
|
||||
publishEvictEvent(new TenantEvictEvent(tenantId, true));
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(tenantId).entity(tenant).build());
|
||||
|
||||
cleanUpService.removeTenantEntities(tenantId, // don't forget to implement deleteEntity from EntityDaoService when adding entity type to this list
|
||||
EntityType.ENTITY_VIEW, EntityType.WIDGETS_BUNDLE, EntityType.WIDGET_TYPE,
|
||||
@ -179,7 +179,6 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
|
||||
EntityType.NOTIFICATION_REQUEST, EntityType.NOTIFICATION_RULE, EntityType.NOTIFICATION_TEMPLATE,
|
||||
EntityType.NOTIFICATION_TARGET, EntityType.QUEUE_STATS, EntityType.CUSTOMER
|
||||
);
|
||||
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(tenantId).entity(tenant).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user