aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-27 16:11:39 -0400
committerRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-27 17:28:40 -0400
commitdb784313b8ba29f5d4396c1cc96bb5f3c853677f (patch)
treef26c260919b39751747ad64e87b1a7932c222046
parentbcca60b3c9e50e93a0f309905049ddbbf45768ef (diff)
Fix sonar issues in policy/gui
Issue-ID: POLICY-3077 Change-Id: Idcd08427cbff2cfdd8ba99db7cf32a0f5c978415 Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyTab.js26
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js39
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskTab.js17
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/dropdownList.js13
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideTextarea.js5
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java9
6 files changed, 52 insertions, 57 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyTab.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyTab.js
index 045eb6d..c6ef0db 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyTab.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyTab.js
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,8 +38,8 @@ function policyTab_activate() {
ajax_get(requestURL, function(data) {
$("#policyTableBody").find("tr:gt(0)").remove();
- for (var i = 0; i < data.messages.message.length; i++) {
- var policy = JSON.parse(data.messages.message[i]).apexPolicy;
+ for (let value of data.messages.message) {
+ var policy = JSON.parse(value).apexPolicy;
var policyRow_tr = document.createElement("tr");
var policyid = policy.policyKey.name + ":" + policy.policyKey.version;
@@ -67,9 +68,9 @@ function policyTab_activate() {
}
}
- for (var p = 0; p < policy.state.entry.length; p++) {
- var stateName = policy.state.entry[p].key;
- state = policy.state.entry[p].value;
+ for (let entry of policy.state.entry) {
+ var stateName = entry.key;
+ state = entry.value;
policyTableRow +=
"<tr><td>" +
@@ -80,9 +81,9 @@ function policyTab_activate() {
"</td>";
policyTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Task Reference</th><th>Output Type</th><th>Output</th></thead><tbody>";
- for (var t = 0; t < state.taskReferences.entry.length; t++) {
- var taskKey = state.taskReferences.entry[t].key;
- var taskRef = state.taskReferences.entry[t].value;
+ for (let entry of state.taskReferences.entry) {
+ var taskKey = entry.key;
+ var taskRef = entry.value;
policyTableRow +=
"<tr><td>" +
@@ -106,8 +107,7 @@ function policyTab_activate() {
"</td>";
policyTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Name</th><th>Next State</th><th>Event</th></thead><tbody>";
- for (var o = 0; o < state.stateOutputs.entry.length; o++) {
- var outputEntry = state.stateOutputs.entry[o];
+ for (let outputEntry of state.stateOutputs.entry) {
policyTableRow +=
"<tr><td>" +
@@ -123,8 +123,7 @@ function policyTab_activate() {
policyTableRow += "</tbody></table></td>";
policyTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Name</th><th>Type</th></thead><tbody>";
- for (var sf = 0; sf < state.stateFinalizerLogicMap.entry.length; sf++) {
- var sflEntry = state.stateFinalizerLogicMap.entry[sf];
+ for (let sflEntry of state.stateFinalizerLogicMap.entry) {
policyTableRow +=
"<tr><td>" +
@@ -138,8 +137,7 @@ function policyTab_activate() {
policyTableRow += "<td><table class='ebTable'><tbody>";
- for (var c = 0; c < state.contextAlbumReference.length; c++) {
- var contextAlbumReference = state.contextAlbumReference[c];
+ for (let contextAlbumReference of state.contextAlbumReference) {
policyTableRow +=
"<tr><td>" +
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js
index 7ae7747..5503064 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,8 +32,8 @@ function editTaskForm_createTask(formParent) {
var requestURL = window.restRootURL + "/ContextSchema/Get?name=&version=";
var contextSchemas = new Array();
ajax_get(requestURL, function(data2) {
- for (var i = 0; i < data2.messages.message.length; i++) {
- var contextSchema = JSON.parse(data2.messages.message[i]).apexContextSchema;
+ for (let value of data2.messages.message) {
+ var contextSchema = JSON.parse(value).apexContextSchema;
var dt = {
"name" : contextSchema.key.name,
"version" : contextSchema.key.version,
@@ -45,8 +46,8 @@ function editTaskForm_createTask(formParent) {
requestURL = window.restRootURL + "/ContextAlbum/Get?name=&version=";
var contextAlbums = new Array();
ajax_get(requestURL, function(data3) {
- for (var y = 0; y < data3.messages.message.length; y++) {
- var contextAlbum = JSON.parse(data3.messages.message[y]).apexContextAlbum;
+ for (let value of data3.messages.message) {
+ var contextAlbum = JSON.parse(value).apexContextAlbum;
var ca = {
"name" : contextAlbum.key.name,
"version" : contextAlbum.key.version,
@@ -87,8 +88,8 @@ function editTaskForm_editTask_inner(formParent, name, version, viewOrEdit) {
requestURL = window.restRootURL + "/ContextSchema/Get?name=&version=";
var contextSchemas = new Array();
ajax_get(requestURL, function(data2) {
- for (var i = 0; i < data2.messages.message.length; i++) {
- var contextSchema = JSON.parse(data2.messages.message[i]).apexContextSchema;
+ for (let value of data2.messages.message) {
+ var contextSchema = JSON.parse(value).apexContextSchema;
contextSchemas.push({
"name" : contextSchema.key.name,
"version" : contextSchema.key.version,
@@ -100,8 +101,8 @@ function editTaskForm_editTask_inner(formParent, name, version, viewOrEdit) {
requestURL = window.restRootURL + "/ContextAlbum/Get?name=&version=";
var contextAlbums = new Array();
ajax_get(requestURL, function(data3) {
- for (var y = 0; y < data3.messages.message.length; y++) {
- var contextAlbum = JSON.parse(data3.messages.message[y]).apexContextAlbum;
+ for (let value of data3.messages.message) {
+ var contextAlbum = JSON.parse(value).apexContextAlbum;
var ca = {
"name" : contextAlbum.key.name,
"version" : contextAlbum.key.version,
@@ -296,8 +297,7 @@ function editTaskForm_activate(parent, operation, task, contextSchemas, contextA
inputfieldstable.appendChild(inputfieldstable_body);
// Add the inputfields
if (task && task.inputFields && task.inputFields.entry) {
- for (var p = 0; p < task.inputFields.entry.length; p++) {
- var inputfieldEntry = task.inputFields.entry[p];
+ for (let inputfieldEntry of task.inputFields.entry) {
var contextSchema = inputfieldEntry.value.fieldSchemaKey;
contextSchema["displaytext"] = contextSchema.name + ":" + contextSchema.version;
editTaskForm_addTaskInputField(inputfieldstable_body, (createEditOrView == "VIEW"), inputfieldEntry.key,
@@ -355,8 +355,7 @@ function editTaskForm_activate(parent, operation, task, contextSchemas, contextA
outputfieldstable.appendChild(outputfieldstable_body);
// Add the outputfields
if (task && task.outputFields && task.outputFields.entry) {
- for (var y = 0; y < task.outputFields.entry.length; y++) {
- var outputfieldEntry = task.outputFields.entry[y];
+ for (let outputfieldEntry of task.outputFields.entry) {
contextSchema = outputfieldEntry.value.fieldSchemaKey;
contextSchema["displaytext"] = contextSchema.name + ":" + contextSchema.version;
editTaskForm_addTaskOutputField(outputfieldstable_body, (createEditOrView == "VIEW"), outputfieldEntry.key,
@@ -447,8 +446,7 @@ function editTaskForm_activate(parent, operation, task, contextSchemas, contextA
paramstable.appendChild(paramstable_body);
// Add the params
if (task && task.taskParameters && task.taskParameters.entry) {
- for (var k = 0; k < task.taskParameters.entry.length; k++) {
- var paramEntry = task.taskParameters.entry[k];
+ for (let paramEntry of task.taskParameters.entry) {
var paramName = paramEntry.key;
var paramValue = paramEntry.value.defaultValue;
editTaskForm_addTaskParameter(paramstable_body, (createEditOrView == "VIEW"), paramName, paramValue);
@@ -497,8 +495,7 @@ function editTaskForm_activate(parent, operation, task, contextSchemas, contextA
contextstable.appendChild(contextstable_body);
// Add the contexts
if (task && task.contextAlbumReference && $.isArray(task.contextAlbumReference)) {
- for (var l = 0; l < task.contextAlbumReference.length; l++) {
- var contextEntry = task.contextAlbumReference[l];
+ for (let contextEntry of task.contextAlbumReference) {
var contextName = contextEntry.name + ":" + contextEntry.version;
var ce = {
"name" : contextEntry.name,
@@ -643,7 +640,7 @@ function editTaskForm_addTaskInputField(parentTBody, disabled, name, optional, c
if (name == null && contextSchema == null && !disabled) {
inputOptional.setAttribute("class", "field-eventparam-optional.new");
}
- if (optional == true) {
+ if (optional) {
inputOptional.checked = true;
} else {
inputOptional.checked = false;
@@ -712,7 +709,7 @@ function editTaskForm_addTaskOutputField(parentTBody, disabled, name, optional,
if (name == null && contextSchema == null && !disabled) {
outputOptional.setAttribute("class", "field-eventparam-optional.new");
}
- if (optional == true) {
+ if (optional) {
outputOptional.checked = true;
} else {
outputOptional.checked = false;
@@ -960,9 +957,9 @@ function editTaskForm_submitPressed() {
return false;
}
var contextalbumname = contextalbumvalue.displaytext;
- for (var j = 0; j < taskbean_context.length; j++) {
- if (taskbean_context[j] != null && taskbean_context[j].name == contextalbumvalue.name
- && taskbean_context[j].version == contextalbumvalue.version) {
+ for (let value of taskbean_context) {
+ if (value != null && value.name == contextalbumvalue.name
+ && value.version == contextalbumvalue.version) {
alert("Task \"" + name + "\" references Context Album \"" + contextalbumname
+ "\" more than once");
return false;
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskTab.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskTab.js
index 28d9379..9c79ad4 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskTab.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskTab.js
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,8 +38,8 @@ function taskTab_activate() {
ajax_get(requestURL, function(data) {
$("#taskTableBody").find("tr:gt(0)").remove();
- for (let i = 0; i < data.messages.message.length; i++) {
- const task = JSON.parse(data.messages.message[i]).apexTask;
+ for (let value of data.messages.message) {
+ const task = JSON.parse(value).apexTask;
const taskRow_tr = document.createElement("tr");
@@ -51,8 +52,7 @@ function taskTab_activate() {
"</td>";
taskTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Field Name</th><th>Field Type/Schema</th><th>Optional</th></tr></thead><tbody>";
- for (var f = 0; f < task.inputFields.entry.length; f++) {
- var fieldEntry = task.inputFields.entry[f];
+ for (let fieldEntry of task.inputFields.entry) {
taskTableRow +=
"<tr><td>" +
@@ -67,8 +67,7 @@ function taskTab_activate() {
taskTableRow += "</tbody></table></td>";
taskTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Field Name</th><th>Field Type/Schema</th><th>Optional</th></tr></thead><tbody>";
- for (var t = 0; t < task.outputFields.entry.length; t++) {
- fieldEntry = task.outputFields.entry[t];
+ for (let fieldEntry of task.outputFields.entry) {
taskTableRow +=
"<tr><td>" +
@@ -83,8 +82,7 @@ function taskTab_activate() {
taskTableRow += "</tbody></table></td>";
taskTableRow += "<td><table class='ebTable'><thead><tr class='headerRow'><th>Parameter Name</th><th>Default Value</th></tr></thead><tbody>";
- for (var p = 0; p < task.taskParameters.entry.length; p++) {
- var parameterEntry = task.taskParameters.entry[p];
+ for (let parameterEntry of task.taskParameters.entry) {
taskTableRow +=
"<tr><td>" +
@@ -97,8 +95,7 @@ function taskTab_activate() {
taskTableRow += "</tbody></table></td>";
taskTableRow += "<td><table class='ebTable'><tbody>";
- for (var c = 0; c < task.contextAlbumReference.length; c++) {
- var contextAlbumReference = task.contextAlbumReference[c];
+ for (let contextAlbumReference of task.contextAlbumReference) {
taskTableRow +=
"<tr><td>" +
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/dropdownList.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/dropdownList.js
index 3657fd4..d18b38e 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/dropdownList.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/dropdownList.js
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,11 +61,11 @@ function dropdownList_filter(optionDiv, optionUl) {
ul = document.getElementById(optionDiv + "_options_list_ul");
var lis = ul.querySelectorAll("#" + ul.id + " > li"); // get li direct
// child elements
- for (var i = 0; i < lis.length; i++) {
- if (lis[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
- lis[i].style.display = "";
+ for (let value of lis) {
+ if (value.innerHTML.toUpperCase().indexOf(filter) > -1) {
+ value.style.display = "";
} else {
- lis[i].style.display = "none";
+ value.style.display = "none";
}
}
}
@@ -123,8 +124,8 @@ function dropdownList_ChangeOptions(dropdownListDIV, options, selected, disabled
// that
// are
// divs
- for (var d = 0; d < subdivs.length; d++) {
- retdiv.removeChild(subdivs[d]);
+ for (let value of subdivs) {
+ retdiv.removeChild(value);
}
var onselect = null;
if (retdiv["_dropDownList_listener"]) {
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideTextarea.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideTextarea.js
index 0a3058e..8c98d3f 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideTextarea.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideTextarea.js
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +24,7 @@ function showHideTextarea_display_hide(showHideDivprefix) {
var ta = document.getElementById(showHideDivprefix + "_textarea");
var sh = document.getElementById(showHideDivprefix + "_showhide");
_showHideTextarea_display_hide(ta, sh)
- if (sh["_clickable"] == true) {
+ if (sh["_clickable"]) {
sh.onclick = function(event) {
showHideTextarea_display_show(showHideDivprefix);
};
@@ -33,7 +34,7 @@ function showHideTextarea_display_show(showHideDivprefix) {
var ta = document.getElementById(showHideDivprefix + "_textarea");
var sh = document.getElementById(showHideDivprefix + "_showhide");
_showHideTextarea_display_show(ta, sh)
- if (sh["_clickable"] == true) {
+ if (sh["_clickable"]) {
sh.onclick = function(event) {
showHideTextarea_display_hide(showHideDivprefix);
};
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
index 9201983..88e2707 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,9 +34,9 @@ public class ApexEditorParametersTest {
apexEditorParameters.setRestPort(-3);
apexEditorParameters.setUploadUrl("what://ever");
final var actual = apexEditorParameters.validate();
- assertThat(actual).contains("upload-url parameter is an invalid");
- assertThat(actual).contains("upload-userid parameter must be specified");
- assertThat(actual).contains("port must be between");
- assertThat(actual).contains("time to live must be greater than -1");
+ assertThat(actual).contains("upload-url parameter is an invalid")
+ .contains("upload-userid parameter must be specified")
+ .contains("port must be between")
+ .contains("time to live must be greater than -1");
}
}