Updated UI to use new database structure
* use new methods to store polling Configuration * refactored DurationConfigField, added Builder Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
committed by
Nonnenmacher Fabian
parent
07fce42469
commit
3f2c0d134a
@@ -15,7 +15,7 @@ import java.time.temporal.TemporalAccessor;
|
||||
public class DurationHelper {
|
||||
|
||||
/**
|
||||
* Format of the String expected in configuration file and in the databse.
|
||||
* Format of the String expected in configuration file and in the database.
|
||||
*/
|
||||
public static final String DURATION_FORMAT = "HH:mm:ss";
|
||||
|
||||
@@ -27,7 +27,7 @@ public class DurationHelper {
|
||||
* @return String in the duration format, specified at
|
||||
* {@link #DURATION_FORMAT}
|
||||
*/
|
||||
public String durationToFormattedString(Duration duration) {
|
||||
public String durationToFormattedString(final Duration duration) {
|
||||
if (duration == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class DurationHelper {
|
||||
* @throws DateTimeParseException
|
||||
* when String is in wrong format
|
||||
*/
|
||||
public Duration formattedStringToDuration(String formattedDuration) throws DateTimeParseException {
|
||||
public Duration formattedStringToDuration(final String formattedDuration) throws DateTimeParseException {
|
||||
if (formattedDuration == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class DurationHelper {
|
||||
* count of seconds
|
||||
* @return duration
|
||||
*/
|
||||
public Duration getDurationByTimeValues(long hours, long minutes, long seconds) {
|
||||
public Duration getDurationByTimeValues(final long hours, final long minutes, final long seconds) {
|
||||
return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ import java.time.Duration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.eclipse.hawkbit.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.TenantMetaData;
|
||||
import org.eclipse.hawkbit.repository.model.helper.PollConfigurationHelper;
|
||||
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.TenantConfigurationKey;
|
||||
import org.eclipse.hawkbit.ui.tenantconfiguration.polling.DurationConfigField;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -34,19 +37,23 @@ public class PollingConfigurationView extends BaseConfigurationView
|
||||
private I18N i18n;
|
||||
|
||||
@Autowired
|
||||
PollConfigurationHelper pollConfigurationHelper;
|
||||
private ControllerPollProperties controllerPollProperties;
|
||||
|
||||
@Autowired
|
||||
private transient SystemManagement systemManagement;
|
||||
|
||||
@Autowired
|
||||
private DurationConfigField fieldPollingTime;
|
||||
private DurationConfigField fieldPollTime = null;
|
||||
private DurationConfigField fieldPollingOverdueTime = null;
|
||||
|
||||
@Autowired
|
||||
private DurationConfigField fieldPollingOverdueTime;
|
||||
private Duration minDuration;
|
||||
private Duration maxDuration;
|
||||
private Duration globalPollTime;
|
||||
private Duration globalOverdueTime;
|
||||
|
||||
private Duration tenantPollingTime;
|
||||
private Duration tenantPollingOverdueTime;
|
||||
private Duration tenantPollTime = null;
|
||||
private Duration tenantOverdueTime = null;
|
||||
|
||||
private final DurationHelper durationHelper = new DurationHelper();
|
||||
|
||||
/**
|
||||
* Initialize Authentication Configuration layout.
|
||||
@@ -54,37 +61,44 @@ public class PollingConfigurationView extends BaseConfigurationView
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
minDuration = durationHelper.formattedStringToDuration(controllerPollProperties.getMinPollingTime());
|
||||
maxDuration = durationHelper.formattedStringToDuration(controllerPollProperties.getMaxPollingTime());
|
||||
globalPollTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingTime());
|
||||
globalOverdueTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingOverdueTime());
|
||||
|
||||
final TenantConfigurationValue<String> pollTimeConfValue = systemManagement
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class);
|
||||
if (!pollTimeConfValue.isGlobal()) {
|
||||
tenantPollTime = durationHelper.formattedStringToDuration(pollTimeConfValue.getValue());
|
||||
}
|
||||
|
||||
final TenantConfigurationValue<String> overdueTimeConfValue = systemManagement
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class);
|
||||
if (!overdueTimeConfValue.isGlobal()) {
|
||||
tenantOverdueTime = durationHelper.formattedStringToDuration(overdueTimeConfValue.getValue());
|
||||
}
|
||||
|
||||
final Panel rootPanel = new Panel();
|
||||
rootPanel.setSizeFull();
|
||||
rootPanel.addStyleName("config-panel");
|
||||
|
||||
final VerticalLayout vLayout = new VerticalLayout();
|
||||
vLayout.setMargin(true);
|
||||
// vLayout.setSizeFull();
|
||||
|
||||
final Label headerDisSetType = new Label(i18n.get("configuration.polling.title"));
|
||||
headerDisSetType.addStyleName("config-panel-header");
|
||||
vLayout.addComponent(headerDisSetType);
|
||||
|
||||
final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata();
|
||||
fieldPollTime = DurationConfigField.builder().caption(i18n.get("configuration.polling.time"))
|
||||
.checkBoxLabel(i18n.get("configuration.polling.custom.value")).range(minDuration, maxDuration)
|
||||
.globalDuration(globalPollTime).tenantDuration(tenantPollTime).build();
|
||||
fieldPollTime.addChangeListener(this);
|
||||
vLayout.addComponent(fieldPollTime);
|
||||
|
||||
tenantPollingTime = tenantMetaData.getPollingTime();
|
||||
fieldPollingTime.setInitValues(i18n.get("configuration.polling.time"), tenantPollingTime,
|
||||
pollConfigurationHelper.getGlobalPollTimeInterval());
|
||||
fieldPollingTime.setAllowedRange(pollConfigurationHelper.getMinimumPollingInterval(),
|
||||
pollConfigurationHelper.getMaximumPollingInterval());
|
||||
fieldPollingTime.addChangeListener(this);
|
||||
|
||||
vLayout.addComponent(fieldPollingTime);
|
||||
|
||||
tenantPollingOverdueTime = tenantMetaData.getPollingOverdueTime();
|
||||
|
||||
fieldPollingOverdueTime.setInitValues(i18n.get("configuration.polling.overduetime"), tenantPollingOverdueTime,
|
||||
pollConfigurationHelper.getGlobalOverduePollTimeInterval());
|
||||
fieldPollingOverdueTime.setAllowedRange(pollConfigurationHelper.getMinimumPollingInterval(),
|
||||
pollConfigurationHelper.getMaximumPollingInterval());
|
||||
fieldPollingOverdueTime = DurationConfigField.builder().caption(i18n.get("configuration.polling.overduetime"))
|
||||
.checkBoxLabel(i18n.get("configuration.polling.custom.value")).range(minDuration, maxDuration)
|
||||
.globalDuration(globalPollTime).tenantDuration(tenantOverdueTime).build();
|
||||
fieldPollingOverdueTime.addChangeListener(this);
|
||||
|
||||
vLayout.addComponent(fieldPollingOverdueTime);
|
||||
|
||||
rootPanel.setContent(vLayout);
|
||||
@@ -95,36 +109,30 @@ public class PollingConfigurationView extends BaseConfigurationView
|
||||
public void save() {
|
||||
// make sure values are only saved, when the value has been changed
|
||||
|
||||
boolean hasChanged = false;
|
||||
|
||||
final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata();
|
||||
|
||||
if (!compareDurations(tenantPollingTime, fieldPollingTime.getValue())) {
|
||||
tenantPollingTime = fieldPollingTime.getValue();
|
||||
tenantMetaData.setPollingTime(fieldPollingTime.getValue());
|
||||
hasChanged = true;
|
||||
if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) {
|
||||
tenantPollTime = fieldPollTime.getValue();
|
||||
systemManagement.addOrUpdateConfiguration(
|
||||
new TenantConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL.getKeyName(),
|
||||
durationHelper.durationToFormattedString(tenantPollTime)));
|
||||
}
|
||||
|
||||
if (!compareDurations(tenantPollingOverdueTime, fieldPollingOverdueTime.getValue())) {
|
||||
tenantPollingOverdueTime = fieldPollingOverdueTime.getValue();
|
||||
tenantMetaData.setPollingOverdueTime(fieldPollingOverdueTime.getValue());
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
if (hasChanged) {
|
||||
systemManagement.updateTenantMetadata(tenantMetaData);
|
||||
if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) {
|
||||
tenantOverdueTime = fieldPollingOverdueTime.getValue();
|
||||
systemManagement.addOrUpdateConfiguration(
|
||||
new TenantConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL.getKeyName(),
|
||||
durationHelper.durationToFormattedString(tenantOverdueTime)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fieldPollingTime.setValue(tenantPollingTime);
|
||||
fieldPollingOverdueTime.setValue(tenantPollingOverdueTime);
|
||||
fieldPollTime.setValue(tenantPollTime);
|
||||
fieldPollingOverdueTime.setValue(tenantOverdueTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserInputValid() {
|
||||
return fieldPollingTime.isUserInputValid() && fieldPollingOverdueTime.isUserInputValid();
|
||||
return fieldPollTime.isUserInputValid() && fieldPollingOverdueTime.isUserInputValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +140,7 @@ public class PollingConfigurationView extends BaseConfigurationView
|
||||
notifyConfigurationChanged();
|
||||
}
|
||||
|
||||
private boolean compareDurations(Duration d1, Duration d2) {
|
||||
private boolean compareDurations(final Duration d1, final Duration d2) {
|
||||
if (d1 == null && d2 == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,20 +4,12 @@ import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.tenantconfiguration.ConfigurationItem;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.CheckBox;
|
||||
import com.vaadin.ui.GridLayout;
|
||||
@@ -29,68 +21,41 @@ import com.vaadin.ui.Label;
|
||||
* duration in the DurationField or he can configure using the global duration
|
||||
* by changing the CheckBox.
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
@Scope("prototype")
|
||||
public class DurationConfigField extends GridLayout implements ValueChangeListener, ConfigurationItem {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final List<ConfigurationItemChangeListener> configurationChangeListeners = new ArrayList<>();
|
||||
|
||||
private CheckBox checkBox;
|
||||
private DurationField durationField;
|
||||
|
||||
private final CheckBox checkBox = new CheckBox();
|
||||
private final DurationField durationField = new DurationField();
|
||||
private Duration globalDuration;
|
||||
private final Label labelCustomValue;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
/**
|
||||
* sets i18n
|
||||
*
|
||||
* @param i18n
|
||||
*/
|
||||
public void setI18n(I18N i18n) {
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
public DurationConfigField() {
|
||||
private DurationConfigField() {
|
||||
super(3, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Authentication Configuration layout.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
this.addStyleName("duration-config-field");
|
||||
this.setSpacing(true);
|
||||
this.setImmediate(true);
|
||||
this.setColumnExpandRatio(1, 1.0F);
|
||||
// gridLayout.setSizeFull();
|
||||
|
||||
checkBox = new CheckBox();
|
||||
|
||||
this.addComponent(checkBox, 0, 0);
|
||||
this.setComponentAlignment(checkBox, Alignment.MIDDLE_LEFT);
|
||||
|
||||
Label customValue = SPUIComponentProvider.getLabel(i18n.get("configuration.polling.custom.value"),
|
||||
SPUILabelDefinitions.SP_LABEL_SIMPLE);
|
||||
this.addComponent(customValue, 1, 0);
|
||||
this.setComponentAlignment(customValue, Alignment.MIDDLE_LEFT);
|
||||
|
||||
durationField = new DurationField();
|
||||
labelCustomValue = SPUIComponentProvider.getLabel("", SPUILabelDefinitions.SP_LABEL_SIMPLE);
|
||||
this.addComponent(labelCustomValue, 1, 0);
|
||||
this.setComponentAlignment(labelCustomValue, Alignment.MIDDLE_LEFT);
|
||||
|
||||
this.addComponent(durationField, 2, 0);
|
||||
this.setComponentAlignment(durationField, Alignment.MIDDLE_LEFT);
|
||||
|
||||
checkBox.addValueChangeListener(this);
|
||||
durationField.addValueChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChange(ValueChangeEvent event) {
|
||||
public void valueChange(final ValueChangeEvent event) {
|
||||
if (event.getProperty() == checkBox) {
|
||||
if (checkBox.getValue()) {
|
||||
durationField.setEnabled(true);
|
||||
@@ -103,35 +68,25 @@ public class DurationConfigField extends GridLayout implements ValueChangeListen
|
||||
}
|
||||
|
||||
/**
|
||||
* sets all mandatitory attributes for correct user interaction
|
||||
*
|
||||
* @param caption
|
||||
* the caption of the field
|
||||
* has to be called before using, see Builder Implementation.
|
||||
*
|
||||
* @param tenantDuration
|
||||
* tenant specific duration value
|
||||
* @param globalDuration
|
||||
* duration value which is stored in the global configuration
|
||||
*/
|
||||
public void setInitValues(String caption, @NotNull Duration tenantDuration, @NotNull Duration globalDuration) {
|
||||
this.setCaption(caption);
|
||||
private void init(final Duration globalDuration, final Duration tenantDuration) {
|
||||
this.globalDuration = globalDuration;
|
||||
|
||||
this.setValue(tenantDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the allowed range of the duration values
|
||||
*
|
||||
* @param minimumDuration
|
||||
* minimum allowed duration value
|
||||
* @param maximumDuration
|
||||
* maximum allowed duration value
|
||||
*/
|
||||
public void setAllowedRange(Duration minimumDuration, Duration maximumDuration) {
|
||||
private void setCheckboxLabel(final String label) {
|
||||
labelCustomValue.setValue(label);
|
||||
}
|
||||
|
||||
private void setAllowedRange(final Duration minimumDuration, final Duration maximumDuration) {
|
||||
durationField.setMinimumDuration(minimumDuration);
|
||||
durationField.setMaximumDuration(maximumDuration);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +96,7 @@ public class DurationConfigField extends GridLayout implements ValueChangeListen
|
||||
* duration which will be set in to the duration field, when
|
||||
* {@code null} the global configuration will be used.
|
||||
*/
|
||||
public void setValue(Duration tenantDuration) {
|
||||
public void setValue(final Duration tenantDuration) {
|
||||
if (tenantDuration == null) {
|
||||
// no tenant specific configuration
|
||||
checkBox.setValue(false);
|
||||
@@ -178,4 +133,54 @@ public class DurationConfigField extends GridLayout implements ValueChangeListen
|
||||
public void addChangeListener(final ConfigurationItemChangeListener listener) {
|
||||
configurationChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
public static DurationConfigFieldBuilder builder() {
|
||||
return new DurationConfigFieldBuilder();
|
||||
}
|
||||
|
||||
public static class DurationConfigFieldBuilder {
|
||||
private final DurationConfigField field;
|
||||
|
||||
private Duration globalDuration = null;
|
||||
private Duration tenantDuration = null;
|
||||
|
||||
private DurationConfigFieldBuilder() {
|
||||
field = new DurationConfigField();
|
||||
};
|
||||
|
||||
public DurationConfigFieldBuilder checkBoxLabel(final String label) {
|
||||
field.setCheckboxLabel(label);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationConfigFieldBuilder globalDuration(final Duration globalDuration) {
|
||||
this.globalDuration = globalDuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationConfigFieldBuilder caption(final String caption) {
|
||||
field.setCaption(caption);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationConfigFieldBuilder range(final Duration minDuration, final Duration maxDuration) {
|
||||
field.setAllowedRange(minDuration, maxDuration);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationConfigFieldBuilder tenantDuration(final Duration tenantDuration) {
|
||||
this.tenantDuration = tenantDuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationConfigField build() {
|
||||
if (globalDuration == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot build DurationConfigField without a value for global duration.");
|
||||
}
|
||||
|
||||
field.init(globalDuration, tenantDuration);
|
||||
return field;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user