-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflows.js
70 lines (60 loc) · 1.7 KB
/
workflows.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs');
const Promise = require('bluebird');
const path = require('path');
const argv = require('minimist')(process.argv.slice(2));
const _ = require('underscore');
const os = require('os');
const xnat = require("./index.js");
const csvtojson = require("csvtojson");
const help = function(){
console.error("Workflow operations");
console.error("Usage: node", process.argv[1],"-csv <filename>");
console.error("Options:");
console.error("--csv <filename>, csv with column 'Workflow ID', you can get a file with the worflow ids if you go to your xnat instance at Administer->More->View All Workflows. You can export a spreadsheet with the Worflow Id");
console.error("--status <Complete,Queued,Failed>, all the workflows will be changed to this status");
}
if(!argv["csv"] || argv["h"] || argv["help"]){
help();
process.exit(1);
}
var csvfilename = argv["csv"];
var status = argv["status"];
if(!status){
status = "Complete";
}
const readCSV = function(filename){
var self = this;
return new Promise(function(resolve, reject){
var objarr = [];
csvtojson()
.fromFile(filename)
.on('json', function(jsonObj){
objarr.push(jsonObj);
})
.on('end', function(){
resolve(objarr);
})
.on('error', function(err){
reject(err);
})
});
}
xnat.start()
.then(function(){
return readCSV(csvfilename)
.then(function(csv){
return _.pluck(csv, "Workflow ID")
});
})
.then(function(res){
return Promise.map(res, function(workflowid){
return xnat.changeWorkflowStatus(workflowid, status);
})
})
.then(function(){
return xnat.logout();
})
.catch(function(e){
console.error(e);
return xnat.logout();
})