From 68e13b3728719a1cebb7644bdc6f09adea47060c Mon Sep 17 00:00:00 2001 From: baranowb Date: Mon, 20 Feb 2017 11:45:28 +0100 Subject: [PATCH 1/2] [HAL-1287] - add capability to display warnings that come from WFCORE-1987 --- .../state/ResponseProcessorDelegate.java | 6 +- .../shared/state/WarningNotification.java | 31 ++++++++++ .../client/shared/state/WarningProcessor.java | 60 +++++++++++++++++++ .../dmr/client/notify/Notifications.java | 11 ++++ .../org/jboss/as/console/client/Console.java | 28 ++++++++- 5 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningNotification.java create mode 100644 dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java index 9ce95e212..bb907bda6 100644 --- a/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java @@ -14,7 +14,8 @@ public class ResponseProcessorDelegate { static ResponseProcessor[] processors = { new DomainResponseProcessor(), - new StandaloneResponseProcessor() + new StandaloneResponseProcessor(), + new WarningProcessor() }; @@ -23,7 +24,6 @@ public ResponseProcessorDelegate() { } public void process(ModelNode response) { - Map serverStates = new HashMap(); for(ResponseProcessor proc : processors) @@ -31,7 +31,7 @@ public void process(ModelNode response) { if(proc.accepts(response)) { proc.process(response, serverStates); - break; + //break; } } diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningNotification.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningNotification.java new file mode 100644 index 000000000..707d4ee4d --- /dev/null +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningNotification.java @@ -0,0 +1,31 @@ +package org.jboss.as.console.client.shared.state; + +import java.util.logging.Level; + +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.event.shared.GwtEvent; + +public class WarningNotification extends GwtEvent { + + public static final Type TYPE = new Type(); + private final String warning; + private final Level severity; + public WarningNotification(final String warning, final Level serverity) { + this.warning = warning; + this.severity = serverity; + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(Handler listener) { + listener.onWarning(this.warning, this.severity); + } + + public interface Handler extends EventHandler { + public void onWarning(String warning, Level level); + } +} diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java new file mode 100644 index 000000000..44e412fad --- /dev/null +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java @@ -0,0 +1,60 @@ +package org.jboss.as.console.client.shared.state; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; + +import org.jboss.dmr.client.ModelNode; +import org.jboss.dmr.client.Property; +import org.jboss.dmr.client.notify.Notifications; + +public class WarningProcessor implements ResponseProcessor { + + protected static final String LEVEL = "level"; + protected static final String RESPONSE_HEADERS = "response-headers"; + protected static final String RESULT = "result"; + protected static final String STEP_1 = "step-1"; + protected static final String WARNING = "warning"; + protected static final String WARNINGS = "warnings"; + + @Override + public boolean accepts(ModelNode response) { + // result->step-x->response-headers->warnings + if (response.hasDefined(RESULT)) { + final ModelNode result = response.get(RESULT); + if (result.hasDefined(STEP_1)) { + final List steps = result.asPropertyList(); + for (Property step : steps) { + final ModelNode stepContent = step.getValue(); + if (stepContent.hasDefined(RESPONSE_HEADERS) && stepContent.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { + return true; + } + } + } + } + return false; + } + + @Override + public void process(ModelNode response, Map serverStates) { + final List warnings = fetchWarnings(response); + for (ModelNode warning : warnings) { + final WarningNotification warningNotification = new WarningNotification(warning.get(WARNING).asString(), + Level.parse(warning.get(LEVEL).asString())); + Notifications.fireWarningNotification(warningNotification); + } + } + + protected List fetchWarnings(final ModelNode response) { + List warnings = new ArrayList(); + for (Property step : response.get(RESULT).asPropertyList()) { + final ModelNode value = step.getValue(); + if (value.hasDefined(RESPONSE_HEADERS) && value.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { + warnings.addAll(value.get(RESPONSE_HEADERS).get(WARNINGS).asList()); + } + } + return warnings; + } + +} diff --git a/dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java b/dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java index 12b1415bd..dcc84e515 100644 --- a/dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java +++ b/dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java @@ -4,6 +4,7 @@ import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.SimpleEventBus; import org.jboss.as.console.client.shared.state.ReloadNotification; +import org.jboss.as.console.client.shared.state.WarningNotification; /** * @author Heiko Braun @@ -18,8 +19,18 @@ public static void addReloadHandler(ReloadNotification.Handler handler) EVENT_BUS.addHandler(ReloadNotification.TYPE, handler); } + public static void addWarningHandler(WarningNotification.Handler handler) + { + EVENT_BUS.addHandler(WarningNotification.TYPE, handler); + } + public static void fireReloadNotification(ReloadNotification notification) { EVENT_BUS.fireEvent(notification); } + + public static void fireWarningNotification(WarningNotification notification) + { + EVENT_BUS.fireEvent(notification); + } } diff --git a/gui/src/main/java/org/jboss/as/console/client/Console.java b/gui/src/main/java/org/jboss/as/console/client/Console.java index e86af910d..bb2ecd6a0 100644 --- a/gui/src/main/java/org/jboss/as/console/client/Console.java +++ b/gui/src/main/java/org/jboss/as/console/client/Console.java @@ -21,6 +21,7 @@ import java.util.EnumSet; import java.util.Map; +import java.util.logging.Level; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.EntryPoint; @@ -52,7 +53,9 @@ import org.jboss.as.console.client.shared.state.ReloadNotification; import org.jboss.as.console.client.shared.state.ReloadState; import org.jboss.as.console.client.shared.state.ServerState; +import org.jboss.as.console.client.shared.state.WarningNotification; import org.jboss.as.console.spi.Entrypoint; +import org.jboss.dmr.client.ModelNode; import org.jboss.dmr.client.dispatch.DispatchError; import org.jboss.dmr.client.notify.Notifications; import org.jboss.gwt.circuit.Dispatcher; @@ -64,7 +67,7 @@ * @author Heiko Braun */ @Entrypoint -public class Console implements EntryPoint, ReloadNotification.Handler { +public class Console implements EntryPoint, ReloadNotification.Handler, WarningNotification.Handler { public final static UIConstants CONSTANTS = GWT.create(UIConstants.class); public final static UIDebugConstants DEBUG_CONSTANTS = GWT.create(UIDebugConstants.class); @@ -126,6 +129,7 @@ public void onSuccess(BootstrapContext context) { // DMR notifications Notifications.addReloadHandler(Console.this); + Notifications.addWarningHandler(Console.this); /* StringBuilder title = new StringBuilder(); title.append(context.getProductName()).append(" Management"); @@ -149,6 +153,28 @@ public void onReloadRequired(Map states) { reloadState.propagateChanges(); } + // ------------------------------------------------------ warning handler + + public void onWarning(String warning, Level severity){ + Message.Severity messsageSeverity = null; + switch(severity.intValue()){ + case 1000: //SEVERE + messsageSeverity = messsageSeverity.Error; + break; + + case 900: //WARNING + messsageSeverity = messsageSeverity.Warning; + break; + + case 800: //INFO + messsageSeverity = messsageSeverity.Info; + break; + + default://CONFIG/FINE.... + messsageSeverity = messsageSeverity.Info; + } + getMessageCenter().notify(new Message(warning.toString(), messsageSeverity)); + } // ------------------------------------------------------ messages From 095670cc925bd9c5ec76ee3a3c114b2597df7385 Mon Sep 17 00:00:00 2001 From: baranowb Date: Mon, 27 Feb 2017 08:11:03 +0100 Subject: [PATCH 2/2] [HAL-1287] - add standalone message processing and fix level translation --- .../state/AbstractWarningProcessor.java | 29 ++++++++++++ .../CompositeOperationWarningProcessor.java | 39 ++++++++++++++++ .../state/ResponseProcessorDelegate.java | 1 + .../client/shared/state/WarningProcessor.java | 46 +++---------------- .../org/jboss/as/console/client/Console.java | 22 +++------ 5 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 dmr/src/main/java/org/jboss/as/console/client/shared/state/AbstractWarningProcessor.java create mode 100644 dmr/src/main/java/org/jboss/as/console/client/shared/state/CompositeOperationWarningProcessor.java diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/AbstractWarningProcessor.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/AbstractWarningProcessor.java new file mode 100644 index 000000000..2f5e9d8e7 --- /dev/null +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/AbstractWarningProcessor.java @@ -0,0 +1,29 @@ +package org.jboss.as.console.client.shared.state; + +import java.util.List; +import java.util.Map; +import java.util.logging.Level; + +import org.jboss.dmr.client.ModelNode; +import org.jboss.dmr.client.notify.Notifications; + +public abstract class AbstractWarningProcessor implements ResponseProcessor { + protected static final String LEVEL = "level"; + protected static final String RESPONSE_HEADERS = "response-headers"; + protected static final String RESULT = "result"; + protected static final String STEP_1 = "step-1"; + protected static final String WARNING = "warning"; + protected static final String WARNINGS = "warnings"; + + @Override + public void process(ModelNode response, Map serverStates) { + final List warnings = fetchWarnings(response); + for (ModelNode warning : warnings) { + final WarningNotification warningNotification = new WarningNotification(warning.get(WARNING).asString(), + Level.parse(warning.get(LEVEL).asString())); + Notifications.fireWarningNotification(warningNotification); + } + } + + protected abstract List fetchWarnings(final ModelNode response); +} diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/CompositeOperationWarningProcessor.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/CompositeOperationWarningProcessor.java new file mode 100644 index 000000000..a4b69ef1c --- /dev/null +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/CompositeOperationWarningProcessor.java @@ -0,0 +1,39 @@ +package org.jboss.as.console.client.shared.state; + +import java.util.ArrayList; +import java.util.List; + +import org.jboss.dmr.client.ModelNode; +import org.jboss.dmr.client.Property; + +public class CompositeOperationWarningProcessor extends AbstractWarningProcessor { + + @Override + public boolean accepts(ModelNode response) { + // result->step-x->response-headers->warnings + if (response.hasDefined(RESULT)) { + final ModelNode result = response.get(RESULT); + if (result.hasDefined(STEP_1)) { + final List steps = result.asPropertyList(); + for (Property step : steps) { + final ModelNode stepContent = step.getValue(); + if (stepContent.hasDefined(RESPONSE_HEADERS) && stepContent.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { + return true; + } + } + } + } + return false; + } + + protected List fetchWarnings(final ModelNode response) { + List warnings = new ArrayList(); + for (Property step : response.get(RESULT).asPropertyList()) { + final ModelNode value = step.getValue(); + if (value.hasDefined(RESPONSE_HEADERS) && value.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { + warnings.addAll(value.get(RESPONSE_HEADERS).get(WARNINGS).asList()); + } + } + return warnings; + } +} \ No newline at end of file diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java index bb907bda6..66b53c73c 100644 --- a/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/ResponseProcessorDelegate.java @@ -15,6 +15,7 @@ public class ResponseProcessorDelegate { static ResponseProcessor[] processors = { new DomainResponseProcessor(), new StandaloneResponseProcessor(), + new CompositeOperationWarningProcessor(), new WarningProcessor() }; diff --git a/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java index 44e412fad..231c92e38 100644 --- a/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java @@ -2,58 +2,26 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.logging.Level; import org.jboss.dmr.client.ModelNode; -import org.jboss.dmr.client.Property; -import org.jboss.dmr.client.notify.Notifications; -public class WarningProcessor implements ResponseProcessor { - - protected static final String LEVEL = "level"; - protected static final String RESPONSE_HEADERS = "response-headers"; - protected static final String RESULT = "result"; - protected static final String STEP_1 = "step-1"; - protected static final String WARNING = "warning"; - protected static final String WARNINGS = "warnings"; +public class WarningProcessor extends AbstractWarningProcessor { @Override public boolean accepts(ModelNode response) { - // result->step-x->response-headers->warnings - if (response.hasDefined(RESULT)) { - final ModelNode result = response.get(RESULT); - if (result.hasDefined(STEP_1)) { - final List steps = result.asPropertyList(); - for (Property step : steps) { - final ModelNode stepContent = step.getValue(); - if (stepContent.hasDefined(RESPONSE_HEADERS) && stepContent.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { - return true; - } - } + // response-headers->warnings + if (response.hasDefined(RESPONSE_HEADERS)) { + final ModelNode result = response.get(RESPONSE_HEADERS); + if (result.hasDefined(WARNINGS)) { + return true; } } return false; } - @Override - public void process(ModelNode response, Map serverStates) { - final List warnings = fetchWarnings(response); - for (ModelNode warning : warnings) { - final WarningNotification warningNotification = new WarningNotification(warning.get(WARNING).asString(), - Level.parse(warning.get(LEVEL).asString())); - Notifications.fireWarningNotification(warningNotification); - } - } - protected List fetchWarnings(final ModelNode response) { List warnings = new ArrayList(); - for (Property step : response.get(RESULT).asPropertyList()) { - final ModelNode value = step.getValue(); - if (value.hasDefined(RESPONSE_HEADERS) && value.get(RESPONSE_HEADERS).hasDefined(WARNINGS)) { - warnings.addAll(value.get(RESPONSE_HEADERS).get(WARNINGS).asList()); - } - } + warnings.addAll(response.get(RESPONSE_HEADERS).get(WARNINGS).asList()); return warnings; } diff --git a/gui/src/main/java/org/jboss/as/console/client/Console.java b/gui/src/main/java/org/jboss/as/console/client/Console.java index bb2ecd6a0..14f5ac52d 100644 --- a/gui/src/main/java/org/jboss/as/console/client/Console.java +++ b/gui/src/main/java/org/jboss/as/console/client/Console.java @@ -157,22 +157,14 @@ public void onReloadRequired(Map states) { public void onWarning(String warning, Level severity){ Message.Severity messsageSeverity = null; - switch(severity.intValue()){ - case 1000: //SEVERE - messsageSeverity = messsageSeverity.Error; - break; - - case 900: //WARNING - messsageSeverity = messsageSeverity.Warning; - break; - - case 800: //INFO - messsageSeverity = messsageSeverity.Info; - break; - - default://CONFIG/FINE.... - messsageSeverity = messsageSeverity.Info; + if(severity == Level.SEVERE){ + messsageSeverity = Message.Severity.Error; + } else if(severity == Level.WARNING){ + messsageSeverity = Message.Severity.Warning; + } else { + messsageSeverity = Message.Severity.Info; } + getMessageCenter().notify(new Message(warning.toString(), messsageSeverity)); }