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:
committed by
Nonnenmacher Fabian
parent
4be880587a
commit
ec79e9bd19
@@ -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.");
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -74,6 +74,10 @@ public abstract class SpServerRtException extends RuntimeException {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the SpServerError
|
||||
*/
|
||||
public SpServerError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user