aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java44
-rw-r--r--framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java59
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java3
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java3
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java5
8 files changed, 88 insertions, 63 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
index b88477c0..fa9bcf02 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
@@ -186,20 +186,8 @@ public class OnapCommandResult {
return noOfRecords;
}
- /**
- * Helps to print the result based on the type.
- *
- * @return string
- * @throws OnapCommandOutputFormatNotsupported
- * excpetion
- * @throws OnapCommandOutputPrintingFailed
- * exception
- */
- public String print() throws OnapCommandException {
- if (this.getType().equals(OnapCommandResultType.TEXT)) {
- return this.getOutput().toString();
- }
+ public OnapCommandPrint createAndLoadPrint() {
OnapCommandPrint print = new OnapCommandPrint();
print.setPrintTitle(this.isIncludeTitle());
print.setDirection(this.printDirection);
@@ -232,6 +220,24 @@ public class OnapCommandResult {
print.addColumn(val.getName(), val.getValues());
}
}
+ return print;
+ }
+
+ /**
+ * Helps to print the result based on the type.
+ *
+ * @return string
+ * @throws OnapCommandOutputFormatNotsupported
+ * excpetion
+ * @throws OnapCommandOutputPrintingFailed
+ * exception
+ */
+ public String print() throws OnapCommandException {
+ if (this.getType().equals(OnapCommandResultType.TEXT)) {
+ return this.getOutput().toString();
+ }
+
+ OnapCommandPrint print = createAndLoadPrint();
if (this.getType().equals(OnapCommandResultType.JSON)) {
return print.printJson();
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
index d2bc98be..14e37c3c 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
@@ -98,6 +98,21 @@ public class OnapCommandPrint {
return max;
}
+ public List<List<Object>> addTitle(List<List<Object>> rows, boolean isNormalize){
+ if (this.isPrintTitle()) {
+ List<Object> list = new ArrayList<>();
+ for (String key : this.data.keySet()) {
+ if (isNormalize && key != null && key.length() > MAX_COLUMN_LENGTH) {
+ list.add(splitIntoList(key, MAX_COLUMN_LENGTH));
+ } else {
+ list.add(key);
+ }
+ }
+ rows.add(list);
+ }
+ return rows;
+ }
+
/**
* Helps to form the rows from columns.
*
@@ -112,17 +127,7 @@ public class OnapCommandPrint {
List<List<Object>> rows = new ArrayList<>();
// add title
- if (this.isPrintTitle()) {
- List<Object> list = new ArrayList<>();
- for (String key : this.data.keySet()) {
- if (isNormalize && key != null && key.length() > MAX_COLUMN_LENGTH) {
- list.add(splitIntoList(key, MAX_COLUMN_LENGTH));
- } else {
- list.add(key);
- }
- }
- rows.add(list);
- }
+ rows = addTitle(rows, isNormalize);
// form row
for (int i = 0; i < this.findMaxRows(); i++) {
@@ -166,7 +171,7 @@ public class OnapCommandPrint {
}
// new line is converted to space char
if (inp.contains("\n")) {
- inp = inp.replaceAll("\n", "");
+ inp = inp.replace("\n", "");
}
StringTokenizer tok = new StringTokenizer(inp, " ");
@@ -243,15 +248,20 @@ public class OnapCommandPrint {
}
}
+ public JSONObject printPortrait(List<List<Object>> rows){
+ JSONObject result = new JSONObject();
+ for (int i=1; i<rows.size(); i++) {
+ if (rows.get(i).get(1) != null)
+ result.put(rows.get(i).get(0).toString(), this.getJsonNodeOrString(rows.get(i).get(1).toString()));
+ }
+ return result;
+ }
+
public String printJson() {
List<List<Object>> rows = this.formRows(false);
if (this.direction.equals(OnapCommandPrintDirection.PORTRAIT)) {
- JSONObject result = new JSONObject();
- for (int i=1; i<rows.size(); i++) {
- if (rows.get(i).get(1) != null)
- result.put(rows.get(i).get(0).toString(), this.getJsonNodeOrString(rows.get(i).get(1).toString()));
- }
+ JSONObject result = printPortrait(rows);
return result.toJSONString();
} else {
JSONArray array = new JSONArray();
diff --git a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
index 28344def..912ea23d 100644
--- a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
@@ -17,6 +17,7 @@
package org.onap.cli.fw.registrar;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -332,7 +333,7 @@ public class OnapCommandRegistrar {
String versionInfo = "";
try {
- versionInfo = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(OnapCommandConstants.VERSION_INFO));
+ versionInfo = IOUtils.toString((this.getClass().getClassLoader().getResourceAsStream(OnapCommandConstants.VERSION_INFO)), (Charset) null);
} catch (IOException e) { // NOSONAR
//Never occurs
}
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 e051d5dd..71a189e5 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
@@ -183,7 +183,7 @@ public class OnapCommandSchemaLoader {
List<String> longOptions = new ArrayList<>();
if (validate) {
- OnapCommandUtils.validateTags(exceptionList, (Map<String, Object>) values, OnapCommandConfig.getCommaSeparatedList(TOP_LEVEL_PARAMS_LIST),
+ OnapCommandUtils.validateTags(exceptionList, values, OnapCommandConfig.getCommaSeparatedList(TOP_LEVEL_PARAMS_LIST),
OnapCommandConfig.getCommaSeparatedList(TOP_LEVEL_MANDATORY_LIST), "root level");
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index 32ececfa..0d68db1c 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -263,6 +263,37 @@ public class OnapCommandArtifactStore {
}
}
+ public Artifact setArtifact(Artifact artifact, Artifact existing) throws OnapCommandArtifactNotFound, OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist, IOException, NoSuchAlgorithmException {
+ if (artifact.getName() == null) {
+ artifact.setName(existing.getName());
+ }
+
+ if (artifact.getDescription() == null) {
+ artifact.setDescription(existing.getDescription());
+ }
+
+ if (artifact.getCategoty() == null) {
+ artifact.setCategoty(existing.getCategoty());
+ }
+
+ if (artifact.getPath()!= null) {
+ if (!new File(artifact.getPath()).exists()) {
+ throw new OnapCommandArtifactContentNotExist(artifact.getPath());
+ }
+ String actual = this.getChecksum(artifact.getPath());
+ if (!existing.getChecksum().equals(actual)) {
+ artifact.setChecksum(actual);
+ artifact.setSize(new File(artifact.getPath()).length() / 1024);
+ }
+ } else {
+ artifact.setPath(existing.getPath());
+ }
+
+ artifact.setCreateAt(existing.getCreateAt());
+ artifact.setLastUpdatedAt(dateFormatter.format(new Date()));
+ return artifact;
+ }
+
public Artifact updateArtifact(String name, String category, Artifact artifact) throws OnapCommandArtifactNotFound, OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist {
Artifact existing = this.getArtifact(name, category);
String existingStorePath = getArtifactPath(name, category);
@@ -273,33 +304,7 @@ public class OnapCommandArtifactStore {
}
try {
- if (artifact.getName() == null) {
- artifact.setName(existing.getName());
- }
-
- if (artifact.getDescription() == null) {
- artifact.setDescription(existing.getDescription());
- }
-
- if (artifact.getCategoty() == null) {
- artifact.setCategoty(existing.getCategoty());
- }
-
- if (artifact.getPath()!= null) {
- if (!new File(artifact.getPath()).exists()) {
- throw new OnapCommandArtifactContentNotExist(artifact.getPath());
- }
- String actual = this.getChecksum(artifact.getPath());
- if (!existing.getChecksum().equals(actual)) {
- artifact.setChecksum(actual);
- artifact.setSize(new File(artifact.getPath()).length() / 1024);
- }
- } else {
- artifact.setPath(existing.getPath());
- }
-
- artifact.setCreateAt(existing.getCreateAt());
- artifact.setLastUpdatedAt(dateFormatter.format(new Date()));
+ artifact = setArtifact(artifact, existing);
if (artifact.getMetadata().size() > 0) {
//update to existing one
for (Map.Entry<String, String> entry: artifact.getMetadata().entrySet()) {
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 dab6669c..acf44a9b 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
@@ -22,6 +22,7 @@ import static org.onap.cli.fw.conf.OnapCommandConstants.IS_INCLUDE;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -270,7 +271,7 @@ public class OnapCommandUtils {
//start to read after file:filepath
String fileName = splEntry.substring(5);
try {
- value = FileUtils.readFileToString(new File(fileName));
+ value = FileUtils.readFileToString((new File(fileName)), (Charset) null);
} catch (IOException e) {
//when file is not found, assign the same file:FILE_PATH
//so that it will given hit to user that FILE_PATH to be
diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java
index ee9c7b33..08ef640f 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -17,6 +17,7 @@
package org.onap.cli.main;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -189,7 +190,7 @@ public class OnapCli {
public void handleHelp() {
try {
if (this.printHelp) {
- this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("oclip-readme.txt")));
+ this.print(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("oclip-readme.txt") , (Charset) null));
String help = OnapCommandRegistrar.getRegistrar().getHelp();
this.print(help);
this.exitSuccessfully();
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
index d0885def..53e90661 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -19,6 +19,7 @@ package org.onap.cli.main.utils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -224,7 +225,7 @@ public class OnapCliArgsParser {
try {
File file = new File(input);
if (file.isFile()) {
- return FileUtils.readFileToString(file);
+ return FileUtils.readFileToString(file, (Charset) null);
} else {
return input;
}
@@ -238,7 +239,7 @@ public class OnapCliArgsParser {
try {
File file = new File(input);
if (file.isFile()) {
- String value = FileUtils.readFileToString(file);
+ String value = FileUtils.readFileToString(file, (Charset) null);
YamlReader reader = new YamlReader(value);
value = (String) reader.read();
return value;