Merge branch 'feature_MECS-86_tenant_specific_polling_configuration' of https://github.com/bsinno/hawkbit.git into feature_MECS-86_tenant_specific_polling_configuration

This commit is contained in:
SirWayne
2016-03-09 11:13:09 +01:00
17 changed files with 152 additions and 197 deletions

View File

@@ -75,8 +75,7 @@ public abstract class SpServerRtException extends RuntimeException {
}
/**
*
* @return the SpServerError
* @return the SpServerError which is wrapped by this exception
*/
public SpServerError getError() {
return error;

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.tenancy.configuration;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationBooleanValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator;
@@ -84,10 +84,18 @@ public enum TenantConfigurationKey {
private final Class<? extends TenantConfigurationValidator> validator;
/**
*
* @param key
* the property key name
* @param allowedValues
* @param defaultKeyName
* the allowed values for this specific key
* @param dataType
* the class of the property
* @param defaultValue
* value which should be returned, in case there is no value in
* the database
* @param validator
* Validator which validates, that property is of correct format
*/
private TenantConfigurationKey(final String key, final String defaultKeyName, final Class<?> dataType,
final String defaultValue, final Class<? extends TenantConfigurationValidator> validator) {
@@ -96,7 +104,6 @@ public enum TenantConfigurationKey {
this.defaultKeyName = defaultKeyName;
this.defaultValue = defaultValue;
this.validator = validator;
}
/**
@@ -138,17 +145,14 @@ public enum TenantConfigurationKey {
* @param value
* which will be validated
* @throws TenantConfigurationValidatorException
* is thrown when object is invalid.
* is thrown, when object is invalid
*/
public void validate(final ApplicationContext context, final Object value)
throws TenantConfigurationValidatorException {
final TenantConfigurationValidator createBean = context.getAutowireCapableBeanFactory().createBean(validator);
public void validate(final ApplicationContext context, final Object value) {
final TenantConfigurationValidator createdBean = context.getAutowireCapableBeanFactory().createBean(validator);
try {
createBean.validate(value);
} catch (final TenantConfigurationValidatorException ex) {
throw ex;
createdBean.validate(value);
} finally {
context.getAutowireCapableBeanFactory().destroyBean(createBean);
context.getAutowireCapableBeanFactory().destroyBean(createdBean);
}
}
@@ -156,17 +160,15 @@ public enum TenantConfigurationKey {
* @param keyName
* name of the TenantConfigurationKey
* @return the TenantConfigurationKey with the name keyName
* @throws InvalidTenantConfigurationKeyException
* if there is no TenantConfigurationKey with the name keyName
*/
public static TenantConfigurationKey fromKeyName(final String keyName)
throws InvalidTenantConfigurationKeyException {
public static TenantConfigurationKey fromKeyName(final String keyName) {
try {
return Arrays.stream(TenantConfigurationKey.values()).filter(conf -> conf.getKeyName().equals(keyName))
.findFirst().get();
} catch (final NoSuchElementException e) {
throw new InvalidTenantConfigurationKeyException("The given configuration key name does not exist.");
final Optional<TenantConfigurationKey> optKey = Arrays.stream(TenantConfigurationKey.values())
.filter(conf -> conf.getKeyName().equals(keyName)).findFirst();
if (optKey.isPresent()) {
return optKey.get();
}
throw new InvalidTenantConfigurationKeyException("The given configuration key name does not exist.");
}
}

View File

@@ -16,13 +16,12 @@ import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.springframework.beans.factory.annotation.Autowired;
/**
* specific tenant configuration validator, which validates that the given value
* is a String in the correct duration format..
* This class is used to validate, that the property is a String and that it is
* in the correct duration format.
*
*/
public class TenantConfigurationPollingDurationValidator implements TenantConfigurationValidator {
// private final ControllerPollProperties properties;
private final DurationHelper durationHelper = new DurationHelper();
private final Duration minDuration;
@@ -35,8 +34,6 @@ public class TenantConfigurationPollingDurationValidator implements TenantConfig
*/
@Autowired
public TenantConfigurationPollingDurationValidator(final ControllerPollProperties properties) {
// this.properties = properties;
minDuration = durationHelper.formattedStringToDuration(properties.getMinPollingTime());
maxDuration = durationHelper.formattedStringToDuration(properties.getMaxPollingTime());
}