Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String, ServerState> serverStates) {
final List<ModelNode> 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<ModelNode> fetchWarnings(final ModelNode response);
}
Original file line number Diff line number Diff line change
@@ -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<Property> 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<ModelNode> fetchWarnings(final ModelNode response) {
List<ModelNode> warnings = new ArrayList<ModelNode>();
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class ResponseProcessorDelegate {

static ResponseProcessor[] processors = {
new DomainResponseProcessor(),
new StandaloneResponseProcessor()
new StandaloneResponseProcessor(),
new CompositeOperationWarningProcessor(),
new WarningProcessor()
};


Expand All @@ -23,15 +25,14 @@ public ResponseProcessorDelegate() {
}

public void process(ModelNode response) {

Map<String, ServerState> serverStates = new HashMap<String, ServerState>();

for(ResponseProcessor proc : processors)
{
if(proc.accepts(response))
{
proc.process(response, serverStates);
break;
//break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<WarningNotification.Handler> {

public static final Type<WarningNotification.Handler> TYPE = new Type<WarningNotification.Handler>();
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<Handler> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ModelNode> fetchWarnings(final ModelNode response) {
List<ModelNode> warnings = new ArrayList<ModelNode>();
warnings.addAll(response.get(RESPONSE_HEADERS).get(WARNINGS).asList());
return warnings;
}

}
11 changes: 11 additions & 0 deletions dmr/src/main/java/org/jboss/dmr/client/notify/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
20 changes: 19 additions & 1 deletion gui/src/main/java/org/jboss/as/console/client/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -149,6 +153,20 @@ public void onReloadRequired(Map<String, ServerState> 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

Expand Down