Merge pull request #270 from bsinno/fix_lock_session_on_show_error_notification
Show error notification needs a lock when run in separate thread
This commit is contained in:
@@ -34,13 +34,13 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Description;
|
||||
@@ -56,9 +56,6 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* Junit tests for RolloutManagment.
|
||||
*
|
||||
* @author Michael Hirsch
|
||||
*
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Rollout Management")
|
||||
|
||||
@@ -18,13 +18,17 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.vaadin.server.ClientConnector.ConnectorErrorEvent;
|
||||
import com.vaadin.server.DefaultErrorHandler;
|
||||
import com.vaadin.server.ErrorEvent;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.shared.Connector;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.Notification.Type;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Default handler for SP UI.
|
||||
* Default handler for Hawkbit UI.
|
||||
*/
|
||||
public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
|
||||
@@ -36,26 +40,36 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
@Override
|
||||
public void error(final ErrorEvent event) {
|
||||
|
||||
final Optional<Page> originError = getPageOriginError(event);
|
||||
|
||||
if (originError.isPresent()) {
|
||||
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
||||
message.show(originError.get());
|
||||
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
||||
if (event instanceof ConnectorErrorEvent) {
|
||||
final Connector connector = ((ConnectorErrorEvent) event).getConnector();
|
||||
if (connector instanceof UI) {
|
||||
final UI uiInstance = (UI) connector;
|
||||
uiInstance.access(() -> message.show(uiInstance.getPage()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final Optional<Page> originError = getPageOriginError(event);
|
||||
if (originError.isPresent()) {
|
||||
message.show(originError.get());
|
||||
return;
|
||||
}
|
||||
|
||||
HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE);
|
||||
}
|
||||
|
||||
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
|
||||
|
||||
return getRootCauseOf(event.getThrowable());
|
||||
}
|
||||
|
||||
private static Throwable getRootCauseOf(final Throwable exception) {
|
||||
private static Throwable getRootCauseOf(final Throwable ex) {
|
||||
|
||||
if (exception.getCause() != null) {
|
||||
return getRootCauseOf(exception.getCause());
|
||||
if (ex.getCause() != null) {
|
||||
return getRootCauseOf(ex.getCause());
|
||||
}
|
||||
|
||||
return exception;
|
||||
return ex;
|
||||
}
|
||||
|
||||
private static Optional<Page> getPageOriginError(final ErrorEvent event) {
|
||||
@@ -66,18 +80,21 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
||||
return Optional.fromNullable(errorOrigin.getUI().getPage());
|
||||
}
|
||||
|
||||
return Optional.of(Page.getCurrent());
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
protected HawkbitErrorNotificationMessage buildNotification(final Throwable exception) {
|
||||
LOG.error("Error in UI: ", exception);
|
||||
return createHawkbitErrorNotificationMessage(exception);
|
||||
}
|
||||
|
||||
protected HawkbitErrorNotificationMessage createHawkbitErrorNotificationMessage(final Throwable exception) {
|
||||
/**
|
||||
* Method to build a notification based on an exception.
|
||||
*
|
||||
* @param ex
|
||||
* the throwable
|
||||
* @return a hawkbit error notification message
|
||||
*/
|
||||
protected HawkbitErrorNotificationMessage buildNotification(final Throwable ex) {
|
||||
LOG.error("Error in UI: ", ex);
|
||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||
return new HawkbitErrorNotificationMessage(STYLE, i18n.get("caption.error"),
|
||||
i18n.get("message.error.temp", exception.getClass().getSimpleName()), false);
|
||||
i18n.get("message.error.temp", ex.getClass().getSimpleName()), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ public class BulkUploadHandler extends CustomComponent
|
||||
final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout;
|
||||
|
||||
private transient EntityFactory entityFactory;
|
||||
private final UI uiInstance;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -111,8 +112,9 @@ public class BulkUploadHandler extends CustomComponent
|
||||
*/
|
||||
public BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout,
|
||||
final TargetManagement targetManagement, final ManagementUIState managementUIState,
|
||||
final DeploymentManagement deploymentManagement, final I18N i18n) {
|
||||
final DeploymentManagement deploymentManagement, final I18N i18n, final UI uiInstance) {
|
||||
this.targetBulkUpdateWindowLayout = targetBulkUpdateWindowLayout;
|
||||
this.uiInstance = uiInstance;
|
||||
this.comboBox = targetBulkUpdateWindowLayout.getDsNamecomboBox();
|
||||
this.descTextArea = targetBulkUpdateWindowLayout.getDescTextArea();
|
||||
this.targetManagement = targetManagement;
|
||||
@@ -213,7 +215,6 @@ public class BulkUploadHandler extends CustomComponent
|
||||
* below event.
|
||||
*/
|
||||
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
innerCounter++;
|
||||
readEachLine(line, innerCounter, totalFileSize);
|
||||
@@ -222,9 +223,7 @@ public class BulkUploadHandler extends CustomComponent
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Error reading file {}", tempFile.getName(), e);
|
||||
} catch (final RuntimeException e) {
|
||||
if (UI.getCurrent() != null) {
|
||||
UI.getCurrent().getErrorHandler().error(new com.vaadin.server.ErrorEvent(e));
|
||||
}
|
||||
uiInstance.getErrorHandler().error(new ConnectorErrorEvent(uiInstance, e));
|
||||
} finally {
|
||||
deleteFile();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.ProgressBar;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
@@ -174,7 +175,7 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
|
||||
|
||||
private BulkUploadHandler getBulkUploadHandler() {
|
||||
final BulkUploadHandler bulkUploadHandler = new BulkUploadHandler(this, targetManagement, managementUIState,
|
||||
deploymentManagement, i18n);
|
||||
deploymentManagement, i18n, UI.getCurrent());
|
||||
bulkUploadHandler.buildLayout();
|
||||
bulkUploadHandler.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_BUTTON);
|
||||
return bulkUploadHandler;
|
||||
|
||||
Reference in New Issue
Block a user