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 9ce95e212..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 @@ -14,7 +14,9 @@ public class ResponseProcessorDelegate { static ResponseProcessor[] processors = { new DomainResponseProcessor(), - new StandaloneResponseProcessor() + new StandaloneResponseProcessor(), + new CompositeOperationWarningProcessor(), + new WarningProcessor() }; @@ -23,7 +25,6 @@ public ResponseProcessorDelegate() { } public void process(ModelNode response) { - Map serverStates = new HashMap(); for(ResponseProcessor proc : processors) @@ -31,7 +32,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..231c92e38 --- /dev/null +++ b/dmr/src/main/java/org/jboss/as/console/client/shared/state/WarningProcessor.java @@ -0,0 +1,28 @@ +package org.jboss.as.console.client.shared.state; + +import java.util.ArrayList; +import java.util.List; + +import org.jboss.dmr.client.ModelNode; + +public class WarningProcessor extends AbstractWarningProcessor { + + @Override + public boolean accepts(ModelNode response) { + // response-headers->warnings + if (response.hasDefined(RESPONSE_HEADERS)) { + final ModelNode result = response.get(RESPONSE_HEADERS); + if (result.hasDefined(WARNINGS)) { + return true; + } + } + return false; + } + + protected List fetchWarnings(final ModelNode response) { + List warnings = new ArrayList(); + warnings.addAll(response.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..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 @@ -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,20 @@ public void onReloadRequired(Map states) { reloadState.propagateChanges(); } + // ------------------------------------------------------ warning handler + + public void onWarning(String warning, Level severity){ + Message.Severity messsageSeverity = null; + 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)); + } // ------------------------------------------------------ messages