CORD Subscriber GUI -- Added description field to bundle.
- deleted obsolete classes.
Change-Id: Ied2dbc36c0c74894789e2aba6ddddd29c2e90b49
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
index f09ecfe..e47e68f 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordModelCache.java
@@ -17,11 +17,15 @@
package org.onosproject.cord.gui;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableList;
import org.onosproject.cord.gui.model.Bundle;
import org.onosproject.cord.gui.model.BundleDescriptor;
import org.onosproject.cord.gui.model.BundleFactory;
+import org.onosproject.cord.gui.model.JsonFactory;
import org.onosproject.cord.gui.model.SubscriberUser;
+import org.onosproject.cord.gui.model.UserFactory;
import java.util.ArrayList;
import java.util.List;
@@ -29,7 +33,11 @@
/**
* In memory cache of the model of the subscriber's account.
*/
-public class CordModelCache {
+public class CordModelCache extends JsonFactory {
+
+ private static final String BUNDLE = "bundle";
+ private static final String USERS = "users";
+
// faked for the demo
private static final int SUBSCRIBER_ID = 92;
@@ -44,7 +52,7 @@
/**
* Constructs a model cache, initializing it with basic bundle.
*/
- public CordModelCache() {
+ CordModelCache() {
currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
users = new ArrayList<SubscriberUser>();
initUsers();
@@ -88,4 +96,51 @@
public List<SubscriberUser> getUsers() {
return ImmutableList.copyOf(users);
}
+
+ private ArrayNode userJsonArray() {
+ ArrayNode userList = arrayNode();
+ for (SubscriberUser user: users) {
+ userList.add(UserFactory.toObjectNode(user));
+ }
+ return userList;
+ }
+
+ // ============= generate JSON for GUI rest calls..
+
+ /**
+ * Returns the dashboard page data as JSON.
+ *
+ * @return dashboard page JSON data
+ */
+ public String jsonDashboard() {
+ ObjectNode root = objectNode();
+ root.put(BUNDLE, currentBundle.descriptor().displayName());
+ root.set(USERS, userJsonArray());
+ return root.toString();
+ }
+
+ /**
+ * Returns the bundle page data as JSON.
+ *
+ * @return bundle page JSON data
+ */
+ public String jsonBundle() {
+ return BundleFactory.toJson(currentBundle);
+ }
+
+ /**
+ * Returns the users page data as JSON.
+ *
+ * @return users page JSON data
+ */
+ public String jsonUsers() {
+ ObjectNode root = objectNode();
+ root.set(USERS, userJsonArray());
+ return root.toString();
+ }
+
+ /**
+ * Singleton instance.
+ */
+ public static final CordModelCache INSTANCE = new CordModelCache();
}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java
index f811044..fa4bba1 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/CordWebResource.java
@@ -29,42 +29,35 @@
@Path("")
public class CordWebResource {
- private Response fakeData(String which, String suffix) {
- String path = "local/" + which + "-" + suffix + ".json";
- String content = FakeUtils.slurp(path);
- if (content == null) {
- return Response.status(Response.Status.NOT_FOUND).build();
- }
- return Response.ok(content).build();
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("dashboard/{suffix}")
- public Response dashboard(@PathParam("suffix") String suffix) {
- return fakeData("dashboard", suffix);
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("bundle/{suffix}")
- public Response bundle(@PathParam("suffix") String suffix) {
- return fakeData("bundle", suffix);
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("users/{suffix}")
- public Response users(@PathParam("suffix") String suffix) {
- return fakeData("users", suffix);
- }
-
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("dashboard")
public Response dashboard() {
- // TODO:
- return Response.ok().build();
+ return Response.ok(CordModelCache.INSTANCE.jsonDashboard()).build();
}
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("bundle")
+ public Response bundle() {
+ return Response.ok(CordModelCache.INSTANCE.jsonBundle()).build();
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("users")
+ public Response users() {
+ return Response.ok(CordModelCache.INSTANCE.jsonUsers()).build();
+ }
+
+ // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("bundle/{id}")
+ @Deprecated
+ public Response bundle(@PathParam("id") String bundleId) {
+ CordModelCache.INSTANCE.setCurrentBundle(bundleId);
+ return bundle();
+ }
}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java
index 8ba5aef..4a97054 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java
@@ -39,6 +39,13 @@
String displayName();
/**
+ * Textual description of this bundle.
+ *
+ * @return description
+ */
+ String description();
+
+ /**
* The set of functions in this bundle instance.
*
* @return the functions
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java
index 0b3c90e..f951409 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java
@@ -34,9 +34,14 @@
private static final String BASIC_ID = "basic";
private static final String BASIC_DISPLAY_NAME = "Basic Bundle";
+ private static final String BASIC_DESCRIPTION =
+ "Provides basic internet and firewall functions.";
private static final String FAMILY_ID = "family";
private static final String FAMILY_DISPLAY_NAME = "Family Bundle";
+ private static final String FAMILY_DESCRIPTION =
+ "Provides internet, firewall and parental control functions.";
+
// no instantiation
private BundleFactory() {}
@@ -46,6 +51,7 @@
*/
public static final BundleDescriptor BASIC_BUNDLE =
new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME,
+ BASIC_DESCRIPTION,
XosFunctionDescriptor.INTERNET,
XosFunctionDescriptor.FIREWALL);
@@ -54,6 +60,7 @@
*/
public static final BundleDescriptor FAMILY_BUNDLE =
new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME,
+ FAMILY_DESCRIPTION,
XosFunctionDescriptor.INTERNET,
XosFunctionDescriptor.FIREWALL,
XosFunctionDescriptor.URL_FILTER);
@@ -97,10 +104,12 @@
*/
public static String toJson(Bundle bundle) {
ObjectNode root = objectNode();
+ BundleDescriptor descriptor = bundle.descriptor();
ObjectNode bnode = objectNode()
- .put(ID, bundle.descriptor().id())
- .put(NAME, bundle.descriptor().displayName());
+ .put(ID, descriptor.id())
+ .put(NAME, descriptor.displayName())
+ .put(DESC, descriptor.description());
ArrayNode funcs = arrayNode();
for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) {
@@ -113,11 +122,11 @@
for (BundleDescriptor bd: BundleFactory.availableBundles()) {
ObjectNode bdnode = objectNode()
.put(ID, bd.id())
- .put(NAME, bd.displayName());
+ .put(NAME, bd.displayName())
+ .put(DESC, bd.description());
bundles.add(bdnode);
}
root.set(BUNDLES, bundles);
return root.toString();
-
}
}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java
index 509e179..1c3d4ab 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java
@@ -29,6 +29,7 @@
private final String id;
private final String displayName;
+ private final String description;
private final Set<XosFunctionDescriptor> functions;
/**
@@ -38,10 +39,11 @@
* @param displayName bundle display name
* @param functions functions that make up this bundle
*/
- DefaultBundleDescriptor(String id, String displayName,
+ DefaultBundleDescriptor(String id, String displayName, String description,
XosFunctionDescriptor... functions) {
this.id = id;
this.displayName = displayName;
+ this.description = description;
this.functions = ImmutableSet.copyOf(functions);
}
@@ -54,6 +56,10 @@
return displayName;
}
+ public String description() {
+ return description;
+ }
+
public Set<XosFunctionDescriptor> functions() {
return functions;
}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java
deleted file mode 100644
index 6bdee4f..0000000
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Default implementation of an XOS function.
- */
-public class DefaultXosFunction implements XosFunction {
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- private final XosFunctionDescriptor descriptor;
-
- public DefaultXosFunction(XosFunctionDescriptor xfd) {
- descriptor = xfd;
- }
-
- public XosFunctionDescriptor descriptor() {
- return descriptor;
- }
-
- public ObjectNode params() {
- return MAPPER.createObjectNode();
- }
-
- public String toJson() {
- return null;
- }
-
- public JsonNode toJsonNode() {
- return null;
- }
-}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonBlob.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonBlob.java
deleted file mode 100644
index 5c20b62..0000000
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonBlob.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onosproject.cord.gui.model;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * An object that can be serialized to JSON.
- */
-public interface JsonBlob {
-
- /**
- * Returns an Object Node representation of this object.
- *
- * @return object node hierarchy
- */
- JsonNode toJsonNode();
-
- /**
- * Returns a JSON string representation of this object.
- *
- * @return JSON serialization
- */
- String toJson();
-}
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java
index 5592b51..fd5cdb5 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java
@@ -30,6 +30,7 @@
protected static final String ID = "id";
protected static final String NAME = "name";
+ protected static final String DESC = "desc";
/**
* Returns a freshly minted object node.
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java
index c580149..1721685 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java
@@ -23,7 +23,7 @@
/**
* Designates a specific instance of an XOS function.
*/
-public interface XosFunction extends JsonBlob {
+public interface XosFunction {
/**
* Returns the descriptor for this function.
diff --git a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java
index ea9ec35..69c5bb5 100644
--- a/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java
+++ b/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java
@@ -12,7 +12,6 @@
*/
public class XosFunctionFactory extends JsonFactory {
- private static final String DESC = "desc";
private static final String PARAMS = "params";
private static final String LEVEL = "level";