Add a generic check for configuration validator
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -15,11 +15,8 @@ package org.eclipse.hawkbit.tenancy.configuration.validator;
|
|||||||
public class TenantConfigurationBooleanValidator implements TenantConfigurationValidator {
|
public class TenantConfigurationBooleanValidator implements TenantConfigurationValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(final Object tenantConfigurationValue) {
|
public Class<?> validateToClass() {
|
||||||
if (tenantConfigurationValue instanceof Boolean) {
|
return Boolean.class;
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new TenantConfigurationValidatorException("The given configuration value is expected as a boolean.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ public class TenantConfigurationPollingDurationValidator implements TenantConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(final Object tenantConfigurationObject) {
|
public void validate(final Object tenantConfigurationObject) {
|
||||||
if (!(tenantConfigurationObject instanceof String)) {
|
TenantConfigurationValidator.super.validate(tenantConfigurationObject);
|
||||||
throw new TenantConfigurationValidatorException("The given configuration value is expected as a string.");
|
|
||||||
}
|
|
||||||
|
|
||||||
final String tenantConfigurationString = (String) tenantConfigurationObject;
|
final String tenantConfigurationString = (String) tenantConfigurationObject;
|
||||||
|
|
||||||
final Duration tenantConfigurationValue;
|
final Duration tenantConfigurationValue;
|
||||||
@@ -66,4 +63,9 @@ public class TenantConfigurationPollingDurationValidator implements TenantConfig
|
|||||||
durationHelper.durationToFormattedString(maxDuration)));
|
durationHelper.durationToFormattedString(maxDuration)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> validateToClass() {
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ package org.eclipse.hawkbit.tenancy.configuration.validator;
|
|||||||
public class TenantConfigurationStringValidator implements TenantConfigurationValidator {
|
public class TenantConfigurationStringValidator implements TenantConfigurationValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(final Object tenantConfigurationValue) {
|
public Class<?> validateToClass() {
|
||||||
if (tenantConfigurationValue instanceof String) {
|
return String.class;
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new TenantConfigurationValidatorException("The given configuration value is expected as a String.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,21 @@ public interface TenantConfigurationValidator {
|
|||||||
* @throws TenantConfigurationValidatorException
|
* @throws TenantConfigurationValidatorException
|
||||||
* is thrown, when parameter is invalid.
|
* is thrown, when parameter is invalid.
|
||||||
*/
|
*/
|
||||||
void validate(Object tenantConfigurationValue) throws TenantConfigurationValidatorException;
|
default void validate(final Object tenantConfigurationValue) throws TenantConfigurationValidatorException {
|
||||||
|
if (tenantConfigurationValue != null
|
||||||
|
&& validateToClass().isAssignableFrom(tenantConfigurationValue.getClass())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new TenantConfigurationValidatorException(
|
||||||
|
"The given configuration value is expected as a " + validateToClass().getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the generic class to check the object
|
||||||
|
*
|
||||||
|
* @return the class to check the value
|
||||||
|
*/
|
||||||
|
default Class<?> validateToClass() {
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user