From c3391bef9e04c2ad38ed96bd28a5c43ab6d961de Mon Sep 17 00:00:00 2001
From: SravanKumarGunda <sravan.kumar1@huawei.com>
Date: Thu, 18 Jun 2020 19:05:44 +0530
Subject: Code Improvements-Sonar Issue Fixes

Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com>
Issue-ID: CLI-270
Change-Id: Iba00ddc8c471bc5990d87ba3729af373e2bd6711
---
 .../org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java    | 17 +++++------------
 .../cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java   |  6 ++++--
 2 files changed, 9 insertions(+), 14 deletions(-)

(limited to 'profiles/command/src/main/java/org')

diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
index eb7b808b..dd2c26cd 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
@@ -22,7 +22,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -46,12 +45,10 @@ import org.onap.cli.fw.store.OnapCommandExecutionStore;
 import org.onap.cli.fw.utils.OnapCommandUtils;
 import org.onap.cli.fw.utils.ProcessRunner;
 
-import com.google.gson.Gson;
 import com.jayway.jsonpath.JsonPath;
 import com.jayway.jsonpath.PathNotFoundException;
 
 import net.minidev.json.JSONArray;
-import net.minidev.json.JSONObject;
 
 /**
  * Hello world.
@@ -191,7 +188,7 @@ public class OpenCommandShellCmd extends OnapCommand {
 
         ProcessRunner pr = new ProcessRunner(
                 cmd,
-                (envs.size() > 0) ? envs.toArray(new String []{}) : null,
+                (!envs.isEmpty()) ? envs.toArray(new String []{}) : null,
                 cwd);
         FileOutputStream stdoutStream = null;
         FileOutputStream stderrStream = null;
@@ -285,11 +282,7 @@ public class OpenCommandShellCmd extends OnapCommand {
             }
 
         //check for pass/failure
-        if (!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())) {
-            this.getResult().setPassed(false);
-        } else {
-            this.getResult().setPassed(true);
-        }
+        this.getResult().setPassed(!(!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())));
    }
 
     public String getOutput() {
@@ -315,10 +308,10 @@ public class OpenCommandShellCmd extends OnapCommand {
                 break;
             }
 
-            int idxE = line.indexOf("}", idxS);
+            int idxE = line.indexOf('}', idxS);
             String tmpName = line.substring(idxS + 7, idxE);
             tmpName = tmpName.trim();
-            String tmpTkns[] = tmpName.split(":");
+            String[] tmpTkns = tmpName.split(":");
             String tmpFileName;
             String paramName;
             if (tmpTkns.length == 2) {
@@ -382,7 +375,7 @@ public class OpenCommandShellCmd extends OnapCommand {
                     break;
                 }
             }
-            int idxE = line.indexOf("}", idxS);
+            int idxE = line.indexOf('}', idxS);
             String jsonPath = line.substring(idxS + 3, idxE);
             jsonPath = jsonPath.trim();
             Object value = new Object();
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
index 676aeb30..1eeadecc 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
@@ -26,6 +26,7 @@ import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants;
 import org.onap.cli.fw.conf.OnapCommandConfig;
 import org.onap.cli.fw.error.OnapCommandException;
 import org.onap.cli.fw.utils.OnapCommandUtils;
+import java.util.stream.Collectors;
 
 public class OnapCommandSchemaCmdLoader {
 
@@ -64,7 +65,7 @@ public class OnapCommandSchemaCmdLoader {
                         if (o instanceof List) {
                             cmd.setCommand((List<String>) o);
                         } else {
-                            cmd.setCommand(Arrays.asList(new String [] {(String) o}));
+                            cmd.setCommand(Arrays.asList((String) o));
                         }
                         break;
 
@@ -90,7 +91,8 @@ public class OnapCommandSchemaCmdLoader {
                         break;
 
                     case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
-                        cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
+                        List<String> list = (ArrayList) valMap.get(key1);
+                        cmd.setSuccessStatusCodes(list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()));
                         break;
 
                     case OnapCommandCmdConstants.PASS_CODE:
-- 
cgit 1.2.3-korg