aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main
diff options
context:
space:
mode:
authorSravanKumarGunda <sravan.kumar1@huawei.com>2020-06-18 19:05:44 +0530
committerSravanKumarGunda <sravan.kumar1@huawei.com>2020-07-02 16:02:50 +0530
commitc3391bef9e04c2ad38ed96bd28a5c43ab6d961de (patch)
treefbb3c017de9d5e016a7d9de88b0ea1193b9d6265 /framework/src/main
parent022ee4b8daa1b852d72c1083658d1efb254f9dd5 (diff)
Code Improvements-Sonar Issue Fixes
Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com> Issue-ID: CLI-270 Change-Id: Iba00ddc8c471bc5990d87ba3729af373e2bd6711
Diffstat (limited to 'framework/src/main')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java36
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java17
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java12
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java8
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java9
12 files changed, 34 insertions, 66 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java
index 5470472c..349fb52e 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java
@@ -37,7 +37,7 @@ public class OnapCommandExceutionListCommand extends OnapCommand {
protected void run() throws OnapCommandException {
Map<String, String> map = new HashMap<>();
- for (String input: Arrays.asList(new String []{"request-id", "product", "service", "command", "profile", "start-time", "end-time"})) {
+ for (String input: Arrays.asList("request-id", "product", "service", "command", "profile", "start-time", "end-time")) {
String value = getParametersMap().get(input).getValue().toString();
if (value != null && !value.isEmpty()) {
map.put(input, value);
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
index 10d9c448..42dc27e2 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
@@ -59,7 +59,7 @@ public class OnapProductsListCommand extends OnapCommand {
if (stream != null) {
Map<String, ?> map = OnapCommandDiscoveryUtils.loadYaml(stream);
Map<String, String> productMap = (Map<String, String>) map.get("product");
- String description = (String) productMap.get(OnapCommandConstants.DESCRIPTION);
+ String description = productMap.get(OnapCommandConstants.DESCRIPTION);
this.getResult().getRecordsMap().get("description").getValues().add(description.trim());
} else {
this.getResult().getRecordsMap().get("description").getValues().add("");
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 76af42d7..307e1b98 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
@@ -94,7 +94,7 @@ public class OnapCommandResultAttribute {
public List<String> getValues() {
if (this.values.isEmpty() && !this.defaultValue.isEmpty()) {
- return Arrays.asList(new String [] {this.defaultValue});
+ return Arrays.asList(this.defaultValue);
}
return values;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java
index ebd13ebd..a1029ca2 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java
@@ -31,11 +31,7 @@ public enum OnapCommandResultType {
* @return boolean
*/
public static boolean isTabularForm(String type) {
- if (type.equalsIgnoreCase(TABLE.name())) {
- return true;
- }
-
- return false;
+ return type.equalsIgnoreCase(TABLE.name());
}
/**
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 8d707906..7a125ce5 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
@@ -238,7 +238,7 @@ public class OnapCommandPrint {
public Object getJsonNodeOrString(String value) {
try {
- return (JSONObject) JSONValue.parse(value);
+ return JSONValue.parse(value);
} catch (Exception e) {
return value;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java b/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java
index 8be7952d..389a98fe 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java
@@ -80,7 +80,7 @@ public class TableGenerator {
for (int cellIndex = 0; cellIndex < row.size(); cellIndex++) {
Object cell = row.get(cellIndex);
String finalCell = "";
- if (cell != null && cell instanceof List) {
+ if (cell instanceof List) {
List<String> list = (List<String>) cell;
if (splitCellIndex < list.size()) {
finalCell = list.get(splitCellIndex);
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 41be2332..4f6e4ea5 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
@@ -346,11 +346,7 @@ public class OnapCommandSchemaLoader {
IS_OPTIONAL, String.valueOf(parameter.get(key2))));
}
- if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setOptional(true);
- } else {
- param.setOptional(false);
- }
+ param.setOptional(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2))));
break;
case IS_SECURED:
@@ -361,11 +357,7 @@ public class OnapCommandSchemaLoader {
}
}
- if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setSecured(true);
- } else {
- param.setSecured(false);
- }
+ param.setSecured(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2))));
break;
case IS_INCLUDE:
@@ -374,11 +366,7 @@ public class OnapCommandSchemaLoader {
IS_INCLUDE, String.valueOf(parameter.get(key2))));
}
- if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setInclude(true);
- } else {
- param.setInclude(false);
- }
+ param.setInclude(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2))));
break;
case IS_DEFAULT_PARAM:
@@ -389,11 +377,7 @@ public class OnapCommandSchemaLoader {
}
}
- if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setDefaultParam(true);
- } else {
- param.setDefaultParam(false);
- }
+ param.setDefaultParam(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2))));
break;
}
}
@@ -477,11 +461,7 @@ public class OnapCommandSchemaLoader {
IS_SECURED, String.valueOf(map.get(key4))));
}
}
- if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) {
- attr.setSecured(true);
- } else {
- attr.setSecured(false);
- }
+ attr.setSecured(BOOLEAN_TRUE.equals(String.valueOf(map.get(key4))));
break;
case IS_DEFAULT_ATTR:
@@ -491,11 +471,7 @@ public class OnapCommandSchemaLoader {
IS_DEFAULT_ATTR, String.valueOf(map.get(key4))));
}
}
- if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) {
- attr.setDefaultAttr(true);
- } else {
- attr.setDefaultAttr(false);
- }
+ attr.setDefaultAttr(BOOLEAN_TRUE.equals(String.valueOf(map.get(key4))));
break;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
index 9e230ff3..b0ebbda5 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
@@ -59,17 +59,17 @@ public class OnapCommandExecutionStore {
private static String SEPARATOR = "__";
private enum SearchMode {
- find,
- file //for developer mode
+ FIND,
+ FILE //for developer mode
}
- private static SearchMode SEARCH_MODE = SearchMode.file;
+ private static SearchMode SEARCH_MODE = SearchMode.FILE;
static {
String mode = OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_EXECUTION_SEARCH_MODE);
- if (mode.equalsIgnoreCase(SearchMode.find.name()))
- SEARCH_MODE = SearchMode.find;
+ if (mode.equalsIgnoreCase(SearchMode.FIND.name()))
+ SEARCH_MODE = SearchMode.FIND;
}
public static class ExecutionStoreContext {
@@ -334,7 +334,7 @@ public class OnapCommandExecutionStore {
try {
List <String> dirs = new ArrayList<>();
- if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.file)) {
+ if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.FILE)) {
for (File f: new File(getBasePath()).listFiles()) {
if(search.containsKey(EXECUTIONID)) {
if (f.getName().startsWith(search.get(EXECUTIONID)))
@@ -379,7 +379,7 @@ public class OnapCommandExecutionStore {
searchString.append("*");
}
- for (String term: Arrays.asList(new String []{"product", "service", "command", "profile"})) {
+ for (String term: Arrays.asList("product", "service", "command", "profile")) {
searchString.append("__");
if (search.get(term) != null && !search.get(term).isEmpty()) {
searchString.append(search.get(term));
@@ -453,8 +453,7 @@ public class OnapCommandExecutionStore {
@Override
public boolean accept(File dir, String name) {
- if (name.startsWith(executionId)) return true;
- return false;
+ return name.startsWith(executionId);
}
});
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index 7a4dc49f..0db96956 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -57,8 +57,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import com.esotericsoftware.yamlbeans.YamlReader;
-import com.esotericsoftware.yamlbeans.YamlException;
-
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
@@ -86,7 +84,7 @@ public class OnapCommandDiscoveryUtils {
public static OnapCommandSchemaInfo getSchemaInfo(String cmd, String version) throws OnapCommandException {
List<OnapCommandSchemaInfo> list = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(false);
OnapCommandSchemaInfo schemaInfo = null;
- if (list != null) {
+ if (list != null) { //NOSONAR
for (OnapCommandSchemaInfo schema : list) {
if (cmd.equals(schema.getCmdName()) && version.equals(schema.getProduct())) {
schemaInfo = schema;
@@ -237,7 +235,7 @@ public class OnapCommandDiscoveryUtils {
*/
public static Resource findResource(String fileName, String pattern) throws IOException {
Resource[] resources = OnapCommandDiscoveryUtils.findResources(pattern);
- if (resources != null && resources.length > 0) {
+ if (resources != null && resources.length > 0) { //NOSONAR
for (Resource res : resources) {
if (res.getFilename().equals(fileName)) {
return res;
@@ -305,7 +303,7 @@ public class OnapCommandDiscoveryUtils {
//default_input_parameters_http.yaml
String profileName = resource.getFilename().substring(
DEAFULT_INPUT_PARAMETERS_NAME.length() + 1,
- resource.getFilename().indexOf("."));
+ resource.getFilename().indexOf('.'));
if (deafultResourceMap.containsKey(PARAMETERS)) {
List<Object> params = new ArrayList<>();
for (Map<String, ?> p: (List<Map<String, ?>>) deafultResourceMap.get(PARAMETERS)) {
@@ -491,7 +489,7 @@ public class OnapCommandDiscoveryUtils {
OnapCommandSchemaInfo schemaInfo = getSchemaInfo(cmd, version);
List<String> sampleFiles = new ArrayList<>();
- if (schemaInfo != null && !schemaInfo.getSampleFiles().isEmpty()) {
+ if (schemaInfo != null && !schemaInfo.getSampleFiles().isEmpty()) { //NOSONAR
sampleFiles.addAll(schemaInfo.getSampleFiles());
}
@@ -584,8 +582,6 @@ public class OnapCommandDiscoveryUtils {
try(InputStreamReader inputStreamReader = new InputStreamReader(inputStream);){
YamlReader reader = new YamlReader(inputStreamReader);
values = (Map<String, ?>) reader.read();
- } catch (YamlException e) {
- throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage());
} catch (IOException e) {
throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage());
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
index 323e9e76..e1150888 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
@@ -183,7 +183,7 @@ public class OnapCommandHelperUtils {
resultTable.getRecords().add(attrHelp);
}
- if (cmd.getResult().getRecords().size() > 0) {
+ if (!cmd.getResult().getRecords().isEmpty()) {
try {
help.append("\n\nResults::\n\n" + resultTable.print());
} catch (OnapCommandException e) {
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 814f5139..ea8e6480 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
@@ -124,7 +124,7 @@ public class OnapCommandUtils {
if (idxS == -1) {
break;
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String paramName = line.substring(idxS + 2, idxE);
paramNames.add(paramName.trim());
@@ -213,7 +213,7 @@ public class OnapCommandUtils {
resultLine.append(line.substring(currentIdx));
break;
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String attr = line.substring(idxS + 3, idxE);
attr = attr.trim();
@@ -246,7 +246,7 @@ public class OnapCommandUtils {
resultSpl.append(lineSpl.substring(currentIdx));
break;
}
- int idxE = lineSpl.indexOf("}", idxS);
+ int idxE = lineSpl.indexOf('}', idxS);
String splEntry = lineSpl.substring(idxS + 3, idxE);
splEntry = splEntry.trim();
@@ -319,7 +319,7 @@ public class OnapCommandUtils {
result.append(line.substring(currentIdx));
break;
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String paramName = line.substring(idxS + 2, idxE);
paramName = paramName.trim();
if (!params.containsKey(paramName)) {
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
index bb37c470..69df6075 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.nio.charset.StandardCharsets;
public class ProcessRunner {
private static Logger log = LoggerFactory.getLogger(ProcessRunner.class);
@@ -127,7 +128,7 @@ public class ProcessRunner {
public void run() {
try {
IOUtils.copy(stdoutP, stdout);
- } catch (IOException e) {
+ } catch (IOException e) { // NOSONAR
}
}
});
@@ -136,7 +137,7 @@ public class ProcessRunner {
public void run() {
try {
IOUtils.copy(stderrP, stderr);
- } catch (IOException e) {
+ } catch (IOException e) { // NOSONAR
}
}
});
@@ -153,10 +154,10 @@ public class ProcessRunner {
}
if (readOutput)
- this.output = new String(((ByteArrayOutputStream)this.getStdout()).toByteArray(), "UTF-8");
+ this.output = new String(((ByteArrayOutputStream)this.getStdout()).toByteArray(), StandardCharsets.UTF_8);
if (readError)
- this.error = new String(((ByteArrayOutputStream)this.getStderr()).toByteArray(), "UTF-8");;
+ this.error = new String(((ByteArrayOutputStream)this.getStderr()).toByteArray(), StandardCharsets.UTF_8);
p.destroy();