aboutsummaryrefslogtreecommitdiffstats
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
parent74f654c7cc41908d0109f60c7554f329f0b29daf (diff)
Add Info section
Issue-Id: CLI-66 Change-Id: I864c4af234e7f27d75eaad7318e0d919c1d82305 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-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
-rw-r--r--framework/src/main/resources/open-cli.properties6
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java40
-rw-r--r--framework/src/test/resources/sample-test-info.yaml9
8 files changed, 214 insertions, 31 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());
+ }
+ }
}
}
+
diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties
index 2531ce22..6ee08900 100644
--- a/framework/src/main/resources/open-cli.properties
+++ b/framework/src/main/resources/open-cli.properties
@@ -13,7 +13,7 @@ cli.no_auth_enable_exclude_params_external_cmd=host-username,host-password,no-au
cli.no_auth_enable_include_params_external_cmd=host-url
#schema validation
-cli.schema.top_level_params_list=open_cli_schema_version,name,version,description,service,parameters,results,http,type
+cli.schema.top_level_params_list=open_cli_schema_version,name,version,description,service,parameters,results,http,type,info
cli.schema.top_level_mandatory_list=open_cli_schema_version
cli.schema.service_params_list=name,version,auth,mode
@@ -31,11 +31,15 @@ cli.schema.http_mandatory_sections=request, success_codes
cli.schema.http_request_params=uri,method,body,headers,queries,multipart_entity_name
cli.schema.http_request_mandatory_params=uri,method
+cli.schema.info_params_list=product,service,type,author
+cli.schema.info_params_mandatory_list=product,service
+
cli.schema.http_methods=post,get,delete,put,head
cli.schema.boolean_values=true,false
cli.schema.auth_values=none,basic
cli.schema.mode_values=direct,catalog
+cli.command.type=cmd,auth,catalog
<<<<<<< 5301969fc26714a8494882027116282898278f32:framework/src/main/resources/onap.properties
#product version
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index b3835cee..096c6ff3 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -22,9 +22,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import mockit.Invocation;
-import mockit.Mock;
-import mockit.MockUp;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
@@ -50,21 +55,16 @@ import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
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.output.OnapCommandResult;
import org.onap.cli.fw.run.OnapCommandExecutor;
import org.springframework.core.io.Resource;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import mockit.Invocation;
+import mockit.Mock;
+import mockit.MockUp;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
@@ -434,6 +434,22 @@ public class OnapCommandUtilsTest {
}
+
+ @Test
+ public void test() throws OnapCommandException {
+ OnapCommandSampleInfo cmd = new OnapCommandSampleInfo();
+ OnapCommandUtils.loadSchema(cmd, "sample-test-info.yaml", true, false);
+ OnapCommandInfo info = cmd.getInfo();
+ assert info != null;
+ }
+
+ @OnapCommandSchema(name = "sample-test-info", version = "cli-1.0", schema = "sample-test-info.yaml")
+ class OnapCommandSampleInfo extends OnapCommand {
+ @Override
+ protected void run() throws OnapCommandException {
+ }
+ }
+
@OnapCommandSchema(name = "sample-test", version = "cli-1.0", schema = "sample-test-schema.yaml")
class OnapCommandSample extends OnapCommand {
@Override
diff --git a/framework/src/test/resources/sample-test-info.yaml b/framework/src/test/resources/sample-test-info.yaml
new file mode 100644
index 00000000..35e59f8e
--- /dev/null
+++ b/framework/src/test/resources/sample-test-info.yaml
@@ -0,0 +1,9 @@
+open_cli_schema_version: 1.0
+name: sample-test-info
+description: Onap sample command to test the command features
+version: cli-1.0
+info:
+ product: cli-1.0
+ service: cli
+ type: cmd
+ author: Kanagaraj Manickam mkr1481@gmail.com