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 788d1d8d8..ccefb01a1 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 @@ -24,7 +24,7 @@ import org.eclipse.hawkbit.security.ControllerPreAuthenticatedGatewaySecurityTok import org.eclipse.hawkbit.security.ControllerPreAuthenticatedSecurityHeaderFilter; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.PreAuthTokenSourceTrustAuthenticationProvider; -import org.eclipse.hawkbit.security.PreAuthenficationFilter; +import org.eclipse.hawkbit.security.PreAuthentificationFilter; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; @@ -45,7 +45,7 @@ public class AmqpControllerAuthentfication { private final PreAuthTokenSourceTrustAuthenticationProvider preAuthenticatedAuthenticationProvider; - private final List filterChain = new ArrayList<>(); + private final List filterChain = new ArrayList<>(); @Autowired private ControllerManagement controllerManagement; @@ -107,7 +107,7 @@ public class AmqpControllerAuthentfication { */ public Authentication doAuthenticate(final TenantSecurityToken secruityToken) { PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(null, null); - for (final PreAuthenficationFilter filter : filterChain) { + for (final PreAuthentificationFilter filter : filterChain) { final PreAuthenticatedAuthenticationToken authenticationRest = createAuthentication(filter, secruityToken); if (authenticationRest != null) { authentication = authenticationRest; @@ -119,7 +119,7 @@ public class AmqpControllerAuthentfication { } - private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthenficationFilter filter, + private static PreAuthenticatedAuthenticationToken createAuthentication(final PreAuthentificationFilter filter, final TenantSecurityToken secruityToken) { if (!filter.isEnable(secruityToken)) { 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 9aa5c72f9..2f2726d98 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 @@ -68,7 +68,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac private final AntPathMatcher pathExtractor; - private PreAuthenficationFilter abstractControllerAuthenticationFilter; + private PreAuthentificationFilter abstractControllerAuthenticationFilter; /** * Constructor for sub-classes. @@ -111,7 +111,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac } } - protected abstract PreAuthenficationFilter createControllerAuthenticationFilter(); + protected abstract PreAuthentificationFilter createControllerAuthenticationFilter(); @Override protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response, 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 index 40fd1e555..7eb338e31 100644 --- 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 @@ -39,7 +39,7 @@ public class HttpControllerPreAuthenticateAnonymousDownloadFilter extends Abstra } @Override - protected PreAuthenficationFilter createControllerAuthenticationFilter() { + protected PreAuthentificationFilter createControllerAuthenticationFilter() { return new ControllerPreAuthenticatedAnonymousDownload(tenantConfigurationManagement, tenantAware, systemSecurityContext); } diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateSecurityTokenFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateSecurityTokenFilter.java index 1eb155b9a..8926506e1 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateSecurityTokenFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticateSecurityTokenFilter.java @@ -55,7 +55,7 @@ public class HttpControllerPreAuthenticateSecurityTokenFilter extends AbstractHt } @Override - protected PreAuthenficationFilter createControllerAuthenticationFilter() { + protected PreAuthentificationFilter createControllerAuthenticationFilter() { return new ControllerPreAuthenticateSecurityTokenFilter(tenantConfigurationManagement, controllerManagement, tenantAware, systemSecurityContext); } diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedGatewaySecurityTokenFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedGatewaySecurityTokenFilter.java index 930c66dca..985c04f34 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedGatewaySecurityTokenFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedGatewaySecurityTokenFilter.java @@ -43,7 +43,7 @@ public class HttpControllerPreAuthenticatedGatewaySecurityTokenFilter } @Override - protected PreAuthenficationFilter createControllerAuthenticationFilter() { + protected PreAuthentificationFilter createControllerAuthenticationFilter() { return new ControllerPreAuthenticatedGatewaySecurityTokenFilter(tenantConfigurationManagement, tenantAware, systemSecurityContext); } diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedSecurityHeaderFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedSecurityHeaderFilter.java index 162e2688d..d4221a2ca 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedSecurityHeaderFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpControllerPreAuthenticatedSecurityHeaderFilter.java @@ -54,7 +54,7 @@ public class HttpControllerPreAuthenticatedSecurityHeaderFilter extends Abstract } @Override - protected PreAuthenficationFilter createControllerAuthenticationFilter() { + protected PreAuthentificationFilter createControllerAuthenticationFilter() { return new ControllerPreAuthenticatedSecurityHeaderFilter(caCommonNameHeader, caAuthorityNameHeader, tenantConfigurationManagement, tenantAware, systemSecurityContext); } 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 9a1cd2aea..edf2ef034 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 @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; * * */ -public abstract class AbstractControllerAuthenticationFilter implements PreAuthenficationFilter { +public abstract class AbstractControllerAuthenticationFilter implements PreAuthentificationFilter { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractControllerAuthenticationFilter.class); 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 index cf55c47fb..4aed42c95 100644 --- 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 @@ -16,7 +16,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; * * @see DdiSecurityProperties */ -public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthenficationFilter { +public class ControllerPreAuthenticatedAnonymousFilter implements PreAuthentificationFilter { private final DdiSecurityProperties ddiSecurityConfiguration; 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/PreAuthentificationFilter.java similarity index 95% rename from hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthenficationFilter.java rename to hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/PreAuthentificationFilter.java index 5e4aacfa9..90f2acd50 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/PreAuthentificationFilter.java @@ -16,12 +16,9 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; /** - * Interface for Pre Authenfication. - * - * - * + * Interface for Pre Authentification. */ -public interface PreAuthenficationFilter { +public interface PreAuthentificationFilter { /** * Check if the filter is enabled. @@ -60,6 +57,6 @@ public interface PreAuthenficationFilter { */ default Collection getSuccessfulAuthenticationAuthorities() { return Collections.emptyList(); - }; + } } 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 a437c0039..a5e6af609 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 @@ -8,8 +8,6 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import java.io.Serializable; - import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.EntityFactory; @@ -17,6 +15,7 @@ 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.common.CommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; @@ -28,6 +27,7 @@ import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.UINotification; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; @@ -48,7 +48,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Serializable { +public class SoftwareModuleAddUpdateWindow extends CustomComponent { private static final long serialVersionUID = -5217675246477211483L; @@ -85,6 +85,25 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se private FormLayout formLayout; + /** + * Save or update the sw module. + */ + private final class SaveOnDialogCloseListener implements SaveDialogCloseListener { + @Override + public void saveOrUpdate() { + if (editSwModule) { + updateSwModule(); + return; + } + addNewBaseSoftware(); + } + + @Override + public boolean canWindowSaveOrUpdate() { + return editSwModule || !isDuplicate(); + } + } + /** * Initialize Distribution Add and Edit Window. */ @@ -180,12 +199,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se setCompositionRoot(formLayout); window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) - .caption(i18n.get("upload.caption.add.new.swmodule")).content(this) - .saveButtonClickListener(event -> saveOrUpdate()).layout(formLayout).i18n(i18n) - .buildCommonDialogWindow(); - - window.getButtonsLayout().removeStyleName("actionButtonsMargin"); - + .caption(i18n.get("upload.caption.add.new.swmodule")).content(this).layout(formLayout).i18n(i18n) + .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow(); nameTextField.setEnabled(!editSwModule); versionTextField.setEnabled(!editSwModule); typeComboBox.setEnabled(!editSwModule); @@ -200,19 +215,31 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; - if (HawkbitCommonUtil.isDuplicate(name, version, type)) { + final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, version, + vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); + if (newBaseSoftwareModule != null) { + /* display success message */ + uiNotifcation.displaySuccess(i18n.get("message.save.success", + new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() })); + eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule)); + } + } + + private boolean isDuplicate() { + final String name = nameTextField.getValue(); + final String version = versionTextField.getValue(); + final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; + + final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); + final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version, + swMgmtService.findSoftwareModuleTypeByName(type)); + + if (swModule != null) { uiNotifcation.displayValidationError( i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); - } else { - final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, - version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); - if (newBaseSoftwareModule != null) { - /* display success message */ - uiNotifcation.displaySuccess(i18n.get("message.save.success", - new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() })); - eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule)); - } + return true; } + return false; } /** @@ -254,14 +281,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se typeComboBox.setValue(swModle.getType().getName()); } - private void saveOrUpdate() { - if (editSwModule) { - updateSwModule(); - } else { - addNewBaseSoftware(); - } - } - public FormLayout getFormLayout() { return formLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index d3dfd8f5b..5f0442bb4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -34,7 +34,6 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; import com.vaadin.ui.OptionGroup; import com.vaadin.ui.TextField; @@ -47,7 +46,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { +public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { private static final long serialVersionUID = -5169398523815919367L; private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class); @@ -124,7 +123,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { super.optionValueChanged(event); - if (updateTypeStr.equals(event.getProperty().getValue())) { + if (updateTagStr.equals(event.getProperty().getValue())) { assignOptiongroup.setEnabled(false); } else { assignOptiongroup.setEnabled(true); @@ -192,18 +191,28 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { } @Override - protected void save(final ClickEvent event) { - final SoftwareModuleType existingSMTypeByKey = swTypeManagementService - .findSoftwareModuleTypeByKey(typeKey.getValue()); - final SoftwareModuleType existingSMTypeByName = swTypeManagementService - .findSoftwareModuleTypeByName(tagName.getValue()); - if (optiongroup.getValue().equals(createTypeStr)) { - if (!checkIsDuplicateByKey(existingSMTypeByKey) && !checkIsDuplicate(existingSMTypeByName)) { - createNewSWModuleType(); - } - } else { - updateSWModuleType(existingSMTypeByName); - } + protected void createEntity() { + createNewSWModuleType(); + } + + @Override + protected void updateEntity(final SoftwareModuleType entity) { + updateSWModuleType(entity); + } + + @Override + protected SoftwareModuleType findEntityByKey() { + return swTypeManagementService.findSoftwareModuleTypeByKey(typeKey.getValue()); + } + + @Override + protected SoftwareModuleType findEntityByName() { + return swTypeManagementService.findSoftwareModuleTypeByName(tagName.getValue()); + } + + @Override + protected String getDuplicateKeyErrorMessage(final SoftwareModuleType existingType) { + return i18n.get("message.type.key.swmodule.duplicate.check", new Object[] { existingType.getKey() }); } private void createNewSWModuleType() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 9b7473e5a..108e09a22 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -332,6 +332,7 @@ public class UploadStatusInfoWindow extends Window { restoreState(); } + @SuppressWarnings("unchecked") private void uploadRecevied(final String filename, final SoftwareModule softwareModule) { final Item item = uploads.addItem(getItemid(filename, softwareModule)); if (item != null) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java index 9283af715..7a1b52a7c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java @@ -16,6 +16,7 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; @@ -97,6 +98,27 @@ public abstract class AbstractMetadataPopupLayout onSave()) - .cancelButtonClickListener(event -> onCancel()).layout(mainLayout).i18n(i18n).buildCommonDialogWindow(); + metadataWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) + .caption(getMetadataCaption(nameVersion)).content(this).cancelButtonClickListener(event -> onCancel()) + .id(SPUIComponentIdProvider.METADATA_POPUP_ID).layout(mainLayout).i18n(i18n) + .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow(); - metadataWindow.setId(SPUIComponentIdProvider.METADATA_POPUP_ID); metadataWindow.setHeight(550, Unit.PIXELS); metadataWindow.setWidth(800, Unit.PIXELS); metadataWindow.getMainLayout().setSizeFull(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CommonDialogWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CommonDialogWindow.java index 34abbeb90..ba9de4539 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CommonDialogWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CommonDialogWindow.java @@ -50,6 +50,7 @@ import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; @@ -89,11 +90,9 @@ public class CommonDialogWindow extends Window { protected ValueChangeListener buttonEnableListener; - private final ClickListener saveButtonClickListener; - private final ClickListener cancelButtonClickListener; - private final ClickListener closeClickListener = event -> close(); + private final ClickListener closeClickListener = event -> onCloseEvent(event); private final transient Map orginalValues; @@ -101,6 +100,8 @@ public class CommonDialogWindow extends Window { private final I18N i18n; + private transient SaveDialogCloseListener closeListener; + /** * Constructor. * @@ -110,8 +111,8 @@ public class CommonDialogWindow extends Window { * the content * @param helpLink * the helpLinks - * @param saveButtonClickListener - * the saveButtonClickListener + * @param closeListener + * the saveDialogCloseListener * @param cancelButtonClickListener * the cancelButtonClickListener * @param layout @@ -120,13 +121,13 @@ public class CommonDialogWindow extends Window { * the i18n service */ public CommonDialogWindow(final String caption, final Component content, final String helpLink, - final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener, + final SaveDialogCloseListener closeListener, final ClickListener cancelButtonClickListener, final AbstractLayout layout, final I18N i18n) { - checkNotNull(saveButtonClickListener); + checkNotNull(closeListener); this.caption = caption; this.content = content; this.helpLink = helpLink; - this.saveButtonClickListener = saveButtonClickListener; + this.closeListener = closeListener; this.cancelButtonClickListener = cancelButtonClickListener; this.orginalValues = new HashMap<>(); this.allComponents = getAllComponents(layout); @@ -134,6 +135,23 @@ public class CommonDialogWindow extends Window { init(); } + private void onCloseEvent(final ClickEvent clickEvent) { + if (!clickEvent.getButton().equals(saveButton)) { + close(); + return; + } + + if (!closeListener.canWindowSaveOrUpdate()) { + return; + } + closeListener.saveOrUpdate(); + + if (closeListener.canWindowClose()) { + close(); + } + + } + @Override public void close() { super.close(); @@ -210,7 +228,7 @@ public class CommonDialogWindow extends Window { setModal(true); addStyleName("fontsize"); setOrginaleValues(); - addListeners(); + addComponentListeners(); } /** @@ -229,12 +247,6 @@ public class CommonDialogWindow extends Window { saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null)); } - protected void addListeners() { - addComponenetListeners(); - addCloseListenerForSaveButton(); - addCloseListenerForCancelButton(); - } - protected void addCloseListenerForSaveButton() { saveButton.addClickListener(closeClickListener); } @@ -243,7 +255,7 @@ public class CommonDialogWindow extends Window { cancelButton.addClickListener(closeClickListener); } - protected void addComponenetListeners() { + protected void addComponentListeners() { for (final AbstractField field : allComponents) { if (field instanceof TextChangeNotifier) { ((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field)); @@ -431,6 +443,7 @@ public class CommonDialogWindow extends Window { FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class); cancelButton.setSizeUndefined(); cancelButton.addStyleName("default-color"); + addCloseListenerForCancelButton(); if (cancelButtonClickListener != null) { cancelButton.addClickListener(cancelButtonClickListener); } @@ -445,7 +458,7 @@ public class CommonDialogWindow extends Window { FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class); saveButton.setSizeUndefined(); saveButton.addStyleName("default-color"); - saveButton.addClickListener(saveButtonClickListener); + addCloseListenerForSaveButton(); saveButton.setEnabled(false); buttonsLayout.addComponent(saveButton); buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT); @@ -505,7 +518,7 @@ public class CommonDialogWindow extends Window { * @param component * AbstractField */ - public void updateAllComponents(final AbstractField component) { + public void updateAllComponents(final AbstractField component) { allComponents.add(component); component.addValueChangeListener(new ChangeListener(component)); @@ -522,4 +535,36 @@ public class CommonDialogWindow extends Window { public void setCancelButtonEnabled(final boolean enabled) { cancelButton.setEnabled(enabled); } + + /** + * Check if the safe action can executed. After a the save action the + * listener checks if the dialog can closed. + * + */ + public interface SaveDialogCloseListener { + + /** + * Checks if the safe action can executed. + * + * @return = save action can executed = cannot execute + * safe action . + */ + boolean canWindowSaveOrUpdate(); + + /** + * Checks if the window can closed after the safe action is executed + * + * @return = window will close = will not closed. + */ + default boolean canWindowClose() { + return true; + } + + /** + * Saves/Updates action. Is called if canWindowSaveOrUpdate is . + * + */ + void saveOrUpdate(); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CustomCommonDialogWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CustomCommonDialogWindow.java deleted file mode 100644 index 8173735ca..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/CustomCommonDialogWindow.java +++ /dev/null @@ -1,33 +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.common; - -import org.eclipse.hawkbit.ui.utils.I18N; - -import com.vaadin.ui.AbstractLayout; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; - -public class CustomCommonDialogWindow extends CommonDialogWindow { - private static final long serialVersionUID = -4453608850403359992L; - - public CustomCommonDialogWindow(final String caption, final Component content, final String helpLink, - final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener, - final AbstractLayout layout, final I18N i18n) { - super(caption, content, helpLink, saveButtonClickListener, cancelButtonClickListener, layout, i18n); - } - - - @Override - protected void addListeners() { - addComponenetListeners(); - addCloseListenerForCancelButton(); - } - -} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/WindowBuilder.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/WindowBuilder.java index 113c33e3d..faef01ded 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/WindowBuilder.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/WindowBuilder.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.common.builder; import org.eclipse.hawkbit.ui.common.CommonDialogWindow; -import org.eclipse.hawkbit.ui.common.CustomCommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; @@ -26,7 +26,6 @@ public class WindowBuilder { private String caption; private Component content; - private ClickListener saveButtonClickListener; private ClickListener cancelButtonClickListener; private String helpLink; private AbstractLayout layout; @@ -34,6 +33,8 @@ public class WindowBuilder { private final String type; private String id; + private SaveDialogCloseListener saveDialogCloseListener; + /** * Constructor. * @@ -44,6 +45,18 @@ public class WindowBuilder { this.type = type; } + /** + * Set the SaveDialogCloseListener. + * + * @param saveDialogCloseListener + * the saveDialogCloseListener + * @return the window builder + */ + public WindowBuilder saveDialogCloseListener(final SaveDialogCloseListener saveDialogCloseListener) { + this.saveDialogCloseListener = saveDialogCloseListener; + return this; + } + /** * Set the caption. * @@ -68,18 +81,6 @@ public class WindowBuilder { return this; } - /** - * Set the saveButtonClickListener. - * - * @param saveButtonClickListener - * the saveButtonClickListener - * @return the window builder - */ - public WindowBuilder saveButtonClickListener(final ClickListener saveButtonClickListener) { - this.saveButtonClickListener = saveButtonClickListener; - return this; - } - /** * Set the cancelButtonClickListener. * @@ -143,20 +144,9 @@ public class WindowBuilder { * @return the window. */ public CommonDialogWindow buildCommonDialogWindow() { - CommonDialogWindow window; - - if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) { - window = new CustomCommonDialogWindow(caption, content, helpLink, saveButtonClickListener, - cancelButtonClickListener, layout, i18n); - window.setDraggable(true); - window.setClosable(true); - return window; - } - window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener, cancelButtonClickListener, - layout, i18n); - + final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveDialogCloseListener, + cancelButtonClickListener, layout, i18n); decorateWindow(window); - return window; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java index 0363aaa6c..9bff75ff2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java @@ -42,7 +42,6 @@ import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; @@ -56,7 +55,7 @@ import com.vaadin.ui.themes.ValoTheme; */ @SpringComponent @ViewScope -public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { +public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { private static final long serialVersionUID = -5169398523815877767L; private static final String DIST_TYPE_NAME = "name"; @@ -456,7 +455,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { super.optionValueChanged(event); - if (updateTypeStr.equals(event.getProperty().getValue())) { + if (updateTagStr.equals(event.getProperty().getValue())) { selectedTable.getContainerDataSource().removeAllItems(); getSourceTableData(); distTypeSelectLayout.setEnabled(false); @@ -568,18 +567,30 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { } @Override - protected void save(final ClickEvent event) { - final DistributionSetType existingDistTypeByKey = distributionSetManagement - .findDistributionSetTypeByKey(typeKey.getValue()); - final DistributionSetType existingDistTypeByName = distributionSetManagement - .findDistributionSetTypeByName(tagName.getValue()); - if (optiongroup.getValue().equals(createTypeStr)) { - if (!checkIsDuplicateByKey(existingDistTypeByKey) && !checkIsDuplicate(existingDistTypeByName)) { - createNewDistributionSetType(); - } - } else { - updateDistributionSetType(existingDistTypeByKey); - } + protected void updateEntity(final DistributionSetType entity) { + updateDistributionSetType(entity); + + } + + @Override + protected void createEntity() { + createNewDistributionSetType(); + + } + + @Override + protected DistributionSetType findEntityByKey() { + return distributionSetManagement.findDistributionSetTypeByKey(typeKey.getValue()); + } + + @Override + protected DistributionSetType findEntityByName() { + return distributionSetManagement.findDistributionSetTypeByName(tagName.getValue()); + } + + @Override + protected String getDuplicateKeyErrorMessage(final DistributionSetType existingType) { + return i18n.get("message.type.key.duplicate.check", new Object[] { existingType.getKey() }); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java index 32b4eee0b..0c4aa3111 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java @@ -13,12 +13,14 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerLayout; import org.eclipse.hawkbit.ui.common.CommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; @@ -55,10 +57,14 @@ import com.vaadin.ui.components.colorpicker.ColorSelector; import com.vaadin.ui.themes.ValoTheme; /** + * * Abstract class for create/update target tag layout. + * + * @param */ -public abstract class AbstractCreateUpdateTagLayout extends CustomComponent +public abstract class AbstractCreateUpdateTagLayout extends CustomComponent implements ColorChangeListener, ColorSelector { + private static final long serialVersionUID = 4229177824620576456L; private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name"; private static final String TAG_DESC_DYNAMIC_STYLE = "new-tag-desc"; @@ -105,14 +111,32 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent protected String tagNameValue; protected String tagDescValue; - protected abstract String getWindowCaption(); - /** - * Save new tag / update new tag. - * - * @param event + * + * Save or update the entity. */ - protected abstract void save(final Button.ClickEvent event); + private final class SaveOnDialogCloseListener implements SaveDialogCloseListener { + + @Override + public void saveOrUpdate() { + if (isUpdateAction()) { + updateEntity(findEntityByName()); + return; + } + + createEntity(); + } + + @Override + public boolean canWindowSaveOrUpdate() { + return isUpdateAction() || !isDuplicate(); + + } + + private boolean isUpdateAction() { + return !optiongroup.getValue().equals(createTagStr); + } + } /** * Discard the changes and close the popup. @@ -400,7 +424,7 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent * * @param colorPickedPreview */ - private void getTargetDynamicStyles(final String colorPickedPreview) { + private static void getTargetDynamicStyles(final String colorPickedPreview) { Page.getCurrent().getJavaScript() .execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview)); } @@ -463,9 +487,8 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent public CommonDialogWindow getWindow() { reset(); window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this) - .saveButtonClickListener(this::save).cancelButtonClickListener(event -> discard()).layout(mainLayout) - .i18n(i18n).buildCommonDialogWindow(); - + .cancelButtonClickListener(event -> discard()).layout(mainLayout).i18n(i18n) + .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow(); return window; } @@ -562,12 +585,19 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent getPreviewButtonColor(previewColor); } - protected Boolean checkIsDuplicate(final Tag existingTag) { - if (existingTag != null) { - displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() })); - return Boolean.TRUE; + private boolean isDuplicateByName() { + final E existingType = findEntityByName(); + if (existingType != null) { + uiNotification.displayValidationError( + i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() })); + return true; } - return Boolean.FALSE; + + return false; + } + + protected boolean isDuplicate() { + return isDuplicateByName(); } public String getColorPicked() { @@ -610,4 +640,12 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent public void removeColorChangeListener(final ColorChangeListener listener) { } + protected abstract E findEntityByName(); + + protected abstract String getWindowCaption(); + + protected abstract void updateEntity(E entity); + + protected abstract void createEntity(); + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java index e15dcffc3..51003fb58 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java @@ -8,9 +8,7 @@ */ package org.eclipse.hawkbit.ui.layouts; -import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.NamedEntity; -import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; @@ -23,24 +21,19 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.server.Page; import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.OptionGroup; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.components.colorpicker.ColorChangeEvent; import com.vaadin.ui.components.colorpicker.ColorSelector; -import com.vaadin.ui.themes.ValoTheme; /** * Superclass defining common properties and methods for creating/updating * types. */ -public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayout { +public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayout { private static final long serialVersionUID = 5732904956185988397L; - protected String createTypeStr; - protected String updateTypeStr; protected TextField typeKey; public static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name"; @@ -55,11 +48,10 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo @Override protected void createRequiredComponents() { - createTypeStr = i18n.get("label.create.type"); - updateTypeStr = i18n.get("label.update.type"); + createTagStr = i18n.get("label.create.type"); + updateTagStr = i18n.get("label.update.type"); comboLabel = new LabelBuilder().name(i18n.get("label.choose.type")).buildLabel(); colorLabel = new LabelBuilder().name(i18n.get("label.choose.type.color")).buildLabel(); - colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE); tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.get("label.combobox.type"), "", "", null, null, false, @@ -137,7 +129,7 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo @Override protected void optionValueChanged(final ValueChangeEvent event) { - if (updateTypeStr.equals(event.getProperty().getValue())) { + if (updateTagStr.equals(event.getProperty().getValue())) { tagName.clear(); tagDesc.clear(); typeKey.clear(); @@ -193,38 +185,6 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo typeKey.addStyleName(SPUIDefinitions.TYPE_KEY); } - /** - * create option group with Create tag/Update tag based on permissions. - */ - @Override - protected void createOptionGroup(final boolean hasCreatePermission, final boolean hasUpdatePermission) { - - optiongroup = new OptionGroup("Select Action"); - optiongroup.setId(SPUIComponentIdProvider.OPTION_GROUP); - optiongroup.addStyleName(ValoTheme.OPTIONGROUP_SMALL); - optiongroup.addStyleName("custom-option-group"); - optiongroup.setNullSelectionAllowed(false); - - if (hasCreatePermission) { - optiongroup.addItem(createTypeStr); - } - if (hasUpdatePermission) { - optiongroup.addItem(updateTypeStr); - } - setOptionGroupDefaultValue(hasCreatePermission, hasUpdatePermission); - } - - @Override - protected void setOptionGroupDefaultValue(final boolean hasCreatePermission, final boolean hasUpdatePermission) { - - if (hasCreatePermission) { - optiongroup.select(createTypeStr); - } - if (hasUpdatePermission && !hasCreatePermission) { - optiongroup.select(updateTypeStr); - } - } - protected void setColorPickerComponentsColor(final String color) { if (null == color) { @@ -257,37 +217,27 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo createDynamicStyleForComponents(tagName, typeKey, tagDesc, event.getColor().getCSS()); } - protected Boolean checkIsDuplicate(final NamedEntity existingType) { + private boolean isDuplicateByKey() { + + final E existingType = findEntityByKey(); if (existingType != null) { - uiNotification.displayValidationError( - i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() })); - return Boolean.TRUE; + uiNotification.displayValidationError(getDuplicateKeyErrorMessage(existingType)); + return true; } - return Boolean.FALSE; - } - protected Boolean checkIsDuplicateByKey(final NamedEntity existingType) { - - if (existingType != null) { - if (existingType instanceof DistributionSetType) { - uiNotification.displayValidationError(i18n.get("message.type.key.duplicate.check", - new Object[] { ((DistributionSetType) existingType).getKey() })); - return Boolean.TRUE; - } else if (existingType instanceof SoftwareModuleType) { - uiNotification.displayValidationError(i18n.get("message.type.key.swmodule.duplicate.check", - new Object[] { ((SoftwareModuleType) existingType).getKey() })); - return Boolean.TRUE; - } - } - return Boolean.FALSE; + return false; } @Override - protected void save(final ClickEvent event) { - // is implemented in the inherited class + protected boolean isDuplicate() { + return isDuplicateByKey() || super.isDuplicate(); } + protected abstract E findEntityByKey(); + + protected abstract String getDuplicateKeyErrorMessage(E existingType); + @Override protected void populateTagNameCombo() { // is implemented in the inherited class 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 f41132f7e..1b96181b5 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 @@ -18,11 +18,11 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; 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.CommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; @@ -41,8 +41,6 @@ import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.UINotification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -68,8 +66,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { private static final long serialVersionUID = -5602182034230568435L; - private static final Logger LOG = LoggerFactory.getLogger(DistributionAddUpdateWindowLayout.class); - @Autowired private I18N i18n; @@ -87,6 +83,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { @Autowired private transient EntityFactory entityFactory; + private TextField distNameTextField; private TextField distVersionTextField; private TextArea descTextArea; @@ -98,6 +95,27 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { private FormLayout formLayout; + /** + * Save or update distribution set. + * + */ + private final class SaveOnCloseDialogListener implements SaveDialogCloseListener { + @Override + public void saveOrUpdate() { + if (editDistribution) { + updateDistribution(); + return; + } + addNewDistribution(); + } + + @Override + public boolean canWindowSaveOrUpdate() { + return !isDuplicate(); + } + + } + /** * Initialize Distribution Add and Edit Window. */ @@ -178,42 +196,30 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { return tenantMetaData.getDefaultDsType(); } - private void saveDistribution() { - if (editDistribution) { - updateDistribution(); - } else { - addNewDistribution(); - } - } - /** * Update Distribution. */ private void updateDistribution() { + + if (isDuplicate()) { + return; + } final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue()); final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue()); final String distSetTypeName = HawkbitCommonUtil .trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue()); + final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId); + final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - if (duplicateCheck(name, version)) { - final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId); - final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); - final boolean isMigStepReq = reqMigStepCheckbox.getValue(); + /* identify the changes */ + setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq); + distributionSetManagement.updateDistributionSet(currentDS); + 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(BaseEntityEventType.UPDATED_ENTITY, currentDS)); - /* identify the changes */ - setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq); - try { - distributionSetManagement.updateDistributionSet(currentDS); - 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(BaseEntityEventType.UPDATED_ENTITY, currentDS)); - } catch (final EntityAlreadyExistsException entityAlreadyExistsException) { - LOG.error("Update distribution failed {}", entityAlreadyExistsException); - notificationMessage.displayValidationError( - i18n.get("message.distribution.no.update", currentDS.getName() + ":" + currentDS.getVersion())); - } - } } /** @@ -221,27 +227,26 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { */ private void addNewDistribution() { editDistribution = Boolean.FALSE; + final String name = HawkbitCommonUtil.trimAndNullIfEmpty(distNameTextField.getValue()); final String version = HawkbitCommonUtil.trimAndNullIfEmpty(distVersionTextField.getValue()); final String distSetTypeName = HawkbitCommonUtil .trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue()); - if (duplicateCheck(name, version)) { - final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); - final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - DistributionSet newDist = entityFactory.generateDistributionSet(); + final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final boolean isMigStepReq = reqMigStepCheckbox.getValue(); + DistributionSet newDist = entityFactory.generateDistributionSet(); - setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq); - newDist = distributionSetManagement.createDistributionSet(newDist); + setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq); + newDist = distributionSetManagement.createDistributionSet(newDist); - notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success", - new Object[] { newDist.getName(), newDist.getVersion() })); + notificationMessage.displaySuccess( + i18n.get("message.new.dist.save.success", new Object[] { newDist.getName(), newDist.getVersion() })); - final Set s = new HashSet<>(); - s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion())); - final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class); - distributionSetTable.setValue(s); - } + final Set s = new HashSet<>(); + s.add(new DistributionSetIdName(newDist.getId(), newDist.getName(), newDist.getVersion())); + final DistributionSetTable distributionSetTable = SpringContextHelper.getBean(DistributionSetTable.class); + distributionSetTable.setValue(s); } /** @@ -267,7 +272,10 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { distributionSet.setRequiredMigrationStep(isMigStepReq); } - private boolean duplicateCheck(final String name, final String version) { + private boolean isDuplicate() { + final String name = distNameTextField.getValue(); + final String version = distVersionTextField.getValue(); + final DistributionSet existingDs = distributionSetManagement.findDistributionSetByNameAndVersion(name, version); /* * Distribution should not exists with the same name & version. Display @@ -276,15 +284,16 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { * distribution Id of the edit window is different then the "existingDs" */ if (existingDs != null && !existingDs.getId().equals(editDistId)) { - distNameTextField.addStyleName("v-textfield-error"); - distVersionTextField.addStyleName("v-textfield-error"); + distNameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT); + distVersionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT); notificationMessage.displayValidationError( i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() })); - return false; - } else { return true; } + + return false; + } /** @@ -293,13 +302,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { public void resetComponents() { editDistribution = Boolean.FALSE; distNameTextField.clear(); - distNameTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR); + distNameTextField.removeStyleName("v-textfield-error"); distVersionTextField.clear(); - distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR); - distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR); + distVersionTextField.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT); + distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT); descTextArea.clear(); reqMigStepCheckbox.clear(); - } private void populateValuesOfDistribution(final Long editDistId) { @@ -327,17 +335,21 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { } } + /** + * Returns the dialog window for the distributions. + * + * @param editDistId + * @return window + */ public CommonDialogWindow getWindow(final Long editDistId) { eventBus.publish(this, DragEvent.HIDE_DROP_HINT); resetComponents(); populateDistSetTypeNameCombo(); populateValuesOfDistribution(editDistId); - window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.dist")) - .content(this).saveButtonClickListener(event -> saveDistribution()).layout(formLayout).i18n(i18n) + .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnCloseDialogListener()) .buildCommonDialogWindow(); - window.getButtonsLayout().removeStyleName("actionButtonsMargin"); return window; } 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 1087f9dbd..b6b616417 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 @@ -137,9 +137,9 @@ public class DistributionTable extends AbstractNamedVersionTable e.getId().equals(ds.getId())).findFirst() .isPresent(); - if ((ds.isComplete() && !dsVisible)) { + if (ds.isComplete() && !dsVisible) { refreshDistributions(); - } else if ((!ds.isComplete() && dsVisible)) { + } else if (!ds.isComplete() && dsVisible) { refreshDistributions(); if (ds.getId().equals(managementUIState.getLastSelectedDsIdName().getId())) { managementUIState.setLastSelectedDistribution(null); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java index f56cd0ae7..ee11ff24e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java @@ -36,7 +36,7 @@ import com.vaadin.ui.UI; */ @SpringComponent @ViewScope -public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout { +public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout { private static final long serialVersionUID = 444276149954167545L; @@ -80,19 +80,21 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat optiongroup.addValueChangeListener(this::optionValueChanged); } - /** - * Update DistributionTag. - */ @Override - public void save(final ClickEvent event) { - final DistributionSetTag existingDistTag = tagManagement.findDistributionSetTag(tagName.getValue()); - if (optiongroup.getValue().equals(createTagStr)) { - if (!checkIsDuplicate(existingDistTag)) { - createNewTag(); - } - } else { - updateExistingTag(existingDistTag); - } + protected void createEntity() { + createNewTag(); + + } + + @Override + protected void updateEntity(final DistributionSetTag entity) { + updateExistingTag(findEntityByName()); + + } + + @Override + protected DistributionSetTag findEntityByName() { + return tagManagement.findDistributionSetTag(tagName.getValue()); } /** 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 753b9aea2..25693dbcb 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 @@ -16,6 +16,7 @@ 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.CommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; @@ -46,6 +47,7 @@ import com.vaadin.ui.Window; @SpringComponent @VaadinSessionScope public class TargetAddUpdateWindowLayout extends CustomComponent { + private static final long serialVersionUID = -6659290471705262389L; @Autowired @@ -66,11 +68,31 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { private TextField controllerIDTextField; private TextField nameTextField; private TextArea descTextArea; - private boolean editTarget = Boolean.FALSE; + private boolean editTarget; private String controllerId; private FormLayout formLayout; private CommonDialogWindow window; + /** + * Save or update the target. + */ + private final class SaveOnDialogCloseListener implements SaveDialogCloseListener { + @Override + public void saveOrUpdate() { + if (editTarget) { + updateTarget(); + return; + } + addNewTarget(); + } + + @Override + public boolean canWindowSaveOrUpdate() { + return editTarget || !isDuplicate(); + } + + } + /** * Initialize the Add Update Window Component for Target. */ @@ -125,45 +147,42 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget)); } - private void saveTargetListner() { - if (editTarget) { - updateTarget(); - } else { - addNewTarget(); - } - } - private void addNewTarget() { final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue()); - if (duplicateCheck(newControlllerId)) { - final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); - final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); + final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); - /* create new target entity */ - Target newTarget = entityFactory.generateTarget(newControlllerId); - /* set values to the new target entity */ - setTargetValues(newTarget, newName, newDesc); - /* save new target */ - newTarget = targetManagement.createTarget(newTarget); - final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class); - final Set s = new HashSet<>(); - s.add(newTarget.getTargetIdName()); - targetTable.setValue(s); + /* create new target entity */ + Target newTarget = entityFactory.generateTarget(newControlllerId); + /* set values to the new target entity */ + setTargetValues(newTarget, newName, newDesc); + /* save new target */ + newTarget = targetManagement.createTarget(newTarget); + final TargetTable targetTable = SpringContextHelper.getBean(TargetTable.class); + final Set s = new HashSet<>(); + s.add(newTarget.getTargetIdName()); + targetTable.setValue(s); - /* display success msg */ - uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() })); - } + /* display success msg */ + uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() })); } public Window getWindow() { eventBus.publish(this, DragEvent.HIDE_DROP_HINT); window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.target")) - .content(this).saveButtonClickListener(event -> saveTargetListner()).layout(formLayout).i18n(i18n) + .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnDialogCloseListener()) .buildCommonDialogWindow(); return window; } + /** + * Returns Target Update window based on the selected Entity Id in the + * target table. + * + * @param entityId + * @return window + */ public Window getWindow(final String entityId) { populateValuesOfTarget(entityId); getWindow(); @@ -189,15 +208,17 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { target.setDescription(description); } - private boolean duplicateCheck(final String newControlllerId) { + private boolean isDuplicate() { + final String newControlllerId = controllerIDTextField.getValue(); final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim()); if (existingTarget != null) { uINotification.displayValidationError( i18n.get("message.target.duplicate.check", new Object[] { newControlllerId })); - return false; - } else { return true; + } else { + return false; } + } /** 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 e2f642296..26211f67d 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 @@ -103,9 +103,7 @@ public class TargetTable extends AbstractTable { private static final Logger LOG = LoggerFactory.getLogger(TargetTable.class); private static final String TARGET_PINNED = "targetPinned"; - private static final long serialVersionUID = -2300392868806614568L; - private static final int PROPERTY_DEPT = 3; @Autowired @@ -121,7 +119,6 @@ public class TargetTable extends AbstractTable { private ManagementViewAcceptCriteria managementViewAcceptCriteria; private Button targetPinnedBtn; - private Boolean isTargetPinned = Boolean.FALSE; @Override @@ -228,17 +225,14 @@ public class TargetTable extends AbstractTable { protected Container createContainer() { // ADD all the filters to the query config final Map queryConfig = prepareQueryConfigFilters(); - // Create TargetBeanQuery factory with the query config. final BeanQueryFactory targetQF = new BeanQueryFactory<>(TargetBeanQuery.class); targetQF.setQueryConfiguration(queryConfig); - // create lazy query container with lazy defination and query final LazyQueryContainer targetTableContainer = new LazyQueryContainer( new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_CONT_ID_NAME), targetQF); targetTableContainer.getQueryView().getQueryDefinition().setMaxNestedPropertyDepth(PROPERTY_DEPT); - return targetTableContainer; } @@ -319,7 +313,6 @@ public class TargetTable extends AbstractTable { shouldRefreshTargets = true; } } - if (shouldRefreshTargets) { refreshOnDelete(); } else { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java index f96c3b174..8aed0896d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java @@ -26,7 +26,6 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; -import com.vaadin.ui.Button.ClickEvent; /** * @@ -34,7 +33,7 @@ import com.vaadin.ui.Button.ClickEvent; */ @SpringComponent @ViewScope -public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout { +public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout { private static final long serialVersionUID = 2446682350481560235L; @@ -101,15 +100,18 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa } @Override - public void save(final ClickEvent event) { - final TargetTag existingTag = tagManagement.findTargetTag(tagName.getValue()); - if (optiongroup.getValue().equals(createTagStr)) { - if (!checkIsDuplicate(existingTag)) { - createNewTag(); - } - } else { - updateExistingTag(existingTag); - } + protected void updateEntity(final TargetTag entity) { + updateExistingTag(entity); + } + + @Override + protected void createEntity() { + createNewTag(); + } + + @Override + protected TargetTag findEntityByName() { + return tagManagement.findTargetTag(tagName.getValue()); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index b685f770b..86eeec403 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.common.CommonDialogWindow; +import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; @@ -144,6 +145,28 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private final NullValidator nullValidator = new NullValidator(null, false); + /** + * Save or update the rollout. + */ + private final class SaveOnDialogCloseListener implements SaveDialogCloseListener { + @Override + public void saveOrUpdate() { + if (editRolloutEnabled) { + editRollout(); + return; + } + createRollout(); + } + + @Override + public boolean canWindowSaveOrUpdate() { + if (editRolloutEnabled) { + return duplicateCheckForEdit(); + } + return duplicateCheck(); + } + } + /** * Create components and layout. */ @@ -168,9 +191,11 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { public CommonDialogWindow getWindow() { resetComponents(); - return new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.configure.rollout")) - .content(this).saveButtonClickListener(event -> onRolloutSave()).layout(this).i18n(i18n) - .helpLink(uiProperties.getLinks().getDocumentation().getRolloutView()).buildCommonDialogWindow(); + final CommonDialogWindow commonDialogWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) + .caption(i18n.get("caption.configure.rollout")).content(this).layout(this).i18n(i18n) + .helpLink(uiProperties.getLinks().getDocumentation().getRolloutView()) + .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow(); + return commonDialogWindow; } /** @@ -395,35 +420,27 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { targetFilterQF); } - private void onRolloutSave() { - if (editRolloutEnabled) { - editRollout(); - } else { - createRollout(); - } - } - private void editRollout() { - if (duplicateCheckForEdit() && rolloutForEdit != null) { - rolloutForEdit.setName(rolloutName.getValue()); - rolloutForEdit.setDescription(description.getValue()); - final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue(); - rolloutForEdit.setDistributionSet( - distributionSetManagement.findDistributionSetById(distributionSetIdName.getId())); - rolloutForEdit.setActionType(getActionType()); - rolloutForEdit.setForcedTime(getForcedTimeStamp()); - final int amountGroup = Integer.parseInt(noOfGroups.getValue()); - final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup); - - for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) { - rolloutGroup.setErrorConditionExp(triggerThreshold.getValue()); - rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent)); - } - final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit); - uiNotification - .displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() })); - eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT); + if (rolloutForEdit == null) { + return; } + rolloutForEdit.setName(rolloutName.getValue()); + rolloutForEdit.setDescription(description.getValue()); + final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue(); + rolloutForEdit + .setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetIdName.getId())); + rolloutForEdit.setActionType(getActionType()); + rolloutForEdit.setForcedTime(getForcedTimeStamp()); + final int amountGroup = Integer.parseInt(noOfGroups.getValue()); + final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup); + + for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) { + rolloutGroup.setErrorConditionExp(triggerThreshold.getValue()); + rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent)); + } + final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit); + uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() })); + eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT); } private boolean duplicateCheckForEdit() { @@ -449,11 +466,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private void createRollout() { - if (duplicateCheck()) { - final Rollout rolloutToCreate = saveRollout(); - uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() })); - eventBus.publish(this, RolloutEvent.CREATE_ROLLOUT); - } + final Rollout rolloutToCreate = saveRollout(); + uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() })); } private Rollout saveRollout() { 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 3270e07b4..e20d4cbae 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 @@ -49,7 +49,6 @@ import com.vaadin.ui.UI; * Common util class. */ public final class HawkbitCommonUtil { - /** * Define spaced string. */ @@ -58,21 +57,17 @@ public final class HawkbitCommonUtil { * Define empty string. */ public static final String SP_STRING_EMPTY = ""; - /** * Html span. */ public static final String SPAN_CLOSE = ""; - public static final String HTML_LI_CLOSE_TAG = ""; public static final String HTML_LI_OPEN_TAG = "
  • "; public static final String HTML_UL_CLOSE_TAG = ""; public static final String HTML_UL_OPEN_TAG = "
      "; private static final String JS_DRAG_COUNT_REM_CHILD = " if(x) { document.head.removeChild(x); } "; - public static final String DIV_DESCRIPTION_START = "

      "; - public static final String DIV_DESCRIPTION_END = "

      "; private static final String DRAG_COUNT_ELEMENT = "var x = document.getElementById('sp-drag-count'); "; @@ -119,7 +114,7 @@ public final class HawkbitCommonUtil { /** * Trim the text and convert into null in case of empty string. - * + * * @param text * as text to be trimed * @return null if the text is null or if the text is blank, text.trim() if @@ -136,7 +131,7 @@ public final class HawkbitCommonUtil { /** * Concatenate the given text all the string arguments with the given * delimiter. - * + * * @param delimiter * the delimiter text to be used while concatenation. * @param texts @@ -162,7 +157,7 @@ public final class HawkbitCommonUtil { /** * Returns the input text within html bold tag ... - * + * * @param text * is the text to be converted in to Bold * @return null if the input text param is null returns text with ... @@ -181,7 +176,7 @@ public final class HawkbitCommonUtil { /** * Get target label Id. - * + * * @param controllerId * as String * @return String as label name @@ -192,7 +187,7 @@ public final class HawkbitCommonUtil { /** * Get distribution table cell id. - * + * * @param name * distribution name * @param version @@ -205,7 +200,7 @@ public final class HawkbitCommonUtil { /** * Get software module label id. - * + * * @param name * software module name * @param version @@ -218,7 +213,7 @@ public final class HawkbitCommonUtil { /** * Get label with software module name and description. - * + * * @param name * software module name * @param desc @@ -233,7 +228,7 @@ public final class HawkbitCommonUtil { /** * Get Label for Artifact Details. - * + * * @param name * @return */ @@ -245,7 +240,7 @@ public final class HawkbitCommonUtil { /** * Get Label for Artifact Details. - * + * * @param caption * as caption of the details * @param name @@ -260,7 +255,7 @@ public final class HawkbitCommonUtil { /** * Get Label for Action History Details. - * + * * @param name * @return */ @@ -272,7 +267,7 @@ public final class HawkbitCommonUtil { /** * Get tool tip for Poll status. - * + * * @param pollStatus * @param i18N * @return @@ -290,7 +285,7 @@ public final class HawkbitCommonUtil { /** * Null check for text. - * + * * @param orgText * text to be formatted * @return String formatted text @@ -302,7 +297,7 @@ public final class HawkbitCommonUtil { /** * Find extra height required to increase by all the components to utilize * the full height of browser for the responsive UI. - * + * * @param newBrowserHeight * as current browser height. * @return extra height required to increase. @@ -314,7 +309,7 @@ public final class HawkbitCommonUtil { /** * Find required extra height of software module. - * + * * @param newBrowserHeight * new browser height * @return float heigth of software module table @@ -354,8 +349,6 @@ public final class HawkbitCommonUtil { } /** - * - * * @param newBrowserHeight * new browser height * @param minPopupHeight @@ -401,7 +394,7 @@ public final class HawkbitCommonUtil { /** * Get target table width based on screen width. - * + * * @param newBrowserWidth * new browser width. * @param minTargetTableLength @@ -554,7 +547,7 @@ public final class HawkbitCommonUtil { /** * Duplicate check - Unique Key. - * + * * @param name * as string * @param version @@ -635,11 +628,9 @@ public final class HawkbitCommonUtil { 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.getAssignedEntity().get(0).getName(), tagName })).append("
      "); - } else if (assignedCount > 1) { formMsg.append(i18n.get("message.target.assigned.many", new Object[] { assignedCount, tagName })) .append("
      "); @@ -650,11 +641,9 @@ public final class HawkbitCommonUtil { formMsg.append(alreadyAssigned).append("
      "); } } - if (unassignedCount == 1) { formMsg.append(i18n.get("message.target.unassigned.one", new Object[] { result.getUnassignedEntity().get(0).getName(), tagName })).append("
      "); - } else if (unassignedCount > 1) { formMsg.append(i18n.get("message.target.unassigned.many", new Object[] { unassignedCount, tagName })) .append("
      "); @@ -679,7 +668,6 @@ public final class HawkbitCommonUtil { } /** - * * Create lazy query container for DS type. * * @param queryFactory diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java index 4c7c02aa8..f2e26564f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java @@ -1024,11 +1024,6 @@ public final class SPUIDefinitions { */ public static final String SOFTWAREMODULE_METADATA_TAB_ID = "swModule.metadata.tab.id"; - /*** - * Custom window for metadata. - */ - public static final String CUSTOM_METADATA_WINDOW = "custom.metadata.window"; - /** * /** Constructor. */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java index 2541348b6..4c8c0ac0b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java @@ -31,6 +31,8 @@ public final class SPUIStyleDefinitions { */ public static final String SP_TEXTFIELD_ERROR = "textfield-error"; + public static final String SP_TEXTFIELD_LAYOUT_ERROR_HIGHTLIGHT = "v-textfield-error"; + /** * STYLE to highlight wrong data combo box field. */ @@ -136,11 +138,11 @@ public final class SPUIStyleDefinitions { * Artifact Details icon in Distribution View. */ public static final String ARTIFACT_DTLS_ICON = "swm-artifact-dtls-icon"; - - /** - * Distribution metadata icon style. - */ - public static final String DS_METADATA_ICON = "ds-metadata-icon"; + + /** + * Distribution metadata icon style. + */ + public static final String DS_METADATA_ICON = "ds-metadata-icon"; /** * Target table style. @@ -302,11 +304,11 @@ public final class SPUIStyleDefinitions { * Grid style. */ public static final String METADATA_GRID = "metadata-grid"; - + /** * Footer layout style. */ - public static final String FOOTER_LAYOUT = "footer-layout"; + public static final String FOOTER_LAYOUT = "footer-layout"; /** * Constructor.