Skip to content

Conversation

@cx-apoorva-singh
Copy link
Contributor

Application Name mapping along with Id to Source Additional Info field of Discovered Application Table
Jira Link: [https://checkmarx.atlassian.net/browse/CXSER-889]

var uniqueAppIds = [];

// Collect all unique application IDs from relevant projects
for (var i = 0; i < projects.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional : var project = projects[i]; and var appId = appIds[j]; and then use project and appID as below.

var uniqueAppIds = [];

for (var i = 0; i < projects.length; i++) {
var project = projects[i];

if (project.createdAt > createdDate) {
    var appIds = project.applicationIds || [];

    for (var j = 0; j < appIds.length; j++) {
        var appId = appIds[j];

        if (uniqueAppIds.indexOf(appId) === -1) {
            uniqueAppIds.push(appId);
        }
    }
}

}

var appNameMap = this.UTIL.getApplicationMapName(this.IMPLEMENTATION, appIdParam);
}

for (var item in projects) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any chance that project will be null?

if (null != projects[item].applicationIds && projects[item].applicationIds.length > 0)
applicationIds = projects[item].applicationIds.toString();
// Build <applications> block
if (projects[item].applicationIds && projects[item].applicationIds.length > 0 && appIdParam && appIdParam.length > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: repeatedly using projects[item], which makes the code harder to read and maintain
Define a project variable once
var project = projects[item];

});
}
}
if (appList.length > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary check for appList.length, this can be achieve with below code as well.

for (var i = 0; i < appList.length; i++) {
...
}

// Make API call for the current 200 app IDs
var responseBody = this._makeRestApiCall(apibaseurl, configId, token, query, "get");
var body = responseBody.getBody();
var result = JSON.parse(body);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do the validation of body?

var applications = result.applications || [];

// Map application ID → Name
for (var k = 0; k < applications.length; k++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional : Can be replace with below.

applications.forEach(function(app) {
appNameMap[app.id] = app.name;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants