Merge pull request #9926 from thingsboard/fix/tenant-queues-creation

Fix isolated queues creation
This commit is contained in:
Andrew Shvayka 2024-01-02 13:34:21 +02:00 committed by GitHub
commit bef85e9654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,7 +38,6 @@ import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig;
import org.thingsboard.server.common.data.oauth2.OAuth2Registration; import org.thingsboard.server.common.data.oauth2.OAuth2Registration;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.common.data.security.UserCredentials; import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.dao.customer.CustomerService;
@ -47,12 +46,12 @@ import org.thingsboard.server.dao.oauth2.OAuth2User;
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
import org.thingsboard.server.dao.tenant.TenantService; import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.user.UserService; import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.service.entitiy.tenant.TbTenantService;
import org.thingsboard.server.service.entitiy.user.TbUserService; import org.thingsboard.server.service.entitiy.user.TbUserService;
import org.thingsboard.server.service.install.InstallScripts; import org.thingsboard.server.service.install.InstallScripts;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.model.UserPrincipal; import org.thingsboard.server.service.security.model.UserPrincipal;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
@ -71,6 +70,9 @@ public abstract class AbstractOAuth2ClientMapper {
@Autowired @Autowired
private TenantService tenantService; private TenantService tenantService;
@Autowired
private TbTenantService tbTenantService;
@Autowired @Autowired
private CustomerService customerService; private CustomerService customerService;
@ -171,19 +173,13 @@ public abstract class AbstractOAuth2ClientMapper {
} }
} }
private TenantId getTenantId(String tenantName) throws IOException { private TenantId getTenantId(String tenantName) throws Exception {
List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData(); List<Tenant> tenants = tenantService.findTenants(new PageLink(1, 0, tenantName)).getData();
Tenant tenant; Tenant tenant;
if (tenants == null || tenants.isEmpty()) { if (tenants == null || tenants.isEmpty()) {
tenant = new Tenant(); tenant = new Tenant();
tenant.setTitle(tenantName); tenant.setTitle(tenantName);
tenant = tenantService.saveTenant(tenant); tenant = tbTenantService.save(tenant);
installScripts.createDefaultRuleChains(tenant.getId());
installScripts.createDefaultEdgeRuleChains(tenant.getId());
tenantProfileCache.evict(tenant.getId());
tbClusterService.onTenantChange(tenant, null);
tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(),
ComponentLifecycleEvent.CREATED);
} else { } else {
tenant = tenants.get(0); tenant = tenants.get(0);
} }