blob: eea1348d215f228c9ead10d4e05f95be87c41084 [file] [log] [blame]
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -08001/*
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 */
16package org.onosproject.ui.impl.cli;
17
18import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.apache.karaf.shell.api.action.Command;
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080021import org.onosproject.cli.AbstractShellCommand;
22import 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")
29public class UiPreferencesListCommand extends AbstractShellCommand {
30
31 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032 protected void doExecute() {
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080033 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}