DataValidator: validateName renamed to validateString

This commit is contained in:
Sergey Matvienko 2023-09-05 16:34:30 +02:00
parent e69009c112
commit e36231364d
36 changed files with 47 additions and 47 deletions

View File

@ -86,7 +86,7 @@ public abstract class DataValidator<D extends BaseData<?>> {
public void validateDelete(TenantId tenantId, EntityId entityId) { public void validateDelete(TenantId tenantId, EntityId entityId) {
} }
public void validateName(String exceptionPrefix, String name) { public void validateString(String exceptionPrefix, String name) {
if (StringUtils.isEmpty(name) || name.trim().length() == 0) { if (StringUtils.isEmpty(name) || name.trim().length() == 0) {
throw new DataValidationException(exceptionPrefix + " should be specified!"); throw new DataValidationException(exceptionPrefix + " should be specified!");
} }

View File

@ -50,7 +50,7 @@ public class AdminSettingsDataValidator extends DataValidator<AdminSettings> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, AdminSettings adminSettings) { protected void validateDataImpl(TenantId tenantId, AdminSettings adminSettings) {
validateName("Key", adminSettings.getKey()); validateString("Key", adminSettings.getKey());
if (adminSettings.getJsonValue() == null) { if (adminSettings.getJsonValue() == null) {
throw new DataValidationException("Json value should be specified!"); throw new DataValidationException("Json value should be specified!");
} }

View File

@ -31,7 +31,7 @@ public class AlarmDataValidator extends DataValidator<Alarm> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Alarm alarm) { protected void validateDataImpl(TenantId tenantId, Alarm alarm) {
validateName("Alarm type", alarm.getType()); validateString("Alarm type", alarm.getType());
if (alarm.getOriginator() == null) { if (alarm.getOriginator() == null) {
throw new DataValidationException("Alarm originator should be specified!"); throw new DataValidationException("Alarm originator should be specified!");
} }

View File

@ -63,7 +63,7 @@ public class AssetDataValidator extends DataValidator<Asset> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Asset asset) { protected void validateDataImpl(TenantId tenantId, Asset asset) {
validateName("Asset name", asset.getName()); validateString("Asset name", asset.getName());
if (asset.getTenantId() == null) { if (asset.getTenantId() == null) {
throw new DataValidationException("Asset should be assigned to tenant!"); throw new DataValidationException("Asset should be assigned to tenant!");
} else { } else {

View File

@ -53,7 +53,7 @@ public class AssetProfileDataValidator extends DataValidator<AssetProfile> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, AssetProfile assetProfile) { protected void validateDataImpl(TenantId tenantId, AssetProfile assetProfile) {
validateName("Asset profile name", assetProfile.getName()); validateString("Asset profile name", assetProfile.getName());
if (assetProfile.getTenantId() == null) { if (assetProfile.getTenantId() == null) {
throw new DataValidationException("Asset profile should be assigned to tenant!"); throw new DataValidationException("Asset profile should be assigned to tenant!");
} else { } else {

View File

@ -41,7 +41,7 @@ public abstract class BaseOtaPackageDataValidator<D extends BaseData<?>> extends
private DeviceProfileDao deviceProfileDao; private DeviceProfileDao deviceProfileDao;
protected void validateImpl(OtaPackageInfo otaPackageInfo) { protected void validateImpl(OtaPackageInfo otaPackageInfo) {
validateName("OtaPackage title", otaPackageInfo.getTitle()); validateString("OtaPackage title", otaPackageInfo.getTitle());
if (otaPackageInfo.getTenantId() == null) { if (otaPackageInfo.getTenantId() == null) {
throw new DataValidationException("OtaPackage should be assigned to tenant!"); throw new DataValidationException("OtaPackage should be assigned to tenant!");

View File

@ -27,7 +27,7 @@ public class ComponentDescriptorDataValidator extends DataValidator<ComponentDes
@Override @Override
protected void validateDataImpl(TenantId tenantId, ComponentDescriptor plugin) { protected void validateDataImpl(TenantId tenantId, ComponentDescriptor plugin) {
validateName("Component name", plugin.getName()); validateString("Component name", plugin.getName());
if (plugin.getType() == null) { if (plugin.getType() == null) {
throw new DataValidationException("Component type should be specified!"); throw new DataValidationException("Component type should be specified!");
} }

View File

@ -63,7 +63,7 @@ public class CustomerDataValidator extends DataValidator<Customer> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Customer customer) { protected void validateDataImpl(TenantId tenantId, Customer customer) {
validateName("Customer title", customer.getTitle()); validateString("Customer title", customer.getTitle());
if (customer.getTitle().equals(CustomerServiceImpl.PUBLIC_CUSTOMER_TITLE)) { if (customer.getTitle().equals(CustomerServiceImpl.PUBLIC_CUSTOMER_TITLE)) {
throw new DataValidationException("'Public' title for customer is system reserved!"); throw new DataValidationException("'Public' title for customer is system reserved!");
} }

View File

@ -37,7 +37,7 @@ public class DashboardDataValidator extends DataValidator<Dashboard> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Dashboard dashboard) { protected void validateDataImpl(TenantId tenantId, Dashboard dashboard) {
validateName("Dashboard title", dashboard.getTitle()); validateString("Dashboard title", dashboard.getTitle());
if (dashboard.getTenantId() == null) { if (dashboard.getTenantId() == null) {
throw new DataValidationException("Dashboard should be assigned to tenant!"); throw new DataValidationException("Dashboard should be assigned to tenant!");
} else { } else {

View File

@ -60,7 +60,7 @@ public class DeviceDataValidator extends AbstractHasOtaPackageValidator<Device>
@Override @Override
protected void validateDataImpl(TenantId tenantId, Device device) { protected void validateDataImpl(TenantId tenantId, Device device) {
validateName("Device name", device.getName()); validateString("Device name", device.getName());
if (device.getTenantId() == null) { if (device.getTenantId() == null) {
throw new DataValidationException("Device should be assigned to tenant!"); throw new DataValidationException("Device should be assigned to tenant!");
} else { } else {

View File

@ -103,7 +103,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
@Override @Override
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) { protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) {
validateName("Device profile name", deviceProfile.getName()); validateString("Device profile name", deviceProfile.getName());
if (deviceProfile.getType() == null) { if (deviceProfile.getType() == null) {
throw new DataValidationException("Device profile type should be specified!"); throw new DataValidationException("Device profile type should be specified!");
} }

View File

@ -49,8 +49,8 @@ public class EdgeDataValidator extends DataValidator<Edge> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Edge edge) { protected void validateDataImpl(TenantId tenantId, Edge edge) {
validateName("Edge name", edge.getName()); validateString("Edge name", edge.getName());
validateName("Edge type", edge.getType()); validateString("Edge type", edge.getType());
if (StringUtils.isEmpty(edge.getSecret())) { if (StringUtils.isEmpty(edge.getSecret())) {
throw new DataValidationException("Edge secret should be specified!"); throw new DataValidationException("Edge secret should be specified!");
} }

View File

@ -58,8 +58,8 @@ public class EntityViewDataValidator extends DataValidator<EntityView> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, EntityView entityView) { protected void validateDataImpl(TenantId tenantId, EntityView entityView) {
validateName("Entity view name", entityView.getName()); validateString("Entity view name", entityView.getName());
validateName("Entity view type", entityView.getType()); validateString("Entity view type", entityView.getType());
if (entityView.getTenantId() == null) { if (entityView.getTenantId() == null) {
throw new DataValidationException("Entity view should be assigned to tenant!"); throw new DataValidationException("Entity view should be assigned to tenant!");
} else { } else {

View File

@ -66,7 +66,7 @@ public class ResourceDataValidator extends DataValidator<TbResource> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, TbResource resource) { protected void validateDataImpl(TenantId tenantId, TbResource resource) {
validateName("Resource title", resource.getTitle()); validateString("Resource title", resource.getTitle());
if (resource.getResourceType() == null) { if (resource.getResourceType() == null) {
throw new DataValidationException("Resource type should be specified!"); throw new DataValidationException("Resource type should be specified!");
} }

View File

@ -64,7 +64,7 @@ public class RuleChainDataValidator extends DataValidator<RuleChain> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, RuleChain ruleChain) { protected void validateDataImpl(TenantId tenantId, RuleChain ruleChain) {
validateName("Rule chain name", ruleChain.getName()); validateString("Rule chain name", ruleChain.getName());
if (ruleChain.getType() == null) { if (ruleChain.getType() == null) {
ruleChain.setType(RuleChainType.CORE); ruleChain.setType(RuleChainType.CORE);
} }

View File

@ -32,7 +32,7 @@ public class TenantDataValidator extends DataValidator<Tenant> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, Tenant tenant) { protected void validateDataImpl(TenantId tenantId, Tenant tenant) {
validateName("Tenant title", tenant.getTitle()); validateString("Tenant title", tenant.getTitle());
if (!StringUtils.isEmpty(tenant.getEmail())) { if (!StringUtils.isEmpty(tenant.getEmail())) {
validateEmail(tenant.getEmail()); validateEmail(tenant.getEmail());
} }

View File

@ -47,7 +47,7 @@ public class TenantProfileDataValidator extends DataValidator<TenantProfile> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, TenantProfile tenantProfile) { protected void validateDataImpl(TenantId tenantId, TenantProfile tenantProfile) {
validateName("Tenant profile name", tenantProfile.getName()); validateString("Tenant profile name", tenantProfile.getName());
if (tenantProfile.getProfileData() == null) { if (tenantProfile.getProfileData() == null) {
throw new DataValidationException("Tenant profile data should be specified!"); throw new DataValidationException("Tenant profile data should be specified!");
} }

View File

@ -37,7 +37,7 @@ public class WidgetTypeDataValidator extends DataValidator<WidgetTypeDetails> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, WidgetTypeDetails widgetTypeDetails) { protected void validateDataImpl(TenantId tenantId, WidgetTypeDetails widgetTypeDetails) {
validateName("Widgets type name", widgetTypeDetails.getName()); validateString("Widgets type name", widgetTypeDetails.getName());
if (widgetTypeDetails.getDescriptor() == null || widgetTypeDetails.getDescriptor().size() == 0) { if (widgetTypeDetails.getDescriptor() == null || widgetTypeDetails.getDescriptor().size() == 0) {
throw new DataValidationException("Widgets type descriptor can't be empty!"); throw new DataValidationException("Widgets type descriptor can't be empty!");
} }

View File

@ -34,7 +34,7 @@ public class WidgetsBundleDataValidator extends DataValidator<WidgetsBundle> {
@Override @Override
protected void validateDataImpl(TenantId tenantId, WidgetsBundle widgetsBundle) { protected void validateDataImpl(TenantId tenantId, WidgetsBundle widgetsBundle) {
validateName("Widgets bundle title", widgetsBundle.getTitle()); validateString("Widgets bundle title", widgetsBundle.getTitle());
if (widgetsBundle.getTenantId() == null) { if (widgetsBundle.getTenantId() == null) {
widgetsBundle.setTenantId(TenantId.fromUUID(ModelConstants.NULL_UUID)); widgetsBundle.setTenantId(TenantId.fromUUID(ModelConstants.NULL_UUID));
} }

View File

@ -41,12 +41,12 @@ public class DataValidatorTest {
"Gdy Pomorze nie pomoże, to pomoże może morze, a gdy morze nie pomoże, to pomoże może Gdańsk", "Gdy Pomorze nie pomoże, to pomoże może morze, a gdy morze nie pomoże, to pomoże może Gdańsk",
}) })
void validateName_thenOK(final String name) { void validateName_thenOK(final String name) {
dataValidator.validateName("Device name", name); dataValidator.validateString("Device name", name);
dataValidator.validateName("Asset name", name); dataValidator.validateString("Asset name", name);
dataValidator.validateName("Asset profile name", name); dataValidator.validateString("Asset profile name", name);
dataValidator.validateName("Alarm type", name); dataValidator.validateString("Alarm type", name);
dataValidator.validateName("Customer name", name); dataValidator.validateString("Customer name", name);
dataValidator.validateName("Tenant name", name); dataValidator.validateString("Tenant name", name);
} }
@ParameterizedTest @ParameterizedTest
@ -57,11 +57,11 @@ public class DataValidatorTest {
}) })
void validateName_thenDataValidationException(final String name) { void validateName_thenDataValidationException(final String name) {
DataValidationException exception; DataValidationException exception;
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateName("Asset name", name)); exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateString("Asset name", name));
log.warn("Exception message Asset name: {}", exception.getMessage()); log.warn("Exception message Asset name: {}", exception.getMessage());
assertThat(exception.getMessage()).as("message Asset name").containsPattern("Asset name .*"); assertThat(exception.getMessage()).as("message Asset name").containsPattern("Asset name .*");
exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateName("Device name", name)); exception = Assertions.assertThrows(DataValidationException.class, () -> dataValidator.validateString("Device name", name));
log.warn("Exception message Device name: {}", exception.getMessage()); log.warn("Exception message Device name: {}", exception.getMessage());
assertThat(exception.getMessage()).as("message Device name").containsPattern("Device name .*"); assertThat(exception.getMessage()).as("message Device name").containsPattern("Device name .*");
} }

View File

@ -44,7 +44,7 @@ class AdminSettingsDataValidatorTest {
adminSettings.setJsonValue(JacksonUtil.toJsonNode("{}")); adminSettings.setJsonValue(JacksonUtil.toJsonNode("{}"));
validator.validateDataImpl(tenantId, adminSettings); validator.validateDataImpl(tenantId, adminSettings);
verify(validator).validateName("Key", adminSettings.getKey()); verify(validator).validateString("Key", adminSettings.getKey());
} }
} }

View File

@ -55,7 +55,7 @@ class AlarmDataValidatorTest {
alarm.setTenantId(tenantId); alarm.setTenantId(tenantId);
validator.validateDataImpl(tenantId, alarm); validator.validateDataImpl(tenantId, alarm);
verify(validator).validateName("Alarm type", alarm.getType()); verify(validator).validateString("Alarm type", alarm.getType());
} }
} }

View File

@ -65,7 +65,7 @@ class AssetProfileDataValidatorTest {
assetProfile.setTenantId(tenantId); assetProfile.setTenantId(tenantId);
validator.validateDataImpl(tenantId, assetProfile); validator.validateDataImpl(tenantId, assetProfile);
verify(validator).validateName("Asset profile name", assetProfile.getName()); verify(validator).validateString("Asset profile name", assetProfile.getName());
} }
} }

View File

@ -54,7 +54,7 @@ class BaseOtaPackageDataValidatorTest {
otaPackageInfo.setTenantId(tenantId); otaPackageInfo.setTenantId(tenantId);
validator.validateImpl(otaPackageInfo); validator.validateImpl(otaPackageInfo);
verify(validator).validateName("OtaPackage title", otaPackageInfo.getTitle()); verify(validator).validateString("OtaPackage title", otaPackageInfo.getTitle());
} }

View File

@ -38,6 +38,6 @@ class ComponentDescriptorDataValidatorTest {
plugin.setName("originator attributes"); plugin.setName("originator attributes");
plugin.setClazz("org.thingsboard.rule.engine.metadata.TbGetAttributesNode"); plugin.setClazz("org.thingsboard.rule.engine.metadata.TbGetAttributesNode");
validator.validateDataImpl(TenantId.SYS_TENANT_ID, plugin); validator.validateDataImpl(TenantId.SYS_TENANT_ID, plugin);
verify(validator).validateName("Component name", plugin.getName()); verify(validator).validateString("Component name", plugin.getName());
} }
} }

View File

@ -53,7 +53,7 @@ class CustomerDataValidatorTest {
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
validator.validateDataImpl(tenantId, customer); validator.validateDataImpl(tenantId, customer);
verify(validator).validateName("Customer title", customer.getTitle()); verify(validator).validateString("Customer title", customer.getTitle());
} }
} }

View File

@ -50,7 +50,7 @@ class DashboardDataValidatorTest {
dashboard.setTenantId(tenantId); dashboard.setTenantId(tenantId);
validator.validateDataImpl(tenantId, dashboard); validator.validateDataImpl(tenantId, dashboard);
verify(validator).validateName("Dashboard title", dashboard.getTitle()); verify(validator).validateString("Dashboard title", dashboard.getTitle());
} }
} }

View File

@ -77,7 +77,7 @@ class DeviceProfileDataValidatorTest {
deviceProfile.setTenantId(tenantId); deviceProfile.setTenantId(tenantId);
validator.validateDataImpl(tenantId, deviceProfile); validator.validateDataImpl(tenantId, deviceProfile);
verify(validator).validateName("Device profile name", deviceProfile.getName()); verify(validator).validateString("Device profile name", deviceProfile.getName());
} }
} }

View File

@ -59,8 +59,8 @@ class EdgeDataValidatorTest {
edge.setTenantId(tenantId); edge.setTenantId(tenantId);
validator.validateDataImpl(tenantId, edge); validator.validateDataImpl(tenantId, edge);
verify(validator).validateName("Edge name", edge.getName()); verify(validator).validateString("Edge name", edge.getName());
verify(validator).validateName("Edge type", edge.getType()); verify(validator).validateString("Edge type", edge.getType());
} }
} }

View File

@ -57,8 +57,8 @@ class EntityViewDataValidatorTest {
entityView.setTenantId(tenantId); entityView.setTenantId(tenantId);
validator.validateDataImpl(tenantId, entityView); validator.validateDataImpl(tenantId, entityView);
verify(validator).validateName("Entity view name", entityView.getName()); verify(validator).validateString("Entity view name", entityView.getName());
verify(validator).validateName("Entity view type", entityView.getType()); verify(validator).validateString("Entity view type", entityView.getType());
} }
} }

View File

@ -63,7 +63,7 @@ class ResourceDataValidatorTest {
resource.setTenantId(tenantId); resource.setTenantId(tenantId);
validator.validateDataImpl(tenantId, resource); validator.validateDataImpl(tenantId, resource);
verify(validator).validateName("Resource title", resource.getTitle()); verify(validator).validateString("Resource title", resource.getTitle());
} }
} }

View File

@ -58,7 +58,7 @@ class RuleChainDataValidatorTest {
ruleChain.setTenantId(tenantId); ruleChain.setTenantId(tenantId);
validator.validateDataImpl(tenantId, ruleChain); validator.validateDataImpl(tenantId, ruleChain);
verify(validator).validateName("Rule chain name", ruleChain.getName()); verify(validator).validateString("Rule chain name", ruleChain.getName());
} }
} }

View File

@ -43,7 +43,7 @@ class TenantDataValidatorTest {
tenant.setEmail("support@thingsboard.io"); tenant.setEmail("support@thingsboard.io");
validator.validateDataImpl(tenantId, tenant); validator.validateDataImpl(tenantId, tenant);
verify(validator).validateName("Tenant title", tenant.getTitle()); verify(validator).validateString("Tenant title", tenant.getTitle());
} }
} }

View File

@ -50,7 +50,7 @@ class TenantProfileDataValidatorTest {
tenantProfile.setProfileData(tenantProfileData); tenantProfile.setProfileData(tenantProfileData);
validator.validateDataImpl(tenantId, tenantProfile); validator.validateDataImpl(tenantId, tenantProfile);
verify(validator).validateName("Tenant profile name", tenantProfile.getName()); verify(validator).validateString("Tenant profile name", tenantProfile.getName());
} }
} }

View File

@ -57,7 +57,7 @@ class WidgetTypeDataValidatorTest {
widgetTypeDetails.setTenantId(tenantId); widgetTypeDetails.setTenantId(tenantId);
validator.validateDataImpl(tenantId, widgetTypeDetails); validator.validateDataImpl(tenantId, widgetTypeDetails);
verify(validator).validateName("Widgets type name", widgetTypeDetails.getName()); verify(validator).validateString("Widgets type name", widgetTypeDetails.getName());
} }
} }

View File

@ -53,7 +53,7 @@ class WidgetsBundleDataValidatorTest {
widgetsBundle.setTenantId(tenantId); widgetsBundle.setTenantId(tenantId);
validator.validateDataImpl(tenantId, widgetsBundle); validator.validateDataImpl(tenantId, widgetsBundle);
verify(validator).validateName("Widgets bundle title", widgetsBundle.getTitle()); verify(validator).validateString("Widgets bundle title", widgetsBundle.getTitle());
} }
} }