Thomas Vachuska | 99b7bbe | 2018-02-01 15:29:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 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 | package org.onosproject.ui.impl.cli; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.ui.UiPreferencesService; |
| 23 | |
| 24 | /** |
| 25 | * Lists all UI user preferences. |
| 26 | */ |
| 27 | @Command(scope = "onos", name = "ui-prefs", |
| 28 | description = "Lists all UI user preferences") |
| 29 | public class UiPreferencesListCommand extends AbstractShellCommand { |
| 30 | |
| 31 | @Override |
| 32 | protected void execute() { |
| 33 | UiPreferencesService service = get(UiPreferencesService.class); |
| 34 | ObjectMapper mapper = new ObjectMapper(); |
| 35 | ObjectNode root = mapper.createObjectNode(); |
| 36 | |
| 37 | service.getUserNames().forEach(user -> { |
| 38 | ObjectNode prefs = mapper.createObjectNode(); |
| 39 | root.set(user, prefs); |
| 40 | service.getPreferences(user).forEach(prefs::set); |
| 41 | }); |
| 42 | |
| 43 | print("%s", root); |
| 44 | } |
| 45 | } |