From a3295b518d5b60c158359c88370c9af3ae66e1c5 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Tue, 22 Mar 2016 17:01:24 +0100 Subject: [PATCH 01/56] 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 From cdac7185c47dc9c8b9288d669a89d57950cf0548 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Wed, 23 Mar 2016 10:23:35 +0100 Subject: [PATCH 02/56] fix typo of class TenantSecurityToken and handle authentication message based on FileResource not only on SHA1 hash Signed-off-by: Michael Hirsch --- .../amqp/AmqpControllerAuthentfication.java | 6 +- .../amqp/AmqpMessageHandlerService.java | 52 ++++-- .../AmqpControllerAuthenticationTest.java | 29 +-- .../amqp/AmqpMessageHandlerServiceTest.java | 9 +- .../dmf/json/model/TenantSecruityToken.java | 94 ---------- .../dmf/json/model/TenantSecurityToken.java | 176 ++++++++++++++++++ ...actHttpControllerAuthenticationFilter.java | 15 +- .../repository/ArtifactManagement.java | 3 +- ...bstractControllerAuthenticationFilter.java | 8 +- .../CoapAnonymousPreAuthenticatedFilter.java | 16 +- ...lerPreAuthenticateSecurityTokenFilter.java | 8 +- ...thenticatedGatewaySecurityTokenFilter.java | 8 +- ...rPreAuthenticatedSecurityHeaderFilter.java | 10 +- .../security/PreAuthenficationFilter.java | 8 +- 14 files changed, 279 insertions(+), 163 deletions(-) delete mode 100644 hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecruityToken.java create mode 100644 hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java index 8f19d9f02..3fa7979b9 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -100,7 +100,7 @@ public class AmqpControllerAuthentfication { * the authentication request object * @return the authentfication object */ - public Authentication doAuthenticate(final TenantSecruityToken secruityToken) { + public Authentication doAuthenticate(final TenantSecurityToken secruityToken) { PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null); for (final PreAuthenficationFilter filter : filterChain) { final PreAuthenticatedAuthenticationToken authenticationRest = createAuthentication(filter, secruityToken); @@ -115,7 +115,7 @@ public class AmqpControllerAuthentfication { } private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthenficationFilter filter, - final TenantSecruityToken secruityToken) { + final TenantSecurityToken secruityToken) { if (!filter.isEnable(secruityToken)) { return null; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index cfd5485a6..71b8f8db8 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -27,8 +27,9 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; @@ -157,25 +158,29 @@ public class AmqpMessageHandlerService extends BaseAmqpService { private Message handleAuthentifiactionMessage(final Message message) { final DownloadResponse authentificationResponse = new DownloadResponse(); final MessageProperties messageProperties = message.getMessageProperties(); - final TenantSecruityToken secruityToken = convertMessage(message, TenantSecruityToken.class); - final String sha1 = secruityToken.getSha1(); + final TenantSecurityToken secruityToken = convertMessage(message, + TenantSecurityToken.class); + final FileResource fileResource = secruityToken.getFileResource(); try { SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken)); - final LocalArtifact localArtifact = artifactManagement - .findFirstLocalArtifactsBySHA1(secruityToken.getSha1()); + + final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); + if (localArtifact == null) { throw new EntityNotFoundException(); } // check action for this download purposes, the method will throw an // EntityNotFoundException in case the controller is not allowed to - // download this file - // because it's not assigned to an action and not assigned to this - // controller. - final Action action = controllerManagement.getActionForDownloadByTargetAndSoftwareModule( - secruityToken.getControllerId(), localArtifact.getSoftwareModule()); - LOG.info("Found action for download authentication request action: {}, sha1: {}", action, - secruityToken.getSha1()); + // download this file because it's not assigned to an action and not + // assigned to this controller. Otherwise no controllerId is set = + // anonymous download + if (secruityToken.getControllerId() != null) { + final Action action = controllerManagement.getActionForDownloadByTargetAndSoftwareModule( + secruityToken.getControllerId(), localArtifact.getSoftwareModule()); + LOG.info("Found action for download authentication request action: {}, resource: {}", action, + secruityToken.getFileResource()); + } final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); if (artifact == null) { @@ -183,7 +188,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } authentificationResponse.setArtifact(artifact); final String downloadId = UUID.randomUUID().toString(); - final DownloadArtifactCache downloadCache = new DownloadArtifactCache(DownloadType.BY_SHA1, sha1); + // SHA1 key is set, download by SHA1 + final DownloadArtifactCache downloadCache = new DownloadArtifactCache(DownloadType.BY_SHA1, + localArtifact.getSha1Hash()); cache.put(downloadId, downloadCache); authentificationResponse .setDownloadUrl(UriComponentsBuilder.fromUri(hostnameResolver.resolveHostname().toURI()) @@ -198,7 +205,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { authentificationResponse.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); authentificationResponse.setMessage("Building download URI failed"); } catch (final EntityNotFoundException e) { - final String errorMessage = "Artifact with sha1 " + sha1 + "not found "; + final String errorMessage = "Artifact for resource " + fileResource + "not found "; LOG.warn(errorMessage, e); authentificationResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); authentificationResponse.setMessage(errorMessage); @@ -207,6 +214,23 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return getMessageConverter().toMessage(authentificationResponse, messageProperties); } + private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { + LocalArtifact localArtifact = null; + if (fileResource.getSha1() != null) { + localArtifact = artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); + } else if (fileResource.getFilename() != null) { + localArtifact = artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream() + .findFirst().orElse(null); + } else if (fileResource.getArtifactId() != null) { + final org.eclipse.hawkbit.repository.model.Artifact artifact = artifactManagement + .findArtifact(fileResource.getArtifactId()); + if (artifact instanceof LocalArtifact) { + localArtifact = (LocalArtifact) artifact; + } + } + return localArtifact; + } + private static Artifact convertDbArtifact(final DbArtifact dbArtifact) { final Artifact artifact = new Artifact(); artifact.setSize(dbArtifact.getSize()); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java index 66527727a..d7ab805ed 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java @@ -19,7 +19,8 @@ import static org.mockito.Mockito.when; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -105,7 +106,8 @@ public class AmqpControllerAuthenticationTest { @Test @Description("Tests authentication manager without principal") public void testAuthenticationeBadCredantialsWithoutPricipal() { - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); try { authenticationManager.doAuthenticate(securityToken); fail("BadCredentialsException was excepeted since principal was missing"); @@ -118,11 +120,12 @@ public class AmqpControllerAuthenticationTest { @Test @Description("Tests authentication manager without wrong credential") public void testAuthenticationBadCredantialsWithWrongCredential() { - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); when(tenantConfigurationManagement.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) .thenReturn(CONFIG_VALUE_TRUE); - securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); + securityToken.getHeaders().put(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); try { authenticationManager.doAuthenticate(securityToken); fail("BadCredentialsException was excepeted due to wrong credential"); @@ -135,11 +138,12 @@ public class AmqpControllerAuthenticationTest { @Test @Description("Tests authentication successfull") public void testSuccessfullAuthentication() { - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); when(tenantConfigurationManagement.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) .thenReturn(CONFIG_VALUE_TRUE); - securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); + securityToken.getHeaders().put(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); final Authentication authentication = authenticationManager.doAuthenticate(securityToken); assertThat(authentication).isNotNull(); } @@ -149,7 +153,8 @@ public class AmqpControllerAuthenticationTest { public void testAuthenticationMessageBadCredantialsWithoutPricipal() { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); @@ -167,11 +172,12 @@ public class AmqpControllerAuthenticationTest { @Description("Tests authentication message without wrong credential") public void testAuthenticationMessageBadCredantialsWithWrongCredential() { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); when(tenantConfigurationManagement.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) .thenReturn(CONFIG_VALUE_TRUE); - securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); + securityToken.getHeaders().put(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); @@ -189,11 +195,12 @@ public class AmqpControllerAuthenticationTest { @Description("Tests authentication message successfull") public void testSuccessfullMessageAuthentication() { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, + FileResource.sha1("12345")); when(tenantConfigurationManagement.getConfigurationValue( eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) .thenReturn(CONFIG_VALUE_TRUE); - securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); + securityToken.getHeaders().put(TenantSecurityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 9d6ae3ba7..930ca02ad 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -34,7 +34,8 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.ActionStatus; import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; @@ -263,7 +264,7 @@ public class AmqpMessageHandlerServiceTest { @Description("Tests that an download request is denied for an artifact which does not exists") public void authenticationRequestDeniedForArtifactWhichDoesNotExists() { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, "123", "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); @@ -282,7 +283,7 @@ public class AmqpMessageHandlerServiceTest { @Description("Tests that an download request is denied for an artifact which is not assigned to the requested target") public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, "123", "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); @@ -306,7 +307,7 @@ public class AmqpMessageHandlerServiceTest { @Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target") public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); - final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, "123", "12345"); + final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); diff --git a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecruityToken.java b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecruityToken.java deleted file mode 100644 index 351684f5e..000000000 --- a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecruityToken.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * 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.dmf.json.model; - -import java.util.Map; -import java.util.TreeMap; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * JSON representation to authenticate a tenant. - * - * - * - */ - -@JsonInclude(Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class TenantSecruityToken { - - public static final String AUTHORIZATION_HEADER = "Authorization"; - public static final String COAP_AUTHORIZATION_HEADER = "Coap-Authorization"; - public static final String COAP_TOKEN_VALUE = "CoapToken"; - - @JsonProperty - private final String tenant; - @JsonProperty - private final String controllerId; - @JsonProperty(required = false) - private Map headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - @JsonProperty(required = false) - private final String sha1; - - /** - * Constructor. - * - * @param tenant - * the tenant for the security token - * @param controllerId - * the ID of the controller for the security token - * @param sha1 - * the sha1 of authentication - */ - @JsonCreator - public TenantSecruityToken(@JsonProperty("tenant") final String tenant, - @JsonProperty("controllerId") final String controllerId, @JsonProperty("sha1") final String sha1) { - this.tenant = tenant; - this.controllerId = controllerId; - this.sha1 = sha1; - } - - public String getTenant() { - return tenant; - } - - public String getControllerId() { - return controllerId; - } - - public Map getHeaders() { - return headers; - } - - public String getSha1() { - return sha1; - } - - /** - * Gets a header value. - * - * @param name - * of header - * @return the value - */ - public String getHeader(final String name) { - return headers.get(name); - } - - public void setHeaders(final Map headers) { - this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - this.headers.putAll(headers); - } - -} diff --git a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java new file mode 100644 index 000000000..9e07d3fc4 --- /dev/null +++ b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java @@ -0,0 +1,176 @@ +/** + * 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.dmf.json.model; + +import java.util.Map; +import java.util.TreeMap; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * JSON representation to authenticate a tenant. + */ + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class TenantSecurityToken { + + public static final String AUTHORIZATION_HEADER = "Authorization"; + public static final String COAP_AUTHORIZATION_HEADER = "Coap-Authorization"; + public static final String COAP_TOKEN_VALUE = "CoapToken"; + + @JsonProperty + private final String tenant; + @JsonProperty + private final String controllerId; + @JsonProperty(required = false) + private Map headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + @JsonProperty(required = false) + private final FileResource fileResource; + + /** + * Constructor. + * + * @param tenant + * the tenant for the security token + * @param controllerId + * the ID of the controller for the security token + * @param fileResource + * the file to obtain + */ + @JsonCreator + public TenantSecurityToken(@JsonProperty("tenant") final String tenant, + @JsonProperty("controllerId") final String controllerId, + @JsonProperty("fileResource") final FileResource fileResource) { + this.tenant = tenant; + this.controllerId = controllerId; + this.fileResource = fileResource; + } + + public String getTenant() { + return tenant; + } + + public String getControllerId() { + return controllerId; + } + + public Map getHeaders() { + return headers; + } + + public FileResource getFileResource() { + return fileResource; + } + + /** + * Gets a header value. + * + * @param name + * of header + * @return the value + */ + public String getHeader(final String name) { + return headers.get(name); + } + + public void setHeaders(final Map headers) { + this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + this.headers.putAll(headers); + } + + /** + * File resource descriptor which is used to ask for the resource to + * download e.g. The lookup of the file can be different e.g. by SHA1 hash + * or by filename. + */ + @JsonInclude(Include.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FileResource { + @JsonProperty(required = false) + private String sha1; + @JsonProperty(required = false) + private String filename; + @JsonProperty(required = false) + private Long artifactId; + + public String getSha1() { + return sha1; + } + + public void setSha1(final String sha1) { + this.sha1 = sha1; + } + + public String getFilename() { + return filename; + } + + public void setFilename(final String filename) { + this.filename = filename; + } + + public Long getArtifactId() { + return artifactId; + } + + public void setArtifactId(final Long artifactId) { + this.artifactId = artifactId; + } + + /** + * factory method to create a file resource for an SHA1 lookup. + * + * @param sha1 + * the SHA1 key of the file to obtain + * @return the {@link FileResource} with SHA1 key set + */ + public static FileResource sha1(final String sha1) { + final FileResource resource = new FileResource(); + resource.sha1 = sha1; + return resource; + } + + /** + * factory method to create a file resource for an filename lookup. + * + * @param filename + * the filename of the file to obtain + * @return the {@link FileResource} with filename set + */ + public static FileResource filename(final String filename) { + final FileResource resource = new FileResource(); + resource.filename = filename; + return resource; + } + + /** + * factory method to create a file resource for an artifactId lookup. + * + * @param artifactId + * the artifactId of the file to obtain + * @return the {@link FileResource} with artifactId set + */ + public static FileResource artifactId(final Long artifactId) { + final FileResource resource = new FileResource(); + resource.artifactId = artifactId; + return resource; + } + + @Override + public String toString() { + return "FileResource [sha1=" + sha1 + ", filename=" + filename + "]"; + } + } +} diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java index adb2858b9..ace5bc834 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java @@ -17,7 +17,8 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; @@ -96,7 +97,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac return; } - final TenantSecruityToken secruityToken = createTenantSecruityTokenVariables((HttpServletRequest) request); + final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables((HttpServletRequest) request); if (secruityToken == null) { chain.doFilter(request, response); return; @@ -121,7 +122,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac * request does not match the pattern and no variables could be * extracted */ - protected TenantSecruityToken createTenantSecruityTokenVariables(final HttpServletRequest request) { + protected TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request) { final String requestURI = request.getRequestURI(); if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) { @@ -153,9 +154,9 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac } } - private TenantSecruityToken createTenantSecruityTokenVariables(final HttpServletRequest request, + private TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request, final String tenant, final String controllerId) { - final TenantSecruityToken secruityToken = new TenantSecruityToken(tenant, controllerId, ""); + final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, controllerId, FileResource.sha1("")); final UnmodifiableIterator forEnumeration = Iterators.forEnumeration(request.getHeaderNames()); forEnumeration.forEachRemaining(header -> secruityToken.getHeaders().put(header, request.getHeader(header))); return secruityToken; @@ -163,7 +164,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac @Override protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) { - final TenantSecruityToken secruityToken = createTenantSecruityTokenVariables(request); + final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request); if (secruityToken == null) { return null; } @@ -172,7 +173,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac @Override protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) { - final TenantSecruityToken secruityToken = createTenantSecruityTokenVariables(request); + final TenantSecurityToken secruityToken = createTenantSecruityTokenVariables(request); if (secruityToken == null) { return null; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index a5ee019dc..122d7b881 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -321,7 +321,8 @@ public class ArtifactManagement { } boolean artifactIsOnlyUsedByOneSoftwareModule = true; - for (LocalArtifact lArtifact : localArtifactRepository.findByGridFsFileName(existing.getGridFsFileName())) { + for (final LocalArtifact lArtifact : localArtifactRepository + .findByGridFsFileName(existing.getGridFsFileName())) { if (!lArtifact.getSoftwareModule().isDeleted() && lArtifact.getSoftwareModule().getId() != existing.getSoftwareModule().getId()) { artifactIsOnlyUsedByOneSoftwareModule = false; diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java index d22c432cf..9a1cd2aea 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -42,15 +42,15 @@ public abstract class AbstractControllerAuthenticationFilter implements PreAuthe protected abstract TenantConfigurationKey getTenantConfigurationKey(); @Override - public boolean isEnable(final TenantSecruityToken secruityToken) { + public boolean isEnable(final TenantSecurityToken secruityToken) { return tenantAware.runAsTenant(secruityToken.getTenant(), configurationKeyTenantRunner); } @Override - public abstract HeaderAuthentication getPreAuthenticatedPrincipal(TenantSecruityToken secruityToken); + public abstract HeaderAuthentication getPreAuthenticatedPrincipal(TenantSecurityToken secruityToken); @Override - public abstract HeaderAuthentication getPreAuthenticatedCredentials(TenantSecruityToken secruityToken); + public abstract HeaderAuthentication getPreAuthenticatedCredentials(TenantSecurityToken secruityToken); private final class SecurityConfigurationKeyTenantRunner implements TenantAware.TenantRunner { @Override diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/CoapAnonymousPreAuthenticatedFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/CoapAnonymousPreAuthenticatedFilter.java index d9d8b9fa7..36a444c43 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/CoapAnonymousPreAuthenticatedFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/CoapAnonymousPreAuthenticatedFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; /** * A Filter for device which download via coap. @@ -19,19 +19,19 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; public class CoapAnonymousPreAuthenticatedFilter implements PreAuthenficationFilter { @Override - public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecruityToken secruityToken) { - return new HeaderAuthentication(secruityToken.getControllerId(), TenantSecruityToken.COAP_TOKEN_VALUE); + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), TenantSecurityToken.COAP_TOKEN_VALUE); } @Override - public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecruityToken secruityToken) { - return new HeaderAuthentication(secruityToken.getControllerId(), TenantSecruityToken.COAP_TOKEN_VALUE); + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), TenantSecurityToken.COAP_TOKEN_VALUE); } @Override - public boolean isEnable(final TenantSecruityToken secruityToken) { - final String authHeader = secruityToken.getHeader(TenantSecruityToken.COAP_AUTHORIZATION_HEADER); - return TenantSecruityToken.COAP_TOKEN_VALUE.equals(authHeader); + public boolean isEnable(final TenantSecurityToken secruityToken) { + final String authHeader = secruityToken.getHeader(TenantSecurityToken.COAP_AUTHORIZATION_HEADER); + return TenantSecurityToken.COAP_TOKEN_VALUE.equals(authHeader); } } diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java index c30f60711..8ff1e9ebc 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.repository.ControllerManagement; @@ -67,8 +67,8 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro } @Override - public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecruityToken secruityToken) { - final String authHeader = secruityToken.getHeader(TenantSecruityToken.AUTHORIZATION_HEADER); + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { + final String authHeader = secruityToken.getHeader(TenantSecurityToken.AUTHORIZATION_HEADER); if ((authHeader != null) && authHeader.startsWith(TARGET_SECURITY_TOKEN_AUTH_SCHEME)) { LOGGER.debug("found authorization header with scheme {} using target security token for authentication", TARGET_SECURITY_TOKEN_AUTH_SCHEME); @@ -81,7 +81,7 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro } @Override - public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecruityToken secruityToken) { + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { final String securityToken = tenantAware.runAsTenant(secruityToken.getTenant(), new GetSecurityTokenTenantRunner(secruityToken.getTenant(), secruityToken.getControllerId())); return new HeaderAuthentication(secruityToken.getControllerId(), securityToken); diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java index 765589df4..7d1bd7b0f 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -56,8 +56,8 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra } @Override - public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecruityToken secruityToken) { - final String authHeader = secruityToken.getHeader(TenantSecruityToken.AUTHORIZATION_HEADER); + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { + final String authHeader = secruityToken.getHeader(TenantSecurityToken.AUTHORIZATION_HEADER); if ((authHeader != null) && authHeader.startsWith(GATEWAY_SECURITY_TOKEN_AUTH_SCHEME)) { LOGGER.debug("found authorization header with scheme {} using target security token for authentication", GATEWAY_SECURITY_TOKEN_AUTH_SCHEME); @@ -71,7 +71,7 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra } @Override - public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecruityToken secruityToken) { + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { final String gatewayToken = tenantAware.runAsTenant(secruityToken.getTenant(), gatewaySecurityTokenKeyConfigRunner); return new HeaderAuthentication(secruityToken.getControllerId(), gatewayToken); diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java index ef8b5fbf7..6836b8a31 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory; /** * An pre-authenticated processing filter which extracts the principal from a * request URI and the credential from a request header in a the - * {@link TenantSecruityToken}. + * {@link TenantSecurityToken}. * * * @@ -75,7 +75,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont } @Override - public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecruityToken secruityToken) { + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { // retrieve the common name header and the authority name header from // the http request and // combine them together @@ -97,7 +97,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont } @Override - public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecruityToken secruityToken) { + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { final String authorityNameConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(), sslIssuerNameConfigTenantRunner); String controllerId = secruityToken.getControllerId(); @@ -117,7 +117,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont * It's ok if we find the the hash in any the trusted CA chain to accept * this request for this tenant. */ - private String getIssuerHashHeader(final TenantSecruityToken secruityToken, final String knownIssuerHash) { + private String getIssuerHashHeader(final TenantSecurityToken secruityToken, final String knownIssuerHash) { // iterate over the headers until we get a null header. int iHeader = 1; String foundHash; diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java index 8aa957005..8981fa9af 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.security; -import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; /** * Interface for Pre Authenfication. @@ -25,7 +25,7 @@ public interface PreAuthenficationFilter { * the secruity info * @return is enabled diabled */ - boolean isEnable(TenantSecruityToken secruityToken); + boolean isEnable(TenantSecurityToken secruityToken); /** * Extract the principal information from the current secruityToken. @@ -34,7 +34,7 @@ public interface PreAuthenficationFilter { * the secruityToken * @return the extracted tenant and controller id */ - HeaderAuthentication getPreAuthenticatedPrincipal(TenantSecruityToken secruityToken); + HeaderAuthentication getPreAuthenticatedPrincipal(TenantSecurityToken secruityToken); /** * Extract the principal credentials from the current secruityToken. @@ -43,6 +43,6 @@ public interface PreAuthenficationFilter { * the secruityToken * @return the extracted tenant and controller id */ - HeaderAuthentication getPreAuthenticatedCredentials(TenantSecruityToken secruityToken); + HeaderAuthentication getPreAuthenticatedCredentials(TenantSecurityToken secruityToken); } From 74782527fedf14c727eaceda743dc1cf353100de Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Wed, 23 Mar 2016 12:14:44 +0100 Subject: [PATCH 03/56] Added javadoc and refactored existing one. Signed-off-by: Jonathan Philip Knoblauch --- .../AuthenticationConfigurationView.java | 3 -- .../BaseConfigurationView.java | 4 +-- .../ConfigurationGroup.java | 5 ++- .../ConfigurationItem.java | 2 +- .../DefaultDistributionSetTypeLayout.java | 3 -- .../DownloadAnonymousConfigurationView.java | 11 ++----- .../PollingConfigurationView.java | 2 -- .../TenantConfigurationDashboardView.java | 12 +------ ...antConfigurationDashboardViewMenuItem.java | 3 -- ...ficateAuthenticationConfigurationItem.java | 31 ++----------------- ...yTokenAuthenticationConfigurationItem.java | 15 ++------- ...yTokenAuthenticationConfigurationItem.java | 22 ++----------- 12 files changed, 18 insertions(+), 95 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index 94e852813..d00223f5a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -30,9 +30,6 @@ import com.vaadin.ui.VerticalLayout; /** * View to configure the authentication mode. - * - * - * */ @SpringComponent @ViewScope diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/BaseConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/BaseConfigurationView.java index 559eeae02..a68b095b4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/BaseConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/BaseConfigurationView.java @@ -14,8 +14,8 @@ import java.util.List; import com.vaadin.ui.CustomComponent; /** - * base class for all configuration views. This class implements the logic for - * the handling of the + * Base class for all configuration views. This class implements the logic for + * the handling of the configurations in a consistent way. * */ public abstract class BaseConfigurationView extends CustomComponent implements ConfigurationGroup { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationGroup.java index 90a38dd56..3ac3610f9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationGroup.java @@ -11,9 +11,8 @@ package org.eclipse.hawkbit.ui.tenantconfiguration; import com.vaadin.ui.Component; /** - * - * - * + * Interface that all system configurations have to implement to save and undo + * their customized changes. */ public interface ConfigurationGroup extends Component, ConfigurationItem { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationItem.java index 142de0abb..856b2090d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/ConfigurationItem.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration; import java.io.Serializable; /** - * represents an configurationItem, which can be modified by the user + * Represents an configurationItem, which can be modified by the user */ public interface ConfigurationItem { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java index ec0e643de..0162f6ed8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java @@ -33,9 +33,6 @@ import com.vaadin.ui.VerticalLayout; /** * Default DistributionSet Panel. - * - * - * */ @SpringComponent @ViewScope 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 index 7366a251f..505c0963d 100644 --- 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 @@ -28,10 +28,8 @@ import com.vaadin.ui.Panel; import com.vaadin.ui.VerticalLayout; /** - * @author Jonathan Knoblauch - * + * View to enable anonymous download. */ - @SpringComponent @ViewScope public class DownloadAnonymousConfigurationView extends BaseConfigurationView @@ -42,7 +40,7 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView private static final long serialVersionUID = 1L; @Autowired - private I18N i18n; // TODO + private I18N i18n; @Autowired private transient TenantConfigurationManagement tenantConfigurationManagement; @@ -52,7 +50,7 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView private CheckBox downloadAnonymousCheckBox; /** - * Initialize Default Distribution Set layout. + * Initialize Default Download Anonymous layout. */ @PostConstruct public void init() { @@ -81,7 +79,6 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); - downloadAnonymousCheckBox.setId("TODO"); downloadAnonymousCheckBox.addValueChangeListener(event -> configurationHasChanged()); gridLayout.addComponent(downloadAnonymousCheckBox); @@ -94,7 +91,6 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView rootPanel.setContent(vLayout); setCompositionRoot(rootPanel); - } @Override @@ -107,7 +103,6 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView public void save() { tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, downloadAnonymousCheckBox.getValue()); - // TODO notification Download server } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java index f751481be..2389a2efa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java @@ -29,8 +29,6 @@ import com.vaadin.ui.VerticalLayout; /** * View to configure the polling interval and the overdue time. - * - * */ @SpringComponent @ViewScope 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 0349ba867..cada6d167 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 @@ -38,9 +38,6 @@ import com.vaadin.ui.VerticalLayout; /** * Main UI for the system configuration view. - * - * - * */ @SpringView(name = TenantConfigurationDashboardView.VIEW_NAME, ui = HawkbitUI.class) @ViewScope @@ -76,7 +73,7 @@ public class TenantConfigurationDashboardView extends CustomComponent implements private final List configurationViews = new ArrayList<>(); /** - * init method adds all Configuration Views to the list of Views. + * Init method adds all Configuration Views to the list of Views. */ @PostConstruct public void init() { @@ -158,13 +155,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements undoConfigurationBtn.setEnabled(false); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.tenantconfiguration.ConfigurationGroup. - * ConfigurationGroupChangeListener #configurationChanged() - */ @Override public void configurationHasChanged() { saveConfigurationBtn.setEnabled(true); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardViewMenuItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardViewMenuItem.java index 1eea3014d..42f96f2c6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardViewMenuItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardViewMenuItem.java @@ -21,9 +21,6 @@ import com.vaadin.server.Resource; /** * Menu item for system configuration view. - * - * - * */ @Component @Order(700) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java index cf2744718..b17d9596f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java @@ -26,16 +26,13 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; /** - * - * + * This class represents the UI item for the certificate authenticated by an + * reverse proxy in the authentication configuration view. */ @SpringComponent @ViewScope public class CertificateAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem { - /** - * - */ private static final long serialVersionUID = 1L; @Autowired @@ -59,7 +56,7 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti } /** - * init mehotd called by spring. + * Init mehotd called by spring. */ @PostConstruct public void init() { @@ -94,12 +91,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti } } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.tenantconfiguration. - * TenantConfigurationItem# configEnable() - */ @Override public void configEnable() { if (!configurationEnabled) { @@ -110,12 +101,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti setDetailVisible(true); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.tenantconfiguration. - * TenantConfigurationItem# configDisable() - */ @Override public void configDisable() { if (configurationEnabled) { @@ -125,11 +110,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti setDetailVisible(false); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.tenantconfiguration.TenantConfigurationItem#save() - */ @Override public void save() { if (configurationEnabledChange) { @@ -142,11 +122,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti } } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.tenantconfiguration.TenantConfigurationItem#undo() - */ @Override public void undo() { configurationEnabledChange = false; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java index fa1ca9271..757460809 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java @@ -30,16 +30,13 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; /** - * - * + * This class represents the UI item for the gateway security token section in + * the authentication configuration view. */ @SpringComponent @ViewScope public class GatewaySecurityTokenAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem { - /** - * - */ private static final long serialVersionUID = 1L; @Autowired @@ -70,7 +67,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac } /** - * init mehotd called by spring. + * Init mehotd called by spring. */ @PostConstruct public void init() { @@ -135,12 +132,6 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac notifyConfigurationChanged(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.tenantconfiguration. - * TenantConfigurationItem# configEnable() - */ @Override public void configEnable() { if (!configurationEnabled) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java index 42e50da2c..641982d73 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java @@ -19,17 +19,13 @@ import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; /** - * - * - * + * This class represents the UI item for the target security token section in + * the authentication configuration view. */ @SpringComponent @ViewScope public class TargetSecurityTokenAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem { - /** - * - */ private static final long serialVersionUID = 1L; @Autowired @@ -49,7 +45,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract } /** - * init mehotd called by spring. + * Init mehotd called by spring. */ @PostConstruct public void init() { @@ -57,12 +53,6 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract configurationEnabled = isConfigEnabled(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.tenantconfiguration. - * TenantConfigurationItem# configEnable() - */ @Override public void configEnable() { if (!configurationEnabled) { @@ -71,12 +61,6 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract configurationEnabled = true; } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.tenantconfiguration. - * TenantConfigurationItem# configDisable() - */ @Override public void configDisable() { if (configurationEnabled) { From 3ff352584e104d1e28123b8a17f957b0af6ca557 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Wed, 23 Mar 2016 14:28:24 +0100 Subject: [PATCH 04/56] Small fix since wrong config value was being accessed. Signed-off-by: Jonathan Philip Knoblauch --- .../DownloadAnonymousConfigurationView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index 505c0963d..fa441476d 100644 --- 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 @@ -107,10 +107,10 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView @Override public void undo() { - anonymousDownloadEnabled = tenantConfigurationManagement - .getGlobalConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); + final TenantConfigurationValue value = tenantConfigurationManagement + .getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); + anonymousDownloadEnabled = value.getValue(); downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); - } } From 1cb7519ace523844a72854944f305cb5c45eaf5a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Wed, 23 Mar 2016 16:17:53 +0100 Subject: [PATCH 05/56] add security and filters for anonymous download via http and amqp requests Signed-off-by: Michael Hirsch --- .../SecurityManagedConfiguration.java | 20 ++++-- .../amqp/AmqpControllerAuthentfication.java | 7 ++ .../amqp/AmqpMessageHandlerService.java | 16 ++--- .../AmqpControllerAuthenticationTest.java | 7 ++ .../dmf/json/model/TenantSecurityToken.java | 62 ++++++++++++++--- ...actHttpControllerAuthenticationFilter.java | 26 ++++--- ...reAuthenticateAnonymousDownloadFilter.java | 47 +++++++++++++ .../repository/ArtifactManagement.java | 2 +- .../im/authentication/SpPermission.java | 18 ++++- ...llerPreAuthenticatedAnonymousDownload.java | 69 +++++++++++++++++++ ...rollerPreAuthenticatedAnonymousFilter.java | 47 +++++++++++++ ...okenSourceTrustAuthenticationProvider.java | 1 + .../security/PreAuthenficationFilter.java | 17 +++++ 13 files changed, 304 insertions(+), 35 deletions(-) create mode 100644 hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateAnonymousDownloadFilter.java create mode 100644 hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownload.java create mode 100644 hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousFilter.java diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 24e9667c2..9638377eb 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.autoconfigure.security; import java.io.IOException; import java.net.URI; -import java.util.Collections; import javax.annotation.PostConstruct; import javax.servlet.Filter; @@ -35,6 +34,7 @@ import org.eclipse.hawkbit.security.ControllerTenantAwareAuthenticationDetailsSo import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.DosFilter; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; +import org.eclipse.hawkbit.security.HttpControllerPreAuthenticateAnonymousDownloadFilter; import org.eclipse.hawkbit.security.HttpControllerPreAuthenticateSecurityTokenFilter; import org.eclipse.hawkbit.security.HttpControllerPreAuthenticatedGatewaySecurityTokenFilter; import org.eclipse.hawkbit.security.HttpControllerPreAuthenticatedSecurityHeaderFilter; @@ -83,6 +83,8 @@ import org.vaadin.spring.security.web.VaadinRedirectStrategy; import org.vaadin.spring.security.web.authentication.VaadinAuthenticationSuccessHandler; import org.vaadin.spring.security.web.authentication.VaadinUrlAuthenticationSuccessHandler; +import com.google.common.collect.Lists; + /** * All configurations related to SP authentication and authorization layer. * @@ -147,6 +149,12 @@ public class SecurityManagedConfiguration { gatewaySecurityTokenFilter.setCheckForPrincipalChanges(true); gatewaySecurityTokenFilter.setAuthenticationDetailsSource(authenticationDetailsSource); + final HttpControllerPreAuthenticateAnonymousDownloadFilter controllerAnonymousDownloadFilter = new HttpControllerPreAuthenticateAnonymousDownloadFilter( + tenantConfigurationManagement, tenantAware, systemSecurityContext); + controllerAnonymousDownloadFilter.setAuthenticationManager(authenticationManager()); + controllerAnonymousDownloadFilter.setCheckForPrincipalChanges(true); + controllerAnonymousDownloadFilter.setAuthenticationDetailsSource(authenticationDetailsSource); + HttpSecurity httpSec = http.csrf().disable().headers() .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.DENY)).contentTypeOptions() .xssProtection().httpStrictTransportSecurity().and(); @@ -159,15 +167,17 @@ public class SecurityManagedConfiguration { LOG.info( "******************\n** Anonymous controller security enabled, should only use for developing purposes **\n******************"); final AnonymousAuthenticationFilter anoymousFilter = new AnonymousAuthenticationFilter( - "controllerAnonymousFilter", "anonymous", Collections.singletonList( - new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS))); + "controllerAnonymousFilter", "anonymous", + Lists.newArrayList(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS), + new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_DOWNLOAD_ROLE))); anoymousFilter.setAuthenticationDetailsSource(authenticationDetailsSource); httpSec.requestMatchers().antMatchers("/*/controller/v1/**", "/*/controller/artifacts/v1/**").and() .securityContext().disable().anonymous().authenticationFilter(anoymousFilter); } else { httpSec.addFilter(securityHeaderFilter).addFilter(securityTokenFilter) - .addFilter(gatewaySecurityTokenFilter).antMatcher("/*/controller/**").anonymous().disable() - .authorizeRequests().anyRequest().authenticated().and().exceptionHandling() + .addFilter(gatewaySecurityTokenFilter).addFilter(controllerAnonymousDownloadFilter) + .antMatcher("/*/controller/**").anonymous().disable().authorizeRequests().anyRequest() + .authenticated().and().exceptionHandling() .authenticationEntryPoint((request, response, authException) -> response .setStatus(HttpStatus.UNAUTHORIZED.value())) .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java index 3fa7979b9..9d120c17b 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentfication.java @@ -19,6 +19,8 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.security.CoapAnonymousPreAuthenticatedFilter; import org.eclipse.hawkbit.security.ControllerPreAuthenticateSecurityTokenFilter; +import org.eclipse.hawkbit.security.ControllerPreAuthenticatedAnonymousDownload; +import org.eclipse.hawkbit.security.ControllerPreAuthenticatedAnonymousFilter; import org.eclipse.hawkbit.security.ControllerPreAuthenticatedGatewaySecurityTokenFilter; import org.eclipse.hawkbit.security.ControllerPreAuthenticatedSecurityHeaderFilter; import org.eclipse.hawkbit.security.DdiSecurityProperties; @@ -90,6 +92,11 @@ public class AmqpControllerAuthentfication { tenantConfigurationManagement, controllerManagement, tenantAware, systemSecurityContext); filterChain.add(securityTokenFilter); + final ControllerPreAuthenticatedAnonymousDownload anonymousDownloadFilter = new ControllerPreAuthenticatedAnonymousDownload( + tenantConfigurationManagement, tenantAware, systemSecurityContext); + filterChain.add(anonymousDownloadFilter); + + filterChain.add(new ControllerPreAuthenticatedAnonymousFilter(ddiSecruityProperties)); filterChain.add(new CoapAnonymousPreAuthenticatedFilter()); } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 71b8f8db8..c5fff29ad 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -27,9 +27,9 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; +import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; -import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; @@ -158,8 +158,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { private Message handleAuthentifiactionMessage(final Message message) { final DownloadResponse authentificationResponse = new DownloadResponse(); final MessageProperties messageProperties = message.getMessageProperties(); - final TenantSecurityToken secruityToken = convertMessage(message, - TenantSecurityToken.class); + final TenantSecurityToken secruityToken = convertMessage(message, TenantSecurityToken.class); final FileResource fileResource = secruityToken.getFileResource(); try { SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken)); @@ -221,12 +220,11 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } else if (fileResource.getFilename() != null) { localArtifact = artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream() .findFirst().orElse(null); - } else if (fileResource.getArtifactId() != null) { - final org.eclipse.hawkbit.repository.model.Artifact artifact = artifactManagement - .findArtifact(fileResource.getArtifactId()); - if (artifact instanceof LocalArtifact) { - localArtifact = (LocalArtifact) artifact; - } + } else if (fileResource.getSoftwareModuleFilenameResource() != null) { + localArtifact = artifactManagement + .findByFilenameAndSoftwareModule(fileResource.getSoftwareModuleFilenameResource().getFilename(), + fileResource.getSoftwareModuleFilenameResource().getSoftwareModuleId()) + .stream().findFirst().orElse(null); } return localArtifact; } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java index d7ab805ed..881260579 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.security.DdiSecurityProperties; +import org.eclipse.hawkbit.security.DdiSecurityProperties.Authentication.Anonymous; import org.eclipse.hawkbit.security.DdiSecurityProperties.Rp; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SystemSecurityContext; @@ -80,8 +81,14 @@ public class AmqpControllerAuthenticationTest { final DdiSecurityProperties secruityProperties = mock(DdiSecurityProperties.class); final Rp rp = mock(Rp.class); + final org.eclipse.hawkbit.security.DdiSecurityProperties.Authentication ddiAuthentication = mock( + org.eclipse.hawkbit.security.DdiSecurityProperties.Authentication.class); + final Anonymous anonymous = mock(Anonymous.class); when(secruityProperties.getRp()).thenReturn(rp); when(rp.getSslIssuerHashHeader()).thenReturn("X-Ssl-Issuer-Hash-%d"); + when(secruityProperties.getAuthentication()).thenReturn(ddiAuthentication); + when(ddiAuthentication.getAnonymous()).thenReturn(anonymous); + when(anonymous.isEnabled()).thenReturn(false); authenticationManager.setSecruityProperties(secruityProperties); tenantConfigurationManagement = mock(TenantConfigurationManagement.class); diff --git a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java index 9e07d3fc4..154ad5158 100644 --- a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java +++ b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java @@ -103,7 +103,7 @@ public class TenantSecurityToken { @JsonProperty(required = false) private String filename; @JsonProperty(required = false) - private Long artifactId; + private SoftwareModuleFilenameResource softwareModuleFilenameResource; public String getSha1() { return sha1; @@ -121,12 +121,13 @@ public class TenantSecurityToken { this.filename = filename; } - public Long getArtifactId() { - return artifactId; + public SoftwareModuleFilenameResource getSoftwareModuleFilenameResource() { + return softwareModuleFilenameResource; } - public void setArtifactId(final Long artifactId) { - this.artifactId = artifactId; + public void setSoftwareModuleFilenameResource( + final SoftwareModuleFilenameResource softwareModuleFilenameResource) { + this.softwareModuleFilenameResource = softwareModuleFilenameResource; } /** @@ -156,15 +157,19 @@ public class TenantSecurityToken { } /** - * factory method to create a file resource for an artifactId lookup. + * factory method to create a file resource for an softwaremodule + + * filename lookup, because an filename is not globally unique but + * within a softwaremodule. * - * @param artifactId - * the artifactId of the file to obtain + * @param softwareModuleId + * the ID of the software module which contains the artifact + * @param filename + * the name of file to obtain within the software module * @return the {@link FileResource} with artifactId set */ - public static FileResource artifactId(final Long artifactId) { + public static FileResource softwareModuleFilename(final Long softwareModuleId, final String filename) { final FileResource resource = new FileResource(); - resource.artifactId = artifactId; + resource.softwareModuleFilenameResource = new SoftwareModuleFilenameResource(softwareModuleId, filename); return resource; } @@ -172,5 +177,42 @@ public class TenantSecurityToken { public String toString() { return "FileResource [sha1=" + sha1 + ", filename=" + filename + "]"; } + + /** + * Inner class which holds the pointer to an artifact based on the + * softwaremoduleId and the filename. + */ + @JsonInclude(Include.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown = true) + public static class SoftwareModuleFilenameResource { + @JsonProperty(required = false) + private final Long softwareModuleId; + @JsonProperty(required = false) + private final String filename; + + /** + * Constructor. + * + * @param softwareModuleId + * the ID of the softwaremodule + * @param filename + * the name of the file of the artifact within the + * softwaremodule + */ + @JsonCreator + public SoftwareModuleFilenameResource(@JsonProperty("softwareModuleId") final Long softwareModuleId, + @JsonProperty("filename") final String filename) { + this.softwareModuleId = softwareModuleId; + this.filename = filename; + } + + public Long getSoftwareModuleId() { + return softwareModuleId; + } + + public String getFilename() { + return filename; + } + } } } diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java index ace5bc834..0e67489ea 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java @@ -9,6 +9,8 @@ package org.eclipse.hawkbit.security; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.Map; import javax.servlet.FilterChain; @@ -16,6 +18,7 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; @@ -23,8 +26,11 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; +import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.util.AntPathMatcher; import com.google.common.collect.Iterators; @@ -80,14 +86,6 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac pathExtractor = new AntPathMatcher(); } - /* - * (non-Javadoc) - * - * @see org.springframework.security.web.authentication.preauth. - * AbstractPreAuthenticatedProcessingFilter - * #doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, - * javax.servlet.FilterChain) - */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { @@ -113,6 +111,18 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac protected abstract PreAuthenficationFilter createControllerAuthenticationFilter(); + @Override + protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response, + final Authentication authResult) { + final Collection authorities = new ArrayList<>(); + authorities.addAll(authResult.getAuthorities()); + authorities.addAll(abstractControllerAuthenticationFilter.getSuccessfulAuthenticationAuthorities()); + final PreAuthenticatedAuthenticationToken authTokenWithGrantedAuthorities = new PreAuthenticatedAuthenticationToken( + authResult.getPrincipal(), authResult.getCredentials(), authorities); + authTokenWithGrantedAuthorities.setDetails(authResult.getDetails()); + super.successfulAuthentication(request, response, authTokenWithGrantedAuthorities); + } + /** * Extracts tenant and controllerId from the request URI as path variables. * diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateAnonymousDownloadFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateAnonymousDownloadFilter.java new file mode 100644 index 000000000..40fd1e555 --- /dev/null +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateAnonymousDownloadFilter.java @@ -0,0 +1,47 @@ +/** + * 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.security; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.tenancy.TenantAware; + +/** + * An pre-authenticated processing filter which add the + * {@link SpringEvalExpressions#CONTROLLER_DOWNLOAD_ROLE_ANONYMOUS} to the + * security context in case the anonymous download is allowed through + * configuration. + */ +public class HttpControllerPreAuthenticateAnonymousDownloadFilter extends AbstractHttpControllerAuthenticationFilter { + + /** + * Constructor. + * + * @param tenantConfigurationManagement + * the system management service to retrieve configuration + * properties + * @param tenantAware + * the tenant aware service to get configuration for the specific + * tenant + * @param systemSecurityContext + * the system security context + */ + public HttpControllerPreAuthenticateAnonymousDownloadFilter( + final TenantConfigurationManagement tenantConfigurationManagement, final TenantAware tenantAware, + final SystemSecurityContext systemSecurityContext) { + super(tenantConfigurationManagement, tenantAware, systemSecurityContext); + } + + @Override + protected PreAuthenficationFilter createControllerAuthenticationFilter() { + return new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagement, tenantAware, + systemSecurityContext); + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index 122d7b881..145287fbf 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -404,7 +404,7 @@ public class ArtifactManagement { * if file could not be found in store */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) + + SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD) public DbArtifact loadLocalArtifactBinary(@NotNull final LocalArtifact artifact) { final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName()); if (result == null) { diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java index 5d4ab9283..2e222d879 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java @@ -182,6 +182,12 @@ public final class SpPermission { */ public static final String CONTROLLER_ROLE_ANONYMOUS = "ROLE_CONTROLLER_ANONYMOUS"; + /** + * The role which contains in the spring security context in case an + * controller is authenticated to download artifacts. + */ + public static final String CONTROLLER_DOWNLOAD_ROLE = "ROLE_CONTROLLER_DOWNLOAD"; + /** * The role which contains the spring security context in case the * system is executing code which is necessary to be privileged. @@ -275,8 +281,16 @@ public final class SpPermission { * context contains the anoynmous role or the controller specific role * {@link SpPermission#CONTROLLER_ROLE}. */ - public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" - + CONTROLLER_ROLE + "')"; + public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" + CONTROLLER_ROLE + + "')"; + + /** + * Spring security eval hasAuthority expression to check if the spring + * context contains the role to allow controllers to download specific + * role {@link SpPermission#CONTROLLER_DOWNLOAD_ROLE}. + */ + public static final String HAS_CONTROLLER_DOWNLOAD = HAS_AUTH_PREFIX + CONTROLLER_DOWNLOAD_ROLE + + HAS_AUTH_SUFFIX; /** * Spring security eval hasAnyRole expression to check if the spring diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownload.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownload.java new file mode 100644 index 000000000..b4457bfcf --- /dev/null +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownload.java @@ -0,0 +1,69 @@ +/** + * 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.security; + +import java.util.Collection; + +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import com.google.common.collect.Lists; + +/** + * An pre-authenticated processing filter which add the + * {@link SpringEvalExpressions#CONTROLLER_DOWNLOAD_ROLE_ANONYMOUS} to the + * security context in case the anonymous download is allowed through + * configuration. + */ +public class ControllerPreAuthenticatedAnonymousDownload extends AbstractControllerAuthenticationFilter { + + /** + * Constructor. + * + * @param tenantConfigurationManagement + * the tenant management service to retrieve configuration + * properties + * @param tenantAware + * the tenant aware service to get configuration for the specific + * tenant + * @param systemSecurityContext + * the system security context to get access to tenant + * configuration + */ + public ControllerPreAuthenticatedAnonymousDownload( + final TenantConfigurationManagement tenantConfigurationManagement, final TenantAware tenantAware, + final SystemSecurityContext systemSecurityContext) { + super(tenantConfigurationManagement, tenantAware, systemSecurityContext); + } + + @Override + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); + } + + @Override + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); + } + + @Override + protected TenantConfigurationKey getTenantConfigurationKey() { + return TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED; + } + + @Override + public Collection getSuccessfulAuthenticationAuthorities() { + return Lists.newArrayList(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_DOWNLOAD_ROLE)); + } +} diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousFilter.java new file mode 100644 index 000000000..cf55c47fb --- /dev/null +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousFilter.java @@ -0,0 +1,47 @@ +/** + * 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.security; + +import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; + +/** + * An anonymous controller filter which is only enabled in case of anonymous + * access is granted. This should only be for development purposes. + * + * @see DdiSecurityProperties + */ +public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthenficationFilter { + + private final DdiSecurityProperties ddiSecurityConfiguration; + + /** + * @param ddiSecurityConfiguration + * the security configuration which holds the configuration if + * anonymous is enabled or not + */ + public ControllerPreAuthenticatedAnonymousFilter(final DdiSecurityProperties ddiSecurityConfiguration) { + this.ddiSecurityConfiguration = ddiSecurityConfiguration; + } + + @Override + public HeaderAuthentication getPreAuthenticatedPrincipal(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); + } + + @Override + public HeaderAuthentication getPreAuthenticatedCredentials(final TenantSecurityToken secruityToken) { + return new HeaderAuthentication(secruityToken.getControllerId(), secruityToken.getControllerId()); + } + + @Override + public boolean isEnable(final TenantSecurityToken secruityToken) { + return ddiSecurityConfiguration.getAuthentication().getAnonymous().isEnabled(); + } + +} diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProvider.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProvider.java index ca38404f7..b81b76e5c 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProvider.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthTokenSourceTrustAuthenticationProvider.java @@ -109,6 +109,7 @@ public class PreAuthTokenSourceTrustAuthenticationProvider implements Authentica if (successAuthentication) { final Collection controllerAuthorities = new ArrayList<>(); controllerAuthorities.add(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_ROLE)); + controllerAuthorities.add(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_DOWNLOAD_ROLE)); final PreAuthenticatedAuthenticationToken successToken = new PreAuthenticatedAuthenticationToken(principal, credentials, controllerAuthorities); successToken.setDetails(tokenDetails); diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java index 8981fa9af..5e4aacfa9 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java @@ -8,7 +8,12 @@ */ package org.eclipse.hawkbit.security; +import java.util.Collection; +import java.util.Collections; + import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; /** * Interface for Pre Authenfication. @@ -45,4 +50,16 @@ public interface PreAuthenficationFilter { */ HeaderAuthentication getPreAuthenticatedCredentials(TenantSecurityToken secruityToken); + /** + * Allows to add additional authorities to the successful authenticated + * token. + * + * @return the authorities granted to the principal, or an empty collection + * if the token has not been authenticated. Never null. + * @see Authentication#getAuthorities() + */ + default Collection getSuccessfulAuthenticationAuthorities() { + return Collections.emptyList(); + }; + } From 771516988946924c2a0b6746cc6355b8440b8fc3 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 24 Mar 2016 11:02:28 +0100 Subject: [PATCH 06/56] Added id for checkbox component for selenium tests Signed-off-by: Jonathan Philip Knoblauch --- .../DownloadAnonymousConfigurationView.java | 3 +++ .../hawkbit/ui/utils/SPUIComponetIdProvider.java | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) 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 index fa441476d..e008e03f2 100644 --- 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 @@ -15,6 +15,7 @@ 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.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -80,6 +81,8 @@ public class DownloadAnonymousConfigurationView extends BaseConfigurationView downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); downloadAnonymousCheckBox.setValue(anonymousDownloadEnabled); downloadAnonymousCheckBox.addValueChangeListener(event -> configurationHasChanged()); + downloadAnonymousCheckBox.setId(SPUIComponetIdProvider.SYSTEM_CONFIGURATION_ANONYMOUS_DOWNLOAD_CHECKBOX); + gridLayout.addComponent(downloadAnonymousCheckBox); final Label configurationLabel = SPUIComponentProvider.getLabel(i18n.get("enonymous.download.label"), diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java index 163be34c4..48e501e1d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java @@ -501,6 +501,11 @@ public final class SPUIComponetIdProvider { */ public static final String SYSTEM_CONFIGURATION_CANCEL = "system.configuration.cancel"; + /** + * Id of the anonymous download checkbox. + */ + public static final String SYSTEM_CONFIGURATION_ANONYMOUS_DOWNLOAD_CHECKBOX = "system.configuration.anonymous.download.checkbox"; + /** * Id of maximize/minimize icon of table - Software module table. */ @@ -827,7 +832,7 @@ public final class SPUIComponetIdProvider { * Rollout status label id. */ public static final String ROLLOUT_STATUS_LABEL_ID = "rollout.status.id"; - + /** * Rollout group status label id. */ @@ -867,12 +872,12 @@ public final class SPUIComponetIdProvider { * Rollout group targets count message label. */ public static final String ROLLOUT_GROUP_TARGET_LABEL = "rollout.group.target.label"; - + /** * Action confirmation popup id. */ public static final String CONFIRMATION_POPUP_ID = "action.confirmation.popup.id"; - + /** * Validation status icon . */ From e033e8718ceba8bbb35b676fa0935c011b0db425 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 29 Mar 2016 11:12:42 +0200 Subject: [PATCH 07/56] unit tests for ControllerPreAuthenticatedAnonymousDownloadTest Signed-off-by: Michael Hirsch --- hawkbit-security-integration/pom.xml | 42 +++++++++---- ...PreAuthenticatedAnonymousDownloadTest.java | 61 +++++++++++++++++++ 2 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 hawkbit-security-integration/src/test/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownloadTest.java diff --git a/hawkbit-security-integration/pom.xml b/hawkbit-security-integration/pom.xml index 9d89c1806..591552997 100644 --- a/hawkbit-security-integration/pom.xml +++ b/hawkbit-security-integration/pom.xml @@ -1,13 +1,6 @@ - + 4.0.0 @@ -35,7 +28,32 @@ org.springframework.security spring-security-web + + + + junit + junit + test + + + org.easytesting + fest-assert-core + test + + + org.easytesting + fest-assert + test + + + org.mockito + mockito-core + test + + + ru.yandex.qatools.allure + allure-junit-adaptor + test + - - diff --git a/hawkbit-security-integration/src/test/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownloadTest.java b/hawkbit-security-integration/src/test/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownloadTest.java new file mode 100644 index 000000000..b8195d023 --- /dev/null +++ b/hawkbit-security-integration/src/test/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedAnonymousDownloadTest.java @@ -0,0 +1,61 @@ +/** + * 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.security; + +import static org.fest.assertions.Assertions.assertThat; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * @author Michael Hirsch + * + */ +@Features("Unit Tests - Security") +@Stories("Exclude path aware shallow ETag filter") +@RunWith(MockitoJUnitRunner.class) +public class ControllerPreAuthenticatedAnonymousDownloadTest { + + private ControllerPreAuthenticatedAnonymousDownload underTest; + + @Mock + private TenantConfigurationManagement tenantConfigurationManagementMock; + + @Mock + private TenantAware tenantAwareMock; + + @Before + public void before() { + underTest = new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagementMock, tenantAwareMock, + new SystemSecurityContext(tenantAwareMock)); + } + + @Test + public void useCorrectTenantConfiguationKey() { + assertThat(underTest.getTenantConfigurationKey()).as("Should be using the correct tenant configuration key") + .isEqualTo(underTest.getTenantConfigurationKey()); + } + + @Test + public void successfulAuthenticationAdditionalAuthoritiesForDownload() { + assertThat(underTest.getSuccessfulAuthenticationAuthorities()) + .as("Additional authorities should be containing the download anonymous role") + .contains(new SimpleGrantedAuthority(SpringEvalExpressions.CONTROLLER_DOWNLOAD_ROLE)); + } +} From 4a52936a3c4f2b06ce168925913a3b2a72f5cb50 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 29 Mar 2016 15:03:58 +0200 Subject: [PATCH 08/56] allow to set the filename and software module id Signed-off-by: Michael Hirsch --- .../hawkbit/dmf/json/model/TenantSecurityToken.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java index 154ad5158..ccc3a5b42 100644 --- a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java +++ b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/TenantSecurityToken.java @@ -186,9 +186,9 @@ public class TenantSecurityToken { @JsonIgnoreProperties(ignoreUnknown = true) public static class SoftwareModuleFilenameResource { @JsonProperty(required = false) - private final Long softwareModuleId; + private Long softwareModuleId; @JsonProperty(required = false) - private final String filename; + private String filename; /** * Constructor. @@ -213,6 +213,14 @@ public class TenantSecurityToken { public String getFilename() { return filename; } + + public void setSoftwareModuleId(final Long softwareModuleId) { + this.softwareModuleId = softwareModuleId; + } + + public void setFilename(final String filename) { + this.filename = filename; + } } } } From b03fa5eec8fe8f5ee48fdc325b80ad9c14a396b9 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 31 Mar 2016 13:04:21 +0200 Subject: [PATCH 09/56] Verify all download URLs generated by SP-server (e.g. DDI and DMF API) - the get artifact request for the DDI API know contains https links - additional there where http links added - section for creating download urls based on patters was moved to hawkbit-core - tests where adapted and extended Signed-off-by: Jonathan Philip Knoblauch --- .../hawkbit/api}/ArtifactUrlHandler.java | 11 +- .../api}/ArtifactUrlHandlerProperties.java | 112 +----------------- .../api}/PropertyBasedArtifactUrlHandler.java | 28 ++--- .../org/eclipse/hawkbit/api/UrlProtocol.java | 11 ++ hawkbit-dmf-amqp/pom.xml | 5 + .../amqp/AmqpMessageDispatcherService.java | 13 +- .../AmqpMessageDispatcherServiceTest.java | 6 +- .../PropertyBasedArtifactUrlHandlerTest.java | 23 +++- hawkbit-rest-resource/pom.xml | 5 + .../controller/DataConversionHelper.java | 36 +++--- .../hawkbit/controller/RootController.java | 10 +- .../controller/DeploymentBaseTest.java | 74 ++++++++++-- 12 files changed, 167 insertions(+), 167 deletions(-) rename {hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util => hawkbit-core/src/main/java/org/eclipse/hawkbit/api}/ArtifactUrlHandler.java (73%) rename {hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util => hawkbit-core/src/main/java/org/eclipse/hawkbit/api}/ArtifactUrlHandlerProperties.java (75%) rename {hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util => hawkbit-core/src/main/java/org/eclipse/hawkbit/api}/PropertyBasedArtifactUrlHandler.java (79%) create mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java similarity index 73% rename from hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandler.java rename to hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java index f477da03a..a80551f9e 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java @@ -6,10 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.util; - -import org.eclipse.hawkbit.dmf.json.model.Artifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +package org.eclipse.hawkbit.api; /** * Interface declaration of the {@link ArtifactUrlHandler} which generates the @@ -23,13 +20,13 @@ public interface ArtifactUrlHandler { * Returns a generated URL for a given artifact for a specific protocol. * * @param controllerId - * the authentifacted controller id + * the authenticated controller id * @param localArtifact * the artifact to retrieve a URL to * @param protocol * the protocol the URL should be generated * @return an URL for the given artifact in a given protocol */ - String getUrl(String controllerId, LocalArtifact localArtifact, final Artifact.UrlProtocol protocol); - + String getUrl(String controllerId, final Long softwareModuleId, final String filename, final String sha1Hash, + final UrlProtocol protocol); } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandlerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java similarity index 75% rename from hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandlerProperties.java rename to hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java index 91c385fae..33fe8651e 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/ArtifactUrlHandlerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java @@ -6,13 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.util; +package org.eclipse.hawkbit.api; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * - * + * Artifact handler properties class for holding all supported protocols with + * host, ip, port and download pattern. */ @ConfigurationProperties("hawkbit.artifact.url") public class ArtifactUrlHandlerProperties { @@ -23,23 +23,14 @@ public class ArtifactUrlHandlerProperties { private final Https https = new Https(); private final Coap coap = new Coap(); - /** - * @return the http - */ public Http getHttp() { return http; } - /** - * @return the https - */ public Https getHttps() { return https; } - /** - * @return the coap - */ public Coap getCoap() { return coap; } @@ -66,9 +57,6 @@ public class ArtifactUrlHandlerProperties { /** * Interface for declaring common properties through all supported protocols * pattern. - * - * - * */ public interface ProtocolProperties { /** @@ -94,9 +82,6 @@ public class ArtifactUrlHandlerProperties { /** * Object to hold the properties for the HTTP protocol. - * - * - * */ public static class Http implements ProtocolProperties { private String hostname = LOCALHOST; @@ -108,66 +93,38 @@ public class ArtifactUrlHandlerProperties { */ private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"; - /** - * @return the hostname - */ @Override public String getHostname() { return hostname; } - /** - * @param hostname - * the hostname to set - */ public void setHostname(final String hostname) { this.hostname = hostname; } - /** - * @return the ip - */ @Override public String getIp() { return ip; } - /** - * @param ip - * the ip to set - */ public void setIp(final String ip) { this.ip = ip; } - /** - * @return the urlPattern - */ @Override public String getPattern() { return pattern; } - /** - * @param urlPattern - * the urlPattern to set - */ public void setPattern(final String urlPattern) { this.pattern = urlPattern; } - /** - * @return the port - */ @Override public String getPort() { return port; } - /** - * @param port - * the port to set - */ public void setPort(final String port) { this.port = port; } @@ -175,9 +132,6 @@ public class ArtifactUrlHandlerProperties { /** * Object to hold the properties for the HTTP protocol. - * - * - * */ public static class Https implements ProtocolProperties { private String hostname = LOCALHOST; @@ -189,66 +143,38 @@ public class ArtifactUrlHandlerProperties { */ private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"; - /** - * @return the hostname - */ @Override public String getHostname() { return hostname; } - /** - * @param hostname - * the hostname to set - */ public void setHostname(final String hostname) { this.hostname = hostname; } - /** - * @return the ip - */ @Override public String getIp() { return ip; } - /** - * @param ip - * the ip to set - */ public void setIp(final String ip) { this.ip = ip; } - /** - * @return the urlPattern - */ @Override public String getPattern() { return pattern; } - /** - * @param urlPattern - * the urlPattern to set - */ public void setPattern(final String urlPattern) { this.pattern = urlPattern; } - /** - * @return the port - */ @Override public String getPort() { return port; } - /** - * @param port - * the port to set - */ public void setPort(final String port) { this.port = port; } @@ -256,9 +182,6 @@ public class ArtifactUrlHandlerProperties { /** * Object to hold the properties for the HTTP protocol. - * - * - * */ public static class Coap implements ProtocolProperties { private String hostname = LOCALHOST; @@ -270,68 +193,41 @@ public class ArtifactUrlHandlerProperties { */ private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}"; - /** - * @return the hostname - */ @Override public String getHostname() { return hostname; } - /** - * @param hostname - * the hostname to set - */ public void setHostname(final String hostname) { this.hostname = hostname; } - /** - * @return the ip - */ @Override public String getIp() { return ip; } - /** - * @param ip - * the ip to set - */ public void setIp(final String ip) { this.ip = ip; } - /** - * @return the urlPattern - */ @Override public String getPattern() { return pattern; } - /** - * @param urlPattern - * the urlPattern to set - */ public void setPattern(final String urlPattern) { this.pattern = urlPattern; } - /** - * @return the port - */ @Override public String getPort() { return port; } - /** - * @param port - * the port to set - */ public void setPort(final String port) { this.port = port; } } + } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java similarity index 79% rename from hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandler.java rename to hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java index 8d4cfbc28..174086613 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java @@ -6,17 +6,15 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.util; +package org.eclipse.hawkbit.api; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.hawkbit.dmf.json.model.Artifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.ProtocolProperties; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.eclipse.hawkbit.util.ArtifactUrlHandlerProperties.ProtocolProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.stereotype.Component; @@ -24,8 +22,8 @@ import org.springframework.stereotype.Component; import com.google.common.base.Strings; /** - * - * + * Implementation for ArtifactUrlHandler for creating urls to download resource + * based on pattern. */ @Component @EnableConfigurationProperties(ArtifactUrlHandlerProperties.class) @@ -48,7 +46,9 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { private TenantAware tenantAware; @Override - public String getUrl(final String targetId, final LocalArtifact artifact, final Artifact.UrlProtocol protocol) { + public String getUrl(final String targetId, final Long softwareModuleId, final String filename, + final String sha1Hash, final UrlProtocol protocol) { + final String protocolString = protocol.name().toLowerCase(); final ProtocolProperties properties = urlHandlerProperties.getProperties(protocolString); if (properties == null || properties.getPattern() == null) { @@ -56,8 +56,8 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { } String urlPattern = properties.getPattern(); - final Set> entrySet = getReplaceMap(targetId, artifact, protocolString, properties) - .entrySet(); + final Set> entrySet = getReplaceMap(targetId, softwareModuleId, filename, sha1Hash, + protocolString, properties).entrySet(); for (final Entry entry : entrySet) { if (entry.getKey().equals(PORT_PLACEHOLDER)) { urlPattern = urlPattern.replace(":{" + entry.getKey() + "}", @@ -69,18 +69,18 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { return urlPattern; } - private Map getReplaceMap(final String targetId, final LocalArtifact artifact, - final String protocol, final ProtocolProperties properties) { + private Map getReplaceMap(final String targetId, final Long softwareModuleId, final String filename, + final String sha1Hash, final String protocol, final ProtocolProperties properties) { final Map replaceMap = new HashMap<>(); replaceMap.put(IP_PLACEHOLDER, properties.getIp()); replaceMap.put(HOSTNAME_PLACEHOLDER, properties.getHostname()); - replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER, artifact.getFilename()); - replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, artifact.getSha1Hash()); + replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER, filename); + replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, sha1Hash); replaceMap.put(PROTOCOL_PLACEHOLDER, protocol); replaceMap.put(PORT_PLACEHOLDER, properties.getPort()); replaceMap.put(TENANT_PLACEHOLDER, tenantAware.getCurrentTenant()); replaceMap.put(TARGET_ID_PLACEHOLDER, targetId); - replaceMap.put(SOFTWARE_MODULE_ID_PLACDEHOLDER, String.valueOf(artifact.getSoftwareModule().getId())); + replaceMap.put(SOFTWARE_MODULE_ID_PLACDEHOLDER, String.valueOf(softwareModuleId)); return replaceMap; } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java new file mode 100644 index 000000000..4dd84b7da --- /dev/null +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + */ +package org.eclipse.hawkbit.api; + +/** + * Represented the supported protocols for artifact url's. + */ +public enum UrlProtocol { + COAP, HTTP, HTTPS +} diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index 2fded8559..127103b91 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -25,6 +25,11 @@ org.eclipse.hawkbit hawkbit-repository ${project.version} + + + org.eclipse.hawkbit + hawkbit-core + ${project.version} org.eclipse.hawkbit diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index b9e6fe9da..19e0cbadf 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -14,6 +14,8 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; +import org.eclipse.hawkbit.api.UrlProtocol; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; @@ -25,7 +27,6 @@ import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.model.LocalArtifact; -import org.eclipse.hawkbit.util.ArtifactUrlHandler; import org.eclipse.hawkbit.util.IpUtil; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageProperties; @@ -152,12 +153,16 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { private Artifact convertArtifact(final String targetId, final LocalArtifact localArtifact) { final Artifact artifact = new Artifact(); + artifact.getUrls().put(Artifact.UrlProtocol.COAP, - artifactUrlHandler.getUrl(targetId, localArtifact, Artifact.UrlProtocol.COAP)); + artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(), + localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.COAP)); artifact.getUrls().put(Artifact.UrlProtocol.HTTP, - artifactUrlHandler.getUrl(targetId, localArtifact, Artifact.UrlProtocol.HTTP)); + artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(), + localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTP)); artifact.getUrls().put(Artifact.UrlProtocol.HTTPS, - artifactUrlHandler.getUrl(targetId, localArtifact, Artifact.UrlProtocol.HTTPS)); + artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(), + localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTPS)); artifact.setFilename(localArtifact.getFilename()); artifact.setHashes(new ArtifactHash(localArtifact.getSha1Hash(), null)); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 46ddd35cc..f2c3d254c 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -25,6 +26,7 @@ import java.util.List; import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; @@ -36,7 +38,6 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.util.ArtifactUrlHandler; import org.eclipse.hawkbit.util.IpUtil; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -77,7 +78,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit amqpMessageDispatcherService.setAmqpSenderService(senderService); final ArtifactUrlHandler artifactUrlHandlerMock = Mockito.mock(ArtifactUrlHandler.class); - when(artifactUrlHandlerMock.getUrl(anyString(), any(), anyObject())).thenReturn("http://mockurl"); + when(artifactUrlHandlerMock.getUrl(anyString(), anyLong(), anyString(), anyString(), anyObject())) + .thenReturn("http://mockurl"); amqpMessageDispatcherService.setArtifactUrlHandler(artifactUrlHandlerMock); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index e7ba06d19..bfc560c38 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -15,7 +15,8 @@ import org.eclipse.hawkbit.AmqpTestConfiguration; import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.TestConfiguration; import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.dmf.json.model.Artifact; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; +import org.eclipse.hawkbit.api.UrlProtocol; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -30,8 +31,7 @@ import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; /** - * - * + * Tests for creating urls to download artifacts. */ @Features("Component Tests - Artifact URL Handler") @Stories("Test to generate the artifact download URL") @@ -45,6 +45,9 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest private TenantAware tenantAware; private LocalArtifact localArtifact; private final String controllerId = "Test"; + private String fileName; + private Long softwareModuleId; + private String sha1Hash; @Before public void setup() { @@ -53,12 +56,18 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest final SoftwareModule module = dsA.getModules().iterator().next(); localArtifact = (LocalArtifact) TestDataUtil.generateArtifacts(artifactManagement, module.getId()).stream() .findAny().get(); + softwareModuleId = localArtifact.getSoftwareModule().getId(); + fileName = localArtifact.getFilename(); + sha1Hash = localArtifact.getSha1Hash(); + } @Test @Description("Tests the generation of http download url.") public void testHttpUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.HTTP); + + final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + UrlProtocol.HTTP); assertEquals("http is build incorrect", "http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" @@ -69,7 +78,8 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Test @Description("Tests the generation of https download url.") public void testHttpsUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.HTTPS); + final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + UrlProtocol.HTTPS); assertEquals("https is build incorrect", "https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" @@ -80,7 +90,8 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Test @Description("Tests the generation of coap download url.") public void testCoapUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, localArtifact, Artifact.UrlProtocol.COAP); + final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + UrlProtocol.COAP); assertEquals("coap is build incorrect", "coap://127.0.0.1:5683/fw/" + tenantAware.getCurrentTenant() + "/" + controllerId + "/sha1/" + localArtifact.getSha1Hash(), url); diff --git a/hawkbit-rest-resource/pom.xml b/hawkbit-rest-resource/pom.xml index 633a1f8cc..0be5d20f5 100644 --- a/hawkbit-rest-resource/pom.xml +++ b/hawkbit-rest-resource/pom.xml @@ -25,6 +25,11 @@ org.eclipse.hawkbit hawkbit-repository ${project.version} + + + org.eclipse.hawkbit + hawkbit-core + ${project.version} org.eclipse.hawkbit diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java index ef4468815..03623abdd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java @@ -18,6 +18,8 @@ import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; +import org.eclipse.hawkbit.api.UrlProtocol; import org.eclipse.hawkbit.controller.model.Artifact; import org.eclipse.hawkbit.controller.model.Chunk; import org.eclipse.hawkbit.controller.model.Config; @@ -29,27 +31,29 @@ import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash; import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.Link; import com.google.common.base.Charsets; /** * Utility class for the Controller API. - * - * - * - * */ public final class DataConversionHelper { + @Autowired + ArtifactUrlHandler artifactUrlHandler; + // utility class, private constructor. private DataConversionHelper() { } - static List createChunks(final String targetid, final Action uAction, final TenantAware tenantAware) { - return uAction.getDistributionSet() - .getModules().stream().map(module -> new Chunk(mapChunkLegacyKeys(module.getType().getKey()), - module.getVersion(), module.getName(), createArtifacts(targetid, module, tenantAware))) + static List createChunks(final String targetid, final Action uAction, final TenantAware tenantAware, + final ArtifactUrlHandler artifactUrlHandler) { + return uAction.getDistributionSet().getModules().stream() + .map(module -> new Chunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), + module.getName(), createArtifacts(targetid, module, tenantAware, artifactUrlHandler))) .collect(Collectors.toList()); } @@ -77,18 +81,22 @@ public final class DataConversionHelper { * @return a list of artifacts or a empty list. Cannot be . */ public static List createArtifacts(final String targetid, - final org.eclipse.hawkbit.repository.model.SoftwareModule module, final TenantAware tenantAware) { + final org.eclipse.hawkbit.repository.model.SoftwareModule module, final TenantAware tenantAware, + final ArtifactUrlHandler artifactUrlHandler) { final List files = new ArrayList<>(); module.getLocalArtifacts().forEach(artifact -> { final Artifact file = new Artifact(); file.setHashes(new ArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); file.setFilename(artifact.getFilename()); file.setSize(artifact.getSize()); - - file.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifact(targetid, - artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("download")); - file.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifactMd5(targetid, - artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("md5sum")); + final String linkHttp = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(), + artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTP); + final String linkHttps = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(), + artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTPS); + file.add(new Link(linkHttps).withRel("download")); + file.add(new Link(linkHttps + ".MD5SUM").withRel("md5sum")); + file.add(new Link(linkHttp).withRel("download-http")); + file.add(new Link(linkHttp + ".MD5SUM").withRel("md5sum-http")); files.add(file); }); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index ff1e26f8b..0a668338c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.controller.model.ActionFeedback; @@ -94,6 +95,9 @@ public class RootController { @Autowired private HawkbitSecurityProperties securityProperties; + @Autowired + private ArtifactUrlHandler artifactUrlHandler; + /** * Returns all artifacts of a given software module and target. * @@ -118,7 +122,8 @@ public class RootController { } - return new ResponseEntity<>(DataConversionHelper.createArtifacts(targetid, softwareModule, tenantAware), + return new ResponseEntity<>( + DataConversionHelper.createArtifacts(targetid, softwareModule, tenantAware, artifactUrlHandler), HttpStatus.OK); } @@ -307,7 +312,8 @@ public class RootController { if (!action.isCancelingOrCanceled()) { - final List chunks = DataConversionHelper.createChunks(targetid, action, tenantAware); + final List chunks = DataConversionHelper.createChunks(targetid, action, tenantAware, + artifactUrlHandler); final HandlingType handlingType = action.isForce() ? HandlingType.FORCED : HandlingType.ATTEMPT; diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java index 2b2b7e597..75e0f906a 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java @@ -170,15 +170,27 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.MD5SUM"))) + + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", + equalTo("http://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].size", equalTo(5 * 1024))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].filename", equalTo("test1.signature"))) @@ -188,11 +200,21 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", + equalTo("http://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() @@ -293,12 +315,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) @@ -311,11 +333,21 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", + equalTo("http://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() @@ -409,15 +441,25 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].filename", equalTo("test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.md5", equalTo(artifact.getMd5Hash()))) - .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", - equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", + equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.MD5SUM"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", + equalTo("http://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() @@ -431,15 +473,27 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", + equalTo("https://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) + + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", + equalTo("http://localhost/" + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) + .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].version", equalTo(ds.findFirstModuleByType(appType).getVersion()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].name", From 1d416327d69380ffd48fe8b25a969f1b0f9c9b1e Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 31 Mar 2016 15:08:20 +0200 Subject: [PATCH 10/56] Sonar fix moving private methods to inner classes - Rule: "private" methods called only by inner classes should be moved to those classes Signed-off-by: Jonathan Philip Knoblauch --- .../ui/artifacts/upload/UploadLayout.java | 31 ++- .../common/tagdetails/AbstractTagToken.java | 34 +-- .../targettable/BulkUploadHandler.java | 213 ++++++++---------- .../ui/rollout/rollout/RolloutListGrid.java | 53 ++--- .../rolloutgroup/RolloutGroupListGrid.java | 24 +- .../RolloutGroupTargetsListGrid.java | 63 +++--- .../polling/DurationConfigField.java | 12 +- 7 files changed, 199 insertions(+), 231 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 41304ddc9..3fb735284 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -215,13 +215,18 @@ public class UploadLayout extends VerticalLayout { hasDirectory = Boolean.TRUE; } } - } - private static boolean isDirectory(final Html5File file) { - if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { - return true; + private StreamVariable createStreamVariable(final Html5File file) { + return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, uploadInfoWindow, + spInfo.getMaxArtifactFileSize(), null, file.getType()); + } + + private boolean isDirectory(final Html5File file) { + if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { + return true; + } + return false; } - return false; } private void displayCompositeMessage() { @@ -282,11 +287,6 @@ public class UploadLayout extends VerticalLayout { discardBtn.addClickListener(event -> discardUploadData(event)); } - private StreamVariable createStreamVariable(final Html5File file) { - return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), null, file.getType()); - } - boolean checkForDuplicate(final String filename) { final Boolean isDuplicate = checkIfFileIsDuplicate(filename); if (isDuplicate) { @@ -349,17 +349,17 @@ public class UploadLayout extends VerticalLayout { } } - Boolean validate(DragAndDropEvent event) { + Boolean validate(final DragAndDropEvent event) { // check if drop is valid.If valid ,check if software module is // selected. - if(!isFilesDropped(event)){ + if (!isFilesDropped(event)) { uiNotification.displayValidationError(i18n.get("message.action.not.allowed")); return false; } return checkIfSoftwareModuleIsSelected(); } - private boolean isFilesDropped(DragAndDropEvent event) { + private boolean isFilesDropped(final DragAndDropEvent event) { if (event.getTransferable() instanceof WrapperTransferable) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); // other components can also be wrapped in WrapperTransferable , so @@ -448,7 +448,7 @@ public class UploadLayout extends VerticalLayout { } private String getDuplicateFileValidationMessage() { - StringBuilder message = new StringBuilder(); + final StringBuilder message = new StringBuilder(); if (!duplicateFileNamesList.isEmpty()) { final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); if (duplicateFileNamesList.size() == 1) { @@ -655,8 +655,7 @@ public class UploadLayout extends VerticalLayout { return uiNotification; } - - public void setHasDirectory(Boolean hasDirectory) { + public void setHasDirectory(final Boolean hasDirectory) { this.hasDirectory = hasDirectory; } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index a00b8ce70..5e5389c9f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -151,18 +151,25 @@ public abstract class AbstractTagToken implements Serializable { } } - } + private void updateTokenStyle(final Object tokenId, final Button button) { + final String color = getColor(tokenId); + button.setCaption("" + FontAwesome.CIRCLE.getHtml() + + "" + " " + getItemNameProperty(tokenId).getValue().toString().concat(" ×")); + button.setCaptionAsHtml(true); + } - private void updateTokenStyle(final Object tokenId, final Button button) { - final String color = getColor(tokenId); - button.setCaption("" + FontAwesome.CIRCLE.getHtml() + "" - + " " + getItemNameProperty(tokenId).getValue().toString().concat(" ×")); - button.setCaptionAsHtml(true); - } + private void onTokenSearch(final Object tokenId) { + assignTag(getItemNameProperty(tokenId).getValue().toString()); + removeTagAssignedFromCombo((Long) tokenId); + } + + private void tokenClick(final Object tokenId) { + final Item item = tokenField.getContainerDataSource().addItem(tokenId); + item.getItemProperty("name").setValue(tagDetails.get(tokenId).getName()); + item.getItemProperty(COLOR_PROPERTY).setValue(tagDetails.get(tokenId).getColor()); + unassignTag(tagDetails.get(tokenId).getName()); + } - private void onTokenSearch(final Object tokenId) { - assignTag(getItemNameProperty(tokenId).getValue().toString()); - removeTagAssignedFromCombo((Long) tokenId); } private Property getItemNameProperty(final Object tokenId) { @@ -184,13 +191,6 @@ public abstract class AbstractTagToken implements Serializable { return (String) item.getItemProperty("name").getValue(); } - private void tokenClick(final Object tokenId) { - final Item item = tokenField.getContainerDataSource().addItem(tokenId); - item.getItemProperty("name").setValue(tagDetails.get(tokenId).getName()); - item.getItemProperty(COLOR_PROPERTY).setValue(tagDetails.get(tokenId).getColor()); - unassignTag(tagDetails.get(tokenId).getName()); - } - protected void removePreviouslyAddedTokens() { tokensAdded.keySet().forEach(previouslyAddedToken -> tokenField.removeToken(previouslyAddedToken)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 0716e6bd6..1a388c324 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -63,14 +63,10 @@ import com.vaadin.ui.Upload.SucceededListener; /** * Bulk target upload handler. - * */ public class BulkUploadHandler extends CustomComponent implements SucceededListener, FailedListener, Receiver, StartedListener { - /** - * - */ private static final long serialVersionUID = -1273494705754674501L; private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class); @@ -149,12 +145,6 @@ public class BulkUploadHandler extends CustomComponent setCompositionRoot(horizontalLayout); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Upload.Receiver#receiveUpload(java.lang.String, - * java.lang.String) - */ @Override public OutputStream receiveUpload(final String filename, final String mimeType) { try { @@ -170,25 +160,11 @@ public class BulkUploadHandler extends CustomComponent return new NullOutputStream(); } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.Upload.FailedListener#uploadFailed(com.vaadin.ui.Upload. - * FailedEvent) - */ @Override public void uploadFailed(final FailedEvent event) { LOG.info("Upload failed for file :{} due to {}", event.getFilename(), event.getReason()); } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.Upload.SucceededListener#uploadSucceeded(com.vaadin.ui. - * Upload.SucceededEvent) - */ @Override public void uploadSucceeded(final SucceededEvent event) { executor.execute(new UploadAsync(event)); @@ -252,6 +228,61 @@ public class BulkUploadHandler extends CustomComponent } } + private double getTotalNumberOfLines() { + + double totalFileSize = 0; + try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), + Charset.defaultCharset())) { + try (BufferedReader readerForSize = new BufferedReader(inputStreamReader)) { + totalFileSize = readerForSize.lines().count(); + } + } catch (final FileNotFoundException e) { + LOG.error("Error reading file {}", tempFile.getName(), e); + } catch (final IOException e) { + LOG.error("Error while closing reader of file {}", tempFile.getName(), e); + } + + return totalFileSize; + } + + private void resetCounts() { + successfullTargetCount = 0; + failedTargetCount = 0; + } + + private void deleteFile() { + if (tempFile.exists()) { + final boolean isDeleted = tempFile.delete(); + if (!isDeleted) { + LOG.info("File {} was not deleted !", tempFile.getName()); + } + } + tempFile = null; + } + + private void readEachLine(final String line, final double innerCounter, final double totalFileSize) { + final String csvDelimiter = ","; + final String[] targets = line.split(csvDelimiter); + if (targets.length == 2) { + final String controllerId = targets[0]; + final String targetName = targets[1]; + addNewTarget(controllerId, targetName); + } else { + failedTargetCount++; + } + final float current = managementUIState.getTargetTableFilters().getBulkUpload() + .getProgressBarCurrentValue(); + final float next = (float) (innerCounter / totalFileSize); + if (Math.abs(next - 0.1) < 0.00001 || current - next >= 0 || next - current >= 0.05 + || Math.abs(next - 1) < 0.00001) { + managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(next); + managementUIState.getTargetTableFilters().getBulkUpload() + .setSucessfulUploadCount(successfullTargetCount); + managementUIState.getTargetTableFilters().getBulkUpload().setFailedUploadCount(failedTargetCount); + eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED)); + } + } + private void doAssignments() { final StringBuilder errorMessage = new StringBuilder(); String dsAssignmentFailedMsg = null; @@ -267,6 +298,43 @@ public class BulkUploadHandler extends CustomComponent displayValidationMessage(errorMessage, dsAssignmentFailedMsg, tagAssignmentFailedMsg); } + private String saveAllAssignments() { + final ActionType actionType = ActionType.FORCED; + final long forcedTimeStamp = new Date().getTime(); + final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload(); + final List targetsList = targetBulkUpload.getTargetsCreated(); + final DistributionSetIdName dsSelected = (DistributionSetIdName) comboBox.getValue(); + if (distributionSetManagement.findDistributionSetById(dsSelected.getId()) == null) { + return i18n.get("message.bulk.upload.assignment.failed"); + } else { + deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion().getId(), actionType, + forcedTimeStamp, targetsList.toArray(new String[targetsList.size()])); + return null; + } + } + + private String tagAssignment() { + final Map tokensSelected = targetBulkTokenTags.getTokensAdded(); + final List deletedTags = new ArrayList<>(); + for (final TagData tagData : tokensSelected.values()) { + if (tagManagement.findTargetTagById(tagData.getId()) == null) { + deletedTags.add(tagData.getName()); + } else { + targetManagement.toggleTagAssignment( + managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated(), + tagData.getName()); + } + } + if (!deletedTags.isEmpty()) { + if (deletedTags.size() == 1) { + return i18n.get("message.bulk.upload.tag.assignment.failed", deletedTags.get(0)); + } else { + return i18n.get("message.bulk.upload.tag.assignments.failed"); + } + } + return null; + } + private boolean ifTagsSelected() { return targetBulkTokenTags.getTokenField().getValue() != null; } @@ -307,59 +375,6 @@ public class BulkUploadHandler extends CustomComponent } } - private double getTotalNumberOfLines() { - - double totalFileSize = 0; - try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), - Charset.defaultCharset())) { - try (BufferedReader readerForSize = new BufferedReader(inputStreamReader)) { - totalFileSize = readerForSize.lines().count(); - } - } catch (final FileNotFoundException e) { - LOG.error("Error reading file {}", tempFile.getName(), e); - } catch (final IOException e) { - LOG.error("Error while closing reader of file {}", tempFile.getName(), e); - } - - return totalFileSize; - } - - private void resetCounts() { - successfullTargetCount = 0; - failedTargetCount = 0; - } - - private void deleteFile() { - if (tempFile.exists()) { - final boolean isDeleted = tempFile.delete(); - if (!isDeleted) { - LOG.info("File {} was not deleted !", tempFile.getName()); - } - } - tempFile = null; - } - - private void readEachLine(final String line, final double innerCounter, final double totalFileSize) { - final String csvDelimiter = ","; - final String[] targets = line.split(csvDelimiter); - if (targets.length == 2) { - final String controllerId = targets[0]; - final String targetName = targets[1]; - addNewTarget(controllerId, targetName); - } else { - failedTargetCount++; - } - final float current = managementUIState.getTargetTableFilters().getBulkUpload().getProgressBarCurrentValue(); - final float next = (float) (innerCounter / totalFileSize); - if (Math.abs(next - 0.1) < 0.00001 || current - next >= 0 || next - current >= 0.05 - || Math.abs(next - 1) < 0.00001) { - managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(next); - managementUIState.getTargetTableFilters().getBulkUpload().setSucessfulUploadCount(successfullTargetCount); - managementUIState.getTargetTableFilters().getBulkUpload().setFailedUploadCount(failedTargetCount); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED)); - } - } - private void addNewTarget(final String controllerId, final String name) { final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId); if (mandatoryCheck(newControllerId) && duplicateCheck(newControllerId)) { @@ -405,43 +420,6 @@ public class BulkUploadHandler extends CustomComponent } } - private String saveAllAssignments() { - final ActionType actionType = ActionType.FORCED; - final long forcedTimeStamp = new Date().getTime(); - final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload(); - final List targetsList = targetBulkUpload.getTargetsCreated(); - final DistributionSetIdName dsSelected = (DistributionSetIdName) comboBox.getValue(); - if (distributionSetManagement.findDistributionSetById(dsSelected.getId()) == null) { - return i18n.get("message.bulk.upload.assignment.failed"); - } else { - deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion().getId(), actionType, - forcedTimeStamp, targetsList.toArray(new String[targetsList.size()])); - return null; - } - } - - private String tagAssignment() { - final Map tokensSelected = targetBulkTokenTags.getTokensAdded(); - final List deletedTags = new ArrayList<>(); - for (final TagData tagData : tokensSelected.values()) { - if (tagManagement.findTargetTagById(tagData.getId()) == null) { - deletedTags.add(tagData.getName()); - } else { - targetManagement.toggleTagAssignment( - managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated(), - tagData.getName()); - } - } - if (!deletedTags.isEmpty()) { - if (deletedTags.size() == 1) { - return i18n.get("message.bulk.upload.tag.assignment.failed", deletedTags.get(0)); - } else { - return i18n.get("message.bulk.upload.tag.assignments.failed"); - } - } - return null; - } - private static class NullOutputStream extends OutputStream { /** * null output stream. @@ -462,13 +440,6 @@ public class BulkUploadHandler extends CustomComponent return upload; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.Upload.StartedListener#uploadStarted(com.vaadin.ui.Upload - * .StartedEvent) - */ @Override public void uploadStarted(final StartedEvent event) { if (!event.getFilename().endsWith(".csv")) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 9151f3932..d60d72527 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -245,7 +245,7 @@ public class RolloutListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); columnList.add(SPUILabelDefinitions.VAR_STATUS); @@ -265,13 +265,13 @@ public class RolloutListGrid extends AbstractGrid { @Override protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); + final List columnsToBeHidden = new ArrayList<>(); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { + for (final Object propertyId : columnsToBeHidden) { getColumn(propertyId).setHidden(true); } @@ -318,7 +318,7 @@ public class RolloutListGrid extends AbstractGrid { @Override public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { return "centeralign"; } @@ -327,18 +327,18 @@ public class RolloutListGrid extends AbstractGrid { }); } - private void onClickOfRolloutName(RendererClickEvent event) { + private void onClickOfRolloutName(final RendererClickEvent event) { rolloutUIState.setRolloutId((long) event.getItemId()); final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); rolloutUIState.setRolloutName(rolloutName); - String ds = (String) getContainerDataSource().getItem(event.getItemId()) + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); rolloutUIState.setRolloutDistributionSet(ds); eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); } - private void onClickOfActionBtn(RendererClickEvent event) { + private void onClickOfActionBtn(final RendererClickEvent event) { final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); contextMenu.open(event.getClientX(), event.getClientY()); @@ -377,7 +377,6 @@ public class RolloutListGrid extends AbstractGrid { return context; } - private void getUpdateMenuItem(final ContextMenu context, final Long rolloutId) { // Add 'Update' option only if user has update permission if (!permissionChecker.hasRolloutUpdatePermission()) { @@ -387,17 +386,6 @@ public class RolloutListGrid extends AbstractGrid { cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); } - private String convertRolloutStatusToString(final RolloutStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); - } - private void menuItemClicked(final ContextMenuItemClickEvent event) { final ContextMenuItem item = (ContextMenuItem) event.getSource(); final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); @@ -441,12 +429,12 @@ public class RolloutListGrid extends AbstractGrid { private static final long serialVersionUID = 2544026030795375748L; private final FontAwesome fontIcon; - public FontIconGenerator(FontAwesome icon) { + public FontIconGenerator(final FontAwesome icon) { this.fontIcon = icon; } @Override - public String getValue(Item item, Object itemId, Object propertyId) { + public String getValue(final Item item, final Object itemId, final Object propertyId) { return fontIcon.getHtml(); } @@ -456,7 +444,7 @@ public class RolloutListGrid extends AbstractGrid { } } - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return cell.getProperty().getValue().toString().toLowerCase(); } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { @@ -558,6 +546,17 @@ public class RolloutListGrid extends AbstractGrid { public Class getPresentationType() { return String.class; } + + private String convertRolloutStatusToString(final RolloutStatus value) { + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + final String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + } } /** @@ -570,14 +569,16 @@ public class RolloutListGrid extends AbstractGrid { private static final long serialVersionUID = -5794528427855153924L; @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 44d945efd..bb4adfe4a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -273,17 +273,7 @@ public class RolloutGroupListGrid extends AbstractGrid { eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); } - private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), - SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); - - } + private void createRolloutGroupStatusToFontMap() { statusIconMap.put(RolloutGroupStatus.FINISHED, @@ -391,6 +381,18 @@ public class RolloutGroupListGrid extends AbstractGrid { public Class getPresentationType() { return String.class; } + + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + StatusFontIcon statusFontIcon = statusIconMap.get(value); + if (statusFontIcon == null) { + return null; + } + String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + + } } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java index e55b30111..0099dfc95 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -158,7 +158,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnList.add(SPUILabelDefinitions.VAR_CREATED_BY); @@ -218,11 +218,9 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { public String convertToPresentation(final Status status, final Class targetType, final Locale locale) { if (status == null) { - // Actions are not created for targets when - // rollout's status - // is READY and when duplicate assignment is done. - // In these cases display a appropriate status with - // description + // Actions are not created for targets when rollout's status is + // READY and when duplicate assignment is done. In these cases + // display a appropriate status with description return getStatus(); } return processActionStatus(status); @@ -238,16 +236,31 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { return String.class; } - } - - private String processActionStatus(final Status status) { - StatusFontIcon statusFontIcon = statusIconMap.get(status); - if (statusFontIcon == null) { - return null; + private String processActionStatus(final Status status) { + final StatusFontIcon statusFontIcon = statusIconMap.get(status); + if (statusFontIcon == null) { + return null; + } + final String codePoint = statusFontIcon.getFontIcon() != null + ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), null); } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; - return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), null); + + private String getStatus() { + final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() + ? rolloutUIState.getRolloutGroup().get() : null; + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", null); + } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.MINUS_CIRCLE.getCodepoint()), "statusIconBlue", null); + } else { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); + } + } + } private void createRolloutStatusToFontMap() { @@ -271,22 +284,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); } - private String getStatus() { - final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() - ? rolloutUIState.getRolloutGroup().get() : null; - if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { - return HawkbitCommonUtil.getStatusLabelDetailsInString( - Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", null); - } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { - return HawkbitCommonUtil.getStatusLabelDetailsInString( - Integer.toString(FontAwesome.MINUS_CIRCLE.getCodepoint()), "statusIconBlue", null); - } else { - return HawkbitCommonUtil.getStatusLabelDetailsInString( - Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); - } - } - - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (!SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return null; } @@ -296,7 +294,6 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { } return cell.getProperty().getValue().toString().toLowerCase(); } - private String getDescriptionWhenNoAction() { final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() @@ -304,7 +301,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { return RolloutGroupStatus.READY.toString().toLowerCase(); } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { - String ds = rolloutUIState.getRolloutDistributionSet().isPresent() + final String ds = rolloutUIState.getRolloutDistributionSet().isPresent() ? rolloutUIState.getRolloutDistributionSet().get() : ""; return i18n.get("message.dist.already.assigned", new Object[] { ds }); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java index 8cefc15fa..e1569db02 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java @@ -14,8 +14,6 @@ import java.util.List; import org.eclipse.hawkbit.ui.tenantconfiguration.ConfigurationItem; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.ui.Alignment; import com.vaadin.ui.CheckBox; import com.vaadin.ui.GridLayout; @@ -50,8 +48,8 @@ public class DurationConfigField extends GridLayout implements ConfigurationItem this.addComponent(durationField, 1, 0); this.setComponentAlignment(durationField, Alignment.MIDDLE_LEFT); - checkBox.addValueChangeListener(event->checkBoxChange()); - durationField.addValueChangeListener(event->notifyConfigurationChanged()); + checkBox.addValueChangeListener(event -> checkBoxChange()); + durationField.addValueChangeListener(event -> notifyConfigurationChanged()); } private void checkBoxChange() { @@ -72,16 +70,16 @@ public class DurationConfigField extends GridLayout implements ConfigurationItem * @param globalDuration * duration value which is stored in the global configuration */ - private void init(final Duration globalDuration, final Duration tenantDuration) { + protected void init(final Duration globalDuration, final Duration tenantDuration) { this.globalDuration = globalDuration; this.setValue(tenantDuration); } - private void setCheckBoxTooltip(final String label) { + protected void setCheckBoxTooltip(final String label) { checkBox.setDescription(label); } - private void setAllowedRange(final Duration minimumDuration, final Duration maximumDuration) { + protected void setAllowedRange(final Duration minimumDuration, final Duration maximumDuration) { durationField.setMinimumDuration(minimumDuration); durationField.setMaximumDuration(maximumDuration); } From 0a0c08b70042ef1043d58b89ee52eb444cabe84d Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 1 Apr 2016 15:55:00 +0200 Subject: [PATCH 11/56] Fixed wrong call of sw module type. UI uses name and not key. Signed-off-by: Kai Zimmermann --- .../java/org/eclipse/hawkbit/repository/SoftwareManagement.java | 2 +- .../java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index c6eab402a..384353b8e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -259,7 +259,7 @@ public class SoftwareManagement { } /** - * retrieves {@link SoftwareModule}s by their name AND version. + * retrieves {@link SoftwareModule} by their name AND version AND type.. * * @param name * of the {@link SoftwareModule} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 67e71ba4f..3f947cfd0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -809,7 +809,7 @@ public final class HawkbitCommonUtil { public static boolean isDuplicate(final String name, final String version, final String type) { final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version, - swMgmtService.findSoftwareModuleTypeByKey(type)); + swMgmtService.findSoftwareModuleTypeByName(type)); boolean duplicate = false; if (swModule != null) { duplicate = true; From bd974ef6ab69d088f531bb380862551fb6e598b1 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 13:29:40 +0200 Subject: [PATCH 12/56] Prepared cloud deployment of hawkbit sandbox --- .../hawkbit-device-simulator/cf/manifest.yml | 21 ++++++++++++++++ examples/hawkbit-device-simulator/pom.xml | 10 ++++++++ .../simulator/DeviceSimulatorUpdater.java | 12 ++++++++- .../simulator/amqp/AmqpConfiguration.java | 5 ++-- .../simulator/amqp/SpReceiverService.java | 18 ++----------- .../src/main/resources/application.properties | 6 +---- examples/hawkbit-example-app/README.md | 25 +++++++++++++++---- .../cf/manifest-simple.yml | 19 ++++++++++++++ examples/hawkbit-example-app/cf/manifest.yml | 21 ++++++++++++++++ examples/hawkbit-example-app/pom.xml | 11 ++++++++ .../application-cloudsandbox.properties | 11 ++++++++ 11 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 examples/hawkbit-device-simulator/cf/manifest.yml create mode 100644 examples/hawkbit-example-app/cf/manifest-simple.yml create mode 100644 examples/hawkbit-example-app/cf/manifest.yml create mode 100644 examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties diff --git a/examples/hawkbit-device-simulator/cf/manifest.yml b/examples/hawkbit-device-simulator/cf/manifest.yml new file mode 100644 index 000000000..8a65690fe --- /dev/null +++ b/examples/hawkbit-device-simulator/cf/manifest.yml @@ -0,0 +1,21 @@ +# +# 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 +# +--- +applications: +- name: hawkbit-simulator + memory: 512M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: hawkbit-example-app-0.2.0-SNAPSHOT.jar + services: + - dmf-rabbit + env: + SPRING_PROFILES_ACTIVE: cloudsandbox,amqp + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index a2575e9db..5ee781e34 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -42,6 +42,16 @@ + + + cf + true + ${project.build.directory} + + manifest.yml + + + diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java index b8b5011aa..afc3a2569 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java @@ -14,6 +14,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.eclipse.hawkbit.simulator.event.InitUpdate; import org.eclipse.hawkbit.simulator.event.ProgressUpdate; @@ -34,6 +35,9 @@ public class DeviceSimulatorUpdater { @Autowired private SpSenderService spSenderService; + @Autowired + private SimulatedDeviceFactory deviceFactory; + @Autowired private EventBus eventbus; @@ -58,7 +62,13 @@ public class DeviceSimulatorUpdater { */ public void startUpdate(final String tenant, final String id, final long actionId, final String swVersion, final UpdaterCallback callback) { - final AbstractSimulatedDevice device = repository.get(tenant, id); + AbstractSimulatedDevice device = repository.get(tenant, id); + + // plug and play - non existing device will be auto created + if (device == null) { + device = repository.add(deviceFactory.createSimulatedDevice(id, tenant, Protocol.DMF_AMQP, -1, null, null)); + } + device.setProgress(0.0); device.setSwversion(swVersion); eventbus.post(new InitUpdate(device)); diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java index 492bb3857..bf5d723a8 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java @@ -59,7 +59,8 @@ public class AmqpConfiguration { } /** - * Create the receiver queue from sp. Receive messages from sp. + * Creates the receiver queue from update server for receiving message from + * update server. * * @return the queue */ @@ -70,7 +71,7 @@ public class AmqpConfiguration { } /** - * Create the recevier exchange. Sp send messages to this exchange. + * Creates the receiver exchange for sending messages to update server. * * @return the exchange */ diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java index 1c314d56f..9f7e4d9ca 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java @@ -26,9 +26,7 @@ import org.springframework.messaging.handler.annotation.Header; import org.springframework.stereotype.Component; /** - * Handle all incoming Messages from SP. - * - * + * Handle all incoming Messages from hawkBit update server. * */ @Component @@ -44,17 +42,6 @@ public class SpReceiverService extends ReceiverService { /** * Constructor. - * - * @param rabbitTemplate - * the rabbit template - * @param amqpProperties - * the amqp properties - * @param lwm2mSenderService - * the lwm2mSenderService - * @param spSenderService - * the spSenderService - * @param deviceUpdater - * the updater service to simulate update process */ @Autowired public SpReceiverService(final RabbitTemplate rabbitTemplate, final AmqpProperties amqpProperties, @@ -62,12 +49,11 @@ public class SpReceiverService extends ReceiverService { super(rabbitTemplate, amqpProperties); this.spSenderService = spSenderService; this.deviceUpdater = deviceUpdater; - } /** * Handle the incoming Message from Queue with the property - * (com.bosch.sp.lwm2m.connector.amqp.receiverConnectorQueueFromSp). + * (hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp). * * @param message * the incoming message diff --git a/examples/hawkbit-device-simulator/src/main/resources/application.properties b/examples/hawkbit-device-simulator/src/main/resources/application.properties index 56d0190a7..cdc72ba28 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/application.properties +++ b/examples/hawkbit-device-simulator/src/main/resources/application.properties @@ -7,11 +7,7 @@ # http://www.eclipse.org/legal/epl-v10.html # - -######################################################################################### -# PUBLIC configuration, i.e. can be changed by users at runtime (defaults provided here) -######################################################################################### -## Configuration for RabbitMQ communication +## Configuration for DMF communication hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp=simulator_receiver hawkbit.device.simulator.amqp.deadLetterQueue=simulator_deadletter hawkbit.device.simulator.amqp.deadLetterExchange=simulator.deadletter diff --git a/examples/hawkbit-example-app/README.md b/examples/hawkbit-example-app/README.md index eaf30f306..4efbdb8ed 100644 --- a/examples/hawkbit-example-app/README.md +++ b/examples/hawkbit-example-app/README.md @@ -1,7 +1,15 @@ # hawkBit Example Application -The hawkBit example application is a standalone spring-boot application with an embedded servlet container to start the hawkBit. +The hawkBit example application is a standalone spring-boot application with an embedded servlet container to host the hawkBit Update Server. -## Run +We have have described several options for you to get access to the example. + +## Try out the example application in our hawkBit sandbox on Bluemix +- try out Management UI https://hawkbit.eu-gb.mybluemix.net/UI +- try out Management API https://hawkbit.eu-gb.mybluemix.net/rest/v1/targets (don't forget basic auth header) +- try out DDI API https://hawkbit.eu-gb.mybluemix.net/DEFAULT/controller/v1/MYTESTDEVICE + +## On your own workstation +### Run ``` java -jar examples/hawkbit-example-app/target/hawkbit-example-app-*-SNAPSHOT.jar ``` @@ -10,6 +18,13 @@ Or: run org eclipse.hawkbit.app.Start ``` -## Usage -The UI can be accessed via _http://localhost:8080/UI_. -The REST API can be accessed via _http://localhost:8080/rest/v1_. +### Usage +The Management UI can be accessed via http://localhost:8080/UI +The Management API can be accessed via http://localhost:8080/rest/v1 + +## Deploy example app to Cloud Foundry + +- Go to ```cf``` subfolder. +- Select one of the two manifests + - **manifest-simple.yml** for a standalone hawkBit installation with embedded H2. + - **manifest.yml** for a standalone hawkBit installation with embedded H2 and RabbitMQ service binding for DMF integration (note: this manifest is used for the sandbox above). diff --git a/examples/hawkbit-example-app/cf/manifest-simple.yml b/examples/hawkbit-example-app/cf/manifest-simple.yml new file mode 100644 index 000000000..4d4a798ef --- /dev/null +++ b/examples/hawkbit-example-app/cf/manifest-simple.yml @@ -0,0 +1,19 @@ +# +# 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 +# +--- +applications: +- name: hawkbit-simple + memory: 1024M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: ${project.build.finalName}.jar + env: + SPRING_PROFILES_ACTIVE: cloudsandbox + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-example-app/cf/manifest.yml b/examples/hawkbit-example-app/cf/manifest.yml new file mode 100644 index 000000000..278f43681 --- /dev/null +++ b/examples/hawkbit-example-app/cf/manifest.yml @@ -0,0 +1,21 @@ +# +# 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 +# +--- +applications: +- name: hawkbit + memory: 1024M + instances: 1 + buildpack: https://github.com/cloudfoundry/java-buildpack + path: ${project.build.finalName}.jar + services: + - dmf-rabbit + env: + SPRING_PROFILES_ACTIVE: cloudsandbox,amqp + CF_STAGING_TIMEOUT: 15 + CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index 33624ffd7..e9f57ad54 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -39,6 +39,17 @@ + + + cf + true + ${project.build.directory} + + manifest.yml + manifest-simple.yml + + + diff --git a/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties new file mode 100644 index 000000000..d54e1d6a2 --- /dev/null +++ b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties @@ -0,0 +1,11 @@ +# +# 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 +# + +spring.profiles.active= +vaadin.servlet.productionMode=true From 6d143273f76d903334b0e358952ef7a1a392b38c Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 21:00:34 +0200 Subject: [PATCH 13/56] Added simulator autostart and cf deployment. --- examples/hawkbit-device-simulator/README.md | 15 +- .../hawkbit-device-simulator/cf/manifest.yml | 6 +- .../simulator/SimulationController.java | 4 +- .../simulator/SimulationProperties.java | 136 ++++++++++++++++++ .../hawkbit/simulator/SimulatorStartup.java | 51 +++++++ .../simulator/amqp/AmqpProperties.java | 9 +- .../simulator/amqp/SpReceiverService.java | 1 - .../src/main/resources/application.properties | 5 +- examples/hawkbit-example-app/README.md | 3 +- .../application-cloudsandbox.properties | 1 - 10 files changed, 212 insertions(+), 19 deletions(-) create mode 100644 examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java create mode 100644 examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java diff --git a/examples/hawkbit-device-simulator/README.md b/examples/hawkbit-device-simulator/README.md index 869f80511..1ba29bb7e 100644 --- a/examples/hawkbit-device-simulator/README.md +++ b/examples/hawkbit-device-simulator/README.md @@ -2,7 +2,7 @@ The device simulator handles software update commands from the update server. -## Run +## Run on your own workstation ``` java -jar examples/hawkbit-device-simulator/target/hawkbit-device-simulator-*-SNAPSHOT.jar ``` @@ -11,6 +11,11 @@ Or: run org.eclipse.hawkbit.simulator.DeviceSimulator ``` +## Deploy to cloud foundry environment + +- Go to ```target``` subfolder. +- Run ```cf push``` + ## Notes The simulator has user authentication enabled in **cloud profile**. Default credentials: @@ -30,9 +35,9 @@ http://localhost:8083 ``` ![](src/main/images/generateScreenshot.png) - + ![](src/main/images/updateProcessScreenshot.png) - + ![](src/main/images/updateResultOverviewScreenshot.png) @@ -54,12 +59,12 @@ Example: for 20 simulated devices (default) http://localhost:8083/start ``` -Example: for 10 simulated devices that start with the name prefix "activeSim": +Example: for 10 simulated devices that start with the name prefix "activeSim": ``` http://localhost:8083/start?amount=10&name=activeSim ``` -Example: for 5 simulated devices that start with the name prefix "ddi" using the Direct Device Integration API (http): +Example: for 5 simulated devices that start with the name prefix "ddi" using the Direct Device Integration API (http): ``` http://localhost:8083/start?amount=5&name=ddi?api=ddi ``` diff --git a/examples/hawkbit-device-simulator/cf/manifest.yml b/examples/hawkbit-device-simulator/cf/manifest.yml index 8a65690fe..df69f92e3 100644 --- a/examples/hawkbit-device-simulator/cf/manifest.yml +++ b/examples/hawkbit-device-simulator/cf/manifest.yml @@ -9,13 +9,13 @@ --- applications: - name: hawkbit-simulator - memory: 512M + memory: 1024M instances: 1 buildpack: https://github.com/cloudfoundry/java-buildpack - path: hawkbit-example-app-0.2.0-SNAPSHOT.jar + path: ${project.build.finalName}.jar services: - dmf-rabbit env: - SPRING_PROFILES_ACTIVE: cloudsandbox,amqp + SPRING_PROFILES_ACTIVE: cloud,amqp CF_STAGING_TIMEOUT: 15 CF_STARTUP_TIMEOUT: 15 diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java index c1f358d89..426860d8b 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java @@ -55,7 +55,7 @@ public class SimulationController { * number of delay in milliseconds to delay polling of DDI * devices * @param gatewayToken - * the hawkbit-update-server gatwaytoken in case authentication + * the hawkbit-update-server gatewaytoken in case authentication * is enforced in hawkbit * @return a response string that devices has been created * @throws MalformedURLException @@ -68,7 +68,7 @@ public class SimulationController { @RequestParam(value = "endpoint", defaultValue = "http://localhost:8080") final String endpoint, @RequestParam(value = "polldelay", defaultValue = "30") final int pollDelay, @RequestParam(value = "gatewaytoken", defaultValue = "") final String gatewayToken) - throws MalformedURLException { + throws MalformedURLException { final Protocol protocol; switch (api.toLowerCase()) { diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java new file mode 100644 index 000000000..354263934 --- /dev/null +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java @@ -0,0 +1,136 @@ +/** + * 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.simulator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * General simulator service properties. + * + */ +@Component +@ConfigurationProperties("hawkbit.device.simulator") +public class SimulationProperties { + + /** + * List of tenants where the simulator should auto start simulations after + * startup. + */ + private final List autostarts = new ArrayList<>(); + + public List getAutostarts() { + return this.autostarts; + } + + /** + * Auto start configuration for simulation setups that the simulator begins + * after startup. + * + */ + public static class Autostart { + /** + * Name prefix of simulated devices, followed by counter, e.g. + * simulated0, simulated1, simulated2.... + */ + private String name = "simulated"; + + /** + * Amount of simulated devices. + */ + private int amount = 20; + + /** + * Tenant name for the simulation. + */ + @NotEmpty + private String tenant; + + /** + * API for simulation. + */ + private Protocol api = Protocol.DMF_AMQP; + + /** + * Endpoint in case of DDI API based simulation. + */ + private String endpoint = "http://localhost:8080"; + + /** + * Poll time in case of DDI API based simulation. + */ + private int pollDelay = 30; + + /** + * Optional gateway token for DDI API based simulation. + */ + private String gatewayToken = ""; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public int getAmount() { + return amount; + } + + public void setAmount(final int amount) { + this.amount = amount; + } + + public String getTenant() { + return tenant; + } + + public void setTenant(final String tenant) { + this.tenant = tenant; + } + + public Protocol getApi() { + return api; + } + + public void setApi(final Protocol api) { + this.api = api; + } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(final String endpoint) { + this.endpoint = endpoint; + } + + public int getPollDelay() { + return pollDelay; + } + + public void setPollDelay(final int pollDelay) { + this.pollDelay = pollDelay; + } + + public String getGatewayToken() { + return gatewayToken; + } + + public void setGatewayToken(final String gatewayToken) { + this.gatewayToken = gatewayToken; + } + } +} diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java new file mode 100644 index 000000000..c0e22a994 --- /dev/null +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -0,0 +1,51 @@ +package org.eclipse.hawkbit.simulator; + +import java.net.URL; + +import org.eclipse.hawkbit.simulator.amqp.SpSenderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +/** + * Execution of operations after startup. Set up of simulations. + * + */ +@Component +public class SimulatorStartup implements ApplicationListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorStartup.class); + + @Autowired + private SimulationProperties simulationProperties; + + @Autowired + private SpSenderService spSenderService; + + @Autowired + private DeviceSimulatorRepository repository; + + @Autowired + private SimulatedDeviceFactory deviceFactory; + + @Override + public void onApplicationEvent(final ContextRefreshedEvent event) { + simulationProperties.getAutostarts().forEach(autostart -> { + for (int i = 0; i < autostart.getAmount(); i++) { + final String deviceId = autostart.getName() + i; + try { + repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(), + autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()), + autostart.getGatewayToken())); + } catch (final Exception e) { + LOGGER.error("Creation of simulated device at startup failed.", e); + } + + spSenderService.createOrUpdateThing(autostart.getTenant(), deviceId); + } + }); + } + +} diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java index f9e6ab23d..f58355980 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpProperties.java @@ -19,26 +19,25 @@ import org.springframework.stereotype.Component; @Component @ConfigurationProperties("hawkbit.device.simulator.amqp") public class AmqpProperties { - /** * Queue for receiving DMF messages from update server. */ - private String receiverConnectorQueueFromSp; + private String receiverConnectorQueueFromSp = "simulator_receiver"; /** * Exchange for sending DMF messages to update server. */ - private String senderForSpExchange; + private String senderForSpExchange = "simulator.replyTo"; /** * Simulator dead letter queue. */ - private String deadLetterQueue; + private String deadLetterQueue = "simulator_deadletter"; /** * Simulator dead letter exchange. */ - private String deadLetterExchange; + private String deadLetterExchange = "simulator.deadletter"; public String getReceiverConnectorQueueFromSp() { return receiverConnectorQueueFromSp; diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java index 9f7e4d9ca..f22839422 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java @@ -31,7 +31,6 @@ import org.springframework.stereotype.Component; */ @Component public class SpReceiverService extends ReceiverService { - private static final Logger LOGGER = LoggerFactory.getLogger(ReceiverService.class); public static final String SOFTWARE_MODULE_FIRMWARE = "firmware"; diff --git a/examples/hawkbit-device-simulator/src/main/resources/application.properties b/examples/hawkbit-device-simulator/src/main/resources/application.properties index cdc72ba28..fbe7261be 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/application.properties +++ b/examples/hawkbit-device-simulator/src/main/resources/application.properties @@ -13,8 +13,11 @@ hawkbit.device.simulator.amqp.deadLetterQueue=simulator_deadletter hawkbit.device.simulator.amqp.deadLetterExchange=simulator.deadletter hawkbit.device.simulator.amqp.senderForSpExchange=simulator.replyTo +## Configuration for simulations +hawkbit.device.simulator.autostarts.[0].tenant=DEFAULT -## Configuration for RabbitMQ integration + +## Configuration for local RabbitMQ integration spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.rabbitmq.virtualHost=/ diff --git a/examples/hawkbit-example-app/README.md b/examples/hawkbit-example-app/README.md index 4efbdb8ed..ecbec93c3 100644 --- a/examples/hawkbit-example-app/README.md +++ b/examples/hawkbit-example-app/README.md @@ -24,7 +24,8 @@ The Management API can be accessed via http://localhost:8080/rest/v1 ## Deploy example app to Cloud Foundry -- Go to ```cf``` subfolder. +- Go to ```target``` subfolder. - Select one of the two manifests - **manifest-simple.yml** for a standalone hawkBit installation with embedded H2. - **manifest.yml** for a standalone hawkBit installation with embedded H2 and RabbitMQ service binding for DMF integration (note: this manifest is used for the sandbox above). +- Run ```cf push``` against you cloud foundry environment. diff --git a/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties index d54e1d6a2..ecf71da41 100644 --- a/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties +++ b/examples/hawkbit-example-app/src/main/resources/application-cloudsandbox.properties @@ -7,5 +7,4 @@ # http://www.eclipse.org/legal/epl-v10.html # -spring.profiles.active= vaadin.servlet.productionMode=true From 171dc461071f37ffb9414e2ce69d9d73416f7f9a Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 21:14:41 +0200 Subject: [PATCH 14/56] Fixed problem that client works only with localhost. --- .../mgmt/client/resource/DistributionSetResourceClient.java | 2 +- .../client/resource/DistributionSetTagResourceClient.java | 2 +- .../client/resource/DistributionSetTypeResourceClient.java | 2 +- .../hawkbit/mgmt/client/resource/RolloutResourceClient.java | 2 +- .../mgmt/client/resource/SoftwareModuleResourceClient.java | 2 +- .../client/resource/SoftwareModuleTypeResourceClient.java | 2 +- .../hawkbit/mgmt/client/resource/TargetResourceClient.java | 2 +- .../hawkbit/mgmt/client/resource/TargetTagResourceClient.java | 2 +- .../mgmt/client/resource/builder/DistributionSetBuilder.java | 4 ---- .../client/resource/builder/DistributionSetTypeBuilder.java | 2 -- .../hawkbit/mgmt/client/resource/builder/RolloutBuilder.java | 2 -- .../resource/builder/SoftwareModuleAssigmentBuilder.java | 2 -- .../mgmt/client/resource/builder/SoftwareModuleBuilder.java | 2 -- .../client/resource/builder/SoftwareModuleTypeBuilder.java | 2 -- .../hawkbit/mgmt/client/resource/builder/TagBuilder.java | 2 -- .../hawkbit/mgmt/client/resource/builder/TargetBuilder.java | 2 -- .../mgmt/client/scenarios/CreateStartedRolloutExample.java | 2 +- .../mgmt/client/scenarios/GettingStartedDefaultScenario.java | 4 ++-- 18 files changed, 11 insertions(+), 29 deletions(-) diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java index 00a9b3fba..5ac11e012 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the DistributionSet resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsets") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsets") public interface DistributionSetResourceClient extends DistributionSetRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java index ea9f5d28a..5fbdaf857 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTagResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the DistributionSetTag resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettags") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsettags") public interface DistributionSetTagResourceClient extends DistributionSetTagRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java index 08d40dfa5..300f8ddcb 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/DistributionSetTypeResourceClient.java @@ -15,7 +15,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; * Client binding for the DistributionSetType resource of the management API. * */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/distributionsettypes") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/distributionsettypes") public interface DistributionSetTypeResourceClient extends DistributionSetTypeRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java index 78b7413e7..aed3af7a2 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/RolloutResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the Rollout resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/rollouts") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/rollouts") public interface RolloutResourceClient extends RolloutRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java index 88e664d78..8610643ef 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the SoftwareModule resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremodules") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/softwaremodules") public interface SoftwareModuleResourceClient extends SoftwareModuleRestAPI { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java index 4896cb8d8..46410dd6c 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/SoftwareModuleTypeResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the oftwareModuleType resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/softwaremoduletypes") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/softwaremoduletypes") public interface SoftwareModuleTypeResourceClient extends SoftwareModuleTypeRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java index a82aa5443..79385fea4 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the Target resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targets") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/targets") public interface TargetResourceClient extends TargetRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java index fee30c686..930931a87 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/TargetTagResourceClient.java @@ -14,7 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient; /** * Client binding for the TargetTag resource of the management API. */ -@FeignClient(url = "${hawkbit.endpoint.url:localhost:8080}/rest/v1/targettags") +@FeignClient(url = "${hawkbit.url:localhost:8080}/rest/v1/targettags") public interface TargetTagResourceClient extends TargetTagRestApi { } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java index c821b106c..358cff0db 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java @@ -16,11 +16,7 @@ import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRe import com.google.common.collect.Lists; /** - * * Builder pattern for building {@link DistributionSetRequestBodyPost}. - * - * @author Jonathan Knoblauch - * */ public class DistributionSetBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java index e1da1f048..752834c7d 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link DistributionSetTypeRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class DistributionSetTypeBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java index bea0fd9a4..2e01e0ba2 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java @@ -15,8 +15,6 @@ import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody; /** * * Builder pattern for building {@link RolloutRestRequestBody}. - * - * @author Jonathan Knoblauch * */ public class RolloutBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java index b209dbe8b..8d69db619 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleAssigmentBuilder.java @@ -16,8 +16,6 @@ import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssi /** * * Builder pattern for building {@link SoftwareModuleAssigmentRest}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleAssigmentBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java index 30b85d901..4bbfd92b4 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link SoftwareModuleRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java index ce128d592..a6472f0a0 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link SoftwareModuleRequestBodyPost}. - * - * @author Jonathan Knoblauch * */ public class SoftwareModuleTypeBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java index f3888de54..6f2eb3248 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TagBuilder.java @@ -17,8 +17,6 @@ import com.google.common.collect.Lists; /** * Builder pattern for building {@link TagRequestBodyPut}. - * - * @author Jonathan Knoblauch * */ public class TagBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java index 5123903d9..e496407e1 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java @@ -19,8 +19,6 @@ import com.google.common.collect.Lists; /** * * Builder pattern for building {@link TargetRequestBody}. - * - * @author Jonathan Knoblauch * */ public class TargetBuilder { diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java index e92f81326..cd74c0474 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java @@ -41,7 +41,7 @@ public class CreateStartedRolloutExample { private static final String SM_MODULE_TYPE = "firmware"; /* known distribution set type name and key */ - private static final String DS_MODULE_TYPE = "firmware"; + private static final String DS_MODULE_TYPE = SM_MODULE_TYPE; @Autowired private DistributionSetResourceClient distributionSetResource; diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java index d17048dea..5873403f0 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java @@ -41,13 +41,13 @@ public class GettingStartedDefaultScenario { private static final String SM_MODULE_TYPE = "gettingstarted"; /* known distribution set type name and key */ - private static final String DS_MODULE_TYPE = "gettingstarted"; + private static final String DS_MODULE_TYPE = SM_MODULE_TYPE; /* known distribution name of this getting started example */ private static final String SM_EXAMPLE_NAME = "gettingstarted-example"; /* known distribution name of this getting started example */ - private static final String DS_EXAMPLE_NAME = "gettingstarted-example"; + private static final String DS_EXAMPLE_NAME = SM_EXAMPLE_NAME; @Autowired private DistributionSetResourceClient distributionSetResource; From 4b95ebc75d92899a2500258855702ac4c01314d5 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 21:36:06 +0200 Subject: [PATCH 15/56] Skript for sandbox setup --- deployHawkBitSandbox.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 deployHawkBitSandbox.sh diff --git a/deployHawkBitSandbox.sh b/deployHawkBitSandbox.sh new file mode 100644 index 000000000..ac2498e2b --- /dev/null +++ b/deployHawkBitSandbox.sh @@ -0,0 +1,20 @@ +# +# 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 +# + +# This script allows the deployment of the complete hawkBit sandbox including +# data example to a cloud foundry enviroment. Expects existing CF CLI +# installation and login to be existing already. + +cd examples/hawkbit-example-app/target/ +cf push +cd ../.. +java -jar hawkbit-mgmt-api-client/target/hawkbit-mgmt-api-client-0.2.0-SNAPSHOT.jar -Dhawkbit.url=hawkbit.eu-gb.mybluemix.net +cd hawkbit-device-simulator/target/ +cf push +cd ../../.. From 36e8949febdd8e538be5de1dcba85052c04bc2cc Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 22:13:21 +0200 Subject: [PATCH 16/56] Fixed final bugs. Sandbox works now. --- deployHawkBitSandbox.sh | 2 +- examples/hawkbit-device-simulator/pom.xml | 3 +++ examples/hawkbit-example-app/pom.xml | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/deployHawkBitSandbox.sh b/deployHawkBitSandbox.sh index ac2498e2b..d774f4205 100644 --- a/deployHawkBitSandbox.sh +++ b/deployHawkBitSandbox.sh @@ -14,7 +14,7 @@ cd examples/hawkbit-example-app/target/ cf push cd ../.. -java -jar hawkbit-mgmt-api-client/target/hawkbit-mgmt-api-client-0.2.0-SNAPSHOT.jar -Dhawkbit.url=hawkbit.eu-gb.mybluemix.net +java -jar hawkbit-mgmt-api-client/target/hawkbit-mgmt-api-client-0.2.0-SNAPSHOT.jar --hawkbit.url=hawkbit.eu-gb.mybluemix.net cd hawkbit-device-simulator/target/ cf push cd ../../.. diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index 5ee781e34..a23051124 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -43,6 +43,9 @@ + + src/main/resources + cf true diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index e9f57ad54..a5c0f864d 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -40,6 +40,9 @@ + + src/main/resources + cf true From 19e628aac9e21d8b534bbe855af61b5f46ae9c7f Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 2 Apr 2016 22:18:04 +0200 Subject: [PATCH 17/56] Added sandbox chapter --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fb649633b..461e12e81 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ see [hawkBit Wiki](https://github.com/eclipse/hawkbit/wiki) * Having issues with hawkBit? Open a [GitHub issue](https://github.com/eclipse/hawkbit/issues). * You can also check out our [Project Homepage](https://projects.eclipse.org/projects/iot.hawkbit) for further contact options. +# hawkBit sandbox + +We offer a sandbox installation that is free for everyone to try out hawkBit. However, keep in mind that the sandbox database will be reset from time to time. It is also not possible to upload any artifacts into the sandbox. But you can use it to try out the Management UI, Management API and DDI API. + +https://hawkbit.eu-gb.mybluemix.net/UI/ # Compile, Run and Getting Started From f4bd947cbd521856f5a92c8836755a8066b60bd0 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Mon, 4 Apr 2016 08:03:42 +0200 Subject: [PATCH 18/56] remove unused parameter Signed-off-by: Michael Hirsch --- .../hawkbit/controller/DataConversionHelper.java | 12 +++++------- .../eclipse/hawkbit/controller/RootController.java | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java index 03623abdd..e035c47ee 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java @@ -49,11 +49,11 @@ public final class DataConversionHelper { } - static List createChunks(final String targetid, final Action uAction, final TenantAware tenantAware, + static List createChunks(final String targetid, final Action uAction, final ArtifactUrlHandler artifactUrlHandler) { return uAction.getDistributionSet().getModules().stream() .map(module -> new Chunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), - module.getName(), createArtifacts(targetid, module, tenantAware, artifactUrlHandler))) + module.getName(), createArtifacts(targetid, module, artifactUrlHandler))) .collect(Collectors.toList()); } @@ -76,12 +76,10 @@ public final class DataConversionHelper { * of the target * @param module * the software module - * @param tenantAware - * of the tenant * @return a list of artifacts or a empty list. Cannot be . */ public static List createArtifacts(final String targetid, - final org.eclipse.hawkbit.repository.model.SoftwareModule module, final TenantAware tenantAware, + final org.eclipse.hawkbit.repository.model.SoftwareModule module, final ArtifactUrlHandler artifactUrlHandler) { final List files = new ArrayList<>(); module.getLocalArtifacts().forEach(artifact -> { @@ -94,9 +92,9 @@ public final class DataConversionHelper { final String linkHttps = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTPS); file.add(new Link(linkHttps).withRel("download")); - file.add(new Link(linkHttps + ".MD5SUM").withRel("md5sum")); + file.add(new Link(linkHttps + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum")); file.add(new Link(linkHttp).withRel("download-http")); - file.add(new Link(linkHttp + ".MD5SUM").withRel("md5sum-http")); + file.add(new Link(linkHttp + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum-http")); files.add(file); }); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index 0a668338c..358448dfd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -90,10 +90,10 @@ public class RootController { private CacheWriteNotify cacheWriteNotify; @Autowired - private TenantAware tenantAware; + private HawkbitSecurityProperties securityProperties; @Autowired - private HawkbitSecurityProperties securityProperties; + private TenantAware tenantAware; @Autowired private ArtifactUrlHandler artifactUrlHandler; @@ -122,8 +122,7 @@ public class RootController { } - return new ResponseEntity<>( - DataConversionHelper.createArtifacts(targetid, softwareModule, tenantAware, artifactUrlHandler), + return new ResponseEntity<>(DataConversionHelper.createArtifacts(targetid, softwareModule, artifactUrlHandler), HttpStatus.OK); } @@ -312,8 +311,7 @@ public class RootController { if (!action.isCancelingOrCanceled()) { - final List chunks = DataConversionHelper.createChunks(targetid, action, tenantAware, - artifactUrlHandler); + final List chunks = DataConversionHelper.createChunks(targetid, action, artifactUrlHandler); final HandlingType handlingType = action.isForce() ? HandlingType.FORCED : HandlingType.ATTEMPT; From 5c661cd6a49b608cf43415b5401904dffdfa1695 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 4 Apr 2016 08:58:58 +0200 Subject: [PATCH 19/56] Added license header --- examples/hawkbit-device-simulator/cf/manifest.yml | 1 + .../org/eclipse/hawkbit/simulator/SimulatorStartup.java | 8 ++++++++ examples/hawkbit-example-app/cf/manifest-simple.yml | 1 + examples/hawkbit-example-app/cf/manifest.yml | 1 + 4 files changed, 11 insertions(+) diff --git a/examples/hawkbit-device-simulator/cf/manifest.yml b/examples/hawkbit-device-simulator/cf/manifest.yml index df69f92e3..51a43ace6 100644 --- a/examples/hawkbit-device-simulator/cf/manifest.yml +++ b/examples/hawkbit-device-simulator/cf/manifest.yml @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # + --- applications: - name: hawkbit-simulator diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index c0e22a994..faff1cc6c 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -1,3 +1,11 @@ +/** + * 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.simulator; import java.net.URL; diff --git a/examples/hawkbit-example-app/cf/manifest-simple.yml b/examples/hawkbit-example-app/cf/manifest-simple.yml index 4d4a798ef..c87a533f4 100644 --- a/examples/hawkbit-example-app/cf/manifest-simple.yml +++ b/examples/hawkbit-example-app/cf/manifest-simple.yml @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # + --- applications: - name: hawkbit-simple diff --git a/examples/hawkbit-example-app/cf/manifest.yml b/examples/hawkbit-example-app/cf/manifest.yml index 278f43681..2145f467d 100644 --- a/examples/hawkbit-example-app/cf/manifest.yml +++ b/examples/hawkbit-example-app/cf/manifest.yml @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # + --- applications: - name: hawkbit From fd3d854bf8f18ab72df903cd96f920b0ca86e4ef Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Mon, 4 Apr 2016 10:31:05 +0200 Subject: [PATCH 20/56] Reseted changes because a bigger refactoring is necessary Signed-off-by: Jonathan Philip Knoblauch --- .../ui/tenantconfiguration/polling/DurationConfigField.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java index e1569db02..15f51877d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/polling/DurationConfigField.java @@ -70,16 +70,16 @@ public class DurationConfigField extends GridLayout implements ConfigurationItem * @param globalDuration * duration value which is stored in the global configuration */ - protected void init(final Duration globalDuration, final Duration tenantDuration) { + private void init(final Duration globalDuration, final Duration tenantDuration) { this.globalDuration = globalDuration; this.setValue(tenantDuration); } - protected void setCheckBoxTooltip(final String label) { + private void setCheckBoxTooltip(final String label) { checkBox.setDescription(label); } - protected void setAllowedRange(final Duration minimumDuration, final Duration maximumDuration) { + private void setAllowedRange(final Duration minimumDuration, final Duration maximumDuration) { durationField.setMinimumDuration(minimumDuration); durationField.setMaximumDuration(maximumDuration); } From 84f543382c0e8a3cd15a43b71ac856d96bb1d052 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Mon, 4 Apr 2016 10:48:14 +0200 Subject: [PATCH 21/56] Updated javadoc for the getURl method Signed-off-by: Jonathan Philip Knoblauch --- .../org/eclipse/hawkbit/api/ArtifactUrlHandler.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java index a80551f9e..522444961 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandler.java @@ -17,15 +17,20 @@ package org.eclipse.hawkbit.api; public interface ArtifactUrlHandler { /** - * Returns a generated URL for a given artifact for a specific protocol. + * Returns a generated download URL for a given artifact parameters for a + * specific protocol. * * @param controllerId * the authenticated controller id - * @param localArtifact - * the artifact to retrieve a URL to + * @param softwareModuleId + * the softwareModuleId belonging to the artifact + * @param filename + * the filename of the artifact + * @param sha1Hash + * the sha1Hash of the artifact * @param protocol * the protocol the URL should be generated - * @return an URL for the given artifact in a given protocol + * @return an URL for the given artifact parameters in a given protocol */ String getUrl(String controllerId, final Long softwareModuleId, final String filename, final String sha1Hash, final UrlProtocol protocol); From a98f91f05e5f067000545ddc414e9a7d9d97e8aa Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 4 Apr 2016 12:54:30 +0200 Subject: [PATCH 22/56] Fixed typos --- examples/hawkbit-mgmt-api-client/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/hawkbit-mgmt-api-client/README.md b/examples/hawkbit-mgmt-api-client/README.md index eff301e20..ac8e7a4cd 100644 --- a/examples/hawkbit-mgmt-api-client/README.md +++ b/examples/hawkbit-mgmt-api-client/README.md @@ -1,4 +1,4 @@ -# HawkBit management API example +# hawkBit Management API example client Example client that shows how to efficiently use the hawkBit management API. @@ -36,4 +36,3 @@ In rollout mode: * assigning software modules to distribution sets * creating a rollout * starting a rollout - From 044f0bef037361f998c15c2a2724b7d0a9257923 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Mon, 4 Apr 2016 12:59:45 +0200 Subject: [PATCH 23/56] Reduce some duplicate code Signed-off-by: SirWayne --- .../DistributionSetAssignmentResult.java | 13 +- .../repository/model/AssignmentResult.java | 42 ++++- .../DistributionSetTagAssignmentResult.java | 21 +-- .../model/TargetTagAssignmentResult.java | 22 +-- .../repository/ControllerManagementTest.java | 4 +- .../repository/DeploymentManagementTest.java | 14 +- .../DistributionSetManagementTest.java | 6 +- .../hawkbit/repository/TagManagementTest.java | 24 +-- .../TargetManagementSearchTest.java | 14 +- .../utils/RepositoryDataGenerator.java | 134 ++++++-------- .../resource/DistributionSetTagResource.java | 4 +- .../hawkbit/rest/resource/TargetResource.java | 2 +- .../rest/resource/TargetTagResource.java | 4 +- .../controller/DeploymentBaseTest.java | 14 +- .../controller/RootControllerTest.java | 2 +- .../rest/resource/TargetResourceTest.java | 2 +- .../event/UploadViewAcceptCriteria.java | 35 ---- .../footer/SMDeleteActionsLayout.java | 50 ----- .../smtable/SoftwareModuleDetails.java | 75 +------- .../smtable/SoftwareModuleTableHeader.java | 33 ---- .../artifacts/smtype/SMTypeFilterButtons.java | 24 --- .../artifacts/smtype/SMTypeFilterHeader.java | 10 +- .../ui/common/AbstractAcceptCriteria.java | 39 ++-- .../AbstractTableDetailsLayout.java | 26 +++ .../filterlayout/AbstractFilterButtons.java | 22 ++- .../filterlayout/AbstractFilterHeader.java | 10 + .../footer/AbstractDeleteActionsLayout.java | 49 ++++- .../hawkbit/ui/common/grid/AbstractGrid.java | 24 ++- .../ui/common/table/AbstractTableHeader.java | 24 +++ .../tagdetails/DistributionTagToken.java | 6 +- .../ui/common/tagdetails/TargetTagToken.java | 6 +- .../disttype/DSTypeFilterButtons.java | 24 --- .../disttype/DSTypeFilterHeader.java | 11 +- .../dstable/DistributionSetDetails.java | 91 +-------- .../dstable/DistributionSetTableHeader.java | 27 --- .../DistributionsViewAcceptCriteria.java | 32 ---- .../footer/DSDeleteActionsLayout.java | 175 +----------------- .../smtable/SwModuleDetails.java | 34 ---- .../smtable/SwModuleTableHeader.java | 26 --- .../smtype/DistSMTypeFilterButtons.java | 17 -- .../smtype/DistSMTypeFilterHeader.java | 8 - .../dstable/DistributionDetails.java | 25 +-- .../management/dstable/DistributionTable.java | 2 +- .../dstable/DistributionTableHeader.java | 27 --- .../dstag/DistributionTagButtons.java | 12 -- .../dstag/DistributionTagHeader.java | 10 +- .../event/DistributionTagDropEvent.java | 2 +- .../event/ManagementViewAcceptCriteria.java | 32 ---- .../footer/DeleteActionsLayout.java | 45 ----- .../management/targettable/TargetDetails.java | 24 +-- .../management/targettable/TargetTable.java | 2 +- .../targettable/TargetTableHeader.java | 18 -- .../targettag/TargetTagFilterButtons.java | 14 +- .../targettag/TargetTagFilterHeader.java | 11 +- .../ui/rollout/rollout/RolloutListGrid.java | 53 ++---- .../rolloutgroup/RolloutGroupListGrid.java | 47 ++--- .../RolloutGroupTargetsListGrid.java | 34 +--- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 61 +----- 58 files changed, 371 insertions(+), 1248 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index 8b1df00da..85e707652 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository; +import java.util.Collections; import java.util.List; import org.eclipse.hawkbit.repository.model.AssignmentResult; @@ -19,7 +20,7 @@ import org.eclipse.hawkbit.repository.model.Target; * how much of the assignments had already been existed. * */ -public class DistributionSetAssignmentResult extends AssignmentResult { +public class DistributionSetAssignmentResult extends AssignmentResult { private final List assignedTargets; private final List actions; @@ -45,16 +46,14 @@ public class DistributionSetAssignmentResult extends AssignmentResult { */ public DistributionSetAssignmentResult(final List assignedTargets, final int assigned, final int alreadyAssigned, final List actions, final TargetManagement targetManagement) { - super(assigned, alreadyAssigned); + super(assigned, alreadyAssigned, 0, Collections.emptyList(), Collections.emptyList()); this.assignedTargets = assignedTargets; this.actions = actions; this.targetManagement = targetManagement; } - - /** - * @return the assignedTargets - */ - public List getAssignedTargets() { + + @Override + public List getAssignedEntity() { return targetManagement.findTargetByControllerID(assignedTargets); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java index eda0bb9bd..2dea94f33 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java @@ -8,15 +8,21 @@ */ package org.eclipse.hawkbit.repository.model; +import java.util.List; + /** * Generic assignment result bean. * */ -public class AssignmentResult { +public class AssignmentResult { private final int total; private final int assigned; private final int alreadyAssigned; + + private final int unassigned; + private final List assignedEntity; + private final List unassignedEntity; /** * Constructor. @@ -24,25 +30,47 @@ public class AssignmentResult { * @param assigned * is the number of newly assigned elements. * @param alreadyAssigned - * is the number of already assigned elements. + * number of already assigned/ignored elements + * @param unassigned + * number of newly assigned elements + * @param assignedEntity + * {@link List} of assigned entity. + * @param unassignedEntity + * {@link List} of unassigned entity. */ - public AssignmentResult(final int assigned, final int alreadyAssigned) { - super(); + public AssignmentResult(final int assigned, final int alreadyAssigned, final int unassigned, + final List assignedEntity, final List unassignedEntity) { this.assigned = assigned; this.alreadyAssigned = alreadyAssigned; total = assigned + alreadyAssigned; + this.unassigned = unassigned; + this.assignedEntity = assignedEntity; + this.unassignedEntity = unassignedEntity; } - + public int getAssigned() { return assigned; } - + public int getTotal() { return total; } - + public int getAlreadyAssigned() { return alreadyAssigned; } + + + public int getUnassigned() { + return unassigned; + } + + public List getAssignedEntity() { + return assignedEntity; + } + + public List getUnassignedEntity() { + return unassignedEntity; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java index eddd10c1b..f1f3b1519 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java @@ -14,11 +14,8 @@ import java.util.List; * Result object for {@link DistributionSetTag} assignments. * */ -public class DistributionSetTagAssignmentResult extends AssignmentResult { +public class DistributionSetTagAssignmentResult extends AssignmentResult { - private final int unassigned; - private final List assignedDs; - private final List unassignedDs; private final DistributionSetTag distributionSetTag; /** @@ -40,27 +37,13 @@ public class DistributionSetTagAssignmentResult extends AssignmentResult { public DistributionSetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned, final List assignedDs, final List unassignedDs, final DistributionSetTag distributionSetTag) { - super(assigned, alreadyAssigned); - this.unassigned = unassigned; - this.assignedDs = assignedDs; - this.unassignedDs = unassignedDs; + super(assigned, alreadyAssigned,unassigned, assignedDs, unassignedDs); this.distributionSetTag = distributionSetTag; } - public int getUnassigned() { - return unassigned; - } - public DistributionSetTag getDistributionSetTag() { return distributionSetTag; } - public List getAssignedDs() { - return assignedDs; - } - - public List getUnassignedDs() { - return unassignedDs; - } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java index 789e6adf2..b454d0c18 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java @@ -14,11 +14,8 @@ import java.util.List; * Result object for {@link TargetTag} assignments. * */ -public class TargetTagAssignmentResult extends AssignmentResult { +public class TargetTagAssignmentResult extends AssignmentResult { - private final int unassigned; - private final List assignedTargets; - private final List unassignedTargets; private final TargetTag targetTag; /** @@ -39,25 +36,10 @@ public class TargetTagAssignmentResult extends AssignmentResult { */ public TargetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned, final List assignedTargets, final List unassignedTargets, final TargetTag targetTag) { - super(assigned, alreadyAssigned); - this.unassigned = unassigned; - this.assignedTargets = assignedTargets; - this.unassignedTargets = unassignedTargets; + super(assigned, alreadyAssigned, unassigned, assignedTargets, unassignedTargets); this.targetTag = targetTag; } - public int getUnassigned() { - return unassigned; - } - - public List getAssignedTargets() { - return assignedTargets; - } - - public List getUnassignedTargets() { - return unassignedTargets; - } - public TargetTag getTargetTag() { return targetTag; } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java index d77c137b1..279932ef7 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java @@ -48,7 +48,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); - savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next(); + savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next(); final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(targetManagement.findTargetByControllerID(savedTarget.getControllerId()).getTargetInfo() @@ -104,7 +104,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); - savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next(); + savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next(); Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); // test and verify diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 83db4ed96..a17054a3d 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -155,8 +155,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { List targets = targetManagement .createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10)); - targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedTargets(); - targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedTargets(); + targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedEntity(); + targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedEntity(); targetManagement.findAllTargetIds().forEach(targetIdName -> { assertThat(deploymentManagement.findActiveActionsByTarget( @@ -604,7 +604,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // activeActions, add a corresponding cancelAction and another // UpdateAction for dsA final Iterable deployed2DS = deploymentManagement - .assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedTargets(); + .assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedEntity(); actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1); // get final updated version of targets @@ -761,7 +761,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { targs.add(targ); // doing the assignment - targs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedTargets(); + targs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity(); targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId()); // checking the revisions of the created entities @@ -799,7 +799,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { assertEquals("wrong installed ds", dsA, targ.getTargetInfo().getInstalledDistributionSet()); targs = deploymentManagement.assignDistributionSet(dsB.getId(), new String[] { "target-id-A" }) - .getAssignedTargets(); + .getAssignedEntity(); targ = targs.iterator().next(); @@ -830,7 +830,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final List targs = new ArrayList(); targs.add(targ); - final Iterable savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedTargets(); + final Iterable savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity(); targ = savedTargs.iterator().next(); assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( @@ -926,7 +926,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // assigning all DistributionSet to the Target in the list // deployedTargets for (final DistributionSet ds : dsList) { - deployedTargets = deploymentManagement.assignDistributionSet(ds, deployedTargets).getAssignedTargets(); + deployedTargets = deploymentManagement.assignDistributionSet(ds, deployedTargets).getAssignedEntity(); } final DeploymentResult deploymentResult = new DeploymentResult(deployedTargets, nakedTargets, dsList, diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java index 90cecfc14..db9618425 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java @@ -495,11 +495,11 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { distributionSetManagement.deleteDistributionSet(dsDeleted); dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()); - ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagA).getAssignedDs(); + ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagA).getAssignedEntity(); dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()); - ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagB).getAssignedDs(); + ds100Group1 = distributionSetManagement.toggleTagAssignment(ds100Group1, dsTagB).getAssignedEntity(); dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()); - ds100Group2 = distributionSetManagement.toggleTagAssignment(ds100Group2, dsTagA).getAssignedDs(); + ds100Group2 = distributionSetManagement.toggleTagAssignment(ds100Group2, dsTagA).getAssignedEntity(); dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()); // check setup diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java index 73244871f..4c6af0d83 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java @@ -179,29 +179,29 @@ public class TagManagementTest extends AbstractIntegrationTest { DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( groupA.stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedDs()).isEmpty(); + assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); // toggle A+B -> A is still assigned and B is assigned as well result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( groupB.stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedDs()).isEmpty(); + assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); // toggle A+B -> both unassigned result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(0); - assertThat(result.getAssignedDs()).isEmpty(); + assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -220,29 +220,29 @@ public class TagManagementTest extends AbstractIntegrationTest { TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedTargets()).isEmpty(); + assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getTargetTag()).isEqualTo(tag); // toggle A+B -> A is still assigned and B is assigned as well result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedTargets()).isEmpty(); + assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getTargetTag()).isEqualTo(tag); // toggle A+B -> both unassigned result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(0); - assertThat(result.getAssignedTargets()).isEmpty(); + assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( + assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags( concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getTargetTag()).isEqualTo(tag); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java index 0c33a651f..73d549eb7 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java @@ -64,19 +64,19 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final String targetDsAIdPref = "targ-A"; List targAs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description"))); - targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedTargets(); + targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity(); final String targetDsBIdPref = "targ-B"; List targBs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description"))); - targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedTargets(); - targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedTargets(); + targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity(); + targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity(); final String targetDsCIdPref = "targ-C"; List targCs = targetManagement.createTargets( TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description"))); - targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedTargets(); - targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedTargets(); + targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity(); + targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity(); final String targetDsDIdPref = "targ-D"; final List targDs = targetManagement.createTargets( @@ -688,8 +688,8 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); - targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedTargets(); - targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedTargets(); + targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity(); + targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity(); targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed"); final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index d7efa50d5..a1c74e791 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -49,7 +49,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.auditing.AuditingHandler; -import org.springframework.data.auditing.DateTimeProvider; import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.context.SecurityContext; @@ -132,24 +131,18 @@ public final class RepositoryDataGenerator { final DistributionSetTag dsTag = tagManagement .createDistributionSetTag(new DistributionSetTag("For " + group + "s")); - auditingHandler.setDateTimeProvider(new DateTimeProvider() { - @Override - public Calendar getNow() { - final Calendar instance = Calendar.getInstance(); - instance.add(Calendar.MONTH, -new Random().nextInt(7)); + auditingHandler.setDateTimeProvider(() -> { + final Calendar instance = Calendar.getInstance(); + instance.add(Calendar.MONTH, -new Random().nextInt(7)); - return instance; - } + return instance; }); final List targets = createTargetTestGroup(group, 20 * sizeMultiplikator); - auditingHandler.setDateTimeProvider(new DateTimeProvider() { - @Override - public Calendar getNow() { - final Calendar instance = Calendar.getInstance(); - return instance; - } + auditingHandler.setDateTimeProvider(() -> { + final Calendar instance = Calendar.getInstance(); + return instance; }); LOG.debug("initDemoRepo - start now real action history for group: {}", group); @@ -290,7 +283,7 @@ public final class RepositoryDataGenerator { LOG.debug("createTargetTestGroup: {} targets status updated including IP", group); - return targetManagement.toggleTagAssignment(targAs, targTag).getAssignedTargets(); + return targetManagement.toggleTagAssignment(targAs, targTag).getAssignedEntity(); } private List buildTargets(final int noOfTgts, final String descriptionPrefix) { @@ -328,75 +321,70 @@ public final class RepositoryDataGenerator { private void initDemoRepo(final int sizeMultiplikator, final int loadtestgroups) { final LoremIpsum jlorem = new LoremIpsum(); - runAsAllAuthorityContext(new Runnable() { + runAsAllAuthorityContext(() -> { + dbCleanupUtil.cleanupDB(null); - @Override - public void run() { - dbCleanupUtil.cleanupDB(null); + // generate targets and assign DS + // 5 groups - 100 targets each -> 500 + final String[] targetTestGroups = { "SHC", "CCU", "Vehicle", "Vending machine", "ECU" }; - // generate targets and assign DS - // 5 groups - 100 targets each -> 500 - final String[] targetTestGroups = { "SHC", "CCU", "Vehicle", "Vending machine", "ECU" }; + final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" }; - final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" }; + final DistributionSetTag depTag = tagManagement + .createDistributionSetTag(new DistributionSetTag("deprecated")); - final DistributionSetTag depTag = tagManagement - .createDistributionSetTag(new DistributionSetTag("deprecated")); + Arrays.stream(targetTestGroups).forEach(group -> { + generateTestTagetGroup(group, sizeMultiplikator); + }); - Arrays.stream(targetTestGroups).forEach(group -> { - generateTestTagetGroup(group, sizeMultiplikator); - }); + // garbage DS + LOG.debug("initDemoRepo - start now DS garbage"); + TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, + softwareManagement, distributionSetManagement); + LOG.debug("initDemoRepo - DS garbage finished"); - // garbage DS - LOG.debug("initDemoRepo - start now DS garbage"); - TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, - softwareManagement, distributionSetManagement); - LOG.debug("initDemoRepo - DS garbage finished"); + LOG.debug("initDemoRepo - start now Extra Software Modules and types"); + Arrays.stream(modulesTypes).forEach(typeName -> { + final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType( + new SoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName, + jlorem.words(5), Integer.MAX_VALUE)); - LOG.debug("initDemoRepo - start now Extra Software Modules and types"); - Arrays.stream(modulesTypes).forEach(typeName -> { - final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType( - new SoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName, - jlorem.words(5), Integer.MAX_VALUE)); - - for (int i = 0; i < sizeMultiplikator; i++) { - softwareManagement.createSoftwareModule(new SoftwareModule(smtype, typeName + i, "1.0." + i, - jlorem.words(5), "the " + typeName + " vendor Inc.")); - } - - }); - LOG.debug("initDemoRepo - Extra Software Modules and types finished"); - - LOG.debug("initDemoRepo - start now target garbage"); - - // garbage targets - // unknown - targetManagement - .createTargets(TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator)); - - // registered - targetManagement.createTargets( - TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "registered"), - TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), generateIPAddress()); - - // pending - final DistributionSetTag dsTag = tagManagement - .createDistributionSetTag(new DistributionSetTag("OnlyAssignedTag")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0", - softwareManagement, distributionSetManagement, - Arrays.asList(new DistributionSetTag[] { dsTag })); - deploymentManagement.assignDistributionSet(ds, targetManagement.createTargets( - TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "pending"))); - - // Load test means additional 1_000_000 target - - for (int i = 0; i < loadtestgroups; i++) { - targetManagement.createTargets(TestDataUtil.generateTargets(i * 1_000, 1_000, "loadtest-")); + for (int i1 = 0; i1 < sizeMultiplikator; i1++) { + softwareManagement.createSoftwareModule(new SoftwareModule(smtype, typeName + i1, "1.0." + i1, + jlorem.words(5), "the " + typeName + " vendor Inc.")); } - LOG.debug("initDemoRepo complete"); + }); + LOG.debug("initDemoRepo - Extra Software Modules and types finished"); + + LOG.debug("initDemoRepo - start now target garbage"); + + // garbage targets + // unknown + targetManagement + .createTargets(TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator)); + + // registered + targetManagement.createTargets( + TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "registered"), + TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), generateIPAddress()); + + // pending + final DistributionSetTag dsTag = tagManagement + .createDistributionSetTag(new DistributionSetTag("OnlyAssignedTag")); + final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0", + softwareManagement, distributionSetManagement, + Arrays.asList(new DistributionSetTag[] { dsTag })); + deploymentManagement.assignDistributionSet(ds, targetManagement.createTargets( + TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "pending"))); + + // Load test means additional 1_000_000 target + + for (int i2 = 0; i2 < loadtestgroups; i2++) { + targetManagement.createTargets(TestDataUtil.generateTargets(i2 * 1_000, 1_000, "loadtest-")); } + LOG.debug("initDemoRepo complete"); }); } /** diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java index 01a446947..eaa0fec28 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java @@ -139,9 +139,9 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi { final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest(); tagAssigmentResultRest.setAssignedDistributionSets( - DistributionSetMapper.toResponseDistributionSets(assigmentResult.getAssignedDs())); + DistributionSetMapper.toResponseDistributionSets(assigmentResult.getAssignedEntity())); tagAssigmentResultRest.setUnassignedDistributionSets( - DistributionSetMapper.toResponseDistributionSets(assigmentResult.getUnassignedDs())); + DistributionSetMapper.toResponseDistributionSets(assigmentResult.getUnassignedEntity())); LOG.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(), assigmentResult.getUnassigned()); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java index 3c79c936c..4b068a41e 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java @@ -263,7 +263,7 @@ public class TargetResource implements TargetRestApi { final ActionType type = (dsId.getType() != null) ? RestResourceConversionHelper.convertActionType(dsId.getType()) : ActionType.FORCED; final Iterator changed = this.deploymentManagement - .assignDistributionSet(dsId.getId(), type, dsId.getForcetime(), targetId).getAssignedTargets() + .assignDistributionSet(dsId.getId(), type, dsId.getForcetime(), targetId).getAssignedEntity() .iterator(); if (changed.hasNext()) { return new ResponseEntity<>(HttpStatus.OK); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java index 9990fb35a..1a9155828 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java @@ -133,8 +133,8 @@ public class TargetTagResource implements TargetTagRestApi { .toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName()); final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest(); - tagAssigmentResultRest.setAssignedTargets(TargetMapper.toResponse(assigmentResult.getAssignedTargets())); - tagAssigmentResultRest.setUnassignedTargets(TargetMapper.toResponse(assigmentResult.getUnassignedTargets())); + tagAssigmentResultRest.setAssignedTargets(TargetMapper.toResponse(assigmentResult.getAssignedEntity())); + tagAssigmentResultRest.setUnassignedTargets(TargetMapper.toResponse(assigmentResult.getUnassignedEntity())); return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK); } diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java index 2b2b7e597..2127c8d1a 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java @@ -114,12 +114,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { assertThat(actionStatusRepository.findAll()).isEmpty(); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, - Action.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedTargets(); + Action.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(actionRepository.findAll()).hasSize(1); - saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedTargets(); + saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); assertThat(actionRepository.findAll()).hasSize(2); @@ -236,12 +236,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { List saved = deploymentManagement .assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, savedTarget.getControllerId()) - .getAssignedTargets(); + .getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(actionRepository.findAll()).hasSize(1); - saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedTargets(); + saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); assertThat(actionRepository.findAll()).hasSize(2); @@ -358,12 +358,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { assertThat(actionStatusRepository.findAll()).isEmpty(); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.TIMEFORCED, - System.currentTimeMillis(), savedTarget.getControllerId()).getAssignedTargets(); + System.currentTimeMillis(), savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(actionRepository.findAll()).hasSize(1); - saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedTargets(); + saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); assertThat(actionRepository.findAll()).hasSize(2); @@ -887,7 +887,7 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); - savedTarget = deploymentManagement.assignDistributionSet(savedSet, toAssign).getAssignedTargets().iterator() + savedTarget = deploymentManagement.assignDistributionSet(savedSet, toAssign).getAssignedEntity().iterator() .next(); deploymentManagement.assignDistributionSet(savedSet2, toAssign2); diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java index a6e457f3a..fa2c5f6d4 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java @@ -270,7 +270,7 @@ public class RootControllerTest extends AbstractIntegrationTestWithMongoDB { Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList(); toAssign.add(savedTarget); - savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next(); + savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next(); final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); mvc.perform(post("/{tenant}/controller/v1/911/deploymentBase/" + savedAction.getId() + "/feedback", tenantAware.getCurrentTenant()) diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java index a8ebfdd9d..8d27d5114 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java @@ -1029,7 +1029,7 @@ public class TargetResourceTest extends AbstractIntegrationTest { // Update final List updatedTargets = deploymentManagement.assignDistributionSet(one, targets) - .getAssignedTargets(); + .getAssignedEntity(); // 2nd update // sleep 10ms to ensure that we can sort by reportedAt Thread.sleep(10); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadViewAcceptCriteria.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadViewAcceptCriteria.java index a3f045a08..060800fb8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadViewAcceptCriteria.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadViewAcceptCriteria.java @@ -14,12 +14,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria; -import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -28,8 +23,6 @@ import com.vaadin.ui.Component; /** * Upload UI View for Accept criteria. * - * - * */ @SpringComponent @ViewScope @@ -41,29 +34,6 @@ public class UploadViewAcceptCriteria extends AbstractAcceptCriteria { private static final Map DROP_HINTS_CONFIGS = createDropHintConfigurations(); - @Autowired - private transient UINotification uiNotification; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Override - protected void analyseDragComponent(final Component compsource) { - final String sourceID = getComponentId(compsource); - final Object event = DROP_HINTS_CONFIGS.get(sourceID); - eventBus.publish(this, event); - } - - @Override - protected void hideDropHints() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - } - - @Override - protected void invalidDrop() { - uiNotification.displayValidationError(SPUILabelDefinitions.ACTION_NOT_ALLOWED); - } - @Override protected String getComponentId(final Component component) { String id = component.getId(); @@ -78,11 +48,6 @@ public class UploadViewAcceptCriteria extends AbstractAcceptCriteria { return DROP_HINTS_CONFIGS; } - @Override - protected void publishDragStartEvent(final Object event) { - eventBus.publish(this, event); - } - @Override protected Map> getDropConfigurations() { return DROP_CONFIGS; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index ef4b17da7..97451961c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -11,22 +11,15 @@ package org.eclipse.hawkbit.ui.artifacts.footer; import java.util.HashSet; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; import org.eclipse.hawkbit.ui.management.event.DragEvent; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -50,18 +43,6 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { private static final long serialVersionUID = -3273982053389866299L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient UINotification notification; - @Autowired private ArtifactUploadState artifactUploadState; @@ -71,22 +52,6 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { @Autowired private UploadViewAcceptCriteria uploadViewAcceptCriteria; - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadArtifactUIEvent event) { @@ -211,26 +176,11 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { updateActionsCount(count); } - @Override - protected String getNoActionsButtonLabel() { - return i18n.get("button.no.actions"); - } - - @Override - protected String getActionsButtonLabel() { - return i18n.get("button.actions"); - } - @Override protected void restoreActionCount() { updateSWActionCount(); } - @Override - protected String getUnsavedActionsWindowCaption() { - return i18n.get("caption.save.window"); - } - @Override protected void unsavedActionsWindowClosed() { final String message = uploadViewConfirmationWindowLayout.getConsolidatedMessage(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index 6eb3e3d5d..dc6035089 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; @@ -19,10 +15,8 @@ import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -46,38 +40,16 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = -4900381301076646366L; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private SpPermissionChecker permissionChecker; - @Autowired private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow; @Autowired private ArtifactUploadState artifactUploadState; - private UI ui; - private Long swModuleId; private SoftwareModule selectedSwModule; - - /** - * Initialize the component. - */ - @Override - @PostConstruct - protected void init() { - super.init(); - ui = UI.getCurrent(); - eventBus.subscribe(this); - } - + @Override protected String getEditButtonId() { return SPUIComponetIdProvider.UPLOAD_SW_MODULE_EDIT_BUTTON; @@ -175,58 +147,24 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { } } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.detailslayout.TableDetailsLayout# - * getDefaultCaption() - */ @Override protected String getDefaultCaption() { return i18n.get("upload.swModuleTable.header"); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.detailslayout.TableDetailsLayout# - * onLoadIsSwModuleSelected() - */ @Override protected Boolean onLoadIsTableRowSelected() { return artifactUploadState.getSelectedBaseSoftwareModule().isPresent(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.detailslayout.TableDetailsLayout# - * onLoadIsTableMaximized() - */ + @Override protected Boolean onLoadIsTableMaximized() { return artifactUploadState.isSwModuleTableMaximized(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.detailslayout.TableDetailsLayout# - * populateDetailsWidget() - */ + @Override protected void populateDetailsWidget() { populateDetailsWidget(selectedSwModule); @@ -266,12 +204,7 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { return permissionChecker.hasUpdateDistributionPermission(); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * getTabSheetId() - */ + @Override protected String getTabSheetId() { return null; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java index 71605ec9f..5f1c56636 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java @@ -8,20 +8,14 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -44,31 +38,12 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { private static final long serialVersionUID = 242961845006626297L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ArtifactUploadState artifactUploadState; @Autowired private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow; - /** - * Initialize the components. - */ - @Override - @PostConstruct - protected void init() { - super.init(); - eventbus.subscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadArtifactUIEvent event) { if (event == UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE) { @@ -76,14 +51,6 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { } } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventbus.unsubscribe(this); - } @Override protected String getHeaderCaption() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java index 857b27a7e..5a1736b04 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtons.java @@ -8,21 +8,17 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtype; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; -import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -48,26 +44,6 @@ public class SMTypeFilterButtons extends AbstractFilterButtons { @Autowired private UploadViewAcceptCriteria uploadViewAcceptCriteria; - @Autowired - private transient EventBus.SessionEventBus eventBus; - - /** - * Initialize component. - * - * @param filterButtonClickBehaviour - * the clickable behaviour. - */ - @Override - public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { - super.init(filterButtonClickBehaviour); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleTypeEvent event) { if (event.getSoftwareModuleTypeEnum() == SoftwareModuleTypeEvent.SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java index b79ecb742..a12517b31 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtype; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; @@ -18,7 +17,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -35,12 +33,6 @@ public class SMTypeFilterHeader extends AbstractFilterHeader { private static final long serialVersionUID = -4855810338059032342L; - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ArtifactUploadState artifactUploadState; @@ -84,7 +76,7 @@ public class SMTypeFilterHeader extends AbstractFilterHeader { @Override protected void hideFilterButtonLayout() { artifactUploadState.setSwTypeFilterClosed(true); - eventbus.publish(this, UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE); + eventBus.publish(this, UploadArtifactUIEvent.HIDE_FILTER_BY_TYPE); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java index a6df4f557..2fa2900d5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java @@ -13,8 +13,13 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.UINotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion; @@ -27,9 +32,6 @@ import com.vaadin.ui.Table; /** * Abstract class for Accept criteria. * - * - * - * */ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { @@ -37,13 +39,12 @@ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { private int previousRowCount; - /* - * (non-Javadoc) - * - * @see - * com.vaadin.event.dd.acceptcriteria.AcceptCriterion#accept(com.vaadin. - * event.dd.DragAndDropEvent ) - */ + @Autowired + protected transient UINotification uiNotification; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + @Override public boolean accept(final DragAndDropEvent dragEvent) { final Component compsource = dragEvent.getTransferable().getSourceComponent(); @@ -129,7 +130,7 @@ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { protected void analyseDragComponent(final Component compsource) { final String sourceID = getComponentId(compsource); final Object event = getDropHintConfigurations().get(sourceID); - publishDragStartEvent(event); + eventBus.publish(this, event); } /** @@ -159,23 +160,19 @@ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { */ protected abstract String getComponentId(final Component component); - /** - * publish the given event into eventBus. - * - * @param event - * to be published in eventBus. - */ - protected abstract void publishDragStartEvent(Object event); - /** * Hide the drop hints. Dragging is stopped. */ - protected abstract void hideDropHints(); + protected void hideDropHints() { + eventBus.publish(this, DragEvent.HIDE_DROP_HINT); + } /** * Display invalid drop message. */ - protected abstract void invalidDrop(); + protected void invalidDrop() { + uiNotification.displayValidationError(SPUILabelDefinitions.ACTION_NOT_ALLOWED); + } /** * @return diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index a6ab09659..20a107ba6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -10,6 +10,10 @@ package org.eclipse.hawkbit.ui.common.detailslayout; import java.util.Map; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -19,6 +23,8 @@ import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.label.ContentMode; @@ -27,6 +33,7 @@ import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; +import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; /** @@ -37,6 +44,17 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { private static final long serialVersionUID = 4862529368471627190L; + @Autowired + protected I18N i18n; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @Autowired + protected SpPermissionChecker permissionChecker; + + protected UI ui; + private Label caption; private Button editButton; @@ -54,7 +72,9 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { /** * Initialize components. */ + @PostConstruct protected void init() { + ui = UI.getCurrent(); createComponents(); buildLayout(); /** @@ -62,6 +82,12 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { * selected in table. */ restoreState(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); } private void createComponents() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java index e95797fb4..b64578782 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java @@ -11,13 +11,17 @@ package org.eclipse.hawkbit.ui.common.filterlayout; import java.util.ArrayList; import java.util.List; +import javax.annotation.PreDestroy; + import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUITagButtonStyle; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.spring.events.EventBus; import com.vaadin.data.Item; import com.vaadin.event.dd.DropHandler; @@ -38,10 +42,13 @@ import com.vaadin.ui.themes.ValoTheme; public abstract class AbstractFilterButtons extends Table { private static final long serialVersionUID = 7783305719009746375L; - + private static final String DEFAULT_GREEN = "rgb(44,151,32)"; protected static final String FILTER_BUTTON_COLUMN = "filterButton"; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; private AbstractFilterButtonClickBehaviour filterButtonClickBehaviour; @@ -54,6 +61,12 @@ public abstract class AbstractFilterButtons extends Table { public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { this.filterButtonClickBehaviour = filterButtonClickBehaviour; createTable(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); } private void createTable() { @@ -88,12 +101,7 @@ public abstract class AbstractFilterButtons extends Table { @SuppressWarnings("serial") protected void addColumn() { - addGeneratedColumn(FILTER_BUTTON_COLUMN, new ColumnGenerator() { - @Override - public Object generateCell(final Table source, final Object itemId, final Object columnId) { - return addGeneratedCell(itemId); - } - }); + addGeneratedColumn(FILTER_BUTTON_COLUMN, (source, itemId, columnId) -> addGeneratedCell(itemId)); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java index 95ac7bb35..ddc2d9889 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java @@ -8,10 +8,13 @@ */ package org.eclipse.hawkbit.ui.common.filterlayout; +import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.server.FontAwesome; import com.vaadin.ui.Alignment; @@ -31,6 +34,13 @@ public abstract class AbstractFilterHeader extends VerticalLayout { private static final long serialVersionUID = -1388340600522323332L; + + @Autowired + protected SpPermissionChecker permChecker; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + private Label title; private Button config; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 5b9bd162c..cdf9ac354 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -8,12 +8,19 @@ */ package org.eclipse.hawkbit.ui.common.footer; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.UINotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; @@ -42,6 +49,18 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme private static final long serialVersionUID = -6047975388519155509L; + @Autowired + protected I18N i18n; + + @Autowired + protected SpPermissionChecker permChecker; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @Autowired + protected transient UINotification notification; + private DragAndDropWrapper deleteWrapper; private Button noActionBtn; @@ -59,6 +78,12 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme buildLayout(); reload(); } + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); } private void reload() { @@ -311,14 +336,27 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme * * @return the no actions label. */ - protected abstract String getNoActionsButtonLabel(); + protected String getNoActionsButtonLabel() { + return i18n.get("button.no.actions"); + } /** * Get the pending actions button label. * * @return the actions label. */ - protected abstract String getActionsButtonLabel(); + protected String getActionsButtonLabel() { + return i18n.get("button.actions"); + } + + /** + * Get caption of unsaved actions window. + * + * @return caption of the window. + */ + protected String getUnsavedActionsWindowCaption() { + return i18n.get("caption.save.window"); + } /** * reload the count value. @@ -330,13 +368,6 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme */ protected abstract void restoreBulkUploadStatusCount(); - /** - * Get caption of unsaved actions window. - * - * @return caption of the window. - */ - protected abstract String getUnsavedActionsWindowCaption(); - /** * This method will be called when unsaved actions window is closed. */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java index 6ac205cf2..be16498e9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGrid.java @@ -8,7 +8,13 @@ */ package org.eclipse.hawkbit.ui.common.grid; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.data.Container; import com.vaadin.data.Container.Indexed; @@ -21,10 +27,18 @@ import com.vaadin.ui.Grid; public abstract class AbstractGrid extends Grid { private static final long serialVersionUID = 4856562746502217630L; + + @Autowired + protected I18N i18n; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + /** * Initialize the components. */ + @PostConstruct protected void init() { setSizeFull(); setImmediate(true); @@ -32,6 +46,12 @@ public abstract class AbstractGrid extends Grid { setSelectionMode(SelectionMode.NONE); setColumnReorderingAllowed(true); addNewContainerDS(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); } public void addNewContainerDS() { @@ -43,13 +63,13 @@ public abstract class AbstractGrid extends Grid { setColumnHeaderNames(); addColumnRenderes(); - CellDescriptionGenerator cellDescriptionGenerator = getDescriptionGenerator(); + final CellDescriptionGenerator cellDescriptionGenerator = getDescriptionGenerator(); if (getDescriptionGenerator() != null) { setCellDescriptionGenerator(cellDescriptionGenerator); } // Allow column hiding - for (Column c : getColumns()) { + for (final Column c : getColumns()) { c.setHidable(true); } setHiddenColumns(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java index 0845f2c55..b4709ccd1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java @@ -8,13 +8,20 @@ */ package org.eclipse.hawkbit.ui.common.table; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.components.SPUIButton; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import com.vaadin.event.dd.DropHandler; import com.vaadin.server.FontAwesome; @@ -37,6 +44,16 @@ import com.vaadin.ui.VerticalLayout; public abstract class AbstractTableHeader extends VerticalLayout { private static final long serialVersionUID = 4881626370291837175L; + + @Autowired + protected I18N i18n; + + @Autowired + protected SpPermissionChecker permChecker; + + @Autowired + protected transient EventBus.SessionEventBus eventbus; + private Label headerCaption; @@ -59,10 +76,17 @@ public abstract class AbstractTableHeader extends VerticalLayout { /** * Initialze components. */ + @PostConstruct protected void init() { createComponents(); buildLayout(); restoreState(); + eventbus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventbus.unsubscribe(this); } private void createComponents() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index d6d37d5c0..33f838dd0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -114,7 +114,7 @@ public class DistributionTagToken extends AbstractTagToken { distributionList.add(selectedDS.getId()); final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, tagNameSelected); - uinotification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(tagNameSelected, result, i18n)); + uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -214,7 +214,7 @@ public class DistributionTagToken extends AbstractTagToken { protected boolean isAssign(final DistributionSetTagAssignmentResult assignmentResult) { if (assignmentResult.getAssigned() > 0) { - final List assignedDsNames = assignmentResult.getAssignedDs().stream().map(t -> t.getId()) + final List assignedDsNames = assignmentResult.getAssignedEntity().stream().map(t -> t.getId()) .collect(Collectors.toList()); if (assignedDsNames.contains(managementUIState.getLastSelectedDsIdName().getId())) { return true; @@ -225,7 +225,7 @@ public class DistributionTagToken extends AbstractTagToken { protected boolean isUnassign(final DistributionSetTagAssignmentResult assignmentResult) { if (assignmentResult.getUnassigned() > 0) { - final List assignedDsNames = assignmentResult.getUnassignedDs().stream().map(t -> t.getId()) + final List assignedDsNames = assignmentResult.getUnassignedEntity().stream().map(t -> t.getId()) .collect(Collectors.toList()); if (assignedDsNames.contains(managementUIState.getLastSelectedDsIdName().getId())) { return true; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index b21b8f075..658501b4d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -81,7 +81,7 @@ public class TargetTagToken extends AbstractTargetTagToken { final Set targetList = new HashSet<>(); targetList.add(selectedTarget.getControllerId()); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); - uinotification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(tagNameSelected, result, i18n)); + uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -151,7 +151,7 @@ public class TargetTagToken extends AbstractTargetTagToken { protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) { if (assignmentResult.getAssigned() > 0) { - final List assignedTargetNames = assignmentResult.getAssignedTargets().stream() + final List assignedTargetNames = assignmentResult.getAssignedEntity().stream() .map(t -> t.getControllerId()).collect(Collectors.toList()); if (assignedTargetNames.contains(managementUIState.getLastSelectedTargetIdName().getControllerId())) { return true; @@ -162,7 +162,7 @@ public class TargetTagToken extends AbstractTargetTagToken { protected boolean isUnassign(final TargetTagAssignmentResult assignmentResult) { if (assignmentResult.getUnassigned() > 0) { - final List unassignedTargetNamesList = assignmentResult.getUnassignedTargets().stream() + final List unassignedTargetNamesList = assignmentResult.getUnassignedEntity().stream() .map(t -> t.getControllerId()).collect(Collectors.toList()); if (unassignedTargetNamesList.contains(managementUIState.getLastSelectedTargetIdName().getControllerId())) { return true; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java index aa35c0622..1abc32a3e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtons.java @@ -8,10 +8,7 @@ */ package org.eclipse.hawkbit.ui.distributions.disttype; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; -import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.distributions.event.DistributionSetTypeEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; @@ -23,7 +20,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -45,27 +41,12 @@ public class DSTypeFilterButtons extends AbstractFilterButtons { private static final long serialVersionUID = 771251569981876005L; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManageDistUIState manageDistUIState; @Autowired private DistributionsViewAcceptCriteria distributionsViewAcceptCriteria; - /** - * Initialize component. - * - * @param filterButtonClickBehaviour - * the clickable behaviour. - */ - @Override - public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { - super.init(filterButtonClickBehaviour); - eventBus.subscribe(this); - } - @Override protected String getButtonsTableId() { @@ -140,9 +121,4 @@ public class DSTypeFilterButtons extends AbstractFilterButtons { setContainerDataSource(createButtonsLazyQueryContainer()); } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java index 068c28065..02c959286 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java @@ -10,14 +10,12 @@ package org.eclipse.hawkbit.ui.distributions.disttype; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -34,12 +32,6 @@ public class DSTypeFilterHeader extends AbstractFilterHeader { private static final long serialVersionUID = 3433417459392880222L; - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ManageDistUIState manageDistUIState; @@ -81,8 +73,7 @@ public class DSTypeFilterHeader extends AbstractFilterHeader { @Override protected void hideFilterButtonLayout() { manageDistUIState.setDistTypeFilterClosed(true); - eventbus.publish(this, DistributionsUIEvent.HIDE_DIST_FILTER_BY_TYPE); - + eventBus.publish(this, DistributionsUIEvent.HIDE_DIST_FILTER_BY_TYPE); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index d72fd971a..02916ae7c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -13,12 +13,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -37,10 +33,8 @@ import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayo import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -72,15 +66,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { private static final String UNASSIGN_SOFT_MODULE = "unassignSoftModule"; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private SpPermissionChecker permissionChecker; - @Autowired private ManageDistUIState manageDistUIState; @@ -104,21 +89,16 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { private Long dsId; - private UI ui; - Map assignedSWModule = new HashMap<>(); /** * softwareLayout Initialize the component. */ @Override - @PostConstruct protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); softwareModuleTable.init(i18n, true, permissionChecker, distributionSetManagement, eventBus, manageDistUIState); super.init(); - ui = UI.getCurrent(); - eventBus.subscribe(this); } protected VerticalLayout createTagsLayout() { @@ -321,12 +301,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { this.dsId = dsId; } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * onEdit(com.vaadin.ui .Button.ClickEvent) - */ @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); @@ -336,68 +310,32 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { newDistWindow.setVisible(Boolean.TRUE); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * getEditButtonId() - */ @Override protected String getEditButtonId() { return SPUIComponetIdProvider.DS_EDIT_BUTTON; } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * onLoadIsSwModuleSelected () - */ @Override protected Boolean onLoadIsTableRowSelected() { return manageDistUIState.getSelectedDistributions().isPresent() && !manageDistUIState.getSelectedDistributions().get().isEmpty(); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * onLoadIsTableMaximized () - */ @Override protected Boolean onLoadIsTableMaximized() { return manageDistUIState.isDsTableMaximized(); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * populateDetailsWidget() - */ @Override protected void populateDetailsWidget() { populateDetailsWidget(selectedDsModule); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * getDefaultCaption() - */ @Override protected String getDefaultCaption() { return i18n.get("distribution.details.header"); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * addTabs(com.vaadin. ui.TabSheet) - */ @Override protected void addTabs(final TabSheet detailsTab) { detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); @@ -407,23 +345,11 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * clearDetails() - */ @Override protected void clearDetails() { populateDetailsWidget(null); } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * hasEditSoftwareModulePermission() - */ @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -476,7 +402,7 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { }); } } - + @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS @@ -498,21 +424,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { } } - @PreDestroy - void destroy() { - /* - * It's good to do this, even though vaadin-spring will automatically - * unsubscribe . - */ - eventBus.unsubscribe(this); - } - - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.detailslayout.AbstractTableDetailsLayout# - * getTabSheetId() - */ @Override protected String getTabSheetId() { return null; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java index f8cb7a45b..6ac4a1007 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.dstable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; @@ -20,10 +16,8 @@ import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayo import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -43,28 +37,12 @@ public class DistributionSetTableHeader extends AbstractTableHeader { private static final long serialVersionUID = -3483238438474530748L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ManageDistUIState manageDistUIstate; @Autowired private DistributionAddUpdateWindowLayout addUpdateWindowLayout; - @Override - @PostConstruct - protected void init() { - super.init(); - eventbus.subscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionsUIEvent event) { if (event == DistributionsUIEvent.HIDE_DIST_FILTER_BY_TYPE) { @@ -181,11 +159,6 @@ public class DistributionSetTableHeader extends AbstractTableHeader { eventbus.publish(this, DragEvent.HIDE_DROP_HINT); } - @PreDestroy - void destroy() { - eventbus.unsubscribe(this); - } - @Override protected Boolean isAddNewItemAllowed() { return Boolean.TRUE; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/DistributionsViewAcceptCriteria.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/DistributionsViewAcceptCriteria.java index 5b79b96f4..140fb41da 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/DistributionsViewAcceptCriteria.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/DistributionsViewAcceptCriteria.java @@ -16,10 +16,6 @@ import java.util.Map; import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -39,29 +35,6 @@ public class DistributionsViewAcceptCriteria extends AbstractAcceptCriteria { private static final Map> DROP_CONFIGS = createDropConfigurations(); - @Autowired - private transient UINotification uiNotification; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Override - protected void analyseDragComponent(final Component compsource) { - final String sourceID = getComponentId(compsource); - final Object event = DROP_HINTS_CONFIGS.get(sourceID); - eventBus.publish(this, event); - } - - @Override - protected void hideDropHints() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - } - - @Override - protected void invalidDrop() { - uiNotification.displayValidationError(SPUILabelDefinitions.ACTION_NOT_ALLOWED); - } - @Override protected String getComponentId(final Component component) { String id = component.getId(); @@ -78,11 +51,6 @@ public class DistributionsViewAcceptCriteria extends AbstractAcceptCriteria { return DROP_HINTS_CONFIGS; } - @Override - protected void publishDragStartEvent(final Object event) { - eventBus.publish(this, event); - } - @Override protected Map> getDropConfigurations() { return DROP_CONFIGS; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index 5b51bb224..8b7d2ada0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -15,10 +15,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -30,13 +26,10 @@ import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -65,21 +58,6 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { Arrays.asList(DragEvent.DISTRIBUTION_TYPE_DRAG, DragEvent.DISTRIBUTION_DRAG, DragEvent.SOFTWAREMODULE_DRAG, DragEvent.SOFTWAREMODULE_TYPE_DRAG)); - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient UINotification notification; - - @Autowired - private transient UINotification uiNotification; - @Autowired private transient SystemManagement systemManagement; @@ -92,28 +70,6 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { @Autowired private DistributionsViewAcceptCriteria distributionsViewAcceptCriteria; - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.DeleteActionsLayout#init() - */ - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DragEvent event) { if (event == DragEvent.HIDE_DROP_HINT) { @@ -139,77 +95,34 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * hasDeletePermission() - */ @Override protected boolean hasDeletePermission() { return permChecker.hasDeleteDistributionPermission(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * hasUpdatePermission() - */ @Override protected boolean hasUpdatePermission() { return permChecker.hasUpdateDistributionPermission(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getDeleteAreaLabel() - */ @Override protected String getDeleteAreaLabel() { return i18n.get("label.components.drop.area"); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getDeleteAreaId() - */ @Override protected String getDeleteAreaId() { return SPUIComponetIdProvider.DELETE_BUTTON_WRAPPER_ID; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getDeleteLayoutAcceptCriteria () - */ @Override protected AcceptCriterion getDeleteLayoutAcceptCriteria() { - return distributionsViewAcceptCriteria; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * processDroppedComponent(com .vaadin.event.dd.DragAndDropEvent) - */ @Override protected void processDroppedComponent(final DragAndDropEvent event) { final Component sourceComponent = event.getTransferable().getSourceComponent(); @@ -298,7 +211,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { * message accordingly. */ - uiNotification.displayValidationError(i18n.get("message.targets.already.deleted")); + notification.displayValidationError(i18n.get("message.targets.already.deleted")); } else if (newDeletedDistributionsSize - existingDeletedDistributionsSize != distributionIdNameSet.size()) { /* * Not the all distributions dropped now are added to the delete @@ -306,7 +219,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { * delete list. Hence display warning message accordingly. */ - uiNotification.displayValidationError(i18n.get("message.dist.deleted.pending")); + notification.displayValidationError(i18n.get("message.dist.deleted.pending")); } } @@ -366,64 +279,12 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { return SPUIComponetIdProvider.UPLOAD_SOFTWARE_MODULE_TABLE.equals(source.getId()); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getNoActionsButtonLabel() - */ - @Override - protected String getNoActionsButtonLabel() { - return i18n.get("button.no.actions"); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getActionsButtonLabel() - */ - @Override - protected String getActionsButtonLabel() { - - return i18n.get("button.actions"); - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * reloadActionCount() - */ @Override protected void restoreActionCount() { updateDSActionCount(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getUnsavedActionsWindowCaption () - */ - @Override - protected String getUnsavedActionsWindowCaption() { - return i18n.get("caption.save.window"); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * unsavedActionsWindowClosed() - */ @Override protected void unsavedActionsWindowClosed() { final String message = distConfirmationWindowLayout.getConsolidatedMessage(); @@ -433,26 +294,12 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * getUnsavedActionsWindowContent () - */ @Override protected Component getUnsavedActionsWindowContent() { distConfirmationWindowLayout.init(); return distConfirmationWindowLayout; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.footer.AbstractDeleteActionsLayout# - * hasUnsavedActions() - */ @Override protected boolean hasUnsavedActions() { boolean unSavedActionsTypes = false; @@ -479,23 +326,11 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout# - * hasBulkUploadPermission() - */ @Override protected boolean hasBulkUploadPermission() { return false; } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout# - * showBulkUploadWindow() - */ @Override protected void showBulkUploadWindow() { /** @@ -503,12 +338,6 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { */ } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout# - * restoreBulkUploadStatusCount() - */ @Override protected void restoreBulkUploadStatusCount() { /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index 3b1a2cad6..7aa7d6f31 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.smtable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; @@ -20,10 +16,8 @@ import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -46,44 +40,16 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = -1052279281066089812L; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private SpPermissionChecker permissionChecker; - @Autowired private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow; @Autowired private ManageDistUIState manageDistUIState; - private UI ui; - private Long swModuleId; private SoftwareModule selectedSwModule; - @Override - @PostConstruct - protected void init() { - super.init(); - ui = UI.getCurrent(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java index 56d7706fc..badbc1492 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.smtable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; @@ -19,10 +15,8 @@ import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -43,14 +37,6 @@ public class SwModuleTableHeader extends AbstractTableHeader { private static final long serialVersionUID = 242961845006626297L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; @Autowired private ManageDistUIState manageDistUIState; @@ -58,18 +44,6 @@ public class SwModuleTableHeader extends AbstractTableHeader { @Autowired private SoftwareModuleAddUpdateWindow softwareModuleAddUpdateWindow; - @Override - @PostConstruct - protected void init() { - super.init(); - eventbus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventbus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionsUIEvent event) { if (event == DistributionsUIEvent.HIDE_SM_FILTER_BY_TYPE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java index f086fed2c..146d8f019 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtons.java @@ -11,11 +11,8 @@ package org.eclipse.hawkbit.ui.distributions.smtype; import java.util.HashMap; import java.util.Map; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; -import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; @@ -27,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -47,21 +43,12 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { private static final long serialVersionUID = 6804534533362387433L; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManageDistUIState manageDistUIState; @Autowired private DistributionsViewAcceptCriteria distributionsViewAcceptCriteria; - @Override - public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { - super.init(filterButtonClickBehaviour); - eventBus.subscribe(this); - } - @Override protected String getButtonsTableId() { return SPUIComponetIdProvider.SW_MODULE_TYPE_TABLE_ID; @@ -135,9 +122,5 @@ public class DistSMTypeFilterButtons extends AbstractFilterButtons { setContainerDataSource(createButtonsLazyQueryContainer()); } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java index edf20b206..e328b45a4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.distributions.smtype; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.smtype.CreateUpdateSoftwareTypeLayout; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; @@ -19,7 +18,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -36,12 +34,6 @@ public class DistSMTypeFilterHeader extends AbstractFilterHeader { private static final long serialVersionUID = -8763788280848718344L; - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManageDistUIState manageDistUIState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index ecc4a26c6..a0de88fda 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.dstable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; @@ -21,10 +17,8 @@ import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -46,15 +40,7 @@ public class DistributionDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = 350360207334118826L; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private SpPermissionChecker permissionChecker; - + @Autowired private ManagementUIState managementUIState; @@ -70,22 +56,13 @@ public class DistributionDetails extends AbstractTableDetailsLayout { private DistributionSet selectedDsModule; - private UI ui; - @Override - @PostConstruct protected void init() { - eventBus.subscribe(this); softwareModuleTable = new SoftwareModuleDetailsTable(); softwareModuleTable.init(i18n, false, permissionChecker, null, null, null); super.init(); - ui = UI.getCurrent(); } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 0cc857c30..6bcfb55ae 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -363,7 +363,7 @@ public class DistributionTable extends AbstractTable { final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distList, distTagName); - notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n)); if (result.getAssigned() >= 1 && managementUIState.getDistributionTableFilters().isNoTagSelected()) { refreshFilter(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java index d2ac628a8..6d4343878 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.dstable; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; @@ -19,10 +15,8 @@ import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -43,33 +37,12 @@ import com.vaadin.ui.Window; public class DistributionTableHeader extends AbstractTableHeader { private static final long serialVersionUID = 7597766804650170127L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ManagementUIState managementUIState; @Autowired private DistributionAddUpdateWindowLayout distributionAddUpdateWindowLayout; - @Override - @PostConstruct - protected void init() { - super.init(); - eventbus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventbus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final ManagementUIEvent event) { if (event == ManagementUIEvent.HIDE_DISTRIBUTION_TAG_LAYOUT) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index 287071fe8..57091b660 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -11,8 +11,6 @@ package org.eclipse.hawkbit.ui.management.dstag; import java.util.HashMap; import java.util.Map; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; @@ -31,7 +29,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -51,9 +48,6 @@ public class DistributionTagButtons extends AbstractFilterButtons { private static final long serialVersionUID = -8151483237450892057L; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private DistributionTagDropEvent spDistTagDropEvent; @@ -64,12 +58,6 @@ public class DistributionTagButtons extends AbstractFilterButtons { public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { super.init(filterButtonClickBehaviour); addNewTag(new DistributionSetTag("NO TAG")); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } @EventBusListenerMethod(scope = EventScope.SESSION) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java index 2d58849dc..df9253bdb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java @@ -10,14 +10,12 @@ package org.eclipse.hawkbit.ui.management.dstag; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -38,12 +36,6 @@ public class DistributionTagHeader extends AbstractFilterHeader { @Autowired private I18N i18n; - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private ManagementUIState managementUIState; @@ -90,7 +82,7 @@ public class DistributionTagHeader extends AbstractFilterHeader { @Override protected void hideFilterButtonLayout() { managementUIState.setDistTagFilterClosed(true); - eventbus.publish(this, ManagementUIEvent.HIDE_DISTRIBUTION_TAG_LAYOUT); + eventBus.publish(this, ManagementUIEvent.HIDE_DISTRIBUTION_TAG_LAYOUT); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java index f8d53bdef..5b1e09282 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTagDropEvent.java @@ -150,7 +150,7 @@ public class DistributionTagDropEvent implements DropHandler { final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, distTagName); - notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(distTagName, result, i18n)); if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty()) { eventBus.publish(this, TargetFilterEvent.FILTER_BY_TAG); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/ManagementViewAcceptCriteria.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/ManagementViewAcceptCriteria.java index 1c44014e8..ddc2c9c1d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/ManagementViewAcceptCriteria.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/ManagementViewAcceptCriteria.java @@ -16,10 +16,6 @@ import java.util.Map; import org.eclipse.hawkbit.ui.common.AbstractAcceptCriteria; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; -import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -41,29 +37,6 @@ public class ManagementViewAcceptCriteria extends AbstractAcceptCriteria { private static final Map DROP_HINTS_CONFIGS = createDropHintConfigurations(); - @Autowired - private transient UINotification uiNotification; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Override - protected void analyseDragComponent(final Component compsource) { - final String sourceID = getComponentId(compsource); - final Object event = DROP_HINTS_CONFIGS.get(sourceID); - eventBus.publish(this, event); - } - - @Override - protected void hideDropHints() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - } - - @Override - protected void invalidDrop() { - uiNotification.displayValidationError(SPUILabelDefinitions.ACTION_NOT_ALLOWED); - } - @Override protected String getComponentId(final Component component) { String id = component.getId(); @@ -80,11 +53,6 @@ public class ManagementViewAcceptCriteria extends AbstractAcceptCriteria { return DROP_HINTS_CONFIGS; } - @Override - protected void publishDragStartEvent(final Object event) { - eventBus.publish(this, event); - } - @Override protected Map> getDropConfigurations() { return DROP_CONFIGS; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 1786429a1..b8c5494a3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -11,10 +11,6 @@ package org.eclipse.hawkbit.ui.management.footer; import java.util.HashSet; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; @@ -28,12 +24,9 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -56,17 +49,6 @@ import com.vaadin.ui.UI; public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private static final long serialVersionUID = -8112907467821886253L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private transient UINotification notification; @Autowired private transient TagManagement tagManagementService; @@ -83,18 +65,6 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { @Autowired private CountMessageLabel countMessageLabel; - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final ManagementUIEvent event) { if (event == ManagementUIEvent.UPDATE_COUNT) { @@ -226,26 +196,11 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return true; } - @Override - protected String getNoActionsButtonLabel() { - return i18n.get("button.no.actions"); - } - - @Override - protected String getActionsButtonLabel() { - return i18n.get("button.actions"); - } - @Override protected void restoreActionCount() { updateActionCount(); } - @Override - protected String getUnsavedActionsWindowCaption() { - return i18n.get("caption.save.window"); - } - @Override protected void unsavedActionsWindowClosed() { final String message = manangementConfirmationWindowLayout.getConsolidatedMessage(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index a94ed6b5f..87854b22c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -10,11 +10,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.net.URI; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.apache.commons.lang3.StringUtils; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; @@ -25,12 +21,10 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -60,15 +54,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = 4571732743399605843L; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - - @Autowired - private SpPermissionChecker permChecker; - @Autowired private ManagementUIState managementUIState; @@ -87,11 +72,9 @@ public class TargetDetails extends AbstractTableDetailsLayout { * Initialize the Target details. */ @Override - @PostConstruct public void init() { super.init(); targetAddUpdateWindowLayout.init(); - eventBus.subscribe(this); } @Override @@ -286,7 +269,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected Boolean hasEditPermission() { - return permChecker.hasUpdateTargetPermission(); + return permissionChecker.hasUpdateTargetPermission(); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -312,11 +295,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { } } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - @Override protected String getTabSheetId() { return SPUIComponetIdProvider.TARGET_DETAILS_TABSHEET; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 3df8fe6a4..6884e8906 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -644,7 +644,7 @@ public class TargetTable extends AbstractTable implements Handler { final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); - notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); if (result.getUnassigned() >= 1 && !tagsClickedList.isEmpty()) { refreshFilter(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 05b6bfe4d..5ad6e3c28 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -11,10 +11,6 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.util.HashSet; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -29,7 +25,6 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUITargetDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; @@ -63,12 +58,6 @@ public class TargetTableHeader extends AbstractTableHeader { private static final long serialVersionUID = -8647521126666320022L; - @Autowired - private I18N i18n; - - @Autowired - private SpPermissionChecker permChecker; - @Autowired private UINotification notification; @@ -90,21 +79,14 @@ public class TargetTableHeader extends AbstractTableHeader { private Boolean isComplexFilterViewDisplayed = Boolean.FALSE; @Override - @PostConstruct protected void init() { super.init(); // creating add window for adding new target targetAddUpdateWindow.init(); targetBulkUpdateWindow.init(); - eventBus.subscribe(this); onLoadRestoreState(); } - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final ManagementUIEvent event) { if (event == ManagementUIEvent.HIDE_TARGET_TAG_LAYOUT) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 169573f39..54f4c382b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -13,8 +13,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; @@ -38,7 +36,6 @@ import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -63,9 +60,6 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { private static final long serialVersionUID = 5049554600376508073L; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManagementUIState managementUIState; @@ -99,12 +93,6 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { this.filterButtonClickBehaviour = filterButtonClickBehaviour; super.init(filterButtonClickBehaviour); addNewTargetTag(new TargetTag("NO TAG")); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -244,7 +232,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final List tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); - notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); + notification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(targTagName, result, i18n)); if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java index 7d0b5c76c..6093843fd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java @@ -10,14 +10,12 @@ package org.eclipse.hawkbit.ui.management.targettag; import javax.annotation.PostConstruct; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; @@ -32,15 +30,9 @@ public class TargetTagFilterHeader extends AbstractFilterHeader { private static final long serialVersionUID = 3046367045669148009L; - @Autowired - private SpPermissionChecker permChecker; - @Autowired private I18N i18n; - @Autowired - private transient EventBus.SessionEventBus eventbus; - @Autowired private CreateUpdateTargetTagLayout createUpdateTargetTagLayout; @@ -58,7 +50,6 @@ public class TargetTagFilterHeader extends AbstractFilterHeader { @Override protected String getHideButtonId() { - return SPUIComponetIdProvider.HIDE_TARGET_TAGS; } @@ -87,7 +78,7 @@ public class TargetTagFilterHeader extends AbstractFilterHeader { @Override protected void hideFilterButtonLayout() { managementUIState.setTargetTagFilterClosed(true); - eventbus.publish(this, ManagementUIEvent.HIDE_TARGET_TAG_LAYOUT); + eventBus.publish(this, ManagementUIEvent.HIDE_TARGET_TAG_LAYOUT); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 9151f3932..6376e505b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -15,9 +15,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; @@ -33,7 +30,6 @@ import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -46,7 +42,6 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; import org.vaadin.peter.contextmenu.ContextMenu; import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem; import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -82,11 +77,6 @@ public class RolloutListGrid extends AbstractGrid { private static final String START_OPTION = "Start"; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; @Autowired private transient RolloutManagement rolloutManagement; @@ -105,17 +95,6 @@ public class RolloutListGrid extends AbstractGrid { private transient Map statusIconMap = new EnumMap<>(RolloutStatus.class); - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final RolloutEvent event) { @@ -245,7 +224,7 @@ public class RolloutListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); columnList.add(SPUILabelDefinitions.VAR_STATUS); @@ -265,13 +244,13 @@ public class RolloutListGrid extends AbstractGrid { @Override protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); + final List columnsToBeHidden = new ArrayList<>(); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { + for (final Object propertyId : columnsToBeHidden) { getColumn(propertyId).setHidden(true); } @@ -318,7 +297,7 @@ public class RolloutListGrid extends AbstractGrid { @Override public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.ACTION }; if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { return "centeralign"; } @@ -327,18 +306,18 @@ public class RolloutListGrid extends AbstractGrid { }); } - private void onClickOfRolloutName(RendererClickEvent event) { + private void onClickOfRolloutName(final RendererClickEvent event) { rolloutUIState.setRolloutId((long) event.getItemId()); final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); rolloutUIState.setRolloutName(rolloutName); - String ds = (String) getContainerDataSource().getItem(event.getItemId()) + final String ds = (String) getContainerDataSource().getItem(event.getItemId()) .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); rolloutUIState.setRolloutDistributionSet(ds); eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); } - private void onClickOfActionBtn(RendererClickEvent event) { + private void onClickOfActionBtn(final RendererClickEvent event) { final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); contextMenu.open(event.getClientX(), event.getClientY()); @@ -388,11 +367,11 @@ public class RolloutListGrid extends AbstractGrid { } private String convertRolloutStatusToString(final RolloutStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); + final StatusFontIcon statusFontIcon = statusIconMap.get(value); if (statusFontIcon == null) { return null; } - String codePoint = statusFontIcon.getFontIcon() != null + final String codePoint = statusFontIcon.getFontIcon() != null ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); @@ -441,12 +420,12 @@ public class RolloutListGrid extends AbstractGrid { private static final long serialVersionUID = 2544026030795375748L; private final FontAwesome fontIcon; - public FontIconGenerator(FontAwesome icon) { + public FontIconGenerator(final FontAwesome icon) { this.fontIcon = icon; } @Override - public String getValue(Item item, Object itemId, Object propertyId) { + public String getValue(final Item item, final Object itemId, final Object propertyId) { return fontIcon.getHtml(); } @@ -456,7 +435,7 @@ public class RolloutListGrid extends AbstractGrid { } } - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return cell.getProperty().getValue().toString().toLowerCase(); } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { @@ -570,14 +549,14 @@ public class RolloutListGrid extends AbstractGrid { private static final long serialVersionUID = -5794528427855153924L; @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public TotalTargetCountStatus convertToModel(final String value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public String convertToPresentation(final TotalTargetCountStatus value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 44d945efd..978a93498 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -15,9 +15,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; @@ -32,7 +29,6 @@ import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -41,7 +37,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -64,12 +59,6 @@ import com.vaadin.ui.renderers.HtmlRenderer; public class RolloutGroupListGrid extends AbstractGrid { private static final long serialVersionUID = 4060904914954370524L; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient RolloutGroupManagement rolloutGroupManagement; @@ -81,18 +70,6 @@ public class RolloutGroupListGrid extends AbstractGrid { private transient Map statusIconMap = new EnumMap<>(RolloutGroupStatus.class); - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final RolloutEvent event) { if (RolloutEvent.SHOW_ROLLOUT_GROUPS != event) { @@ -218,7 +195,7 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_STATUS); columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); @@ -251,13 +228,13 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); + final List columnsToBeHidden = new ArrayList<>(); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { + for (final Object propertyId : columnsToBeHidden) { getColumn(propertyId).setHidden(true); } } @@ -267,18 +244,18 @@ public class RolloutGroupListGrid extends AbstractGrid { return cell -> getDescription(cell); } - private void onClickOfRolloutGroupName(RendererClickEvent event) { + private void onClickOfRolloutGroupName(final RendererClickEvent event) { rolloutUIState .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); } private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); + final StatusFontIcon statusFontIcon = statusIconMap.get(value); if (statusFontIcon == null) { return null; } - String codePoint = statusFontIcon.getFontIcon() != null + final String codePoint = statusFontIcon.getFontIcon() != null ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); @@ -298,7 +275,7 @@ public class RolloutGroupListGrid extends AbstractGrid { new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); } - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return cell.getProperty().getValue().toString().toLowerCase(); } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { @@ -318,7 +295,7 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { return "centeralign"; @@ -339,14 +316,14 @@ public class RolloutGroupListGrid extends AbstractGrid { private static final long serialVersionUID = -9205943894818450807L; @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public TotalTargetCountStatus convertToModel(final String value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public String convertToPresentation(final TotalTargetCountStatus value, final Class targetType, + final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java index e55b30111..e3bedc7bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -14,9 +14,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; @@ -26,7 +23,6 @@ import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -35,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -55,29 +50,12 @@ import com.vaadin.spring.annotation.ViewScope; public class RolloutGroupTargetsListGrid extends AbstractGrid { private static final long serialVersionUID = -2244756637458984597L; - - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - + @Autowired private transient RolloutUIState rolloutUIState; private transient Map statusIconMap = new EnumMap<>(Status.class); - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final RolloutEvent event) { @@ -158,7 +136,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnList.add(SPUILabelDefinitions.VAR_CREATED_BY); @@ -241,11 +219,11 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { } private String processActionStatus(final Status status) { - StatusFontIcon statusFontIcon = statusIconMap.get(status); + final StatusFontIcon statusFontIcon = statusIconMap.get(status); if (statusFontIcon == null) { return null; } - String codePoint = statusFontIcon.getFontIcon() != null + final String codePoint = statusFontIcon.getFontIcon() != null ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), null); } @@ -286,7 +264,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { } } - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (!SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return null; } @@ -304,7 +282,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { return RolloutGroupStatus.READY.toString().toLowerCase(); } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { - String ds = rolloutUIState.getRolloutDistributionSet().isPresent() + final String ds = rolloutUIState.getRolloutDistributionSet().isPresent() ? rolloutUIState.getRolloutDistributionSet().get() : ""; return i18n.get("message.dist.already.assigned", new Object[] { ds }); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 3f947cfd0..3abd73592 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -24,14 +24,14 @@ import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; +import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; -import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; @@ -868,7 +868,7 @@ public final class HawkbitCommonUtil { /** * Display Target Tag action message. * - * @param targTagName + * @param tagName * as tag name * @param result * as TargetTagAssigmentResult @@ -878,7 +878,7 @@ public final class HawkbitCommonUtil { * I18N * @return message */ - public static String getTargetTagAssigmentMsg(final String targTagName, final TargetTagAssignmentResult result, + public static String createAssignmentMessage(final String tagName, final AssignmentResult result, final I18N i18n) { final StringBuilder formMsg = new StringBuilder(); final int assignedCount = result.getAssigned(); @@ -887,10 +887,10 @@ public final class HawkbitCommonUtil { if (assignedCount == 1) { formMsg.append(i18n.get("message.target.assigned.one", - new Object[] { result.getAssignedTargets().get(0).getName(), targTagName })).append("
"); + new Object[] { result.getAssignedEntity().get(0).getName(), tagName })).append("
"); } else if (assignedCount > 1) { - formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, targTagName })) + formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, tagName })) .append("
"); if (alreadyAssignedCount > 0) { @@ -902,55 +902,10 @@ public final class HawkbitCommonUtil { if (unassignedCount == 1) { formMsg.append(i18n.get("message.target.unassigned.one", - new Object[] { result.getUnassignedTargets().get(0).getName(), targTagName })).append("
"); + new Object[] { result.getUnassignedEntity().get(0).getName(), tagName })).append("
"); } else if (unassignedCount > 1) { - formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, targTagName })) - .append("
"); - } - return formMsg.toString(); - } - - /** - * Get message to be displayed after distribution tag assignment. - * - * @param targTagName - * tag name - * @param result - * DistributionSetTagAssigmentResult - * @param tagsClickedList - * list of clicked tags - * @param i18n - * I18N - * @return message - */ - public static String getDistributionTagAssignmentMsg(final String targTagName, - final DistributionSetTagAssignmentResult result, final I18N i18n) { - final StringBuilder formMsg = new StringBuilder(); - final int assignedCount = result.getAssigned(); - final int alreadyAssignedCount = result.getAlreadyAssigned(); - final int unassignedCount = result.getUnassigned(); - - if (assignedCount == 1) { - formMsg.append(i18n.get("message.target.assigned.one", - new Object[] { result.getAssignedDs().get(0).getName(), targTagName })).append("
"); - - } else if (assignedCount > 1) { - formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, targTagName })) - .append("
"); - - if (alreadyAssignedCount > 0) { - final String alreadyAssigned = i18n.get("message.target.alreadyAssigned", - new Object[] { alreadyAssignedCount }); - formMsg.append(alreadyAssigned).append("
"); - } - } - - if (unassignedCount == 1) { - formMsg.append(i18n.get("message.target.unassigned.one", - new Object[] { result.getUnassignedDs().get(0).getName(), targTagName })).append("
"); - } else if (unassignedCount > 1) { - formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, targTagName })) + formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, tagName })) .append("
"); } return formMsg.toString(); From 87661624ba0f57edf3f3e513624b3a59a7eb78d0 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Mon, 4 Apr 2016 18:02:43 +0200 Subject: [PATCH 24/56] Refactoring after review - added new method to HawkbitCommenUtil to reduce duplicated code - added early return Signed-off-by: Jonathan Philip Knoblauch --- .../targettable/BulkUploadHandler.java | 14 ++++---- .../ui/rollout/rollout/RolloutListGrid.java | 6 +--- .../rolloutgroup/RolloutGroupListGrid.java | 36 +++++++++---------- .../RolloutGroupTargetsListGrid.java | 6 +--- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 26 +++++++++++--- 5 files changed, 46 insertions(+), 42 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 1a388c324..d52537a92 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -325,14 +325,14 @@ public class BulkUploadHandler extends CustomComponent tagData.getName()); } } - if (!deletedTags.isEmpty()) { - if (deletedTags.size() == 1) { - return i18n.get("message.bulk.upload.tag.assignment.failed", deletedTags.get(0)); - } else { - return i18n.get("message.bulk.upload.tag.assignments.failed"); - } + if (deletedTags.isEmpty()) { + return null; + } + if (deletedTags.size() == 1) { + return i18n.get("message.bulk.upload.tag.assignment.failed", deletedTags.get(0)); + } else { + return i18n.get("message.bulk.upload.tag.assignments.failed"); } - return null; } private boolean ifTagsSelected() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index d60d72527..f17a93b56 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -549,11 +549,7 @@ public class RolloutListGrid extends AbstractGrid { private String convertRolloutStatusToString(final RolloutStatus value) { final StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - final String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index bb4adfe4a..a87bcc525 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -218,7 +218,7 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override protected void setColumnProperties() { - List columnList = new ArrayList<>(); + final List columnList = new ArrayList<>(); columnList.add(SPUILabelDefinitions.VAR_NAME); columnList.add(SPUILabelDefinitions.VAR_STATUS); columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); @@ -240,7 +240,7 @@ public class RolloutGroupListGrid extends AbstractGrid { createRolloutGroupStatusToFontMap(); getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), new RolloutGroupStatusConverter()); - + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new HtmlRenderer(), new TotalTargetCountStatusConverter()); if (permissionChecker.hasRolloutTargetsReadPermission()) { @@ -251,13 +251,13 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override protected void setHiddenColumns() { - List columnsToBeHidden = new ArrayList<>(); + final List columnsToBeHidden = new ArrayList<>(); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); - for (Object propertyId : columnsToBeHidden) { + for (final Object propertyId : columnsToBeHidden) { getColumn(propertyId).setHidden(true); } } @@ -267,14 +267,12 @@ public class RolloutGroupListGrid extends AbstractGrid { return cell -> getDescription(cell); } - private void onClickOfRolloutGroupName(RendererClickEvent event) { + private void onClickOfRolloutGroupName(final RendererClickEvent event) { rolloutUIState .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); } - - private void createRolloutGroupStatusToFontMap() { statusIconMap.put(RolloutGroupStatus.FINISHED, new StatusFontIcon(FontAwesome.CHECK_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_GREEN)); @@ -288,7 +286,7 @@ public class RolloutGroupListGrid extends AbstractGrid { new StatusFontIcon(FontAwesome.EXCLAMATION_CIRCLE, SPUIStyleDefinitions.STATUS_ICON_RED)); } - private String getDescription(CellReference cell) { + private String getDescription(final CellReference cell) { if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { return cell.getProperty().getValue().toString().toLowerCase(); } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { @@ -308,7 +306,7 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override public String getStyle(final CellReference cellReference) { - String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + final String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { return "centeralign"; @@ -329,14 +327,16 @@ public class RolloutGroupListGrid extends AbstractGrid { private static final long serialVersionUID = -9205943894818450807L; @Override - public TotalTargetCountStatus convertToModel(String value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public TotalTargetCountStatus convertToModel(final String value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { return null; } @Override - public String convertToPresentation(TotalTargetCountStatus value, Class targetType, - Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { + public String convertToPresentation(final TotalTargetCountStatus value, + final Class targetType, final Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { return DistributionBarHelper.getDistributionBarAsHTMLString(value.getStatusTotalCountMap()); } @@ -381,14 +381,10 @@ public class RolloutGroupListGrid extends AbstractGrid { public Class getPresentationType() { return String.class; } - + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { - StatusFontIcon statusFontIcon = statusIconMap.get(value); - if (statusFontIcon == null) { - return null; - } - String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + final StatusFontIcon statusFontIcon = statusIconMap.get(value); + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java index 0099dfc95..0a1446169 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -238,11 +238,7 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { private String processActionStatus(final Status status) { final StatusFontIcon statusFontIcon = statusIconMap.get(status); - if (statusFontIcon == null) { - return null; - } - final String codePoint = statusFontIcon.getFontIcon() != null - ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) : null; + final String codePoint = HawkbitCommonUtil.getCodePoint(statusFontIcon); return HawkbitCommonUtil.getStatusLabelDetailsInString(codePoint, statusFontIcon.getStyle(), null); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index e697e220e..a8c66a2a8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -37,6 +37,7 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; import org.eclipse.hawkbit.ui.management.dstable.DistributionTable; import org.eclipse.hawkbit.ui.management.targettable.TargetTable; +import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.userdetails.UserDetails; @@ -1359,12 +1360,12 @@ public final class HawkbitCommonUtil { * details of status and count * @return String */ - public static String getFormattedString(Map details) { - StringBuilder val = new StringBuilder(); + public static String getFormattedString(final Map details) { + final StringBuilder val = new StringBuilder(); if (details == null || details.isEmpty()) { return null; } - for (Entry entry : details.entrySet()) { + for (final Entry entry : details.entrySet()) { val.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } return val.substring(0, val.length() - 1); @@ -1382,8 +1383,8 @@ public final class HawkbitCommonUtil { * label id * @return */ - public static String getStatusLabelDetailsInString(String value, String style, String id) { - StringBuilder val = new StringBuilder(); + public static String getStatusLabelDetailsInString(final String value, final String style, final String id) { + final StringBuilder val = new StringBuilder(); if (!Strings.isNullOrEmpty(value)) { val.append("value:").append(value).append(","); } @@ -1394,4 +1395,19 @@ public final class HawkbitCommonUtil { return val.toString(); } + /** + * Receive the code point of a given StatusFontIcon. + * + * @param statusFontIcon + * the status font icon + * @return the code point of the StatusFontIcon + */ + public static String getCodePoint(final StatusFontIcon statusFontIcon) { + if (statusFontIcon == null) { + return null; + } + return statusFontIcon.getFontIcon() != null ? Integer.toString(statusFontIcon.getFontIcon().getCodepoint()) + : null; + } + } From 16fff8db979f7052e4a070248eb19fe2084b25b6 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Tue, 5 Apr 2016 10:50:31 +0200 Subject: [PATCH 25/56] Refactoring after review - removed else when not needed - return the if statement directly in the isDirectory method Signed-off-by: Jonathan Philip Knoblauch --- .../hawkbit/ui/artifacts/upload/UploadLayout.java | 5 +---- .../ui/management/targettable/BulkUploadHandler.java | 10 ++++------ .../RolloutGroupTargetsListGrid.java | 8 ++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 3fb735284..7376cce13 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -222,10 +222,7 @@ public class UploadLayout extends VerticalLayout { } private boolean isDirectory(final Html5File file) { - if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { - return true; - } - return false; + return Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0; } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index d52537a92..2369893c7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -306,11 +306,10 @@ public class BulkUploadHandler extends CustomComponent final DistributionSetIdName dsSelected = (DistributionSetIdName) comboBox.getValue(); if (distributionSetManagement.findDistributionSetById(dsSelected.getId()) == null) { return i18n.get("message.bulk.upload.assignment.failed"); - } else { - deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion().getId(), actionType, - forcedTimeStamp, targetsList.toArray(new String[targetsList.size()])); - return null; } + deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion().getId(), actionType, + forcedTimeStamp, targetsList.toArray(new String[targetsList.size()])); + return null; } private String tagAssignment() { @@ -330,9 +329,8 @@ public class BulkUploadHandler extends CustomComponent } if (deletedTags.size() == 1) { return i18n.get("message.bulk.upload.tag.assignment.failed", deletedTags.get(0)); - } else { - return i18n.get("message.bulk.upload.tag.assignments.failed"); } + return i18n.get("message.bulk.upload.tag.assignments.failed"); } private boolean ifTagsSelected() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java index 0a1446169..fe17b3cba 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -248,13 +248,13 @@ public class RolloutGroupTargetsListGrid extends AbstractGrid { if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { return HawkbitCommonUtil.getStatusLabelDetailsInString( Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", null); - } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + } + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { return HawkbitCommonUtil.getStatusLabelDetailsInString( Integer.toString(FontAwesome.MINUS_CIRCLE.getCodepoint()), "statusIconBlue", null); - } else { - return HawkbitCommonUtil.getStatusLabelDetailsInString( - Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); } + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); } } From 421bd9154ca545ace4e47fce05b4215ec7c12218 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 5 Apr 2016 12:13:36 +0200 Subject: [PATCH 26/56] fix license header of UrlProtocol enum --- .../src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java index 4dd84b7da..77c23ad0d 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/UrlProtocol.java @@ -1,5 +1,10 @@ /** - * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + * 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.api; From 9c9bdf640650ef4108234551f2032c09cf427e1a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 5 Apr 2016 12:20:49 +0200 Subject: [PATCH 27/56] fix json creator for PagedList for creating clients Signed-off-by: Michael Hirsch --- .../hawkbit/rest/resource/model/PagedList.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java index 880ee0c16..757a6106e 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java @@ -14,9 +14,11 @@ import javax.validation.constraints.NotNull; import org.springframework.hateoas.ResourceSupport; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; /** * A list representation with meta data for pagination, e.g. containing the @@ -31,7 +33,9 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @JsonInclude(Include.NON_NULL) public class PagedList extends ResourceSupport { + @JsonProperty private final List content; + @JsonProperty private final long totalElements; private final int size; @@ -41,14 +45,16 @@ public class PagedList extends ResourceSupport { * * @param content * the actual content of the list - * @param total + * @param totalElements * the total amount of elements * @throws NullPointerException * in case {@code content} is {@code null}. */ - public PagedList(@NotNull final List content, final long total) { + @JsonCreator + public PagedList(@JsonProperty("content") @NotNull final List content, + @JsonProperty("totalElements") final long totalElements) { this.size = content.size(); - this.totalElements = total; + this.totalElements = totalElements; this.content = content; } From c47c29519d9902943f2b3e685f5e35a6d0f31be1 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 5 Apr 2016 12:23:26 +0200 Subject: [PATCH 28/56] Add missing @PostConstruct Signed-off-by: SirWayne --- .../ui/common/footer/AbstractDeleteActionsLayout.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index cdf9ac354..f3b8b72e7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.ui.common.footer; +import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; @@ -41,9 +42,6 @@ import com.vaadin.ui.themes.ValoTheme; /** * Parent class for footer layout. * - * - * - * */ public abstract class AbstractDeleteActionsLayout extends VerticalLayout implements DropHandler { @@ -72,6 +70,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme /** * Initialize. */ + @PostConstruct protected void init() { if (hasCountMessage() || hasDeletePermission() || hasUpdatePermission() || hasBulkUploadPermission()) { createComponents(); From 5c0257adb99eb79fb83253a5b9f8c622ef32ecff Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 5 Apr 2016 12:35:01 +0200 Subject: [PATCH 29/56] Reduce more code Signed-off-by: SirWayne --- .../common/tagdetails/AbstractTagToken.java | 27 ++++++++++ .../tagdetails/AbstractTargetTagToken.java | 29 ----------- .../tagdetails/DistributionTagToken.java | 51 ++++--------------- .../ui/common/tagdetails/TargetTagToken.java | 6 +-- 4 files changed, 39 insertions(+), 74 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index a00b8ce70..4404e1f8a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -13,10 +13,17 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; import org.vaadin.tokenfield.TokenField; import org.vaadin.tokenfield.TokenField.InsertPosition; @@ -52,13 +59,33 @@ public abstract class AbstractTagToken implements Serializable { protected final Map tokensAdded = new HashMap<>(); protected CssLayout tokenLayout = new CssLayout(); + + @Autowired + protected SpPermissionChecker checker; + @Autowired + protected I18N i18n; + + @Autowired + protected UINotification uinotification; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + @Autowired protected ManagementUIState managementUIState; + @PostConstruct protected void init() { createTokenField(); checkIfTagAssignedIsAllowed(); + eventBus.subscribe(this); + } + + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); } private void createTokenField() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index efedbe3bc..c38a97228 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -8,54 +8,25 @@ */ package org.eclipse.hawkbit.ui.common.tagdetails; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; -import com.vaadin.ui.UI; - /** * Abstract class for target tag token layout. */ public abstract class AbstractTargetTagToken extends AbstractTagToken { private static final long serialVersionUID = 7772876588903171201L; - protected UI ui; - - @Autowired - protected transient EventBus.SessionEventBus eventBus; - - @Autowired - protected I18N i18n; @Autowired protected transient TagManagement tagManagement; - @Autowired - protected SpPermissionChecker checker; - @Override - @PostConstruct - protected void init() { - super.init(); - ui = UI.getCurrent(); - eventBus.subscribe(this); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } @EventBusListenerMethod(scope = EventScope.SESSION) void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 33f838dd0..9a245229b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; @@ -22,7 +21,6 @@ import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; @@ -31,10 +29,7 @@ import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -52,19 +47,6 @@ import com.vaadin.ui.UI; public class DistributionTagToken extends AbstractTagToken { private static final long serialVersionUID = -8022738301736043396L; - - @Autowired - private SpPermissionChecker spChecker; - - @Autowired - private I18N i18n; - - @Autowired - private UINotification uinotification; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient TagManagement tagManagement; @@ -73,20 +55,9 @@ public class DistributionTagToken extends AbstractTagToken { private DistributionSet selectedDS; - private UI ui; - // To Be Done : have to set this value based on view??? private static final Boolean NOTAGS_SELECTED = Boolean.FALSE; - @Override - @PostConstruct - protected void init() { - super.init(); - ui = UI.getCurrent(); - eventBus.subscribe(this); - - } - @Override protected String getTagStyleName() { return "distribution-tag-"; @@ -140,7 +111,7 @@ public class DistributionTagToken extends AbstractTagToken { @Override protected Boolean isToggleTagAssignmentAllowed() { - return spChecker.hasUpdateDistributionPermission(); + return checker.hasUpdateDistributionPermission(); } @Override @@ -163,18 +134,15 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE) { - ui.access(() -> { - /** - * distributionTableEvent.getDistributionSet() is null when - * table has no data. - */ - if (distributionTableEvent.getDistributionSet() != null) { - selectedDS = distributionTableEvent.getDistributionSet(); - repopulateToken(); - } - }); + if (distributionTableEvent.getDistributionComponentEvent() != DistributionComponentEvent.ON_VALUE_CHANGE) { + return; } + UI.getCurrent().access(() -> { + if (distributionTableEvent.getDistributionSet() != null) { + selectedDS = distributionTableEvent.getDistributionSet(); + repopulateToken(); + } + }); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -234,6 +202,7 @@ public class DistributionTagToken extends AbstractTagToken { return false; } + @Override @PreDestroy void destroy() { eventBus.unsubscribe(this); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 658501b4d..376e7d905 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -32,6 +32,7 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Item; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.UI; /** * Implementation of Target tag token. @@ -175,10 +176,7 @@ public class TargetTagToken extends AbstractTargetTagToken { void onEvent(final TargetTableEvent targetTableEvent) { if (targetTableEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET && targetTableEvent.getTarget() != null) { - ui.access(() -> { - /** - * targetTableEvent.getTarget() is null when table has no data. - */ + UI.getCurrent().access(() -> { selectedTarget = targetTableEvent.getTarget(); repopulateToken(); }); From bf168ffb706ec6ca9d438b283796073473d7ef29 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 5 Apr 2016 14:00:57 +0200 Subject: [PATCH 30/56] reduced duplicate code. --- .../model/DistributionSetMetadata.java | 52 ++-------- .../hawkbit/repository/model/MetaData.java | 98 +++++++++++++++++++ .../model/SoftwareModuleMetadata.java | 53 ++-------- 3 files changed, 111 insertions(+), 92 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index 7b2e637b9..28afd5517 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -8,10 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import java.io.Serializable; - -import javax.persistence.Basic; -import javax.persistence.Column; import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -29,24 +25,16 @@ import javax.persistence.Table; @IdClass(DsMetadataCompositeKey.class) @Entity @Table(name = "sp_ds_metadata") -public class DistributionSetMetadata implements Serializable { +public class DistributionSetMetadata extends MetaData { private static final long serialVersionUID = 1L; - @Id - @Column(name = "meta_key", length = 128) - private String key; - - @Column(name = "meta_value", length = 4000) - @Basic - private String value; - @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_ds")) private DistributionSet distributionSet; public DistributionSetMetadata() { - // Default constructor for JPA. + super(); } /** @@ -57,35 +45,18 @@ public class DistributionSetMetadata implements Serializable { * @param value */ public DistributionSetMetadata(final String key, final DistributionSet distributionSet, final String value) { - this.key = key; + super(key, value); this.distributionSet = distributionSet; - this.value = value; } public DsMetadataCompositeKey getId() { - return new DsMetadataCompositeKey(distributionSet, key); - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; + return new DsMetadataCompositeKey(distributionSet, getKey()); } public void setDistributionSet(final DistributionSet distributionSet) { this.distributionSet = distributionSet; } - public String getValue() { - return value; - } - - public void setValue(final String value) { - this.value = value; - } - public DistributionSet getDistributionSet() { return distributionSet; } @@ -93,9 +64,8 @@ public class DistributionSetMetadata implements Serializable { @Override public int hashCode() { final int prime = 31; - int result = 1; - result = prime * result + (distributionSet == null ? 0 : distributionSet.hashCode()); - result = prime * result + (key == null ? 0 : key.hashCode()); + int result = super.hashCode(); + result = prime * result + ((distributionSet == null) ? 0 : distributionSet.hashCode()); return result; } @@ -104,7 +74,7 @@ public class DistributionSetMetadata implements Serializable { if (this == obj) { return true; } - if (obj == null) { + if (!super.equals(obj)) { return false; } if (!(obj instanceof DistributionSetMetadata)) { @@ -118,14 +88,6 @@ public class DistributionSetMetadata implements Serializable { } else if (!distributionSet.equals(other.distributionSet)) { return false; } - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } return true; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java new file mode 100644 index 000000000..97ffacdcc --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -0,0 +1,98 @@ +/** + * 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.repository.model; + +import java.io.Serializable; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +/** + * Meta data for entities. + * + */ +@MappedSuperclass +public abstract class MetaData implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "meta_key", length = 128) + private String key; + + @Column(name = "meta_value", length = 4000) + @Basic + private String value; + + public MetaData(final String key, final String value) { + super(); + this.key = key; + this.value = value; + } + + public MetaData() { + // Default constructor needed for JPA entities + } + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(final String value) { + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof MetaData)) { + return false; + } + final MetaData other = (MetaData) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index c7af1f2ae..8783fec96 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -8,9 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import java.io.Serializable; - -import javax.persistence.Column; import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -28,16 +25,9 @@ import javax.persistence.Table; @IdClass(SwMetadataCompositeKey.class) @Entity @Table(name = "sp_sw_metadata") -public class SoftwareModuleMetadata implements Serializable { +public class SoftwareModuleMetadata extends MetaData { private static final long serialVersionUID = 1L; - @Id - @Column(name = "meta_key", length = 128) - private String key; - - @Column(name = "meta_value", length = 4000) - private String value; - @Id @ManyToOne(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY) @JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) @@ -47,7 +37,7 @@ public class SoftwareModuleMetadata implements Serializable { * Default constructor for JPA. */ public SoftwareModuleMetadata() { - // default constructor for JPA. + super(); } /** @@ -60,21 +50,12 @@ public class SoftwareModuleMetadata implements Serializable { * of the meta data element */ public SoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { - this.key = key; + super(key, value); this.softwareModule = softwareModule; - this.value = value; } public SwMetadataCompositeKey getId() { - return new SwMetadataCompositeKey(softwareModule, key); - } - - public String getValue() { - return value; - } - - public void setValue(final String value) { - this.value = value; + return new SwMetadataCompositeKey(softwareModule, getKey()); } public SoftwareModule getSoftwareModule() { @@ -85,24 +66,10 @@ public class SoftwareModuleMetadata implements Serializable { this.softwareModule = softwareModule; } - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - @Override - public String toString() { - return "SoftwareModuleMetadata [key=" + key + ", value=" + value + ", softwareModule=" + softwareModule + "]"; - } - @Override public int hashCode() { final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); + int result = super.hashCode(); result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode()); return result; } @@ -112,20 +79,13 @@ public class SoftwareModuleMetadata implements Serializable { if (this == obj) { return true; } - if (obj == null) { + if (!super.equals(obj)) { return false; } if (!(obj instanceof SoftwareModuleMetadata)) { return false; } final SoftwareModuleMetadata other = (SoftwareModuleMetadata) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } if (softwareModule == null) { if (other.softwareModule != null) { return false; @@ -135,5 +95,4 @@ public class SoftwareModuleMetadata implements Serializable { } return true; } - } From d8268e8b6bd0b8d6091a566afde4e8b53c96747f Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 5 Apr 2016 14:01:09 +0200 Subject: [PATCH 31/56] Used proper exception --- .../java/org/eclipse/hawkbit/simulator/SimulatorStartup.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java index faff1cc6c..60f3055bd 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatorStartup.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.simulator; +import java.net.MalformedURLException; import java.net.URL; import org.eclipse.hawkbit.simulator.amqp.SpSenderService; @@ -47,7 +48,7 @@ public class SimulatorStartup implements ApplicationListener Date: Tue, 5 Apr 2016 14:42:00 +0200 Subject: [PATCH 32/56] fix license header in pom.xml Signed-off-by: Michael Hirsch --- hawkbit-security-integration/pom.xml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hawkbit-security-integration/pom.xml b/hawkbit-security-integration/pom.xml index 591552997..c17317b3d 100644 --- a/hawkbit-security-integration/pom.xml +++ b/hawkbit-security-integration/pom.xml @@ -1,6 +1,13 @@ - + 4.0.0 From 39fc74469f513f879d4e836aee7592cf3d19289e Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 5 Apr 2016 15:02:55 +0200 Subject: [PATCH 33/56] fix paged list json. Signed-off-by: Michael Hirsch --- .../hawkbit/rest/resource/model/PagedList.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java index 757a6106e..9d5cc458c 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/PagedList.java @@ -36,7 +36,7 @@ public class PagedList extends ResourceSupport { @JsonProperty private final List content; @JsonProperty - private final long totalElements; + private final long total; private final int size; /** @@ -45,16 +45,15 @@ public class PagedList extends ResourceSupport { * * @param content * the actual content of the list - * @param totalElements + * @param total * the total amount of elements * @throws NullPointerException * in case {@code content} is {@code null}. */ @JsonCreator - public PagedList(@JsonProperty("content") @NotNull final List content, - @JsonProperty("totalElements") final long totalElements) { + public PagedList(@JsonProperty("content") @NotNull final List content, @JsonProperty("total") final long total) { this.size = content.size(); - this.totalElements = totalElements; + this.total = total; this.content = content; } @@ -69,7 +68,7 @@ public class PagedList extends ResourceSupport { * @return the total amount of elements */ public long getTotal() { - return totalElements; + return total; } public List getContent() { From 4884f18deb35403dec062619f4a0fdb259e982be Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 5 Apr 2016 19:06:14 +0200 Subject: [PATCH 34/56] remove local variable which is never read only returned Signed-off-by: Michael Hirsch --- .../hawkbit/amqp/AmqpMessageHandlerService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index c5fff29ad..41e70f91f 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -214,19 +214,18 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { - LocalArtifact localArtifact = null; if (fileResource.getSha1() != null) { - localArtifact = artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); + return artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); } else if (fileResource.getFilename() != null) { - localArtifact = artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream() - .findFirst().orElse(null); + return artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream().findFirst() + .orElse(null); } else if (fileResource.getSoftwareModuleFilenameResource() != null) { - localArtifact = artifactManagement + return artifactManagement .findByFilenameAndSoftwareModule(fileResource.getSoftwareModuleFilenameResource().getFilename(), fileResource.getSoftwareModuleFilenameResource().getSoftwareModuleId()) .stream().findFirst().orElse(null); } - return localArtifact; + return null; } private static Artifact convertDbArtifact(final DbArtifact dbArtifact) { From f4f9c10186a0763d9ecd35b8c9a53f7654d9aa89 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 6 Apr 2016 10:57:23 +0200 Subject: [PATCH 35/56] Optimized equals. Signed-off-by: Kai Zimmermann --- .../model/DistributionSetMetadata.java | 15 +------------- .../hawkbit/repository/model/MetaData.java | 2 +- .../model/SoftwareModuleMetadata.java | 20 +------------------ 3 files changed, 3 insertions(+), 34 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index 28afd5517..67a99506c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -34,16 +34,9 @@ public class DistributionSetMetadata extends MetaData { private DistributionSet distributionSet; public DistributionSetMetadata() { - super(); + // default public constructor for JPA } - /** - * Parameter constructor. - * - * @param key - * @param distributionSet - * @param value - */ public DistributionSetMetadata(final String key, final DistributionSet distributionSet, final String value) { super(key, value); this.distributionSet = distributionSet; @@ -71,15 +64,9 @@ public class DistributionSetMetadata extends MetaData { @Override public boolean equals(final Object obj) { - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } - if (!(obj instanceof DistributionSetMetadata)) { - return false; - } final DistributionSetMetadata other = (DistributionSetMetadata) obj; if (distributionSet == null) { if (other.distributionSet != null) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java index 97ffacdcc..c41a0e8c9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -74,7 +74,7 @@ public abstract class MetaData implements Serializable { if (obj == null) { return false; } - if (!(obj instanceof MetaData)) { + if (!(this.getClass().isInstance(obj))) { return false; } final MetaData other = (MetaData) obj; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index 8783fec96..5ddd273d3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -33,22 +33,10 @@ public class SoftwareModuleMetadata extends MetaData { @JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) private SoftwareModule softwareModule; - /** - * Default constructor for JPA. - */ public SoftwareModuleMetadata() { - super(); + // default public constructor for JPA } - /** - * Standard constructor. - * - * @param key - * of the meta data element - * @param softwareModule - * @param value - * of the meta data element - */ public SoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { super(key, value); this.softwareModule = softwareModule; @@ -76,15 +64,9 @@ public class SoftwareModuleMetadata extends MetaData { @Override public boolean equals(final Object obj) { - if (this == obj) { - return true; - } if (!super.equals(obj)) { return false; } - if (!(obj instanceof SoftwareModuleMetadata)) { - return false; - } final SoftwareModuleMetadata other = (SoftwareModuleMetadata) obj; if (softwareModule == null) { if (other.softwareModule != null) { From dc18bfea7b6aaf956e33418cc321a9216bde3bab Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 6 Apr 2016 17:42:02 +0200 Subject: [PATCH 36/56] Refactoring Table, TableHeader and Detail Layout components - Add interfaces to reduce boiler plate code - Add generic to reuse code - Try to remove duplicate code Signed-off-by: SirWayne --- .../ui/artifacts/UploadArtifactView.java | 6 +- .../details/ArtifactDetailsLayout.java | 26 ++- .../artifacts/event/SoftwareModuleEvent.java | 41 ++--- .../footer/SMDeleteActionsLayout.java | 32 +--- .../UploadViewConfirmationWindowLayout.java | 82 ++------- .../SoftwareModuleAddUpdateWindow.java | 9 +- .../smtable/SoftwareModuleDetails.java | 96 ++--------- .../smtable/SoftwareModuleTable.java | 160 ++++-------------- .../smtable/SoftwareModuleTableHeader.java | 7 +- .../artifacts/state/ArtifactUploadState.java | 49 +++--- .../ui/common/ManagmentEntityState.java | 22 +++ .../AbstractConfirmationWindowLayout.java | 55 +++--- ...amedVersionedEntityTableDetailsLayout.java | 28 +++ .../AbstractTableDetailsLayout.java | 96 ++++++----- .../SoftwareModuleDetailsTable.java | 7 +- .../footer/AbstractDeleteActionsLayout.java | 109 ++++++------ .../ui/common/table/AbstractTable.java | 158 +++++++++++++++-- .../ui/common/table/BaseEntityEvent.java | 44 +++++ .../ui/common/table/BaseEntityEventType.java | 17 ++ .../common/tagdetails/AbstractTagToken.java | 28 ++- .../tagdetails/AbstractTargetTagToken.java | 5 +- .../tagdetails/DistributionTagToken.java | 34 +--- .../ui/common/tagdetails/TargetTagToken.java | 20 +-- .../ui/distributions/DistributionsView.java | 11 +- .../dstable/DistributionSetDetails.java | 131 ++++---------- .../dstable/DistributionSetTable.java | 158 +++++------------ .../dstable/DistributionSetTableHeader.java | 6 +- .../footer/DSDeleteActionsLayout.java | 32 +--- ...DistributionsConfirmationWindowLayout.java | 134 +++------------ .../smtable/SwModuleDetails.java | 91 ++-------- .../distributions/smtable/SwModuleTable.java | 137 +++++---------- .../smtable/SwModuleTableHeader.java | 7 +- .../state/ManageDistUIState.java | 16 +- .../hawkbit/ui/management/DeploymentView.java | 10 +- .../actionhistory/ActionHistoryComponent.java | 6 +- .../actionhistory/ActionHistoryTable.java | 8 +- .../DistributionAddUpdateWindowLayout.java | 7 +- .../dstable/DistributionDetails.java | 89 +--------- .../management/dstable/DistributionTable.java | 113 +++++-------- .../dstable/DistributionTableHeader.java | 6 +- .../event/DistributionTableEvent.java | 46 ++--- .../event/TargetAddUpdateWindowEvent.java | 33 +--- .../ui/management/event/TargetTableEvent.java | 64 +++---- .../management/footer/CountMessageLabel.java | 4 +- .../footer/DeleteActionsLayout.java | 7 +- .../ManangementConfirmationWindowLayout.java | 107 +++--------- .../management/state/ManagementUIState.java | 14 +- .../TargetAddUpdateWindowLayout.java | 7 +- .../management/targettable/TargetDetails.java | 91 +++------- .../management/targettable/TargetTable.java | 126 ++++---------- .../targettable/TargetTableHeader.java | 9 +- .../targettag/TargetTagFilterButtons.java | 3 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 77 +-------- 53 files changed, 934 insertions(+), 1747 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java index 54ba5cc8e..b07aa0276 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java @@ -15,12 +15,12 @@ import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.footer.SMDeleteActionsLayout; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleTableLayout; import org.eclipse.hawkbit.ui.artifacts.smtype.SMTypeFilterLayout; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -111,9 +111,9 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeSwTable(); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeSwTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java index 1bc9da65c..7c5d4153f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIButton; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -110,8 +111,6 @@ public class ArtifactDetailsLayout extends VerticalLayout { private boolean fullWindowMode = false; - private UI ui; - private boolean readOnly = false; /** @@ -122,7 +121,6 @@ public class ArtifactDetailsLayout extends VerticalLayout { createComponents(); buildLayout(); eventBus.subscribe(this); - ui = UI.getCurrent(); if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); populateArtifactDetails(selectedSoftwareModule.getId(), HawkbitCommonUtil @@ -461,23 +459,23 @@ public class ArtifactDetailsLayout extends VerticalLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE) { - ui.access(() -> { - if (softwareModuleEvent.getSoftwareModule() != null) { - populateArtifactDetails(softwareModuleEvent.getSoftwareModule().getId(), - HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getSoftwareModule().getName(), - softwareModuleEvent.getSoftwareModule().getVersion())); + if (BaseEntityEventType.SELECTED_ENTITY == softwareModuleEvent.getEventType()) { + UI.getCurrent().access(() -> { + if (softwareModuleEvent.getEntity() != null) { + populateArtifactDetails(softwareModuleEvent.getEntity().getId(), + HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(), + softwareModuleEvent.getEntity().getVersion())); } else { populateArtifactDetails(null, null); } }); } if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.ARTIFACTS_CHANGED) { - ui.access(() -> { - if (softwareModuleEvent.getSoftwareModule() != null) { - populateArtifactDetails(softwareModuleEvent.getSoftwareModule().getId(), - HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getSoftwareModule().getName(), - softwareModuleEvent.getSoftwareModule().getVersion())); + UI.getCurrent().access(() -> { + if (softwareModuleEvent.getEntity() != null) { + populateArtifactDetails(softwareModuleEvent.getEntity().getId(), + HawkbitCommonUtil.getFormattedNameVersion(softwareModuleEvent.getEntity().getName(), + softwareModuleEvent.getEntity().getVersion())); } else { populateArtifactDetails(null, null); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java index 3d0897dcd..95770cb8f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java @@ -9,58 +9,53 @@ package org.eclipse.hawkbit.ui.artifacts.event; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * Event to represent software add, update or delete. - * - * * */ -public class SoftwareModuleEvent { +public class SoftwareModuleEvent extends BaseEntityEvent { /** * Software module events in the Upload UI. - * - * * */ public enum SoftwareModuleEventType { - NEW_SOFTWARE_MODULE, UPDATED_SOFTWARE_MODULE, DELETE_SOFTWARE_MODULE, SELECTED_SOFTWARE_MODULE, MAXIMIZED, MINIMIZED, ARTIFACTS_CHANGED, ASSIGN_SOFTWARE_MODULE + ARTIFACTS_CHANGED, ASSIGN_SOFTWARE_MODULE } private SoftwareModuleEventType softwareModuleEventType; - private SoftwareModule softwareModule; + /** + * Creates software module event. + * + * @param entityEventType + * the event type + * @param softwareModule + * the module + */ + public SoftwareModuleEvent(final BaseEntityEventType entityEventType, final SoftwareModule softwareModule) { + super(entityEventType, softwareModule); + } /** * Creates software module event. * * @param softwareModuleEventType - * reference of {@link SoftwareModuleEventType} + * the event type * @param softwareModule - * reference of {@link SoftwareModule} + * the module */ public SoftwareModuleEvent(final SoftwareModuleEventType softwareModuleEventType, final SoftwareModule softwareModule) { - super(); + super(null, softwareModule); this.softwareModuleEventType = softwareModuleEventType; - this.softwareModule = softwareModule; } public SoftwareModuleEventType getSoftwareModuleEventType() { return softwareModuleEventType; } - public void setSoftwareModuleEventType(final SoftwareModuleEventType softwareModuleEventType) { - this.softwareModuleEventType = softwareModuleEventType; - } - - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = softwareModule; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index 97451961c..a5cb5c8d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -28,7 +28,6 @@ import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Component; -import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.Table.TableTransferable; import com.vaadin.ui.UI; @@ -191,7 +190,7 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - uploadViewConfirmationWindowLayout.init(); + uploadViewConfirmationWindowLayout.inittialize(); return uploadViewConfirmationWindowLayout; } @@ -201,33 +200,4 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { || !artifactUploadState.getSelectedDeleteSWModuleTypes().isEmpty(); } - @Override - protected boolean hasCountMessage() { - return false; - } - - @Override - protected Label getCountMessageLabel() { - return null; - } - - @Override - protected boolean hasBulkUploadPermission() { - return false; - } - - @Override - protected void showBulkUploadWindow() { - /** - * Bulk upload not supported .No implementation required. - */ - } - - @Override - protected void restoreBulkUploadStatusCount() { - /** - * Bulk upload not supported .No implementation required. - */ - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java index 49e9ab59f..e6284d5d6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java @@ -14,23 +14,17 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -39,8 +33,8 @@ import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; -import com.vaadin.ui.themes.ValoTheme; /** * Abstract layout of confirm actions window. @@ -62,32 +56,12 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind private static final String DISCARD = "Discard"; - @Autowired - private I18N i18n; - @Autowired private transient SoftwareManagement softwareManagement; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ArtifactUploadState artifactUploadState; - /** - * Initialze the component. - */ - @PostConstruct - void init() { - super.inittialize(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.confirmwindow.layout. - * AbstractConfirmationWindowLayout# getConfimrationTabs() - */ @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -116,26 +90,13 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind // Add the discard action column tab.getTable().addGeneratedColumn(SW_DISCARD_CHGS, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + "redicon", true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardSoftwareDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardSoftwareDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_NAME_MSG); - visibleColumnIds.add(SW_DISCARD_CHGS); - visibleColumnLabels.add(i18n.get("upload.swModuleTable.header")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_NAME_MSG, SW_DISCARD_CHGS); + tab.getTable().setColumnHeaders(i18n.get("upload.swModuleTable.header"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_NAME_MSG, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -233,30 +194,14 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind // Add the discard action column tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append("redicon"); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener(event -> discardSoftwareTypeDelete( - (String) ((Button) event.getComponent()).getData(), itemId, tab)); - return deleteIcon; + final ClickListener clickListener = event -> discardSoftwareTypeDelete( + (String) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_TYPE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.swmodule.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.swmodule.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_TYPE_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.swmodule.type.table"), + i18n.get("header.second.delete.swmodule.type.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_TYPE_NAME, 2); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -264,9 +209,6 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind return tab; } - /** - * @return - */ private Container getSWModuleTypeTableContainer() { final IndexedContainer contactContainer = new IndexedContainer(); contactContainer.addContainerProperty(SW_MODULE_TYPE_NAME, String.class, ""); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 7e05e8c63..cc08929bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -13,8 +13,8 @@ import java.io.Serializable; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -282,8 +282,8 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { /* display success message */ uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() })); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.NEW_SOFTWARE_MODULE, - newBaseSoftwareModule)); + eventBus.publish(this, + new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule)); } // close the window closeThisWindow(); @@ -302,8 +302,7 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { newSWModule.getName() + ":" + newSWModule.getVersion() })); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE, newSWModule)); + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.UPDATED_ENTITY, newSWModule)); } closeThisWindow(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index dc6035089..397f0cf2b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -10,9 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -36,7 +35,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SoftwareModuleDetails extends AbstractTableDetailsLayout { +public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -4900381301076646366L; @@ -46,10 +45,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { @Autowired private ArtifactUploadState artifactUploadState; - private Long swModuleId; - - private SoftwareModule selectedSwModule; - @Override protected String getEditButtonId() { return SPUIComponetIdProvider.UPLOAD_SW_MODULE_EDIT_BUTTON; @@ -64,21 +59,24 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - final Window addSoftwareModule = softwareModuleAddUpdateWindow.createUpdateSoftwareModuleWindow(swModuleId); + final Window addSoftwareModule = softwareModuleAddUpdateWindow + .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } - private void populateDetails(final SoftwareModule swModule) { + @Override + protected void populateDetailsWidget() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (swModule != null) { - if (swModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { + if (selectedBaseEntity != null) { + if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { maxAssign = i18n.get("label.multiAssign.type"); } else { maxAssign = i18n.get("label.singleAssign.type"); } - updateSoftwareModuleDetailsLayout(swModule.getType().getName(), swModule.getVendor(), maxAssign); + updateSoftwareModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), + maxAssign); } else { updateSoftwareModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -109,45 +107,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { } - private void populateLog(final SoftwareModule softwareModule) { - if (null != softwareModule) { - updateLogLayout(getLogLayout(), softwareModule.getLastModifiedAt(), softwareModule.getLastModifiedBy(), - softwareModule.getCreatedAt(), softwareModule.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - public void setSwModuleId(final Long swModuleId) { - this.swModuleId = swModuleId; - } - - private void populateDetailsWidget(final SoftwareModule swModule) { - if (swModule != null) { - setSwModuleId(swModule.getId()); - setName(getDefaultCaption(), - HawkbitCommonUtil.getFormattedNameVersion(swModule.getName(), swModule.getVersion())); - populateDetails(swModule); - populateDescription(swModule); - populateLog(swModule); - } else { - setSwModuleId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populateLog(null); - } - } - - private void populateDescription(final SoftwareModule swModule) { - if (swModule != null) { - updateDescriptionLayout(i18n.get("label.description"), swModule.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - - @Override protected String getDefaultCaption() { return i18n.get("upload.swModuleTable.header"); @@ -158,45 +117,14 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { return artifactUploadState.getSelectedBaseSoftwareModule().isPresent(); } - @Override protected Boolean onLoadIsTableMaximized() { return artifactUploadState.isSwModuleTableMaximized(); } - - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedSwModule); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE - || softwareModuleEvent - .getSoftwareModuleEventType() == SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE) { - ui.access(() -> { - /** - * softwareModuleEvent.getSoftwareModule() is null when table - * has no data. - */ - if (softwareModuleEvent.getSoftwareModule() != null) { - selectedSwModule = softwareModuleEvent.getSoftwareModule(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - showLayout(); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - hideLayout(); - } - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); + onBaseEntityEvent(softwareModuleEvent); } @Override @@ -204,7 +132,6 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { return permissionChecker.hasUpdateDistributionPermission(); } - @Override protected String getTabSheetId() { return null; @@ -214,4 +141,5 @@ public class SoftwareModuleDetails extends AbstractTableDetailsLayout { protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.TARGET_DETAILS_HEADER_LABEL_ID; } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index aea80476a..6164fa3bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -8,29 +8,20 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -39,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -58,45 +48,19 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class SoftwareModuleTable extends AbstractTable { +public class SoftwareModuleTable extends AbstractTable { private static final long serialVersionUID = 6469417305487144809L; - @Autowired - private I18N i18n; - @Autowired private ArtifactUploadState artifactUploadState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient SoftwareManagement softwareManagement; @Autowired private UploadViewAcceptCriteria uploadViewAcceptCriteria; - /** - * Initialize the filter layout. - */ - @Override - @PostConstruct - protected void init() { - super.init(); - eventBus.subscribe(this); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SMFilterEvent filterEvent) { UI.getCurrent().access(() -> { @@ -150,74 +114,40 @@ public class SoftwareModuleTable extends AbstractTable { lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); } - @Override - protected void addCustomGeneratedColumns() { - /* No generated columns */ - } - @Override protected boolean isFirstRowSelectedOnLoad() { return artifactUploadState.getSelectedSoftwareModules().isEmpty(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.SPTable#getItemIdToSelect() - */ @Override protected Object getItemIdToSelect() { return artifactUploadState.getSelectedSoftwareModules(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.table.SPTable#isMaximized() - */ @Override protected boolean isMaximized() { return artifactUploadState.isSwModuleTableMaximized(); } - @SuppressWarnings("rawtypes") @Override - protected void onValueChange() { - eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); - Long value = null; - while (iterator.hasNext()) { - value = iterator.next(); - } - if (null != value) { - artifactUploadState.setSelectedBaseSwModuleId(value); - final SoftwareModule baseSoftwareModule = softwareManagement.findSoftwareModuleById(value); - artifactUploadState.setSelectedBaseSoftwareModule(baseSoftwareModule); - artifactUploadState.setSelectedSoftwareModules(values); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, baseSoftwareModule)); - } - } else { - artifactUploadState.setSelectedBaseSwModuleId(null); - artifactUploadState.setSelectedBaseSoftwareModule(null); - artifactUploadState.setSelectedSoftwareModules(Collections.emptySet()); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, null)); - } + protected SoftwareModule findEntityByTableValue(final Long entityTableId) { + return softwareManagement.findSoftwareModuleById(entityTableId); + } + + @Override + protected ArtifactUploadState getManagmentEntityState() { + return artifactUploadState; + } + + @Override + protected void publishEntityAfterValueChange(final SoftwareModule lastSoftwareModule) { + artifactUploadState.setSelectedBaseSoftwareModule(lastSoftwareModule); + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, lastSoftwareModule)); } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.NEW_SOFTWARE_MODULE) { - UI.getCurrent().access(() -> addSoftwareModule(event.getSoftwareModule())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -227,51 +157,30 @@ public class SoftwareModuleTable extends AbstractTable { } } - /** - * Add new software module to table. - * - * @param swModule - * new software module - */ @SuppressWarnings("unchecked") - private void addSoftwareModule(final SoftwareModule swModule) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - final String swNameVersion = HawkbitCommonUtil.concatStrings(":", swModule.getName(), swModule.getVersion()); + @Override + protected Item addEntity(final SoftwareModule baseEntity) { + final Item item = super.addEntity(baseEntity); + + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty("swId").setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(swModule.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(swModule.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(swModule.getVendor()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY).setValue(swModule.getCreatedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setValue(swModule.getLastModifiedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getLastModifiedAt())); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); if (!artifactUploadState.getSelectedSoftwareModules().isEmpty()) { - artifactUploadState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); + artifactUploadState.getSelectedSoftwareModules().stream().forEach(this::unselect); } - select(swModule.getId()); + select(baseEntity.getId()); + return item; + } @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); @@ -297,12 +206,9 @@ public class SoftwareModuleTable extends AbstractTable { }; } - private void setNoDataAvailable() { - final int containerSize = getContainerDataSource().size(); - if (containerSize == 0) { - artifactUploadState.setNoDataAvilableSoftwareModule(true); - } else { - artifactUploadState.setNoDataAvilableSoftwareModule(false); - } + @Override + protected void setDataAvailable(final boolean available) { + artifactUploadState.setNoDataAvilableSoftwareModule(!available); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java index 5f1c56636..16ef3154c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java @@ -10,10 +10,10 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -51,7 +51,6 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { } } - @Override protected String getHeaderCaption() { return i18n.get("upload.swModuleTable.header"); @@ -131,14 +130,14 @@ public class SoftwareModuleTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { artifactUploadState.setSwModuleTableMaximized(Boolean.TRUE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MAXIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { artifactUploadState.setSwModuleTableMaximized(Boolean.FALSE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MINIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index a502b341c..b975ad1fd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -17,6 +17,7 @@ import java.util.Optional; import java.util.Set; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -29,7 +30,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @VaadinSessionScope @SpringComponent -public class ArtifactUploadState implements Serializable { +public class ArtifactUploadState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = 8273440375917450859L; @@ -88,29 +89,6 @@ public class ArtifactUploadState implements Serializable { return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); } - /** - * @param selectedBaseSwModuleId - * the selectedBaseSwModuleId to set - */ - public void setSelectedBaseSwModuleId(final Long selectedBaseSwModuleId) { - this.selectedBaseSwModuleId = selectedBaseSwModuleId; - } - - /** - * @return the selectedBaseSoftwareModule - */ - public Optional getSelectedBaseSoftwareModule() { - return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); - } - - /** - * @param selectedBaseSoftwareModule - * the selectedBaseSoftwareModule to set - */ - public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { - this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; - } - /** * @return the baseSwModuleList */ @@ -125,12 +103,15 @@ public class ArtifactUploadState implements Serializable { return selectedSoftwareModules; } - /** - * @param selectedSoftwareModules - * the selectedSoftwareModules to set - */ - public void setSelectedSoftwareModules(final Set selectedSoftwareModules) { - this.selectedSoftwareModules = selectedSoftwareModules; + @Override + public void setLastSelectedEntity(final Long value) { + this.selectedBaseSwModuleId = value; + + } + + @Override + public void setSelectedEnitities(final Set values) { + this.selectedSoftwareModules = values; } /** @@ -197,4 +178,12 @@ public class ArtifactUploadState implements Serializable { this.noDataAvilableSoftwareModule = noDataAvilableSoftwareModule; } + public Optional getSelectedBaseSoftwareModule() { + return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); + } + + public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { + this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java new file mode 100644 index 000000000..8b2318ace --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java @@ -0,0 +1,22 @@ +/** + * 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.common; + +import java.util.Set; + +/** + * + */ +public interface ManagmentEntityState { + + void setSelectedEnitities(Set values); + + void setLastSelectedEntity(T value); + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index 8a89ee821..a737fabbf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -11,21 +11,29 @@ package org.eclipse.hawkbit.ui.common.confirmwindow.layout; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; -import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import javax.annotation.PostConstruct; +import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; + +import com.vaadin.server.FontAwesome; import com.vaadin.ui.Accordion; import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; /** * Abstract layout of confirm actions window. * - * - * - * */ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { @@ -37,33 +45,25 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { private String consolidatedMessage; - protected void inittialize() { - // Remove all components + @Autowired + protected I18N i18n; + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @PostConstruct + public void inittialize() { removeAllComponents(); consolidatedMessage = ""; - - // create components again createComponents(); - - // Build layout. buildLayout(); } - /** - * Create accordion and add respective tabs. - */ private void createComponents() { - // create accordion createAccordian(); - - // create action message label createActionMessgaeLabel(); } - /** - * Create a message label to show the results of any actions which user does - * in the confirmation window. - */ private void createActionMessgaeLabel() { actionMessage = SPUIComponentProvider.getLabel("", null); actionMessage.addStyleName(SPUIStyleDefinitions.CONFIRM_WINDOW_INFO_BOX); @@ -138,4 +138,15 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { public String getConsolidatedMessage() { return consolidatedMessage; } + + protected Button createDiscardButton(final Object itemId, final ClickListener clickListener) { + final Button deletesDsIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, + ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, + SPUIButtonStyleSmallNoBorder.class); + deletesDsIcon.setData(itemId); + deletesDsIcon.setImmediate(true); + deletesDsIcon.addClickListener(clickListener); + return deletesDsIcon; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java new file mode 100644 index 000000000..31fbe5996 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -0,0 +1,28 @@ +/** + * 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.common.detailslayout; + +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; + +/** + * + * + */ +public abstract class AbstractNamedVersionedEntityTableDetailsLayout + extends AbstractTableDetailsLayout { + + private static final long serialVersionUID = 1L; + + @Override + protected String getName() { + return HawkbitCommonUtil.getFormattedNameVersion(selectedBaseEntity.getName(), selectedBaseEntity.getVersion()); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 20a107ba6..02b1f0044 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -13,8 +13,12 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -40,7 +44,7 @@ import com.vaadin.ui.VerticalLayout; * * */ -public abstract class AbstractTableDetailsLayout extends VerticalLayout { +public abstract class AbstractTableDetailsLayout extends VerticalLayout { private static final long serialVersionUID = 4862529368471627190L; @@ -53,7 +57,7 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { @Autowired protected SpPermissionChecker permissionChecker; - protected UI ui; + protected T selectedBaseEntity; private Label caption; @@ -74,13 +78,8 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { */ @PostConstruct protected void init() { - ui = UI.getCurrent(); createComponents(); buildLayout(); - /** - * On load of UI/Refresh details will be loaded based on the row - * selected in table. - */ restoreState(); eventBus.subscribe(this); } @@ -90,6 +89,18 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { eventBus.unsubscribe(this); } + protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + final BaseEntityEventType eventType = baseEntityEvent.getEventType(); + if (BaseEntityEventType.SELECTED_ENTITY == eventType + || BaseEntityEventType.UPDATED_ENTITY == eventType) { + UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity())); + } else if (BaseEntityEventType.MINIMIZED == eventType) { + UI.getCurrent().access(() -> setVisible(true)); + } else if (BaseEntityEventType.MAXIMIZED == eventType) { + UI.getCurrent().access(() -> setVisible(false)); + } + } + private void createComponents() { /** * Default caption is set.Reset on selecting table row. @@ -156,44 +167,29 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { private void restoreState() { if (onLoadIsTableRowSelected()) { - populateData(true); + populateData(null); + editButton.setEnabled(true); } if (onLoadIsTableMaximized()) { - /** - * If table is maximized hide details layout. - */ - hideLayout(); + setVisible(false); } } - protected void showLayout() { - setVisible(true); - } - - protected void hideLayout() { - setVisible(false); - } - /** * If no data in table (i,e no row selected),then disable the edit button. * If row is selected ,enable edit button. */ - protected void populateData(final Boolean isRowSelected) { - if (isRowSelected) { - populateDetailsWidget(); - enableEditButton(); + private void populateData(final T selectedBaseEntity) { + this.selectedBaseEntity = selectedBaseEntity; + editButton.setEnabled(selectedBaseEntity != null); + if (selectedBaseEntity == null) { + setName(getDefaultCaption(), StringUtils.EMPTY); } else { - disableEditButton(); - clearDetails(); + setName(getDefaultCaption(), getName()); } - } - - protected void enableEditButton() { - editButton.setEnabled(true); - } - - protected void disableEditButton() { - editButton.setEnabled(false); + populateLog(); + populateDescription(); + populateDetailsWidget(); } protected void updateLogLayout(final VerticalLayout changeLogLayout, final Long lastModifiedAt, @@ -297,13 +293,6 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { protected abstract String getTabSheetId(); - /** - * Populate details layout. - */ - protected abstract void populateDetailsWidget(); - - protected abstract void clearDetails(); - protected abstract Boolean hasEditPermission(); public VerticalLayout getDetailsLayout() { @@ -314,6 +303,31 @@ public abstract class AbstractTableDetailsLayout extends VerticalLayout { return logLayout; } + private void populateLog() { + if (selectedBaseEntity == null) { + updateLogLayout(getLogLayout(), null, StringUtils.EMPTY, null, null, i18n); + return; + } + updateLogLayout(getLogLayout(), selectedBaseEntity.getLastModifiedAt(), selectedBaseEntity.getLastModifiedBy(), + selectedBaseEntity.getCreatedAt(), selectedBaseEntity.getCreatedBy(), i18n); + } + + private void populateDescription() { + if (selectedBaseEntity != null) { + updateDescriptionLayout(i18n.get("label.description"), selectedBaseEntity.getDescription()); + } else { + updateDescriptionLayout(i18n.get("label.description"), null); + } + } + + protected abstract void populateDetailsWidget(); + + protected Long getSelectedBaseEntityId() { + return selectedBaseEntity == null ? null : selectedBaseEntity.getId(); + } + protected abstract String getDetailsHeaderCaptionId(); + protected abstract String getName(); + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index 40acb6581..c0ecf9869 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -16,12 +16,12 @@ import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; @@ -214,9 +214,8 @@ public class SoftwareModuleDetailsTable extends Table { .getItem(event.getButton().getId()).getItemProperty(SOFT_MODULE).getValue(), alreadyAssignedSwModules); final DistributionSet newDistributionSet = distributionSetManagement.unassignSoftwareModule(distributionSet, unAssignedSw); - manageDistUIState.setLastSelectedDistribution(newDistributionSet.getDistributionSetIdName()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, newDistributionSet)); + manageDistUIState.setLastSelectedEntity(newDistributionSet.getDistributionSetIdName()); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, newDistributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); uiNotification.displaySuccess(i18n.get("message.sw.unassigned", unAssignedSw.getName())); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index f3b8b72e7..0f5e2de32 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -182,40 +182,45 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } protected void setUploadStatusButtonCaption(final Long count) { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.setCaption("
" + count + "
"); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.setCaption("
" + count + "
"); } protected void enableBulkUploadStatusButton() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.setVisible(true); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.setVisible(true); } protected void updateUploadBtnIconToComplete() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); - bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD); } protected void updateUploadBtnIconToProgressIndicator() { - if (null != bulkUploadStatusButton) { - bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); - bulkUploadStatusButton.setIcon(null); + if (bulkUploadStatusButton == null) { + return; } + bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.setIcon(null); } protected void actionButtonClicked() { - if (hasUnsavedActions()) { - unsavedActionsWindow = SPUIComponentProvider.getWindow(getUnsavedActionsWindowCaption(), - SPUIComponetIdProvider.SAVE_ACTIONS_POPUP, SPUIDefinitions.CONFIRMATION_WINDOW); - unsavedActionsWindow.addCloseListener(event -> unsavedActionsWindowClosed()); - unsavedActionsWindow.setContent(getUnsavedActionsWindowContent()); - unsavedActionsWindow.setId(SPUIComponetIdProvider.CONFIRMATION_POPUP_ID); - UI.getCurrent().addWindow(unsavedActionsWindow); + if (!hasUnsavedActions()) { + return; } + unsavedActionsWindow = SPUIComponentProvider.getWindow(getUnsavedActionsWindowCaption(), + SPUIComponetIdProvider.SAVE_ACTIONS_POPUP, SPUIDefinitions.CONFIRMATION_WINDOW); + unsavedActionsWindow.addCloseListener(event -> unsavedActionsWindowClosed()); + unsavedActionsWindow.setContent(getUnsavedActionsWindowContent()); + unsavedActionsWindow.setId(SPUIComponetIdProvider.CONFIRMATION_POPUP_ID); + UI.getCurrent().addWindow(unsavedActionsWindow); } /** @@ -225,22 +230,11 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme UI.getCurrent().removeWindow(unsavedActionsWindow); } - /* - * (non-Javadoc) - * - * @see com.vaadin.event.dd.DropHandler#getAcceptCriterion() - */ @Override public AcceptCriterion getAcceptCriterion() { return getDeleteLayoutAcceptCriteria(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.event.dd.DropHandler#drop(com.vaadin.event.dd. - * DragAndDropEvent) - */ @Override public void drop(final DragAndDropEvent event) { processDroppedComponent(event); @@ -287,6 +281,43 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } } + /** + * Only in deployment view count message is displayed. + * + * @return + */ + protected boolean hasCountMessage() { + return false; + } + + /** + * + * @return the count message label + */ + protected Label getCountMessageLabel() { + return null; + } + + /** + * @return true if bulk upload is allowed and has required create + * permissions. + */ + protected boolean hasBulkUploadPermission() { + // can be overriden + return false; + } + + protected void showBulkUploadWindow() { + // can be overriden + } + + /** + * restore the upload status count. + */ + protected void restoreBulkUploadStatusCount() { + // can be overriden + } + /** * Check user has delete permission. * @@ -362,11 +393,6 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme */ protected abstract void restoreActionCount(); - /** - * restore the upload status count. - */ - protected abstract void restoreBulkUploadStatusCount(); - /** * This method will be called when unsaved actions window is closed. */ @@ -387,21 +413,4 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme */ protected abstract boolean hasUnsavedActions(); - /** - * Only in deployment view count message is displayed. - * - * @return - */ - protected abstract boolean hasCountMessage(); - - protected abstract Label getCountMessageLabel(); - - /** - * @return true if bulk upload is allowed and has required create - * permissions. - */ - protected abstract boolean hasBulkUploadPermission(); - - protected abstract void showBulkUploadWindow(); - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index ae6811ddb..c9487d467 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -9,29 +9,59 @@ package org.eclipse.hawkbit.ui.common.table; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; +import com.google.gwt.thirdparty.guava.common.collect.Iterables; import com.vaadin.data.Container; +import com.vaadin.data.Item; import com.vaadin.event.dd.DropHandler; import com.vaadin.ui.Table; +import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** - * Parent class for table. - * - * + * Abstract table to handling entity * + * @param + * e is the entity class + * @param + * i is the id of the table */ -public abstract class AbstractTable extends Table { +public abstract class AbstractTable extends Table { private static final long serialVersionUID = 4856562746502217630L; + private static final Logger LOG = LoggerFactory.getLogger(AbstractTable.class); + + @Autowired + protected transient EventBus.SessionEventBus eventBus; + + @Autowired + protected I18N i18n; + /** * Initialize the components. */ + @PostConstruct protected void init() { setStyleName("sp-table"); setSizeFull(); @@ -48,6 +78,52 @@ public abstract class AbstractTable extends Table { addValueChangeListener(event -> onValueChange()); selectRow(); setPageLength(SPUIDefinitions.PAGE_SIZE); + + setDataAvailable(getContainerDataSource().size() != 0); + eventBus.subscribe(this); + } + + @PreDestroy + protected void destroy() { + eventBus.unsubscribe(this); + } + + public static Set getTableValue(final Table table) { + @SuppressWarnings("unchecked") + Set values = (Set) table.getValue(); + if (values == null) { + values = Collections.emptySet(); + } + if (values.remove(null)) { + LOG.warn("Null values in table content. How could this happen?"); + } + return values; + } + + private void onValueChange() { + eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); + + // TODO Einzelwerte? + + final Set values = getTableValue(this); + + E entity = null; + + final I lastId = Iterables.getLast(values); + if (lastId != null) { + entity = findEntityByTableValue(lastId); + } + setManagementEntitiyStateValues(values, lastId); + publishEntityAfterValueChange(entity); + } + + protected void setManagementEntitiyStateValues(final Set values, final I lastId) { + final ManagmentEntityState managmentEntityState = getManagmentEntityState(); + if (managmentEntityState == null) { + return; + } + managmentEntityState.setLastSelectedEntity(lastId); + managmentEntityState.setSelectedEnitities(values); } private void setDefault() { @@ -118,6 +194,51 @@ public abstract class AbstractTable extends Table { selectRow(); } + /** + * Add new software module to table. + * + * @param baseEntity + * new software module + */ + protected Item addEntity(final E baseEntity) { + final Object addItem = addItem(); + final Item item = getItem(addItem); + updateEntity(baseEntity, item); + return item; + } + + @SuppressWarnings("unchecked") + protected void updateEntity(final E baseEntity, final Item item) { + item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(baseEntity.getName()); + item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(baseEntity.getDescription()); + item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) + .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getCreatedBy())); + item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) + .setValue(HawkbitCommonUtil.getIMUser(baseEntity.getLastModifiedBy())); + item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) + .setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getCreatedAt())); + item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) + .setValue(SPDateTimeUtil.getFormattedDate(baseEntity.getLastModifiedAt())); + + } + + protected void onBaseEntityEvent(final BaseEntityEvent event) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { + UI.getCurrent().access(() -> applyMinTableSettings()); + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { + UI.getCurrent().access(() -> applyMaxTableSettings()); + } else if (BaseEntityEventType.NEW_ENTITY == event.getEventType()) { + UI.getCurrent().access(() -> addEntity(event.getEntity())); + } + } + + protected abstract E findEntityByTableValue(I lastSelectedId); + + protected abstract void publishEntityAfterValueChange(E selectedLastEntity); + + protected abstract ManagmentEntityState getManagmentEntityState(); + /** * Get Id of the table. * @@ -141,7 +262,9 @@ public abstract class AbstractTable extends Table { /** * Add any generated columns if required. */ - protected abstract void addCustomGeneratedColumns(); + protected void addCustomGeneratedColumns() { + // can be overriden + } /** * Check if first row should be selected by default on load. @@ -157,11 +280,6 @@ public abstract class AbstractTable extends Table { */ protected abstract Object getItemIdToSelect(); - /** - * On select of row. - */ - protected abstract void onValueChange(); - /** * Check if the table is maximized or minimized. * @@ -174,7 +292,23 @@ public abstract class AbstractTable extends Table { * * @return List list of visible columns */ - protected abstract List getTableVisibleColumns(); + protected List getTableVisibleColumns() { + final List columnList = new ArrayList<>(); + if (isMaximized()) { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); + columnList + .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), + 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + } + return columnList; + } /** * Get drop handler for the table. @@ -183,4 +317,6 @@ public abstract class AbstractTable extends Table { */ protected abstract DropHandler getTableDropHandler(); + protected abstract void setDataAvailable(boolean available); + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java new file mode 100644 index 000000000..b0b7551ac --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java @@ -0,0 +1,44 @@ +/** + * 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.common.table; + +import org.eclipse.hawkbit.repository.model.BaseEntity; + +/** + * Event to represent add, update or delete. + * + */ +public class BaseEntityEvent { + + private final BaseEntityEventType eventType; + + private final T entity; + + /** + * Base entity event + * + * @param eventType + * the event type + * @param entity + * the entity reference + */ + public BaseEntityEvent(final BaseEntityEventType eventType, final T entity) { + this.eventType = eventType; + this.entity = entity; + } + + public T getEntity() { + return entity; + } + + public BaseEntityEventType getEventType() { + return eventType; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java new file mode 100644 index 000000000..bfaf593fb --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java @@ -0,0 +1,17 @@ +/** + * 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.common.table; + +/** + * + * + */ +public enum BaseEntityEventType { + NEW_ENTITY, UPDATED_ENTITY, DELETE_ENTITY, SELECTED_ENTITY, MAXIMIZED, MINIMIZED; +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index 4404e1f8a..30aeba925 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -17,6 +17,9 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -35,6 +38,7 @@ import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.combobox.FilteringMode; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** @@ -44,7 +48,7 @@ import com.vaadin.ui.themes.ValoTheme; * * */ -public abstract class AbstractTagToken implements Serializable { +public abstract class AbstractTagToken implements Serializable { private static final String COLOR_PROPERTY = "color"; @@ -59,7 +63,7 @@ public abstract class AbstractTagToken implements Serializable { protected final Map tokensAdded = new HashMap<>(); protected CssLayout tokenLayout = new CssLayout(); - + @Autowired protected SpPermissionChecker checker; @@ -71,23 +75,37 @@ public abstract class AbstractTagToken implements Serializable { @Autowired protected transient EventBus.SessionEventBus eventBus; - + @Autowired protected ManagementUIState managementUIState; + protected T selectedEntity; + @PostConstruct protected void init() { createTokenField(); checkIfTagAssignedIsAllowed(); eventBus.subscribe(this); } - @PreDestroy - void destroy() { + protected void destroy() { eventBus.unsubscribe(this); } + protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + if (BaseEntityEventType.SELECTED_ENTITY != baseEntityEvent.getEventType()) { + return; + } + UI.getCurrent().access(() -> { + final T entity = baseEntityEvent.getEntity(); + if (entity != null) { + selectedEntity = entity; + repopulateToken(); + } + }); + } + private void createTokenField() { final Container tokenContainer = createContainer(); tokenField = createTokenField(tokenContainer); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index c38a97228..ce9f101f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -19,15 +20,13 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; /** * Abstract class for target tag token layout. */ -public abstract class AbstractTargetTagToken extends AbstractTagToken { +public abstract class AbstractTargetTagToken extends AbstractTagToken { private static final long serialVersionUID = 7772876588903171201L; @Autowired protected transient TagManagement tagManagement; - - @EventBusListenerMethod(scope = EventScope.SESSION) void onEventTargetTagCreated(final TargetTagCreatedBulkEvent event) { for (final TargetTag tag : event.getEntities()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 9a245229b..178610c23 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -14,8 +14,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; @@ -26,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +33,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Item; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.UI; /** * Implementation of target/ds tag token layout. @@ -44,7 +40,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTagToken extends AbstractTagToken { +public class DistributionTagToken extends AbstractTagToken { private static final long serialVersionUID = -8022738301736043396L; @Autowired @@ -53,8 +49,6 @@ public class DistributionTagToken extends AbstractTagToken { @Autowired private transient DistributionSetManagement distributionSetManagement; - private DistributionSet selectedDS; - // To Be Done : have to set this value based on view??? private static final Boolean NOTAGS_SELECTED = Boolean.FALSE; @@ -82,9 +76,9 @@ public class DistributionTagToken extends AbstractTagToken { private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set distributionList = new HashSet<>(); - distributionList.add(selectedDS.getId()); - final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, - tagNameSelected); + distributionList.add(selectedEntity.getId()); + final DistributionSetTagAssignmentResult result = distributionSetManagement + .toggleTagAssignment(distributionList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -117,8 +111,8 @@ public class DistributionTagToken extends AbstractTagToken { @Override public void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); - if (selectedDS != null) { - for (final DistributionSetTag tag : selectedDS.getTags()) { + if (selectedEntity != null) { + for (final DistributionSetTag tag : selectedEntity.getTags()) { addNewToken(tag.getId()); } } @@ -134,15 +128,7 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() != DistributionComponentEvent.ON_VALUE_CHANGE) { - return; - } - UI.getCurrent().access(() -> { - if (distributionTableEvent.getDistributionSet() != null) { - selectedDS = distributionTableEvent.getDistributionSet(); - repopulateToken(); - } - }); + onBaseEntityEvent(distributionTableEvent); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -202,10 +188,4 @@ public class DistributionTagToken extends AbstractTagToken { return false; } - @Override - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 376e7d905..6f03c5860 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +31,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Item; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.UI; /** * Implementation of Target tag token. @@ -41,7 +39,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class TargetTagToken extends AbstractTargetTagToken { +public class TargetTagToken extends AbstractTargetTagToken { private static final long serialVersionUID = 7124887018280196721L; @@ -54,8 +52,6 @@ public class TargetTagToken extends AbstractTargetTagToken { @Autowired private transient TargetManagement targetManagement; - private Target selectedTarget; - @Override protected String getTagStyleName() { return "target-tag-"; @@ -80,7 +76,7 @@ public class TargetTagToken extends AbstractTargetTagToken { private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final Set targetList = new HashSet<>(); - targetList.add(selectedTarget.getControllerId()); + targetList.add(selectedEntity.getControllerId()); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; @@ -114,8 +110,8 @@ public class TargetTagToken extends AbstractTargetTagToken { @Override protected void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); - if (selectedTarget != null) { - for (final TargetTag tag : selectedTarget.getTags()) { + if (selectedEntity != null) { + for (final TargetTag tag : selectedEntity.getTags()) { addNewToken(tag.getId()); } } @@ -174,13 +170,7 @@ public class TargetTagToken extends AbstractTargetTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetTableEvent) { - if (targetTableEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET - && targetTableEvent.getTarget() != null) { - UI.getCurrent().access(() -> { - selectedTarget = targetTableEvent.getTarget(); - repopulateToken(); - }); - } + onBaseEntityEvent(targetTableEvent); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java index 451a16ea7..ab41bc579 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java @@ -13,7 +13,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.disttype.DSTypeFilterLayout; import org.eclipse.hawkbit.ui.distributions.dstable.DistributionSetTableLayout; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; @@ -22,7 +22,6 @@ import org.eclipse.hawkbit.ui.distributions.smtable.SwModuleTableLayout; import org.eclipse.hawkbit.ui.distributions.smtype.DistSMTypeFilterLayout; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; @@ -160,18 +159,18 @@ public class DistributionsView extends VerticalLayout implements View, BrowserWi @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeDistTable(); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeDistTable(); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeSwTable(); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeSwTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 02916ae7c..64a9819bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -21,7 +21,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -31,7 +31,6 @@ import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleAssignmentDiscar import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -58,7 +57,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class DistributionSetDetails extends AbstractTableDetailsLayout { +public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -4595004466943546669L; @@ -85,10 +84,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { private VerticalLayout tagsLayout; - private DistributionSet selectedDsModule; - - private Long dsId; - Map assignedSWModule = new HashMap<>(); /** @@ -106,28 +101,15 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return tagsLayout; } - private void populateDetailsWidget(final DistributionSet ds) { - if (ds != null) { - setDsId(ds.getId()); - setName(getDefaultCaption(), HawkbitCommonUtil.getFormattedNameVersion(ds.getName(), ds.getVersion())); - populateDetails(ds); - populateDescription(ds); - populateLog(ds); - populteModule(ds); - populateTags(ds); - } else { - setDsId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populteModule(null); - populateTags(null); - populateLog(null); - } + @Override + protected void populateDetailsWidget() { + populateDetails(); + populateModule(); + populateTags(); } - private void populteModule(final DistributionSet distributionSet) { - softwareModuleTable.populateModule(distributionSet); + private void populateModule() { + softwareModuleTable.populateModule(selectedBaseEntity); showUnsavedAssignment(); } @@ -159,7 +141,7 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { assignedSWModule.put(softwareModule.getType().getName(), new StringBuilder().append("").append( getUnsavedAssigedSwModule(softwareModule.getName(), softwareModule.getVersion())) - .append("")); + .append("")); } } @@ -243,38 +225,22 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return softwareLayout; } - private void populateTags(final DistributionSet ds) { + private void populateTags() { tagsLayout.removeAllComponents(); - if (null != ds) { + if (null != selectedBaseEntity) { tagsLayout.addComponent(distributionTagToken.getTokenField()); } } - private void populateLog(final DistributionSet ds) { - if (null != ds) { - updateLogLayout(getLogLayout(), ds.getLastModifiedAt(), ds.getLastModifiedBy(), ds.getCreatedAt(), - ds.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - private void populateDetails(final DistributionSet ds) { - if (ds != null) { - updateDistributionSetDetailsLayout(ds.getType().getName(), ds.isRequiredMigrationStep()); + private void populateDetails() { + if (selectedBaseEntity != null) { + updateDistributionSetDetailsLayout(selectedBaseEntity.getType().getName(), + selectedBaseEntity.isRequiredMigrationStep()); } else { updateDistributionSetDetailsLayout(null, null); } } - private void populateDescription(final DistributionSet ds) { - if (ds != null) { - updateDescriptionLayout(i18n.get("label.description"), ds.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateDistributionSetDetailsLayout(final String type, final Boolean isMigrationRequired) { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); @@ -293,18 +259,10 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { } } - public Long getDsId() { - return dsId; - } - - public void setDsId(final Long dsId) { - this.dsId = dsId; - } - @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); - distributionAddUpdateWindowLayout.populateValuesOfDistribution(getDsId()); + distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); newDistWindow.setCaption(i18n.get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); @@ -326,11 +284,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { return manageDistUIState.isDsTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedDsModule); - } - @Override protected String getDefaultCaption() { return i18n.get("distribution.details.header"); @@ -345,11 +298,6 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); } - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -358,59 +306,40 @@ public class DistributionSetDetails extends AbstractTableDetailsLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.ASSIGN_SOFTWARE_MODULE) { - ui.access(() -> updateSoftwareModule(event.getSoftwareModule())); + UI.getCurrent().access(() -> updateSoftwareModule(event.getEntity())); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE - || distributionTableEvent - .getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - assignedSWModule.clear(); - ui.access(() -> { - /** - * distributionTableEvent.getDistributionSet() is null when - * table has no data. - */ - if (distributionTableEvent.getDistributionSet() != null) { - selectedDsModule = distributionTableEvent.getDistributionSet(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - ui.access(() -> showLayout()); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - ui.access(() -> hideLayout()); - } + onBaseEntityEvent(distributionTableEvent); } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleAssignmentDiscardEvent softwareModuleAssignmentDiscardEvent) { if (softwareModuleAssignmentDiscardEvent.getDistributionSetIdName() != null) { - ui.access(() -> { + UI.getCurrent().access(() -> { final DistributionSetIdName distIdName = softwareModuleAssignmentDiscardEvent .getDistributionSetIdName(); - if (distIdName.getId().equals(selectedDsModule.getId()) - && distIdName.getName().equals(selectedDsModule.getName())) { - selectedDsModule = distributionSetManagement - .findDistributionSetByIdWithDetails(selectedDsModule.getId()); - populteModule(selectedDsModule); + if (distIdName.getId().equals(getSelectedBaseEntityId()) + && distIdName.getName().equals(selectedBaseEntity.getName())) { + selectedBaseEntity = distributionSetManagement + .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + populateModule(); } }); } } - + @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS || saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS) - && selectedDsModule != null) { + && selectedBaseEntity != null) { assignedSWModule.clear(); - selectedDsModule = distributionSetManagement.findDistributionSetByIdWithDetails(selectedDsModule.getId()); - ui.access(() -> populteModule(selectedDsModule)); + selectedBaseEntity = distributionSetManagement + .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + UI.getCurrent().access(() -> populateModule()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 8d22f6782..51f30117a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -12,15 +12,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; @@ -33,17 +29,15 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -56,7 +50,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -77,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionSetTable extends AbstractTable { +public class DistributionSetTable extends AbstractTable { private static final long serialVersionUID = -7731776093470487988L; @@ -86,18 +79,12 @@ public class DistributionSetTable extends AbstractTable { private static final List DISPLAY_DROP_HINT_EVENTS = new ArrayList<>( Arrays.asList(DragEvent.SOFTWAREMODULE_DRAG)); - @Autowired - private I18N i18n; - @Autowired private SpPermissionChecker permissionChecker; @Autowired private ManageDistUIState manageDistUIState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient DistributionSetManagement distributionSetManagement; @@ -117,12 +104,9 @@ public class DistributionSetTable extends AbstractTable { * Initialize the component. */ @Override - @PostConstruct protected void init() { super.init(); addTableStyleGenerator(); - setNoDataAvailable(); - eventBus.subscribe(this); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -171,13 +155,6 @@ public class DistributionSetTable extends AbstractTable { Boolean.class, null, false, true); } - @Override - protected void addCustomGeneratedColumns() { - /** - * No generated columns. - */ - } - @Override protected boolean isFirstRowSelectedOnLoad() { return !manageDistUIState.getSelectedDistributions().isPresent() @@ -193,37 +170,19 @@ public class DistributionSetTable extends AbstractTable { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - DistributionSetIdName value = null; - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); + protected DistributionSet findEntityByTableValue(final DistributionSetIdName entityTableId) { + return distributionSetManagement.findDistributionSetByIdWithDetails(entityTableId.getId()); + } - while (iterator.hasNext()) { - value = iterator.next(); - } - /** - * Adding null check to make to avoid NPE.Its weird that at times - * getValue returns null. - */ - if (null != value) { - manageDistUIState.setSelectedDistributions(values); - manageDistUIState.setLastSelectedDistribution(value); + @Override + protected ManageDistUIState getManagmentEntityState() { + return manageDistUIState; + } - final DistributionSet lastSelectedDistSet = distributionSetManagement - .findDistributionSetByIdWithDetails(value.getId()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, lastSelectedDistSet)); - } - } else { - manageDistUIState.setSelectedDistributions(null); - manageDistUIState.setLastSelectedDistribution(null); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, null)); - } + @Override + protected void publishEntityAfterValueChange(final DistributionSet distributionSet) { + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, distributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); - } @Override @@ -233,7 +192,13 @@ public class DistributionSetTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - return HawkbitCommonUtil.getTableVisibleColumns(isMaximized(), false, i18n); + final List columnList = super.getTableVisibleColumns(); + if (isMaximized()) { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); + } + return columnList; } @Override @@ -331,10 +296,6 @@ public class DistributionSetTable extends AbstractTable { updateDropedDetails(distributionSetIdName, softwareModules); } - /** - * @param distId - * @param softwareModule - */ private void publishAssignEvent(final Long distId, final SoftwareModule softwareModule) { if (manageDistUIState.getLastSelectedDistribution().isPresent() && manageDistUIState.getLastSelectedDistribution().get().getId().equals(distId)) { @@ -343,11 +304,6 @@ public class DistributionSetTable extends AbstractTable { } } - /** - * @param map - * @param softwareModule - * @param softwareModuleIdName - */ private void handleFirmwareCase(final Map> map, final SoftwareModule softwareModule, final SoftwareModuleIdName softwareModuleIdName) { if (softwareModule.getType().getMaxAssignments() == 1) { @@ -361,11 +317,6 @@ public class DistributionSetTable extends AbstractTable { } } - /** - * @param map - * @param softwareModule - * @param softwareModuleIdName - */ private void handleSoftwareCase(final Map> map, final SoftwareModule softwareModule, final SoftwareModuleIdName softwareModuleIdName) { if (softwareModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { @@ -475,37 +426,6 @@ public class DistributionSetTable extends AbstractTable { return true; } - /** - * Add new software module to table. - * - * @param swModule - * new software module - */ - @SuppressWarnings("unchecked") - private void addDistributionSet(final DistributionSet distributionSet) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(distributionSet.getName()); - item.getItemProperty(SPUILabelDefinitions.DIST_ID).setValue(distributionSet.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(distributionSet.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(distributionSet.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(distributionSet.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) - .setValue(HawkbitCommonUtil.getIMUser(distributionSet.getCreatedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(distributionSet.getLastModifiedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_IS_DISTRIBUTION_COMPLETE).setValue(distributionSet.isComplete()); - if (manageDistUIState.getSelectedDistributions().isPresent()) { - manageDistUIState.getSelectedDistributions().get().stream().forEach(dsNameId -> unselect(dsNameId)); - } - select(distributionSet.getDistributionSetIdName()); - } - private void addTableStyleGenerator() { setCellStyleGenerator((source, itemId, propertyId) -> { if (propertyId == null) { @@ -525,13 +445,7 @@ public class DistributionSetTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.ADD_DISTRIBUTION) { - UI.getCurrent().access(() -> addDistributionSet(event.getDistributionSet())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -556,21 +470,25 @@ public class DistributionSetTable extends AbstractTable { } } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); + @Override + @SuppressWarnings("unchecked") + protected Item addEntity(final DistributionSet baseEntity) { + final Item item = super.addEntity(baseEntity); + item.getItemProperty(SPUILabelDefinitions.DIST_ID).setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_IS_DISTRIBUTION_COMPLETE).setValue(baseEntity.isComplete()); + + if (manageDistUIState.getSelectedDistributions().isPresent()) { + manageDistUIState.getSelectedDistributions().get().stream().forEach(dsNameId -> unselect(dsNameId)); + } + select(baseEntity.getDistributionSetIdName()); + return item; } - private void setNoDataAvailable() { - final int containerSize = getContainerDataSource().size(); - if (containerSize == 0) { - manageDistUIState.setNoDataAvailableDist(true); - } else { - manageDistUIState.setNoDataAvailableDist(false); - } + @Override + protected void setDataAvailable(final boolean available) { + manageDistUIState.setNoDataAvailableDist(!available); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java index 6ac4a1007..a42563505 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableHeader.java @@ -9,12 +9,12 @@ package org.eclipse.hawkbit.ui.distributions.dstable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -125,13 +125,13 @@ public class DistributionSetTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { manageDistUIstate.setDsTableMaximized(Boolean.TRUE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MAXIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { manageDistUIstate.setDsTableMaximized(Boolean.FALSE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MINIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index 8b7d2ada0..ea33a2ea3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -37,7 +37,6 @@ import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Component; -import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.Table.TableTransferable; import com.vaadin.ui.UI; @@ -296,7 +295,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - distConfirmationWindowLayout.init(); + distConfirmationWindowLayout.inittialize(); return distConfirmationWindowLayout; } @@ -316,35 +315,6 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { return unSavedActionsTables || unSavedActionsTypes; } - @Override - protected boolean hasCountMessage() { - return false; - } - - @Override - protected Label getCountMessageLabel() { - return null; - } - - @Override - protected boolean hasBulkUploadPermission() { - return false; - } - - @Override - protected void showBulkUploadWindow() { - /** - * Bulk upload not supported No implementation required. - */ - } - - @Override - protected void restoreBulkUploadStatusCount() { - /** - * No implementation required.As no bulk upload in Distribution view. - */ - } - private DistributionSetType getCurrentDistributionSetType() { return systemManagement.getTenantMetadata().getDefaultDsType(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java index 2299054f3..a97c5786d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.footer; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -17,8 +16,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -32,13 +29,11 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -48,6 +43,7 @@ import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; import com.vaadin.ui.themes.ValoTheme; @@ -83,12 +79,6 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW private ConfirmationTab assignmnetTab; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient DistributionSetManagement dsManagement; @@ -98,20 +88,6 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW @Autowired private ManageDistUIState manageDistUIState; - /** - * Initialze the component. - */ - @PostConstruct - public void init() { - super.inittialize(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.confirmwindow.layout. - * AbstractConfirmationWindowLayout# getConfimrationTabs() - */ @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -161,26 +137,13 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW /* Add the discard action column */ tab.getTable().addGeneratedColumn(SW_DISCARD_CHGS, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardSoftwareDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardSoftwareDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_NAME_MSG); - visibleColumnIds.add(SW_DISCARD_CHGS); - visibleColumnLabels.add(i18n.get("upload.swModuleTable.header")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_NAME_MSG, SW_DISCARD_CHGS); + tab.getTable().setColumnHeaders(i18n.get("upload.swModuleTable.header"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_NAME_MSG, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -295,18 +258,9 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW return deleteIcon; }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(SW_MODULE_TYPE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.swmodule.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.swmodule.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(SW_MODULE_TYPE_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.swmodule.type.table"), + i18n.get("header.second.delete.swmodule.type.table")); tab.getTable().setColumnExpandRatio(SW_MODULE_TYPE_NAME, 2); tab.getTable().setColumnExpandRatio(SW_DISCARD_CHGS, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -383,26 +337,14 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final Button deleteswIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deleteswIcon.setData(itemId); - deleteswIcon.setImmediate(true); - deleteswIcon.addClickListener(event -> discardDistDelete(event, itemId, tab)); - return deleteswIcon; + final ClickListener clickListener = event -> discardDistDelete(event, itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.one.deletedist.table")); - visibleColumnLabels.add(i18n.get("header.second.deletedist.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DIST_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.one.deletedist.table"), + i18n.get("header.second.deletedist.table")); tab.getTable().setColumnExpandRatio(DIST_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -495,30 +437,15 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW // Add the discard action column tab.getTable().addGeneratedColumn(DISCARD, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append(SPUIStyleDefinitions.REDICON); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener( - event -> discardDistTypeDelete((String) ((Button) event.getComponent()).getData(), itemId, tab)); - return deleteIcon; + final ClickListener clickListener = event -> discardDistTypeDelete( + (String) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_SET_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.first.delete.dist.type.table")); - visibleColumnLabels.add(i18n.get("header.second.delete.dist.type.table")); - - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DIST_SET_NAME, DISCARD); + tab.getTable().setColumnHeaders(i18n.get("header.first.delete.dist.type.table"), + i18n.get("header.second.delete.dist.type.table")); tab.getTable().setColumnExpandRatio(DIST_SET_NAME, 2); tab.getTable().setColumnExpandRatio(DISCARD, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -610,20 +537,9 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW return deleteIcon; }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DIST_NAME); - visibleColumnIds.add(SOFTWARE_MODULE_NAME); - visibleColumnIds.add(DISCARD); - visibleColumnLabels.add(i18n.get("header.dist.first.assignment.table")); - visibleColumnLabels.add(i18n.get("header.dist.second.assignment.table")); - visibleColumnLabels.add(i18n.get("header.third.assignment.table")); - - } - assignmnetTab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - assignmnetTab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + assignmnetTab.getTable().setVisibleColumns(DIST_NAME, SOFTWARE_MODULE_NAME, DISCARD); + assignmnetTab.getTable().setColumnHeaders(i18n.get("header.dist.first.assignment.table"), + i18n.get("header.dist.second.assignment.table"), i18n.get("header.third.assignment.table")); assignmnetTab.getTable().setColumnExpandRatio(DIST_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(SOFTWARE_MODULE_NAME, 2); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index 7aa7d6f31..e1c39ee89 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -10,9 +10,8 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -36,7 +35,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleDetails extends AbstractTableDetailsLayout { +public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = -1052279281066089812L; @@ -46,37 +45,15 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { @Autowired private ManageDistUIState manageDistUIState; - private Long swModuleId; - - private SoftwareModule selectedSwModule; - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent softwareModuleEvent) { - if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE - || softwareModuleEvent - .getSoftwareModuleEventType() == SoftwareModuleEventType.UPDATED_SOFTWARE_MODULE) { - ui.access(() -> { - /** - * softwareModuleEvent.getSoftwareModule() is null when table - * has no data. - */ - if (softwareModuleEvent.getSoftwareModule() != null) { - selectedSwModule = softwareModuleEvent.getSoftwareModule(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - showLayout(); - } else if (softwareModuleEvent.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - hideLayout(); - } + onBaseEntityEvent(softwareModuleEvent); } @Override protected void onEdit(final ClickEvent event) { - final Window addSoftwareModule = softwareModuleAddUpdateWindow.createUpdateSoftwareModuleWindow(swModuleId); + final Window addSoftwareModule = softwareModuleAddUpdateWindow + .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); @@ -109,16 +86,6 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { return manageDistUIState.isSwModuleTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedSwModule); - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -129,29 +96,22 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { return null; } - private void populateDetails(final SoftwareModule swModule) { + private void populateDetails() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (swModule != null) { - if (swModule.getType().getMaxAssignments() == Integer.MAX_VALUE) { + if (selectedBaseEntity != null) { + if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { maxAssign = i18n.get("label.multiAssign.type"); } else { maxAssign = i18n.get("label.singleAssign.type"); } - updateSwModuleDetailsLayout(swModule.getType().getName(), swModule.getVendor(), maxAssign); + updateSwModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), + maxAssign); } else { updateSwModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); } } - private void populateDescription(final SoftwareModule sw) { - if (sw != null) { - updateDescriptionLayout(i18n.get("label.description"), sw.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateSwModuleDetailsLayout(final String type, final String vendor, final String maxAssign) { final VerticalLayout detailsTabLayout = getDetailsLayout(); @@ -176,34 +136,9 @@ public class SwModuleDetails extends AbstractTableDetailsLayout { } - private void populateLog(final SoftwareModule softwareModule) { - if (null != softwareModule) { - updateLogLayout(getLogLayout(), softwareModule.getLastModifiedAt(), softwareModule.getLastModifiedBy(), - softwareModule.getCreatedAt(), softwareModule.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } - } - - public void setSwModuleId(final Long swModuleId) { - this.swModuleId = swModuleId; - } - - private void populateDetailsWidget(final SoftwareModule swModule) { - if (swModule != null) { - setSwModuleId(swModule.getId()); - setName(getDefaultCaption(), - HawkbitCommonUtil.getFormattedNameVersion(swModule.getName(), swModule.getVersion())); - populateDetails(swModule); - populateDescription(swModule); - populateLog(swModule); - } else { - setSwModuleId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - populateLog(null); - } + @Override + protected void populateDetailsWidget() { + populateDetails(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 9218198b9..dac8d2ecf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -9,33 +9,26 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; -import org.eclipse.hawkbit.ui.distributions.event.DragEvent; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -45,7 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -71,19 +63,13 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleTable extends AbstractTable { +public class SwModuleTable extends AbstractTable { private static final long serialVersionUID = 6785314784507424750L; - @Autowired - private I18N i18n; - @Autowired private ManageDistUIState manageDistUIState; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient SoftwareManagement softwareManagement; @@ -97,21 +83,9 @@ public class SwModuleTable extends AbstractTable { * Initialize the filter layout. */ @Override - @PostConstruct protected void init() { super.init(); - eventBus.subscribe(this); styleTableOnDistSelection(); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); } /* All event Listeners */ @@ -148,13 +122,7 @@ public class SwModuleTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SoftwareModuleEvent event) { - if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.NEW_SOFTWARE_MODULE) { - UI.getCurrent().access(() -> addSoftwareModule(event.getSoftwareModule())); - } + onBaseEntityEvent(event); } @Override @@ -237,52 +205,38 @@ public class SwModuleTable extends AbstractTable { return manageDistUIState.isSwModuleTableMaximized(); } - @SuppressWarnings("rawtypes") @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = (Set) getValue(); - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); - Long value = null; - while (iterator.hasNext()) { - value = iterator.next(); - } - if (null != value) { - manageDistUIState.setSelectedBaseSwModuleId(value); - final SoftwareModule baseSoftwareModule = softwareManagement.findSoftwareModuleById(value); - manageDistUIState.setSelectedSoftwareModules(values); - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, baseSoftwareModule)); - } - } else { - manageDistUIState.setSelectedBaseSwModuleId(null); - manageDistUIState.setSelectedSoftwareModules(Collections.emptySet()); - eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.SELECTED_SOFTWARE_MODULE, null)); - } + protected void publishEntityAfterValueChange(final SoftwareModule selectedLastEntity) { + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + + @Override + protected void setManagementEntitiyStateValues(final Set values, final Long lastId) { + manageDistUIState.setSelectedBaseSwModuleId(lastId); + manageDistUIState.setSelectedSoftwareModules(values); + } + + @Override + protected SoftwareModule findEntityByTableValue(final Long lastSelectedId) { + return softwareManagement.findSoftwareModuleById(lastSelectedId); + } + + @Override + protected ManagmentEntityState getManagmentEntityState() { + return null; } @Override protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); + columnList.addAll(super.getTableVisibleColumns()); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); - } return columnList; } @@ -369,30 +323,24 @@ public class SwModuleTable extends AbstractTable { return name + "." + version; } + @Override @SuppressWarnings("unchecked") - private void addSoftwareModule(final SoftwareModule swModule) { - final Object addItem = addItem(); - final Item item = getItem(addItem); - final String swNameVersion = HawkbitCommonUtil.concatStrings(":", swModule.getName(), swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty("swId").setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_ID).setValue(swModule.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(swModule.getDescription()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(swModule.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(swModule.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(swModule.getVendor()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY).setValue(swModule.getCreatedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setValue(swModule.getLastModifiedBy()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(swModule.getLastModifiedAt())); + protected Item addEntity(final SoftwareModule baseEntity) { + final Item item = super.addEntity(baseEntity); + + final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), + baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); + item.getItemProperty("swId").setValue(baseEntity.getId()); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); + item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(baseEntity.getType().getColour()); - item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(swModule.getType().getColour()); if (!manageDistUIState.getSelectedSoftwareModules().isEmpty()) { manageDistUIState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); } - select(swModule.getId()); + select(baseEntity.getId()); + return item; } private void showArtifactDetailsWindow(final Long itemId, final String nameVersionStr) { @@ -431,13 +379,10 @@ public class SwModuleTable extends AbstractTable { UI.getCurrent().addWindow(atrifactDtlsWindow); } - private void setNoDataAvailable() { - final int conatinerSize = getContainerDataSource().size(); - if (conatinerSize == 0) { - manageDistUIState.setNoDataAvilableSwModule(true); - } else { - manageDistUIState.setNoDataAvilableSwModule(false); - } + @Override + protected void setDataAvailable(final boolean available) { + manageDistUIState.setNoDataAvilableSwModule(!available); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java index badbc1492..e02dffa8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java @@ -10,9 +10,9 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -37,7 +37,6 @@ public class SwModuleTableHeader extends AbstractTableHeader { private static final long serialVersionUID = 242961845006626297L; - @Autowired private ManageDistUIState manageDistUIState; @@ -123,14 +122,14 @@ public class SwModuleTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { manageDistUIState.setSwModuleTableMaximized(Boolean.TRUE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MAXIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { manageDistUIState.setSwModuleTableMaximized(Boolean.FALSE); - eventbus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.MINIMIZED, null)); + eventbus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java index ce31f649b..b3475cb8b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -30,7 +31,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @SpringComponent @VaadinSessionScope -public class ManageDistUIState implements Serializable { +public class ManageDistUIState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = -7569047247017742928L; @@ -111,16 +112,13 @@ public class ManageDistUIState implements Serializable { return lastSelectedDistribution == null ? Optional.empty() : Optional.of(lastSelectedDistribution); } - /** - * @param lastSelectedDistribution - * the lastSelectedDistribution to set - */ - public void setLastSelectedDistribution(final DistributionSetIdName lastSelectedDistribution) { - this.lastSelectedDistribution = lastSelectedDistribution; + @Override + public void setLastSelectedEntity(final DistributionSetIdName value) { + this.lastSelectedDistribution = value; } - public void setSelectedDistributions(final Set slectedDistributions) { - selectedDistributions = slectedDistributions; + public void setSelectedEnitities(final java.util.Set values) { + selectedDistributions = values; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java index 9069858aa..e260a3bf4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java @@ -12,6 +12,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.ui.HawkbitUI; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.actionhistory.ActionHistoryComponent; import org.eclipse.hawkbit.ui.management.dstable.DistributionTableLayout; import org.eclipse.hawkbit.ui.management.dstag.DistributionTagLayout; @@ -108,19 +109,18 @@ public class DeploymentView extends VerticalLayout implements View, BrowserWindo @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionTableEvent.DistributionComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeDistTable(); - } else if (event - .getDistributionComponentEvent() == DistributionTableEvent.DistributionComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeDistTable(); } } @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.MINIMIZED) { + if (BaseEntityEventType.MINIMIZED == event.getEventType()) { minimizeTargetTable(); - } else if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.MAXIMIZED) { + } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { maximizeTargetTable(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java index 908c8c18f..25448fbe1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryComponent.java @@ -12,8 +12,8 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; @@ -62,9 +62,9 @@ public class ActionHistoryComponent extends VerticalLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetUIEvent) { - if (targetUIEvent.getTargetComponentEvent() == TargetComponentEvent.SELECTED_TARGET) { + if (BaseEntityEventType.SELECTED_ENTITY == targetUIEvent.getEventType()) { setData(SPUIDefinitions.DATA_AVAILABLE); - UI.getCurrent().access(() -> populateActionHistoryDetails(targetUIEvent.getTarget())); + UI.getCurrent().access(() -> populateActionHistoryDetails(targetUIEvent.getEntity())); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index 3f7b7eee5..834566f7e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -25,11 +25,11 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -855,11 +855,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { } private void updateTargetAndDsTable() { - /* - * Update the target status in the Target table and update the color - * settings for DS in DS table. - */ - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.EDIT_TARGET, target)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, target)); updateDistributionTableStyle(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 9bbc1c05d..80c1b5700 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -23,10 +23,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; @@ -260,8 +260,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success", new Object[] { currentDS.getName(), currentDS.getVersion() })); // update table row+details layout - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.EDIT_DISTRIBUTION, currentDS)); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS)); } catch (final EntityAlreadyExistsException entityAlreadyExistsException) { LOG.error("Update distribution failed {}", entityAlreadyExistsException); notificationMessage.displayValidationError( @@ -307,7 +306,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { /* close the window */ closeThisWindow(); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ADD_DISTRIBUTION, newDist)); + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist)); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index a0de88fda..aedce157e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -9,14 +9,12 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; +import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -36,11 +34,10 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class DistributionDetails extends AbstractTableDetailsLayout { +public class DistributionDetails extends AbstractNamedVersionedEntityTableDetailsLayout { private static final long serialVersionUID = 350360207334118826L; - @Autowired private ManagementUIState managementUIState; @@ -52,10 +49,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { private SoftwareModuleDetailsTable softwareModuleTable; - private Long dsId; - - private DistributionSet selectedDsModule; - @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); @@ -63,29 +56,9 @@ public class DistributionDetails extends AbstractTableDetailsLayout { super.init(); } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent distributionTableEvent) { - if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.ON_VALUE_CHANGE - || distributionTableEvent - .getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - ui.access(() -> { - /** - * distributionTableEvent.getDistributionSet() is null when - * table has no data. - */ - if (distributionTableEvent.getDistributionSet() != null) { - selectedDsModule = distributionTableEvent.getDistributionSet(); - populateData(true); - } else { - populateData(false); - } - }); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - ui.access(() -> showLayout()); - } else if (distributionTableEvent.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - ui.access(() -> hideLayout()); - } + onBaseEntityEvent(distributionTableEvent); } @Override @@ -105,7 +78,7 @@ public class DistributionDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); - distributionAddUpdateWindowLayout.populateValuesOfDistribution(getDsId()); + distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); newDistWindow.setCaption(i18n.get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); @@ -127,16 +100,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return managementUIState.isDsTableMaximized(); } - @Override - protected void populateDetailsWidget() { - populateDetailsWidget(selectedDsModule); - } - - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateDistributionPermission(); @@ -147,31 +110,11 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return SPUIComponetIdProvider.DISTRIBUTION_DETAILS_TABSHEET; } - private void populateDetailsWidget(final DistributionSet dist) { - if (dist != null) { - setDsId(dist.getId()); - setName(getDefaultCaption(), HawkbitCommonUtil.getFormattedNameVersion(dist.getName(), dist.getVersion())); - populateDetails(dist); - populateDescription(dist); - populateLog(dist); - softwareModuleTable.populateModule(dist); - } else { - setDsId(null); - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); - populateDetails(null); - populateDescription(null); - softwareModuleTable.populateModule(null); - populateLog(null); - } - } + @Override + protected void populateDetailsWidget() { + softwareModuleTable.populateModule(selectedBaseEntity); + populateDetails(selectedBaseEntity); - private void populateLog(final DistributionSet ds) { - if (null != ds) { - updateLogLayout(getLogLayout(), ds.getLastModifiedAt(), ds.getLastModifiedBy(), ds.getCreatedAt(), - ds.getCreatedBy(), i18n); - } else { - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - } } private void populateDetails(final DistributionSet ds) { @@ -182,14 +125,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { } } - private void populateDescription(final DistributionSet ds) { - if (ds != null) { - updateDescriptionLayout(i18n.get("label.description"), ds.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } - } - private void updateDistributionDetailsLayout(final String type, final Boolean isMigrationRequired) { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); @@ -221,14 +156,6 @@ public class DistributionDetails extends AbstractTableDetailsLayout { return tagsLayout; } - public Long getDsId() { - return dsId; - } - - public void setDsId(final Long dsId) { - this.dsId = dsId; - } - @Override protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.DISTRIBUTION_DETAILS_HEADER_LABEL_ID; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 6bcfb55ae..5e546b79a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -11,15 +11,12 @@ package org.eclipse.hawkbit.ui.management.dstable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - +import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; @@ -29,9 +26,9 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -40,8 +37,6 @@ import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -52,7 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -76,22 +70,16 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTable extends AbstractTable { +public class DistributionTable extends AbstractTable { private static final long serialVersionUID = -1928335256399519494L; - @Autowired - private I18N i18n; - @Autowired private SpPermissionChecker permissionChecker; @Autowired private UINotification notification; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManagementUIState managementUIState; @@ -111,17 +99,9 @@ public class DistributionTable extends AbstractTable { private Button distributinPinnedBtn; @Override - @PostConstruct protected void init() { super.init(); - eventBus.subscribe(this); notAllowedMsg = i18n.get("message.action.not.allowed"); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } /** @@ -151,13 +131,7 @@ public class DistributionTable extends AbstractTable { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final DistributionTableEvent event) { - if (event.getDistributionComponentEvent() == DistributionComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getDistributionComponentEvent() == DistributionComponentEvent.EDIT_DISTRIBUTION) { - UI.getCurrent().access(() -> updateDistributionInTable(event.getDistributionSet())); - } + onBaseEntityEvent(event); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -272,31 +246,18 @@ public class DistributionTable extends AbstractTable { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - final Set values = HawkbitCommonUtil.getSelectedDSDetails(this); - DistributionSetIdName value = null; - if (values != null && !values.isEmpty()) { - final Iterator iterator = values.iterator(); + protected DistributionSet findEntityByTableValue(final DistributionSetIdName lastSelectedId) { + return distributionSetManagement.findDistributionSetByIdWithDetails(lastSelectedId.getId()); + } - while (iterator.hasNext()) { - value = iterator.next(); - } - - if (null != value) { - managementUIState.setSelectedDsIdName(values); - managementUIState.setLastSelectedDsIdName(value); - final DistributionSet lastSelectedDistSet = distributionSetManagement - .findDistributionSetByIdWithDetails(value.getId()); - eventBus.publish(this, - new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, lastSelectedDistSet)); - } - } else { - managementUIState.setSelectedDsIdName(null); - managementUIState.setLastSelectedDsIdName(null); - eventBus.publish(this, new DistributionTableEvent(DistributionComponentEvent.ON_VALUE_CHANGE, null)); - } + @Override + protected void publishEntityAfterValueChange(final DistributionSet selectedLastEntity) { + eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + @Override + protected ManagementUIState getManagmentEntityState() { + return managementUIState; } @Override @@ -306,7 +267,16 @@ public class DistributionTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - return HawkbitCommonUtil.getTableVisibleColumns(isMaximized(), true, i18n); + final List columnList = new ArrayList<>(); + if (isMaximized()) { + columnList.addAll(super.getTableVisibleColumns()); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); + } else { + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); + columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); + } + return columnList; } @Override @@ -345,7 +315,7 @@ public class DistributionTable extends AbstractTable { private void assignDsTag(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails(); final Table distTable = (Table) taregtDet.getTarget(); - final Set distsSelected = HawkbitCommonUtil.getSelectedDSDetails(distTable); + final Set distsSelected = getTableValue(distTable); final Set distList = new HashSet<>(); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); @@ -390,7 +360,7 @@ public class DistributionTable extends AbstractTable { private void assignTargetToDs(final DragAndDropEvent event) { final TableTransferable transferable = (TableTransferable) event.getTransferable(); final Table source = transferable.getSourceComponent(); - final Set targetsSelected = HawkbitCommonUtil.getSelectedTargetDetails(source); + final Set targetsSelected = getTableValue(source); final Set targetDetailsList = new HashSet<>(); if (!targetsSelected.contains(transferable.getData("itemId"))) { @@ -502,17 +472,14 @@ public class DistributionTable extends AbstractTable { private void updateDistributionInTable(final DistributionSet editedDs) { final Item item = getContainerDataSource() .getItem(new DistributionSetIdName(editedDs.getId(), editedDs.getName(), editedDs.getVersion())); - item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(editedDs.getName()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(editedDs.getVersion()); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_BY) - .setValue(HawkbitCommonUtil.getIMUser(editedDs.getCreatedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_CREATED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(editedDs.getCreatedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY) - .setValue(HawkbitCommonUtil.getIMUser(editedDs.getLastModifiedBy())); - item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE) - .setValue(SPDateTimeUtil.getFormattedDate(editedDs.getLastModifiedAt())); - item.getItemProperty(SPUILabelDefinitions.VAR_DESC).setValue(editedDs.getDescription()); + updateEntity(editedDs, item); + + } + + @Override + protected void updateEntity(final DistributionSet baseEntity, final Item item) { + super.updateEntity(baseEntity, item); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); } private void restoreDistributionTableStyle() { @@ -703,12 +670,10 @@ public class DistributionTable extends AbstractTable { this.distributinPinnedBtn = distributinPinnedBtn; } - private void setNoDataAvailable() { - final int size = getContainerDataSource().size(); - if (size == 0) { - managementUIState.setNoDataAvailableDistribution(true); - } else { - managementUIState.setNoDataAvailableDistribution(false); - } + @Override + protected void setDataAvailable(final boolean available) { + managementUIState.setNoDataAvailableDistribution(!available); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java index 6d4343878..2ccbac961 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableHeader.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableFilterEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -127,13 +127,13 @@ public class DistributionTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { managementUIState.setDsTableMaximized(Boolean.TRUE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MAXIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MAXIMIZED, null)); } @Override public void minimizeTable() { managementUIState.setDsTableMaximized(Boolean.FALSE); - eventbus.publish(this, new DistributionTableEvent(DistributionComponentEvent.MINIMIZED, null)); + eventbus.publish(this, new DistributionTableEvent(BaseEntityEventType.MINIMIZED, null)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java index 7690bf109..14eeaf26e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java @@ -9,50 +9,26 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * * * */ -public class DistributionTableEvent { +public class DistributionTableEvent extends BaseEntityEvent { /** - * - * + * Constructor. + * + * @param eventType + * the event type + * @param entity + * the distribution set */ - public enum DistributionComponentEvent { - ADD_DISTRIBUTION, EDIT_DISTRIBUTION, DELETE_DISTRIBUTION, ON_VALUE_CHANGE, MAXIMIZED, MINIMIZED - } - - private DistributionComponentEvent distributionComponentEvent; - - private DistributionSet distributionSet; - - /** - * @param distributionComponentEvent - * @param distributionSet - */ - public DistributionTableEvent(final DistributionComponentEvent distributionComponentEvent, - final DistributionSet distributionSet) { - this.distributionComponentEvent = distributionComponentEvent; - this.distributionSet = distributionSet; - } - - public DistributionComponentEvent getDistributionComponentEvent() { - return distributionComponentEvent; - } - - public void setDistributionComponentEvent(final DistributionComponentEvent distributionComponentEvent) { - this.distributionComponentEvent = distributionComponentEvent; - } - - public DistributionSet getDistributionSet() { - return distributionSet; - } - - public void setDistributionSet(final DistributionSet distributionSet) { - this.distributionSet = distributionSet; + public DistributionTableEvent(final BaseEntityEventType eventType, final DistributionSet entity) { + super(eventType, entity); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java index f1bc5d8ec..cf2661c60 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java @@ -9,7 +9,8 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * @@ -17,34 +18,18 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE * * */ -public class TargetAddUpdateWindowEvent { - - private final TargetComponentEvent targetComponentEvent; - - private final Target target; +public class TargetAddUpdateWindowEvent extends BaseEntityEvent { /** + * Constructor. + * * @param eventType * the event type - * @param target - * the target which has been created or modified + * @param entity + * the entity */ - public TargetAddUpdateWindowEvent(final TargetComponentEvent eventType, final Target target) { - this.targetComponentEvent = eventType; - this.target = target; + public TargetAddUpdateWindowEvent(final BaseEntityEventType eventType, final Target entity) { + super(eventType, entity); } - /** - * @return the targetComponentEvent - */ - public TargetComponentEvent getTargetComponentEvent() { - return targetComponentEvent; - } - - /** - * @return the target - */ - public Target getTarget() { - return target; - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java index 1706361f0..04dd917a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java @@ -9,77 +9,51 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; /** * * * */ -public class TargetTableEvent { +public class TargetTableEvent extends BaseEntityEvent { /** * Target table components events. * */ public enum TargetComponentEvent { - REFRESH_TARGETS, EDIT_TARGET, DELETE_TARGET, SELECTED_TARGET, MAXIMIZED, MINIMIZED, SELLECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED + REFRESH_TARGETS, SELLECT_ALL, BULK_TARGET_CREATED, BULK_UPLOAD_COMPLETED, BULK_TARGET_UPLOAD_STARTED, BULK_UPLOAD_PROCESS_STARTED } private TargetComponentEvent targetComponentEvent; - private Target target; - - private TargetIdName targetIdName; + /** + * Constructor. + * + * @param eventType + * the event type. + * @param entity + * the entity + */ + public TargetTableEvent(final BaseEntityEventType eventType, final Target entity) { + super(eventType, entity); + } /** + * The component event. + * * @param targetComponentEvent + * the target component event. */ public TargetTableEvent(final TargetComponentEvent targetComponentEvent) { - super(); + super(null, null); this.targetComponentEvent = targetComponentEvent; } - /** - * @param targetComponentEvent - * @param target - */ - public TargetTableEvent(final TargetComponentEvent targetComponentEvent, final Target target) { - this(targetComponentEvent); - this.target = target; - } - - /** - * @param targetComponentEvent - * @param targetIdName - */ - public TargetTableEvent(final TargetComponentEvent targetComponentEvent, final TargetIdName targetIdName) { - this(targetComponentEvent); - this.targetIdName = targetIdName; - } - public TargetComponentEvent getTargetComponentEvent() { return targetComponentEvent; } - public void setTargetComponentEvent(final TargetComponentEvent targetComponentEvent) { - this.targetComponentEvent = targetComponentEvent; - } - - public Target getTarget() { - return target; - } - - public void setTarget(final Target target) { - this.target = target; - } - - public TargetIdName getTargetIdName() { - return targetIdName; - } - - public void setTargetIdName(final TargetIdName targetIdName) { - this.targetIdName = targetIdName; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index 7ff9f53e4..ed002defb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -95,8 +95,8 @@ public class CountMessageLabel extends Label { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetTableEvent.TargetComponentEvent.SELLECT_ALL - || event.getTargetComponentEvent() == TargetComponentEvent.REFRESH_TARGETS) { + if (TargetTableEvent.TargetComponentEvent.SELLECT_ALL == event.getTargetComponentEvent() + || TargetComponentEvent.REFRESH_TARGETS == event.getTargetComponentEvent()) { displayTargetCountStatus(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index b8c5494a3..4a95df51a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -15,6 +15,7 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.BulkUploadPopupEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; @@ -211,7 +212,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - manangementConfirmationWindowLayout.init(); + manangementConfirmationWindowLayout.inittialize(); return manangementConfirmationWindowLayout; } @@ -257,7 +258,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addInDeleteDistributionList(final Table sourceTable, final TableTransferable transferable) { - final Set distSelected = HawkbitCommonUtil.getSelectedDSDetails(sourceTable); + final Set distSelected = AbstractTable.getTableValue(sourceTable); final Set distributionIdNameSet = new HashSet<>(); if (!distSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { @@ -311,7 +312,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(sourceTable); + final Set targetSelected = AbstractTable.getTableValue(sourceTable); final Set targetIdNameSet = new HashSet<>(); if (!targetSelected.contains(transferable.getData(SPUIDefinitions.ITEMID))) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index c0f681c7a..56e11a6fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -19,8 +19,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; - import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; @@ -31,20 +29,15 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.ConfirmationTab; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.PinUnpinEvent; import org.eclipse.hawkbit.ui.management.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.management.footer.ActionTypeOptionGroupLayout.ActionTypeOption; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; -import org.vaadin.spring.events.EventBus; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; @@ -52,8 +45,8 @@ import com.vaadin.server.FontAwesome; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table.Align; -import com.vaadin.ui.themes.ValoTheme; /** * Confirmation window for target/ds delete and assignment. @@ -79,12 +72,6 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin @Autowired private ManagementUIState managementUIState; - @Autowired - private I18N i18n; - - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private transient TargetManagement targetManagement; @@ -99,14 +86,6 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin private ConfirmationTab assignmnetTab; - /** - * Initialze the component. - */ - @PostConstruct - public void init() { - super.inittialize(); - } - @Override protected Map getConfimrationTabs() { final Map tabs = new HashMap<>(); @@ -130,6 +109,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin assignmnetTab.getConfirmAll().setIcon(FontAwesome.SAVE); assignmnetTab.getConfirmAll().setCaption(i18n.get("button.assign.all")); assignmnetTab.getConfirmAll().addClickListener(event -> saveAllAssignments(assignmnetTab)); + assignmnetTab.getDiscardAll().setCaption(i18n.get(SPUILabelDefinitions.BUTTON_DISCARD_ALL)); assignmnetTab.getDiscardAll().setId(SPUIComponetIdProvider.DISCARD_ASSIGNMENT); assignmnetTab.getDiscardAll().addClickListener(event -> discardAllAssignments(assignmnetTab)); @@ -139,35 +119,17 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin // Add the discard action column assignmnetTab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final StringBuilder style = new StringBuilder(ValoTheme.BUTTON_TINY); - style.append(' '); - style.append(SPUIStyleDefinitions.REDICON); - final Button deleteIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - style.toString(), true, FontAwesome.REPLY, SPUIButtonStyleSmallNoBorder.class); - deleteIcon.setData(itemId); - deleteIcon.setImmediate(true); - deleteIcon.addClickListener(event -> discardAssignment( - (TargetIdName) ((Button) event.getComponent()).getData(), assignmnetTab)); - return deleteIcon; + final ClickListener clickListener = event -> discardAssignment( + (TargetIdName) ((Button) event.getComponent()).getData(), assignmnetTab); + return createDiscardButton(itemId, clickListener); }); - // set the visible columns - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(TARGET_NAME); - visibleColumnIds.add(DISTRIBUTION_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.first.assignment.table")); - visibleColumnLabels.add(i18n.get("header.second.assignment.table")); - visibleColumnLabels.add(i18n.get("header.third.assignment.table")); - } - assignmnetTab.getTable().setColumnExpandRatio(TARGET_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(DISTRIBUTION_NAME, 2); assignmnetTab.getTable().setColumnExpandRatio(DISCARD_CHANGES, 1); - assignmnetTab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - assignmnetTab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + assignmnetTab.getTable().setVisibleColumns(TARGET_NAME, DISTRIBUTION_NAME, DISCARD_CHANGES); + assignmnetTab.getTable().setColumnHeaders(i18n.get("header.first.assignment.table"), + i18n.get("header.second.assignment.table"), i18n.get("header.third.assignment.table")); assignmnetTab.getTable().setColumnAlignment(DISCARD_CHANGES, Align.CENTER); actionTypeOptionGroupLayout.selectDefaultOption(); @@ -326,27 +288,15 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final Button deletestargetIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deletestargetIcon.setData(itemId); - deletestargetIcon.setImmediate(true); - deletestargetIcon.addClickListener(event -> discardTargetDelete( - (TargetIdName) ((Button) event.getComponent()).getData(), itemId, tab)); - return deletestargetIcon; + final ClickListener clickListener = event -> discardTargetDelete( + (TargetIdName) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); + }); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(TARGET_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.first.deletetarget.table")); - visibleColumnLabels.add(i18n.get("header.second.deletetarget.table")); - } - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(TARGET_NAME, DISCARD_CHANGES); + tab.getTable().setColumnHeaders(i18n.get("header.first.deletetarget.table"), + i18n.get("header.second.deletetarget.table")); tab.getTable().setColumnExpandRatio(TARGET_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD_CHANGES, SPUIDefinitions.DISCARD_COLUMN_WIDTH); @@ -371,30 +321,17 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin /* Add the discard action column */ tab.getTable().addGeneratedColumn(DISCARD_CHANGES, (source, itemId, columnId) -> { - final Button deletesDsIcon = SPUIComponentProvider.getButton("", "", SPUILabelDefinitions.DISCARD, - ValoTheme.BUTTON_TINY + " " + SPUIStyleDefinitions.REDICON, true, FontAwesome.REPLY, - SPUIButtonStyleSmallNoBorder.class); - deletesDsIcon.setData(itemId); - deletesDsIcon.setImmediate(true); - deletesDsIcon.addClickListener(event -> discardDSDelete( - (DistributionSetIdName) ((Button) event.getComponent()).getData(), itemId, tab)); - return deletesDsIcon; - }); + final ClickListener clickListener = event -> discardDSDelete( + (DistributionSetIdName) ((Button) event.getComponent()).getData(), itemId, tab); + return createDiscardButton(itemId, clickListener); - /* set the visible columns */ - final List visibleColumnIds = new ArrayList<>(); - final List visibleColumnLabels = new ArrayList<>(); - if (visibleColumnIds.isEmpty() && visibleColumnLabels.isEmpty()) { - visibleColumnIds.add(DISTRIBUTION_NAME); - visibleColumnIds.add(DISCARD_CHANGES); - visibleColumnLabels.add(i18n.get("header.one.deletedist.table")); - visibleColumnLabels.add(i18n.get("header.second.deletedist.table")); - } + }); tab.getTable().setColumnExpandRatio(DISTRIBUTION_NAME, SPUIDefinitions.TARGET_DISTRIBUTION_COLUMN_WIDTH); tab.getTable().setColumnExpandRatio(DISCARD_CHANGES, SPUIDefinitions.DISCARD_COLUMN_WIDTH); - tab.getTable().setVisibleColumns(visibleColumnIds.toArray()); - tab.getTable().setColumnHeaders(visibleColumnLabels.toArray(new String[0])); + tab.getTable().setVisibleColumns(DISTRIBUTION_NAME, DISCARD_CHANGES); + tab.getTable().setColumnHeaders(i18n.get("header.one.deletedist.table"), + i18n.get("header.second.deletedist.table")); tab.getTable().setColumnAlignment(DISCARD_CHANGES, Align.CENTER); return tab; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java index 3184bf923..73e2ed1a7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -31,7 +32,7 @@ import com.vaadin.spring.annotation.VaadinSessionScope; */ @VaadinSessionScope @SpringComponent -public class ManagementUIState implements Serializable { +public class ManagementUIState implements ManagmentEntityState, Serializable { private static final long serialVersionUID = 7301409196969723794L; @@ -266,12 +267,15 @@ public class ManagementUIState implements Serializable { return lastSelectedDsIdName; } - public void setLastSelectedDsIdName(final DistributionSetIdName lastSelectedDsIdName) { - this.lastSelectedDsIdName = lastSelectedDsIdName; + @Override + public void setLastSelectedEntity(final DistributionSetIdName value) { + this.lastSelectedDsIdName = value; } - public void setSelectedDsIdName(final Set selectedDsIdName) { - this.selectedDsIdName = selectedDsIdName; + @Override + public void setSelectedEnitities(final Set values) { + this.selectedDsIdName = values; + } public Optional> getSelectedDsIdName() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index 48f0ad2bf..973d61857 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -14,11 +14,11 @@ import java.util.Set; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -56,6 +56,8 @@ import com.vaadin.ui.themes.ValoTheme; @SpringComponent @VaadinSessionScope public class TargetAddUpdateWindowLayout extends CustomComponent { + private static final long serialVersionUID = -6659290471705262389L; + @Autowired private I18N i18n; @@ -68,7 +70,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { @Autowired private transient UINotification uINotification; - private static final long serialVersionUID = -6659290471705262389L; private TextField controllerIDTextField; private TextField nameTextField; private TextArea descTextArea; @@ -218,7 +219,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { /* display success msg */ uINotification.displaySuccess(i18n.get("message.update.success", new Object[] { latestTarget.getName() })); // publishing through event bus - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.EDIT_TARGET, latestTarget)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget)); /* close the window */ closeThisWindow(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 87854b22c..6105409bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.common.tagdetails.TargetTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -50,7 +49,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class TargetDetails extends AbstractTableDetailsLayout { +public class TargetDetails extends AbstractTableDetailsLayout { private static final long serialVersionUID = 4571732743399605843L; @@ -63,8 +62,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Autowired private TargetTagToken targetTagToken; - private Target selectedTarget = null; - private VerticalLayout assignedDistLayout; private VerticalLayout installedDistLayout; @@ -112,13 +109,14 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - if (selectedTarget != null) { - final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); - targetAddUpdateWindowLayout.populateValuesOfTarget(selectedTarget.getControllerId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); - UI.getCurrent().addWindow(newDistWindow); - newDistWindow.setVisible(Boolean.TRUE); + if (selectedBaseEntity == null) { + return; } + final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); + targetAddUpdateWindowLayout.populateValuesOfTarget(selectedBaseEntity.getControllerId()); + newDistWindow.setCaption(i18n.get("caption.update.dist")); + UI.getCurrent().addWindow(newDistWindow); + newDistWindow.setVisible(Boolean.TRUE); } @Override @@ -138,50 +136,24 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void populateDetailsWidget() { - if (selectedTarget != null) { - setName(getDefaultCaption(), selectedTarget.getName()); - } - populateDetailsWidget(selectedTarget); - } - - private void populateDetailsWidget(final Target target) { - if (target != null) { - setName(getDefaultCaption(), target.getName()); - updateDetailsLayout(target.getControllerId(), target.getTargetInfo().getAddress(), - target.getSecurityToken(), - SPDateTimeUtil.getFormattedDate(target.getTargetInfo().getLastTargetQuery())); - populateDescription(target); - populateDistributionDtls(installedDistLayout, target.getTargetInfo().getInstalledDistributionSet()); - populateDistributionDtls(assignedDistLayout, target.getAssignedDistributionSet()); - updateLogLayout(getLogLayout(), target.getLastModifiedAt(), target.getLastModifiedBy(), - target.getCreatedAt(), target.getCreatedBy(), i18n); - populateAttributes(target); + if (selectedBaseEntity != null) { + updateDetailsLayout(selectedBaseEntity.getControllerId(), selectedBaseEntity.getTargetInfo().getAddress(), + selectedBaseEntity.getSecurityToken(), + SPDateTimeUtil.getFormattedDate(selectedBaseEntity.getTargetInfo().getLastTargetQuery())); + populateDistributionDtls(installedDistLayout, + selectedBaseEntity.getTargetInfo().getInstalledDistributionSet()); + populateDistributionDtls(assignedDistLayout, selectedBaseEntity.getAssignedDistributionSet()); } else { - setName(getDefaultCaption(), HawkbitCommonUtil.SP_STRING_EMPTY); updateDetailsLayout(null, null, null, null); - populateDescription(null); populateDistributionDtls(installedDistLayout, null); populateDistributionDtls(assignedDistLayout, null); - updateLogLayout(getLogLayout(), null, HawkbitCommonUtil.SP_STRING_EMPTY, null, null, i18n); - populateAttributes(null); } + updateAttributesLayout(selectedBaseEntity); } - private void populateAttributes(final Target target) { - if (target != null) { - - updateAttributesLayout(target); - } else { - updateAttributesLayout(null); - } - } - - private void populateDescription(final Target target) { - if (target != null) { - updateDescriptionLayout(i18n.get("label.description"), target.getDescription()); - } else { - updateDescriptionLayout(i18n.get("label.description"), null); - } + @Override + protected String getName() { + return selectedBaseEntity.getName(); } private void updateDetailsLayout(final String controllerId, final URI address, final String securityToken, @@ -262,11 +234,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { return SPUIComponentProvider.createNameValueLabel(labelName + " : ", swModule.getName(), swModule.getVersion()); } - @Override - protected void clearDetails() { - populateDetailsWidget(null); - } - @Override protected Boolean hasEditPermission() { return permissionChecker.hasUpdateTargetPermission(); @@ -274,25 +241,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent targetTableEvent) { - // Get the event type - final TargetComponentEvent event = targetTableEvent.getTargetComponentEvent(); - - if (event == TargetComponentEvent.SELECTED_TARGET || event == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> { - // If selected or edited, populate the fresh details. - if (targetTableEvent.getTarget() != null) { - selectedTarget = targetTableEvent.getTarget(); - } else { - selectedTarget = null; - } - populateData(selectedTarget != null); - - }); - } else if (event == TargetComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> showLayout()); - } else if (event == TargetComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> hideLayout()); - } + onBaseEntityEvent(targetTableEvent); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 6884e8906..559169f2e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -18,9 +18,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; @@ -34,7 +31,9 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.filter.FilterExpression; import org.eclipse.hawkbit.ui.filter.Filters; import org.eclipse.hawkbit.ui.filter.target.CustomTargetFilter; @@ -53,7 +52,6 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetTableFilters; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -69,7 +67,6 @@ import org.springframework.data.domain.Sort; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; -import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -102,7 +99,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class TargetTable extends AbstractTable implements Handler { +public class TargetTable extends AbstractTable implements Handler { private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); private static final String TARGET_PINNED = "targetPinned"; @@ -116,9 +113,6 @@ public class TargetTable extends AbstractTable implements Handler { @Autowired private transient TargetManagement targetManagement; - @Autowired - private I18N i18n; - @Autowired private ManagementUIState managementUIState; @@ -128,9 +122,6 @@ public class TargetTable extends AbstractTable implements Handler { @Autowired private UINotification notification; - @Autowired - private transient EventBus.SessionEventBus eventBus; - @Autowired private ManagementViewAcceptCriteria managementViewAcceptCriteria; @@ -141,19 +132,11 @@ public class TargetTable extends AbstractTable implements Handler { private ShortcutAction actionUnSelectAll; @Override - @PostConstruct protected void init() { super.init(); addActionHandler(this); actionSelectAll = new ShortcutAction(i18n.get("action.target.table.selectall")); actionUnSelectAll = new ShortcutAction(i18n.get("action.target.table.clear")); - eventBus.subscribe(this); - setNoDataAvailable(); - } - - @PreDestroy - void destroy() { - eventBus.unsubscribe(this); } /** @@ -199,9 +182,10 @@ public class TargetTable extends AbstractTable implements Handler { @EventBusListenerMethod(scope = EventScope.SESSION) void addOrEditEvent(final TargetAddUpdateWindowEvent targetUIEvent) { - if (targetUIEvent.getTargetComponentEvent() == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> updateTarget(targetUIEvent.getTarget())); + if (BaseEntityEventType.UPDATED_ENTITY != targetUIEvent.getEventType()) { + return; } + UI.getCurrent().access(() -> updateTarget(targetUIEvent.getEntity())); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -239,33 +223,14 @@ public class TargetTable extends AbstractTable implements Handler { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final TargetTableEvent event) { - if (event.getTargetComponentEvent() == TargetComponentEvent.MINIMIZED) { - UI.getCurrent().access(() -> applyMinTableSettings()); - } else if (event.getTargetComponentEvent() == TargetComponentEvent.MAXIMIZED) { - UI.getCurrent().access(() -> applyMaxTableSettings()); - } else if (event.getTargetComponentEvent() == TargetComponentEvent.EDIT_TARGET) { - UI.getCurrent().access(() -> updateTarget(event.getTarget())); - } + onBaseEntityEvent(event); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#getTableId() - */ @Override protected String getTableId() { return SPUIComponetIdProvider.TARGET_TABLE_ID; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.ui.common.table.AbstractTable#createContainer( - * ) - */ @Override protected Container createContainer() { // ADD all the filters to the query config @@ -311,12 +276,6 @@ public class TargetTable extends AbstractTable implements Handler { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.common.table.AbstractTable# - * addCustomGeneratedColumns () - */ @Override protected void addCustomGeneratedColumns() { addGeneratedColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, @@ -340,22 +299,24 @@ public class TargetTable extends AbstractTable implements Handler { } @Override - protected void onValueChange() { - eventBus.publish(this, DragEvent.HIDE_DROP_HINT); - @SuppressWarnings("unchecked") - final Set values = HawkbitCommonUtil.getSelectedTargetDetails(this); - if (values != null && !values.isEmpty()) { - final TargetIdName lastSelectedItem = getLastSelectedItem(values); - managementUIState.setSelectedTargetIdName(values); - managementUIState.setLastSelectedTargetIdName(lastSelectedItem); - final Target target = targetManagement - .findTargetByControllerIDWithDetails(lastSelectedItem.getControllerId()); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, target)); - } else { - managementUIState.setSelectedTargetIdName(null); - managementUIState.setLastSelectedTargetIdName(null); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, (Target) null)); - } + protected void publishEntityAfterValueChange(final Target selectedLastEntity) { + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, selectedLastEntity)); + } + + @Override + protected Target findEntityByTableValue(final TargetIdName lastSelectedId) { + return targetManagement.findTargetByControllerIDWithDetails(lastSelectedId.getControllerId()); + } + + @Override + protected void setManagementEntitiyStateValues(final Set values, final TargetIdName lastId) { + managementUIState.setSelectedTargetIdName(values); + managementUIState.setLastSelectedTargetIdName(lastId); + } + + @Override + protected ManagmentEntityState getManagmentEntityState() { + return null; } @Override @@ -365,30 +326,15 @@ public class TargetTable extends AbstractTable implements Handler { @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1f)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8f)); + final List columnList = super.getTableVisibleColumns(); + if (!isMaximized()) { columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0f)); columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0f)); } return columnList; + } - /* - * (non-Javadoc) - * - * @see hawkbit.server.ui.common.table.AbstractTable#getTableDropHandler() - */ @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -630,7 +576,7 @@ public class TargetTable extends AbstractTable implements Handler { private void tagAssignment(final DragAndDropEvent event) { final com.vaadin.event.dd.TargetDetails taregtDet = event.getTargetDetails(); final Table targetTable = (Table) taregtDet.getTarget(); - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(targetTable); + final Set targetSelected = getTableValue(targetTable); final Set targetList = new HashSet<>(); final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails(); final Object targetItemId = dropData.getItemIdOver(); @@ -688,7 +634,7 @@ public class TargetTable extends AbstractTable implements Handler { private static Set getDraggedDistributionSet(final TableTransferable transferable, final Table source) { - final Set distSelected = HawkbitCommonUtil.getSelectedDSDetails(source); + final Set distSelected = getTableValue(source); final Set distributionIdSet = new HashSet<>(); if (!distSelected.contains(transferable.getData(ITEMID))) { distributionIdSet.add((DistributionSetIdName) transferable.getData(ITEMID)); @@ -962,7 +908,7 @@ public class TargetTable extends AbstractTable implements Handler { refreshTargets(); } if (lastSelectedTarget != null) { - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.SELECTED_TARGET, lastSelectedTarget)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, lastSelectedTarget)); } } @@ -1042,13 +988,9 @@ public class TargetTable extends AbstractTable implements Handler { setValue(null); } - private void setNoDataAvailable() { - final int tableSize = getContainerDataSource().size(); - if (tableSize == 0) { - managementUIState.setNoDataAvilableTarget(true); - } else { - managementUIState.setNoDataAvilableTarget(false); - } + @Override + protected void setDataAvailable(final boolean available) { + managementUIState.setNoDataAvilableTarget(!available); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 5ad6e3c28..cb00c2338 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -12,7 +12,9 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; +import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.BulkUploadPopupEvent; @@ -254,13 +256,13 @@ public class TargetTableHeader extends AbstractTableHeader { @Override public void maximizeTable() { managementUIState.setTargetTableMaximized(Boolean.TRUE); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.MAXIMIZED)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.MAXIMIZED,null)); } @Override public void minimizeTable() { managementUIState.setTargetTableMaximized(Boolean.FALSE); - eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.MINIMIZED)); + eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.MINIMIZED,null)); } @Override @@ -377,8 +379,7 @@ public class TargetTableHeader extends AbstractTableHeader { } private Set getDropppedDistributionDetails(final TableTransferable transferable) { - final Set distSelected = HawkbitCommonUtil - .getSelectedDSDetails(transferable.getSourceComponent()); + final Set distSelected = AbstractTable.getTableValue(transferable.getSourceComponent()); final Set distributionIdSet = new HashSet<>(); if (!distSelected.contains(transferable.getData("itemId"))) { distributionIdSet.add((DistributionSetIdName) transferable.getData("itemId")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 54f4c382b..c60ab37ca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; +import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementViewAcceptCriteria; @@ -217,7 +218,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { final TableTransferable transferable = (TableTransferable) event.getTransferable(); final Table source = transferable.getSourceComponent(); - final Set targetSelected = HawkbitCommonUtil.getSelectedTargetDetails(source); + final Set targetSelected = AbstractTable.getTableValue(source); final Set targetList = new HashSet<>(); if (transferable.getData(ITEMID) != null) { if (!targetSelected.contains(transferable.getData(ITEMID))) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 3abd73592..2552fcf9a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -14,29 +14,23 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; -import org.eclipse.hawkbit.ui.management.dstable.DistributionTable; -import org.eclipse.hawkbit.ui.management.targettable.TargetTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.userdetails.UserDetails; @@ -878,8 +872,8 @@ public final class HawkbitCommonUtil { * I18N * @return message */ - public static String createAssignmentMessage(final String tagName, final AssignmentResult result, - final I18N i18n) { + public static String createAssignmentMessage(final String tagName, + final AssignmentResult result, final I18N i18n) { final StringBuilder formMsg = new StringBuilder(); final int assignedCount = result.getAssigned(); final int alreadyAssignedCount = result.getAlreadyAssigned(); @@ -959,43 +953,6 @@ public final class HawkbitCommonUtil { lqc.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, null, false, true); } - /** - * Get visible columns in table. - * - * @param isMaximized - * true if table is maximized - * @param isShowPinColumn - * if true pin column will be displayed. - * @param i18n - * I18N - * @return List list of columns to be displayed. - */ - public static List getTableVisibleColumns(final Boolean isMaximized, final Boolean isShowPinColumn, - final I18N i18n) { - final List columnList = new ArrayList<>(); - if (isMaximized) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1f)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1f)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2f)); - } else if (isShowPinColumn) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.7f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, SP_STRING_EMPTY, 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get(HEADER_NAME), 0.8f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get(HEADER_VERSION), 0.2f)); - } - return columnList; - - } - /** * Reset the software module table rows highlight css. * @@ -1102,36 +1059,6 @@ public final class HawkbitCommonUtil { return DELETE_TAG_DROP_REMOVE_SCRIPT; } - /** - * Get the details of selected rows of {@link TargetTable}. - * - * @param sourceTable - * @return set of {@link TargetIdName} - */ - public static Set getSelectedTargetDetails(final Table sourceTable) { - Set targetSelected = null; - if (sourceTable.getValue() != null) { - targetSelected = new LinkedHashSet<>((Set) sourceTable.getValue()); - targetSelected.remove(null); - } - return targetSelected; - } - - /** - * Get the details of selected rows of {@link DistributionTable}. - * - * @param sourceTable - * @return set of {@link DistributionSetIdName} - */ - public static Set getSelectedDSDetails(final Table sourceTable) { - Set distSelected = null; - if (sourceTable.getValue() != null) { - distSelected = new LinkedHashSet<>((Set) sourceTable.getValue()); - distSelected.remove(null); - } - return distSelected; - } - /** * * Add target table container properties. From e09ff4a716bd83bd9c91c12b610da5e1f80798ee Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 10:32:59 +0200 Subject: [PATCH 37/56] Refactor TableHeader Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 1 - .../ui/common/table/AbstractTable.java | 30 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 6164fa3bf..4f668ee8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -182,7 +182,6 @@ public class SoftwareModuleTable extends AbstractTable { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); } return columnList; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index c9487d467..be77cfaf2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -94,7 +94,7 @@ public abstract class AbstractTable extends Table { if (values == null) { values = Collections.emptySet(); } - if (values.remove(null)) { + if (values.contains(null)) { LOG.warn("Null values in table content. How could this happen?"); } return values; @@ -103,14 +103,12 @@ public abstract class AbstractTable extends Table { private void onValueChange() { eventBus.publish(this, UploadArtifactUIEvent.HIDE_DROP_HINTS); - // TODO Einzelwerte? - final Set values = getTableValue(this); E entity = null; - - final I lastId = Iterables.getLast(values); - if (lastId != null) { + I lastId = null; + if (!values.isEmpty()) { + lastId = Iterables.getLast(values); entity = findEntityByTableValue(lastId); } setManagementEntitiyStateValues(values, lastId); @@ -294,19 +292,17 @@ public abstract class AbstractTable extends Table { */ protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); - columnList - .add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); - columnList.add( - new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), - 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); - } else { + if (!isMaximized()) { columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_BY, i18n.get("header.createdBy"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, i18n.get("header.modifiedBy"), 0.1F)); + columnList.add( + new TableColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, i18n.get("header.modifiedDate"), 0.1F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_DESC, i18n.get("header.description"), 0.2F)); return columnList; } From 927ef461b9abc7941132323dfed172f98e7b5493 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:01:08 +0200 Subject: [PATCH 38/56] Update Distribution Set in table Signed-off-by: SirWayne --- .../hawkbit/ui/management/dstable/DistributionTable.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 5e546b79a..44574fb3a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -132,6 +132,11 @@ public class DistributionTable extends AbstractTable updateDistributionInTable(event.getEntity())); + } @EventBusListenerMethod(scope = EventScope.SESSION) From 6f2383b07723e3e6302be8f6dafe4ee5f018f0f7 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:23:56 +0200 Subject: [PATCH 39/56] Add Javadoc Signed-off-by: SirWayne --- .../hawkbit/ui/common/ManagmentEntityState.java | 15 ++++++++++++++- .../detailslayout/AbstractTableDetailsLayout.java | 11 ++++++++--- .../ui/common/table/BaseEntityEventType.java | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java index 8b2318ace..ecc378ad7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ManagmentEntityState.java @@ -11,12 +11,25 @@ package org.eclipse.hawkbit.ui.common; import java.util.Set; /** - * + * Interface for all entity states UI to show the details to a entity. */ public interface ManagmentEntityState { + /** + * The selected entities for the detail. + * + * @param values + * the selected entities. + * + */ void setSelectedEnitities(Set values); + /** + * The last selected value. + * + * @param value + * the value + */ void setLastSelectedEntity(T value); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 02b1f0044..334eee90f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -41,7 +41,7 @@ import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; /** - * + * Abstract Layout to show the entity details. * */ public abstract class AbstractTableDetailsLayout extends VerticalLayout { @@ -89,10 +89,15 @@ public abstract class AbstractTableDetailsLayout extends eventBus.unsubscribe(this); } + /** + * Default implementation to handle a entity event. + * + * @param baseEntityEvent + * the event + */ protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { final BaseEntityEventType eventType = baseEntityEvent.getEventType(); - if (BaseEntityEventType.SELECTED_ENTITY == eventType - || BaseEntityEventType.UPDATED_ENTITY == eventType) { + if (BaseEntityEventType.SELECTED_ENTITY == eventType || BaseEntityEventType.UPDATED_ENTITY == eventType) { UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity())); } else if (BaseEntityEventType.MINIMIZED == eventType) { UI.getCurrent().access(() -> setVisible(true)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java index bfaf593fb..d9f7f544c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEventType.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.common.table; /** - * + * Types of the entity event. * */ public enum BaseEntityEventType { From fdee1528850a69a3b8b3f3273755867cfb4fe8d4 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 12:42:50 +0200 Subject: [PATCH 40/56] Fix typo Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java | 2 +- .../confirmwindow/layout/AbstractConfirmationWindowLayout.java | 2 +- .../hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java | 2 +- .../hawkbit/ui/management/footer/DeleteActionsLayout.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java index a5cb5c8d0..ee2fc356f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/SMDeleteActionsLayout.java @@ -190,7 +190,7 @@ public class SMDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - uploadViewConfirmationWindowLayout.inittialize(); + uploadViewConfirmationWindowLayout.initialize(); return uploadViewConfirmationWindowLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index a737fabbf..bc5de63ff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -52,7 +52,7 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { protected transient EventBus.SessionEventBus eventBus; @PostConstruct - public void inittialize() { + public void initialize() { removeAllComponents(); consolidatedMessage = ""; createComponents(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index ea33a2ea3..dba8155db 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -295,7 +295,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - distConfirmationWindowLayout.inittialize(); + distConfirmationWindowLayout.initialize(); return distConfirmationWindowLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 4a95df51a..678a5704f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -212,7 +212,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { @Override protected Component getUnsavedActionsWindowContent() { - manangementConfirmationWindowLayout.inittialize(); + manangementConfirmationWindowLayout.initialize(); return manangementConfirmationWindowLayout; } From c069b904b21a7dc5fbb1a975458e332b16367a1c Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:00:39 +0200 Subject: [PATCH 41/56] Use Optional.ofNullable instead of a if statement Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/state/ArtifactUploadState.java | 4 ++-- .../AbstractNamedVersionedEntityTableDetailsLayout.java | 1 - .../hawkbit/ui/distributions/state/ManageDistUIState.java | 6 +++--- .../hawkbit/ui/management/state/ManagementUIState.java | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index b975ad1fd..d387ff105 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -86,7 +86,7 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ * @return the selectedBaseSwModuleId */ public Optional getSelectedBaseSwModuleId() { - return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); + return Optional.ofNullable(selectedBaseSwModuleId); } /** @@ -179,7 +179,7 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ } public Optional getSelectedBaseSoftwareModule() { - return selectedBaseSoftwareModule == null ? Optional.empty() : Optional.of(selectedBaseSoftwareModule); + return Optional.ofNullable(selectedBaseSoftwareModule); } public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java index 31fbe5996..19bfb324e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -24,5 +24,4 @@ public abstract class AbstractNamedVersionedEntityTableDetailsLayout> getSelectedDistributions() { - return selectedDistributions == null ? Optional.empty() : Optional.of(selectedDistributions); + return Optional.ofNullable(selectedDistributions); } /** * @return the lastSelectedDistribution */ public Optional getLastSelectedDistribution() { - return lastSelectedDistribution == null ? Optional.empty() : Optional.of(lastSelectedDistribution); + return Optional.ofNullable(lastSelectedDistribution); } @Override @@ -139,7 +139,7 @@ public class ManageDistUIState implements ManagmentEntityState getSelectedBaseSwModuleId() { - return selectedBaseSwModuleId != null ? Optional.of(selectedBaseSwModuleId) : Optional.empty(); + return Optional.ofNullable(selectedBaseSwModuleId); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java index 73e2ed1a7..653075735 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java @@ -171,7 +171,7 @@ public class ManagementUIState implements ManagmentEntityState> getSelectedTargetIdName() { - return selectedTargetIdName == null ? Optional.empty() : Optional.of(selectedTargetIdName); + return Optional.ofNullable(selectedTargetIdName); } public void setSelectedTargetIdName(final Set selectedTargetIdName) { @@ -279,7 +279,7 @@ public class ManagementUIState implements ManagmentEntityState> getSelectedDsIdName() { - return selectedDsIdName == null ? Optional.empty() : Optional.of(selectedDsIdName); + return Optional.ofNullable(selectedDsIdName); } /** From 15702cb5c98d62f9fd1f5ed38cae35a8171af31f Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:11:16 +0200 Subject: [PATCH 42/56] Improve javadoc Signed-off-by: SirWayne --- .../hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 0f5e2de32..615760a1c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -282,9 +282,8 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme } /** - * Only in deployment view count message is displayed. * - * @return + * @return true if the count label is displayed false ist not displayed */ protected boolean hasCountMessage() { return false; From 27118e293945e03c8f28b84a155a53d5edd03a7f Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 13:23:08 +0200 Subject: [PATCH 43/56] fix typo Signed-off-by: SirWayne --- .../hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 615760a1c..75bd43447 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -283,7 +283,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme /** * - * @return true if the count label is displayed false ist not displayed + * @return true if the count label is displayed false is not displayed */ protected boolean hasCountMessage() { return false; From 5e0f07b8527f5c9776052c27ef4901cee56794f5 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:12:26 +0200 Subject: [PATCH 44/56] Add new abstract table to reduce the visible columns and add entity code Signed-off-by: SirWayne --- .../smtable/SoftwareModuleTable.java | 14 +++--- .../table/AbstractNamedVersionTable.java | 47 +++++++++++++++++++ .../ui/common/table/AbstractTable.java | 7 ++- .../dstable/DistributionSetTable.java | 7 ++- .../distributions/smtable/SwModuleTable.java | 19 ++++---- .../management/dstable/DistributionTable.java | 26 ++++------ 6 files changed, 81 insertions(+), 39 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 4f668ee8e..1ef4b8f7a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadViewAcceptCriteria; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; @@ -48,7 +48,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class SoftwareModuleTable extends AbstractTable { +public class SoftwareModuleTable extends AbstractNamedVersionTable { private static final long serialVersionUID = 6469417305487144809L; @@ -165,7 +165,7 @@ public class SoftwareModuleTable extends AbstractTable { final String swNameVersion = HawkbitCommonUtil.concatStrings(":", baseEntity.getName(), baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); if (!artifactUploadState.getSelectedSoftwareModules().isEmpty()) { artifactUploadState.getSelectedSoftwareModules().stream().forEach(this::unselect); @@ -178,12 +178,10 @@ public class SoftwareModuleTable extends AbstractTable { @Override protected List getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); + if (!isMaximized()) { + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); return columnList; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java new file mode 100644 index 000000000..64460bc1c --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -0,0 +1,47 @@ +/** + * 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.common.table; + +import java.util.List; + +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.TableColumn; + +import com.vaadin.data.Item; + +/** + * Abstract table to handling {@link NamedVersionedEntity} + * + * @param + * e is the entity class + * @param + * i is the id of the table + */ +public abstract class AbstractNamedVersionTable extends AbstractTable { + + private static final long serialVersionUID = 780050712209750719L; + + @Override + protected List getTableVisibleColumns() { + final List columnList = super.getTableVisibleColumns(); + final float versionColumnSize = isMaximized() ? 0.1f : 0.2f; + columnList + .add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), versionColumnSize)); + return columnList; + } + + @SuppressWarnings("unchecked") + @Override + protected void updateEntity(final E baseEntity, final Item item) { + super.updateEntity(baseEntity, item); + item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index be77cfaf2..5aea8914f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -293,7 +293,8 @@ public abstract class AbstractTable extends Table { protected List getTableVisibleColumns() { final List columnList = new ArrayList<>(); if (!isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.8F)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), + getColumnNameMinimizedSize())); return columnList; } columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.2F)); @@ -306,6 +307,10 @@ public abstract class AbstractTable extends Table { return columnList; } + protected float getColumnNameMinimizedSize() { + return 0.8F; + } + /** * Get drop handler for the table. * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 51f30117a..c49a89368 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.event.DistributionsViewAcceptCriteria; @@ -70,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionSetTable extends AbstractTable { +public class DistributionSetTable extends AbstractNamedVersionTable { private static final long serialVersionUID = -7731776093470487988L; @@ -475,11 +475,10 @@ public class DistributionSetTable extends AbstractTable unselect(dsNameId)); + manageDistUIState.getSelectedDistributions().get().stream().forEach(this::unselect); } select(baseEntity.getDistributionSetIdName()); return item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index dac8d2ecf..9c02f1d8a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.distributions.smtable; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,7 +19,7 @@ import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -63,7 +62,7 @@ import com.vaadin.ui.Window; */ @SpringComponent @ViewScope -public class SwModuleTable extends AbstractTable { +public class SwModuleTable extends AbstractNamedVersionTable { private static final long serialVersionUID = 6785314784507424750L; @@ -228,19 +227,20 @@ public class SwModuleTable extends AbstractTable { @Override protected List getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.addAll(super.getTableVisibleColumns()); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7F)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2F)); columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); } return columnList; } + @Override + protected float getColumnNameMinimizedSize() { + return 0.7F; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -332,12 +332,11 @@ public class SwModuleTable extends AbstractTable { baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(swNameVersion); item.getItemProperty("swId").setValue(baseEntity.getId()); - item.getItemProperty(SPUILabelDefinitions.VAR_VERSION).setValue(baseEntity.getVersion()); item.getItemProperty(SPUILabelDefinitions.VAR_VENDOR).setValue(baseEntity.getVendor()); item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).setValue(baseEntity.getType().getColour()); if (!manageDistUIState.getSelectedSoftwareModules().isEmpty()) { - manageDistUIState.getSelectedSoftwareModules().stream().forEach(swmNameId -> unselect(swmNameId)); + manageDistUIState.getSelectedSoftwareModules().stream().forEach(this::unselect); } select(baseEntity.getId()); return item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 44574fb3a..4ba164bde 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -25,7 +25,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; -import org.eclipse.hawkbit.ui.common.table.AbstractTable; +import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; @@ -70,7 +70,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class DistributionTable extends AbstractTable { +public class DistributionTable extends AbstractNamedVersionTable { private static final long serialVersionUID = -1928335256399519494L; @@ -272,18 +272,19 @@ public class DistributionTable extends AbstractTable getTableVisibleColumns() { - final List columnList = new ArrayList<>(); + final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.addAll(super.getTableVisibleColumns()); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_NAME, i18n.get("header.name"), 0.7f)); - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); - columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); + return columnList; } + columnList.add(new TableColumn(SPUILabelDefinitions.PIN_COLUMN, StringUtils.EMPTY, 0.1f)); return columnList; } + @Override + protected float getColumnNameMinimizedSize() { + return 0.7F; + } + @Override protected DropHandler getTableDropHandler() { return new DropHandler() { @@ -478,13 +479,6 @@ public class DistributionTable extends AbstractTable Date: Thu, 7 Apr 2016 14:13:27 +0200 Subject: [PATCH 45/56] Remove full qualified pakcage Signed-off-by: SirWayne --- .../hawkbit/ui/distributions/state/ManageDistUIState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java index 11a0a0ff2..a68a42e00 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/state/ManageDistUIState.java @@ -117,7 +117,7 @@ public class ManageDistUIState implements ManagmentEntityState values) { + public void setSelectedEnitities(final Set values) { selectedDistributions = values; } From 08e0dc4b3db62941e96cb5a3f52322afdd075350 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 7 Apr 2016 14:16:43 +0200 Subject: [PATCH 46/56] Add new abstract table to reduce the visible columns and add entity code Signed-off-by: SirWayne --- .../distributions/dstable/DistributionSetTable.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index c49a89368..1cd89b30f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -42,7 +42,6 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; -import org.eclipse.hawkbit.ui.utils.TableColumn; import org.eclipse.hawkbit.ui.utils.UINotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,17 +189,6 @@ public class DistributionSetTable extends AbstractNamedVersionTable getTableVisibleColumns() { - final List columnList = super.getTableVisibleColumns(); - if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.1f)); - } else { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), 0.2f)); - } - return columnList; - } - @Override protected DropHandler getTableDropHandler() { return new DropHandler() { From 929916165253b7f11ee072d7eb83069ece848e2b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 14:43:05 +0200 Subject: [PATCH 47/56] Added anonymous download section as part of authentication configuration section Signed-off-by: Jonathan Philip Knoblauch --- .../AuthenticationConfigurationView.java | 20 ++- .../DownloadAnonymousConfigurationView.java | 119 ------------------ .../TenantConfigurationDashboardView.java | 4 - ...wnloadAuthenticationConfigurationItem.java | 86 +++++++++++++ 4 files changed, 105 insertions(+), 124 deletions(-) delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index d00223f5a..f3c42552e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AnonymousDownloadAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.CertificateAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.GatewaySecurityTokenAuthenticationConfigurationItem; @@ -52,12 +53,17 @@ public class AuthenticationConfigurationView extends BaseConfigurationView @Autowired private GatewaySecurityTokenAuthenticationConfigurationItem gatewaySecurityTokenAuthenticationConfigurationItem; + @Autowired + private AnonymousDownloadAuthenticationConfigurationItem anonymousDownloadAuthenticationConfigurationItem; + private CheckBox gatewaySecTokenCheckBox; private CheckBox targetSecTokenCheckBox; private CheckBox certificateAuthCheckbox; + private CheckBox downloadAnonymousCheckBox; + /** * Initialize Authentication Configuration layout. */ @@ -77,7 +83,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView headerDisSetType.addStyleName("config-panel-header"); vLayout.addComponent(headerDisSetType); - final GridLayout gridLayout = new GridLayout(2, 3); + final GridLayout gridLayout = new GridLayout(2, 4); gridLayout.setSpacing(true); gridLayout.setImmediate(true); gridLayout.setColumnExpandRatio(1, 1.0F); @@ -105,6 +111,13 @@ public class AuthenticationConfigurationView extends BaseConfigurationView gridLayout.addComponent(gatewaySecTokenCheckBox, 0, 2); gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2); + downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); + downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); + downloadAnonymousCheckBox.addValueChangeListener(this); + anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this); + gridLayout.addComponent(downloadAnonymousCheckBox, 0, 3); + gridLayout.addComponent(anonymousDownloadAuthenticationConfigurationItem, 1, 3); + vLayout.addComponent(gridLayout); rootPanel.setContent(vLayout); setCompositionRoot(rootPanel); @@ -115,6 +128,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView certificateAuthenticationConfigurationItem.save(); targetSecurityTokenAuthenticationConfigurationItem.save(); gatewaySecurityTokenAuthenticationConfigurationItem.save(); + anonymousDownloadAuthenticationConfigurationItem.save(); } @Override @@ -122,9 +136,11 @@ public class AuthenticationConfigurationView extends BaseConfigurationView certificateAuthenticationConfigurationItem.undo(); targetSecurityTokenAuthenticationConfigurationItem.undo(); gatewaySecurityTokenAuthenticationConfigurationItem.undo(); + anonymousDownloadAuthenticationConfigurationItem.undo(); certificateAuthCheckbox.setValue(certificateAuthenticationConfigurationItem.isConfigEnabled()); targetSecTokenCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); gatewaySecTokenCheckBox.setValue(gatewaySecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); + downloadAnonymousCheckBox.setValue(anonymousDownloadAuthenticationConfigurationItem.isConfigEnabled()); } @Override @@ -150,6 +166,8 @@ public class AuthenticationConfigurationView extends BaseConfigurationView configurationItem = targetSecurityTokenAuthenticationConfigurationItem; } else if (checkBox == certificateAuthCheckbox) { configurationItem = certificateAuthenticationConfigurationItem; + } else if (checkBox == downloadAnonymousCheckBox) { + configurationItem = anonymousDownloadAuthenticationConfigurationItem; } else { return; } 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 deleted file mode 100644 index e008e03f2..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DownloadAnonymousConfigurationView.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * 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.SPUIComponetIdProvider; -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; - -/** - * View to enable anonymous download. - */ -@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; - - @Autowired - private transient TenantConfigurationManagement tenantConfigurationManagement; - - boolean anonymousDownloadEnabled; - - private CheckBox downloadAnonymousCheckBox; - - /** - * Initialize Default Download Anonymous 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.addValueChangeListener(event -> configurationHasChanged()); - downloadAnonymousCheckBox.setId(SPUIComponetIdProvider.SYSTEM_CONFIGURATION_ANONYMOUS_DOWNLOAD_CHECKBOX); - - 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()); - } - - @Override - public void undo() { - final TenantConfigurationValue value = tenantConfigurationManagement - .getConfigurationValue(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, Boolean.class); - anonymousDownloadEnabled = value.getValue(); - 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 cada6d167..d021254bc 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 @@ -55,9 +55,6 @@ public class TenantConfigurationDashboardView extends CustomComponent implements @Autowired private PollingConfigurationView pollingConfigurationView; - @Autowired - private DownloadAnonymousConfigurationView downloadAnonymousConfigurationView; - @Autowired private I18N i18n; @@ -80,7 +77,6 @@ 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/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java new file mode 100644 index 000000000..3c5a95df1 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -0,0 +1,86 @@ +/** + * 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.authentication; + +import javax.annotation.PostConstruct; + +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.springframework.beans.factory.annotation.Autowired; + +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; + +/** + * This class represents the UI item for the anonymous download by in the + * authentication configuration view. + */ +@SpringComponent +@ViewScope +public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAuthenticationTenantConfigurationItem { + + private static final long serialVersionUID = 1L; + + private boolean configurationEnabled = false; + private boolean configurationEnabledChange = false; + + @Autowired + private I18N i18n; + + @Autowired + public AnonymousDownloadAuthenticationConfigurationItem( + final TenantConfigurationManagement tenantConfigurationManagement) { + super(TenantConfigurationKey.ANONYMOUS_DOWNLOAD_MODE_ENABLED, tenantConfigurationManagement); + } + + @PostConstruct + public void init() { + + super.init(i18n.get("enonymous.download.label")); + configurationEnabled = isConfigEnabled(); + + } + + @Override + public void configEnable() { + + if (!configurationEnabled) { + configurationEnabledChange = true; + } + configurationEnabled = true; + } + + @Override + public void configDisable() { + if (configurationEnabled) { + configurationEnabledChange = true; + } + configurationEnabled = false; + } + + @Override + public void save() { + if (!configurationEnabledChange) { + return; + } + getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); + + } + + @Override + public void undo() { + + configurationEnabledChange = false; + configurationEnabled = getTenantConfigurationManagement() + .getConfigurationValue(getConfigurationKey(), Boolean.class).getValue(); + + } + +} From 7281c0e84e24d09e15228b972e0cf1edb055224b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 15:25:31 +0200 Subject: [PATCH 48/56] Added description for anonymous download checkbox Signed-off-by: Jonathan Philip Knoblauch --- .../AnonymousDownloadAuthenticationConfigurationItem.java | 2 +- hawkbit-ui/src/main/resources/messages.properties | 3 +-- hawkbit-ui/src/main/resources/messages_de.properties | 4 ++-- hawkbit-ui/src/main/resources/messages_en.properties | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java index 3c5a95df1..b1da8e0ee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -43,7 +43,7 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu @PostConstruct public void init() { - super.init(i18n.get("enonymous.download.label")); + super.init(i18n.get("label.configuration.anonymous.download")); configurationEnabled = isConfigEnabled(); } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index ebdcfa76f..d2e36dd2d 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -161,6 +161,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -401,8 +402,6 @@ 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 47cb36f31..98ac9edb3 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -159,6 +159,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -389,8 +390,7 @@ 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 50c04ad46..d6b4b1088 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -160,6 +160,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token +label.configuration.anonymous.download = Allow targets to download anonymous label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox @@ -383,8 +384,6 @@ 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 From d815aaf12c28a12f3478c99c55ea7b30cf9842ae Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Thu, 7 Apr 2016 15:58:25 +0200 Subject: [PATCH 49/56] Added id to anonymous download checkbox Signed-off-by: Jonathan Philip Knoblauch --- .../ui/tenantconfiguration/AuthenticationConfigurationView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index f3c42552e..616acaf3f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -112,6 +112,7 @@ public class AuthenticationConfigurationView extends BaseConfigurationView gridLayout.addComponent(gatewaySecurityTokenAuthenticationConfigurationItem, 1, 2); downloadAnonymousCheckBox = SPUIComponentProvider.getCheckBox("", DIST_CHECKBOX_STYLE, null, false, ""); + downloadAnonymousCheckBox.setId("downloadanonymouscheckbox"); downloadAnonymousCheckBox.setValue(targetSecurityTokenAuthenticationConfigurationItem.isConfigEnabled()); downloadAnonymousCheckBox.addValueChangeListener(this); anonymousDownloadAuthenticationConfigurationItem.addChangeListener(this); From 1e28acb1704d0394550a9db1e65570ec3bed361a Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 8 Apr 2016 08:16:47 +0200 Subject: [PATCH 50/56] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 461e12e81..0a9b0b4c6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ https://hawkbit.eu-gb.mybluemix.net/UI/ # Compile, Run and Getting Started -We are not providing an off the shelf installation ready hawkBit update server. However, we recommend to check out the [Example Application](examples/hawkbit-example-app) for a runtime ready Spring Boot based update server that is empowered by hawkBit. +We are not providing an off the shelf installation ready hawkBit update server. However, we recommend to check out the [Example Application](examples/hawkbit-example-app) for a runtime ready Spring Boot based update server that is empowered by hawkBit. In addition we have [guide](https://github.com/eclipse/hawkbit/wiki/Run-hawkBit) for setting up a complete landscape. #### Clone and build hawkBit ``` From a021630c0491fefc8d8c312116958fa4e5c58f65 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 10:12:16 +0200 Subject: [PATCH 51/56] Remove empty lines Signed-off-by: SirWayne --- .../hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java | 1 - .../hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java | 1 - .../eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java | 1 - .../confirmwindow/layout/AbstractConfirmationWindowLayout.java | 1 - 4 files changed, 4 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index 397f0cf2b..d839be40d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -141,5 +141,4 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta protected String getDetailsHeaderCaptionId() { return SPUIComponetIdProvider.TARGET_DETAILS_HEADER_LABEL_ID; } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 1ef4b8f7a..f101c94a7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -206,6 +206,5 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable, Serializ public void setSelectedBaseSoftwareModule(final SoftwareModule selectedBaseSoftwareModule) { this.selectedBaseSoftwareModule = selectedBaseSoftwareModule; } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java index bc5de63ff..f4fe21425 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/confirmwindow/layout/AbstractConfirmationWindowLayout.java @@ -148,5 +148,4 @@ public abstract class AbstractConfirmationWindowLayout extends VerticalLayout { deletesDsIcon.addClickListener(clickListener); return deletesDsIcon; } - } From 3070dcfc3d99d1361bf4e788c3aa0d1d30052114 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 15:01:26 +0200 Subject: [PATCH 52/56] Modify scope of protected attributes to private. Create getter/setter to access the the attribute. see clean code Protected variables should be avoided because: http://programmers.stackexchange.com/questions/162643/why-is-clean-code-suggesting-avoiding-protected-variables Signed-off-by: SirWayne --- .../smtable/SoftwareModuleDetails.java | 30 ++++---- ...amedVersionedEntityTableDetailsLayout.java | 3 +- .../AbstractTableDetailsLayout.java | 30 ++++++-- .../dstable/DistributionSetDetails.java | 58 +++++++------- .../smtable/SwModuleDetails.java | 30 ++++---- .../dstable/DistributionDetails.java | 30 ++++---- .../management/targettable/TargetDetails.java | 76 +++++++++---------- 7 files changed, 135 insertions(+), 122 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index d839be40d..9d535f7f5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -52,16 +52,16 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected void onEdit(final ClickEvent event) { final Window addSoftwareModule = softwareModuleAddUpdateWindow .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); - addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); + addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } @@ -69,14 +69,14 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected void populateDetailsWidget() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (selectedBaseEntity != null) { - if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { - maxAssign = i18n.get("label.multiAssign.type"); + if (getSelectedBaseEntity() != null) { + if (getSelectedBaseEntity().getType().getMaxAssignments() == Integer.MAX_VALUE) { + maxAssign = getI18n().get("label.multiAssign.type"); } else { - maxAssign = i18n.get("label.singleAssign.type"); + maxAssign = getI18n().get("label.singleAssign.type"); } - updateSoftwareModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), - maxAssign); + updateSoftwareModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().getVendor(), maxAssign); } else { updateSoftwareModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -88,19 +88,19 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta detailsTabLayout.removeAllComponents(); - final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.vendor"), + final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.vendor"), HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor); vendorLabel.setId(SPUIComponetIdProvider.DETAILS_VENDOR_LABEL_ID); detailsTabLayout.addComponent(vendorLabel); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } - final Label assignLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.assigned.type"), + final Label assignLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.assigned.type"), HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign); assignLabel.setId(SPUIComponetIdProvider.SWM_DTLS_MAX_ASSIGN); detailsTabLayout.addComponent(assignLabel); @@ -109,7 +109,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected String getDefaultCaption() { - return i18n.get("upload.swModuleTable.header"); + return getI18n().get("upload.swModuleTable.header"); } @Override @@ -129,7 +129,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java index 19bfb324e..3ccbb8ad7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractNamedVersionedEntityTableDetailsLayout.java @@ -22,6 +22,7 @@ public abstract class AbstractNamedVersionedEntityTableDetailsLayout extends private static final long serialVersionUID = 4862529368471627190L; @Autowired - protected I18N i18n; + private I18N i18n; @Autowired - protected transient EventBus.SessionEventBus eventBus; + private transient EventBus.SessionEventBus eventBus; @Autowired - protected SpPermissionChecker permissionChecker; + private SpPermissionChecker permissionChecker; - protected T selectedBaseEntity; + private T selectedBaseEntity; private Label caption; @@ -89,6 +89,26 @@ public abstract class AbstractTableDetailsLayout extends eventBus.unsubscribe(this); } + protected SpPermissionChecker getPermissionChecker() { + return permissionChecker; + } + + protected EventBus.SessionEventBus getEventBus() { + return eventBus; + } + + protected I18N getI18n() { + return i18n; + } + + protected T getSelectedBaseEntity() { + return selectedBaseEntity; + } + + public void setSelectedBaseEntity(final T selectedBaseEntity) { + this.selectedBaseEntity = selectedBaseEntity; + } + /** * Default implementation to handle a entity event. * @@ -118,7 +138,7 @@ public abstract class AbstractTableDetailsLayout extends editButton = SPUIComponentProvider.getButton("", "", "", null, false, FontAwesome.PENCIL_SQUARE_O, SPUIButtonStyleSmallNoBorder.class); editButton.setId(getEditButtonId()); - editButton.addClickListener(event -> onEdit(event)); + editButton.addClickListener(this::onEdit); editButton.setEnabled(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 64a9819bb..a1d1ffcfe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -92,7 +92,8 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); - softwareModuleTable.init(i18n, true, permissionChecker, distributionSetManagement, eventBus, manageDistUIState); + softwareModuleTable.init(getI18n(), true, getPermissionChecker(), distributionSetManagement, getEventBus(), + manageDistUIState); super.init(); } @@ -109,7 +110,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet } private void populateModule() { - softwareModuleTable.populateModule(selectedBaseEntity); + softwareModuleTable.populateModule(getSelectedBaseEntity()); showUnsavedAssignment(); } @@ -157,12 +158,8 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet } } - /** - * @param item - * @param entry - */ private void assignSoftModuleButton(final Item item, final Map.Entry entry) { - if (permissionChecker.hasUpdateDistributionPermission() && distributionSetManagement + if (getPermissionChecker().hasUpdateDistributionPermission() && distributionSetManagement .findDistributionSetById(manageDistUIState.getLastSelectedDistribution().get().getId()) .getAssignedTargets().isEmpty()) { final Button reassignSoftModule = SPUIComponentProvider.getButton(entry.getKey(), "", "", "", true, @@ -227,15 +224,16 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet private void populateTags() { tagsLayout.removeAllComponents(); - if (null != selectedBaseEntity) { - tagsLayout.addComponent(distributionTagToken.getTokenField()); + if (getSelectedBaseEntity() == null) { + return; } + tagsLayout.addComponent(distributionTagToken.getTokenField()); } private void populateDetails() { - if (selectedBaseEntity != null) { - updateDistributionSetDetailsLayout(selectedBaseEntity.getType().getName(), - selectedBaseEntity.isRequiredMigrationStep()); + if (getSelectedBaseEntity() != null) { + updateDistributionSetDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().isRequiredMigrationStep()); } else { updateDistributionSetDetailsLayout(null, null); } @@ -246,16 +244,16 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet detailsTabLayout.removeAllComponents(); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } if (isMigrationRequired != null) { - detailsTabLayout.addComponent( - SPUIComponentProvider.createNameValueLabel(i18n.get("checkbox.dist.migration.required"), - isMigrationRequired.equals(Boolean.TRUE) ? i18n.get("label.yes") : i18n.get("label.no"))); + detailsTabLayout.addComponent(SPUIComponentProvider.createNameValueLabel( + getI18n().get("checkbox.dist.migration.required"), + isMigrationRequired.equals(Boolean.TRUE) ? getI18n().get("label.yes") : getI18n().get("label.no"))); } } @@ -263,7 +261,7 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -286,21 +284,21 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet @Override protected String getDefaultCaption() { - return i18n.get("distribution.details.header"); + return getI18n().get("distribution.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createSoftwareModuleTab(), i18n.get("caption.softwares.distdetail.tab"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createSoftwareModuleTab(), getI18n().get("caption.softwares.distdetail.tab"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -322,9 +320,9 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet final DistributionSetIdName distIdName = softwareModuleAssignmentDiscardEvent .getDistributionSetIdName(); if (distIdName.getId().equals(getSelectedBaseEntityId()) - && distIdName.getName().equals(selectedBaseEntity.getName())) { - selectedBaseEntity = distributionSetManagement - .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + && distIdName.getName().equals(getSelectedBaseEntity().getName())) { + setSelectedBaseEntity( + distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId())); populateModule(); } }); @@ -335,10 +333,10 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS || saveActionWindowEvent == SaveActionWindowEvent.DISCARD_ALL_ASSIGNMENTS) - && selectedBaseEntity != null) { + && getSelectedBaseEntity() != null) { assignedSWModule.clear(); - selectedBaseEntity = distributionSetManagement - .findDistributionSetByIdWithDetails(getSelectedBaseEntityId()); + setSelectedBaseEntity( + distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId())); UI.getCurrent().access(() -> populateModule()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index e1c39ee89..8774c9e08 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -54,7 +54,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay protected void onEdit(final ClickEvent event) { final Window addSoftwareModule = softwareModuleAddUpdateWindow .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId()); - addSoftwareModule.setCaption(i18n.get("upload.caption.update.swmodule")); + addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule")); UI.getCurrent().addWindow(addSoftwareModule); addSoftwareModule.setVisible(Boolean.TRUE); } @@ -66,14 +66,14 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected String getDefaultCaption() { - return i18n.get("upload.swModuleTable.header"); + return getI18n().get("upload.swModuleTable.header"); } @Override @@ -88,7 +88,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override @@ -98,14 +98,14 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay private void populateDetails() { String maxAssign = HawkbitCommonUtil.SP_STRING_EMPTY; - if (selectedBaseEntity != null) { - if (selectedBaseEntity.getType().getMaxAssignments() == Integer.MAX_VALUE) { - maxAssign = i18n.get("label.multiAssign.type"); + if (getSelectedBaseEntity() != null) { + if (getSelectedBaseEntity().getType().getMaxAssignments() == Integer.MAX_VALUE) { + maxAssign = getI18n().get("label.multiAssign.type"); } else { - maxAssign = i18n.get("label.singleAssign.type"); + maxAssign = getI18n().get("label.singleAssign.type"); } - updateSwModuleDetailsLayout(selectedBaseEntity.getType().getName(), selectedBaseEntity.getVendor(), - maxAssign); + updateSwModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), + getSelectedBaseEntity().getVendor(), maxAssign); } else { updateSwModuleDetailsLayout(HawkbitCommonUtil.SP_STRING_EMPTY, HawkbitCommonUtil.SP_STRING_EMPTY, maxAssign); @@ -117,19 +117,19 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); - final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.vendor"), + final Label vendorLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.vendor"), HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor); vendorLabel.setId(SPUIComponetIdProvider.DETAILS_VENDOR_LABEL_ID); detailsTabLayout.addComponent(vendorLabel); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } - final Label assignLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.assigned.type"), + final Label assignLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.assigned.type"), HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign); assignLabel.setId(SPUIComponetIdProvider.SWM_DTLS_MAX_ASSIGN); detailsTabLayout.addComponent(assignLabel); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index aedce157e..81151b076 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -52,7 +52,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected void init() { softwareModuleTable = new SoftwareModuleDetailsTable(); - softwareModuleTable.init(i18n, false, permissionChecker, null, null, null); + softwareModuleTable.init(getI18n(), false, getPermissionChecker(), null, null, null); super.init(); } @@ -63,23 +63,23 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected String getDefaultCaption() { - return i18n.get("distribution.details.header"); + return getI18n().get("distribution.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createSoftwareModuleTab(), i18n.get("caption.softwares.distdetail.tab"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createSoftwareModuleTab(), getI18n().get("caption.softwares.distdetail.tab"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @Override protected void onEdit(final ClickEvent event) { final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(); distributionAddUpdateWindowLayout.populateValuesOfDistribution(getSelectedBaseEntityId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -102,7 +102,7 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateDistributionPermission(); + return getPermissionChecker().hasUpdateDistributionPermission(); } @Override @@ -112,8 +112,8 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail @Override protected void populateDetailsWidget() { - softwareModuleTable.populateModule(selectedBaseEntity); - populateDetails(selectedBaseEntity); + softwareModuleTable.populateModule(getSelectedBaseEntity()); + populateDetails(getSelectedBaseEntity()); } @@ -130,16 +130,16 @@ public class DistributionDetails extends AbstractNamedVersionedEntityTableDetail detailsTabLayout.removeAllComponents(); if (type != null) { - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.type"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.type"), type); typeLabel.setId(SPUIComponetIdProvider.DETAILS_TYPE_LABEL_ID); detailsTabLayout.addComponent(typeLabel); } if (isMigrationRequired != null) { - detailsTabLayout.addComponent( - SPUIComponentProvider.createNameValueLabel(i18n.get("checkbox.dist.migration.required"), - isMigrationRequired.equals(Boolean.TRUE) ? i18n.get("label.yes") : i18n.get("label.no"))); + detailsTabLayout.addComponent(SPUIComponentProvider.createNameValueLabel( + getI18n().get("checkbox.dist.migration.required"), + isMigrationRequired.equals(Boolean.TRUE) ? getI18n().get("label.yes") : getI18n().get("label.no"))); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 6105409bf..8ab4f8b0d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -43,9 +43,6 @@ import com.vaadin.ui.themes.ValoTheme; /** * Target details layout. - * - * - * */ @SpringComponent @ViewScope @@ -65,9 +62,6 @@ public class TargetDetails extends AbstractTableDetailsLayout { private VerticalLayout assignedDistLayout; private VerticalLayout installedDistLayout; - /** - * Initialize the Target details. - */ @Override public void init() { super.init(); @@ -76,18 +70,18 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected String getDefaultCaption() { - return i18n.get("target.details.header"); + return getI18n().get("target.details.header"); } @Override protected void addTabs(final TabSheet detailsTab) { - detailsTab.addTab(createDetailsLayout(), i18n.get("caption.tab.details"), null); - detailsTab.addTab(createDescriptionLayout(), i18n.get("caption.tab.description"), null); - detailsTab.addTab(createAttributesLayout(), i18n.get("caption.attributes.tab"), null); - detailsTab.addTab(createAssignedDistLayout(), i18n.get("header.target.assigned"), null); - detailsTab.addTab(createInstalledDistLayout(), i18n.get("header.target.installed"), null); - detailsTab.addTab(createTagsLayout(), i18n.get("caption.tags.tab"), null); - detailsTab.addTab(createLogLayout(), i18n.get("caption.logs.tab"), null); + detailsTab.addTab(createDetailsLayout(), getI18n().get("caption.tab.details"), null); + detailsTab.addTab(createDescriptionLayout(), getI18n().get("caption.tab.description"), null); + detailsTab.addTab(createAttributesLayout(), getI18n().get("caption.attributes.tab"), null); + detailsTab.addTab(createAssignedDistLayout(), getI18n().get("header.target.assigned"), null); + detailsTab.addTab(createInstalledDistLayout(), getI18n().get("header.target.installed"), null); + detailsTab.addTab(createTagsLayout(), getI18n().get("caption.tags.tab"), null); + detailsTab.addTab(createLogLayout(), getI18n().get("caption.logs.tab"), null); } @@ -109,12 +103,12 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void onEdit(final ClickEvent event) { - if (selectedBaseEntity == null) { + if (getSelectedBaseEntity() == null) { return; } final Window newDistWindow = targetAddUpdateWindowLayout.getWindow(); - targetAddUpdateWindowLayout.populateValuesOfTarget(selectedBaseEntity.getControllerId()); - newDistWindow.setCaption(i18n.get("caption.update.dist")); + targetAddUpdateWindowLayout.populateValuesOfTarget(getSelectedBaseEntity().getControllerId()); + newDistWindow.setCaption(getI18n().get("caption.update.dist")); UI.getCurrent().addWindow(newDistWindow); newDistWindow.setVisible(Boolean.TRUE); } @@ -136,24 +130,24 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void populateDetailsWidget() { - if (selectedBaseEntity != null) { - updateDetailsLayout(selectedBaseEntity.getControllerId(), selectedBaseEntity.getTargetInfo().getAddress(), - selectedBaseEntity.getSecurityToken(), - SPDateTimeUtil.getFormattedDate(selectedBaseEntity.getTargetInfo().getLastTargetQuery())); + if (getSelectedBaseEntity() != null) { + updateDetailsLayout(getSelectedBaseEntity().getControllerId(), + getSelectedBaseEntity().getTargetInfo().getAddress(), getSelectedBaseEntity().getSecurityToken(), + SPDateTimeUtil.getFormattedDate(getSelectedBaseEntity().getTargetInfo().getLastTargetQuery())); populateDistributionDtls(installedDistLayout, - selectedBaseEntity.getTargetInfo().getInstalledDistributionSet()); - populateDistributionDtls(assignedDistLayout, selectedBaseEntity.getAssignedDistributionSet()); + getSelectedBaseEntity().getTargetInfo().getInstalledDistributionSet()); + populateDistributionDtls(assignedDistLayout, getSelectedBaseEntity().getAssignedDistributionSet()); } else { updateDetailsLayout(null, null, null, null); populateDistributionDtls(installedDistLayout, null); populateDistributionDtls(assignedDistLayout, null); } - updateAttributesLayout(selectedBaseEntity); + updateAttributesLayout(getSelectedBaseEntity()); } @Override protected String getName() { - return selectedBaseEntity.getName(); + return getSelectedBaseEntity().getName(); } private void updateDetailsLayout(final String controllerId, final URI address, final String securityToken, @@ -161,17 +155,18 @@ public class TargetDetails extends AbstractTableDetailsLayout { final VerticalLayout detailsTabLayout = getDetailsLayout(); detailsTabLayout.removeAllComponents(); - final Label controllerLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.target.id"), + final Label controllerLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.target.id"), HawkbitCommonUtil.trimAndNullIfEmpty(controllerId) == null ? "" : controllerId); controllerLabel.setId(SPUIComponetIdProvider.TARGET_CONTROLLER_ID); detailsTabLayout.addComponent(controllerLabel); - final Label lastPollDtLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.target.lastpolldate"), + final Label lastPollDtLabel = SPUIComponentProvider.createNameValueLabel( + getI18n().get("label.target.lastpolldate"), HawkbitCommonUtil.trimAndNullIfEmpty(lastQueryDate) == null ? "" : lastQueryDate); lastPollDtLabel.setId(SPUIComponetIdProvider.TARGET_LAST_QUERY_DT); detailsTabLayout.addComponent(lastPollDtLabel); - final Label typeLabel = SPUIComponentProvider.createNameValueLabel(i18n.get("label.ip"), + final Label typeLabel = SPUIComponentProvider.createNameValueLabel(getI18n().get("label.ip"), address == null ? StringUtils.EMPTY : address.toString()); typeLabel.setId(SPUIComponetIdProvider.TARGET_IP_ADDRESS); detailsTabLayout.addComponent(typeLabel); @@ -187,7 +182,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { final HorizontalLayout securityTokenLayout = new HorizontalLayout(); final Label securityTableLbl = new Label( - SPUIComponentProvider.getBoldHTMLText(i18n.get("label.target.security.token")), ContentMode.HTML); + SPUIComponentProvider.getBoldHTMLText(getI18n().get("label.target.security.token")), ContentMode.HTML); securityTableLbl.addStyleName(SPUIDefinitions.TEXT_STYLE); securityTableLbl.addStyleName("label-style"); @@ -207,18 +202,17 @@ public class TargetDetails extends AbstractTableDetailsLayout { private void populateDistributionDtls(final VerticalLayout layout, final DistributionSet distributionSet) { layout.removeAllComponents(); - if (distributionSet != null) { - // Display distribution set name - layout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.name"), - distributionSet.getName())); - - layout.addComponent(SPUIComponentProvider.createNameValueLabel(i18n.get("label.dist.details.version"), - distributionSet.getVersion())); - - /* Module info */ - distributionSet.getModules() - .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); + if (distributionSet == null) { + return; } + layout.addComponent(SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.name"), + distributionSet.getName())); + + layout.addComponent(SPUIComponentProvider.createNameValueLabel(getI18n().get("label.dist.details.version"), + distributionSet.getVersion())); + + distributionSet.getModules() + .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); } /** @@ -236,7 +230,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected Boolean hasEditPermission() { - return permissionChecker.hasUpdateTargetPermission(); + return getPermissionChecker().hasUpdateTargetPermission(); } @EventBusListenerMethod(scope = EventScope.SESSION) From b26cde62df32c0d8fb7306f1d24b89e944ad89a5 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 15:35:59 +0200 Subject: [PATCH 53/56] Use for float uppercase F Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractTable.java | 2 +- .../ui/distributions/smtable/SwModuleTable.java | 2 +- .../ui/management/dstable/DistributionTable.java | 15 +-------------- .../ui/management/targettable/TargetTable.java | 4 ++-- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 5aea8914f..eb1951d27 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -66,7 +66,7 @@ public abstract class AbstractTable extends Table { setStyleName("sp-table"); setSizeFull(); setImmediate(true); - setHeight(100.0f, Unit.PERCENTAGE); + setHeight(100.0F, Unit.PERCENTAGE); addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); addStyleName(ValoTheme.TABLE_SMALL); setSortEnabled(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 9c02f1d8a..a9a4562ce 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -229,7 +229,7 @@ public class SwModuleTable extends AbstractNamedVersionTable getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); if (isMaximized()) { - columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1f)); + columnList.add(new TableColumn(SPUILabelDefinitions.VAR_VENDOR, i18n.get("header.vendor"), 0.1F)); } else { columnList.add(new TableColumn(SPUILabelDefinitions.ARTIFACT_ICON, "", 0.1F)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 4ba164bde..1b856277e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -173,24 +173,11 @@ public class DistributionTable extends AbstractNamedVersionTable queryConfiguration = prepareQueryConfigFilters(); @@ -276,7 +263,7 @@ public class DistributionTable extends AbstractNamedVersionTable implements protected List getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); if (!isMaximized()) { - columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0f)); - columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0f)); + columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, "", 0.0F)); + columnList.add(new TableColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, "", 0.0F)); } return columnList; From 7731b549c327227277ca686d542f8d77936196e1 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 16:03:29 +0200 Subject: [PATCH 54/56] Use for float uppercase F Signed-off-by: SirWayne --- .../hawkbit/ui/common/table/AbstractNamedVersionTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java index 64460bc1c..3e215f77c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractNamedVersionTable.java @@ -31,7 +31,7 @@ public abstract class AbstractNamedVersionTable getTableVisibleColumns() { final List columnList = super.getTableVisibleColumns(); - final float versionColumnSize = isMaximized() ? 0.1f : 0.2f; + final float versionColumnSize = isMaximized() ? 0.1F : 0.2F; columnList .add(new TableColumn(SPUILabelDefinitions.VAR_VERSION, i18n.get("header.version"), versionColumnSize)); return columnList; From 313751a3fd38ea1469fe7838bbc8f35a513f1bbb Mon Sep 17 00:00:00 2001 From: SirWayne Date: Fri, 8 Apr 2016 16:05:38 +0200 Subject: [PATCH 55/56] fix typo Signed-off-by: SirWayne --- .../ui/common/detailslayout/AbstractTableDetailsLayout.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 615cba33f..969436904 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -110,7 +110,7 @@ public abstract class AbstractTableDetailsLayout extends } /** - * Default implementation to handle a entity event. + * Default implementation to handle an entity event. * * @param baseEntityEvent * the event @@ -127,9 +127,6 @@ public abstract class AbstractTableDetailsLayout extends } private void createComponents() { - /** - * Default caption is set.Reset on selecting table row. - */ caption = createHeaderCaption(); caption.setImmediate(true); caption.setContentMode(ContentMode.HTML); @@ -152,7 +149,6 @@ public abstract class AbstractTableDetailsLayout extends } private void buildLayout() { - final HorizontalLayout nameEditLayout = new HorizontalLayout(); nameEditLayout.setWidth(100.0f, Unit.PERCENTAGE); nameEditLayout.addComponent(caption); From 40478dd6752f2dbbccdf3f10952439aad165c06b Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Fri, 8 Apr 2016 17:15:15 +0200 Subject: [PATCH 56/56] Refactoring after review - changed label sentence - remove I18N to parent class - remove empty lines - set variable for configurationEnabledChange directly Signed-off-by: Jonathan Philip Knoblauch --- ...AuthenticationTenantConfigurationItem.java | 7 ++++++- ...wnloadAuthenticationConfigurationItem.java | 20 +++---------------- ...ficateAuthenticationConfigurationItem.java | 6 +----- ...yTokenAuthenticationConfigurationItem.java | 5 +---- ...yTokenAuthenticationConfigurationItem.java | 6 +----- .../src/main/resources/messages.properties | 2 +- .../src/main/resources/messages_de.properties | 2 +- .../src/main/resources/messages_en.properties | 2 +- 8 files changed, 15 insertions(+), 35 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java index 0907ebf9e..4f222f080 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java @@ -14,7 +14,9 @@ import java.util.List; 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.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.ui.VerticalLayout; @@ -30,6 +32,9 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay private static final long serialVersionUID = 1L; + @Autowired + private I18N i18n; + private final TenantConfigurationKey configurationKey; private final transient TenantConfigurationManagement tenantConfigurationManagement; @@ -53,7 +58,7 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay */ protected void init(final String labelText) { setImmediate(true); - addComponent(SPUIComponentProvider.getLabel(labelText, SPUILabelDefinitions.SP_LABEL_SIMPLE)); + addComponent(SPUIComponentProvider.getLabel(i18n.get(labelText), SPUILabelDefinitions.SP_LABEL_SIMPLE)); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java index b1da8e0ee..1180eba64 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AnonymousDownloadAuthenticationConfigurationItem.java @@ -12,7 +12,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -31,9 +30,6 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; - @Autowired - private I18N i18n; - @Autowired public AnonymousDownloadAuthenticationConfigurationItem( final TenantConfigurationManagement tenantConfigurationManagement) { @@ -42,26 +38,19 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu @PostConstruct public void init() { - - super.init(i18n.get("label.configuration.anonymous.download")); + super.init("label.configuration.anonymous.download"); configurationEnabled = isConfigEnabled(); - } @Override public void configEnable() { - - if (!configurationEnabled) { - configurationEnabledChange = true; - } + configurationEnabledChange = !configurationEnabled; configurationEnabled = true; } @Override public void configDisable() { - if (configurationEnabled) { - configurationEnabledChange = true; - } + configurationEnabledChange = configurationEnabled; configurationEnabled = false; } @@ -71,16 +60,13 @@ public class AnonymousDownloadAuthenticationConfigurationItem extends AbstractAu return; } getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); - } @Override public void undo() { - configurationEnabledChange = false; configurationEnabled = getTenantConfigurationManagement() .getConfigurationValue(getConfigurationKey(), Boolean.class).getValue(); - } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java index b17d9596f..438917072 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java @@ -13,7 +13,6 @@ import javax.annotation.PostConstruct; 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.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -35,9 +34,6 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti private static final long serialVersionUID = 1L; - @Autowired - private I18N i18n; - private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; private boolean configurationCaRootAuthorityChanged = false; @@ -60,7 +56,7 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti */ @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.header")); + super.init("label.configuration.auth.header"); configurationEnabled = isConfigEnabled(); detailLayout = new VerticalLayout(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java index 757460809..3fa87538c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java @@ -15,7 +15,6 @@ import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall; -import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -41,8 +40,6 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac @Autowired private transient SecurityTokenGenerator securityTokenGenerator; - @Autowired - private I18N i18n; private TextField gatewayTokenNameTextField; @@ -72,7 +69,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.gatewaytoken")); + super.init("label.configuration.auth.gatewaytoken"); configurationEnabled = isConfigEnabled(); detailLayout = new VerticalLayout(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java index 641982d73..9ca82e7ea 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java @@ -12,7 +12,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.spring.annotation.SpringComponent; @@ -28,9 +27,6 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract private static final long serialVersionUID = 1L; - @Autowired - private I18N i18n; - private boolean configurationEnabled = false; private boolean configurationEnabledChange = false; @@ -49,7 +45,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract */ @PostConstruct public void init() { - super.init(i18n.get("label.configuration.auth.targettoken")); + super.init("label.configuration.auth.targettoken"); configurationEnabled = isConfigEnabled(); } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index d2e36dd2d..25dabd354 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -161,7 +161,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 98ac9edb3..39661e3c9 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -159,7 +159,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index d6b4b1088..23df35ad2 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -160,7 +160,7 @@ label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy label.configuration.auth.gatewaytoken = Allow a gateway to authenticate and manage multiple targets through a gateway security token label.configuration.auth.targettoken = Allow targets to authenticate directly with their target security token -label.configuration.anonymous.download = Allow targets to download anonymous +label.configuration.anonymous.download = Allow targets to download artifacts without security credentials label.unsupported.browser.ie=Sorry! current browser is not supported. Please use Internet Explorer 11 and above # Checkbox label prefix with - checkbox