summaryrefslogtreecommitdiffstats
path: root/framework/src/main/java
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-10-01 00:12:20 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-11-14 14:39:44 +0530
commitde0dcbad873481bee88eb68e2c03a82bdad85781 (patch)
treeacf3ad45c3177fc1ca2b466453cf158bb1b644a3 /framework/src/main/java
parent74f654c7cc41908d0109f60c7554f329f0b29daf (diff)
Add Info section
Issue-Id: CLI-66 Change-Id: I864c4af234e7f27d75eaad7318e0d919c1d82305 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java11
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java11
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java65
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java102
5 files changed, 172 insertions, 18 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
index 9be9b88e..8ef8a3c5 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -38,6 +38,7 @@ import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
+import org.onap.cli.fw.info.OnapCommandInfo;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
@@ -57,6 +58,8 @@ public abstract class OnapCommand {
private String cmdSchemaName;
+ private OnapCommandInfo info;
+
private String productVersion;
private OnapService onapService = new OnapService();
@@ -95,6 +98,14 @@ public abstract class OnapCommand {
this.cmdName = name;
}
+ public OnapCommandInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(OnapCommandInfo info) {
+ this.info = info;
+ }
+
public boolean isCommandInternal() {
return onapService.getName() != null
&& onapService.getName().equalsIgnoreCase(OnapCommandConfg.getInternalCmd())
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 a1ade420..64747bf9 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
@@ -27,6 +27,8 @@ public class Constants {
public static final String TOP_LEVEL_MANDATORY_LIST ="cli.schema.top_level_mandatory_list";
public static final String SERVICE_PARAMS_LIST ="cli.schema.service_params_list";
public static final String SERVICE_PARAMS_MANDATORY_LIST ="cli.schema.service_params_mandatory_list";
+ public static final String INFO_PARAMS_LIST ="cli.schema.info_params_list";
+ public static final String INFO_PARAMS_MANDATORY_LIST ="cli.schema.info_params_mandatory_list";
public static final String INPUT_PARAMS_LIST ="cli.schema.input_params_list";
public static final String INPUT_PARAMS_MANDATORY_LIST ="cli.schema.input_params_mandatory_list";
public static final String RESULT_PARAMS_LIST ="cli.schema.result_params_list";
@@ -39,7 +41,7 @@ public class Constants {
public static final String BOOLEAN_VALUE ="cli.schema.boolean_values";
public static final String AUTH_VALUES="cli.schema.auth_values";
public static final String MODE_VALUES="cli.schema.mode_values";
-
+ public static final String COMMAND_TYPE_VALUES="cli.command.type";
public static final String SSLCONTEST_TLS = "TLSV1.2";
public static final String APPLICATION_JSON = "application/json";
@@ -60,6 +62,13 @@ public class Constants {
public static final String SUCCESS_CODES = "success_codes";
public static final String RESULT_MAP = "result_map";
+ //Info
+ public static final String INFO = "info";
+ public static final String INFO_PRODUCT = "product";
+ public static final String INFO_SERVICE = "service";
+ public static final String INFO_TYPE = "type";
+ public static final String INFO_AUTHOR = "author";
+
//swagger
public static final String EXECUTOR = "exec";
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 447a7f4c..64e54335 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
@@ -158,6 +158,7 @@ public final class OnapCommandConfg {
.split(",")).map(String::trim).collect(Collectors.toSet());
}
+ //mrkanag move this utils class
public static List<String> getSchemaAttrInfo(String key) {
return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR
}
diff --git a/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java b/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java
new file mode 100644
index 00000000..a747f681
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/info/OnapCommandInfo.java
@@ -0,0 +1,65 @@
+/*
+ * 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.info;
+
+import org.onap.cli.fw.cmd.CommandType;
+
+/**
+ * Onap Command info like product version, service, contact, etc.
+ */
+public class OnapCommandInfo {
+
+ private String product;
+
+ private String service;
+
+ private String author;
+
+ private CommandType type;
+
+ public String getProduct() {
+ return product;
+ }
+
+ public void setProduct(String product) {
+ this.product = product;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String email) {
+ this.author = email;
+ }
+
+ public CommandType getCommandType() {
+ return type;
+ }
+
+ public void setCommandType(CommandType type) {
+ this.type = type;
+ }
+} \ No newline at end of file
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 5a074ef2..2261766d 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
@@ -24,6 +24,7 @@ import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
import static org.onap.cli.fw.conf.Constants.CLIENT;
import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE;
+import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE_VALUES;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_HOST_URL;
@@ -52,6 +53,13 @@ import static org.onap.cli.fw.conf.Constants.HTTP_REQUEST_MANDATORY_PARAMS;
import static org.onap.cli.fw.conf.Constants.HTTP_REQUEST_PARAMS;
import static org.onap.cli.fw.conf.Constants.HTTP_SECTIONS;
import static org.onap.cli.fw.conf.Constants.HTTP_SUCCESS_CODE_INVALID;
+import static org.onap.cli.fw.conf.Constants.INFO;
+import static org.onap.cli.fw.conf.Constants.INFO_AUTHOR;
+import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.INFO_PRODUCT;
+import static org.onap.cli.fw.conf.Constants.INFO_SERVICE;
+import static org.onap.cli.fw.conf.Constants.INFO_TYPE;
import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_LIST;
import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_MANDATORY_LIST;
import static org.onap.cli.fw.conf.Constants.IS_OPTIONAL;
@@ -138,6 +146,7 @@ import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
import org.onap.cli.fw.http.HttpInput;
import org.onap.cli.fw.http.HttpResult;
+import org.onap.cli.fw.info.OnapCommandInfo;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
@@ -369,7 +378,7 @@ public class OnapCommandUtils {
}
- List<String> sections = Arrays.asList(NAME, DESCRIPTION, VERSION, COMMAND_TYPE, SERVICE,
+ List<String> sections = Arrays.asList(NAME, DESCRIPTION, INFO, VERSION, COMMAND_TYPE, SERVICE,
DEFAULT_PARAMETERS, PARAMETERS, RESULTS);
for (String key : sections) {
@@ -404,6 +413,64 @@ public class OnapCommandUtils {
}
break;
+ case INFO:
+ Map<String, String> infoMap = (Map<String, String>) values.get(key);
+
+ if (infoMap != null) {
+ if (validate) {
+ validateTags(exceptionList, (Map<String, Object>) values.get(key),
+ OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_MANDATORY_LIST), INFO);
+
+ HashMap<String, String> validationMap = new HashMap<>();
+ validationMap.put(INFO_TYPE, COMMAND_TYPE_VALUES);
+
+ for (String secKey : validationMap.keySet()) {
+ if (infoMap.containsKey(secKey)) {
+ Object obj = infoMap.get(secKey);
+ if (obj == null) {
+ exceptionList.add("Attribute '" + secKey + "' under '" + INFO + "' is empty");
+ } else {
+ String value = String.valueOf(obj);
+ if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
+ exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
+ + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
+ }
+ }
+ }
+ }
+ }
+
+ OnapCommandInfo info = new OnapCommandInfo();
+
+ for (Map.Entry<String, String> entry1 : infoMap.entrySet()) {
+ String key1 = entry1.getKey();
+
+ switch (key1) {
+ case INFO_PRODUCT:
+ info.setProduct(infoMap.get(key1));
+ break;
+
+ case INFO_SERVICE:
+ info.setService(infoMap.get(key1).toString());
+ break;
+
+ case INFO_TYPE:
+ Object obj = infoMap.get(key1);
+ info.setCommandType(CommandType.get(obj.toString()));
+ break;
+
+ case INFO_AUTHOR:
+ Object mode = infoMap.get(key1);
+ info.setAuthor(mode.toString());
+ break;
+ }
+ }
+
+ cmd.setInfo(info);
+ }
+ break;
+
case SERVICE:
Map<String, String> serviceMap = (Map<String, String>) values.get(key);
@@ -1863,25 +1930,26 @@ public class OnapCommandUtils {
}
return schemaStr;
}
-
+
/**
* Copy the parameters across the commands, mainly used for catalog, login and logout commands
- *
- * @throws OnapCommandInvalidParameterValue
+ *
+ * @throws OnapCommandInvalidParameterValue
*/
public static void copyParamsFrom(OnapCommand from, OnapCommand to) throws OnapCommandInvalidParameterValue {
- for (OnapCommandParameter param: to.getParameters()) {
-
- OnapCommandParameter fromParam = from.getParametersMap().get(param.getName());
-
- if (fromParam != null) {
- param.setValue(fromParam.getValue());
- param.setDefaultValue(fromParam.getDefaultValue());
- } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_NAME)) { // for catalog cmd
- param.setValue(from.getService().getName());
- } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_VERSION)) { // for catalog cmd
- param.setValue(from.getService().getVersion());
- }
- }
+ for (OnapCommandParameter param: to.getParameters()) {
+
+ OnapCommandParameter fromParam = from.getParametersMap().get(param.getName());
+
+ if (fromParam != null) {
+ param.setValue(fromParam.getValue());
+ param.setDefaultValue(fromParam.getDefaultValue());
+ } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_NAME)) { // for catalog cmd
+ param.setValue(from.getService().getName());
+ } else if (param.getName().equalsIgnoreCase(Constants.CATALOG_SERVICE_VERSION)) { // for catalog cmd
+ param.setValue(from.getService().getVersion());
+ }
+ }
}
}
+