Browse Source

replace getting tenant and checking it for null to invocations of 'exists' method

pull/5959/head
desoliture 5 years ago
parent
commit
27efb4adfc
  1. 3
      dao/src/main/java/org/thingsboard/server/dao/alarm/BaseAlarmService.java
  2. 3
      dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java
  3. 3
      dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
  4. 3
      dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java
  5. 3
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java
  6. 3
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
  7. 3
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java
  8. 3
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java
  9. 4
      dao/src/main/java/org/thingsboard/server/dao/ota/BaseOtaPackageService.java
  10. 3
      dao/src/main/java/org/thingsboard/server/dao/resource/BaseResourceService.java
  11. 3
      dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java
  12. 3
      dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java
  13. 4
      dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java
  14. 3
      dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java
  15. 3
      dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java

3
dao/src/main/java/org/thingsboard/server/dao/alarm/BaseAlarmService.java

@ -430,8 +430,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
if (alarm.getTenantId() == null) {
throw new DataValidationException("Alarm should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(alarm.getTenantId());
if (tenant == null) {
if (!tenantService.exists(alarm.getTenantId())) {
throw new DataValidationException("Alarm is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java

@ -411,8 +411,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
if (asset.getTenantId() == null) {
throw new DataValidationException("Asset should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(asset.getTenantId());
if (tenant == null) {
if (!tenantService.exists(asset.getTenantId())) {
throw new DataValidationException("Asset is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java

@ -210,8 +210,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom
if (customer.getTenantId() == null) {
throw new DataValidationException("Customer should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(customer.getTenantId());
if (tenant == null) {
if (!tenantService.exists(customer.getTenantId())) {
throw new DataValidationException("Customer is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/dashboard/DashboardServiceImpl.java

@ -308,8 +308,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
if (dashboard.getTenantId() == null) {
throw new DataValidationException("Dashboard should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(dashboard.getTenantId());
if (tenant == null) {
if (!tenantService.exists(dashboard.getTenantId())) {
throw new DataValidationException("Dashboard is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java

@ -375,8 +375,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
if (deviceProfile.getTenantId() == null) {
throw new DataValidationException("Device profile should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(deviceProfile.getTenantId());
if (tenant == null) {
if (!tenantService.exists(deviceProfile.getTenantId())) {
throw new DataValidationException("Device profile is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -731,8 +731,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
if (device.getTenantId() == null) {
throw new DataValidationException("Device should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(device.getTenantId());
if (tenant == null) {
if (!tenantService.exists(device.getTenantId())) {
throw new DataValidationException("Device is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

@ -413,8 +413,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
if (edge.getTenantId() == null) {
throw new DataValidationException("Edge should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(edge.getTenantId());
if (tenant == null) {
if (!tenantService.exists(edge.getTenantId())) {
throw new DataValidationException("Edge is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java

@ -446,8 +446,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
if (entityView.getTenantId() == null) {
throw new DataValidationException("Entity view should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(entityView.getTenantId());
if (tenant == null) {
if (!tenantService.exists(entityView.getTenantId())) {
throw new DataValidationException("Entity view is referencing to non-existent tenant!");
}
}

4
dao/src/main/java/org/thingsboard/server/dao/ota/BaseOtaPackageService.java

@ -357,9 +357,7 @@ public class BaseOtaPackageService implements OtaPackageService {
if (otaPackageInfo.getTenantId() == null) {
throw new DataValidationException("OtaPackage should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(otaPackageInfo.getTenantId());
// TODO: 12.01.22 Instead of finding and checking for null need to create and use tenantService.exists()
if (tenant == null) {
if (!tenantService.exists(otaPackageInfo.getTenantId())) {
throw new DataValidationException("OtaPackage is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/resource/BaseResourceService.java

@ -183,8 +183,7 @@ public class BaseResourceService implements ResourceService {
resource.setTenantId(new TenantId(ModelConstants.NULL_UUID));
}
if (!resource.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
Tenant tenant = tenantService.findTenantById(resource.getTenantId());
if (tenant == null) {
if (!tenantService.exists(resource.getTenantId())) {
throw new DataValidationException("Resource is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java

@ -726,8 +726,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
if (ruleChain.getTenantId() == null || ruleChain.getTenantId().isNullUid()) {
throw new DataValidationException("Rule chain should be assigned to tenant!");
}
Tenant tenant = tenantService.findTenantById(ruleChain.getTenantId());
if (tenant == null) {
if (!tenantService.exists(ruleChain.getTenantId())) {
throw new DataValidationException("Rule chain is referencing to non-existent tenant!");
}
if (ruleChain.isRoot() && RuleChainType.CORE.equals(ruleChain.getType())) {

3
dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java

@ -164,8 +164,7 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
if (apiUsageState.getTenantId() == null) {
throw new DataValidationException("ApiUsageState should be assigned to tenant!");
} else {
Tenant tenant = tenantService.findTenantById(apiUsageState.getTenantId());
if (tenant == null && !requestTenantId.equals(TenantId.SYS_TENANT_ID)) {
if (!tenantService.exists(apiUsageState.getTenantId()) && !requestTenantId.equals(TenantId.SYS_TENANT_ID)) {
throw new DataValidationException("ApiUsageState is referencing to non-existent tenant!");
}
}

4
dao/src/main/java/org/thingsboard/server/dao/user/UserServiceImpl.java

@ -448,9 +448,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
+ " already present in database!");
}
if (!tenantId.getId().equals(ModelConstants.NULL_UUID)) {
Tenant tenant = tenantService.findTenantById(user.getTenantId());
// TODO: 12.01.22 Instead of finding and checking for null need to create and use tenantService.exists()
if (tenant == null) {
if (!tenantService.exists(user.getTenantId())) {
throw new DataValidationException("User is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetTypeServiceImpl.java

@ -138,8 +138,7 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
widgetTypeDetails.setTenantId(new TenantId(ModelConstants.NULL_UUID));
}
if (!widgetTypeDetails.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
Tenant tenant = tenantService.findTenantById(widgetTypeDetails.getTenantId());
if (tenant == null) {
if (!tenantService.exists(widgetTypeDetails.getTenantId())) {
throw new DataValidationException("Widget type is referencing to non-existent tenant!");
}
}

3
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java

@ -162,8 +162,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
widgetsBundle.setTenantId(new TenantId(ModelConstants.NULL_UUID));
}
if (!widgetsBundle.getTenantId().getId().equals(ModelConstants.NULL_UUID)) {
Tenant tenant = tenantService.findTenantById(widgetsBundle.getTenantId());
if (tenant == null) {
if (!tenantService.exists(widgetsBundle.getTenantId())) {
throw new DataValidationException("Widgets bundle is referencing to non-existent tenant!");
}
}

Loading…
Cancel
Save