Thomas Vachuska | 4cfcc56 | 2015-06-03 09:51:02 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 4cfcc56 | 2015-06-03 09:51:02 -0700 | [diff] [blame] | 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.cli; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | import org.onosproject.ui.UiExtension; |
| 23 | import org.onosproject.ui.UiExtensionService; |
| 24 | |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * Lists all UI views. |
| 29 | */ |
| 30 | @Command(scope = "onos", name = "ui-views", |
| 31 | description = "Lists all UI views") |
| 32 | public class UiViewListCommand extends AbstractShellCommand { |
| 33 | |
| 34 | private static final String FMT = "id=%s, category=%s, label=%s, icon=%s"; |
| 35 | |
| 36 | @Override |
| 37 | protected void execute() { |
| 38 | UiExtensionService service = get(UiExtensionService.class); |
| 39 | if (outputJson()) { |
| 40 | print("%s", json(service.getExtensions())); |
| 41 | } else { |
| 42 | service.getExtensions().forEach(ext -> ext.views() |
| 43 | .forEach(v -> print(FMT, v.id(), v.category().label(), |
| 44 | v.label(), v.iconId()))); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | private JsonNode json(List<UiExtension> extensions) { |
| 49 | ObjectMapper mapper = new ObjectMapper(); |
| 50 | ArrayNode node = mapper.createArrayNode(); |
| 51 | extensions.forEach(ext -> ext.views() |
| 52 | .forEach(v -> node.add(mapper.createObjectNode() |
| 53 | .put("id", v.id()) |
| 54 | .put("category", v.category().label()) |
| 55 | .put("label", v.label()) |
| 56 | .put("icon", v.iconId())))); |
| 57 | return node; |
| 58 | } |
| 59 | |
| 60 | } |