From b9f6fcea022c3ad8c98466c151d0b78bf64a1964 Mon Sep 17 00:00:00 2001 From: Melanie Retter Date: Tue, 23 Jan 2018 15:32:40 +0100 Subject: [PATCH] Some small UI glitches (#622) * Show error notification if exception occurs while saving Signed-off-by: Melanie Retter * General solution for Validation Exceptions Signed-off-by: Melanie Retter * Use String not Long for presenting ID in UI Signed-off-by: Melanie Retter * Table for displaying softwareModules of distributionSet contains as much rows as necessary. Signed-off-by: Melanie Retter * Add validator to the target filter combobox Signed-off-by: Melanie Retter * Error Notification displays the exception message if available, otherwise displays the exception's class name Signed-off-by: Melanie Retter * Refactor validation message Signed-off-by: Melanie Retter --- .../SoftwareModuleDetailsTable.java | 6 +++- .../ui/components/HawkbitUIErrorHandler.java | 27 ++++------------ .../actionhistory/ActionHistoryGrid.java | 2 +- .../rollout/AddUpdateRolloutWindowLayout.java | 32 ++++++++++++++----- .../src/main/resources/messages.properties | 1 + 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index ee86dd694..4bbcbe483 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -163,10 +163,15 @@ public class SoftwareModuleDetailsTable extends Table { if (!CollectionUtils.isEmpty(swModuleOptionalTypes)) { swModuleOptionalTypes.forEach(swModule -> setSwModuleProperties(swModule, false, distributionSet)); } + setAmountOfTableRows(getContainerDataSource().size()); } } + private void setAmountOfTableRows(final int amountOfRows) { + setPageLength(amountOfRows); + } + private void setSwModuleProperties(final SoftwareModuleType swModType, final Boolean isMandatory, final DistributionSet distributionSet) { final Set alreadyAssignedSwModules = distributionSet.getModules(); @@ -179,7 +184,6 @@ public class SoftwareModuleDetailsTable extends Table { saveTblitem.getItemProperty(SOFT_TYPE_MANDATORY).setValue(mandatoryLabel); saveTblitem.getItemProperty(SOFT_TYPE_NAME).setValue(typeName); saveTblitem.getItemProperty(SOFT_MODULE).setValue(verticalLayout); - } private void unassignSW(final ClickEvent event, final DistributionSet distributionSet, 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 6cfd4a2bd..6b79d5835 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,16 +8,11 @@ */ 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; import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; import com.google.common.base.Optional; import com.vaadin.server.ClientConnector.ConnectorErrorEvent; @@ -99,25 +94,17 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler { LOG.error("Error in UI: ", ex); final String errorMessage = extractMessageFrom(ex); - final VaadinMessageSource i18n = SpringContextHelper.getBean(VaadinMessageSource.class); - return new HawkbitErrorNotificationMessage(STYLE, i18n.getMessage("caption.error"), - i18n.getMessage("message.error.temp", errorMessage), false); + + return new HawkbitErrorNotificationMessage(STYLE, i18n.getMessage("caption.error"), errorMessage, true); } - private String extractMessageFrom(final Throwable ex) { + private static String extractMessageFrom(final Throwable ex) { - if (!(ex instanceof ConstraintViolation)) { - return ex.getClass().getSimpleName(); + if (!StringUtils.isEmpty(ex.getMessage())) { + return ex.getMessage(); } - final Set> violations = ((ConstraintViolationException) ex).getConstraintViolations(); - - if (violations == null) { - return ex.getClass().getSimpleName(); - } - - return violations.stream().map(violation -> violation.getPropertyPath() + " " + violation.getMessage()) - .collect(Collectors.joining(System.lineSeparator())); + return ex.getClass().getSimpleName(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryGrid.java index cff68af76..9300e9f51 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryGrid.java @@ -206,7 +206,7 @@ public class ActionHistoryGrid extends AbstractGrid { rawCont.addContainerProperty(ProxyAction.PXY_ACTION_LAST_MODIFIED_AT, Long.class, null, true, true); rawCont.addContainerProperty(ProxyAction.PXY_ACTION_STATUS, Action.Status.class, null, true, false); - rawCont.addContainerProperty(ProxyAction.PXY_ACTION_ID, Long.class, null, true, true); + rawCont.addContainerProperty(ProxyAction.PXY_ACTION_ID, String.class, null, true, true); rawCont.addContainerProperty(ProxyAction.PXY_ACTION_ROLLOUT_NAME, String.class, null, true, true); } 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 6eef9c18c..8c86785cc 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 @@ -77,6 +77,7 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Validator; import com.vaadin.data.util.converter.StringToIntegerConverter; import com.vaadin.data.validator.IntegerRangeValidator; +import com.vaadin.data.validator.LongRangeValidator; import com.vaadin.data.validator.NullValidator; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.ComboBox; @@ -99,6 +100,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private static final String MESSAGE_ROLLOUT_FIELD_VALUE_RANGE = "message.rollout.field.value.range"; + private static final String MESSAGE_ROLLOUT_FILTER_TARGET_EXISTS = "message.rollout.filter.target.exists"; + private static final String MESSAGE_ENTER_NUMBER = "message.enter.number"; private final ActionTypeOptionGroupLayout actionTypeOptionGroupLayout; @@ -201,6 +204,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { * Save or update the rollout. */ private final class SaveOnDialogCloseListener implements SaveDialogCloseListener { + @Override public void saveOrUpdate() { if (editRolloutEnabled) { @@ -267,8 +271,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private boolean duplicateCheckForEdit() { final String rolloutNameVal = getRolloutName(); - if (!rollout.getName().equals(rolloutNameVal) - && rolloutManagement.getByName(rolloutNameVal).isPresent()) { + if (!rollout.getName().equals(rolloutNameVal) && rolloutManagement.getByName(rolloutNameVal).isPresent()) { uiNotification .displayValidationError(i18n.getMessage("message.rollout.duplicate.check", rolloutNameVal)); return false; @@ -344,6 +347,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { return (AutoStartOptionGroupLayout.AutoStartOption) autoStartOptionGroupLayout.getAutoStartOptionGroup() .getValue(); } + } CommonDialogWindow getWindow(final Long rolloutId, final boolean copy) { @@ -443,6 +447,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { addComponent(getMandatoryLabel("prompt.target.filter"), 0, 2); addComponent(targetFilterQueryCombo, 1, 2); targetFilterQueryCombo.addValidator(nullValidator); + targetFilterQueryCombo.addValidator(new TargetExistsValidator()); targetFilterQuery.removeValidator(nullValidator); addComponent(getLabel("textfield.description"), 0, 3); @@ -734,8 +739,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private void populateTargetFilterQuery(final Rollout rollout) { - final Page filterQueries = targetFilterQueryManagement - .findByQuery(new PageRequest(0, 1), rollout.getTargetFilterQuery()); + final Page filterQueries = targetFilterQueryManagement.findByQuery(new PageRequest(0, 1), + rollout.getTargetFilterQuery()); if (filterQueries.getTotalElements() > 0) { final TargetFilterQuery filterQuery = filterQueries.getContent().get(0); targetFilterQueryCombo.setValue(filterQuery.getName()); @@ -868,6 +873,18 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { return (int) Math.ceil((double) totalTargetsCount / Double.parseDouble(noOfGroups.getValue())); } + class TargetExistsValidator implements Validator { + private static final long serialVersionUID = 1L; + + @Override + public void validate(final Object value) { + if (value != null) { + new LongRangeValidator(i18n.getMessage(MESSAGE_ROLLOUT_FILTER_TARGET_EXISTS), 1L, null) + .validate(totalTargetsCount); + } + } + } + class ThresholdFieldValidator implements Validator { private static final long serialVersionUID = 9049939751976326550L; @@ -936,10 +953,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { window.updateAllComponents(this); window.setOrginaleValues(); - updateGroupsChart( - rolloutGroupManagement.findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), - rollout.getId()).getContent(), - rollout.getTotalTargets()); + updateGroupsChart(rolloutGroupManagement + .findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), rollout.getId()) + .getContent(), rollout.getTotalTargets()); } totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery()); diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index f1835c857..dcc8b8073 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -556,6 +556,7 @@ message.rollout.duplicate.check = Rollout [ {0} ] must be unique, entered value 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} +message.rollout.filter.target.exists = The selected target filter does not match any existing target message.rollout.started = Rollout {0} started successfully message.rollout.paused = Rollout {0} paused successfully message.rollout.resumed = Rollout {0} resumed successfully