liveapicreator-admin-cli
Version:
The NodeJS command line utility for 'CA Live API Creator' DevOps Administration from CA Technologies
51 lines (48 loc) • 2 kB
JavaScript
var apicreator = require('caliveapicreator');
var fs = require('fs');
console.log(" ");
console.log("Node SDK - Import a CSV File and Create a new Table populated with these values");
var api = apicreator.connect('http://localhost:8080/APIServer/rest/default/csvparser/v1', 'demo', 'Password1');
var csvdefinition = api.endpoint('main:csvdefinition');
//default values below - change if needed
//"firstRowHasHeader": true,
//"haltOnFirstError": false,
//"columnDelim": ",",
//"useColumnMap": false,
//"project_url": "demo",
var csvdef = { "csvMapName": "ImportCLI-2", "tableName": "CLITestTable2", "Description": "Sample CLI Import", "project_url": "csvtables" , "prefix": "main" };
var filename = "./testcsv.csv";
var thePromise = csvdefinition.post(csvdef, {rulessummary: true});
thePromise.then(function (txSummary) {
console.log("procesing...");
console.log(txSummary); //an object which will include a transaction summary and a summary of the rules fired during this request
var data = txSummary.txsummary;
var header_ident = 0;
var ident = data[0].ident;
//upload the file
console.log("ident = "+ident);
////// UPLOAD THE FILE AS A BYTE ARRAY
fs.readFile(filename, function read(err,data){
if(err) {
console.log("Unable to read file");
return;
}
var base64 = "b64:"+new Buffer(data).toString('base64');
//console.log(base64);
var header = api.endpoint('main:csvheader');
var content = { "content": base64, "csv_ident": ident ,"@metadata": {"checksum":"override"}};
var promise = header.post(content, {});
promise.then(function(txSummary2){
var data2 = txSummary2.txsummary;
header_ident = data2[0].ident;
console.log(header_ident);
var procesCSV = { "genTableFlag": true, "ident": header_ident ,"@metadata": {"checksum":"override"}};
console.log(txSummary2);
var promiseGen = header.put(procesCSV, {});
promiseGen.then(function(txSummary3){
console.log(txSummary3);
});
});
});
});
console.log("done");