TenantId for SYS_TENANT_ID refactored (new instances replaced with constant)

This commit is contained in:
Sergey Matvienko 2022-01-10 13:07:07 +02:00
parent d3987d1c67
commit 6f19efd539
12 changed files with 16 additions and 16 deletions

View File

@ -222,7 +222,7 @@ public class AppActor extends ContextAwareActor {
@Override @Override
public TbActorId createActorId() { public TbActorId createActorId() {
return new TbEntityActorId(new TenantId(EntityId.NULL_UUID)); return new TbEntityActorId(TenantId.SYS_TENANT_ID);
} }
@Override @Override

View File

@ -99,7 +99,7 @@ public class DatabaseHelper {
} }
} }
for (CustomerId customerId : customerIds) { for (CustomerId customerId : customerIds) {
dashboardService.assignDashboardToCustomer(new TenantId(EntityId.NULL_UUID), dashboardId, customerId); dashboardService.assignDashboardToCustomer(TenantId.SYS_TENANT_ID, dashboardId, customerId);
} }
}); });
} }

View File

@ -169,7 +169,7 @@ public class InstallScripts {
ruleChain = ruleChainService.saveRuleChain(ruleChain); ruleChain = ruleChainService.saveRuleChain(ruleChain);
ruleChainMetaData.setRuleChainId(ruleChain.getId()); ruleChainMetaData.setRuleChainId(ruleChain.getId());
ruleChainService.saveRuleChainMetaData(new TenantId(EntityId.NULL_UUID), ruleChainMetaData); ruleChainService.saveRuleChainMetaData(TenantId.SYS_TENANT_ID, ruleChainMetaData);
return ruleChain; return ruleChain;
} }
@ -217,7 +217,7 @@ public class InstallScripts {
dashboard.setTenantId(tenantId); dashboard.setTenantId(tenantId);
Dashboard savedDashboard = dashboardService.saveDashboard(dashboard); Dashboard savedDashboard = dashboardService.saveDashboard(dashboard);
if (customerId != null && !customerId.isNullUid()) { if (customerId != null && !customerId.isNullUid()) {
dashboardService.assignDashboardToCustomer(new TenantId(EntityId.NULL_UUID), savedDashboard.getId(), customerId); dashboardService.assignDashboardToCustomer(TenantId.SYS_TENANT_ID, savedDashboard.getId(), customerId);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unable to load dashboard from json: [{}]", path.toString()); log.error("Unable to load dashboard from json: [{}]", path.toString());

View File

@ -95,7 +95,7 @@ public class DefaultMailService implements MailService {
@Override @Override
public void updateMailConfiguration() { public void updateMailConfiguration() {
AdminSettings settings = adminSettingsService.findAdminSettingsByKey(new TenantId(EntityId.NULL_UUID), "mail"); AdminSettings settings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail");
if (settings != null) { if (settings != null) {
JsonNode jsonConfig = settings.getJsonValue(); JsonNode jsonConfig = settings.getJsonValue();
mailSender = createMailSender(jsonConfig); mailSender = createMailSender(jsonConfig);

View File

@ -75,7 +75,7 @@ public class RefreshTokenAuthenticationProvider implements AuthenticationProvide
} }
private SecurityUser authenticateByUserId(UserId userId) { private SecurityUser authenticateByUserId(UserId userId) {
TenantId systemId = new TenantId(EntityId.NULL_UUID); TenantId systemId = TenantId.SYS_TENANT_ID;
User user = userService.findUserById(systemId, userId); User user = userService.findUserById(systemId, userId);
if (user == null) { if (user == null) {
throw new UsernameNotFoundException("User not found by refresh token"); throw new UsernameNotFoundException("User not found by refresh token");
@ -99,7 +99,7 @@ public class RefreshTokenAuthenticationProvider implements AuthenticationProvide
} }
private SecurityUser authenticateByPublicId(String publicId) { private SecurityUser authenticateByPublicId(String publicId) {
TenantId systemId = new TenantId(EntityId.NULL_UUID); TenantId systemId = TenantId.SYS_TENANT_ID;
CustomerId customerId; CustomerId customerId;
try { try {
customerId = new CustomerId(UUID.fromString(publicId)); customerId = new CustomerId(UUID.fromString(publicId));

View File

@ -71,7 +71,7 @@ public class DefaultSmsService implements SmsService {
@Override @Override
public void updateSmsConfiguration() { public void updateSmsConfiguration() {
AdminSettings settings = adminSettingsService.findAdminSettingsByKey(new TenantId(EntityId.NULL_UUID), "sms"); AdminSettings settings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "sms");
if (settings != null) { if (settings != null) {
try { try {
JsonNode jsonConfig = settings.getJsonValue(); JsonNode jsonConfig = settings.getJsonValue();

View File

@ -279,7 +279,7 @@ public class HashPartitionService implements PartitionService {
tpi.tenantId(tenantId); tpi.tenantId(tenantId);
myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, tenantId); myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, tenantId);
} else { } else {
myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, new TenantId(TenantId.NULL_UUID)); myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, TenantId.SYS_TENANT_ID);
} }
List<Integer> partitions = myPartitions.get(myPartitionsSearchKey); List<Integer> partitions = myPartitions.get(myPartitionsSearchKey);
if (partitions != null) { if (partitions != null) {

View File

@ -51,7 +51,7 @@ public class BaseComponentDescriptorService implements ComponentDescriptorServic
@Override @Override
public ComponentDescriptor saveComponent(TenantId tenantId, ComponentDescriptor component) { public ComponentDescriptor saveComponent(TenantId tenantId, ComponentDescriptor component) {
componentValidator.validate(component, data -> new TenantId(EntityId.NULL_UUID)); componentValidator.validate(component, data -> TenantId.SYS_TENANT_ID);
Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(tenantId, component); Optional<ComponentDescriptor> result = componentDescriptorDao.saveIfNotExist(tenantId, component);
return result.orElseGet(() -> componentDescriptorDao.findByClazz(tenantId, component.getClazz())); return result.orElseGet(() -> componentDescriptorDao.findByClazz(tenantId, component.getClazz()));
} }

View File

@ -73,7 +73,7 @@ public class DeviceCredentialsServiceImpl extends AbstractEntityService implemen
public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) { public DeviceCredentials findDeviceCredentialsByCredentialsId(String credentialsId) {
log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId); log.trace("Executing findDeviceCredentialsByCredentialsId [{}]", credentialsId);
validateString(credentialsId, "Incorrect credentialsId " + credentialsId); validateString(credentialsId, "Incorrect credentialsId " + credentialsId);
return deviceCredentialsDao.findByCredentialsId(new TenantId(EntityId.NULL_UUID), credentialsId); return deviceCredentialsDao.findByCredentialsId(TenantId.SYS_TENANT_ID, credentialsId);
} }
@Override @Override

View File

@ -168,20 +168,20 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe
public PageData<Tenant> findTenants(PageLink pageLink) { public PageData<Tenant> findTenants(PageLink pageLink) {
log.trace("Executing findTenants pageLink [{}]", pageLink); log.trace("Executing findTenants pageLink [{}]", pageLink);
Validator.validatePageLink(pageLink); Validator.validatePageLink(pageLink);
return tenantDao.findTenantsByRegion(new TenantId(EntityId.NULL_UUID), DEFAULT_TENANT_REGION, pageLink); return tenantDao.findTenantsByRegion(TenantId.SYS_TENANT_ID, DEFAULT_TENANT_REGION, pageLink);
} }
@Override @Override
public PageData<TenantInfo> findTenantInfos(PageLink pageLink) { public PageData<TenantInfo> findTenantInfos(PageLink pageLink) {
log.trace("Executing findTenantInfos pageLink [{}]", pageLink); log.trace("Executing findTenantInfos pageLink [{}]", pageLink);
Validator.validatePageLink(pageLink); Validator.validatePageLink(pageLink);
return tenantDao.findTenantInfosByRegion(new TenantId(EntityId.NULL_UUID), DEFAULT_TENANT_REGION, pageLink); return tenantDao.findTenantInfosByRegion(TenantId.SYS_TENANT_ID, DEFAULT_TENANT_REGION, pageLink);
} }
@Override @Override
public void deleteTenants() { public void deleteTenants() {
log.trace("Executing deleteTenants"); log.trace("Executing deleteTenants");
tenantsRemover.removeEntities(new TenantId(EntityId.NULL_UUID), DEFAULT_TENANT_REGION); tenantsRemover.removeEntities(TenantId.SYS_TENANT_ID, DEFAULT_TENANT_REGION);
} }
private DataValidator<Tenant> tenantValidator = private DataValidator<Tenant> tenantValidator =

View File

@ -86,7 +86,7 @@ public abstract class AbstractServiceTest {
protected ObjectMapper mapper = new ObjectMapper(); protected ObjectMapper mapper = new ObjectMapper();
public static final TenantId SYSTEM_TENANT_ID = new TenantId(EntityId.NULL_UUID); public static final TenantId SYSTEM_TENANT_ID = TenantId.SYS_TENANT_ID;
@Autowired @Autowired
protected UserService userService; protected UserService userService;

View File

@ -158,7 +158,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
WidgetsBundle widgetsBundle = new WidgetsBundle(); WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setAlias(prefix + i); widgetsBundle.setAlias(prefix + i);
widgetsBundle.setTitle(prefix + i); widgetsBundle.setTitle(prefix + i);
widgetsBundle.setTenantId(new TenantId(NULL_UUID)); widgetsBundle.setTenantId(TenantId.SYS_TENANT_ID);
widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased())); widgetsBundle.setId(new WidgetsBundleId(Uuids.timeBased()));
widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle); widgetsBundleDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, widgetsBundle);
} }