aboutsummaryrefslogtreecommitdiffstats
path: root/auth/cli-editor
diff options
context:
space:
mode:
Diffstat (limited to 'auth/cli-editor')
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java7
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java32
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java9
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java2
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java5
5 files changed, 28 insertions, 27 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java
index cb1a92eaf..0d36d2daa 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java
@@ -68,7 +68,7 @@ public class ApexCLIEditorMain {
}
parameters.validate();
} catch (final Exception e) {
- LOGGER.error("start of Apex command line editor failed, " + e.getMessage());
+ LOGGER.error("start of Apex command line editor failed, ", e);
errorCount++;
return;
}
@@ -80,8 +80,7 @@ public class ApexCLIEditorMain {
commands = new JSONHandler<CLICommands>().read(CLICommands.class, parameters.getMetadataStream());
} catch (final Exception e) {
LOGGER.error("start of Apex command line editor failed, error reading command metadata from "
- + parameters.getMetadataLocation());
- LOGGER.error(e.getMessage());
+ + parameters.getMetadataLocation(), e);
errorCount++;
return;
}
@@ -139,7 +138,7 @@ public class ApexCLIEditorMain {
modelHandler =
new ApexModelHandler(apexModelProperties.getProperties(), parameters.getInputModelFileName());
} catch (final Exception e) {
- LOGGER.error("execution of Apex command line editor failed: " + e.getMessage());
+ LOGGER.error("execution of Apex command line editor failed: ", e);
errorCount++;
return;
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java
index 560648901..4eacde04b 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java
@@ -20,6 +20,8 @@
package org.onap.policy.apex.auth.clieditor;
+import static org.onap.policy.apex.model.utilities.TreeMapUtils.findMatchingEntries;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -170,7 +172,7 @@ public class CLIEditorLoop {
try {
// Parse the line into a list of commands and arguments
- final ArrayList<String> commandWords = parser.parse(line, logicBlock);
+ final List<String> commandWords = parser.parse(line, logicBlock);
// Find the command, if the command is null, then we are simply changing position in
// the hierarchy
@@ -240,7 +242,7 @@ public class CLIEditorLoop {
* @return The found command
*/
- private CLICommand findCommand(final ArrayList<String> commandWords) {
+ private CLICommand findCommand(final List<String> commandWords) {
CLICommand command = null;
final KeywordNode startKeywordNode = keywordNodeDeque.peek();
@@ -258,8 +260,8 @@ public class CLIEditorLoop {
// If the node entries found is not equal to one, then we have either no command or more
// than one command matching
final List<Entry<String, KeywordNode>> foundNodeEntries =
- TreeMapUtils.findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i));
- if (foundNodeEntries.size() == 0) {
+ findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i));
+ if (foundNodeEntries.isEmpty()) {
unwindStack(startKeywordNode);
throw new CLIException("command not found: " + stringAL2String(commandWords));
} else if (foundNodeEntries.size() > 1) {
@@ -311,7 +313,7 @@ public class CLIEditorLoop {
* @return the argument values
*/
private TreeMap<String, CLIArgumentValue> getArgumentValues(final CLICommand command,
- final ArrayList<String> commandWords) {
+ final List<String> commandWords) {
final TreeMap<String, CLIArgumentValue> argumentValues = new TreeMap<>();
for (final CLIArgument argument : command.getArgumentList()) {
if (argument != null) {
@@ -338,13 +340,11 @@ public class CLIEditorLoop {
// Now check all mandatory arguments are set
for (final CLIArgumentValue argumentValue : argumentValues.values()) {
- if (!argumentValue.isSpecified()) {
- // Argument values are null by default so if this argument is not nullable it is
- // mandatory
- if (!argumentValue.getCliArgument().isNullable()) {
- throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \""
- + argumentValue.getCliArgument().getArgumentName() + "\" not specified");
- }
+ // Argument values are null by default so if this argument is not nullable it is
+ // mandatory
+ if (!argumentValue.isSpecified() && !argumentValue.getCliArgument().isNullable()) {
+ throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \""
+ + argumentValue.getCliArgument().getArgumentName() + "\" not specified");
}
}
@@ -358,7 +358,7 @@ public class CLIEditorLoop {
* @param commandWords The command words entered by the user
* @return the arguments as an entry array list
*/
- private ArrayList<Entry<String, String>> getCommandArguments(final ArrayList<String> commandWords) {
+ private ArrayList<Entry<String, String>> getCommandArguments(final List<String> commandWords) {
final ArrayList<Entry<String, String>> arguments = new ArrayList<>();
// Iterate over the command words, arguments are of the format name=value
@@ -398,11 +398,11 @@ public class CLIEditorLoop {
* @return the result of execution of the command
*/
private ApexAPIResult exceuteSystemCommand(final CLICommand command, final PrintWriter writer) {
- if (command.getName().equals("back")) {
+ if ("back".equals(command.getName())) {
return executeBackCommand();
- } else if (command.getName().equals("help")) {
+ } else if ("help".equals(command.getName())) {
return executeHelpCommand(writer);
- } else if (command.getName().equals("quit")) {
+ } else if ("quit".equals(command.getName())) {
return executeQuitCommand();
} else {
return new ApexAPIResult(RESULT.SUCCESS);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java
index fd4541f28..502eb48c5 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.auth.clieditor;
import java.util.ArrayList;
+import java.util.List;
/**
* This class chops a command line up into commands, parameters and arguments.
@@ -43,7 +44,7 @@ public class CLILineParser {
* @param logicBlock A block of logic code to be taken literally
* @return the string array list
*/
- public ArrayList<String> parse(final String line, final String logicBlock) {
+ public List<String> parse(final String line, final String logicBlock) {
return checkFormat(
mergeArguments(mergeEquals(
splitOnEquals(stripAndSplitWords(mergeQuotes(splitOnChar(stripComments(line), '\"')))))),
@@ -78,12 +79,12 @@ public class CLILineParser {
final ArrayList<String> wordsWithQuotesMerged = new ArrayList<>();
for (int i = 0; i < wordsSplitOnQuotes.size();) {
- if (wordsSplitOnQuotes.get(i).equals("\"")) {
+ if ("\"".equals(wordsSplitOnQuotes.get(i))) {
String quotedWord = wordsSplitOnQuotes.get(i++);
for (; i < wordsSplitOnQuotes.size(); i++) {
quotedWord += wordsSplitOnQuotes.get(i);
- if (wordsSplitOnQuotes.get(i).equals("\"")) {
+ if ("\"".equals(wordsSplitOnQuotes.get(i))) {
i++;
break;
}
@@ -147,7 +148,7 @@ public class CLILineParser {
continue;
}
- if (wordsSplitOnEquals.get(i).equals("=")) {
+ if ("=".equals(wordsSplitOnEquals.get(i))) {
if (i < wordsSplitOnEquals.size() - 1 && !wordsSplitOnEquals.get(i + 1).startsWith("=")) {
wordsWithEqualsMerged.add(wordsSplitOnEquals.get(i) + wordsSplitOnEquals.get(i + 1));
i += 2;
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java
index 476d17e3f..5f363cfa7 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java
@@ -216,7 +216,7 @@ public class CLIParameters {
try {
theFile.createNewFile();
} catch (final IOException e) {
- throw new CLIException("file " + fileName + " cannot be created: " + e.getMessage());
+ throw new CLIException("file " + fileName + " cannot be created: ", e);
}
}
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
index 06579e073..6be5c6846 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.auth.clieditor;
import java.util.ArrayList;
import java.util.List;
+import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -70,7 +71,7 @@ public class KeywordNode implements Comparable<KeywordNode> {
* @param incomingCommand the command
*/
public void processKeywords(final List<String> keywordList, final CLICommand incomingCommand) {
- if (keywordList.size() <= 0) {
+ if (keywordList.isEmpty()) {
this.command = incomingCommand;
return;
}
@@ -118,7 +119,7 @@ public class KeywordNode implements Comparable<KeywordNode> {
*
* @return the children of this keyword node
*/
- public TreeMap<String, KeywordNode> getChildren() {
+ public NavigableMap<String, KeywordNode> getChildren() {
return children;
}