diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java index 4e4cb05a6..710d6d97c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java @@ -30,10 +30,7 @@ import com.vaadin.ui.VerticalLayout; * View class that is instantiated when no other view matches the navigation * state. * - * - * * @see Navigator#setErrorView(Class) - * */ @SuppressWarnings("serial") @SpringComponent diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java index f4c26a960..2a56adf28 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java @@ -14,7 +14,7 @@ import java.util.Set; import javax.servlet.http.Cookie; -import org.eclipse.hawkbit.ui.components.SPUIErrorHandler; +import org.eclipse.hawkbit.ui.components.HawkbitUIErrorHandler; import org.eclipse.hawkbit.ui.menu.DashboardEvent.PostViewChangeEvent; import org.eclipse.hawkbit.ui.menu.DashboardMenu; import org.eclipse.hawkbit.ui.menu.DashboardMenuItem; @@ -180,7 +180,10 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { final String locale = getLocaleId(SPUIDefinitions.getAvailableLocales()); setLocale(new Locale(locale)); - UI.getCurrent().setErrorHandler(new SPUIErrorHandler()); + if (UI.getCurrent().getErrorHandler() == null) { + UI.getCurrent().setErrorHandler(new HawkbitUIErrorHandler()); + } + LOG.info("Current locale of the application is : {}", i18n.getLocale()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPNotificationMessage.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitNotificationMessage.java similarity index 61% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPNotificationMessage.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitNotificationMessage.java index 2685d2097..b0561dbb5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPNotificationMessage.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitNotificationMessage.java @@ -10,17 +10,13 @@ package org.eclipse.hawkbit.ui.components; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; -import com.vaadin.server.Page; import com.vaadin.shared.Position; import com.vaadin.ui.Notification; /** * Notification message component. - * - * - * */ -public class SPNotificationMessage extends Notification { +public class HawkbitNotificationMessage extends Notification { /** * ID. @@ -30,30 +26,10 @@ public class SPNotificationMessage extends Notification { /** * Constructor. */ - public SPNotificationMessage() { + public HawkbitNotificationMessage() { super(""); } - /** - * Notification message component. - * - * @param styleName - * style name of message - * @param caption - * message caption - * @param description - * message description - * @param autoClose - * flag to indicate enable close option - * @param page - * current {@link Page} - */ - public void showNotification(final String styleName, final String caption, final String description, - final Boolean autoClose, final Page page) { - decorate(styleName, caption, description, autoClose); - this.show(page); - } - /** * Decorate. * @@ -66,7 +42,7 @@ public class SPNotificationMessage extends Notification { * @param autoClose * flag to indicate enable close option */ - private void decorate(final String styleName, final String caption, final String description, + public void decorateWith(final String styleName, final String caption, final String description, final Boolean autoClose) { setCaption(caption); setDescription(description); 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 new file mode 100644 index 000000000..54552d4da --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java @@ -0,0 +1,84 @@ +/** + * 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.components; + +import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_CLOSABLE; +import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_FAILURE; +import static com.vaadin.ui.themes.ValoTheme.NOTIFICATION_SMALL; + +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Optional; +import com.vaadin.server.DefaultErrorHandler; +import com.vaadin.server.ErrorEvent; +import com.vaadin.server.Page; +import com.vaadin.ui.Component; + +/** + * Default handler for SP UI. + */ +public class HawkbitUIErrorHandler extends DefaultErrorHandler { + + private static final long serialVersionUID = 1L; + private static final Logger LOG = LoggerFactory.getLogger(HawkbitUIErrorHandler.class); + + private static final String STYLE = NOTIFICATION_FAILURE + " " + NOTIFICATION_SMALL + " " + NOTIFICATION_CLOSABLE; + + @Override + public void error(final ErrorEvent event) { + + LOG.error("Error in UI: ", event.getThrowable()); + + final Optional originError = getPageOriginError(event); + + if (originError.isPresent()) { + final HawkbitNotificationMessage message = buildNotification(getRootExceptionFrom(event)); + message.show(originError.get()); + } + } + + private Throwable getRootExceptionFrom(final ErrorEvent event) { + + return getRootCauseOf(event.getThrowable()); + } + + private Throwable getRootCauseOf(final Throwable exception) { + + if (exception.getCause() != null) { + return getRootCauseOf(exception.getCause()); + } + + return exception; + } + + private Optional getPageOriginError(final ErrorEvent event) { + + final Component errorOrigin = findAbstractComponent(event); + + if (errorOrigin != null && errorOrigin.getUI() != null) { + return Optional.fromNullable(errorOrigin.getUI().getPage()); + } + + return Optional.absent(); + } + + protected HawkbitNotificationMessage buildNotification(final Throwable exception) { + + final HawkbitNotificationMessage notification = new HawkbitNotificationMessage(); + final I18N i18n = SpringContextHelper.getBean(I18N.class); + notification.decorateWith(STYLE, i18n.get("caption.error"), + i18n.get("message.error.temp", exception.getClass().getSimpleName()), false); + + return notification; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIErrorHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIErrorHandler.java deleted file mode 100644 index e3d4881f0..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPUIErrorHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.components; - -import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SpringContextHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.vaadin.server.DefaultErrorHandler; -import com.vaadin.server.ErrorEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.themes.ValoTheme; - -/** - * - * Default handler for SP UI. - * - * - * - * - * - */ -public class SPUIErrorHandler extends DefaultErrorHandler { - - /** - * Comment for serialVersionUID. - */ - private static final long serialVersionUID = 1877326479308824191L; - /** - * logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(SPUIErrorHandler.class); - - @Override - public void error(final ErrorEvent event) { - final SPNotificationMessage notification = new SPNotificationMessage(); - // Build error style - final StringBuilder style = new StringBuilder(ValoTheme.NOTIFICATION_FAILURE); - style.append(' '); - style.append(ValoTheme.NOTIFICATION_SMALL); - style.append(' '); - style.append(ValoTheme.NOTIFICATION_CLOSABLE); - final I18N i18n = SpringContextHelper.getBean(I18N.class); - String exceptionName = null; - // From the exception trace we get the expected exception class name - for (Throwable error = event.getThrowable(); error != null; error = error.getCause()) { - exceptionName = HawkbitCommonUtil.getLastSequenceBySplitByDot(error.getClass().getName()); - LOG.error("Error in SP-UI:", error); - } - final Component errorOrgin = findAbstractComponent(event); - if (null != errorOrgin && errorOrgin.getUI() != null) { - notification.showNotification(style.toString(), i18n.get("caption.error"), - i18n.get("message.error.temp", new Object[] { exceptionName }), false, - errorOrgin.getUI().getPage()); - } - } -} 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 217a84a30..b5ac26d11 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 @@ -590,24 +590,6 @@ public final class HawkbitCommonUtil { return requiredExtraWidth + minTableWidth; } - /** - * get the Last sequence of string which is after last dot in String. - * - * @param name - * dotted String name - * @return String name - */ - public static String getLastSequenceBySplitByDot(final String name) { - String lastSequence = null; - if (null != name) { - final String[] strArray = name.split("\\."); - if (strArray.length > 0) { - lastSequence = strArray[strArray.length - 1]; - } - } - return lastSequence; - } - /** * Remove the prefix from text. * 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 d930b89ea..22d680872 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 @@ -54,6 +54,7 @@ public final class SPUILabelDefinitions { */ public static final String SP_NOTIFICATION_ERROR_MESSAGE_STYLE = ValoTheme.NOTIFICATION_ERROR + " " + ValoTheme.NOTIFICATION_TRAY; + /** * Style - Warning. */ @@ -539,13 +540,12 @@ public final class SPUILabelDefinitions { * Total target coulmn property name. */ public static final String VAR_TOTAL_TARGETS = "totalTargetsCount"; - - + /** * Total target count status coulmn property name. */ public static final String VAR_TOTAL_TARGETS_COUNT_STATUS = "totalTargetCountStatus"; - + /** * Rollout group started date column property. */ @@ -560,7 +560,7 @@ public final class SPUILabelDefinitions { * Rollout group installed percentage column property. */ public static final String ROLLOUT_GROUP_INSTALLED_PERCENTAGE = "finishedPercentage"; - + /** * Add metadata icon. */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UINotification.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UINotification.java index a1982d625..4822af570 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UINotification.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UINotification.java @@ -18,8 +18,6 @@ import com.vaadin.spring.annotation.ViewScope; /** * Show success and error messages. - * - * */ @ViewScope @SpringComponent @@ -33,8 +31,6 @@ public class UINotification implements Serializable { /** * Display success type of notification message. * - * @param notificationMessage - * as reference * @param message * is the message to displayed as success. */ @@ -46,8 +42,6 @@ public class UINotification implements Serializable { /** * Display error type of notification message. * - * @param notificationMessage - * as reference * @param message * as message. */ @@ -62,9 +56,13 @@ public class UINotification implements Serializable { /** * Display error type of notification message. * - * @param message. - * @param caption. - * @param autoClose. + * @param message + * errorMessage + * @param caption + * caption of the errorMessage + * @param autoClose + * boolean, if errorMessage should be closed by clicking on the + * error (false) or by clicking anywhere (true) */ public void displayError(final String message, final String caption, final Boolean autoClose) { final StringBuilder updatedMsg = new StringBuilder(FontAwesome.EXCLAMATION_TRIANGLE.getHtml());