From a3295b518d5b60c158359c88370c9af3ae66e1c5 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Tue, 22 Mar 2016 17:01:24 +0100 Subject: [PATCH] Added tenant configuration for anyonmous download and UI element to allow to configure anonymous download Signed-off-by: Jonathan Philip Knoblauch --- .../configuration/TenantConfigurationKey.java | 7 +- .../DownloadAnonymousConfigurationView.java | 121 ++++++++++++++++++ .../TenantConfigurationDashboardView.java | 4 + .../src/main/resources/messages.properties | 2 + .../src/main/resources/messages_de.properties | 2 + .../src/main/resources/messages_en.properties | 2 + 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java index c83f24dc2..32a7a8376 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java @@ -63,7 +63,12 @@ public enum TenantConfigurationKey { /** * string value which holds the polling time interval in the format HH:mm:ss */ - POLLING_OVERDUE_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, TenantConfigurationPollingDurationValidator.class); + POLLING_OVERDUE_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, TenantConfigurationPollingDurationValidator.class), + + /** + * boolean value {@code true} {@code false}. + */ + ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class); private final String keyName; private final String defaultKeyName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java new file mode 100644 index 000000000..7366a251f --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.tenantconfiguration; + +import javax.annotation.PostConstruct; + +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; + +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; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; + +/** + * @author Jonathan Knoblauch + * + */ + +@SpringComponent +@ViewScope +public class DownloadAnonymousConfigurationView extends BaseConfigurationView + implements ConfigurationItem.ConfigurationItemChangeListener { + + private static final String DIST_CHECKBOX_STYLE = "dist-checkbox-style"; + + private static final long serialVersionUID = 1L; + + @Autowired + private I18N i18n; // TODO + + @Autowired + private transient TenantConfigurationManagement tenantConfigurationManagement; + + boolean anonymousDownloadEnabled; + + private CheckBox downloadAnonymousCheckBox; + + /** + * Initialize Default Distribution Set layout. + */ + @PostConstruct + public void init() { + + final TenantConfigurationValue value = tenantConfigurationManagement + .getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); + anonymousDownloadEnabled = value.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("enonymous.download.title")); + headerDisSetType.addStyleName("config-panel-header"); + vLayout.addComponent(headerDisSetType); + + final GridLayout gridLayout = new GridLayout(2, 1); + gridLayout.setSpacing(true); + gridLayout.setImmediate(true); + gridLayout.setColumnExpandRatio(1, 1.0F); + gridLayout.setSizeFull(); + + downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); + downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); + downloadAnonymousCheckBox.setId("TODO"); + downloadAnonymousCheckBox.addValueChangeListener(event -> configurationHasChanged()); + gridLayout.addComponent(downloadAnonymousCheckBox); + + final Label configurationLabel = SPUIComponentProvider.getLabel(i18n.get("enonymous.download.label"), + SPUILabelDefinitions.SP_LABEL_SIMPLE); + gridLayout.addComponent(configurationLabel); + gridLayout.setComponentAlignment(configurationLabel, Alignment.MIDDLE_LEFT); + + vLayout.addComponent(gridLayout); + + rootPanel.setContent(vLayout); + setCompositionRoot(rootPanel); + + } + + @Override + public void configurationHasChanged() { + anonymousDownloadEnabled = downloadAnonymousCheckBox.getValue(); + notifyConfigurationChanged(); + } + + @Override + public void save() { + tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, + downloadAnonymousCheckBox.getValue()); + // TODO notification Download server + } + + @Override + public void undo() { + anonymousDownloadEnabled = tenantConfigurationManagement + .getGlobalConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); + downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); + + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java index 8a22064ab..0349ba867 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java @@ -58,6 +58,9 @@ public class TenantConfigurationDashboardView extends CustomComponent implements @Autowired private PollingConfigurationView pollingConfigurationView; + @Autowired + private DownloadAnonymousConfigurationView downloadAnonymousConfigurationView; + @Autowired private I18N i18n; @@ -80,6 +83,7 @@ public class TenantConfigurationDashboardView extends CustomComponent implements configurationViews.add(defaultDistributionSetTypeLayout); configurationViews.add(authenticationConfigurationView); configurationViews.add(pollingConfigurationView); + configurationViews.add(downloadAnonymousConfigurationView); } @Override diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index 27103a0b9..ebdcfa76f 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -401,6 +401,8 @@ configuration.polling.title=Polling Configuration configuration.polling.time=Polling Time configuration.polling.overduetime=Polling Overdue Time configuration.polling.custom.value=use a custom value +enonymous.download.title=Anonymous download +enonymous.download.label=Allow anonymous download. If you enable this option the download server will accept anonymous download requests. #Calendar calendar.year=year diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 9ff2e5e75..47cb36f31 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -389,6 +389,8 @@ configuration.defaultdistributionset.select.label=Wahl des default Distribution configuration.savebutton.tooltip=Konfigurationen speichern configuration.cancellbutton.tooltip=Konfigurationen zur�cksetzen configuration.authentication.title=Authentifikationseinstellungen +enonymous.download.title=Anonymes herunterladen +enonymous.download.label=Erlaube anonymes herunterladen. When diese option aktivert ist, wird der download server anonyme download anfragen erlauben. #Calendar calendar.year=Jahr calendar.years=Jahre diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index 74f50f378..50c04ad46 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -383,6 +383,8 @@ configuration.authentication.title=Authentication Configuration controller.polling.title=Polling Configuration controller.polling.time=Polling Time controller.polling.overduetime=Polling Overdue Time +enonymous.download.title=Anonymous download +enonymous.download.label=Allow anonymous download. If you enable this option the download server will accept anonymous download requests. #Calendar calendar.year=year