CORD Subscriber GUI - XosFunction mementos now stored inside each SubscriberUser to capture the parameter state per user.

Change-Id: I678249f63a68172db66a5d3faa0b1747c670bf6e
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 69c5bb5..93ed831 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
@@ -1,30 +1,24 @@
 package org.onosproject.cord.gui.model;
 
-import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 import java.util.HashMap;
 import java.util.Map;
 
+import static org.onosproject.cord.gui.model.XosFunctionDescriptor.URL_FILTER;
+
 /**
  * Utility factory for operating on XOS functions.
  */
 public class XosFunctionFactory extends JsonFactory {
 
     private static final String PARAMS = "params";
-
     private static final String LEVEL = "level";
     private static final String LEVELS = "levels";
 
-
-    // URL Filtering Levels...
-    private static final String PG = "PG";
-    private static final String PG13 = "PG-13";
-    private static final String R = "R";
-
-    private static final String[] FILTER_LEVELS = { PG, PG13, R };
-    private static final String DEFAULT_FILTER_LEVEL = PG;
+    private static final UrlFilterFunction.Level DEFAULT_FILTER_LEVEL =
+        UrlFilterFunction.Level.PG;
 
 
     // no instantiation
@@ -45,38 +39,76 @@
         return root;
     }
 
-    private static JsonNode paramsForXfd(XosFunctionDescriptor xfd) {
-        ParamStructFactory psf = PARAM_MAP.get(xfd);
+    private static ObjectNode paramsForXfd(XosFunctionDescriptor xfd) {
+        ParamsFactory psf = PARAM_MAP.get(xfd);
         if (psf == null) {
-            psf = DEF_PARAMS;
+            psf = DEF_PARAMS_FACTORY;
         }
         return psf.params();
     }
 
-    // ==== handling different parameter structures...
-    private static final Map<XosFunctionDescriptor, ParamStructFactory>
-        PARAM_MAP = new HashMap<XosFunctionDescriptor, ParamStructFactory>();
 
-    private static final ParamStructFactory DEF_PARAMS = new ParamStructFactory();
+    // ==== handling different parameter structures...
+    private static final Map<XosFunctionDescriptor, ParamsFactory>
+        PARAM_MAP = new HashMap<XosFunctionDescriptor, ParamsFactory>();
+
+    private static final ParamsFactory DEF_PARAMS_FACTORY = new ParamsFactory();
     static {
-        PARAM_MAP.put(XosFunctionDescriptor.URL_FILTER, new UrlFilterParams());
+        PARAM_MAP.put(URL_FILTER, new UrlFilterParamsFactory());
     }
 
+    /**
+     * Applies a parameter change for the given function, in the context of
+     * the specified user.
+     *
+     * @param xfd function context
+     * @param userId user identifier
+     * @param param parameter name
+     * @param value value to apply
+     */
+    public static void apply(XosFunctionDescriptor xfd, int userId,
+                             String param, String value) {
+        // TODO:
+    }
+
+    /**
+     * Creates an object node representation of the profile for the
+     * specified user.
+     *
+     * @param user the user
+     * @return object node profile
+     */
+    public static ObjectNode profileForUser(SubscriberUser user) {
+        ObjectNode root = objectNode();
+        for (XosFunctionDescriptor xfd: XosFunctionDescriptor.values()) {
+            XosFunction.Memento mem = user.getMemento(xfd);
+            if (mem != null) {
+                root.set(xfd.id(), mem.toObjectNode());
+            }
+        }
+        return root;
+    }
+
+
+    // ===================================================================
+    // === factories for creating parameter structures, both default
+    //     and from a memento...
+
     // private parameter structure creator
-    static class ParamStructFactory {
+    static class ParamsFactory {
         ObjectNode params() {
             return objectNode();
         }
     }
 
-    static class UrlFilterParams extends ParamStructFactory {
+    static class UrlFilterParamsFactory extends ParamsFactory {
         @Override
         ObjectNode params() {
             ObjectNode result = objectNode();
-            result.put(LEVEL, DEFAULT_FILTER_LEVEL);
+            result.put(LEVEL, DEFAULT_FILTER_LEVEL.name());
             ArrayNode levels = arrayNode();
-            for (String lvl: FILTER_LEVELS) {
-                levels.add(lvl);
+            for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) {
+                levels.add(lvl.name());
             }
             result.set(LEVELS, levels);
             return result;