Highlighted
Micro Focus Expert
Micro Focus Expert
71 views

ALM Octane nodejs API SDK mass update entities example

ALM Octane nodejs API SDK mass update entities example

In ALM Octane you can fill a workspace with sample data. This is useful for demo or playing around. If you want to experiment with the reports and dashboards for example you will need some data otherwise all reports are empty. 

The demo data is quite nice, but some fields are not filled. I was especially missing the priorities and severities. Also a bit annoying: The owners are all the same ("sa@nga" for all items in my case). So I did create this nodejs script to fill the sample project with some more random sample data (priorities, severities and owners). 

I am posting this here in case you want to do something similar or copy some ideas from the code. Maybe someone finds this useful. 

Usage

As a prerequisite you have to install the ALM Octane nodejs SDK (see my previous post) and copy / paste the sample code to a file. You will have to do some adjustments so that it matches your ALM Octane installation. Provide your connection details such as host, port, shared space id, workspace id, client id and secret in the code. 

Running the example

To run this example from command line simply use:

$ node demodata.js

 

Sample code

Here the nodejs code "demodata.js":

// Octane JSK SDK, see octane-api-installation-notes.txt on how to instal it
var Octane = require('@microfocus/hpe-alm-octane-js-rest-sdk')

var octane = new Octane({
protocol: "http",
host: "myoctane.mydomain.com",
port: "8080",
shared_space_id: "1001",
workspace_id: "1002",
//routesConfig: <ROUTES_CONFIG_FILE_PATH> | <ROUTES_CONFIG_JSON_OBJECT>
})

 

 

// Logon to ALM Octane api
octane.authenticate({

client_id: "<paste your id here>",
client_secret: "<paste your secret here including all special characters>"

}, function (err) {
if (err) {
console.log('API authenticate Error - %s', err.message)
return
}

// get all severities
octane.severities.getAll({}, function (err, severities) {
if (err) {
console.log('Severities getAll Error - %s', err.message)
return
}

// get all priorities
octane.priorities.getAll({}, function (err, priorities) {
if (err) {
console.log('Priorities getAll Error - %s', err.message)
return
}

// get all workspace users
octane.workspaceUsers.getAll({}, function (err, workspaceUsers) {
if (err) {
console.log('workspaceUsers getAll Error - %s', err.message)
return
}

// get all defects
octane.defects.getAll({}, function (err, defects) {
if (err) {
console.log('Defects getAll Error - %s', err.message)
return
}

// set new random severity if severity is empty
i = 0
var a = []
defects.forEach(function (defect) {
if (defect.severity == null) {
random_no = Math.floor((Math.random() * 5))
severity = severities[random_no]
a[i] = {id: defect.id, severity:{type:'list_node', id: severity.id}}
i = i + 1
}
})

// update all severities
octane.defects.updateBulk(a)

// set new random priority if priority is empty
i = 0
var b = []
defects.forEach(function (defect) {
if (defect.priority == null) {
random_no = Math.floor((Math.random() * 5))
priority = priorities[random_no]
b[i] = {id: defect.id, priority:{type:'list_node', id: priority.id}}
i = i + 1
}
})

// update all priorities
octane.defects.updateBulk(b)

// set random owners
i = 0
var u = []
defects.forEach(function (defect) {
if (defect.owner == null || defect.owner == "sa@nga") {
random_no = Math.floor((Math.random() * workspaceUsers.length))
workspace_user = workspaceUsers[random_no]
u[i] = {id: defect.id, owner:{type:'workspace_user', id: workspace_user.id}}
i = i + 1
}
})

// update all owners
octane.defects.updateBulk(u)

i = 0
var defect_author = []
defects.forEach(function (defect) {
if (defect.author = null || defect.author.id == 1001) {
console.log(defect)
random_no = Math.floor((Math.random() * workspaceUsers.length))
workspace_user = workspaceUsers[random_no]
defect_author[i] = {id: defect.id, detected_by:{type:'workspace_user', id: workspace_user.id}}
i = i + 1
}
})

// update all authors
octane.defects.updateBulk(defect_author)

})
})
})
})
})

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.