From 82b9e1fb1673b2ea2cf16c074ce0c76c200fff8a Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 21 Dec 2017 12:44:57 +0530 Subject: Add is_deafult_parm and is_default_attr Issue-ID: CLI-66 Change-Id: Id6789ffda5d8ae93f4927564844bde36ecd88678 Signed-off-by: Kanagaraj Manickam k00365106 --- .../main/java/org/onap/cli/fw/cmd/OnapCommand.java | 14 ++++++-- .../org/onap/cli/fw/conf/OnapCommandConstants.java | 3 ++ .../onap/cli/fw/input/OnapCommandParameter.java | 18 +++++++++++ .../cli/fw/output/OnapCommandResultAttribute.java | 22 +++++++++++++ .../cli/fw/schema/OnapCommandSchemaLoader.java | 37 +++++++++++++++++++--- framework/src/main/resources/log4j.properties | 2 +- .../open-cli-schema/default_input_parameters.yaml | 8 ++++- framework/src/main/resources/open-cli.properties | 2 +- 8 files changed, 97 insertions(+), 9 deletions(-) (limited to 'framework') diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java index 09e1927a..5479b51b 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java @@ -35,6 +35,8 @@ import org.onap.cli.fw.output.OnapCommandResultType; import org.onap.cli.fw.schema.OnapCommandSchemaLoader; import org.onap.cli.fw.utils.OnapCommandHelperUtils; import org.onap.cli.fw.utils.OnapCommandUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Oclip Command. @@ -42,6 +44,8 @@ import org.onap.cli.fw.utils.OnapCommandUtils; */ public abstract class OnapCommand { + private static Logger LOG = LoggerFactory.getLogger(OnapCommand.class); + private String cmdDescription; private String cmdName; @@ -127,7 +131,7 @@ public abstract class OnapCommand { this.setSchemaName(schema); List errors = OnapCommandSchemaLoader.loadSchema(this, schema, true, validate); - errors.addAll(this.initializeProfileSchema()); + errors.addAll(this.initializeProfileSchema(validate)); this.isInitialzied = true; return errors; @@ -135,7 +139,7 @@ public abstract class OnapCommand { /** * Any additional profile based such as http schema could be initialized. */ - protected List initializeProfileSchema() throws OnapCommandException { + protected List initializeProfileSchema(boolean validate) throws OnapCommandException { return new ArrayList<>(); } @@ -162,8 +166,12 @@ public abstract class OnapCommand { throw new OnapCommandNotInitialized(this.getClass().getName()); } + LOG.info("CMD: " + this.getName()); + Map paramMap = this.getParametersMap(); + LOG.info("INPUT: " + paramMap); + // -h or --help is always higher precedence !, user can set this value to get help message if (OnapCommandConstants.BOOLEAN_TRUE.equals(paramMap.get(OnapCommandConstants.DEFAULT_PARAMETER_HELP).getValue())) { this.cmdResult.setType(OnapCommandResultType.TEXT); @@ -208,6 +216,8 @@ public abstract class OnapCommand { this.run(); + LOG.info("OUTPUT: " + this.cmdResult.getRecords()); + return this.cmdResult; } diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java index 6f911c29..3b2188f3 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java @@ -67,6 +67,7 @@ public class OnapCommandConstants { public static final String DEFAULT_VALUE = "default_value"; public static final String IS_SECURED = "is_secured"; public static final String IS_INCLUDE = "is_include"; + public static final String IS_DEFAULT_PARAM = "is_default_param"; public static final String PARAMETER_TYPE_JSON = "json"; public static final String PARAMETER_TYPE_YAML = "yaml"; @@ -84,6 +85,7 @@ public class OnapCommandConstants { public static final String DEFAULT_PARAMETER_DEBUG = "debug"; public static final String DEFAULT_PARAMETER_OUTPUT_FORMAT = "format"; public static final String DEFAULT_PARAMETER_OUTPUT_ATTR_LONG = "long"; + public static final String DEFAULT_PARAMETER_OUTPUT_NO_TITLE = "no-title"; //results @@ -98,6 +100,7 @@ public class OnapCommandConstants { public static final String SCOPE = "scope"; public static final String RESULT_SCOPE_SHORT = "short"; public static final String RESULT_SCOPE_LONG = "long"; + public static final String IS_DEFAULT_ATTR = "is_default_attr"; //print public static final String PORTRAINT_COLUMN_NAME_PROPERTY = "property"; diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java index 4b21ed4f..00a93725 100644 --- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java +++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java @@ -98,6 +98,19 @@ public class OnapCommandParameter { */ private boolean isInclude = true; + /* + * This param is from The default input parameters file + */ + private boolean isDefaultParam = false; + + public boolean isDefaultParam() { + return isDefaultParam; + } + + public void setDefaultParam(boolean isDefaultParam) { + this.isDefaultParam = isDefaultParam; + } + public String getName() { return cmdName; } @@ -321,4 +334,9 @@ public class OnapCommandParameter { return false; return true; } + + @Override + public String toString() { + return this.getName() + ": " + this.getValue(); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java index 1208a3cd..76af42d7 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java +++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java @@ -57,6 +57,19 @@ public class OnapCommandResultAttribute { private boolean isSecured = false; + /* + * This attr is from The default input parameters file + */ + private boolean isDefaultAttr = false; + + public boolean isDefaultAttr() { + return isDefaultAttr; + } + + public void setDefaultAttr(boolean isDefaultAttr) { + this.isDefaultAttr = isDefaultAttr; + } + public void setValues(List values) { if (values != null) { this.values = values; @@ -86,6 +99,11 @@ public class OnapCommandResultAttribute { return values; } + public void resetValues(String value) { + this.values.clear(); + this.values.add(value); + } + public OnapCommandResultAttributeScope getScope() { return outScope; } @@ -118,4 +136,8 @@ public class OnapCommandResultAttribute { this.defaultValue = defaultValue; } + @Override + public String toString() { + return this.getName() + ": " + this.getValues(); + } } diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java index 28597443..0c4af809 100644 --- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java +++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java @@ -36,6 +36,8 @@ import static org.onap.cli.fw.conf.OnapCommandConstants.INPUT_PARAMS_MANDATORY_L import static org.onap.cli.fw.conf.OnapCommandConstants.IS_INCLUDE; import static org.onap.cli.fw.conf.OnapCommandConstants.IS_OPTIONAL; import static org.onap.cli.fw.conf.OnapCommandConstants.IS_SECURED; +import static org.onap.cli.fw.conf.OnapCommandConstants.IS_DEFAULT_ATTR; +import static org.onap.cli.fw.conf.OnapCommandConstants.IS_DEFAULT_PARAM; import static org.onap.cli.fw.conf.OnapCommandConstants.LONG_OPTION; import static org.onap.cli.fw.conf.OnapCommandConstants.NAME; import static org.onap.cli.fw.conf.OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION; @@ -384,6 +386,21 @@ public class OnapCommandSchemaLoader { param.setInclude(false); } break; + + case IS_DEFAULT_PARAM: + if (validate) { + if (!OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) { + exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME), + IS_DEFAULT_PARAM, parameter.get(key2))); + } + } + + if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { + param.setDefaultParam(true); + } else { + param.setDefaultParam(false); + } + break; } } @@ -399,14 +416,13 @@ public class OnapCommandSchemaLoader { case RESULTS: Map valueMap = (Map) values.get(key); if (valueMap != null) { - OnapCommandResult result = new OnapCommandResult(); for (Map.Entry entry1 : valueMap.entrySet()) { String key3 = entry1.getKey(); switch (key3) { case DIRECTION: try { - result.setPrintDirection(OnapCommandPrintDirection.get((String) valueMap.get(key3))); + cmd.getResult().setPrintDirection(OnapCommandPrintDirection.get((String) valueMap.get(key3))); } catch (OnapCommandException ex) { OnapCommandUtils.throwOrCollect(ex, exceptionList, validate); } @@ -477,15 +493,28 @@ public class OnapCommandSchemaLoader { attr.setSecured(false); } break; + + case IS_DEFAULT_ATTR: + if (validate) { + if (!OnapCommandUtils.validateBoolean(String.valueOf(map.get(key4)))) { + exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(ATTRIBUTES, + IS_DEFAULT_ATTR, map.get(key4))); + } + } + if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) { + attr.setDefaultAttr(true); + } else { + attr.setDefaultAttr(false); + } + break; } } - result.getRecords().add(attr); + cmd.getResult().getRecords().add(attr); } break; } } - cmd.setResult(result); } break; } diff --git a/framework/src/main/resources/log4j.properties b/framework/src/main/resources/log4j.properties index 419faf30..d27b1d60 100644 --- a/framework/src/main/resources/log4j.properties +++ b/framework/src/main/resources/log4j.properties @@ -2,7 +2,7 @@ log4j.rootLogger=ALL, file # Redirect log messages to a log file, support file rolling. log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=${OPEN_CLI_HOME}/logs/oclip.log +log4j.appender.file.File=${OPEN_CLI_HOME}/logs/open-cli.log log4j.appender.file.MaxFileSize=5MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout diff --git a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml index 02e8a717..44c71e53 100644 --- a/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml +++ b/framework/src/main/resources/open-cli-schema/default_input_parameters.yaml @@ -12,33 +12,39 @@ parameters: short_option: h long_option: help default_value: false + is_default_param: true - name: version type: bool description: print service version short_option: v long_option: version default_value: false + is_default_param: true - name: debug type: bool description: Enable debug output short_option: d long_option: debug default_value: false + is_default_param: true - name: format type: string description: Output formats, supported formats such as table, csv, json, yaml short_option: f long_option: format default_value: table + is_default_param: true - name: long type: bool description: whether to print all attributes or only short attributes short_option: s long_option: long default_value: false + is_default_param: true - name: no-title type: bool description: whether to print title or not short_option: t long_option: no-title - default_value: false \ No newline at end of file + default_value: false + is_default_param: true \ No newline at end of file diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties index 4971269f..0e8b2af5 100644 --- a/framework/src/main/resources/open-cli.properties +++ b/framework/src/main/resources/open-cli.properties @@ -9,7 +9,7 @@ cli.schema.top_level_mandatory_list=open_cli_schema_version cli.schema.info_params_list=product,service,type,author,ignore cli.schema.info_params_mandatory_list=product,service -cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include +cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include,is_default_param cli.schema.input_params_mandatory_list=name,description,type cli.schema.result_params_list=name,description,scope,type,is_secured, default_value -- cgit 1.2.3-korg