Skip to content

Commit

Permalink
Pass critical notification details to the client (#18342)
Browse files Browse the repository at this point in the history
Change-Id: I3c4eace624453eb854a32fef5fe44d253b164f62
  • Loading branch information
Artur- committed Jun 25, 2015
1 parent 7552e9c commit 10e7a46
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
4 changes: 3 additions & 1 deletion client/src/com/vaadin/client/ApplicationConnection.java
Expand Up @@ -63,6 +63,7 @@
import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConfiguration.ErrorMessage; import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.ResourceLoader.ResourceLoadListener;
import com.vaadin.client.communication.HasJavaScriptConnectorHelper; import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
Expand Down Expand Up @@ -1768,7 +1769,8 @@ public void run() {
if (meta.containsKey("appError")) { if (meta.containsKey("appError")) {
ValueMap error = meta.getValueMap("appError"); ValueMap error = meta.getValueMap("appError");


showError(null, error.getString("caption"), showError(error.getString("details"),
error.getString("caption"),
error.getString("message"), error.getString("message"),
error.getString("url")); error.getString("url"));


Expand Down
15 changes: 2 additions & 13 deletions server/src/com/vaadin/server/VaadinService.java
Expand Up @@ -1574,8 +1574,8 @@ public static String createCriticalNotificationJSON(String caption,
JsonObject appError = Json.createObject(); JsonObject appError = Json.createObject();
putValueOrJsonNull(appError, "caption", caption); putValueOrJsonNull(appError, "caption", caption);
putValueOrJsonNull(appError, "url", url); putValueOrJsonNull(appError, "url", url);
putValueOrJsonNull(appError, "message", putValueOrJsonNull(appError, "message", message);
createCriticalNotificationMessage(message, details)); putValueOrJsonNull(appError, "details", details);


JsonObject meta = Json.createObject(); JsonObject meta = Json.createObject();
meta.put("appError", appError); meta.put("appError", appError);
Expand All @@ -1595,17 +1595,6 @@ public static String createCriticalNotificationJSON(String caption,
return "for(;;);[" + returnString + "]"; return "for(;;);[" + returnString + "]";
} }


private static String createCriticalNotificationMessage(String message,
String details) {
if (message == null) {
return details;
} else if (details != null) {
return message + "<br/><br/>" + details;
}

return message;
}

private static void putValueOrJsonNull(JsonObject json, String key, private static void putValueOrJsonNull(JsonObject json, String key,
String value) { String value) {
if (value == null) { if (value == null) {
Expand Down
45 changes: 23 additions & 22 deletions server/tests/src/com/vaadin/server/VaadinServiceTest.java
Expand Up @@ -42,9 +42,10 @@ public void sessionDestroy(SessionDestroyEvent event) {
} }
} }


private String createCriticalNotification(String caption, String message, String details, String url) { private String createCriticalNotification(String caption, String message,
return VaadinService String details, String url) {
.createCriticalNotificationJSON(caption, message, details, url); return VaadinService.createCriticalNotificationJSON(caption, message,
details, url);
} }


@Test @Test
Expand Down Expand Up @@ -77,64 +78,64 @@ public void testFireSessionDestroy() throws ServletException {


@Test @Test
public void captionIsSetToACriticalNotification() { public void captionIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("foobar", "message",
createCriticalNotification("foobar", "message", "details", "url"); "details", "url");


assertThat(notification, containsString("\"caption\":\"foobar\"")); assertThat(notification, containsString("\"caption\":\"foobar\""));
} }


@Test @Test
public void nullCaptionIsSetToACriticalNotification() { public void nullCaptionIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification(null, "message",
createCriticalNotification(null, "message", "details", "url"); "details", "url");


assertThat(notification, containsString("\"caption\":null")); assertThat(notification, containsString("\"caption\":null"));
} }


@Test @Test
public void messageWithDetailsIsSetToACriticalNotification() { public void messageWithDetailsIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", "foo",
createCriticalNotification("caption", "foo", "bar", "url"); "bar", "url");


assertThat(notification, containsString("\"message\":\"foo<br/><br/>bar\"")); assertThat(notification, containsString("\"details\":\"bar\""));
} }


@Test @Test
public void nullMessageIsReplacedByDetailsInACriticalNotification() { public void nullMessageSentAsNullInACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", null,
createCriticalNotification("caption", null, "foobar", "url"); "foobar", "url");


assertThat(notification, containsString("\"message\":\"foobar\"")); assertThat(notification, containsString("\"message\":null"));
} }


@Test @Test
public void nullMessageIsSetToACriticalNotification() { public void nullMessageIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", null, null,
createCriticalNotification("caption", null, null, "url"); "url");


assertThat(notification, containsString("\"message\":null")); assertThat(notification, containsString("\"message\":null"));
} }


@Test @Test
public void messageSetToACriticalNotification() { public void messageSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", "foobar",
createCriticalNotification("caption", "foobar", null, "url"); null, "url");


assertThat(notification, containsString("\"message\":\"foobar\"")); assertThat(notification, containsString("\"message\":\"foobar\""));
} }


@Test @Test
public void urlIsSetToACriticalNotification() { public void urlIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", "message",
createCriticalNotification("caption", "message", "details", "foobar"); "details", "foobar");


assertThat(notification, containsString("\"url\":\"foobar\"")); assertThat(notification, containsString("\"url\":\"foobar\""));
} }


@Test @Test
public void nullUrlIsSetToACriticalNotification() { public void nullUrlIsSetToACriticalNotification() {
String notification = String notification = createCriticalNotification("caption", "message",
createCriticalNotification("caption", "message", "details", null); "details", null);


assertThat(notification, containsString("\"url\":null")); assertThat(notification, containsString("\"url\":null"));
} }
Expand Down
28 changes: 23 additions & 5 deletions uitest/src/com/vaadin/tests/application/CriticalNotifications.java
Expand Up @@ -26,24 +26,30 @@
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;


public class CriticalNotifications extends AbstractTestUI { public class CriticalNotifications extends AbstractTestUI {


private SystemMessages systemMessages; private SystemMessages systemMessages;
private CheckBox includeDetails;


@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
systemMessages = VaadinService.getCurrent().getSystemMessages( systemMessages = VaadinService.getCurrent().getSystemMessages(
getLocale(), request); getLocale(), request);


includeDetails = new CheckBox("Include details");
addComponent(includeDetails);

Button sessionExpired = new Button("Session expired"); Button sessionExpired = new Button("Session expired");
addComponent(sessionExpired); addComponent(sessionExpired);
sessionExpired.addClickListener(new ClickListener() { sessionExpired.addClickListener(new ClickListener() {
@Override @Override
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
showCriticalNotification( showCriticalNotification(
systemMessages.getSessionExpiredCaption(), systemMessages.getSessionExpiredCaption(),
systemMessages.getSessionExpiredMessage(), null, systemMessages.getSessionExpiredMessage(),
getDetailsMessage(),
systemMessages.getSessionExpiredURL()); systemMessages.getSessionExpiredURL());


} }
Expand All @@ -56,7 +62,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
showCriticalNotification( showCriticalNotification(
systemMessages.getAuthenticationErrorCaption(), systemMessages.getAuthenticationErrorCaption(),
systemMessages.getAuthenticationErrorMessage(), null, systemMessages.getAuthenticationErrorMessage(),
getDetailsMessage(),
systemMessages.getAuthenticationErrorURL()); systemMessages.getAuthenticationErrorURL());


} }
Expand All @@ -69,7 +76,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
showCriticalNotification( showCriticalNotification(
systemMessages.getCommunicationErrorCaption(), systemMessages.getCommunicationErrorCaption(),
systemMessages.getCommunicationErrorMessage(), null, systemMessages.getCommunicationErrorMessage(),
getDetailsMessage(),
systemMessages.getCommunicationErrorURL()); systemMessages.getCommunicationErrorURL());


} }
Expand All @@ -82,7 +90,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
showCriticalNotification( showCriticalNotification(
systemMessages.getInternalErrorCaption(), systemMessages.getInternalErrorCaption(),
systemMessages.getInternalErrorMessage(), null, systemMessages.getInternalErrorMessage(),
getDetailsMessage(),
systemMessages.getInternalErrorURL()); systemMessages.getInternalErrorURL());


} }
Expand All @@ -95,7 +104,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) { public void buttonClick(ClickEvent event) {
showCriticalNotification( showCriticalNotification(
systemMessages.getCookiesDisabledCaption(), systemMessages.getCookiesDisabledCaption(),
systemMessages.getCookiesDisabledMessage(), null, systemMessages.getCookiesDisabledMessage(),
getDetailsMessage(),
systemMessages.getCookiesDisabledURL()); systemMessages.getCookiesDisabledURL());


} }
Expand All @@ -112,6 +122,14 @@ public void buttonClick(ClickEvent event) {
}); });
} }


protected String getDetailsMessage() {
if (includeDetails.getValue()) {
return "Some details for the error";
} else {
return null;
}
}

protected void showCriticalNotification(String caption, String message, protected void showCriticalNotification(String caption, String message,
String details, String url) { String details, String url) {
VaadinService service = VaadinService.getCurrent(); VaadinService service = VaadinService.getCurrent();
Expand Down

0 comments on commit 10e7a46

Please sign in to comment.