diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2017-09-08 04:14:43 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-08 04:14:43 +0000 |
commit | bf3937c6eaa4b479b5f54879e5a56b8e86ad3af4 (patch) | |
tree | c50cb9d8dcf83375daac89a2450d6d7937615e77 | |
parent | 03d634fc99b01894ec1481113e1fe0f44161f9fd (diff) | |
parent | f24521907506d3c7b77375d76661458bc3ad9f33 (diff) |
Merge "Make set specific to product version"
6 files changed, 84 insertions, 10 deletions
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<String, String> 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<String, Map<String, String>> paramCache = new HashMap<>(); + + public void add(String productVersion, String paramName, String paramValue) { + + if (!paramCache.containsKey(productVersion)) { + paramCache.put(productVersion, new HashMap<String, String>()); + } + + 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<String, String> getParams(String productVersion) { + if (paramCache.containsKey(productVersion)) { + return this.paramCache.get(productVersion); + } else { + return new HashMap<String, String>(); + } + } + + 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<String> args = new ArrayList<>(); - Map<String, String> 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 <args.size(); i++) { - if (this.paramCache.containsKey(args.get(i))) { - this.paramCache.remove(args.get(i)); - } + OnapCommandRegistrar.getRegistrar().removeParamCache(args.get(i)); } } } else { @@ -313,8 +310,8 @@ public class OnapCli { } for (OnapCommandParameter param: cmd.getParameters()) { - if (this.paramCache.containsKey(param.getLongOption())) { - param.setValue(this.paramCache.get(param.getLongOption())); + if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(param.getLongOption())) { + param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(param.getLongOption())); } } |