Simon Hunt

CORD Subscriber GUI -- Added description field to bundle.

- deleted obsolete classes.

Change-Id: Ied2dbc36c0c74894789e2aba6ddddd29c2e90b49
...@@ -17,11 +17,15 @@ ...@@ -17,11 +17,15 @@
17 17
18 package org.onosproject.cord.gui; 18 package org.onosproject.cord.gui;
19 19
20 +import com.fasterxml.jackson.databind.node.ArrayNode;
21 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 import com.google.common.collect.ImmutableList; 22 import com.google.common.collect.ImmutableList;
21 import org.onosproject.cord.gui.model.Bundle; 23 import org.onosproject.cord.gui.model.Bundle;
22 import org.onosproject.cord.gui.model.BundleDescriptor; 24 import org.onosproject.cord.gui.model.BundleDescriptor;
23 import org.onosproject.cord.gui.model.BundleFactory; 25 import org.onosproject.cord.gui.model.BundleFactory;
26 +import org.onosproject.cord.gui.model.JsonFactory;
24 import org.onosproject.cord.gui.model.SubscriberUser; 27 import org.onosproject.cord.gui.model.SubscriberUser;
28 +import org.onosproject.cord.gui.model.UserFactory;
25 29
26 import java.util.ArrayList; 30 import java.util.ArrayList;
27 import java.util.List; 31 import java.util.List;
...@@ -29,7 +33,11 @@ import java.util.List; ...@@ -29,7 +33,11 @@ import java.util.List;
29 /** 33 /**
30 * In memory cache of the model of the subscriber's account. 34 * In memory cache of the model of the subscriber's account.
31 */ 35 */
32 -public class CordModelCache { 36 +public class CordModelCache extends JsonFactory {
37 +
38 + private static final String BUNDLE = "bundle";
39 + private static final String USERS = "users";
40 +
33 41
34 // faked for the demo 42 // faked for the demo
35 private static final int SUBSCRIBER_ID = 92; 43 private static final int SUBSCRIBER_ID = 92;
...@@ -44,7 +52,7 @@ public class CordModelCache { ...@@ -44,7 +52,7 @@ public class CordModelCache {
44 /** 52 /**
45 * Constructs a model cache, initializing it with basic bundle. 53 * Constructs a model cache, initializing it with basic bundle.
46 */ 54 */
47 - public CordModelCache() { 55 + CordModelCache() {
48 currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE); 56 currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
49 users = new ArrayList<SubscriberUser>(); 57 users = new ArrayList<SubscriberUser>();
50 initUsers(); 58 initUsers();
...@@ -88,4 +96,51 @@ public class CordModelCache { ...@@ -88,4 +96,51 @@ public class CordModelCache {
88 public List<SubscriberUser> getUsers() { 96 public List<SubscriberUser> getUsers() {
89 return ImmutableList.copyOf(users); 97 return ImmutableList.copyOf(users);
90 } 98 }
99 +
100 + private ArrayNode userJsonArray() {
101 + ArrayNode userList = arrayNode();
102 + for (SubscriberUser user: users) {
103 + userList.add(UserFactory.toObjectNode(user));
104 + }
105 + return userList;
106 + }
107 +
108 + // ============= generate JSON for GUI rest calls..
109 +
110 + /**
111 + * Returns the dashboard page data as JSON.
112 + *
113 + * @return dashboard page JSON data
114 + */
115 + public String jsonDashboard() {
116 + ObjectNode root = objectNode();
117 + root.put(BUNDLE, currentBundle.descriptor().displayName());
118 + root.set(USERS, userJsonArray());
119 + return root.toString();
120 + }
121 +
122 + /**
123 + * Returns the bundle page data as JSON.
124 + *
125 + * @return bundle page JSON data
126 + */
127 + public String jsonBundle() {
128 + return BundleFactory.toJson(currentBundle);
129 + }
130 +
131 + /**
132 + * Returns the users page data as JSON.
133 + *
134 + * @return users page JSON data
135 + */
136 + public String jsonUsers() {
137 + ObjectNode root = objectNode();
138 + root.set(USERS, userJsonArray());
139 + return root.toString();
140 + }
141 +
142 + /**
143 + * Singleton instance.
144 + */
145 + public static final CordModelCache INSTANCE = new CordModelCache();
91 } 146 }
......
...@@ -29,42 +29,35 @@ import javax.ws.rs.core.Response; ...@@ -29,42 +29,35 @@ import javax.ws.rs.core.Response;
29 @Path("") 29 @Path("")
30 public class CordWebResource { 30 public class CordWebResource {
31 31
32 - private Response fakeData(String which, String suffix) {
33 - String path = "local/" + which + "-" + suffix + ".json";
34 - String content = FakeUtils.slurp(path);
35 - if (content == null) {
36 - return Response.status(Response.Status.NOT_FOUND).build();
37 - }
38 - return Response.ok(content).build();
39 - }
40 -
41 @GET 32 @GET
42 @Produces(MediaType.APPLICATION_JSON) 33 @Produces(MediaType.APPLICATION_JSON)
43 - @Path("dashboard/{suffix}") 34 + @Path("dashboard")
44 - public Response dashboard(@PathParam("suffix") String suffix) { 35 + public Response dashboard() {
45 - return fakeData("dashboard", suffix); 36 + return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build();
46 } 37 }
47 38
48 @GET 39 @GET
49 @Produces(MediaType.APPLICATION_JSON) 40 @Produces(MediaType.APPLICATION_JSON)
50 - @Path("bundle/{suffix}") 41 + @Path("bundle")
51 - public Response bundle(@PathParam("suffix") String suffix) { 42 + public Response bundle() {
52 - return fakeData("bundle", suffix); 43 + return Response.ok(CordModelCache.INSTANCE.jsonBundle()).build();
53 } 44 }
54 45
55 @GET 46 @GET
56 @Produces(MediaType.APPLICATION_JSON) 47 @Produces(MediaType.APPLICATION_JSON)
57 - @Path("users/{suffix}") 48 + @Path("users")
58 - public Response users(@PathParam("suffix") String suffix) { 49 + public Response users() {
59 - return fakeData("users", suffix); 50 + return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
60 } 51 }
61 52
53 + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
54 +
62 @GET 55 @GET
63 @Produces(MediaType.APPLICATION_JSON) 56 @Produces(MediaType.APPLICATION_JSON)
64 - @Path("dashboard") 57 + @Path("bundle/{id}")
65 - public Response dashboard() { 58 + @Deprecated
66 - // TODO: 59 + public Response bundle(@PathParam("id") String bundleId) {
67 - return Response.ok().build(); 60 + CordModelCache.INSTANCE.setCurrentBundle(bundleId);
61 + return bundle();
68 } 62 }
69 -
70 } 63 }
......
...@@ -39,6 +39,13 @@ public interface BundleDescriptor { ...@@ -39,6 +39,13 @@ public interface BundleDescriptor {
39 String displayName(); 39 String displayName();
40 40
41 /** 41 /**
42 + * Textual description of this bundle.
43 + *
44 + * @return description
45 + */
46 + String description();
47 +
48 + /**
42 * The set of functions in this bundle instance. 49 * The set of functions in this bundle instance.
43 * 50 *
44 * @return the functions 51 * @return the functions
......
...@@ -34,9 +34,14 @@ public class BundleFactory extends JsonFactory { ...@@ -34,9 +34,14 @@ public class BundleFactory extends JsonFactory {
34 34
35 private static final String BASIC_ID = "basic"; 35 private static final String BASIC_ID = "basic";
36 private static final String BASIC_DISPLAY_NAME = "Basic Bundle"; 36 private static final String BASIC_DISPLAY_NAME = "Basic Bundle";
37 + private static final String BASIC_DESCRIPTION =
38 + "Provides basic internet and firewall functions.";
37 39
38 private static final String FAMILY_ID = "family"; 40 private static final String FAMILY_ID = "family";
39 private static final String FAMILY_DISPLAY_NAME = "Family Bundle"; 41 private static final String FAMILY_DISPLAY_NAME = "Family Bundle";
42 + private static final String FAMILY_DESCRIPTION =
43 + "Provides internet, firewall and parental control functions.";
44 +
40 45
41 // no instantiation 46 // no instantiation
42 private BundleFactory() {} 47 private BundleFactory() {}
...@@ -46,6 +51,7 @@ public class BundleFactory extends JsonFactory { ...@@ -46,6 +51,7 @@ public class BundleFactory extends JsonFactory {
46 */ 51 */
47 public static final BundleDescriptor BASIC_BUNDLE = 52 public static final BundleDescriptor BASIC_BUNDLE =
48 new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME, 53 new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME,
54 + BASIC_DESCRIPTION,
49 XosFunctionDescriptor.INTERNET, 55 XosFunctionDescriptor.INTERNET,
50 XosFunctionDescriptor.FIREWALL); 56 XosFunctionDescriptor.FIREWALL);
51 57
...@@ -54,6 +60,7 @@ public class BundleFactory extends JsonFactory { ...@@ -54,6 +60,7 @@ public class BundleFactory extends JsonFactory {
54 */ 60 */
55 public static final BundleDescriptor FAMILY_BUNDLE = 61 public static final BundleDescriptor FAMILY_BUNDLE =
56 new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME, 62 new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME,
63 + FAMILY_DESCRIPTION,
57 XosFunctionDescriptor.INTERNET, 64 XosFunctionDescriptor.INTERNET,
58 XosFunctionDescriptor.FIREWALL, 65 XosFunctionDescriptor.FIREWALL,
59 XosFunctionDescriptor.URL_FILTER); 66 XosFunctionDescriptor.URL_FILTER);
...@@ -97,10 +104,12 @@ public class BundleFactory extends JsonFactory { ...@@ -97,10 +104,12 @@ public class BundleFactory extends JsonFactory {
97 */ 104 */
98 public static String toJson(Bundle bundle) { 105 public static String toJson(Bundle bundle) {
99 ObjectNode root = objectNode(); 106 ObjectNode root = objectNode();
107 + BundleDescriptor descriptor = bundle.descriptor();
100 108
101 ObjectNode bnode = objectNode() 109 ObjectNode bnode = objectNode()
102 - .put(ID, bundle.descriptor().id()) 110 + .put(ID, descriptor.id())
103 - .put(NAME, bundle.descriptor().displayName()); 111 + .put(NAME, descriptor.displayName())
112 + .put(DESC, descriptor.description());
104 113
105 ArrayNode funcs = arrayNode(); 114 ArrayNode funcs = arrayNode();
106 for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) { 115 for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) {
...@@ -113,11 +122,11 @@ public class BundleFactory extends JsonFactory { ...@@ -113,11 +122,11 @@ public class BundleFactory extends JsonFactory {
113 for (BundleDescriptor bd: BundleFactory.availableBundles()) { 122 for (BundleDescriptor bd: BundleFactory.availableBundles()) {
114 ObjectNode bdnode = objectNode() 123 ObjectNode bdnode = objectNode()
115 .put(ID, bd.id()) 124 .put(ID, bd.id())
116 - .put(NAME, bd.displayName()); 125 + .put(NAME, bd.displayName())
126 + .put(DESC, bd.description());
117 bundles.add(bdnode); 127 bundles.add(bdnode);
118 } 128 }
119 root.set(BUNDLES, bundles); 129 root.set(BUNDLES, bundles);
120 return root.toString(); 130 return root.toString();
121 -
122 } 131 }
123 } 132 }
......
...@@ -29,6 +29,7 @@ public class DefaultBundleDescriptor implements BundleDescriptor { ...@@ -29,6 +29,7 @@ public class DefaultBundleDescriptor implements BundleDescriptor {
29 29
30 private final String id; 30 private final String id;
31 private final String displayName; 31 private final String displayName;
32 + private final String description;
32 private final Set<XosFunctionDescriptor> functions; 33 private final Set<XosFunctionDescriptor> functions;
33 34
34 /** 35 /**
...@@ -38,10 +39,11 @@ public class DefaultBundleDescriptor implements BundleDescriptor { ...@@ -38,10 +39,11 @@ public class DefaultBundleDescriptor implements BundleDescriptor {
38 * @param displayName bundle display name 39 * @param displayName bundle display name
39 * @param functions functions that make up this bundle 40 * @param functions functions that make up this bundle
40 */ 41 */
41 - DefaultBundleDescriptor(String id, String displayName, 42 + DefaultBundleDescriptor(String id, String displayName, String description,
42 XosFunctionDescriptor... functions) { 43 XosFunctionDescriptor... functions) {
43 this.id = id; 44 this.id = id;
44 this.displayName = displayName; 45 this.displayName = displayName;
46 + this.description = description;
45 this.functions = ImmutableSet.copyOf(functions); 47 this.functions = ImmutableSet.copyOf(functions);
46 } 48 }
47 49
...@@ -54,6 +56,10 @@ public class DefaultBundleDescriptor implements BundleDescriptor { ...@@ -54,6 +56,10 @@ public class DefaultBundleDescriptor implements BundleDescriptor {
54 return displayName; 56 return displayName;
55 } 57 }
56 58
59 + public String description() {
60 + return description;
61 + }
62 +
57 public Set<XosFunctionDescriptor> functions() { 63 public Set<XosFunctionDescriptor> functions() {
58 return functions; 64 return functions;
59 } 65 }
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - */
17 -
18 -package org.onosproject.cord.gui.model;
19 -
20 -import com.fasterxml.jackson.databind.JsonNode;
21 -import com.fasterxml.jackson.databind.ObjectMapper;
22 -import com.fasterxml.jackson.databind.node.ObjectNode;
23 -
24 -/**
25 - * Default implementation of an XOS function.
26 - */
27 -public class DefaultXosFunction implements XosFunction {
28 -
29 - private static final ObjectMapper MAPPER = new ObjectMapper();
30 -
31 - private final XosFunctionDescriptor descriptor;
32 -
33 - public DefaultXosFunction(XosFunctionDescriptor xfd) {
34 - descriptor = xfd;
35 - }
36 -
37 - public XosFunctionDescriptor descriptor() {
38 - return descriptor;
39 - }
40 -
41 - public ObjectNode params() {
42 - return MAPPER.createObjectNode();
43 - }
44 -
45 - public String toJson() {
46 - return null;
47 - }
48 -
49 - public JsonNode toJsonNode() {
50 - return null;
51 - }
52 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - */
17 -
18 -package org.onosproject.cord.gui.model;
19 -
20 -import com.fasterxml.jackson.databind.JsonNode;
21 -
22 -/**
23 - * An object that can be serialized to JSON.
24 - */
25 -public interface JsonBlob {
26 -
27 - /**
28 - * Returns an Object Node representation of this object.
29 - *
30 - * @return object node hierarchy
31 - */
32 - JsonNode toJsonNode();
33 -
34 - /**
35 - * Returns a JSON string representation of this object.
36 - *
37 - * @return JSON serialization
38 - */
39 - String toJson();
40 -}
...@@ -30,6 +30,7 @@ public abstract class JsonFactory { ...@@ -30,6 +30,7 @@ public abstract class JsonFactory {
30 30
31 protected static final String ID = "id"; 31 protected static final String ID = "id";
32 protected static final String NAME = "name"; 32 protected static final String NAME = "name";
33 + protected static final String DESC = "desc";
33 34
34 /** 35 /**
35 * Returns a freshly minted object node. 36 * Returns a freshly minted object node.
......
...@@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
23 /** 23 /**
24 * Designates a specific instance of an XOS function. 24 * Designates a specific instance of an XOS function.
25 */ 25 */
26 -public interface XosFunction extends JsonBlob { 26 +public interface XosFunction {
27 27
28 /** 28 /**
29 * Returns the descriptor for this function. 29 * Returns the descriptor for this function.
......
...@@ -12,7 +12,6 @@ import java.util.Map; ...@@ -12,7 +12,6 @@ import java.util.Map;
12 */ 12 */
13 public class XosFunctionFactory extends JsonFactory { 13 public class XosFunctionFactory extends JsonFactory {
14 14
15 - private static final String DESC = "desc";
16 private static final String PARAMS = "params"; 15 private static final String PARAMS = "params";
17 16
18 private static final String LEVEL = "level"; 17 private static final String LEVEL = "level";
......