Refactored the code to fix the sonar issues.
Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
@@ -26,6 +26,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;
|
||||
@@ -184,6 +185,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), null, null, formLayout, i18n);
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
window.setCloseListener(() -> !isDuplicate());
|
||||
|
||||
nameTextField.setEnabled(!editSwModule);
|
||||
versionTextField.setEnabled(!editSwModule);
|
||||
@@ -199,21 +201,30 @@ 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)) {
|
||||
if (isDuplicate()) {
|
||||
uiNotifcation.displayValidationError(
|
||||
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
} else {
|
||||
final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name,
|
||||
version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
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;
|
||||
}
|
||||
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));
|
||||
return swModule != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout {
|
||||
public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<SoftwareModuleType> {
|
||||
|
||||
private static final long serialVersionUID = -5169398523815919367L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class);
|
||||
@@ -191,19 +191,30 @@ 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)) {
|
||||
if (!isDuplicate()) {
|
||||
createNewSWModuleType();
|
||||
}
|
||||
} else {
|
||||
updateSWModuleType(existingSMTypeByName);
|
||||
updateSWModuleType(findEntityByName());
|
||||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
int assignNumber = 0;
|
||||
final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview());
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.common;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -51,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;
|
||||
@@ -70,7 +70,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
* corner and a save and cancel button at the bottom. Is not intended to reuse.
|
||||
*
|
||||
*/
|
||||
public class CommonDialogWindow extends Window implements Serializable {
|
||||
public class CommonDialogWindow extends Window {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -94,15 +94,15 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
|
||||
private final ClickListener cancelButtonClickListener;
|
||||
|
||||
private final ClickListener closeClickListener = event -> close();
|
||||
private final ClickListener closeClickListener = event -> onCloseEvent(event);
|
||||
|
||||
private final transient Map<Component, Object> orginalValues;
|
||||
|
||||
private final List<AbstractField<?>> allComponents;
|
||||
|
||||
private final I18N i18n;
|
||||
|
||||
private boolean isDuplicate;
|
||||
|
||||
private transient CommonDialogWindowCloseListener closeListener;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -137,17 +137,29 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
init();
|
||||
}
|
||||
|
||||
public void setCloseListener(final CommonDialogWindowCloseListener closeListener) {
|
||||
this.closeListener = closeListener;
|
||||
}
|
||||
|
||||
private void onCloseEvent(final ClickEvent clickEvent) {
|
||||
if (!clickEvent.getButton().equals(saveButton)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (closeListener != null && !closeListener.canWindowClose()) {
|
||||
return;
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if(!isDuplicate){
|
||||
super.close();
|
||||
orginalValues.clear();
|
||||
removeListeners();
|
||||
allComponents.clear();
|
||||
this.saveButton.setEnabled(false);
|
||||
}else{
|
||||
isDuplicate = Boolean.FALSE;
|
||||
}
|
||||
super.close();
|
||||
orginalValues.clear();
|
||||
removeListeners();
|
||||
allComponents.clear();
|
||||
this.saveButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private void removeListeners() {
|
||||
@@ -217,7 +229,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
setModal(true);
|
||||
addStyleName("fontsize");
|
||||
setOrginaleValues();
|
||||
addListeners();
|
||||
addComponenetListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,12 +248,6 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
|
||||
}
|
||||
|
||||
protected void addListeners() {
|
||||
addComponenetListeners();
|
||||
addCloseListenerForSaveButton();
|
||||
addCloseListenerForCancelButton();
|
||||
}
|
||||
|
||||
protected void addCloseListenerForSaveButton() {
|
||||
saveButton.addClickListener(closeClickListener);
|
||||
}
|
||||
@@ -438,6 +444,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
FontAwesome.TIMES, SPUIButtonStyleNoBorderWithIcon.class);
|
||||
cancelButton.setSizeUndefined();
|
||||
cancelButton.addStyleName("default-color");
|
||||
addCloseListenerForCancelButton();
|
||||
if (cancelButtonClickListener != null) {
|
||||
cancelButton.addClickListener(cancelButtonClickListener);
|
||||
}
|
||||
@@ -452,6 +459,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
FontAwesome.SAVE, SPUIButtonStyleNoBorderWithIcon.class);
|
||||
saveButton.setSizeUndefined();
|
||||
saveButton.addStyleName("default-color");
|
||||
addCloseListenerForSaveButton();
|
||||
saveButton.addClickListener(saveButtonClickListener);
|
||||
saveButton.setEnabled(false);
|
||||
buttonsLayout.addComponent(saveButton);
|
||||
@@ -531,20 +539,16 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean.TRUE/Boolean.FALSE based on the entity saved in the window already exists.
|
||||
* @return isDuplicate
|
||||
* Called before the save happens.
|
||||
*
|
||||
*/
|
||||
public boolean getIsDuplicate() {
|
||||
return isDuplicate;
|
||||
@FunctionalInterface
|
||||
public interface CommonDialogWindowCloseListener {
|
||||
|
||||
/**
|
||||
* @return true/false based on the dialog window to be closed or not.
|
||||
*/
|
||||
boolean canWindowClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Boolean.TRUE/Boolean.FALSE based on the entity saved in the window already exists.
|
||||
* @param isDuplicate
|
||||
*/
|
||||
public void setIsDuplicate(final boolean isDuplicate) {
|
||||
this.isDuplicate = isDuplicate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.eclipse.hawkbit.ui.decorators;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
|
||||
import org.eclipse.hawkbit.ui.common.CustomCommonDialogWindow;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
@@ -48,33 +47,31 @@ public final class SPUIWindowDecorator {
|
||||
public static CommonDialogWindow getWindow(final String caption, final String id, final String type,
|
||||
final Component content, final ClickListener saveButtonClickListener,
|
||||
final ClickListener cancelButtonClickListener, final String helpLink, final AbstractLayout layout,
|
||||
final I18N i18n) {
|
||||
CommonDialogWindow window = null;
|
||||
if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) {
|
||||
window = new CustomCommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
|
||||
cancelButtonClickListener, layout, i18n);
|
||||
window.setDraggable(true);
|
||||
window.setClosable(true);
|
||||
} else {
|
||||
window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
|
||||
cancelButtonClickListener, layout, i18n);
|
||||
if (null != id) {
|
||||
window.setId(id);
|
||||
}
|
||||
if (SPUIDefinitions.CONFIRMATION_WINDOW.equals(type)) {
|
||||
window.setDraggable(false);
|
||||
window.setClosable(true);
|
||||
window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);
|
||||
final I18N i18n) {
|
||||
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
|
||||
cancelButtonClickListener, layout, i18n);
|
||||
|
||||
} else if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) {
|
||||
window.setDraggable(true);
|
||||
window.setClosable(true);
|
||||
}
|
||||
}
|
||||
return window;
|
||||
}
|
||||
if (SPUIDefinitions.CUSTOM_METADATA_WINDOW.equals(type)) {
|
||||
window.setCloseListener(() -> false);
|
||||
window.setDraggable(true);
|
||||
window.setClosable(true);
|
||||
} else {
|
||||
if (null != id) {
|
||||
window.setId(id);
|
||||
}
|
||||
if (SPUIDefinitions.CONFIRMATION_WINDOW.equals(type)) {
|
||||
window.setDraggable(false);
|
||||
window.setClosable(true);
|
||||
window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);
|
||||
|
||||
} else if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) {
|
||||
window.setDraggable(true);
|
||||
window.setClosable(true);
|
||||
}
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decorates window based on type.
|
||||
*
|
||||
|
||||
@@ -53,7 +53,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
|
||||
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<DistributionSetType> {
|
||||
|
||||
private static final long serialVersionUID = -5169398523815877767L;
|
||||
private static final String DIST_TYPE_NAME = "name";
|
||||
@@ -566,19 +566,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)) {
|
||||
if (!isDuplicate()) {
|
||||
createNewDistributionSetType();
|
||||
}
|
||||
} else {
|
||||
updateDistributionSetType(existingDistTypeByKey);
|
||||
updateDistributionSetType(findEntityByKey());
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
protected String getWindowCaption() {
|
||||
return i18n.get("caption.add.type");
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
@@ -55,7 +56,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
/**
|
||||
* Abstract class for create/update target tag layout.
|
||||
*/
|
||||
public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> extends CustomComponent
|
||||
implements ColorChangeListener, ColorSelector {
|
||||
private static final long serialVersionUID = 4229177824620576456L;
|
||||
private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name";
|
||||
@@ -464,6 +465,7 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
reset();
|
||||
window = SPUIWindowDecorator.getWindow(getWindowCaption(), null, SPUIDefinitions.CREATE_UPDATE_WINDOW, this,
|
||||
this::save, this::discard, null, mainLayout, i18n);
|
||||
window.setCloseListener(() -> !isDuplicate());
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -560,16 +562,23 @@ 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() }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
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;
|
||||
}
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
return Boolean.FALSE;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isDuplicate() {
|
||||
return isDuplicateByName();
|
||||
}
|
||||
|
||||
protected abstract E findEntityByName();
|
||||
|
||||
public String getColorPicked() {
|
||||
return colorPicked;
|
||||
}
|
||||
|
||||
@@ -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.components.SPUIComponentProvider;
|
||||
@@ -34,7 +32,7 @@ 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<E extends NamedEntity> extends AbstractCreateUpdateTagLayout {
|
||||
|
||||
private static final long serialVersionUID = 5732904956185988397L;
|
||||
|
||||
@@ -255,37 +253,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() }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
return Boolean.TRUE;
|
||||
uiNotification.displayValidationError(getDuplicateKeyErrorMessage(existingType));
|
||||
return true;
|
||||
}
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
return Boolean.FALSE;
|
||||
|
||||
return 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() }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
return Boolean.TRUE;
|
||||
} else if (existingType instanceof SoftwareModuleType) {
|
||||
uiNotification.displayValidationError(i18n.get("message.type.key.swmodule.duplicate.check",
|
||||
new Object[] { ((SoftwareModuleType) existingType).getKey() }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
return Boolean.FALSE;
|
||||
@Override
|
||||
protected boolean isDuplicate() {
|
||||
return isDuplicateByKey() || super.isDuplicate();
|
||||
}
|
||||
|
||||
protected abstract E findEntityByKey();
|
||||
|
||||
protected abstract String getDuplicateKeyErrorMessage(E existingType);
|
||||
|
||||
@Override
|
||||
protected void save(final ClickEvent event) {
|
||||
// is implemented in the inherited class
|
||||
|
||||
@@ -186,29 +186,30 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
* 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);
|
||||
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()));
|
||||
}
|
||||
/* 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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,24 +218,26 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
*/
|
||||
private void addNewDistribution() {
|
||||
editDistribution = Boolean.FALSE;
|
||||
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());
|
||||
|
||||
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() }));
|
||||
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist));
|
||||
}
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +263,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
|
||||
@@ -273,13 +279,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
distVersionTextField.addStyleName("v-textfield-error");
|
||||
notificationMessage.displayValidationError(
|
||||
i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +299,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
distsetTypeNameComboBox.removeStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR);
|
||||
descTextArea.clear();
|
||||
reqMigStepCheckbox.clear();
|
||||
|
||||
}
|
||||
|
||||
private void populateValuesOfDistribution(final Long editDistId) {
|
||||
@@ -322,6 +326,12 @@ 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();
|
||||
@@ -330,6 +340,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.dist"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), null, null, formLayout, i18n);
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
window.setCloseListener(() -> !isDuplicate());
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.vaadin.ui.UI;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout {
|
||||
public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdateTagLayout<DistributionSetTag> {
|
||||
|
||||
private static final long serialVersionUID = 444276149954167545L;
|
||||
|
||||
@@ -85,16 +85,20 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat
|
||||
*/
|
||||
@Override
|
||||
public void save(final ClickEvent event) {
|
||||
final DistributionSetTag existingDistTag = tagManagement.findDistributionSetTag(tagName.getValue());
|
||||
if (optiongroup.getValue().equals(createTagStr)) {
|
||||
if (!checkIsDuplicate(existingDistTag)) {
|
||||
if (!isDuplicate()) {
|
||||
createNewTag();
|
||||
}
|
||||
} else {
|
||||
updateExistingTag(existingDistTag);
|
||||
updateExistingTag(findEntityByName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DistributionSetTag findEntityByName() {
|
||||
return tagManagement.findDistributionSetTag(tagName.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new tag.
|
||||
*/
|
||||
|
||||
@@ -143,31 +143,33 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
/* 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<TargetIdName> s = new HashSet<>();
|
||||
s.add(newTarget.getTargetIdName());
|
||||
targetTable.setValue(s);
|
||||
|
||||
/* display success msg */
|
||||
uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() }));
|
||||
if (isDuplicate()) {
|
||||
return;
|
||||
}
|
||||
final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.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<TargetIdName> s = new HashSet<>();
|
||||
s.add(newTarget.getTargetIdName());
|
||||
targetTable.setValue(s);
|
||||
|
||||
/* 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 = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.target"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(), null, null, formLayout, i18n);
|
||||
window.setCloseListener(() -> !isDuplicate());
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -196,17 +198,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 }));
|
||||
window.setIsDuplicate(Boolean.TRUE);
|
||||
return false;
|
||||
} else {
|
||||
window.setIsDuplicate(Boolean.FALSE);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.vaadin.ui.Button.ClickEvent;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout {
|
||||
public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout<TargetTag> {
|
||||
|
||||
private static final long serialVersionUID = 2446682350481560235L;
|
||||
|
||||
@@ -102,16 +102,20 @@ 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)) {
|
||||
if (!isDuplicate()) {
|
||||
createNewTag();
|
||||
}
|
||||
} else {
|
||||
updateExistingTag(existingTag);
|
||||
updateExistingTag(findEntityByName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TargetTag findEntityByName() {
|
||||
return tagManagement.findTargetTag(tagName.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new tag.
|
||||
*/
|
||||
|
||||
@@ -706,28 +706,6 @@ public final class HawkbitCommonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate check - Unique Key.
|
||||
*
|
||||
* @param name
|
||||
* as string
|
||||
* @param version
|
||||
* as string
|
||||
* @param type
|
||||
* key as string
|
||||
* @return boolean as flag
|
||||
*/
|
||||
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.findSoftwareModuleTypeByName(type));
|
||||
boolean duplicate = false;
|
||||
if (swModule != null) {
|
||||
duplicate = true;
|
||||
}
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new base software module.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user