summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-09-07 16:58:41 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-09-07 17:00:14 +0530
commit635d08899576ff360a7ca52d6b2f17076670b6fc (patch)
treed07b783d0c04c032cd8b87d76b435f3a15f051d3
parentf24521907506d3c7b77375d76661458bc3ad9f33 (diff)
Add TEXT parameter type
CLI-2 Change-Id: I4af65e154649e1cd891f30b870406fe5b5ea8cbb Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/ParameterType.java4
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java19
2 files changed, 22 insertions, 1 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/input/ParameterType.java b/framework/src/main/java/org/onap/cli/fw/input/ParameterType.java
index c93d92fe..2625883e 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/ParameterType.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/ParameterType.java
@@ -30,7 +30,7 @@ public enum ParameterType {
/**
* YAML file.
*/
- YAML, STRING, LONG,
+ YAML, STRING, TEXT, LONG,
/**
* URL location.
*/
@@ -66,6 +66,8 @@ public enum ParameterType {
return BINARY;
} else if (UUID.name().equalsIgnoreCase(name)) {
return UUID;
+ } else if (TEXT.name().equalsIgnoreCase(name)) {
+ return TEXT;
} else {
throw new OnapCommandInvalidParameterType(name);
}
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java
index ed47bc68..be88aed0 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import net.minidev.json.JSONObject;
+import org.apache.commons.io.FileUtils;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
import org.onap.cli.fw.input.OnapCommandParameter;
@@ -110,6 +111,11 @@ public class OnapCliUtils {
paramMap.get(shortOptionMap.get(args.get(i))).getName()));
i++;
continue;
+ } if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) {
+ paramMap.get(shortOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1),
+ paramMap.get(shortOptionMap.get(args.get(i))).getName()));
+ i++;
+ continue;
} else if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType()
.equals(ParameterType.ARRAY)) {
Object value = paramMap.get(shortOptionMap.get(args.get(i))).getValue();
@@ -171,6 +177,11 @@ public class OnapCliUtils {
paramMap.get(longOptionMap.get(args.get(i))).getName()));
i++;
continue;
+ } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) {
+ paramMap.get(longOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1),
+ paramMap.get(longOptionMap.get(args.get(i))).getName()));
+ i++;
+ continue;
} else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType()
.equals(ParameterType.ARRAY)) {
Object value = paramMap.get(longOptionMap.get(args.get(i))).getValue();
@@ -248,6 +259,14 @@ public class OnapCliUtils {
}
}
+ private static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
+ try {
+ return FileUtils.readFileToString(new File(input));
+ } catch (IOException e) {
+ throw new OnapCliInvalidArgument(argName, e);
+ }
+ }
+
private static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument {
TypeReference<List<String>> mapType = new TypeReference<List<String>>() {
};