From f24521907506d3c7b77375d76661458bc3ad9f33 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 7 Sep 2017 14:23:14 +0530 Subject: Make set specific to product version CLI-2 Change-Id: If6c72255c4c84615dafe5f0074eb5532bc90bf5e Signed-off-by: Kanagaraj Manickam k00365106 --- .../java/org/onap/cli/fw/OnapCommandRegistrar.java | 15 ++++++ .../main/java/org/onap/cli/fw/conf/Constants.java | 1 + .../org/onap/cli/fw/conf/OnapCommandConfg.java | 5 +- .../fw/input/cache/OnapCommandParameterCache.java | 58 ++++++++++++++++++++++ framework/src/main/resources/onap.properties | 2 + main/src/main/java/org/onap/cli/main/OnapCli.java | 13 ++--- 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java index 424d26ca..019eb824 100644 --- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java +++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java @@ -34,6 +34,7 @@ import org.onap.cli.fw.error.OnapCommandNotFound; import org.onap.cli.fw.error.OnapCommandProductVersionInvalid; import org.onap.cli.fw.error.OnapCommandRegistrationFailed; import org.onap.cli.fw.error.OnapCommandRegistrationVersionMissing; +import org.onap.cli.fw.input.cache.OnapCommandParameterCache; import org.onap.cli.fw.output.OnapCommandResult; import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cli.fw.output.OnapCommandResultAttributeScope; @@ -57,6 +58,8 @@ public class OnapCommandRegistrar { private boolean isInteractiveMode = false; + private OnapCommandParameterCache paramCache = new OnapCommandParameterCache(); + public boolean isInteractiveMode() { return isInteractiveMode; } @@ -65,6 +68,18 @@ public class OnapCommandRegistrar { this.isInteractiveMode = isInteractiveMode; } + public Map getParamCache() { + return paramCache.getParams(this.getEnabledProductVersion()); + } + + public void addParamCache(String paramName, String paramValue) { + paramCache.add(this.getEnabledProductVersion(), paramName, paramValue); + } + + public void removeParamCache(String paramName) { + paramCache.remove(this.getEnabledProductVersion(), paramName); + } + private static OnapCommandRegistrar registrar = null; /** diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java index d27649b0..23dfbbbe 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java @@ -194,6 +194,7 @@ public class Constants { public static final String HTTP_SAMPLE_RESPONSE_FAILED_PARSING = "The http Sample response json is failed to parse."; public static final String USE_DIRECTIVE = "use"; + public static final String PARAM_CACHE_FILE_NAME = "cli.parameter.cache.file"; private Constants() { } diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java index 5ca0589f..35461a05 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java @@ -16,8 +16,6 @@ package org.onap.cli.fw.conf; -import org.onap.cli.fw.input.OnapCommandParameter; - import java.io.IOException; import java.util.Arrays; import java.util.HashMap; @@ -163,4 +161,7 @@ public final class OnapCommandConfg { return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR } + public static String getParamCacheFileName() { + return prps.getProperty(Constants.PARAM_CACHE_FILE_NAME); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java new file mode 100644 index 00000000..5c8bdf6d --- /dev/null +++ b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * 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.onap.cli.fw.input.cache; + +import java.util.HashMap; +import java.util.Map; + +public class OnapCommandParameterCache { + + public Map> paramCache = new HashMap<>(); + + public void add(String productVersion, String paramName, String paramValue) { + + if (!paramCache.containsKey(productVersion)) { + paramCache.put(productVersion, new HashMap()); + } + + paramCache.get(productVersion).put(paramName, paramValue); + } + + public void remove(String productVersion, String paramName) { + if (paramCache.containsKey(productVersion)) { + if (paramCache.get(productVersion).containsKey(paramName)) { + paramCache.get(productVersion).remove(paramName); + } + } + } + + public Map getParams(String productVersion) { + if (paramCache.containsKey(productVersion)) { + return this.paramCache.get(productVersion); + } else { + return new HashMap(); + } + } + + public void persist() { + // mrkana add persistence logic + } + + public void load() { + // mrkanag add loading cache from persistence + } +} diff --git a/framework/src/main/resources/onap.properties b/framework/src/main/resources/onap.properties index 9e6b34bd..6df5682a 100644 --- a/framework/src/main/resources/onap.properties +++ b/framework/src/main/resources/onap.properties @@ -54,3 +54,5 @@ cli.schema.mode_values=direct,catalog #product version cli.product.version=cli-1.0 + +cli.parameter.cache.file=param-cache.json diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index 52922277..c175f67b 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -50,7 +50,6 @@ import jline.console.ConsoleReader; public class OnapCli { private List args = new ArrayList<>(); - Map paramCache = new HashMap<>(); private int exitCode = -1; @@ -212,19 +211,17 @@ public class OnapCli { if (args.size() > 1) { String [] paramEntry = args.get(1).trim().split("="); if (paramEntry.length >= 2) { - this.paramCache.put(paramEntry[0].trim(), paramEntry[1].trim()); + OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim()); } else { this.print("Please use it in the form of 'set param-name=param-value'"); } } else { - this.print(this.paramCache.toString()); + this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString()); } } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) { if (args.size() > 1) { for (int i = 1; i