ONOS-2186 - GUI Topo Overlay - (WIP)
- Moved TopoJson to core ui API, so it is accessible to external apps
- Added highlightsMessage() to TopoJson
- Pulled sendMessage() up to UiMessageHandler

Change-Id: Iacab5b69e3b2a6db98be8391274695247ba5526d
diff --git a/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java b/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java
index e27f5d9..9b9a406 100644
--- a/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java
+++ b/core/api/src/main/java/org/onosproject/ui/UiMessageHandler.java
@@ -190,4 +190,18 @@
     protected ArrayNode arrayNode() {
         return mapper.createArrayNode();
     }
+
+    /**
+     * Sends the specified data to the client.
+     * It is expected that the data is in the prescribed JSON format for
+     * events to the client.
+     *
+     * @param data data to be sent
+     */
+    protected synchronized void sendMessage(ObjectNode data) {
+        UiConnection connection = connection();
+        if (connection != null) {
+            connection.sendMessage(data);
+        }
+    }
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoJson.java b/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
similarity index 88%
rename from web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoJson.java
rename to core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
index 91cbc05..a94068e 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoJson.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
@@ -15,23 +15,21 @@
  *
  */
 
-package org.onosproject.ui.impl.topo;
+package org.onosproject.ui.topo;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.ui.topo.ButtonId;
-import org.onosproject.ui.topo.DeviceHighlight;
-import org.onosproject.ui.topo.Highlights;
-import org.onosproject.ui.topo.HostHighlight;
-import org.onosproject.ui.topo.LinkHighlight;
-import org.onosproject.ui.topo.PropertyPanel;
+
+import static org.onosproject.ui.JsonUtils.envelope;
 
 /**
  * JSON utilities for the Topology View.
  */
 public final class TopoJson {
     // package-private for unit test access
+    static final String SHOW_HIGHLIGHTS = "showHighlights";
+
     static final String DEVICES = "devices";
     static final String HOSTS = "hosts";
     static final String LINKS = "links";
@@ -62,6 +60,17 @@
     private TopoJson() { }
 
     /**
+     * Returns a formatted message ready to send to the topology view
+     * to render highlights.
+     *
+     * @param highlights highlights model to transform
+     * @return fully formatted "show highlights" message
+     */
+    public static ObjectNode highlightsMessage(Highlights highlights) {
+        return envelope(SHOW_HIGHLIGHTS, json(highlights));
+    }
+
+    /**
      * Transforms the given highlights model into a JSON message payload.
      *
      * @param highlights the model to transform
diff --git a/web/gui/src/test/java/org/onosproject/ui/impl/topo/TopoJsonTest.java b/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
similarity index 96%
rename from web/gui/src/test/java/org/onosproject/ui/impl/topo/TopoJsonTest.java
rename to core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
index aab650c..6a3bfa4 100644
--- a/web/gui/src/test/java/org/onosproject/ui/impl/topo/TopoJsonTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
@@ -15,13 +15,12 @@
  *
  */
 
-package org.onosproject.ui.impl.topo;
+package org.onosproject.ui.topo;
 
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.junit.Test;
 import org.onosproject.ui.JsonUtils;
-import org.onosproject.ui.topo.Highlights;
 import org.onosproject.ui.topo.Highlights.Amount;
 
 import static org.junit.Assert.assertEquals;
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
index 1e8f403..8acdc2c 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java
@@ -80,7 +80,8 @@
 import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
 import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED;
 import static org.onosproject.ui.JsonUtils.envelope;
-import static org.onosproject.ui.impl.topo.TopoJson.json;
+import static org.onosproject.ui.topo.TopoJson.highlightsMessage;
+import static org.onosproject.ui.topo.TopoJson.json;
 
 /**
  * Web socket capable of interacting with the GUI topology view.
@@ -538,15 +539,7 @@
 
     // Converts highlights to JSON format and sends the message to the client
     protected void sendHighlights(Highlights highlights) {
-        sendMessage(envelope(SHOW_HIGHLIGHTS, json(highlights)));
-    }
-
-    // Sends the specified data to the client.
-    protected synchronized void sendMessage(ObjectNode data) {
-        UiConnection connection = connection();
-        if (connection != null) {
-            connection.sendMessage(data);
-        }
+        sendMessage(highlightsMessage(highlights));
     }
 
     // Subscribes for summary messages.