blob: 656af195b61cefc9e9a5f2bf07d996c162914c74 [file] [log] [blame]
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09003 *
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
17package org.onosproject.cli.security;
18
19import org.apache.karaf.shell.console.completer.StringsCompleter;
20import org.onosproject.app.ApplicationService;
Changhoon Yoonb856b812015-08-10 03:47:19 +090021import org.onosproject.app.ApplicationState;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090022import org.onosproject.cli.AbstractCompleter;
23import org.onosproject.core.Application;
24
25import java.util.Iterator;
26import java.util.List;
27import java.util.SortedSet;
28
Changhoon Yoonb856b812015-08-10 03:47:19 +090029import static org.onosproject.app.ApplicationState.INSTALLED;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090030import static org.onosproject.cli.AbstractShellCommand.get;
31
32/**
Changhoon Yoonb856b812015-08-10 03:47:19 +090033 * Application name completer for security review command.
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090034 */
Changhoon Yoonb856b812015-08-10 03:47:19 +090035public class ReviewApplicationNameCompleter extends AbstractCompleter {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090036 @Override
37 public int complete(String buffer, int cursor, List<String> candidates) {
38 // Delegate string completer
39 StringsCompleter delegate = new StringsCompleter();
40
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090041 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 Yoonb856b812015-08-10 03:47:19 +090046 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 Yoon23dee8f2015-05-18 22:19:49 +090053 }
54
55 // Now let the completer do the work for figuring out what to offer.
56 return delegate.complete(buffer, cursor, candidates);
57 }
Changhoon Yoonb856b812015-08-10 03:47:19 +090058}