Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [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 | |
| 17 | package org.onosproject.cli.security; |
| 18 | |
| 19 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 20 | import org.onosproject.app.ApplicationService; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 21 | import org.onosproject.app.ApplicationState; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractCompleter; |
| 23 | import org.onosproject.core.Application; |
| 24 | |
| 25 | import java.util.Iterator; |
| 26 | import java.util.List; |
| 27 | import java.util.SortedSet; |
| 28 | |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 29 | import static org.onosproject.app.ApplicationState.INSTALLED; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 30 | import static org.onosproject.cli.AbstractShellCommand.get; |
| 31 | |
| 32 | /** |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 33 | * Application name completer for security review command. |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 34 | */ |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 35 | public class ReviewApplicationNameCompleter extends AbstractCompleter { |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 36 | @Override |
| 37 | public int complete(String buffer, int cursor, List<String> candidates) { |
| 38 | // Delegate string completer |
| 39 | StringsCompleter delegate = new StringsCompleter(); |
| 40 | |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 41 | ApplicationService service = get(ApplicationService.class); |
| 42 | Iterator<Application> it = service.getApplications().iterator(); |
| 43 | SortedSet<String> strings = delegate.getStrings(); |
| 44 | while (it.hasNext()) { |
| 45 | Application app = it.next(); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 46 | ApplicationState state = service.getState(app.id()); |
| 47 | // if (previousApps.contains(app.id().name())) { |
| 48 | // continue; |
| 49 | // } |
| 50 | if (state == INSTALLED) { |
| 51 | strings.add(app.id().name()); |
| 52 | } |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // Now let the completer do the work for figuring out what to offer. |
| 56 | return delegate.complete(buffer, cursor, candidates); |
| 57 | } |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 58 | } |