summaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-12-21 12:44:57 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-12-21 12:44:57 +0530
commit82b9e1fb1673b2ea2cf16c074ce0c76c200fff8a (patch)
treeaecf13e01e0e5f74854f35c26ec89c36a58ba892 /framework/src/main/java/org
parente8e6e21d2ecf21920a338860ee21a11c6278caaf (diff)
Add is_deafult_parm and is_default_attr
Issue-ID: CLI-66 Change-Id: Id6789ffda5d8ae93f4927564844bde36ecd88678 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java/org')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java14
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java18
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java22
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java37
5 files changed, 88 insertions, 6 deletions
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<String> 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<String> initializeProfileSchema() throws OnapCommandException {
+ protected List<String> 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<String, OnapCommandParameter> 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<String> 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<String, ?> valueMap = (Map<String, ?>) values.get(key);
if (valueMap != null) {
- OnapCommandResult result = new OnapCommandResult();
for (Map.Entry<String, ?> 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;
}