Added REST interfaces for tenant configuration

- added GET, DELETE and PUT function on configuration value interfaces
- changed Exception in TenantConfigurationManagement for correct mapping to HTTP Status
- added function to get global configurations from TenantConfigurationManagement, to have
  only one class for handling these configuration values

Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-28 18:44:31 +01:00
committed by Nonnenmacher Fabian
parent 4be880587a
commit ec79e9bd19
20 changed files with 389 additions and 246 deletions

View File

@@ -181,7 +181,11 @@ public enum SpServerError {
*
*/
SP_CONFIGURATION_VALUE_INVALID("hawkbit.server.error.configValueInvalid",
"The given configuration value is invalid.");
"The given configuration value is invalid."),
/**
*
*/
SP_CONFIGURATION_KEY_INVALID("hawkbit.server.error.configKeyInvalid", "The given configuration key is invalid.");
/**
*

View File

@@ -74,6 +74,10 @@ public abstract class SpServerRtException extends RuntimeException {
this.error = error;
}
/**
*
* @return the SpServerError
*/
public SpServerError getError() {
return error;
}

View File

@@ -0,0 +1,55 @@
package org.eclipse.hawkbit.tenancy.configuration;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
/**
* The {@link #InvalidTenantConfigurationKeyException} is thrown when an invalid
* configuration key is used.
*
*/
public class InvalidTenantConfigurationKeyException extends SpServerRtException {
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_CONFIGURATION_KEY_INVALID;
/**
* Default constructor.
*/
public InvalidTenantConfigurationKeyException() {
super(THIS_ERROR);
}
/**
* Parameterized constructor.
*
* @param cause
* of the exception
*/
public InvalidTenantConfigurationKeyException(final Throwable cause) {
super(THIS_ERROR, cause);
}
/**
* Parameterized constructor.
*
* @param message
* of the exception
* @param cause
* of the exception
*/
public InvalidTenantConfigurationKeyException(final String message, final Throwable cause) {
super(message, THIS_ERROR, cause);
}
/**
* Parameterized constructor.
*
* @param message
* of the exception
*/
public InvalidTenantConfigurationKeyException(final String message) {
super(message, THIS_ERROR);
}
}

View File

@@ -9,12 +9,13 @@
package org.eclipse.hawkbit.tenancy.configuration;
import java.util.Arrays;
import java.util.NoSuchElementException;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationBooleanValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationStringValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidatorException;
import org.springframework.context.ApplicationContext;
/**
@@ -121,7 +122,8 @@ public enum TenantConfigurationKey {
/**
*
* @return the datatype of the tenant configuration value
* @return the data type of the tenant configuration value. (e.g.
* Integer.class, String.class)
*/
public Class<?> getDataType() {
return dataType;
@@ -150,9 +152,21 @@ public enum TenantConfigurationKey {
}
}
public static TenantConfigurationKey fromKeyName(final String keyName) {
/**
* @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 {
return Arrays.stream(TenantConfigurationKey.values()).filter(conf -> conf.getKeyName().equals(keyName))
.findFirst().get();
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.");
}
}
}

View File

@@ -1,7 +1,5 @@
package org.eclipse.hawkbit.tenancy.configuration.validator;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
/**
* specific tenant configuration validator, which validates that the given value is a booleans.
*/

View File

@@ -5,7 +5,6 @@ import java.time.format.DateTimeParseException;
import org.eclipse.hawkbit.ControllerPollProperties;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
import org.springframework.beans.factory.annotation.Autowired;
/**

View File

@@ -1,7 +1,5 @@
package org.eclipse.hawkbit.tenancy.configuration.validator;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
/**
* specific tenant configuration validator, which validates Strings.
*/

View File

@@ -1,7 +1,5 @@
package org.eclipse.hawkbit.tenancy.configuration.validator;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
/**
* base interface for clases which can validate tenant configuration values.
*

View File

@@ -1,4 +1,4 @@
package org.eclipse.hawkbit.tenancy.configuration.validator.exceptions;
package org.eclipse.hawkbit.tenancy.configuration.validator;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;