JSON for flows should return the app name, not the app ID

Change-Id: I12d217b07bffb59615dfeefd40242f01669989c2
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
index d46c301..923bdf2 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java
@@ -17,6 +17,7 @@
 
 import org.onosproject.codec.CodecContext;
 import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.CoreService;
 import org.onosproject.net.flow.FlowEntry;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
@@ -34,9 +35,11 @@
     public ObjectNode encode(FlowEntry flowEntry, CodecContext context) {
         checkNotNull(flowEntry, "Flow entry cannot be null");
 
+        CoreService service = context.getService(CoreService.class);
+
         final ObjectNode result = context.mapper().createObjectNode()
                 .put("id", Long.toString(flowEntry.id().value()))
-                .put("appId", flowEntry.appId())
+                .put("appId", service.getAppId(flowEntry.appId()).name())
                 .put("groupId", flowEntry.groupId().id())
                 .put("priority", flowEntry.priority())
                 .put("timeout", flowEntry.timeout())
diff --git a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
index 9cb63e7..4fb5821 100644
--- a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
@@ -299,10 +299,12 @@
      */
     public static class FlowJsonMatcher extends TypeSafeMatcher<JsonObject> {
         private final FlowEntry flow;
+        private final String expectedAppId;
         private String reason = "";
 
-        public FlowJsonMatcher(FlowEntry flowValue) {
+        public FlowJsonMatcher(FlowEntry flowValue, String expectedAppIdValue) {
             flow = flowValue;
+            expectedAppId = expectedAppIdValue;
         }
 
         @Override
@@ -316,8 +318,8 @@
             }
 
             // check application id
-            final int jsonAppId = jsonFlow.get("appId").asInt();
-            if (jsonAppId != flow.appId()) {
+            final String jsonAppId = jsonFlow.get("appId").asString();
+            if (!jsonAppId.equals(expectedAppId)) {
                 reason = "appId " + Short.toString(flow.appId());
                 return false;
             }
@@ -399,8 +401,8 @@
      * @param flow flow object we are looking for
      * @return matcher
      */
-    private static FlowJsonMatcher matchesFlow(FlowEntry flow) {
-        return new FlowJsonMatcher(flow);
+    private static FlowJsonMatcher matchesFlow(FlowEntry flow, String expectedAppName) {
+        return new FlowJsonMatcher(flow, expectedAppName);
     }
 
     /**
@@ -430,7 +432,7 @@
                     flowFound = true;
 
                     //  We found the correct flow, check attribute values
-                    assertThat(jsonFlow, matchesFlow(flow));
+                    assertThat(jsonFlow, matchesFlow(flow, APP_ID.name()));
                 }
             }
             if (!flowFound) {