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 | |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | |
Simon Hunt | 0d94f06 | 2015-06-04 10:56:03 -0700 | [diff] [blame] | 22 | import java.util.HashMap; |
| 23 | import java.util.Map; |
| 24 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Utility functions on users. |
| 27 | */ |
| 28 | public class UserFactory extends JsonFactory { |
| 29 | |
| 30 | private static final String MAC = "mac"; |
| 31 | private static final String PROFILE = "profile"; |
| 32 | |
Simon Hunt | 0d94f06 | 2015-06-04 10:56:03 -0700 | [diff] [blame] | 33 | |
| 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 Cole | 7d4d11b | 2015-06-12 15:41:42 -0700 | [diff] [blame] | 40 | ICON_LOOKUP.put("Jack's Laptop", "boy2"); |
| 41 | ICON_LOOKUP.put("Jill's Laptop", "girl1"); |
Simon Hunt | 0d94f06 | 2015-06-04 10:56:03 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | private static final String DEFAULT_ICON_ID = "boy1"; |
| 45 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 46 | // 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 Hunt | 0d94f06 | 2015-06-04 10:56:03 -0700 | [diff] [blame] | 56 | String icon = ICON_LOOKUP.get(user.name()); |
| 57 | icon = icon == null ? DEFAULT_ICON_ID : icon; |
| 58 | |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 59 | ObjectNode root = objectNode() |
| 60 | .put(ID, user.id()) |
Simon Hunt | 0d94f06 | 2015-06-04 10:56:03 -0700 | [diff] [blame] | 61 | .put(ICON_ID, icon) |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 62 | .put(NAME, user.name()) |
| 63 | .put(MAC, user.mac()); |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 64 | root.set(PROFILE, XosFunctionFactory.profileForUser(user)); |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 65 | return root; |
| 66 | } |
| 67 | |
| 68 | } |