blob: 83f06e48285b26362e068443a8301d4b6b490d5f [file] [log] [blame]
breezestarsdf95f9f2016-09-16 15:35:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
breezestarsdf95f9f2016-09-16 15:35:25 -07003 *
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 */
breezestarsdf95f9f2016-09-16 15:35:25 -070016package org.onosproject.vpls.cli.completer;
17
Ray Milkey32ce0ed2018-10-10 15:39:24 -070018import org.apache.karaf.shell.api.action.lifecycle.Service;
breezestarsdf95f9f2016-09-16 15:35:25 -070019import org.onosproject.cli.AbstractChoicesCompleter;
Yi Tsengf4e13e32017-03-30 15:38:39 -070020import org.onosproject.vpls.api.Vpls;
21import org.onosproject.vpls.api.VplsData;
breezestarsdf95f9f2016-09-16 15:35:25 -070022
Yi Tsengf4e13e32017-03-30 15:38:39 -070023import java.util.Collection;
breezestarsdf95f9f2016-09-16 15:35:25 -070024import java.util.List;
Yi Tsengf4e13e32017-03-30 15:38:39 -070025import java.util.stream.Collectors;
breezestarsdf95f9f2016-09-16 15:35:25 -070026
27import static org.onosproject.cli.AbstractShellCommand.get;
28
29/**
Luca Pretedce16f82016-11-22 13:11:56 -080030 * VPLS name completer.
breezestarsdf95f9f2016-09-16 15:35:25 -070031 */
Ray Milkey32ce0ed2018-10-10 15:39:24 -070032@Service
Luca Pretedce16f82016-11-22 13:11:56 -080033public class VplsNameCompleter extends AbstractChoicesCompleter {
breezestarsdf95f9f2016-09-16 15:35:25 -070034
Ray Milkey074ba9b2018-02-06 10:23:41 -080035 protected Vpls vpls;
Yi Tsengf4e13e32017-03-30 15:38:39 -070036
breezestarsdf95f9f2016-09-16 15:35:25 -070037 @Override
Luca Pretedce16f82016-11-22 13:11:56 -080038 public List<String> choices() {
Yi Tsengf4e13e32017-03-30 15:38:39 -070039 if (vpls == null) {
40 vpls = get(Vpls.class);
41 }
42 Collection<VplsData> vplses = vpls.getAllVpls();
43 return vplses.stream().map(VplsData::name).collect(Collectors.toList());
breezestarsdf95f9f2016-09-16 15:35:25 -070044 }
45}