Skip to content

Commit

Permalink
#1966 - Fix sonarcloud critical issues (part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh16011993 committed May 26, 2023
1 parent daece83 commit 6db3267
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class BCeIDService {
);

try {
var client = await createClientAsync(this.bceidConfig.wsdlEndpoint, {
const client = await createClientAsync(this.bceidConfig.wsdlEndpoint, {
wsdl_headers: wsdlAuthHeader,
});
client.setSecurity(clientSecurity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export abstract class SFTPIntegrationBase<DownloadType> {

return filesToProcess
.map((file) => path.join(remoteDownloadFolder, file.name))
.sort();
.sort((file1: string, file2: string) => {
if (file1 <= file2) {
return -1;
} else {
return 1;
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// var system = java.lang.System;
// system.out.println(“System out println”);

var applicationExceptions = [];
var dynamicData = S(execution.getVariable("applicationData"));
const applicationExceptions = [];
const dynamicData = S(execution.getVariable("applicationData"));
// Value assigned to a property to determine that it is an application exception.
var STUDENT_APPLICATION_EXCEPTION_VALUE_IDENTIFIER =
const STUDENT_APPLICATION_EXCEPTION_VALUE_IDENTIFIER =
"studentApplicationException";

/**
Expand All @@ -16,19 +16,19 @@ var STUDENT_APPLICATION_EXCEPTION_VALUE_IDENTIFIER =
*/
function searchExceptions(payload) {
if (payload.isArray()) {
var arrayItems = payload.elements();
for (var i = 0; i < arrayItems.length; i++) {
const arrayItems = payload.elements();
for (let i = 0; i < arrayItems.length; i++) {
// If the payload is an array, iterate through each item
// looking for some application exception.
searchExceptions(arrayItems[i]);
}
} else if (payload.isObject()) {
// If the payload is an object, iterate through its properties
// looking for some application exception.
var objectFieldNames = payload.fieldNames();
for (var i = 0; i < objectFieldNames.length; i++) {
var fieldName = objectFieldNames[i];
var objectProp = payload.prop(fieldName);
const objectFieldNames = payload.fieldNames();
for (let i = 0; i < objectFieldNames.length; i++) {
const fieldName = objectFieldNames[i];
const objectProp = payload.prop(fieldName);
if (objectProp.isArray() || objectProp.isObject()) {
searchExceptions(objectProp);
} else if (
Expand Down Expand Up @@ -58,13 +58,13 @@ function arrayToPayload(fieldName) {
searchExceptions(dynamicData);
// Prepare the payload that will be used to call the SIMS API
// and create the application exceptions, if needed.
var applicationExceptionsPayload = applicationExceptions.map(arrayToPayload);
const applicationExceptionsPayload = applicationExceptions.map(arrayToPayload);
execution.setVariable(
"applicationExceptions",
JSON.stringify(applicationExceptionsPayload)
JSON.stringify(applicationExceptionsPayload),
);
// Set hasApplicationExceptions for easy verification on the workflow decisions.
execution.setVariable(
"hasApplicationExceptions",
applicationExceptions.length > 0
applicationExceptions.length > 0,
);
32 changes: 16 additions & 16 deletions sources/packages/backend/workflow/scripts/api-response-parser.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Sample code to write to the console.
// var system = java.lang.System;

var httpSuccessCode = connector.getVariable("httpSuccessCode");
var errorCodeName = connector.getVariable("errorCodeName");
var statusCode = connector.getVariable("statusCode");
const httpSuccessCode = connector.getVariable("httpSuccessCode");
const errorCodeName = connector.getVariable("errorCodeName");
const statusCode = connector.getVariable("statusCode");
if (statusCode !== parseInt(httpSuccessCode)) {
throw new org.camunda.bpm.engine.delegate.BpmnError(errorCodeName, response);
}

/**
* Input field names are expected in the format someParent.someChild.
*/
var INPUT_HIERARCHY_SEPARATOR = ".";
const INPUT_HIERARCHY_SEPARATOR = ".";
/**
* Output connector variables will be created in the format someParent_someChild.
*/
var OUTPUT_HIERARCHY_SEPARATOR = "_";
const OUTPUT_HIERARCHY_SEPARATOR = "_";

/**
* Recursively read the values from the payload to create workflow variables.
Expand All @@ -28,31 +28,31 @@ var OUTPUT_HIERARCHY_SEPARATOR = "_";
*/
function setValuesFromPayload(payload, fieldName, fieldsNamesPath) {
// Check if the field has some hierarchy (e.g. someParent.someChild).
var parentIndex = fieldName.indexOf(INPUT_HIERARCHY_SEPARATOR);
const parentIndex = fieldName.indexOf(INPUT_HIERARCHY_SEPARATOR);
if (payload && parentIndex > -1) {
// Extract the parent field name (e.g. someParent);
var parentFieldName = fieldName.substring(0, parentIndex);
const parentFieldName = fieldName.substring(0, parentIndex);
fieldsNamesPath.push(parentFieldName);
// Extract the child field name (e.g. someChild);
var childFieldName = fieldName.substring(parentIndex + 1);
const childFieldName = fieldName.substring(parentIndex + 1);
// Ensures that the parent exists in the payload.
var parentPayload = null;
const parentPayload = null;
if (payload.hasProp(parentFieldName)) {
parentPayload = payload.prop(parentFieldName);
}
setValuesFromPayload(parentPayload, childFieldName, fieldsNamesPath);
} else if (payload === null) {
// If parent does not exists just set null to the variable.
fieldsNamesPath = fieldsNamesPath.concat(
fieldName.split(INPUT_HIERARCHY_SEPARATOR)
fieldName.split(INPUT_HIERARCHY_SEPARATOR),
);
setVariableWithFullName(fieldsNamesPath, null);
} else {
// This means that the last field on the hierarchy was reached and
// the variable can be set.
var fieldValue = null;
const fieldValue = null;
if (payload.hasProp(fieldName)) {
var fieldProp = payload.prop(fieldName);
const fieldProp = payload.prop(fieldName);
if (fieldProp.isArray() || fieldProp.isObject()) {
fieldValue = fieldProp;
} else {
Expand All @@ -71,13 +71,13 @@ function setValuesFromPayload(payload, fieldName, fieldsNamesPath) {
* @param fieldValue value to be set.
*/
function setVariableWithFullName(fieldsNamesPath, fieldValue) {
var fullVariableName = fieldsNamesPath.join(OUTPUT_HIERARCHY_SEPARATOR);
const fullVariableName = fieldsNamesPath.join(OUTPUT_HIERARCHY_SEPARATOR);
connector.setVariable(fullVariableName, fieldValue);
}

// Script entry point that will iterate through all the variables requested to be created.
var fieldNames = connector.getVariable("fieldNames");
var output = S(connector.getVariable("response"));
for (var i = 0; i < fieldNames.length; i++) {
const fieldNames = connector.getVariable("fieldNames");
const output = S(connector.getVariable("response"));
for (let i = 0; i < fieldNames.length; i++) {
setValuesFromPayload(output, fieldNames[i], []);
}
10 changes: 5 additions & 5 deletions testing/src/uploadResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const TQ_USERNAME = process.env.TQ_USER_NAME;
const TQ_PASSWORD = process.env.TQ_PASSWORD;
const TQ_SECRET = process.env.TQ_SECRET;
const TQ_RUN_ID = process.env.TQ_RUN_ID; //( default id is 26606. Will need to change once we have integrated TQ account for the team)
const TQ_API_URL = 'https://api.testquality.com/api'
const TQ_API_URL = "https://api.testquality.com/api";

async function getAuthToken (): Promise<AxiosResponse<String>> {
async function getAuthToken(): Promise<AxiosResponse<String>> {
const auth_url = `${TQ_API_URL}/oauth/access_token`;
const body = {
grant_type: "password",
Expand All @@ -31,13 +31,13 @@ async function getAuthToken (): Promise<AxiosResponse<String>> {
console.error(error);
throw error;
}
};
}

async function uploadResultFile() {
const auth = await getAuthToken();
const url = `${TQ_API_URL}/plan/${TQ_RUN_ID}/junit_xml`;
var formData = new FormData();
var resultFile = fs.createReadStream("test-results.xml");
const formData = new FormData();
const resultFile = fs.createReadStream("test-results.xml");
formData.append("file", resultFile, "test-results.xml");
try {
const settings = {
Expand Down

0 comments on commit 6db3267

Please sign in to comment.