blob: e1dcb64d07492e405ae02baa168a154ce849bc6c [file] [log] [blame]
Sean Condon87b78502018-09-17 20:53:24 +01001/*
2 * Copyright 2018-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 */
16
17package org.onosproject.faultmanagement.alarms.cli.completer;
18
19import org.apache.felix.service.command.CommandSession;
20import org.apache.karaf.shell.console.CommandSessionHolder;
21import org.apache.karaf.shell.console.completer.ArgumentCompleter;
22import org.onosproject.cli.AbstractChoicesCompleter;
23import org.onosproject.faultmanagement.alarms.cli.UpdateAlarm;
24
25import java.time.Instant;
26import java.util.ArrayList;
27import java.util.List;
28
29/**
30 * CLI completer for Alarm Field values.
31 */
32public class AlarmFieldValueCompleter extends AbstractChoicesCompleter {
33 @Override
34 protected List<String> choices() {
35
36 List<String> choices = new ArrayList<>();
37 CommandSession session = CommandSessionHolder.getSession();
38
39 ArgumentCompleter.ArgumentList list =
40 (ArgumentCompleter.ArgumentList) session.get(ArgumentCompleter.ARGUMENTS_LIST);
41 UpdateAlarm.AlarmField field = UpdateAlarm.AlarmField.valueOf(list.getArguments()[2]);
42
43 switch (field) {
44 case ACKNOWLEDGED:
45 case MANUALLY_CLEARABLE:
46 case SERVICE_AFFECTING:
47 choices.add("TRUE");
48 choices.add("FALSE");
49 return choices;
50 case TIME_CLEARED:
51 case TIME_UPDATED:
52 choices.add(Instant.now().toString());
53 default:
54 return choices;
55 }
56 }
57}