blob: bd26ea78579b07fc0f14dc4bf4982a1719a8c288 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.ui.UiPreferencesService;
24
25/**
26 * Lists all UI user preferences.
27 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070028@Service
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080029@Command(scope = "onos", name = "ui-prefs",
30 description = "Lists all UI user preferences")
31public class UiPreferencesListCommand extends AbstractShellCommand {
32
33 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034 protected void doExecute() {
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080035 UiPreferencesService service = get(UiPreferencesService.class);
36 ObjectMapper mapper = new ObjectMapper();
37 ObjectNode root = mapper.createObjectNode();
38
39 service.getUserNames().forEach(user -> {
40 ObjectNode prefs = mapper.createObjectNode();
41 root.set(user, prefs);
42 service.getPreferences(user).forEach(prefs::set);
43 });
44
45 print("%s", root);
46 }
47}