diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 3904c77c0..d8358a609 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -114,8 +114,8 @@ public interface DeploymentManagement { * do not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - DistributionSetAssignmentResult assignDistributionSet(long dsID, - @NotEmpty Collection targets, String actionMessage); + DistributionSetAssignmentResult assignDistributionSet(long dsID, @NotEmpty Collection targets, + String actionMessage); /** * Method registers an "offline" assignment, i.e. adds a completed action @@ -407,8 +407,7 @@ public interface DeploymentManagement { * @return the amount of started actions */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - long startScheduledActionsByRolloutGroupParent(long rolloutId, long distributionSetId, - Long rolloutGroupParentId); + long startScheduledActionsByRolloutGroupParent(long rolloutId, long distributionSetId, Long rolloutGroupParentId); /** * All {@link ActionStatus} entries in the repository. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 5fcb1862a..9b9e1ad9a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -197,8 +197,8 @@ public interface DistributionSetManagement * of distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findMetaDataByDistributionSetIdAndRsql(@NotNull Pageable pageable, - long setId, @NotNull String rsqlParam); + Page findMetaDataByDistributionSetIdAndRsql(@NotNull Pageable pageable, long setId, + @NotNull String rsqlParam); /** * finds all {@link DistributionSet}s. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index b595b076b..4be0071d9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -508,8 +508,8 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageable, - long orderByDistributionId, @NotNull FilterParams filterParams); + Slice findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageable, long orderByDistributionId, + @NotNull FilterParams filterParams); /** * Find targets by tag name. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index e6adcc928..53592acb6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -76,9 +76,7 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery swModuleBeans; if (type == null && StringUtils.isEmpty(searchText)) { - swModuleBeans = getSoftwareManagementService() - .findAll(new OffsetBasedPageRequest(startIndex, count, sort)); - + swModuleBeans = getSoftwareManagementService().findAll(new OffsetBasedPageRequest(startIndex, count, sort)); } else { swModuleBeans = getSoftwareManagementService() .findByTextAndType(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type); 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 f576b6d72..5315a5c44 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 @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; 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.EmptyStringValidator; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; @@ -133,14 +134,13 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { } private void addNewBaseSoftware() { - final String name = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); - final String version = HawkbitCommonUtil.trimAndNullIfEmpty(versionTextField.getValue()); - final String vendor = HawkbitCommonUtil.trimAndNullIfEmpty(vendorTextField.getValue()); - final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final String name = nameTextField.getValue(); + final String version = versionTextField.getValue(); + final String vendor = vendorTextField.getValue(); + final String description = descTextArea.getValue(); final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; - final SoftwareModuleType softwareModuleTypeByName = softwareModuleTypeManagement - .getByName(type) + final SoftwareModuleType softwareModuleTypeByName = softwareModuleTypeManagement.getByName(type) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type)); final SoftwareModuleCreate softwareModule = entityFactory.softwareModule().create() .type(softwareModuleTypeByName).name(name).version(version).description(description).vendor(vendor); @@ -172,9 +172,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { * updates a softwareModule */ private void updateSwModule() { - final SoftwareModule newSWModule = softwareModuleManagement - .update(entityFactory.softwareModule().update(baseSwModuleId) - .description(descTextArea.getValue()).vendor(vendorTextField.getValue())); + final SoftwareModule newSWModule = softwareModuleManagement.update(entityFactory.softwareModule() + .update(baseSwModuleId).description(descTextArea.getValue()).vendor(vendorTextField.getValue())); if (newSWModule != null) { uiNotifcation.displaySuccess(i18n.getMessage("message.save.success", new Object[] { newSWModule.getName() + ":" + newSWModule.getVersion() })); @@ -213,8 +212,10 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { private void createRequiredComponents() { nameTextField = createTextField("textfield.name", UIComponentIdProvider.SOFT_MODULE_NAME); + nameTextField.addValidator(new EmptyStringValidator(i18n)); versionTextField = createTextField("textfield.version", UIComponentIdProvider.SOFT_MODULE_VERSION); + versionTextField.addValidator(new EmptyStringValidator(i18n)); vendorTextField = createTextField("textfield.vendor", UIComponentIdProvider.SOFT_MODULE_VENDOR); vendorTextField.setRequired(false); @@ -292,8 +293,8 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { softwareModuleManagement.get(baseSwModuleId).ifPresent(swModule -> { nameTextField.setValue(swModule.getName()); versionTextField.setValue(swModule.getVersion()); - vendorTextField.setValue(HawkbitCommonUtil.trimAndNullIfEmpty(swModule.getVendor())); - descTextArea.setValue(HawkbitCommonUtil.trimAndNullIfEmpty(swModule.getDescription())); + vendorTextField.setValue(swModule.getVendor()); + descTextArea.setValue(swModule.getDescription()); if (swModule.getType().isDeleted()) { typeComboBox.addItem(swModule.getType().getName()); 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 3bc4a9f3c..4e7bbbad1 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 @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; +import org.eclipse.hawkbit.ui.common.EmptyStringValidator; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; @@ -129,7 +130,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout uploadResultList = new ArrayList<>(); @@ -145,9 +146,9 @@ public class UploadConfirmationWindow implements Button.ClickListener { private Boolean preUploadValidation(final List itemIds) { Boolean validationSuccess = true; for (final String itemId : itemIds) { - final Item item = tabelContainer.getItem(itemId); + final Item item = tableContainer.getItem(itemId); final String providedFileName = (String) item.getItemProperty(FILE_NAME).getValue(); - if (HawkbitCommonUtil.trimAndNullIfEmpty(providedFileName) == null) { + if (!StringUtils.hasText(providedFileName)) { validationSuccess = false; break; } @@ -189,9 +190,11 @@ public class UploadConfirmationWindow implements Button.ClickListener { */ private void setWarningIcon(final Label warningIconLabel, final String fileName, final Object itemId) { final Item item = uploadDetailsTable.getItem(itemId); - if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) { + if (StringUtils.hasText(fileName)) { + final String fileNameTrimmed = StringUtils.trimWhitespace(fileName); final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue(); - final Optional artifact = artifactManagement.getByFilenameAndSoftwareModule(fileName, baseSwId); + final Optional artifact = artifactManagement.getByFilenameAndSoftwareModule(fileNameTrimmed, + baseSwId); if (artifact.isPresent()) { warningIconLabel.setVisible(true); if (isErrorIcon(warningIconLabel)) { @@ -199,7 +202,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { redErrorLabelCount--; } warningIconLabel.setDescription(i18n.getMessage(ALREADY_EXISTS_MSG)); - if (checkForDuplicate(fileName, itemId, baseSwId)) { + if (checkForDuplicate(fileNameTrimmed, itemId, baseSwId)) { warningIconLabel.setDescription(i18n.getMessage("message.duplicate.filename")); warningIconLabel.addStyleName(SPUIStyleDefinitions.ERROR_LABEL); redErrorLabelCount++; @@ -216,8 +219,8 @@ public class UploadConfirmationWindow implements Button.ClickListener { } private Boolean checkForDuplicate(final String fileName, final Object itemId, final Long currentBaseSwId) { - for (final Object newItemId : tabelContainer.getItemIds()) { - final Item newItem = tabelContainer.getItem(newItemId); + for (final Object newItemId : tableContainer.getItemIds()) { + final Item newItem = tableContainer.getItem(newItemId); final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue(); final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue(); if (!newItemId.equals(itemId) && newBaseSwId.equals(currentBaseSwId) && newFileName.equals(fileName)) { @@ -232,7 +235,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { final String swNameVersion = HawkbitCommonUtil.getFormattedNameVersion( customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); final String itemId = swNameVersion + "/" + customFile.getFileName(); - final Item newItem = tabelContainer.addItem(itemId); + final Item newItem = tableContainer.addItem(itemId); final SoftwareModule bSoftwareModule = artifactUploadState.getBaseSwModuleList().get(swNameVersion); newItem.getItemProperty(BASE_SOFTWARE_ID).setValue(bSoftwareModule.getId()); @@ -328,8 +331,8 @@ public class UploadConfirmationWindow implements Button.ClickListener { * file name before modification */ private void modifyIconOfSameSwId(final Object itemId, final Long oldSwId, final String oldFileName) { - for (final Object rowId : tabelContainer.getItemIds()) { - final Item newItem = tabelContainer.getItem(rowId); + for (final Object rowId : tableContainer.getItemIds()) { + final Item newItem = tableContainer.getItem(rowId); final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue(); final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue(); if (!rowId.equals(itemId) && newBaseSwId.equals(oldSwId) && newFileName.equals(oldFileName)) { @@ -380,9 +383,9 @@ public class UploadConfirmationWindow implements Button.ClickListener { } private void newFileNameIsDuplicate(final Object itemId, final Long currentSwId, final String currentChangedText) { - for (final Object rowId : tabelContainer.getItemIds()) { - final Item currentItem = tabelContainer.getItem(itemId); - final Item newItem = tabelContainer.getItem(rowId); + for (final Object rowId : tableContainer.getItemIds()) { + final Item currentItem = tableContainer.getItem(itemId); + final Item newItem = tableContainer.getItem(rowId); final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue(); final String fileName = (String) newItem.getItemProperty(FILE_NAME).getValue(); if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && fileName.equals(currentChangedText)) { @@ -406,8 +409,8 @@ public class UploadConfirmationWindow implements Button.ClickListener { Label errorLabel = null; int errorLabelCount = 0; int duplicateCount = 0; - for (final Object rowId : tabelContainer.getItemIds()) { - final Item newItem = tabelContainer.getItem(rowId); + for (final Object rowId : tableContainer.getItemIds()) { + final Item newItem = tableContainer.getItem(rowId); final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue(); final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue(); if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && newFileName.equals(oldFileName)) { @@ -461,19 +464,19 @@ public class UploadConfirmationWindow implements Button.ClickListener { } private void setTableContainer() { - tabelContainer = new IndexedContainer(); - tabelContainer.addContainerProperty(FILE_NAME_LAYOUT, HorizontalLayout.class, null); - tabelContainer.addContainerProperty(SW_MODULE_NAME, Label.class, null); - tabelContainer.addContainerProperty(SHA1_CHECKSUM, TextField.class, null); - tabelContainer.addContainerProperty(MD5_CHECKSUM, TextField.class, null); - tabelContainer.addContainerProperty(SIZE, Long.class, null); - tabelContainer.addContainerProperty(ACTION, Button.class, ""); - tabelContainer.addContainerProperty(FILE_NAME, String.class, null); - tabelContainer.addContainerProperty(BASE_SOFTWARE_ID, Long.class, null); - tabelContainer.addContainerProperty(WARNING_ICON, Label.class, null); - tabelContainer.addContainerProperty(CUSTOM_FILE, CustomFile.class, null); + tableContainer = new IndexedContainer(); + tableContainer.addContainerProperty(FILE_NAME_LAYOUT, HorizontalLayout.class, null); + tableContainer.addContainerProperty(SW_MODULE_NAME, Label.class, null); + tableContainer.addContainerProperty(SHA1_CHECKSUM, TextField.class, null); + tableContainer.addContainerProperty(MD5_CHECKSUM, TextField.class, null); + tableContainer.addContainerProperty(SIZE, Long.class, null); + tableContainer.addContainerProperty(ACTION, Button.class, ""); + tableContainer.addContainerProperty(FILE_NAME, String.class, null); + tableContainer.addContainerProperty(BASE_SOFTWARE_ID, Long.class, null); + tableContainer.addContainerProperty(WARNING_ICON, Label.class, null); + tableContainer.addContainerProperty(CUSTOM_FILE, CustomFile.class, null); - uploadDetailsTable.setContainerDataSource(tabelContainer); + uploadDetailsTable.setContainerDataSource(tableContainer); uploadDetailsTable.setPageLength(10); uploadDetailsTable.setColumnHeader(FILE_NAME_LAYOUT, i18n.getMessage("upload.file.name")); uploadDetailsTable.setColumnHeader(SW_MODULE_NAME, i18n.getMessage("upload.swModuleTable.header")); @@ -619,9 +622,14 @@ public class UploadConfirmationWindow implements Button.ClickListener { final SoftwareModule baseSw) { final File newFile = new File(filePath); - final Item item = tabelContainer.getItem(itemId); - final String sha1Checksum = ((TextField) item.getItemProperty(SHA1_CHECKSUM).getValue()).getValue(); - final String md5Checksum = ((TextField) item.getItemProperty(MD5_CHECKSUM).getValue()).getValue(); + final Item item = tableContainer.getItem(itemId); + // We have to make sure that null is assigned to sha1Checksum and + // md5Checksum if no alphanumeric value is provided. Empty String will + // fail + final String sha1Checksum = HawkbitCommonUtil + .trimAndNullIfEmpty(((TextField) item.getItemProperty(SHA1_CHECKSUM).getValue()).getValue()); + final String md5Checksum = HawkbitCommonUtil + .trimAndNullIfEmpty(((TextField) item.getItemProperty(MD5_CHECKSUM).getValue()).getValue()); final String providedFileName = (String) item.getItemProperty(FILE_NAME).getValue(); final CustomFile customFile = (CustomFile) item.getItemProperty(CUSTOM_FILE).getValue(); final String[] itemDet = itemId.split("/"); @@ -629,9 +637,8 @@ public class UploadConfirmationWindow implements Button.ClickListener { try (FileInputStream fis = new FileInputStream(newFile)) { - artifactManagement.create(fis, baseSw.getId(), providedFileName, - HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum), - HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType()); + artifactManagement.create(fis, baseSw.getId(), providedFileName, md5Checksum, sha1Checksum, true, + customFile.getMimeType()); saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.SUCCESS, ""); } catch (final ArtifactUploadFailedException | InvalidSHA1HashException | InvalidMD5HashException 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 1fd4b3ff5..326e55d5a 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 @@ -239,7 +239,7 @@ public abstract class AbstractMetadataPopupLayout) value); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/EmptyStringValidator.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/EmptyStringValidator.java new file mode 100644 index 000000000..fa510274e --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/EmptyStringValidator.java @@ -0,0 +1,55 @@ +/** + * 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.VaadinMessageSource; + +import com.vaadin.data.validator.StringLengthValidator; + +/** + * Assures that the entered text does not contain only whitespaces. At least one + * character has to be entered. Leading and trailing whitespaces are allowed as + * they will be trimmed by the repository. + */ +public class EmptyStringValidator extends StringLengthValidator { + + private static final long serialVersionUID = 1L; + + private static final String MESSAGE_KEY = "validator.textfield.min.length"; + + private static final int TEXT_FIELD_DEFAULT_MAX_LENGTH = 64; + + /** + * Constructor for EmptyStringValidator + * + * @param i18n + * {@link VaadinMessageSource} + */ + public EmptyStringValidator(final VaadinMessageSource i18n) { + super(i18n.getMessage(MESSAGE_KEY), 1, TEXT_FIELD_DEFAULT_MAX_LENGTH, false); + } + + /** + * Constructor for EmptyStringValidator + * + * @param i18n + * {@link VaadinMessageSource} + * @param maxLength + * max length of the textfield + */ + public EmptyStringValidator(final VaadinMessageSource i18n, final int maxLength) { + super(i18n.getMessage(MESSAGE_KEY), 1, maxLength, false); + } + + @Override + public boolean isValid(final Object value) { + return super.isValid(value != null ? value.toString().trim() : null); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/AbstractTextFieldBuilder.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/AbstractTextFieldBuilder.java index 8f61b314c..9a6363016 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/AbstractTextFieldBuilder.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/AbstractTextFieldBuilder.java @@ -8,8 +8,12 @@ */ package org.eclipse.hawkbit.ui.common.builder; +import java.util.LinkedList; +import java.util.List; + import org.springframework.util.StringUtils; +import com.vaadin.data.Validator; import com.vaadin.ui.AbstractTextField; /** @@ -30,6 +34,7 @@ public abstract class AbstractTextFieldBuilder { private boolean readOnly; private boolean enabled = true; private int maxLengthAllowed; + private final List validators = new LinkedList<>(); /** * @param caption @@ -131,6 +136,17 @@ public abstract class AbstractTextFieldBuilder { return this; } + /** + * + * @param validator + * the validator to set for this field + * @return the builder + */ + public AbstractTextFieldBuilder validator(final Validator validator) { + validators.add(validator); + return this; + } + /** * Build a textfield * @@ -167,6 +183,10 @@ public abstract class AbstractTextFieldBuilder { textComponent.setId(id); } + if (!validators.isEmpty()) { + validators.forEach(textComponent::addValidator); + } + return textComponent; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextFieldBuilder.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextFieldBuilder.java index f4bb5f8e6..dbcfee3f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextFieldBuilder.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextFieldBuilder.java @@ -20,8 +20,6 @@ import com.vaadin.ui.themes.ValoTheme; */ public class TextFieldBuilder extends AbstractTextFieldBuilder { - private static final int TEXT_FIELD_DEFAULT_MAX_LENGTH = 64; - /** * Constructor. */ @@ -36,7 +34,6 @@ public class TextFieldBuilder extends AbstractTextFieldBuilder { * the id */ public TextFieldBuilder(final String id) { - maxLengthAllowed(TEXT_FIELD_DEFAULT_MAX_LENGTH); styleName(ValoTheme.TEXTAREA_TINY); id(id); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java index b2de2810d..d51ef875a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java @@ -16,7 +16,6 @@ import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.distributions.smtable.SwMetadataPopupLayout; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -123,9 +122,8 @@ public abstract class AbstractSoftwareModuleDetails detailsTabLayout.removeAllComponents(); - final Label vendorLabel = SPUIComponentProvider.createNameValueLabel( - getI18n().getMessage("label.dist.details.vendor"), - HawkbitCommonUtil.trimAndNullIfEmpty(vendor) == null ? "" : vendor); + final Label vendorLabel = SPUIComponentProvider + .createNameValueLabel(getI18n().getMessage("label.dist.details.vendor"), vendor == null ? "" : vendor); vendorLabel.setId(UIComponentIdProvider.DETAILS_VENDOR_LABEL_ID); detailsTabLayout.addComponent(vendorLabel); @@ -136,9 +134,8 @@ public abstract class AbstractSoftwareModuleDetails detailsTabLayout.addComponent(typeLabel); } - final Label assignLabel = SPUIComponentProvider.createNameValueLabel( - getI18n().getMessage("label.assigned.type"), - HawkbitCommonUtil.trimAndNullIfEmpty(maxAssign) == null ? "" : maxAssign); + final Label assignLabel = SPUIComponentProvider + .createNameValueLabel(getI18n().getMessage("label.assigned.type"), maxAssign == null ? "" : maxAssign); assignLabel.setId(UIComponentIdProvider.SWM_DTLS_MAX_ASSIGN); detailsTabLayout.addComponent(assignLabel); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 8ff79a2a0..8fc3ed026 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -162,8 +162,7 @@ public abstract class AbstractTableDetailsLayout extends protected void updateDescriptionLayout(final String description) { descriptionLayout.removeAllComponents(); - final Label descLabel = SPUIComponentProvider.createNameValueLabel("", - HawkbitCommonUtil.trimAndNullIfEmpty(description) == null ? "" : description); + final Label descLabel = SPUIComponentProvider.createNameValueLabel("", description == null ? "" : description); /** * By default text will be truncated based on layout width. So removing * it as we need full description. @@ -181,8 +180,7 @@ public abstract class AbstractTableDetailsLayout extends attributesLayout.removeAllComponents(); for (final Map.Entry entry : attributes.entrySet()) { final Label conAttributeLabel = SPUIComponentProvider.createNameValueLabel( - entry.getKey().concat(" : "), - HawkbitCommonUtil.trimAndNullIfEmpty(entry.getValue()) == null ? "" : entry.getValue()); + entry.getKey().concat(" : "), entry.getValue() == null ? "" : entry.getValue()); conAttributeLabel.setDescription(entry.getKey().concat(" : ") + entry.getValue()); conAttributeLabel.addStyleName("label-style"); attributesLayout.addComponent(conAttributeLabel); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java index 79f0e9667..6d7bc5afa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterButtons.java @@ -15,10 +15,10 @@ import java.util.List; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUITagButtonStyle; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.util.StringUtils; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -95,14 +95,12 @@ public abstract class AbstractFilterButtons extends Table { final Item item = getItem(itemId); final Long id = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_ID).getValue(); final String name = (String) item.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - final String desc = HawkbitCommonUtil - .trimAndNullIfEmpty((String) item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()) != null - ? item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue().toString() : null; - final String color = HawkbitCommonUtil - .trimAndNullIfEmpty((String) item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue()) != null - ? item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue().toString() : DEFAULT_GREEN; + final String desc = (String) item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue() != null + ? item.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue().toString() : null; + final String color = (String) item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue() != null + ? item.getItemProperty(SPUILabelDefinitions.VAR_COLOR).getValue().toString() : DEFAULT_GREEN; final Button typeButton = createFilterButton(id, name, desc, color, itemId); - typeButton.addClickListener(event -> filterButtonClickBehaviour.processFilterButtonClick(event)); + typeButton.addClickListener(filterButtonClickBehaviour::processFilterButtonClick); if ((NO_TAG_BUTTON_ID.equals(typeButton.getData()) && isNoTagStateSelected()) || (id != null && isClickedByDefault(name))) { @@ -159,7 +157,7 @@ public abstract class AbstractFilterButtons extends Table { button.setCaption(prepareFilterButtonCaption(button.getCaption(), color)); } - if (HawkbitCommonUtil.trimAndNullIfEmpty(description) != null) { + if (!StringUtils.isEmpty(description)) { button.setDescription(description); } else { button.setDescription(name); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java index 7622cfbc7..6dc9d9af7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTableHeader.java @@ -17,10 +17,10 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; +import org.springframework.util.StringUtils; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -113,9 +113,9 @@ public abstract class AbstractTableHeader extends VerticalLayout { private void restoreState() { final String onLoadSearchBoxValue = onLoadSearchBoxValue(); - if (HawkbitCommonUtil.trimAndNullIfEmpty(onLoadSearchBoxValue) != null) { + if (StringUtils.hasText(onLoadSearchBoxValue)) { openSearchTextField(); - searchField.setValue(onLoadSearchBoxValue); + searchField.setValue(onLoadSearchBoxValue.trim()); } if (onLoadIsTableMaximized()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java index 6b79d5835..cb94f296c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java @@ -8,6 +8,12 @@ */ package org.eclipse.hawkbit.ui.components; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; + import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.slf4j.Logger; @@ -101,10 +107,20 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler { private static String extractMessageFrom(final Throwable ex) { - if (!StringUtils.isEmpty(ex.getMessage())) { - return ex.getMessage(); + if (!(ex instanceof ConstraintViolationException)) { + if (!StringUtils.isEmpty(ex.getMessage())) { + return ex.getMessage(); + } + return ex.getClass().getSimpleName(); } - return ex.getClass().getSimpleName(); + final Set> violations = ((ConstraintViolationException) ex).getConstraintViolations(); + + if (violations == null) { + return ex.getClass().getSimpleName(); + } else { + return violations.stream().map(violation -> violation.getPropertyPath() + " " + violation.getMessage()) + .collect(Collectors.joining(System.lineSeparator())); + } } } 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 940874fff..26e01baa3 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 @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.EmptyStringValidator; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -39,6 +40,7 @@ import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -137,7 +139,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout itemIds = (List) selectedTable.getItemIds(); - if (null != typeNameValue && null != typeKeyValue && !CollectionUtils.isEmpty(itemIds)) { + if (typeNameValue != null && typeKeyValue != null && !CollectionUtils.isEmpty(itemIds)) { final List mandatory = itemIds.stream() .filter(itemId -> isMandatoryModuleType(selectedTable.getItem(itemId))) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index c2b53b689..c6edb7dec 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -120,7 +120,7 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { @Override public int size() { - if (StringUtils.isEmpty(searchText) && null == distributionSetType) { + if (StringUtils.isEmpty(searchText) && distributionSetType == null) { // if no search filters available firstPageDistributionSets = getDistributionSetManagement() .findByCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), dsComplete); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index 6a88f3156..fd64fbaa1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -101,7 +101,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button private HorizontalLayout captionLayout; - private BlurListener nameTextFieldBlusListner; + private BlurListener nameTextFieldBlurListener; private LayoutClickListener nameLayoutClickListner; @@ -210,7 +210,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private void createListeners() { - nameTextFieldBlusListner = event -> { + nameTextFieldBlurListener = event -> { if (!StringUtils.isEmpty(nameTextField.getValue())) { captionLayout.removeComponent(nameTextField); captionLayout.addComponent(nameLabel); @@ -283,12 +283,12 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button private void setUpCaptionLayout(final boolean isCreateView) { captionLayout.removeAllComponents(); if (isCreateView) { - nameTextField.removeBlurListener(nameTextFieldBlusListner); + nameTextField.removeBlurListener(nameTextFieldBlurListener); captionLayout.removeLayoutClickListener(nameLayoutClickListner); captionLayout.addComponent(nameTextField); } else { captionLayout.addComponent(nameLabel); - nameTextField.addBlurListener(nameTextFieldBlusListner); + nameTextField.addBlurListener(nameTextFieldBlurListener); captionLayout.addLayoutClickListener(nameLayoutClickListner); } } 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 3df443e3b..e75e49136 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 @@ -18,6 +18,7 @@ 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.EmptyStringValidator; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; @@ -193,7 +194,7 @@ public abstract class AbstractCreateUpdateTagLayout exten tagName = new TextFieldBuilder().caption(i18n.getMessage("textfield.name")) .styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_NAME).required(true) .prompt(i18n.getMessage("textfield.name")).immediate(true).id(SPUIDefinitions.NEW_TARGET_TAG_NAME) - .buildTextComponent(); + .validator(new EmptyStringValidator(i18n)).buildTextComponent(); tagDesc = new TextAreaBuilder().caption(i18n.getMessage("textfield.description")) .styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_DESC) @@ -541,8 +542,8 @@ public abstract class AbstractCreateUpdateTagLayout exten */ protected void createNewTag() { colorPicked = ColorPickerHelper.getColorPickedString(colorPickerLayout.getSelPreview()); - tagNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagName.getValue()); - tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); + tagNameValue = tagName.getValue(); + tagDescValue = tagDesc.getValue(); } protected void displaySuccess(final String tagName) { 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 8d2ea9ff8..4c4fb55c6 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 @@ -22,6 +22,7 @@ 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.DistributionSetTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.EmptyStringValidator; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; @@ -29,7 +30,6 @@ import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.distributions.dstable.DistributionSetTable; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; @@ -142,10 +142,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final Long distSetTypeId = (Long) distsetTypeNameComboBox.getValue(); distributionSetTypeManagement.get(distSetTypeId).ifPresent(type -> { - final DistributionSet currentDS = distributionSetManagement.update( - entityFactory.distributionSet().update(editDistId).name(distNameTextField.getValue()) - .description(descTextArea.getValue()).version(distVersionTextField.getValue()) - .requiredMigrationStep(isMigStepReq).type(type)); + final DistributionSet currentDS = distributionSetManagement.update(entityFactory.distributionSet() + .update(editDistId).name(distNameTextField.getValue()).description(descTextArea.getValue()) + .version(distVersionTextField.getValue()).requiredMigrationStep(isMigStepReq).type(type)); notificationMessage.displaySuccess(i18n.getMessage("message.new.dist.save.success", new Object[] { currentDS.getName(), currentDS.getVersion() })); // update table row+details layout @@ -159,18 +158,17 @@ 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 name = distNameTextField.getValue(); + final String version = distVersionTextField.getValue(); final Long distSetTypeId = (Long) distsetTypeNameComboBox.getValue(); - final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final String desc = descTextArea.getValue(); final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - final DistributionSetType distributionSetType = distributionSetTypeManagement - .get(distSetTypeId) + final DistributionSetType distributionSetType = distributionSetTypeManagement.get(distSetTypeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distSetTypeId)); final DistributionSet newDist = distributionSetManagement - .create(entityFactory.distributionSet().create().name(name).version(version) - .description(desc).type(distributionSetType).requiredMigrationStep(isMigStepReq)); + .create(entityFactory.distributionSet().create().name(name).version(version).description(desc) + .type(distributionSetType).requiredMigrationStep(isMigStepReq)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.ADD_ENTITY, newDist)); notificationMessage.displaySuccess(i18n.getMessage("message.new.dist.save.success", @@ -182,8 +180,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final String name = distNameTextField.getValue(); final String version = distVersionTextField.getValue(); - final Optional existingDs = distributionSetManagement - .getByNameAndVersion(name, version); + final Optional existingDs = distributionSetManagement.getByNameAndVersion(name, version); /* * Distribution should not exists with the same name & version. * Display error message, when the "existingDs" is not null and it @@ -247,7 +244,8 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { private TextField createTextField(final String in18Key, final String id) { final TextField buildTextField = new TextFieldBuilder().caption(i18n.getMessage(in18Key)).required(true) - .prompt(i18n.getMessage(in18Key)).immediate(true).id(id).buildTextComponent(); + .validator(new EmptyStringValidator(i18n)).prompt(i18n.getMessage(in18Key)).immediate(true).id(id) + .buildTextComponent(); buildTextField.setNullRepresentation(""); return buildTextField; } @@ -296,8 +294,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { return; } - final Optional distSet = distributionSetManagement - .getWithDetails(editDistId); + final Optional distSet = distributionSetManagement.getWithDetails(editDistId); if (!distSet.isPresent()) { return; } 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 cda9c19bb..2269cded3 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 @@ -25,9 +25,7 @@ import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.RefreshableContainer; import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout; import org.eclipse.hawkbit.ui.management.event.DistributionSetTagTableEvent; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; -import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; @@ -123,23 +121,16 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat @Override protected void createNewTag() { super.createNewTag(); - final String tagNameValueTrimmed = HawkbitCommonUtil.trimAndNullIfEmpty(tagNameValue); - final String tagDescriptionTrimmed = HawkbitCommonUtil.trimAndNullIfEmpty(tagDescValue); - if (!StringUtils.isEmpty(tagNameValueTrimmed)) { - - String colour = ColorPickerConstants.START_COLOR.getCSS(); - if (!StringUtils.isEmpty(getColorPicked())) { - colour = getColorPicked(); - } - - final DistributionSetTag newDistTag = distributionSetTagManagement.create(entityFactory - .tag().create().name(tagNameValueTrimmed).description(tagDescriptionTrimmed).colour(colour)); - eventBus.publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.ADD_ENTITY, newDistTag)); - displaySuccess(newDistTag.getName()); - resetDistTagValues(); - } else { - displayValidationError(i18n.getMessage(SPUILabelDefinitions.MISSING_TAG_NAME)); + String colour = ColorPickerConstants.START_COLOR.getCSS(); + if (!StringUtils.isEmpty(getColorPicked())) { + colour = getColorPicked(); } + + final DistributionSetTag newDistTag = distributionSetTagManagement + .create(entityFactory.tag().create().name(tagNameValue).description(tagDescValue).colour(colour)); + eventBus.publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.ADD_ENTITY, newDistTag)); + displaySuccess(newDistTag.getName()); + resetDistTagValues(); } /** @@ -175,8 +166,7 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat @Override public void setTagDetails(final String distTagSelected) { tagName.setValue(distTagSelected); - final Optional selectedDistTag = distributionSetTagManagement - .getByName(distTagSelected); + final Optional selectedDistTag = distributionSetTagManagement.getByName(distTagSelected); if (selectedDistTag.isPresent()) { tagDesc.setValue(selectedDistTag.get().getDescription()); if (null == selectedDistTag.get().getColour()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 3749e2c69..d54284c09 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -40,7 +40,6 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetBulkUpload; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.slf4j.Logger; @@ -108,8 +107,8 @@ public class BulkUploadHandler extends CustomComponent BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout, final TargetManagement targetManagement, final TargetTagManagement tagManagement, final EntityFactory entityFactory, final DistributionSetManagement distributionSetManagement, - final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, final VaadinMessageSource i18n, - final UI uiInstance, final Executor uiExecutor) { + final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, + final VaadinMessageSource i18n, final UI uiInstance, final Executor uiExecutor) { this.uiInstance = uiInstance; this.comboBox = targetBulkUpdateWindowLayout.getDsNamecomboBox(); this.descTextArea = targetBulkUpdateWindowLayout.getDescTextArea(); @@ -364,8 +363,8 @@ public class BulkUploadHandler extends CustomComponent // Exception squid:S1166 - Targets that exist already are simply ignored @SuppressWarnings("squid:S1166") private void addNewTarget(final String controllerId, final String name) { - final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId); - final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final String newControllerId = controllerId; + final String description = descTextArea.getValue(); try { targetManagement.create(entityFactory.target().create().controllerId(newControllerId).name(name) 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 8564b8455..b6c492a09 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 @@ -20,7 +20,6 @@ import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; @@ -140,9 +139,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { } private void addNewTarget() { - final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue()); - final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); - final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); + final String newControllerId = controllerIDTextField.getValue(); + final String newName = nameTextField.getValue(); + final String newDesc = descTextArea.getValue(); final Target newTarget = targetManagement.create( entityFactory.target().create().controllerId(newControllerId).name(newName).description(newDesc)); @@ -156,7 +155,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) .caption(i18n.getMessage(UIComponentIdProvider.TARGET_ADD_CAPTION)).content(this).layout(formLayout) .i18n(i18n).saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow(); - return window; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index aee8691a2..110feaaa7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.ui.common.tagdetails.TargetTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; @@ -164,14 +163,12 @@ public class TargetDetails extends AbstractTableDetailsLayout { detailsTabLayout.removeAllComponents(); final Label controllerLabel = SPUIComponentProvider.createNameValueLabel( - getI18n().getMessage("label.target.id"), - HawkbitCommonUtil.trimAndNullIfEmpty(controllerId) == null ? "" : controllerId); + getI18n().getMessage("label.target.id"), controllerId == null ? "" : controllerId); controllerLabel.setId(UIComponentIdProvider.TARGET_CONTROLLER_ID); detailsTabLayout.addComponent(controllerLabel); final Label lastPollDtLabel = SPUIComponentProvider.createNameValueLabel( - getI18n().getMessage("label.target.lastpolldate"), - HawkbitCommonUtil.trimAndNullIfEmpty(lastQueryDate) == null ? "" : lastQueryDate); + getI18n().getMessage("label.target.lastpolldate"), lastQueryDate == null ? "" : lastQueryDate); lastPollDtLabel.setId(UIComponentIdProvider.TARGET_LAST_QUERY_DT); detailsTabLayout.addComponent(lastPollDtLabel); 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 3cad09fba..2f770ac41 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 @@ -276,7 +276,7 @@ public class TargetTable extends AbstractTable { addGeneratedColumn(SPUIDefinitions.TARGET_STATUS_PIN_TOGGLE_ICON, (source, itemId, columnId) -> getTagetPinButton(itemId)); addGeneratedColumn(SPUIDefinitions.TARGET_STATUS_POLL_TIME, - (source, itemId, columnId) -> getTagetPollTime(itemId)); + (source, itemId, columnId) -> getTargetPollTime(itemId)); } @Override @@ -363,14 +363,14 @@ public class TargetTable extends AbstractTable { return queryConfig; } - private Label getTagetPollTime(final Object itemId) { + private Label getTargetPollTime(final Object itemId) { final Label statusLabel = new Label(); statusLabel.addStyleName(ValoTheme.LABEL_SMALL); statusLabel.setHeightUndefined(); statusLabel.setContentMode(ContentMode.HTML); final String pollStatusToolTip = (String) getContainerDataSource().getItem(itemId) .getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP).getValue(); - if (HawkbitCommonUtil.trimAndNullIfEmpty(pollStatusToolTip) != null) { + if (StringUtils.hasText(pollStatusToolTip)) { statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); } else { statusLabel.setValue(FontAwesome.CLOCK_O.getHtml()); 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 2c0fbcecb..e642e9a45 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 @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.RefreshableContainer; import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout; import org.eclipse.hawkbit.ui.management.event.TargetTagTableEvent; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; @@ -134,16 +133,14 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa @Override protected void createNewTag() { super.createNewTag(); - final String tagNameTrimmed = HawkbitCommonUtil.trimAndNullIfEmpty(tagNameValue); - final String tagDescriptionTrimmed = HawkbitCommonUtil.trimAndNullIfEmpty(tagDescValue); - if (!StringUtils.isEmpty(tagNameTrimmed)) { + if (!StringUtils.isEmpty(tagNameValue)) { String colour = ColorPickerConstants.START_COLOR.getCSS(); if (!StringUtils.isEmpty(getColorPicked())) { colour = getColorPicked(); } - final TargetTag newTargetTag = targetTagManagement.create(entityFactory.tag().create() - .name(tagNameTrimmed).description(tagDescriptionTrimmed).colour(colour)); + final TargetTag newTargetTag = targetTagManagement + .create(entityFactory.tag().create().name(tagNameValue).description(tagDescValue).colour(colour)); eventBus.publish(this, new TargetTagTableEvent(BaseEntityEventType.ADD_ENTITY, newTargetTag)); displaySuccess(newTargetTag.getName()); } else { 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 8c86785cc..bea32bc24 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 @@ -52,7 +52,6 @@ import org.eclipse.hawkbit.ui.management.footer.ActionTypeOptionGroupLayout; import org.eclipse.hawkbit.ui.management.footer.ActionTypeOptionGroupLayout.ActionTypeOption; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.groupschart.GroupsPieChart; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; @@ -207,6 +206,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { @Override public void saveOrUpdate() { + if (editRolloutEnabled) { editRollout(); return; @@ -228,6 +228,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private boolean duplicateCheck() { + if (!StringUtils.hasText(rolloutName.getValue())) { + uiNotification.displayValidationError(i18n.getMessage("message.rollout.name.empty")); + return false; + } if (rolloutManagement.getByName(getRolloutName()).isPresent()) { uiNotification .displayValidationError(i18n.getMessage("message.rollout.duplicate.check", getRolloutName())); @@ -270,6 +274,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private boolean duplicateCheckForEdit() { + if (!StringUtils.hasText(rolloutName.getValue())) { + uiNotification.displayValidationError(i18n.getMessage("message.rollout.name.empty")); + return false; + } final String rolloutNameVal = getRolloutName(); if (!rollout.getName().equals(rolloutNameVal) && rolloutManagement.getByName(rolloutNameVal).isPresent()) { uiNotification @@ -280,7 +288,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private String getRolloutName() { - return HawkbitCommonUtil.trimAndNullIfEmpty(rolloutName.getValue()); + return StringUtils.trimWhitespace(rolloutName.getValue()); } private Rollout saveRollout() { @@ -756,13 +764,12 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private String getTargetFilterQuery() { - if (null != targetFilterQueryCombo.getValue() - && HawkbitCommonUtil.trimAndNullIfEmpty((String) targetFilterQueryCombo.getValue()) != null) { - final Item filterItem = targetFilterQueryCombo.getContainerDataSource() - .getItem(targetFilterQueryCombo.getValue()); - return (String) filterItem.getItemProperty("query").getValue(); + if (StringUtils.isEmpty(targetFilterQueryCombo.getValue())) { + return null; } - return null; + final Item filterItem = targetFilterQueryCombo.getContainerDataSource() + .getItem(targetFilterQueryCombo.getValue()); + return (String) filterItem.getItemProperty("query").getValue(); } private void setDefaultSaveStartGroupOption() { @@ -863,9 +870,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private boolean isNoOfGroupsOrTargetFilterEmpty() { - return HawkbitCommonUtil.trimAndNullIfEmpty(noOfGroups.getValue()) == null - || (HawkbitCommonUtil.trimAndNullIfEmpty((String) targetFilterQueryCombo.getValue()) == null - && targetFilterQuery.getValue() == null); + return !StringUtils.hasText(noOfGroups.getValue()) + || (!StringUtils.hasText((String) targetFilterQueryCombo.getValue()) + && !StringUtils.hasText(targetFilterQuery.getValue())); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java index 39fa980e0..c19908b0d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java @@ -31,7 +31,6 @@ import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon; import org.eclipse.hawkbit.ui.filtermanagement.TargetFilterBeanQuery; -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; @@ -170,6 +169,7 @@ public class DefineGroupsLayout extends GridLayout { button.setVisible(true); button.addClickListener(event -> addGroupRowAndValidate()); return button; + } private GroupRow addGroupRow() { @@ -238,8 +238,9 @@ public class DefineGroupsLayout extends GridLayout { removeAllRows(); - final List groups = rolloutGroupManagement.findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), - rollout.getId()).getContent(); + final List groups = rolloutGroupManagement + .findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), rollout.getId()) + .getContent(); for (final RolloutGroup group : groups) { final GroupRow groupRow = addGroupRow(); groupRow.populateByGroup(group); @@ -299,6 +300,7 @@ public class DefineGroupsLayout extends GridLayout { } runningValidationsCounter.incrementAndGet(); + } /** @@ -388,32 +390,31 @@ public class DefineGroupsLayout extends GridLayout { groupName = createTextField("textfield.name", UIComponentIdProvider.ROLLOUT_GROUP_LIST_GRID_ID); groupName.setValue(i18n.getMessage("textfield.rollout.group.default.name", groupsCount)); groupName.setStyleName("rollout-group-name"); - groupName.addValueChangeListener(event -> valueChanged()); + groupName.addValueChangeListener( + + event -> valueChanged()); + + targetFilterQueryCombo = + + createTargetFilterQueryCombo(); - targetFilterQueryCombo = createTargetFilterQueryCombo(); populateTargetFilterQuery(); targetFilterQueryCombo.addValueChangeListener(event -> valueChanged()); - targetFilterQuery = createTargetFilterQuery(); - targetPercentage = createPercentageWithDecimalsField("textfield.target.percentage", UIComponentIdProvider.ROLLOUT_GROUP_TARGET_PERC_ID); targetPercentage.setValue("100"); targetPercentage.addValueChangeListener(event -> valueChanged()); - triggerThreshold = createPercentageField("prompt.tigger.threshold", UIComponentIdProvider.ROLLOUT_TRIGGER_THRESOLD_ID); triggerThreshold.setValue(defaultTriggerThreshold); triggerThreshold.addValueChangeListener(event -> valueChanged()); - errorThreshold = createPercentageField("prompt.error.threshold", UIComponentIdProvider.ROLLOUT_ERROR_THRESOLD_ID); errorThreshold.setValue(defaultErrorThreshold); errorThreshold.addValueChangeListener(event -> valueChanged()); - optionsLayout = new HorizontalLayout(); optionsLayout.addComponent(createRemoveButton()); - initialized = true; } @@ -540,13 +541,12 @@ public class DefineGroupsLayout extends GridLayout { } private String getTargetFilterQuery() { - if (null != targetFilterQueryCombo.getValue() - && HawkbitCommonUtil.trimAndNullIfEmpty((String) targetFilterQueryCombo.getValue()) != null) { - final Item filterItem = targetFilterQueryCombo.getContainerDataSource() - .getItem(targetFilterQueryCombo.getValue()); - return (String) filterItem.getItemProperty("query").getValue(); + if (!StringUtils.hasText((String) targetFilterQueryCombo.getValue())) { + return null; } - return null; + final Item filterItem = targetFilterQueryCombo.getContainerDataSource() + .getItem(targetFilterQueryCombo.getValue()); + return (String) filterItem.getItemProperty("query").getValue(); } /** 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 28b6c66cf..4528c0e80 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 @@ -77,19 +77,18 @@ public final class HawkbitCommonUtil { } /** - * Trim the text and convert into null in case of empty string. + * Trims the text and converts into null in case of an empty string. * * @param text - * as text to be trimed + * text to be trimmed * @return null if the text is null or if the text is blank, text.trim() if * the text is not empty. */ public static String trimAndNullIfEmpty(final String text) { - String resultStr = null; if (text != null && !text.trim().isEmpty()) { - resultStr = text.trim(); + return text.trim(); } - return resultStr; + return null; } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java index c3e3d8117..583d16a62 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java @@ -12,11 +12,6 @@ import com.vaadin.ui.themes.ValoTheme; /** * RepositoryConstants required for Label. - * - * - * - * - * */ public final class SPUILabelDefinitions { @@ -48,44 +43,11 @@ public final class SPUILabelDefinitions { * Delay - Notification. */ public static final int SP_DELAY = 1000; - /** - * Cannot be deleted message. - */ - public static final String CANNOT_BE_DELETED_MESSAGE = "Cannot be deleted"; - - /** - * Only one distribution set can be assigned message. - */ - public static final String ONLY_ONE_DS_CAN_BE_ASSIGNED = "Only one distribution set can be assigned"; - - /** - * Only one distribution set can be dropped. - */ - public static final String ONLY_ONE_DS_CAN_BE_DROPPED = "Only one distribution set can be dropped"; /** * Cannot be deleted message. */ public static final String ACTION_NOT_ALLOWED = "Action not allowed"; - /** - * Target already assigned or installed. - */ - public static final String TARGET_ALREADY_ASSIGNED = "Some target(s) are already assigned or installed.Will be ignored"; - - /** - * Target already assigned or installed. - */ - public static final String TARGET_ALREADY_ASSIGNED_PENDING_ACTION = "Some target(s) are already assigned.Pending for action"; - - /** - * Duplicate distribution delete message. - */ - public static final String DUPLICATE_DISTRIBUTION_DELETE = "Distribution(s) already deleted.Pending for action"; - - /** - * Few distribution already deleted message. - */ - public static final String FEW_DISTRIBUTION_ALREADY_DELETED = "Few distribution(s) are already deleted.Pending for action"; /** * NAME. @@ -103,18 +65,10 @@ public final class SPUILabelDefinitions { * Assigned. */ public static final String VAR_ASSIGNED = "assigned"; - /** - * Softwarew type. - */ - public static final String VAR_SOFT_TYPE = "type"; /** * Softwarew type ID. */ public static final String VAR_SOFT_TYPE_ID = "typeId"; - /** - * CreatedAt. - */ - public static final String VAR_CREATED_AT = "createdAt"; /** * CONT ID. */ @@ -130,10 +84,6 @@ public final class SPUILabelDefinitions { */ public static final String VAR_ID = "id"; - /** - * Key. - */ - public static final String VAR_KEY = "key"; /** * DESC. */ @@ -214,10 +164,6 @@ public final class SPUILabelDefinitions { */ public static final String INSTALLED_DISTRIBUTION_NAME_VER = "installedDistNameVersion"; - /** - * Name description label. - */ - public static final String NAME_DESCRIPTION_LABEL = "nameDescLabel"; /** * Name description label. */ @@ -227,32 +173,14 @@ public final class SPUILabelDefinitions { */ public static final String VAR_TARGET_STATUS = "updateStatus"; - /** - * Duplicate target delete message. - */ - public static final String DUPLICATE_TARGET_DELETE = "Target(s) already deleted.Pending for action"; - - /** - * Few target already deleted message. - */ - public static final String FEW_TARGET_ALREADY_DELETED = "Few Target(s) are already deleted.Pending for action"; - /** * Discard all label. */ public static final String DISCARD_ALL = "Discard All"; - /** - * Delete all label. - */ - public static final String DELETE_ALL = "Delete All"; /** * Discard label. */ public static final String DISCARD = "Discard"; - /** - * Delete Software label. - */ - public static final String DELETE_SOFTWARE_ARTIFACT = "Delete Sofware"; /** * Delete Custom Filter. @@ -264,78 +192,16 @@ public final class SPUILabelDefinitions { */ public static final String UPDATE_CUSTOM_FILTER = "Update Custom Filter"; - /** - * Yes label. - */ - public static final String YES = "Yes"; - - /** - * No label. - */ - public static final String NO = "No"; - - /** - * JVM label. - */ - public static final String JVM_LABEL = "Runtime"; - - /** - * Agent hub label. - */ - public static final String AGENT_HUB_LABEL = "Application"; - - /** - * OS label. - */ - public static final String OS_LABEL = "OS"; - - /** - * Missing mandatory details message. - */ - public static final String MISSING_MANDATORY_MSG = "Mandatory details are missing"; - - /** - * Missing Jvm. - */ - public static final String MISSING_JVM = "Please select Runtime"; - /** - * Missing Agent hub. - */ - public static final String MISSING_AH = "Please select Application"; - /** - * Missing Os. - */ - public static final String MISSING_OS = "Please select OS"; - - /** - * Missing tag name. - */ - public static final String MISSING_TAG_NAME = "Please enter the Tag name"; - - /** - * Missing tag name. - */ - public static final String MISSING_TYPE_NAME_KEY = "Please enter the Type name and Key"; - /** * HTML space. */ public static final String HTML_SPACE = " "; - /** - * No data available. - */ - public static final String NO_DATA_AVAIALABLE = "No data available"; /** * Type. */ public static final String TYPE = "Filter by type"; - /** - * Dist Type. - */ - public static final String DISTTYPE = "Filter by Disttype"; - /** * Name. */ @@ -345,35 +211,6 @@ public final class SPUILabelDefinitions { * Upload - process button caption. */ public static final String PROCESS = "Process"; - /** - * Upload - no action button caption. - */ - public static final String NO_ACTION = "No Action"; - - /** - * Files selected for upload. - */ - public static final String UPLOAD_FILES_DROPPED = " files are selected for upload"; - - /** - * Single file selected for upload. - */ - public static final String UPLOAD_FILE_DROPPED = " file is selected for upload"; - - /** - * Upload - upload button caption. - */ - public static final String UPLOAD = "Upload"; - - /** - * Upload - upload button caption. - */ - public static final String CANCEL = "Cancel"; - - /** - * No file selected for upload. - */ - public static final String NO_FILE_SELECTED = "No file selecetd for upload"; /** * Upload results - label. @@ -445,11 +282,6 @@ public final class SPUILabelDefinitions { */ public static final String VAR_STATUS = "status"; - /** - * Target filter query - column property. - */ - public static final String VAR_TARGETFILTERQUERY = "targetFilterQuery"; - /** * Distribution name and version - column property. */ @@ -460,56 +292,10 @@ public final class SPUILabelDefinitions { */ public static final String VAR_NUMBER_OF_GROUPS = "numberOfGroups"; - /** - * Delete label. - */ - public static final String DELETE = "Delete"; - /** - * Rollout name link's description. - */ - public static final String SHOW_ROLLOUT_GROUP_DETAILS = "show group details"; /** * Rollout action button description. */ public static final String ACTION = "Action"; - /** - * Rollout pause button name. - */ - public static final String PAUSE = "Pause"; - - /** - * Rollout resume button name. - */ - public static final String RESUME = "Resume"; - /** - * Rollout and rollout group property - count of not started targets. - */ - public static final String VAR_COUNT_TARGETS_NOT_STARTED = "notStartedTargetsCount"; - - /** - * Rollout and rollout group property - count of running targets. - */ - public static final String VAR_COUNT_TARGETS_RUNNING = "runningTargetsCount"; - - /** - * Rollout and rollout group property - count of scheduled targets. - */ - public static final String VAR_COUNT_TARGETS_SCHEDULED = "scheduledTargetsCount"; - - /** - * Rollout and rollout group property - count of targets in error. - */ - public static final String VAR_COUNT_TARGETS_ERROR = "errorTargetsCount"; - - /** - * Rollout and rollout group property - count of finished targets. - */ - public static final String VAR_COUNT_TARGETS_FINISHED = "finishedTargetsCount"; - - /** - * Rollout and rollout group property - count of targets cancelled targets. - */ - public static final String VAR_COUNT_TARGETS_CANCELLED = "cancelledTargetsCount"; /** * Total target coulmn property name. diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index dcc8b8073..fc470bcf9 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -553,6 +553,7 @@ prompt.target.filter = Custom Target Filter message.rollout.nonzero.group.number = Number of groups must be greater than zero message.rollout.max.group.number = Number of groups must not be greater than 500 message.rollout.duplicate.check = Rollout [ {0} ] must be unique, entered value already exists. +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.rollout.field.value.range = Value should be in range {0} to {1} @@ -612,3 +613,5 @@ distributionset.not.existsDistribution=Distribution set does not exist. Maybe th distributionsets.not.exists=Distribution sets do not exists. Maybe the sets were deleted. targettag.not.exists=Target tag {0} does not exists. Maybe the target tag was deleted. + +validator.textfield.min.length = Please enter a text consisting of at least one and a maximum of {0} characters.