Skip to content

Commit

Permalink
feat: Added GetReportData function
Browse files Browse the repository at this point in the history
Added GetReportData function, changed api slightly, better error handling and fixed tests

BREAKING CHANGE: The main API changed (the way the jcognos object is exported.
  • Loading branch information
batje committed Mar 13, 2018
1 parent f860e84 commit 2786922
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 68 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ listFolderById - Lists the folder content by id

- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Cognos Object id of the folder
- `pattern` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** = '_' Pattern like you would use when listing folders in your filesystem. eg. 'Sales_' (optional, default `'*'`)
- `types` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** = '['folder']' Types of Cognos objects to list. defaults to folders only. Other values could be 'report' (optional, default `['folder']`)

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CognosObject](#cognosobject)>** List of sub-folders

Expand Down
71 changes: 57 additions & 14 deletions dist/jcognos.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ var CognosRequest = (function() {
}

try {
err.response.data.promptInfo.displayObjects.forEach(function(
item
) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
if (typeof err.response !== 'undefined') {
err.response.data.promptInfo.displayObjects.forEach(function(
item
) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
} else {
throw err.message;
}
} catch (error) {
me.error(error);
}
Expand Down Expand Up @@ -269,8 +273,21 @@ var CognosRequest = (function() {
return response;
})
.catch(function(err) {
var errormessage = '';
if (typeof err.response !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.message;
}

me.log('CognosRequest : Error in post', err);
me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand Down Expand Up @@ -439,6 +456,7 @@ var Cognos = (function() {
})
.catch(function(err) {
me.log('Cognos: Error when logging in.');
throw err;
});
return result;
}
Expand Down Expand Up @@ -528,6 +546,10 @@ var Cognos = (function() {
arguments.length > 1 && arguments[1] !== undefined
? arguments[1]
: '*';
var types =
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: ['folder'];

var me = this;
var result = me.requester
Expand All @@ -541,12 +563,15 @@ var Cognos = (function() {
folders.data.forEach(function(folder) {
if (minimatch(folder.defaultName, pattern)) {
me.log('folder ', folder.defaultName);

var tpFolder = {
name: folder.defaultName,
id: folder.id
};
result.push(tpFolder);
if (types.indexOf(folder.type) > -1) {
var tpFolder = {
name: folder.defaultName,
id: folder.id,
searchPath: folder.searchPath,
type: folder.type
};
result.push(tpFolder);
}
}
});
return result;
Expand Down Expand Up @@ -616,6 +641,24 @@ var Cognos = (function() {
return result;
}
},
{
key: 'getReportData',
value: function getReportData(id) {
var me = this;

var result = me.requester
.get(
'bi/v1/disp/rds/reportData/report/' +
id +
'?fmt=DataSetJSON&rowLimit=100'
)
.then(function(data) {
me.log('retrieved the data', data);
return data;
});
return result;
}
},
{
key: 'uploadExtension',
value: function uploadExtension(path, name) {
Expand Down
71 changes: 57 additions & 14 deletions dist/jcognos.js
Original file line number Diff line number Diff line change
Expand Up @@ -27955,14 +27955,18 @@ exports.inflateUndermine = inflateUndermine;
}

try {
err.response.data.promptInfo.displayObjects.forEach(function(
item
) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
if (typeof err.response !== 'undefined') {
err.response.data.promptInfo.displayObjects.forEach(function(
item
) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
} else {
throw err.message;
}
} catch (error) {
me.error(error);
}
Expand Down Expand Up @@ -28032,8 +28036,21 @@ exports.inflateUndermine = inflateUndermine;
return response;
})
.catch(function(err) {
var errormessage = '';
if (typeof err.response !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.message;
}

me.log('CognosRequest : Error in post', err);
me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand Down Expand Up @@ -29660,6 +29677,7 @@ exports.inflateUndermine = inflateUndermine;
})
.catch(function(err) {
me.log('Cognos: Error when logging in.');
throw err;
});
return result;
}
Expand Down Expand Up @@ -29749,6 +29767,10 @@ exports.inflateUndermine = inflateUndermine;
arguments.length > 1 && arguments[1] !== undefined
? arguments[1]
: '*';
var types =
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: ['folder'];

var me = this;
var result = me.requester
Expand All @@ -29762,12 +29784,15 @@ exports.inflateUndermine = inflateUndermine;
folders.data.forEach(function(folder) {
if (minimatch_1(folder.defaultName, pattern)) {
me.log('folder ', folder.defaultName);

var tpFolder = {
name: folder.defaultName,
id: folder.id
};
result.push(tpFolder);
if (types.indexOf(folder.type) > -1) {
var tpFolder = {
name: folder.defaultName,
id: folder.id,
searchPath: folder.searchPath,
type: folder.type
};
result.push(tpFolder);
}
}
});
return result;
Expand Down Expand Up @@ -29837,6 +29862,24 @@ exports.inflateUndermine = inflateUndermine;
return result;
}
},
{
key: 'getReportData',
value: function getReportData(id) {
var me = this;

var result = me.requester
.get(
'bi/v1/disp/rds/reportData/report/' +
id +
'?fmt=DataSetJSON&rowLimit=100'
)
.then(function(data) {
me.log('retrieved the data', data);
return data;
});
return result;
}
},
{
key: 'uploadExtension',
value: function uploadExtension(path, name) {
Expand Down
37 changes: 30 additions & 7 deletions src/Cognos.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Cognos {
})
.catch(function(err) {
me.log('Cognos: Error when logging in.');
throw err;
});
return result;
}
Expand Down Expand Up @@ -183,9 +184,10 @@ class Cognos {
*
* @param {String} id Cognos Object id of the folder
* @param {String} pattern = '*' Pattern like you would use when listing folders in your filesystem. eg. 'Sales*'
* @param {Array} types = '['folder']' Types of Cognos objects to list. defaults to folders only. Other values could be 'report'
* @return {CognosObject[]} List of sub-folders
*/
listFolderById(id, pattern = '*') {
listFolderById(id, pattern = '*', types = ['folder']) {
var me = this;
var result = me.requester
.get(
Expand All @@ -200,12 +202,15 @@ class Cognos {
// options is optional
if (minimatch(folder.defaultName, pattern)) {
me.log('folder ', folder.defaultName);

var tpFolder = {
name: folder.defaultName,
id: folder.id
};
result.push(tpFolder);
if (types.indexOf(folder.type) > -1) {
var tpFolder = {
name: folder.defaultName,
id: folder.id,
searchPath: folder.searchPath,
type: folder.type
};
result.push(tpFolder);
}
}
});
return result;
Expand Down Expand Up @@ -277,6 +282,24 @@ class Cognos {
return result;
}

getReportData(id) {
var me = this;
// Cognos 11
// https://srv06.gologic.eu/ibmcognos/bi/v1/disp/atom/cm/id/iD9D1A99B207B40D6AB25DB476C476E33?json=
// https://srv06.gologic.eu/ibmcognos/bi/v1/disp/rds/reportData/report/i821EB6721EDB41A29E0361BC83393C56?fmt=DataSet&rowLimit=2000
var result = me.requester
.get(
'bi/v1/disp/rds/reportData/report/' +
id +
'?fmt=DataSetJSON&rowLimit=100'
)
.then(function(data) {
me.log('retrieved the data', data);
return data;
});
return result;
}

/**
* uploadExtension - Uploads zipfile containing Cognos Extension. Only supports updating an existing module.
* This function is only supported by Node.js. In the browser this function returns false;
Expand Down
29 changes: 23 additions & 6 deletions src/CognosRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ class CognosRequest {

// Find the namespace in the body
try {
err.response.data.promptInfo.displayObjects.forEach(function(item) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
if (typeof err.response !== 'undefined') {
err.response.data.promptInfo.displayObjects.forEach(function(item) {
if (item.name == 'CAMNamespace') {
me.namespace = item.value;
me.log('Namespace: ' + me.namespace);
}
});
} else {
throw err.message;
}
} catch (error) {
me.error(error);
}
Expand Down Expand Up @@ -219,8 +223,21 @@ class CognosRequest {
return response;
})
.catch(function(err) {
var errormessage = '';
if (typeof err.response !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.message;
}

me.log('CognosRequest : Error in post', err);
me.error(err);
/*
* This happens when you didnt logout properly. It seems harmless.
*/
if (errormessage != 'AAA-AUT-0011 Invalid namespace was selected.') {
throw errormessage;
}
});
return result;
}
Expand Down
4 changes: 0 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//import axios from 'axios';

//window.axios = axios;

import { getCognos } from './Cognos.js';

export { getCognos };
Loading

0 comments on commit 2786922

Please sign in to comment.