Moved tenant configuration functions to new management class

- moved fucntions to TenantConfigurationManagement, for better function capseling
- updated references
- updated references in tests, tests were succesfully

Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-27 17:00:39 +01:00
committed by Nonnenmacher Fabian
parent b56477191a
commit 6cef6aed1a
29 changed files with 466 additions and 373 deletions

View File

@@ -5,10 +5,10 @@ import java.time.Duration;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ControllerPollProperties;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.helper.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.tenantconfiguration.polling.DurationConfigField;
import org.eclipse.hawkbit.ui.utils.I18N;
@@ -40,7 +40,7 @@ public class PollingConfigurationView extends BaseConfigurationView
private ControllerPollProperties controllerPollProperties;
@Autowired
private transient SystemManagement systemManagement;
private transient TenantConfigurationManagement tenantConfigurationManagement;
private DurationConfigField fieldPollTime = null;
private DurationConfigField fieldPollingOverdueTime = null;
@@ -66,13 +66,13 @@ public class PollingConfigurationView extends BaseConfigurationView
globalPollTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingTime());
globalOverdueTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingOverdueTime());
final TenantConfigurationValue<String> pollTimeConfValue = systemManagement
final TenantConfigurationValue<String> pollTimeConfValue = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class);
if (!pollTimeConfValue.isGlobal()) {
tenantPollTime = durationHelper.formattedStringToDuration(pollTimeConfValue.getValue());
}
final TenantConfigurationValue<String> overdueTimeConfValue = systemManagement
final TenantConfigurationValue<String> overdueTimeConfValue = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class);
if (!overdueTimeConfValue.isGlobal()) {
tenantOverdueTime = durationHelper.formattedStringToDuration(overdueTimeConfValue.getValue());
@@ -97,7 +97,7 @@ public class PollingConfigurationView extends BaseConfigurationView
fieldPollingOverdueTime = DurationConfigField.builder().caption(i18n.get("configuration.polling.overduetime"))
.checkBoxLabel(i18n.get("configuration.polling.custom.value")).range(minDuration, maxDuration)
.globalDuration(globalPollTime).tenantDuration(tenantOverdueTime).build();
.globalDuration(globalOverdueTime).tenantDuration(tenantOverdueTime).build();
fieldPollingOverdueTime.addChangeListener(this);
vLayout.addComponent(fieldPollingOverdueTime);
@@ -111,14 +111,14 @@ public class PollingConfigurationView extends BaseConfigurationView
if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) {
tenantPollTime = fieldPollTime.getValue();
systemManagement.addOrUpdateConfiguration(
tenantConfigurationManagement.addOrUpdateConfiguration(
new TenantConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL.getKeyName(),
durationHelper.durationToFormattedString(tenantPollTime)));
}
if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) {
tenantOverdueTime = fieldPollingOverdueTime.getValue();
systemManagement.addOrUpdateConfiguration(
tenantConfigurationManagement.addOrUpdateConfiguration(
new TenantConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL.getKeyName(),
durationHelper.durationToFormattedString(tenantOverdueTime)));
}

View File

@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
@@ -34,20 +34,21 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay
private static final long serialVersionUID = 1L;
private final TenantConfigurationKey configurationKey;
private final transient SystemManagement systemManagement;
private final transient TenantConfigurationManagement tenantConfigurationManagement;
private final List<ConfigurationItemChangeListener> configurationChangeListeners = new ArrayList<>();
/**
* @param configurationKey
* the key for this configuration
* @param systemManagement
* the system management to retrive the configuration value
* @param tenantConfigurationManagement
* the tenant configuration management to retrieve the
* configuration value
*/
public AbstractAuthenticationTenantConfigurationItem(final TenantConfigurationKey configurationKey,
final SystemManagement systemManagement) {
final TenantConfigurationManagement tenantConfigurationManagement) {
this.configurationKey = configurationKey;
this.systemManagement = systemManagement;
this.tenantConfigurationManagement = tenantConfigurationManagement;
}
/**
@@ -66,15 +67,16 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay
*/
@Override
public boolean isConfigEnabled() {
final boolean b = systemManagement.getConfigurationValue(configurationKey, Boolean.class).getValue();
final boolean b = tenantConfigurationManagement.getConfigurationValue(configurationKey, Boolean.class)
.getValue();
return b;
}
/**
* @return the systemManagement
*/
protected SystemManagement getSystemManagement() {
return systemManagement;
protected TenantConfigurationManagement getTenantConfigurationManagement() {
return tenantConfigurationManagement;
}
/**

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
@@ -54,8 +54,9 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
* the system management to retrie the configuration
*/
@Autowired
public CertificateAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED, systemManagement);
public CertificateAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED, tenantConfigurationManagement);
}
/**
@@ -133,12 +134,12 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
}
if (configurationCaRootAuthorityChanged) {
final String value = caRootAuthorityTextField.getValue() != null ? caRootAuthorityTextField.getValue() : "";
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME.getKeyName(), value));
}
}
@@ -153,13 +154,13 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
configurationEnabledChange = false;
configurationCaRootAuthorityChanged = false;
configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class)
.getValue();
configurationEnabled = getTenantConfigurationManagement()
.getConfigurationValue(getConfigurationKey(), Boolean.class).getValue();
caRootAuthorityTextField.setValue(getCaRootAuthorityValue());
}
private String getCaRootAuthorityValue() {
return getSystemManagement()
return getTenantConfigurationManagement()
.getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class)
.getValue();
}

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
@@ -66,8 +66,9 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
* @param systemManagement
*/
@Autowired
public GatewaySecurityTokenAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, systemManagement);
public GatewaySecurityTokenAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, tenantConfigurationManagement);
}
/**
@@ -167,12 +168,12 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
}
private String getSecurityTokenName() {
return getSystemManagement().getConfigurationValue(
return getTenantConfigurationManagement().getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME, String.class).getValue();
}
private String getSecurityTokenKey() {
return getSystemManagement().getConfigurationValue(
return getTenantConfigurationManagement().getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue();
}
@@ -188,18 +189,18 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED.getKeyName(),
String.valueOf(configurationEnabled)));
}
if (keyNameChanged) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME.getKeyName(),
gatewayTokenNameTextField.getValue()));
}
if (keyChanged) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY.getKeyName(),
gatewayTokenkeyLabel.getValue()));
}

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.utils.I18N;
@@ -44,8 +44,9 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
* the system management to retrie the configuration
*/
@Autowired
public TargetSecurityTokenAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, systemManagement);
public TargetSecurityTokenAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, tenantConfigurationManagement);
}
/**
@@ -88,7 +89,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
}
}
@@ -96,7 +97,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
@Override
public void undo() {
configurationEnabledChange = false;
configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class)
.getValue();
configurationEnabled = getTenantConfigurationManagement()
.getConfigurationValue(getConfigurationKey(), Boolean.class).getValue();
}
}