From 268be523fb1142138a3f710642b5773453841eeb Mon Sep 17 00:00:00 2001 From: "priyanka.akhade" Date: Thu, 18 Jun 2020 15:11:08 +0530 Subject: code improvements Signed-off-by: priyanka.akhade Issue-ID: CLI-270 Change-Id: If9eab4bc8642c7c20a841d58c8a9e2bf5ae6c98b --- .../org/onap/cli/fw/http/cmd/OnapHttpCommand.java | 2 +- .../java/org/onap/cli/fw/http/mock/MocoServer.java | 2 +- .../http/schema/OnapCommandSchemaHttpLoader.java | 2 +- .../cli/fw/http/utils/OnapCommandHttpUtils.java | 30 +++++++++++----------- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'profiles/http/src/main') diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java index 53a2d042..387ec3be 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java @@ -253,7 +253,7 @@ public class OnapHttpCommand extends OnapCommand { this.resultMap.put(resultMapEntry.getKey(), value); } - Map> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output); + Map> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output); //results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap()); for (OnapCommandResultAttribute attr : this.getResult().getRecords()) { diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java index a2e025a8..9c4185b7 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java @@ -43,7 +43,7 @@ import java.io.InputStreamReader; public class MocoServer { private Runner runner; - private Map mocoServerConfigs = new HashMap(); + private Map mocoServerConfigs = new HashMap<>(); private static Gson gson = new GsonBuilder().serializeNulls().create(); public MocoServer(String mockFile) throws OnapCommandException { diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java index df9c84fc..33f58060 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java @@ -92,7 +92,7 @@ public class OnapCommandSchemaHttpLoader { * @throws OnapCommandException * on error */ - public static ArrayList parseHttpSchema(OnapHttpCommand cmd, + public static List parseHttpSchema(OnapHttpCommand cmd, final Map values, boolean validate) throws OnapCommandException { ArrayList errorList = new ArrayList<>(); diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java index a592ac79..fcd25c24 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java @@ -145,9 +145,9 @@ public class OnapCommandHttpUtils { * @throws OnapCommandResultMapProcessingFailed * map processing failed exception */ - public static Map> populateOutputs(Map resultMap, HttpResult resultHttp) + public static Map> populateOutputs(Map resultMap, HttpResult resultHttp) throws OnapCommandException { - Map> resultsProcessed = new HashMap<>(); + Map> resultsProcessed = new HashMap<>(); for (Entry entry : resultMap.entrySet()) { String key = entry.getKey(); @@ -161,10 +161,10 @@ public class OnapCommandHttpUtils { return resultsProcessed; } - public static ArrayList replaceLineFromOutputResults(String line, HttpResult resultHttp) + public static List replaceLineFromOutputResults(String line, HttpResult resultHttp) throws OnapCommandHttpHeaderNotFound, OnapCommandHttpInvalidResponseBody, OnapCommandResultMapProcessingFailed, OnapCommandResultEmpty { - String headerProcessedLine = ""; + StringBuilder headerProcessedLine = new StringBuilder(); ArrayList result = new ArrayList<>(); if (!line.contains("$b{") && !line.contains("$h{")) { @@ -187,7 +187,7 @@ public class OnapCommandHttpUtils { while (currentIdx < line.length()) { int idxS = line.indexOf("$h{", currentIdx); if (idxS == -1) { - headerProcessedLine += line.substring(currentIdx); + headerProcessedLine.append(line.substring(currentIdx)); break; } int idxE = line.indexOf("}", idxS); @@ -198,19 +198,19 @@ public class OnapCommandHttpUtils { } String value = resultHttp.getRespHeaders().get(headerName); - headerProcessedLine += line.substring(currentIdx, idxS) + value; + headerProcessedLine.append(line.substring(currentIdx, idxS) + value); currentIdx = idxE + 1; } // Process body jsonpath macros List values = new ArrayList<>(); - String bodyProcessedPattern = ""; + StringBuilder bodyProcessedPattern = new StringBuilder(); currentIdx = 0; int maxRows = 1; // in normal case, only one row will be there while (currentIdx < headerProcessedLine.length()) { int idxS = headerProcessedLine.indexOf("$b{", currentIdx); if (idxS == -1) { - bodyProcessedPattern += headerProcessedLine.substring(currentIdx); + bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx)); break; } int idxE = headerProcessedLine.indexOf("}", idxS); @@ -233,23 +233,23 @@ public class OnapCommandHttpUtils { maxRows = arr.size(); } } - bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s"; + bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx, idxS) + "%s"); values.add(value); currentIdx = idxE + 1; } - if (bodyProcessedPattern.isEmpty()) { - result.add(headerProcessedLine); + if (bodyProcessedPattern.toString().isEmpty()) { + result.add(headerProcessedLine.toString()); return result; } else { for (int i = 0; i < maxRows; i++) { currentIdx = 0; - String bodyProcessedLine = ""; + StringBuilder bodyProcessedLine = new StringBuilder(); int positionalIdx = 0; // %s positional idx while (currentIdx < bodyProcessedPattern.length()) { int idxS = bodyProcessedPattern.indexOf("%s", currentIdx); if (idxS == -1) { - bodyProcessedLine += bodyProcessedPattern.substring(currentIdx); + bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx)); break; } int idxE = idxS + 2; // %s @@ -265,7 +265,7 @@ public class OnapCommandHttpUtils { } } - bodyProcessedLine += bodyProcessedPattern.substring(currentIdx, idxS) + valueS; + bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx, idxS) + valueS); currentIdx = idxE; positionalIdx++; } catch (OnapCommandResultEmpty e) { @@ -274,7 +274,7 @@ public class OnapCommandHttpUtils { throw new OnapCommandResultMapProcessingFailed(line, e); } } - result.add(bodyProcessedLine); + result.add(bodyProcessedLine.toString()); } return result; -- cgit 1.2.3-korg