Fix ONOS-2090 - Improvements to Intent JSON
- Intents are now identified by the name portion of the appId rather than
  the number
- removed the now useless "details" field which had a toString()
  dump of the intent for when we didn't support all intent types
- Single Intent GET operations now accept a decimal or hexadecimal
  value for the Intent key.

Change-Id: I39d635e68cccf2e59d0d11307b93329a2dc0bc96
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
index 36ff8fa..8613a96 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
@@ -28,6 +28,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.net.UrlEscapers;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.util.Tools.nullIsIllegal;
@@ -40,7 +41,6 @@
     protected static final String TYPE = "type";
     protected static final String ID = "id";
     protected static final String APP_ID = "appId";
-    protected static final String DETAILS = "details";
     protected static final String STATE = "state";
     protected static final String PRIORITY = "priority";
     protected static final String RESOURCES = "resources";
@@ -50,11 +50,12 @@
     @Override
     public ObjectNode encode(Intent intent, CodecContext context) {
         checkNotNull(intent, "Intent cannot be null");
+
         final ObjectNode result = context.mapper().createObjectNode()
                 .put(TYPE, intent.getClass().getSimpleName())
                 .put(ID, intent.id().toString())
-                .put(APP_ID, intent.appId().toString())
-                .put(DETAILS, intent.toString());
+                .put(APP_ID, UrlEscapers.urlPathSegmentEscaper()
+                        .escape(intent.appId().name()));
 
         final ArrayNode jsonResources = result.putArray(RESOURCES);
 
@@ -98,8 +99,8 @@
      */
     public static void intentAttributes(ObjectNode json, CodecContext context,
                                     Intent.Builder builder) {
-        short appId = (short) nullIsIllegal(json.get(IntentCodec.APP_ID),
-                IntentCodec.TYPE + IntentCodec.MISSING_MEMBER_MESSAGE).asInt();
+        String appId = nullIsIllegal(json.get(IntentCodec.APP_ID),
+                IntentCodec.APP_ID + IntentCodec.MISSING_MEMBER_MESSAGE).asText();
         CoreService service = context.getService(CoreService.class);
         builder.appId(service.getAppId(appId));
 
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
index 0824bd5..7cbce4d 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
@@ -103,8 +103,8 @@
         final IntentService mockIntentService = new IntentServiceAdapter();
         context.registerService(IntentService.class, mockIntentService);
         context.registerService(CoreService.class, mockCoreService);
-        expect(mockCoreService.getAppId((short) 2))
-                .andReturn(new DefaultApplicationId(2, "app"));
+        expect(mockCoreService.getAppId(appId.name()))
+                .andReturn(appId);
         replay(mockCoreService);
     }
 
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
index d30999d..e485a5f 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentJsonMatcher.java
@@ -443,8 +443,10 @@
         }
 
         // check application id
-        final String jsonAppId = jsonIntent.get("appId").asText();
-        final String appId = intent.appId().toString();
+        final JsonNode jsonAppIdNode = jsonIntent.get("appId");
+
+        final String jsonAppId = jsonAppIdNode.asText();
+        final String appId = intent.appId().name();
         if (!jsonAppId.equals(appId)) {
             description.appendText("appId was " + jsonAppId);
             return false;
@@ -458,14 +460,6 @@
             return false;
         }
 
-        // check details field
-        final String jsonDetails = jsonIntent.get("details").asText();
-        final String details = intent.toString();
-        if (!jsonDetails.equals(details)) {
-            description.appendText("details were " + jsonDetails);
-            return false;
-        }
-
         // check resources array
         final JsonNode jsonResources = jsonIntent.get("resources");
         if (intent.resources() != null) {
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/HostToHostIntent.json b/core/common/src/test/resources/org/onosproject/codec/impl/HostToHostIntent.json
index 5010c48..fedea25 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/HostToHostIntent.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/HostToHostIntent.json
@@ -1,6 +1,6 @@
 {
   "type": "HostToHostIntent",
-  "appId": 2,
+  "appId": "test",
   "selector": {"criteria": []},
   "treatment": {
     "instructions": [],
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/PointToPointIntent.json b/core/common/src/test/resources/org/onosproject/codec/impl/PointToPointIntent.json
index 4c6c4b8..b941bef 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/PointToPointIntent.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/PointToPointIntent.json
@@ -1,6 +1,6 @@
 {
   "type": "PointToPointIntent",
-  "appId": 2,
+  "appId": "test",
   "selector": {
     "criteria": [
       {