Jian Li
Committed by Gerrit Code Review

Make results of application codec and swagger doc desc consistent

Application codec returns permissions, requiredApps and features
in string format. However, based on swagger doc, the codec is
supposed to return array. This commit fixes the type inconsistent
issue raised in application rest api.

Change-Id: If47338b287518a981c98ff89ca543802579c7610
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.codec.impl; 16 package org.onosproject.codec.impl;
17 17
18 +import com.fasterxml.jackson.databind.node.ArrayNode;
18 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
19 import org.apache.commons.lang3.StringEscapeUtils; 20 import org.apache.commons.lang3.StringEscapeUtils;
20 import org.onosproject.app.ApplicationService; 21 import org.onosproject.app.ApplicationService;
...@@ -33,7 +34,16 @@ public final class ApplicationCodec extends JsonCodec<Application> { ...@@ -33,7 +34,16 @@ public final class ApplicationCodec extends JsonCodec<Application> {
33 public ObjectNode encode(Application app, CodecContext context) { 34 public ObjectNode encode(Application app, CodecContext context) {
34 checkNotNull(app, "Application cannot be null"); 35 checkNotNull(app, "Application cannot be null");
35 ApplicationService service = context.getService(ApplicationService.class); 36 ApplicationService service = context.getService(ApplicationService.class);
36 - return context.mapper().createObjectNode() 37 +
38 + ArrayNode permissions = context.mapper().createArrayNode();
39 + ArrayNode features = context.mapper().createArrayNode();
40 + ArrayNode requiredApps = context.mapper().createArrayNode();
41 +
42 + app.permissions().forEach(p -> permissions.add(p.toString()));
43 + app.features().forEach(f -> features.add(f));
44 + app.requiredApps().forEach(a -> requiredApps.add(a));
45 +
46 + ObjectNode result = context.mapper().createObjectNode()
37 .put("name", app.id().name()) 47 .put("name", app.id().name())
38 .put("id", app.id().id()) 48 .put("id", app.id().id())
39 .put("version", app.version().toString()) 49 .put("version", app.version().toString())
...@@ -42,11 +52,14 @@ public final class ApplicationCodec extends JsonCodec<Application> { ...@@ -42,11 +52,14 @@ public final class ApplicationCodec extends JsonCodec<Application> {
42 .put("readme", StringEscapeUtils.escapeJson(app.readme())) 52 .put("readme", StringEscapeUtils.escapeJson(app.readme()))
43 .put("origin", app.origin()) 53 .put("origin", app.origin())
44 .put("url", app.url()) 54 .put("url", app.url())
45 - .put("permissions", app.permissions().toString()) // FIXME: change to an array
46 .put("featuresRepo", app.featuresRepo().isPresent() ? 55 .put("featuresRepo", app.featuresRepo().isPresent() ?
47 app.featuresRepo().get().toString() : "") 56 app.featuresRepo().get().toString() : "")
48 - .put("features", app.features().toString()) // FIXME: change to an array
49 - .put("requiredApps", app.requiredApps().toString()) // FIXME: change to an array
50 .put("state", service.getState(app.id()).toString()); 57 .put("state", service.getState(app.id()).toString());
58 +
59 + result.set("features", features);
60 + result.set("permissions", permissions);
61 + result.set("requiredApps", requiredApps);
62 +
63 + return result;
51 } 64 }
52 } 65 }
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
53 "permissions": { 53 "permissions": {
54 "type": "array", 54 "type": "array",
55 "xml": { 55 "xml": {
56 - "name": "hosts", 56 + "name": "permissions",
57 "wrapped": true 57 "wrapped": true
58 }, 58 },
59 "items": { 59 "items": {
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
53 "permissions": { 53 "permissions": {
54 "type": "array", 54 "type": "array",
55 "xml": { 55 "xml": {
56 - "name": "hosts", 56 + "name": "permissions",
57 "wrapped": true 57 "wrapped": true
58 }, 58 },
59 "items": { 59 "items": {
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
66 "permissions": { 66 "permissions": {
67 "type": "array", 67 "type": "array",
68 "xml": { 68 "xml": {
69 - "name": "hosts", 69 + "name": "permissions",
70 "wrapped": true 70 "wrapped": true
71 }, 71 },
72 "items": { 72 "items": {
......