Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 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 | |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 20 | import java.util.HashMap; |
| 21 | import java.util.Map; |
| 22 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Designates a user of a subscriber's account. |
| 25 | */ |
| 26 | public class SubscriberUser { |
| 27 | private final int id; |
| 28 | private final String name; |
| 29 | private final String mac; |
| 30 | |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 31 | // this is "duplicated" in the URL_FILTER memento, but, oh well... |
| 32 | // -- the level, as returned from XOS, when we create this user object. |
| 33 | private String level; |
| 34 | |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 35 | private final Map<XosFunctionDescriptor, XosFunction.Memento> mementos = |
| 36 | new HashMap<XosFunctionDescriptor, XosFunction.Memento>(); |
| 37 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Constructs a subscriber user from the given parameters. |
| 40 | * |
| 41 | * @param id internal identifier |
| 42 | * @param name display name |
| 43 | * @param mac MAC address of the associated device |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 44 | * @param level URL filter level |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 45 | */ |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 46 | public SubscriberUser(int id, String name, String mac, String level) { |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 47 | this.id = id; |
| 48 | this.name = name; |
| 49 | this.mac = mac; |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 50 | this.level = level; |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns the internal identifier. |
| 55 | * |
| 56 | * @return the identifier |
| 57 | */ |
| 58 | public int id() { |
| 59 | return id; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the display name. |
| 64 | * |
| 65 | * @return display name |
| 66 | */ |
| 67 | public String name() { |
| 68 | return name; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the MAC address of the associated device. |
| 73 | * |
| 74 | * @return MAC address |
| 75 | */ |
| 76 | public String mac() { |
| 77 | return mac; |
| 78 | } |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 81 | * Returns the URL filter level. |
| 82 | * |
| 83 | * @return URL filter level |
| 84 | */ |
| 85 | public String urlFilterLevel() { |
| 86 | return level; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets the URL filter level. |
| 91 | * |
| 92 | * @param level URL filter level |
| 93 | */ |
| 94 | public void setUrlFilterLevel(String level) { |
| 95 | this.level = level; |
| 96 | } |
| 97 | |
| 98 | /** |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 99 | * Stores a memento for the given XOS function. |
| 100 | * |
| 101 | * @param f XOS function |
| 102 | * @param m memento |
| 103 | */ |
| 104 | public void setMemento(XosFunctionDescriptor f, XosFunction.Memento m) { |
| 105 | if (m != null) { |
| 106 | mementos.put(f, m); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the memento stored on this user, for the given XOS function. |
| 112 | * |
| 113 | * @param f XOS function |
| 114 | * @return memento |
| 115 | */ |
| 116 | public XosFunction.Memento getMemento(XosFunctionDescriptor f) { |
| 117 | return mementos.get(f); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Clears the memento map. |
| 122 | */ |
| 123 | public void clearMementos() { |
| 124 | mementos.clear(); |
| 125 | } |
Simon Hunt | a00b0ce | 2015-05-22 15:57:11 -0700 | [diff] [blame] | 126 | |
| 127 | @Override |
| 128 | public String toString() { |
| 129 | return "{User: " + name + "}"; |
| 130 | } |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 131 | } |