Jian Li
Committed by Gerrit Code Review

Enhance the detection of meter table supportability in meter GUI

Change-Id: I9925cf8e4ede51f0c7e627ec93b800e146aefbe7
......@@ -34,6 +34,7 @@ import org.onosproject.ui.table.cell.HexLongFormatter;
import org.onosproject.ui.table.cell.NumberFormatter;
import java.util.Collection;
import java.util.Set;
/**
* Message handler for meter view related messages.
......@@ -46,6 +47,10 @@ public class MeterViewMessageHandler extends UiMessageHandler {
private static final String PROTOCOL = "protocol";
private static final String OF_10 = "OF_10";
private static final String OF_11 = "OF_11";
private static final String OF_12 = "OF_12";
private static final Set<String> UNSUPPORTED_PROTOCOLS =
ImmutableSet.of(OF_10, OF_11, OF_12);
private static final String ID = "id";
private static final String APP_ID = "app_id";
......@@ -63,11 +68,6 @@ public class MeterViewMessageHandler extends UiMessageHandler {
return ImmutableSet.of(new MeterDataRequest());
}
private static String deviceProtocol(Device device) {
String protocol = device.annotations().value(PROTOCOL);
return protocol != null ? protocol : "";
}
// handler for meter table requests
private final class MeterDataRequest extends TableRequestHandler {
......@@ -90,8 +90,7 @@ public class MeterViewMessageHandler extends UiMessageHandler {
DeviceService ds = get(DeviceService.class);
Device dev = ds.getDevice(DeviceId.deviceId(uri));
// TODO: replace with a less brittle solution...
if (deviceProtocol(dev).equals(OF_10)) {
if (meterNotSupported(dev)) {
return NOT_SUPPORT_MESSAGE;
}
}
......@@ -129,6 +128,11 @@ public class MeterViewMessageHandler extends UiMessageHandler {
.cell(BANDS, m.bands());
}
private boolean meterNotSupported(Device dev) {
String protocol = dev.annotations().value(PROTOCOL);
return UNSUPPORTED_PROTOCOLS.contains(protocol);
}
private final class BandFormatter implements CellFormatter {
private static final String BREAK = "<br>";
......