From 82b9e1fb1673b2ea2cf16c074ce0c76c200fff8a Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 21 Dec 2017 12:44:57 +0530 Subject: Add is_deafult_parm and is_default_attr Issue-ID: CLI-66 Change-Id: Id6789ffda5d8ae93f4927564844bde36ecd88678 Signed-off-by: Kanagaraj Manickam k00365106 --- .../fw/http/auth/OnapCommandHttpAuthClient.java | 2 +- .../org/onap/cli/fw/http/cmd/OnapHttpCommand.java | 4 ++-- .../cli/fw/http/connect/OnapHttpConnection.java | 8 ++++++- .../cli/fw/http/utils/OnapCommandHttpUtils.java | 26 +++++++++++++--------- .../http/default_input_parameters_http.yaml | 6 ++++- 5 files changed, 31 insertions(+), 15 deletions(-) (limited to 'profiles') diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java index 4b1752af..aa1368ec 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/auth/OnapCommandHttpAuthClient.java @@ -116,7 +116,7 @@ public class OnapCommandHttpAuthClient { if (cmd.getService().isModeDirect()){ return cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).getValue().toString(); } else { //Catalog mode - OnapCommand catalog = OnapCommandRegistrar.getRegistrar().get("catalog"); + OnapCommand catalog = OnapCommandRegistrar.getRegistrar().get("catalog", cmd.getInfo().getProduct()); Map paramsOverrides = new HashMap<>(); paramsOverrides.put(OnapCommandHttpConstants.CATALOG_SERVICE_NAME, cmd.getService().getName()); 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 7178be81..12309341 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 @@ -102,8 +102,8 @@ public class OnapHttpCommand extends OnapCommand { } @Override - protected List initializeProfileSchema() throws OnapCommandException { - return OnapCommandSchemaHttpLoader.loadHttpSchema(this, this.getSchemaName(), true, false); + protected List initializeProfileSchema(boolean validate) throws OnapCommandException { + return OnapCommandSchemaHttpLoader.loadHttpSchema(this, this.getSchemaName(), true, validate); } @Override diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java index 1ce0433c..5b6df29d 100644 --- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java +++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java @@ -65,12 +65,16 @@ import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; import org.onap.cli.fw.http.conf.OnapCommandHttpConstants; import org.onap.cli.fw.http.error.OnapCommandHttpFailure; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Helps to make http connection.
*/ public class OnapHttpConnection { + private static Logger LOG = LoggerFactory.getLogger(OnapHttpConnection.class); + private HttpClient httpClient = null; Map mapCommonHeaders = new HashMap (); @@ -331,8 +335,10 @@ public class OnapHttpConnection { } catch (ParseException | IOException e) { throw new OnapCommandHttpFailure(e); } finally { + String info = input + " " + result; + LOG.info(info); if (this.debug) { - this.debugDetails = input + " " + result; + this.debugDetails = info; } } 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 e4d2cf06..cd918783 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 @@ -38,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.PathNotFoundException; import net.minidev.json.JSONArray; @@ -169,21 +170,26 @@ public class OnapCommandHttpUtils { int idxE = headerProcessedLine.indexOf("}", idxS); String jsonPath = headerProcessedLine.substring(idxS + 3, idxE); jsonPath = jsonPath.trim(); + Object value = new Object(); try { // JSONArray or String - Object value = JsonPath.read(resultHttp.getBody(), jsonPath); - if (value instanceof JSONArray) { - JSONArray arr = (JSONArray) value; - if (arr.size() > maxRows) { - maxRows = arr.size(); - } - } - bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s"; - values.add(value); - currentIdx = idxE + 1; + value = JsonPath.read(resultHttp.getBody(), jsonPath); + } catch (PathNotFoundException e1) { + //set to blank for those entries which are missing from the output json + value = ""; } catch (Exception e) { throw new OnapCommandHttpInvalidResponseBody(jsonPath, e); } + + if (value instanceof JSONArray) { + JSONArray arr = (JSONArray) value; + if (arr.size() > maxRows) { + maxRows = arr.size(); + } + } + bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s"; + values.add(value); + currentIdx = idxE + 1; } if (bodyProcessedPattern.isEmpty()) { diff --git a/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml b/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml index d7fbe03c..9029e273 100644 --- a/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml +++ b/profiles/http/src/main/resources/open-cli-schema/http/default_input_parameters_http.yaml @@ -13,6 +13,7 @@ parameters: long_option: host-username default_value: $s{env:OPEN_CLI_HOST_USERNAME} is_optional: false + is_default_param: true - name: host-password type: string description: Host user password @@ -21,6 +22,7 @@ parameters: default_value: $s{env:OPEN_CLI_HOST_PASSWORD} is_secured: true is_optional: false + is_default_param: true - name: host-url type: url description: host url in http(s) @@ -28,9 +30,11 @@ parameters: long_option: host-url is_optional: false default_value: $s{env:OPEN_CLI_HOST_URL} + is_default_param: true - name: no-auth type: bool description: whether to authenticate user or not short_option: a long_option: no-auth - default_value: false \ No newline at end of file + default_value: false + is_default_param: true \ No newline at end of file -- cgit 1.2.3-korg