blob: c843af1b295cd01ba5d6fa0492d04c014eb01317 [file] [log] [blame]
Simon Hunt41b943e2015-05-21 13:52:01 -07001/*
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
18package org.onosproject.cord.gui.model;
19
20import com.fasterxml.jackson.databind.node.ObjectNode;
21
Simon Hunt0d94f062015-06-04 10:56:03 -070022import java.util.HashMap;
23import java.util.Map;
24
Simon Hunt41b943e2015-05-21 13:52:01 -070025/**
26 * Utility functions on users.
27 */
28public class UserFactory extends JsonFactory {
29
30 private static final String MAC = "mac";
31 private static final String PROFILE = "profile";
32
Simon Hunt0d94f062015-06-04 10:56:03 -070033
34 // hard-coded icons for the demo
35 private static final Map<String, String> ICON_LOOKUP =
36 new HashMap<String, String>();
37 static {
38 ICON_LOOKUP.put("Mom's PC", "mom");
39 ICON_LOOKUP.put("Dad's PC", "dad");
Bri Prebilic Cole7d4d11b2015-06-12 15:41:42 -070040 ICON_LOOKUP.put("Jack's Laptop", "boy2");
41 ICON_LOOKUP.put("Jill's Laptop", "girl1");
Simon Hunt0d94f062015-06-04 10:56:03 -070042 }
43
44 private static final String DEFAULT_ICON_ID = "boy1";
45
Simon Hunt41b943e2015-05-21 13:52:01 -070046 // no instantiation
47 private UserFactory() {}
48
49 /**
50 * Returns an object node representation of the given user.
51 *
52 * @param user the user
53 * @return object node
54 */
55 public static ObjectNode toObjectNode(SubscriberUser user) {
Simon Hunt0d94f062015-06-04 10:56:03 -070056 String icon = ICON_LOOKUP.get(user.name());
57 icon = icon == null ? DEFAULT_ICON_ID : icon;
58
Simon Hunt41b943e2015-05-21 13:52:01 -070059 ObjectNode root = objectNode()
60 .put(ID, user.id())
Simon Hunt0d94f062015-06-04 10:56:03 -070061 .put(ICON_ID, icon)
Simon Hunt41b943e2015-05-21 13:52:01 -070062 .put(NAME, user.name())
63 .put(MAC, user.mac());
Simon Hunt6c2555b2015-05-21 18:17:56 -070064 root.set(PROFILE, XosFunctionFactory.profileForUser(user));
Simon Hunt41b943e2015-05-21 13:52:01 -070065 return root;
66 }
67
68}