From b731e2f1dd0972409b136aebc7b463dd72c9cfad Mon Sep 17 00:00:00 2001 From: CNlucius Date: Tue, 13 Sep 2016 11:40:12 +0800 Subject: ONOSFW-171 O/S-SFC-ONOS scenario documentation Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365 Signed-off-by: CNlucius --- .../org/onosproject/cord/gui/model/Bundle.java | 95 -------------- .../cord/gui/model/BundleDescriptor.java | 54 -------- .../onosproject/cord/gui/model/BundleFactory.java | 144 --------------------- .../cord/gui/model/DefaultBundleDescriptor.java | 89 ------------- .../cord/gui/model/DefaultXosFunction.java | 66 ---------- .../onosproject/cord/gui/model/JsonFactory.java | 53 -------- .../onosproject/cord/gui/model/SubscriberUser.java | 131 ------------------- .../cord/gui/model/UrlFilterFunction.java | 93 ------------- .../onosproject/cord/gui/model/UserFactory.java | 68 ---------- .../onosproject/cord/gui/model/XosFunction.java | 73 ----------- .../cord/gui/model/XosFunctionDescriptor.java | 126 ------------------ .../cord/gui/model/XosFunctionFactory.java | 115 ---------------- 12 files changed, 1107 deletions(-) delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java delete mode 100644 framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java (limited to 'framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model') diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java deleted file mode 100644 index c51cc848..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/Bundle.java +++ /dev/null @@ -1,95 +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.google.common.collect.ImmutableSet; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * Encapsulates a bundle, including current state. - */ -public class Bundle { - private final BundleDescriptor bundleDescriptor; - private final Map functionMap = - new HashMap(); - - /** - * Constructs a new bundle instance. - * - * @param bundleDescriptor the descriptor - */ - public Bundle(BundleDescriptor bundleDescriptor) { - this.bundleDescriptor = bundleDescriptor; - initFunctions(); - } - - /** - * Returns the bundle descriptor. - * - * @return the descriptor - */ - public BundleDescriptor descriptor() { - return bundleDescriptor; - } - - /** - * Returns the set of function instances for this bundle. - * - * @return the functions - */ - public Set functions() { - return ImmutableSet.copyOf(functionMap.values()); - } - - /** - * Creates an initial set of function instances. - */ - private void initFunctions() { - for (XosFunctionDescriptor xfd: bundleDescriptor.functions()) { - functionMap.put(xfd, createFunction(xfd)); - } - } - - private XosFunction createFunction(XosFunctionDescriptor xfd) { - XosFunction func; - switch (xfd) { - case URL_FILTER: - func = new UrlFilterFunction(); - break; - - default: - func = new DefaultXosFunction(xfd); - break; - } - return func; - } - - /** - * Returns the function instance for the specified descriptor, or returns - * null if function is not part of this bundle. - * - * @param xfd function descrriptor - * @return function instance - */ - public XosFunction findFunction(XosFunctionDescriptor xfd) { - return functionMap.get(xfd); - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java deleted file mode 100644 index 4a970543..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleDescriptor.java +++ /dev/null @@ -1,54 +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 java.util.Set; - -/** - * Defines a bundle of {@link XosFunctionDescriptor XOS functions}. - */ -public interface BundleDescriptor { - - /** - * Bundle internal identifier. - * - * @return bundle identifier - */ - String id(); - - /** - * Bundle display name. - * - * @return display name - */ - String displayName(); - - /** - * Textual description of this bundle. - * - * @return description - */ - String description(); - - /** - * The set of functions in this bundle instance. - * - * @return the functions - */ - Set functions(); -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java deleted file mode 100644 index 813ad98b..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/BundleFactory.java +++ /dev/null @@ -1,144 +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.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.ImmutableList; - -import java.util.List; - -/** - * Utility factory for creating and/or operating on bundles. - */ -public class BundleFactory extends JsonFactory { - - private static final String BUNDLE = "bundle"; - private static final String BUNDLES = "bundles"; - private static final String FUNCTIONS = "functions"; - - private static final String BASIC_ID = "basic"; - private static final String BASIC_DISPLAY_NAME = "Basic Bundle"; - private static final String BASIC_DESCRIPTION = - "If the thing that matters most to you is high speed Internet" + - " connectivity delivered at a great price, then the basic" + - " bundle is right for you.\n" + - "Starting at $30 a month for 12 months."; - - private static final String FAMILY_ID = "family"; - private static final String FAMILY_DISPLAY_NAME = "Family Bundle"; - private static final String FAMILY_DESCRIPTION = - "Enjoy great entertainment, peace of mind and big savings when " + - "you bundle high speed Internet and Firewall with" + - " Parental Control.\n" + - "Starting at $40 a month for 12 months."; - - - // no instantiation - private BundleFactory() {} - - /** - * Designates the BASIC bundle. - */ - public static final BundleDescriptor BASIC_BUNDLE = - new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME, - BASIC_DESCRIPTION, - XosFunctionDescriptor.INTERNET, - XosFunctionDescriptor.FIREWALL, - XosFunctionDescriptor.CDN); - - /** - * Designates the FAMILY bundle. - */ - public static final BundleDescriptor FAMILY_BUNDLE = - new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME, - FAMILY_DESCRIPTION, - XosFunctionDescriptor.INTERNET, - XosFunctionDescriptor.FIREWALL, - XosFunctionDescriptor.CDN, - XosFunctionDescriptor.URL_FILTER); - - // all bundles, in the order they should be listed in the GUI - private static final List ALL_BUNDLES = ImmutableList.of( - BASIC_BUNDLE, - FAMILY_BUNDLE - ); - - /** - * Returns the list of available bundles. - * - * @return available bundles - */ - public static List availableBundles() { - return ALL_BUNDLES; - } - - /** - * Returns the bundle descriptor for the given identifier. - * - * @param bundleId bundle identifier - * @return bundle descriptor - * @throws IllegalArgumentException if bundle ID is unknown - */ - public static BundleDescriptor bundleFromId(String bundleId) { - for (BundleDescriptor bd : ALL_BUNDLES) { - if (bd.id().equals(bundleId)) { - return bd; - } - } - throw new IllegalArgumentException("unknown bundle: " + bundleId); - } - - /** - * Returns an object node representation of the given bundle. - * Note that some functions (such as CDN) are not added to the output - * as we don't want them to appear in the GUI. - * - * @param bundle the bundle - * @return object node - */ - public static ObjectNode toObjectNode(Bundle bundle) { - ObjectNode root = objectNode(); - BundleDescriptor descriptor = bundle.descriptor(); - - ObjectNode bnode = objectNode() - .put(ID, descriptor.id()) - .put(NAME, descriptor.displayName()) - .put(DESC, descriptor.description()); - - ArrayNode funcs = arrayNode(); - for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) { - if (xfd.visible()) { - funcs.add(XosFunctionFactory.toObjectNode(xfd)); - } - } - bnode.set(FUNCTIONS, funcs); - root.set(BUNDLE, bnode); - - ArrayNode bundles = arrayNode(); - for (BundleDescriptor bd: BundleFactory.availableBundles()) { - ObjectNode bdnode = objectNode() - .put(ID, bd.id()) - .put(NAME, bd.displayName()) - .put(DESC, bd.description()); - bundles.add(bdnode); - } - root.set(BUNDLES, bundles); - return root; - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java deleted file mode 100644 index 1c3d4abc..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultBundleDescriptor.java +++ /dev/null @@ -1,89 +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.google.common.collect.ImmutableSet; - -import java.util.Set; - - -/** - * Base implementation of BundleDescriptor. - */ -public class DefaultBundleDescriptor implements BundleDescriptor { - - private final String id; - private final String displayName; - private final String description; - private final Set functions; - - /** - * Constructs a bundle descriptor. - * - * @param id bundle identifier - * @param displayName bundle display name - * @param functions functions that make up this bundle - */ - DefaultBundleDescriptor(String id, String displayName, String description, - XosFunctionDescriptor... functions) { - this.id = id; - this.displayName = displayName; - this.description = description; - this.functions = ImmutableSet.copyOf(functions); - } - - - public String id() { - return id; - } - - public String displayName() { - return displayName; - } - - public String description() { - return description; - } - - public Set functions() { - return functions; - } - - @Override - public String toString() { - return "{BundleDescriptor: " + displayName + "}"; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - DefaultBundleDescriptor that = (DefaultBundleDescriptor) o; - return id.equals(that.id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java deleted file mode 100644 index 1ffa8ef0..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/DefaultXosFunction.java +++ /dev/null @@ -1,66 +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.ObjectMapper; - -/** - * Default XOS function implementation, that does not have any parameters - * to tweak. - */ -public class DefaultXosFunction implements XosFunction { - - protected static final ObjectMapper MAPPER = new ObjectMapper(); - - private final XosFunctionDescriptor xfd; - - public DefaultXosFunction(XosFunctionDescriptor xfd) { - this.xfd = xfd; - } - - public XosFunctionDescriptor descriptor() { - return xfd; - } - - /** - * {@inheritDoc} - *

- * This default implementation throws an exception. - * - * @param user user to apply the change to - * @param param parameter name - * @param value new parameter value - * @throws UnsupportedOperationException if invoked - */ - public void applyParam(SubscriberUser user, String param, String value) { - throw new UnsupportedOperationException(); - } - - public Memento createMemento() { - return null; - } - - public String xosUrlApply(SubscriberUser user) { - return null; - } - - @Override - public String toString() { - return "{XosFunction: " + xfd + "}"; - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java deleted file mode 100644 index 3f295994..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/JsonFactory.java +++ /dev/null @@ -1,53 +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.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Base class for factories that convert objects to JSON. - */ -public abstract class JsonFactory { - - private static final ObjectMapper MAPPER = new ObjectMapper(); - - protected static final String ID = "id"; - protected static final String NAME = "name"; - protected static final String DESC = "desc"; - protected static final String ICON_ID = "icon_id"; - - /** - * Returns a freshly minted object node. - * - * @return empty object node - */ - protected static ObjectNode objectNode() { - return MAPPER.createObjectNode(); - } - - /** - * Returns a freshly minted array node. - * - * @return empty array node - */ - protected static ArrayNode arrayNode() { - return MAPPER.createArrayNode(); - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java deleted file mode 100644 index 81261821..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/SubscriberUser.java +++ /dev/null @@ -1,131 +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 java.util.HashMap; -import java.util.Map; - -/** - * Designates a user of a subscriber's account. - */ -public class SubscriberUser { - private final int id; - private final String name; - private final String mac; - - // this is "duplicated" in the URL_FILTER memento, but, oh well... - // -- the level, as returned from XOS, when we create this user object. - private String level; - - private final Map mementos = - new HashMap(); - - /** - * Constructs a subscriber user from the given parameters. - * - * @param id internal identifier - * @param name display name - * @param mac MAC address of the associated device - * @param level URL filter level - */ - public SubscriberUser(int id, String name, String mac, String level) { - this.id = id; - this.name = name; - this.mac = mac; - this.level = level; - } - - /** - * Returns the internal identifier. - * - * @return the identifier - */ - public int id() { - return id; - } - - /** - * Returns the display name. - * - * @return display name - */ - public String name() { - return name; - } - - /** - * Returns the MAC address of the associated device. - * - * @return MAC address - */ - public String mac() { - return mac; - } - - /** - * Returns the URL filter level. - * - * @return URL filter level - */ - public String urlFilterLevel() { - return level; - } - - /** - * Sets the URL filter level. - * - * @param level URL filter level - */ - public void setUrlFilterLevel(String level) { - this.level = level; - } - - /** - * Stores a memento for the given XOS function. - * - * @param f XOS function - * @param m memento - */ - public void setMemento(XosFunctionDescriptor f, XosFunction.Memento m) { - if (m != null) { - mementos.put(f, m); - } - } - - /** - * Returns the memento stored on this user, for the given XOS function. - * - * @param f XOS function - * @return memento - */ - public XosFunction.Memento getMemento(XosFunctionDescriptor f) { - return mementos.get(f); - } - - /** - * Clears the memento map. - */ - public void clearMementos() { - mementos.clear(); - } - - @Override - public String toString() { - return "{User: " + name + "}"; - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java deleted file mode 100644 index ec1ff380..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UrlFilterFunction.java +++ /dev/null @@ -1,93 +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.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Specialization of XosFunction for URL filtering. - */ -public class UrlFilterFunction extends DefaultXosFunction { - - private static final String LEVEL = "level"; - private static final String URI_PATTERN = "%s/%s/"; - - /** - * Denotes the URL filtering levels available. From most restrictive - * to least restrictive. Note: NONE allows nothing; - * ALL allows everything. - */ - public enum Level { NONE, G, PG, PG_13, R, ALL } - - /** - * The default URL filtering level - */ - public static final Level DEFAULT_LEVEL = Level.G; - - public UrlFilterFunction() { - super(XosFunctionDescriptor.URL_FILTER); - } - - @Override - public void applyParam(SubscriberUser user, String param, String value) { - Memento memo = user.getMemento(descriptor()); - checkNotNull(memo, "missing memento for " + descriptor()); - UrlFilterMemento ufMemo = (UrlFilterMemento) memo; - - if (LEVEL.equals(param)) { - Level newLevel = Level.valueOf(value.toUpperCase()); - ufMemo.setLevel(newLevel); - - // Also store the (string version) of the level - // (not in the memento). Hackish, but that's how it is for now. - user.setUrlFilterLevel(value); - } - } - - @Override - public Memento createMemento() { - return new UrlFilterMemento(); - } - - class UrlFilterMemento implements Memento { - private Level level = DEFAULT_LEVEL; - - public ObjectNode toObjectNode() { - ObjectNode node = MAPPER.createObjectNode(); - node.put(LEVEL, level.name()); - return node; - } - - public void setLevel(Level level) { - this.level = level; - } - - public String level() { - return level.toString(); - } - } - - @Override - public String xosUrlApply(SubscriberUser user) { - XosFunctionDescriptor xfd = XosFunctionDescriptor.URL_FILTER; - UrlFilterMemento memo = (UrlFilterMemento) user.getMemento(xfd); - return String.format(URI_PATTERN, xfd.id(), memo.level()); - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java deleted file mode 100644 index c843af1b..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/UserFactory.java +++ /dev/null @@ -1,68 +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.node.ObjectNode; - -import java.util.HashMap; -import java.util.Map; - -/** - * Utility functions on users. - */ -public class UserFactory extends JsonFactory { - - private static final String MAC = "mac"; - private static final String PROFILE = "profile"; - - - // hard-coded icons for the demo - private static final Map ICON_LOOKUP = - new HashMap(); - static { - ICON_LOOKUP.put("Mom's PC", "mom"); - ICON_LOOKUP.put("Dad's PC", "dad"); - ICON_LOOKUP.put("Jack's Laptop", "boy2"); - ICON_LOOKUP.put("Jill's Laptop", "girl1"); - } - - private static final String DEFAULT_ICON_ID = "boy1"; - - // no instantiation - private UserFactory() {} - - /** - * Returns an object node representation of the given user. - * - * @param user the user - * @return object node - */ - public static ObjectNode toObjectNode(SubscriberUser user) { - String icon = ICON_LOOKUP.get(user.name()); - icon = icon == null ? DEFAULT_ICON_ID : icon; - - ObjectNode root = objectNode() - .put(ID, user.id()) - .put(ICON_ID, icon) - .put(NAME, user.name()) - .put(MAC, user.mac()); - root.set(PROFILE, XosFunctionFactory.profileForUser(user)); - return root; - } - -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java deleted file mode 100644 index 2790dfd5..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunction.java +++ /dev/null @@ -1,73 +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.node.ObjectNode; - -/** - * Designates a specific instance of an XOS function. - */ -public interface XosFunction { - - /** - * Returns the descriptor for this function. - * - * @return function descriptor - */ - XosFunctionDescriptor descriptor(); - - /** - * Applies a parameter change for the given user. - * - * @param user user to apply change to - * @param param parameter name - * @param value new parameter value - */ - void applyParam(SubscriberUser user, String param, String value); - - /** - * Create an initialized memento. - * If the function maintains no state per user, return null. - * - * @return a new memento - */ - Memento createMemento(); - - /** - * Create the XOS specific URL suffix for applying state change for - * the given user. - * - * @param user the user - * @return URL suffix - */ - String xosUrlApply(SubscriberUser user); - - /** - * Internal state memento. - */ - interface Memento { - /** - * Returns a JSON representation of this memento. - * - * @return memento state as object node - */ - ObjectNode toObjectNode(); - } -} - diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java deleted file mode 100644 index efc95377..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionDescriptor.java +++ /dev/null @@ -1,126 +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; - -/** - * Designates XOS Functions. - */ -public enum XosFunctionDescriptor { - /** - * Internet function. - */ - INTERNET("internet", - "Internet", - "Discover the joys of high-speed, reliable Internet" + - " connectivity delivered seamlessly to your home.", - false, - true), - - /** - * Firewall function. - */ - FIREWALL("firewall", - "Firewall", - "Simple access control and filtering with minimal set-up.", - true, - true), - - /** - * URL Filtering function (parental controls). - */ - URL_FILTER("url_filter", - "Parental Control", - "Parental Control is peace of mind that your kids are safe" + - " - whether you are around or away. Indicate with a " + - "few clicks what online content is appropriate for " + - "your children, and voila - you have control over" + - " what your kids can and cannot view.", - true, - true), - - /** - * Content Distribution function. - */ - CDN("cdn", - "CDN", - "Content Distribution Network service.", - true, - false); - - - private final String id; - private final String displayName; - private final String description; - private final boolean backend; - private final boolean visible; - - XosFunctionDescriptor(String id, String displayName, String description, - boolean backend, boolean visible) { - this.id = id; - this.displayName = displayName; - this.description = description; - this.backend = backend; - this.visible = visible; - } - - /** - * Returns this function's internal identifier. - * - * @return the identifier - */ - public String id() { - return id; - } - - /** - * Returns this function's display name. - * - * @return display name - */ - public String displayName() { - return displayName; - } - - /** - * Returns a short, textual description of the function. - * - * @return textual description - */ - public String description() { - return description; - } - - /** - * Returns true if this function is supported by the XOS backend. - * - * @return true if backend function exists - */ - public boolean backend() { - return backend; - } - - /** - * Returns true if this function should be shown in the GUI, in the - * bundle listing. - * - * @return true if to be displayed - */ - public boolean visible() { - return visible; - } -} diff --git a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java b/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java deleted file mode 100644 index dffabceb..00000000 --- a/framework/src/onos/apps/demo/cord-gui/src/main/java/org/onosproject/cord/gui/model/XosFunctionFactory.java +++ /dev/null @@ -1,115 +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.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"; - - - // no instantiation - private XosFunctionFactory() {} - - /** - * Produces the JSON representation of the given XOS function descriptor. - * - * @param xfd function descriptor - * @return JSON encoding - */ - public static ObjectNode toObjectNode(XosFunctionDescriptor xfd) { - ObjectNode root = objectNode() - .put(ID, xfd.id()) - .put(NAME, xfd.displayName()) - .put(DESC, xfd.description()); - root.set(PARAMS, paramsForXfd(xfd)); - return root; - } - - private static ObjectNode paramsForXfd(XosFunctionDescriptor xfd) { - ParamsFactory psf = PARAM_MAP.get(xfd); - if (psf == null) { - psf = DEF_PARAMS_FACTORY; - } - return psf.params(); - } - - - // ==== handling different parameter structures... - private static final Map - PARAM_MAP = new HashMap(); - - private static final ParamsFactory DEF_PARAMS_FACTORY = new ParamsFactory(); - static { - PARAM_MAP.put(URL_FILTER, new UrlFilterParamsFactory()); - } - - /** - * 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 ParamsFactory { - ObjectNode params() { - return objectNode(); - } - } - - static class UrlFilterParamsFactory extends ParamsFactory { - @Override - ObjectNode params() { - ObjectNode result = objectNode(); - result.put(LEVEL, UrlFilterFunction.DEFAULT_LEVEL.name()); - ArrayNode levels = arrayNode(); - for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) { - levels.add(lvl.name()); - } - result.set(LEVELS, levels); - return result; - } - } -} -- cgit 1.2.3-korg