From 2f531e5eaaee5b762616f4e745c39edb74aad743 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Tue, 27 Mar 2018 15:34:06 +0530 Subject: Macro fails to subsitute map param Issue-ID: CLI-78 Change-Id: Ice150ba53f85b9bbed5264805b06f6c28e2d21e7 Signed-off-by: Kanagaraj Manickam k00365106 --- .../cli/fw/utils/OnapCommandDiscoveryUtils.java | 38 +++++++++++++++------- .../org/onap/cli/fw/utils/OnapCommandUtils.java | 20 ++++++++---- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index 9bdd8a51..b10629f4 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -16,27 +16,43 @@ package org.onap.cli.fw.utils; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_DIRECTORY; +import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_JSON_PATTERN; +import static org.onap.cli.fw.conf.OnapCommandConstants.DISCOVERY_FILE; +import static org.onap.cli.fw.conf.OnapCommandConstants.NAME; +import static org.onap.cli.fw.conf.OnapCommandConstants.OPEN_CLI_SAMPLE_VERSION; +import static org.onap.cli.fw.conf.OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION; +import static org.onap.cli.fw.conf.OnapCommandConstants.SCHEMA_DIRECTORY; +import static org.onap.cli.fw.conf.OnapCommandConstants.SCHEMA_PATH_PATERN; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.ServiceLoader; + import org.apache.commons.io.FileUtils; import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.conf.OnapCommandConfig; import org.onap.cli.fw.conf.OnapCommandConstants; -import org.onap.cli.fw.error.*; -import org.onap.cli.fw.registrar.OnapCommandRegistrar; +import org.onap.cli.fw.error.OnapCommandDiscoveryFailed; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandInstantiationFailed; +import org.onap.cli.fw.error.OnapCommandInvalidSample; +import org.onap.cli.fw.error.OnapCommandInvalidSchema; import org.onap.cli.fw.schema.OnapCommandSchemaInfo; -import org.onap.cli.fw.schema.OnapCommandSchemaLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.yaml.snakeyaml.Yaml; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import static org.onap.cli.fw.conf.OnapCommandConstants.*; +import com.fasterxml.jackson.databind.ObjectMapper; public class OnapCommandDiscoveryUtils { diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java index c5ebbc21..accea717 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java @@ -39,6 +39,8 @@ import org.onap.cli.fw.input.OnapCommandParameterType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; /** @@ -247,18 +249,24 @@ public class OnapCommandUtils { throw new OnapCommandParameterNotFound(paramName); } - String value = params.get(paramName).getValue().toString(); - OnapCommandParameter param = params.get(paramName); if (OnapCommandParameterType.ARRAY.equals(param.getParameterType()) - || OnapCommandParameterType.MAP.equals(param.getParameterType()) || OnapCommandParameterType.JSON.equals(param.getParameterType()) || OnapCommandParameterType.YAML.equals(param.getParameterType())) { // ignore the front and back double quotes in json body - result += line.substring(currentIdx, idxS - 1) + value; + result += line.substring(currentIdx, idxS - 1) + params.get(paramName).getValue().toString(); + currentIdx = idxE + 2; + } else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) { + try { + String value = new ObjectMapper().writeValueAsString(params.get(paramName).getValue()); + result += line.substring(currentIdx, idxS - 1) + value; + } catch (JsonProcessingException e) { // NOSONAR + //never occur as map is coverted to json string here + } + currentIdx = idxE + 2; - } else { - result += line.substring(currentIdx, idxS) + value; + }else { + result += line.substring(currentIdx, idxS) + params.get(paramName).getValue().toString(); currentIdx = idxE + 1; } } -- cgit 1.2.3-korg