Fix issues in rollout creation dialog (#1329)

* Introduce text input converter and validator to prevent problems with rollout group definitions.
* Add 2023 bosch.io license
* add new header to pom
* Extend usage of new TrimmingStringConverter.
* fixed compile error
This commit is contained in:
Michael Herdt
2023-03-17 15:41:27 +01:00
committed by GitHub
parent e80bef6156
commit d567b32280
45 changed files with 229 additions and 178 deletions

View File

@@ -23,7 +23,6 @@ import org.eclipse.hawkbit.ui.common.event.EventView;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload.SelectionChangedEventType;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.springframework.util.StringUtils;
/**
* Controller for populating and saving data in Add Software Module Window.
@@ -110,10 +109,10 @@ public class AddSmWindowController
@Override
protected boolean isEntityValid(final ProxySoftwareModule entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
final String name = entity.getName();
final String version = entity.getVersion();
final Long typeId = entity.getTypeInfo().getId();
return validator.isEntityValid(entity,
() -> smManagement.getByNameAndVersionAndType(trimmedName, trimmedVersion, typeId).isPresent());
() -> smManagement.getByNameAndVersionAndType(name, version, typeId).isPresent());
}
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxySoftwareModule;
import org.springframework.util.StringUtils;
@@ -38,10 +38,8 @@ public class ProxySmValidator extends EntityValidator {
return false;
}
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
if (duplicateCheck.getAsBoolean()) {
displayValidationError("message.duplicate.softwaremodule", trimmedName, trimmedVersion);
displayValidationError("message.duplicate.softwaremodule", entity.getName(), entity.getVersion());
return false;
}

View File

@@ -14,6 +14,7 @@ import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.data.providers.SoftwareModuleTypeDataProvider;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxySoftwareModule;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTypeInfo;
import org.eclipse.hawkbit.ui.utils.TrimmingStringConverter;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
@@ -100,7 +101,8 @@ public class SmWindowLayoutComponentBuilder {
.prompt(i18n.getMessage(TEXTFIELD_VENDOR)).buildTextComponent();
smVendor.setSizeUndefined();
binder.forField(smVendor).bind(ProxySoftwareModule::getVendor, ProxySoftwareModule::setVendor);
binder.forField(smVendor).withConverter(new TrimmingStringConverter()).bind(ProxySoftwareModule::getVendor,
ProxySoftwareModule::setVendor);
return smVendor;
}

View File

@@ -17,7 +17,6 @@ import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxySoftwareModule;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.springframework.util.StringUtils;
/**
* Controller for update software module window
@@ -106,11 +105,11 @@ public class UpdateSmWindowController
@Override
protected boolean isEntityValid(final ProxySoftwareModule entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
final String name = entity.getName();
final String version = entity.getVersion();
final Long typeId = entity.getTypeInfo().getId();
return validator.isEntityValid(entity, () -> hasNameOrVersionChanged(trimmedName, trimmedVersion)
&& smManagement.getByNameAndVersionAndType(trimmedName, trimmedVersion, typeId).isPresent());
return validator.isEntityValid(entity, () -> hasNameOrVersionChanged(name, version)
&& smManagement.getByNameAndVersionAndType(name, version, typeId).isPresent());
}
private boolean hasNameOrVersionChanged(final String trimmedName, final String trimmedVersion) {

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxySoftwareModule;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType.SmTypeAssign;
import org.eclipse.hawkbit.ui.common.type.ProxyTypeValidator;
import org.springframework.util.StringUtils;
/**
* Controller for Add software module type window
@@ -82,9 +81,7 @@ public class AddSmTypeWindowController
@Override
protected boolean isEntityValid(final ProxyType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
return validator.isSmTypeValid(entity, () -> smTypeManagement.getByKey(trimmedKey).isPresent(),
() -> smTypeManagement.getByName(trimmedName).isPresent());
return validator.isSmTypeValid(entity, () -> smTypeManagement.getByKey(entity.getKey()).isPresent(),
() -> smTypeManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxySoftwareModule;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType.SmTypeAssign;
import org.eclipse.hawkbit.ui.common.type.ProxyTypeValidator;
import org.springframework.util.StringUtils;
/**
* Controller for update software module type window
@@ -107,11 +106,11 @@ public class UpdateSmTypeWindowController
@Override
protected boolean isEntityValid(final ProxyType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
final String name = entity.getName();
final String key = entity.getKey();
return validator.isSmTypeValid(entity,
() -> hasKeyChanged(trimmedKey) && smTypeManagement.getByKey(trimmedKey).isPresent(),
() -> hasNameChanged(trimmedName) && smTypeManagement.getByName(trimmedName).isPresent());
() -> hasKeyChanged(key) && smTypeManagement.getByKey(key).isPresent(),
() -> hasNameChanged(name) && smTypeManagement.getByName(name).isPresent());
}
private boolean hasNameChanged(final String trimmedName) {

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.ui.common;
import java.io.Serializable;
import java.util.function.Consumer;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.ConfirmStyle;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;

View File

@@ -8,16 +8,6 @@
*/
package org.eclipse.hawkbit.ui.common.builder;
import com.vaadin.data.Binder;
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
import com.vaadin.data.Validator;
import com.vaadin.data.ValueProvider;
import com.vaadin.server.Setter;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.model.Type;
@@ -42,11 +32,23 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.management.miscs.ActionTypeOptionGroupAssignmentLayout;
import org.eclipse.hawkbit.ui.rollout.window.components.AutoStartOptionGroupLayout;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.eclipse.hawkbit.ui.utils.TrimmingStringConverter;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.UIMessageIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import org.springframework.util.StringUtils;
import com.vaadin.data.Binder;
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
import com.vaadin.data.Validator;
import com.vaadin.data.ValueProvider;
import com.vaadin.server.Setter;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
/**
* Builder class for from components
*/
@@ -77,14 +79,14 @@ public final class FormComponentBuilder {
* @return the TextField with its Binding
*/
public static <T extends NameAware> BoundComponent<TextField> createNameInput(final Binder<T> binder,
final VaadinMessageSource i18n, final String fieldId) {
final VaadinMessageSource i18n, final String fieldId) {
final TextField nameInput = new TextFieldBuilder(NamedEntity.NAME_MAX_SIZE).id(fieldId)
.caption(i18n.getMessage(TEXTFIELD_NAME)).prompt(i18n.getMessage(TEXTFIELD_NAME)).buildTextComponent();
.caption(i18n.getMessage(TEXTFIELD_NAME)).prompt(i18n.getMessage(TEXTFIELD_NAME)).buildTextComponent();
nameInput.setSizeUndefined();
final Binding<T, String> binding = binder.forField(nameInput)
.asRequired(i18n.getMessage(UIMessageIdProvider.MESSAGE_ERROR_NAMEREQUIRED))
.bind(NameAware::getName, NameAware::setName);
final Binding<T, String> binding = binder.forField(nameInput).withConverter(new TrimmingStringConverter())
.asRequired(i18n.getMessage(UIMessageIdProvider.MESSAGE_ERROR_NAMEREQUIRED))
.bind(NameAware::getName, NameAware::setName);
return new BoundComponent<>(nameInput, binding);
}
@@ -109,7 +111,7 @@ public final class FormComponentBuilder {
.buildTextComponent();
versionInput.setSizeUndefined();
final Binding<T, String> binding = binder.forField(versionInput)
final Binding<T, String> binding = binder.forField(versionInput).withConverter(new TrimmingStringConverter())
.asRequired(i18n.getMessage(UIMessageIdProvider.MESSAGE_ERROR_VERSIONREQUIRED))
.bind(VersionAware::getVersion, VersionAware::setVersion);
@@ -136,8 +138,8 @@ public final class FormComponentBuilder {
}
public static <T> BoundComponent<TextArea> createBigTextInput(final Binder<T> binder,
final VaadinMessageSource i18n, final String fieldId, final String caption, final String prompt,
ValueProvider<T, String> getter, Setter<T, String> setter) {
final VaadinMessageSource i18n, final String fieldId, final String caption, final String prompt,
final ValueProvider<T, String> getter, final Setter<T, String> setter) {
final TextArea descriptionInput = new TextAreaBuilder(NamedEntity.DESCRIPTION_MAX_SIZE).id(fieldId)
.caption(i18n.getMessage(caption)).prompt(i18n.getMessage(prompt)).style("text-area-style")
.buildTextComponent();
@@ -362,8 +364,8 @@ public final class FormComponentBuilder {
.buildTextComponent();
typeKey.setSizeUndefined();
binder.forField(typeKey).asRequired(i18n.getMessage("message.type.key.empty")).bind(ProxyType::getKey,
ProxyType::setKey);
binder.forField(typeKey).withConverter(new TrimmingStringConverter())
.asRequired(i18n.getMessage("message.type.key.empty")).bind(ProxyType::getKey, ProxyType::setKey);
return typeKey;
}

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyMetaData;
import org.eclipse.hawkbit.ui.common.event.EntityModifiedEventPayload;
import org.springframework.util.StringUtils;
/**
* Controller to add meta data window
@@ -109,8 +108,7 @@ public class AddMetaDataWindowController
@Override
protected boolean isEntityValid(final ProxyMetaData entity) {
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
return validator.isEntityValid(entity, () -> duplicateCheckCallback.test(trimmedKey));
return validator.isEntityValid(entity, () -> duplicateCheckCallback.test(entity.getKey()));
}
@Override

View File

@@ -13,6 +13,7 @@ import org.eclipse.hawkbit.ui.common.builder.FormComponentBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyMetaData;
import org.eclipse.hawkbit.ui.utils.TrimmingStringConverter;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
@@ -56,7 +57,8 @@ public class MetaDataAddUpdateWindowLayoutComponentBuilder {
.prompt(i18n.getMessage(TEXTFIELD_KEY)).buildTextComponent();
keyField.setSizeFull();
binder.forField(keyField).asRequired(i18n.getMessage("message.metadata.key.required"))
binder.forField(keyField).withConverter(new TrimmingStringConverter())
.asRequired(i18n.getMessage("message.metadata.key.required"))
.bind(ProxyMetaData::getKey, ProxyMetaData::setKey);
return keyField;

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.common.detailslayout;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyMetaData;
import org.springframework.util.StringUtils;
@@ -42,9 +42,8 @@ public class ProxyMetadataValidator extends EntityValidator {
return false;
}
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
if (duplicateCheck.getAsBoolean()) {
displayValidationError("message.metadata.duplicate.check", trimmedKey);
displayValidationError("message.metadata.duplicate.check", entity.getKey());
return false;
}

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyMetaData;
import org.eclipse.hawkbit.ui.common.event.EntityModifiedEventPayload;
import org.springframework.util.StringUtils;
/**
* Controller for update meta data window
@@ -128,9 +127,8 @@ public class UpdateMetaDataWindowController
@Override
protected boolean isEntityValid(final ProxyMetaData entity) {
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
return validator.isEntityValid(entity,
() -> hasKeyChanged(trimmedKey) && duplicateCheckCallback.test(trimmedKey));
final String key = entity.getKey();
return validator.isEntityValid(entity, () -> hasKeyChanged(key) && duplicateCheckCallback.test(key));
}
private boolean hasKeyChanged(final String trimmedKey) {

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.common.tag;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.springframework.util.StringUtils;
@@ -47,8 +47,7 @@ public class ProxyTagValidator extends EntityValidator {
}
if (duplicateCheck.getAsBoolean()) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
displayValidationError("message.tag.duplicate.check", trimmedName);
displayValidationError("message.tag.duplicate.check", entity.getName());
return false;
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.common.targettype;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetType;
import org.springframework.util.StringUtils;
@@ -38,8 +38,7 @@ public class ProxyTargetTypeValidator extends EntityValidator {
}
if (duplicateCheck.getAsBoolean()) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
displayValidationError("message.type.duplicate.check", trimmedName);
displayValidationError("message.type.duplicate.check", entity.getName());
return false;
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.common.type;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.springframework.util.CollectionUtils;
@@ -93,8 +93,7 @@ public class ProxyTypeValidator extends EntityValidator {
private boolean keyDoesNotExistInRepo(final ProxyType entity, final BooleanSupplier keyExistsInRepository,
final String duplicateKeyMessageKey) {
if (keyExistsInRepository.getAsBoolean()) {
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
displayValidationError(duplicateKeyMessageKey, trimmedKey);
displayValidationError(duplicateKeyMessageKey, entity.getKey());
return false;
}
return true;
@@ -102,8 +101,7 @@ public class ProxyTypeValidator extends EntityValidator {
private boolean nameDoesNotExistInRepo(final ProxyType entity, final BooleanSupplier nameExistsInRepository) {
if (nameExistsInRepository.getAsBoolean()) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
displayValidationError("message.type.duplicate.check", trimmedName);
displayValidationError("message.type.duplicate.check", entity.getName());
return false;
}
return true;

View File

@@ -20,7 +20,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyDistributionSet;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.type.ProxyTypeValidator;
import org.springframework.util.StringUtils;
/**
* Add distribution set type window controller
@@ -89,9 +88,7 @@ public class AddDsTypeWindowController
@Override
protected boolean isEntityValid(final ProxyType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
return validator.isDsTypeValid(entity, () -> dsTypeManagement.getByKey(trimmedKey).isPresent(),
() -> dsTypeManagement.getByName(trimmedName).isPresent());
return validator.isDsTypeValid(entity, () -> dsTypeManagement.getByKey(entity.getKey()).isPresent(),
() -> dsTypeManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -26,7 +26,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyDistributionSet;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.type.ProxyTypeValidator;
import org.springframework.util.StringUtils;
/**
* Controller for update distribution set type window
@@ -154,11 +153,11 @@ public class UpdateDsTypeWindowController
@Override
protected boolean isEntityValid(final ProxyType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedKey = StringUtils.trimWhitespace(entity.getKey());
final String name = entity.getName();
final String key = entity.getKey();
return validator.isDsTypeValid(entity,
() -> hasKeyChanged(trimmedKey) && dsTypeManagement.getByKey(trimmedKey).isPresent(),
() -> hasNameChanged(trimmedName) && dsTypeManagement.getByName(trimmedName).isPresent());
() -> hasKeyChanged(key) && dsTypeManagement.getByKey(key).isPresent(),
() -> hasNameChanged(name) && dsTypeManagement.getByName(name).isPresent());
}
private boolean hasNameChanged(final String trimmedName) {

View File

@@ -23,7 +23,6 @@ import org.eclipse.hawkbit.ui.common.event.EventView;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload.SelectionChangedEventType;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.springframework.util.StringUtils;
/**
* Controller for add distribution set window
@@ -111,9 +110,7 @@ public class AddDsWindowController
@Override
protected boolean isEntityValid(final ProxyDistributionSet entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
return validator.isEntityValid(entity,
() -> dsManagement.getByNameAndVersion(trimmedName, trimmedVersion).isPresent());
() -> dsManagement.getByNameAndVersion(entity.getName(), entity.getVersion()).isPresent());
}
}

View File

@@ -36,10 +36,8 @@ public class ProxyDsValidator extends EntityValidator {
return false;
}
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
if (duplicateCheck.getAsBoolean()) {
displayValidationError("message.duplicate.dist", trimmedName, trimmedVersion);
displayValidationError("message.duplicate.dist", entity.getName(), entity.getVersion());
return false;
}

View File

@@ -17,7 +17,6 @@ import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyDistributionSet;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.springframework.util.StringUtils;
/**
* Controller for update distribution set window
@@ -103,10 +102,10 @@ public class UpdateDsWindowController
@Override
protected boolean isEntityValid(final ProxyDistributionSet entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String trimmedVersion = StringUtils.trimWhitespace(entity.getVersion());
return validator.isEntityValid(entity, () -> hasNameOrVersionChanged(trimmedName, trimmedVersion)
&& dsManagement.getByNameAndVersion(trimmedName, trimmedVersion).isPresent());
final String name = entity.getName();
final String version = entity.getVersion();
return validator.isEntityValid(entity, () -> hasNameOrVersionChanged(name, version)
&& dsManagement.getByNameAndVersion(name, version).isPresent());
}
private boolean hasNameOrVersionChanged(final String trimmedName, final String trimmedVersion) {

View File

@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetFilterQuery;
import org.springframework.util.StringUtils;
/**
* Controller for add target filter
@@ -97,7 +96,6 @@ public class AddTargetFilterController
@Override
protected boolean isEntityValid(final ProxyTargetFilterQuery entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
return validator.isEntityValid(entity, () -> targetFilterManagement.getByName(trimmedName).isPresent());
return validator.isEntityValid(entity, () -> targetFilterManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.filtermanagement;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetFilterQuery;
import org.springframework.util.StringUtils;
@@ -37,9 +37,8 @@ public class ProxyTargetFilterValidator extends EntityValidator {
return false;
}
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
if (duplicateCheck.getAsBoolean()) {
displayValidationError("message.target.filter.duplicate", trimmedName);
displayValidationError("message.target.filter.duplicate", entity.getName());
return false;
}

View File

@@ -31,8 +31,6 @@ import com.vaadin.ui.TextField;
*/
public class TargetFilterAddUpdateLayoutComponentBuilder {
public static final String TEXTFIELD_FILTER_NAME = "textfield.name";
private final VaadinMessageSource i18n;
private final UiProperties uiProperties;
private final RsqlValidationOracle rsqlValidationOracle;

View File

@@ -16,7 +16,6 @@ import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetFilterQuery;
import org.springframework.util.StringUtils;
/**
* Controller for update target filter
@@ -106,9 +105,9 @@ public class UpdateTargetFilterController extends
@Override
protected boolean isEntityValid(final ProxyTargetFilterQuery entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String name = entity.getName();
return validator.isEntityValid(entity,
() -> hasNamedChanged(trimmedName) && targetFilterManagement.getByName(trimmedName).isPresent());
() -> hasNamedChanged(name) && targetFilterManagement.getByName(name).isPresent());
}
private boolean hasNamedChanged(final String trimmedName) {

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.eclipse.hawkbit.ui.common.tag.ProxyTagValidator;
import org.eclipse.hawkbit.ui.management.tag.TagWindowLayout;
import org.springframework.util.StringUtils;
/**
* Controller for add distribution tag window
@@ -78,7 +77,6 @@ public class AddDsTagWindowController extends AbstractAddNamedEntityWindowContro
@Override
protected boolean isEntityValid(final ProxyTag entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
return validator.isEntityValid(entity, () -> dsTagManagement.getByName(trimmedName).isPresent());
return validator.isEntityValid(entity, () -> dsTagManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.eclipse.hawkbit.ui.common.tag.ProxyTagValidator;
import org.eclipse.hawkbit.ui.management.tag.TagWindowLayout;
import org.springframework.util.StringUtils;
/**
* Controller for update distribution set tag window
@@ -94,9 +93,9 @@ public class UpdateDsTagWindowController extends AbstractUpdateNamedEntityWindow
@Override
protected boolean isEntityValid(final ProxyTag entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String name = entity.getName();
return validator.isEntityValid(entity,
() -> hasNamedChanged(trimmedName) && dsTagManagement.getByName(trimmedName).isPresent());
() -> hasNamedChanged(name) && dsTagManagement.getByName(name).isPresent());
}
private boolean hasNamedChanged(final String trimmedName) {

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.ui.common.event.EventLayout;
import org.eclipse.hawkbit.ui.common.event.EventView;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload;
import org.eclipse.hawkbit.ui.common.event.SelectionChangedEventPayload.SelectionChangedEventType;
import org.springframework.util.StringUtils;
/**
* Controller for add target window
@@ -103,9 +102,8 @@ public class AddTargetWindowController
@Override
protected boolean isEntityValid(final ProxyTarget entity) {
final String trimmedControllerId = StringUtils.trimWhitespace(entity.getControllerId());
return proxyTargetValidator.isEntityValid(entity,
() -> targetManagement.getByControllerID(trimmedControllerId).isPresent());
() -> targetManagement.getByControllerID(entity.getControllerId()).isPresent());
}
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.management.targettable;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.springframework.util.StringUtils;
@@ -37,8 +37,7 @@ public class ProxyTargetValidator extends EntityValidator {
}
if (duplicateCheck.getAsBoolean()) {
final String trimmedControllerId = StringUtils.trimWhitespace(entity.getControllerId());
displayValidationError("message.target.duplicate.check", trimmedControllerId);
displayValidationError("message.target.duplicate.check", entity.getControllerId());
return false;
}

View File

@@ -8,13 +8,17 @@
*/
package org.eclipse.hawkbit.ui.management.targettable;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_ACTIVATEDAT;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_INITIATOR;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_REMARK;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_ROLLOUTS_USER;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_STATE;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_TOGGLE_DIALOG;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import org.eclipse.hawkbit.repository.ConfirmationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
@@ -29,22 +33,17 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorder;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import org.springframework.util.StringUtils;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;
import org.springframework.util.StringUtils;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_TOGGLE_DIALOG;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_ACTIVATEDAT;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_INITIATOR;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_REMARK;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_ROLLOUTS_USER;
import static org.eclipse.hawkbit.ui.utils.UIComponentIdProvider.AUTO_CONFIRMATION_DETAILS_STATE;
/**
* target auto confirmation detail component

View File

@@ -57,14 +57,14 @@ public class TargetWindowBuilder extends AbstractEntityWindowBuilder<ProxyTarget
@Override
public Window getWindowForAdd() {
return getWindowForNewEntity(
new AddTargetWindowController(uiDependencies, targetManagement, new TargetWindowLayout(getI18n(), targetTypeManagement), view));
return getWindowForNewEntity(new AddTargetWindowController(uiDependencies, targetManagement,
new TargetWindowLayout(getI18n(), targetTypeManagement), view));
}
@Override
public Window getWindowForUpdate(final ProxyTarget proxyTarget) {
return getWindowForEntity(proxyTarget,
new UpdateTargetWindowController(uiDependencies, targetManagement, new TargetWindowLayout(getI18n(), targetTypeManagement)));
return getWindowForEntity(proxyTarget, new UpdateTargetWindowController(uiDependencies, targetManagement,
new TargetWindowLayout(getI18n(), targetTypeManagement)));
}
}

View File

@@ -8,11 +8,6 @@
*/
package org.eclipse.hawkbit.ui.management.targettable;
import com.vaadin.data.Binder;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.ui.common.builder.BoundComponent;
import org.eclipse.hawkbit.ui.common.builder.FormComponentBuilder;
@@ -20,9 +15,16 @@ import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.data.providers.TargetTypeDataProvider;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTypeInfo;
import org.eclipse.hawkbit.ui.utils.TrimmingStringConverter;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import com.vaadin.data.Binder;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
/**
* Builder for target window layout component
*/
@@ -57,6 +59,7 @@ public class TargetWindowLayoutComponentBuilder {
targetControllerId.setSizeUndefined();
binder.forField(targetControllerId).asRequired(i18n.getMessage("message.error.missing.controllerId"))
.withConverter(new TrimmingStringConverter())
.withValidator(new RegexpValidator(i18n.getMessage("message.target.whitespace.check"), "[.\\S]*"))
.bind(ProxyTarget::getControllerId, ProxyTarget::setControllerId);
@@ -95,7 +98,7 @@ public class TargetWindowLayoutComponentBuilder {
* TargetTypeDataProvider
* @return input component
*/
public BoundComponent<ComboBox<ProxyTypeInfo>> createTargetTypeCombo(final Binder<ProxyTarget> binder, TargetTypeDataProvider<ProxyTypeInfo> targetTypeDataProvider) {
public BoundComponent<ComboBox<ProxyTypeInfo>> createTargetTypeCombo(final Binder<ProxyTarget> binder, final TargetTypeDataProvider<ProxyTypeInfo> targetTypeDataProvider) {
return FormComponentBuilder
.createTypeCombo(binder, targetTypeDataProvider, i18n, UIComponentIdProvider.TARGET_ADD_TARGETTYPE, false);
}

View File

@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.ui.common.AbstractUpdateNamedEntityWindowController;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.springframework.util.StringUtils;
/**
* Controller for update target window
@@ -80,7 +79,7 @@ public class UpdateTargetWindowController
.name(entity.getName()).description(entity.getDescription())
.targetType(entity.getTypeInfo() != null ? entity.getTypeInfo().getId() : null);
Target updatedTarget = targetManagement.update(targetUpdate);
final Target updatedTarget = targetManagement.update(targetUpdate);
// Un-assigning target type needs another DB request to update the target type value to Null
if (entity.getTypeInfo() == null){
@@ -97,9 +96,9 @@ public class UpdateTargetWindowController
@Override
protected boolean isEntityValid(final ProxyTarget entity) {
final String trimmedControllerId = StringUtils.trimWhitespace(entity.getControllerId());
return proxyTargetValidator.isEntityValid(entity, () -> hasControllerIdChanged(trimmedControllerId)
&& targetManagement.getByControllerID(trimmedControllerId).isPresent());
final String controllerId = entity.getControllerId();
return proxyTargetValidator.isEntityValid(entity, () -> hasControllerIdChanged(controllerId)
&& targetManagement.getByControllerID(controllerId).isPresent());
}
private boolean hasControllerIdChanged(final String trimmedControllerId) {

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.eclipse.hawkbit.ui.common.tag.ProxyTagValidator;
import org.eclipse.hawkbit.ui.management.tag.TagWindowLayout;
import org.springframework.util.StringUtils;
/**
* Controller for add target tag window
@@ -78,7 +77,6 @@ public class AddTargetTagWindowController extends AbstractAddNamedEntityWindowCo
@Override
protected boolean isEntityValid(final ProxyTag entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
return validator.isEntityValid(entity, () -> targetTagManagement.getByName(trimmedName).isPresent());
return validator.isEntityValid(entity, () -> targetTagManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTag;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.eclipse.hawkbit.ui.common.tag.ProxyTagValidator;
import org.eclipse.hawkbit.ui.management.tag.TagWindowLayout;
import org.springframework.util.StringUtils;
/**
* Controller for Update target tag window
@@ -95,9 +94,9 @@ public class UpdateTargetTagWindowController
@Override
protected boolean isEntityValid(final ProxyTag entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String name = entity.getName();
return validator.isEntityValid(entity,
() -> hasNamedChanged(trimmedName) && targetTagManagement.getByName(trimmedName).isPresent());
() -> hasNamedChanged(name) && targetTagManagement.getByName(name).isPresent());
}
private boolean hasNamedChanged(final String trimmedName) {

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.management.targettag.targettype;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TargetTypeManagement;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.ui.common.AbstractAddNamedEntityWindowController;
@@ -19,7 +20,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetType;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.targettype.ProxyTargetTypeValidator;
import org.springframework.util.StringUtils;
/**
* Add target type window controller
@@ -80,7 +80,6 @@ public class AddTargetTypeWindowController
@Override
protected boolean isEntityValid(final ProxyTargetType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
return validator.isEntityValid(entity, () -> targetTypeManagement.getByName(trimmedName).isPresent());
return validator.isEntityValid(entity, () -> targetTypeManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -8,6 +8,11 @@
*/
package org.eclipse.hawkbit.ui.management.targettag.targettype;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TargetTypeManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TargetType;
@@ -20,12 +25,6 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTargetType;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyType;
import org.eclipse.hawkbit.ui.common.targettype.ProxyTargetTypeValidator;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Controller for update target type window
@@ -80,7 +79,7 @@ public class UpdateTargetTypeWindowController
}
private Set<ProxyType> getDsTypesByDsTypeId(final Long id) {
Optional<TargetType> targetType = targetTypeManagement.get(id);
final Optional<TargetType> targetType = targetTypeManagement.get(id);
return targetType.map(type -> type.getCompatibleDistributionSetTypes().stream()
.map(dsTypeToProxyTypeMapper::map).collect(Collectors.toSet())).orElse(Collections.emptySet());
@@ -89,13 +88,13 @@ public class UpdateTargetTypeWindowController
@Override
protected TargetType persistEntityInRepository(final ProxyTargetType entity) {
Set<Long> dsTypesIds = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId).collect(Collectors.toSet());
final Set<Long> dsTypesIds = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId).collect(Collectors.toSet());
Set<Long> selectedDsIds = entity.getSelectedDsTypes().stream().map(ProxyType::getId).collect(Collectors.toSet());
final Set<Long> selectedDsIds = entity.getSelectedDsTypes().stream().map(ProxyType::getId).collect(Collectors.toSet());
Set<Long> dsTypesForRemoval = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId)
final Set<Long> dsTypesForRemoval = getDsTypesByDsTypeId(entity.getId()).stream().map(ProxyType::getId)
.filter(dsType -> !selectedDsIds.contains(dsType)).collect(Collectors.toSet());
Set<Long> dsTypesForAdd = selectedDsIds.stream()
final Set<Long> dsTypesForAdd = selectedDsIds.stream()
.filter(dsType -> !dsTypesIds.contains(dsType)).collect(Collectors.toSet());
dsTypesForRemoval.forEach(dsType -> targetTypeManagement.unassignDistributionSetType(entity.getId(), dsType));
@@ -121,9 +120,9 @@ public class UpdateTargetTypeWindowController
@Override
protected boolean isEntityValid(final ProxyTargetType entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String name = entity.getName();
return validator.isEntityValid(entity,
() -> hasNamedChanged(trimmedName) && targetTypeManagement.getByName(trimmedName).isPresent());
() -> hasNamedChanged(name) && targetTypeManagement.getByName(name).isPresent());
}
private boolean hasNamedChanged(final String trimmedName) {

View File

@@ -10,11 +10,6 @@ package org.eclipse.hawkbit.ui.rollout.window.components;
import java.util.function.IntConsumer;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.ExternalResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Link;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.ui.UiProperties;
import org.eclipse.hawkbit.ui.common.builder.BoundComponent;
@@ -24,9 +19,12 @@ import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxySimpleRolloutGroupsDefinition;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.NumericInputValidator;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.TrimmingStringConverter;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import org.eclipse.hawkbit.utils.TenantConfigHelper;
import com.vaadin.data.Binder;
import com.vaadin.data.Binder.Binding;
@@ -34,13 +32,17 @@ import com.vaadin.data.ValidationException;
import com.vaadin.data.ValidationResult;
import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.ExternalResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.RadioButtonGroup;
import com.vaadin.ui.TextField;
import com.vaadin.ui.themes.ValoTheme;
import org.eclipse.hawkbit.utils.TenantConfigHelper;
/**
* Simple group layout component
@@ -159,7 +161,10 @@ public class SimpleGroupsLayout extends ValidatableLayout {
.prompt(i18n.getMessage("prompt.trigger.threshold")).buildTextComponent();
triggerThresholdField.setSizeUndefined();
final NumericInputValidator numericInputValidator = new NumericInputValidator(i18n);
binder.forField(triggerThresholdField).asRequired(i18n.getMessage("prompt.trigger.threshold.required"))
.withConverter(new TrimmingStringConverter()).withValidator(numericInputValidator)
.withValidator((triggerThresholdText,
context) -> new IntegerRangeValidator(
i18n.getMessage(MESSAGE_ROLLOUT_FIELD_VALUE_RANGE, 0, 100), 0, 100)
@@ -183,9 +188,12 @@ public class SimpleGroupsLayout extends ValidatableLayout {
.id(UIComponentIdProvider.ROLLOUT_ERROR_THRESOLD_ID).prompt(i18n.getMessage("prompt.error.threshold"))
.buildTextComponent();
errorThresholdField.setSizeUndefined();
final NumericInputValidator numericInputValidator = new NumericInputValidator(i18n);
final Binding<ProxySimpleRolloutGroupsDefinition, String> binding = binder.forField(errorThresholdField)
.asRequired(i18n.getMessage("prompt.error.threshold.required"))
.withConverter(new TrimmingStringConverter()).withValidator(numericInputValidator)
.withValidator((errorThresholdText, context) -> {
if (ERROR_THRESHOLD_OPTIONS.PERCENT == errorThresholdOptionGroup.getValue()) {
return new IntegerRangeValidator(i18n.getMessage(MESSAGE_ROLLOUT_FIELD_VALUE_RANGE, 0, 100), 0,

View File

@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.ui.rollout.window.RolloutWindowDependencies;
import org.eclipse.hawkbit.ui.rollout.window.components.AutoStartOptionGroupLayout.AutoStartOption;
import org.eclipse.hawkbit.ui.rollout.window.layouts.AddRolloutWindowLayout;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.springframework.util.StringUtils;
/**
* Controller for populating and saving data in Add Rollout Window.
@@ -112,7 +111,7 @@ public class AddRolloutWindowController
: RepositoryModelConstants.NO_FORCE_TIME)
.startAt(entity.getStartAtByOption());
Rollout rolloutToCreate;
final Rollout rolloutToCreate;
if (GroupDefinitionMode.SIMPLE == entity.getGroupDefinitionMode()) {
rolloutToCreate = rolloutManagement.create(rolloutCreate, entity.getNumberOfGroups(),
entity.isConfirmationRequired(), conditions);
@@ -154,7 +153,6 @@ public class AddRolloutWindowController
@Override
protected boolean isEntityValid(final ProxyRolloutWindow entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
return validator.isEntityValid(entity, () -> rolloutManagement.getByName(trimmedName).isPresent());
return validator.isEntityValid(entity, () -> rolloutManagement.getByName(entity.getName()).isPresent());
}
}

View File

@@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.rollout.window.controllers;
import java.util.function.BooleanSupplier;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.CommonUiDependencies;
import org.eclipse.hawkbit.ui.common.EntityValidator;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyRolloutWindow;
import org.springframework.util.StringUtils;
@@ -42,9 +42,8 @@ public class ProxyRolloutValidator extends EntityValidator {
return false;
}
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
if (duplicateCheck.getAsBoolean()) {
displayValidationError("message.rollout.duplicate.check", trimmedName);
displayValidationError("message.rollout.duplicate.check", entity.getName());
return false;
}

View File

@@ -31,7 +31,6 @@ import org.eclipse.hawkbit.ui.rollout.window.RolloutWindowDependencies;
import org.eclipse.hawkbit.ui.rollout.window.components.AutoStartOptionGroupLayout.AutoStartOption;
import org.eclipse.hawkbit.ui.rollout.window.layouts.UpdateRolloutWindowLayout;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
import org.springframework.util.StringUtils;
/**
* Controller for populating and editing/saving data in Update Rollout Window.
@@ -156,9 +155,9 @@ public class UpdateRolloutWindowController
@Override
protected boolean isEntityValid(final ProxyRolloutWindow entity) {
final String trimmedName = StringUtils.trimWhitespace(entity.getName());
final String name = entity.getName();
return validator.isEntityValid(entity,
() -> hasNamedChanged(trimmedName) && rolloutManagement.getByName(trimmedName).isPresent());
() -> hasNamedChanged(name) && rolloutManagement.getByName(name).isPresent());
}
private boolean hasNamedChanged(final String trimmedName) {

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2023 Bosch.IO 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.utils;
import com.vaadin.data.ValidationResult;
import com.vaadin.data.ValueContext;
import com.vaadin.data.validator.AbstractValidator;
/**
* Validator to verify a text input in {@link String} format if it's parseable
* into an instance of {@link Integer}
*/
public class NumericInputValidator extends AbstractValidator<String> {
private static final String MESSAGE_FIELD_VALIDATOR_INVALID_INPUT = "message.field.validator.numeric.invalid.input";
/**
* Constructor
*
* @param messageSource
* needed to fetch the message in case the input is not valid
*/
public NumericInputValidator(final VaadinMessageSource messageSource) {
super(messageSource.getMessage(MESSAGE_FIELD_VALIDATOR_INVALID_INPUT));
}
@Override
public ValidationResult apply(final String input, final ValueContext valueContext) {
try {
Integer.parseInt(input);
return ValidationResult.ok();
} catch (final NumberFormatException e) {
return this.toResult(input, false);
}
}
}

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2023 Bosch.IO 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.utils;
import org.springframework.util.StringUtils;
import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.ValueContext;
/**
* Converter to trim whitespaces for an input e.g. to further convert it into an
* Integer, etc.
*/
public class TrimmingStringConverter implements Converter<String, String> {
@Override
public Result<String> convertToModel(final String s, final ValueContext valueContext) {
return Result.ok(trimmedString(s));
}
@Override
public String convertToPresentation(final String s, final ValueContext valueContext) {
return trimmedString(s);
}
private static String trimmedString(final String s){
return s == null ? "" : StringUtils.trimWhitespace(s);
}
}

View File

@@ -798,6 +798,7 @@ message.rollout.duplicate.check = Rollout [ {0} ] must be unique, entered value
message.rollout.name.empty = Please enter a name for Rollout
message.correct.invalid.value = Please correct invalid values
message.enter.number = Please enter number
message.field.validator.numeric.invalid.input = Value {0} should be in a numeric format
message.rollout.field.value.range = Value should be in range {0} to {1}
message.rollout.filter.target.exists = The selected target filter does not match any existing target
message.rollout.max.group.size.exceeded = The maximum group size of {0} targets is exceeded. Please increase the number of groups or select a different target filter