[ONOS-7732] Automating switch workflow: workflow store cli command completeter

Change-Id: Ieb2a4d60f4d567f4a7117b734691178c79ef1d26
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowIdCompleter.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowIdCompleter.java
new file mode 100644
index 0000000..f8b1683
--- /dev/null
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowIdCompleter.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.cli;
+
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractChoicesCompleter;
+import org.onosproject.workflow.api.WorkflowStore;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+/**
+ * Workflow ID completer.
+ */
+@Service
+public class WorkFlowIdCompleter extends AbstractChoicesCompleter {
+    @Override
+    protected List<String> choices() {
+        WorkflowStore workflowStore = getService(WorkflowStore.class);
+        return workflowStore.getAll().stream()
+                .map(workflow -> workflow.id().toString())
+                .collect(Collectors.toList());
+    }
+}
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCommand.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCommand.java
index d1e37c8..25312c8 100644
--- a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCommand.java
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCommand.java
@@ -17,6 +17,7 @@
 
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.workflow.api.Workflow;
@@ -29,10 +30,16 @@
 @Command(scope = "onos", name = "workflowstore", description = "workflow store cli")
 public class WorkFlowStoreCommand extends AbstractShellCommand {
 
-    @Argument(index = 0, name = "cmd", description = "command(rm)", required = false)
+    static final String RM = "rm";
+
+    @Argument(index = 0, name = "cmd",
+            description = "command(" + RM + ")", required = false)
+    @Completion(WorkFlowStoreCompleter.class)
     private String cmd = null;
 
-    @Argument(index = 1, name = "id", description = "workflow id(URI)", required = false)
+    @Argument(index = 1, name = "id",
+            description = "workflow id(URI)", required = false)
+    @Completion(WorkFlowIdCompleter.class)
     private String id = null;
 
     @Override
@@ -49,7 +56,7 @@
         }
 
         switch (cmd) {
-            case "rm":
+            case RM:
                 rmWorkflow(id);
                 break;
             default:
diff --git a/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCompleter.java b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCompleter.java
new file mode 100644
index 0000000..66d623c
--- /dev/null
+++ b/apps/workflow/app/src/main/java/org/onosproject/workflow/cli/WorkFlowStoreCompleter.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.workflow.cli;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractChoicesCompleter;
+
+import java.util.List;
+
+import static org.onosproject.workflow.cli.WorkFlowStoreCommand.RM;
+
+/**
+ * Workflow Store command completer.
+ */
+@Service
+public class WorkFlowStoreCompleter extends AbstractChoicesCompleter {
+    @Override
+    protected List<String> choices() {
+        return ImmutableList.of(RM);
+    }
+}