diff --git a/README.md b/README.md index 2500a5a..fc1e6fa 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,18 @@ module against Cognos Analytics 11.0.7 or later, follow these steps: - [Cognos](#cognos) - [Parameters](#parameters) + - [capabilities](#capabilities) + - [preferences](#preferences) + - [defaultNamespace](#defaultnamespace) + - [namespaces](#namespaces) - [login](#login) - [Parameters](#parameters-1) - [logoff](#logoff) - [reset](#reset) + - [getCognosVersion](#getcognosversion) + - [\_getPublicFolderId](#_getpublicfolderid) - [listRootFolder](#listrootfolder) + - [listPublicFolders](#listpublicfolders) - [listFolderById](#listfolderbyid) - [Parameters](#parameters-2) - [addFolder](#addfolder) @@ -72,6 +79,8 @@ module against Cognos Analytics 11.0.7 or later, follow these steps: - [Parameters](#parameters-6) - [CognosObject](#cognosobject) - [Properties](#properties) +- [NameSpace](#namespace) + - [Properties](#properties-1) - [cRequest](#crequest) - [isStandardBrowserEnv](#isstandardbrowserenv) - [isNode](#isnode) @@ -84,6 +93,31 @@ retrieve the Cognos instance. ### Parameters - `debug` +- `timeout` + +### capabilities + +capabilities - returns the Cognos User Capabilities object + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object with Capabilities + +### preferences + +preferences - returns the Cognos User Preferences, eg. timezone, skin, accessibiltity settings etc. + +Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object with Preferences + +### defaultNamespace + +defaultNamespace - returns the default namespace that jCognos will login to + +Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** id of the default namespace + +### namespaces + +namespaces - returns a list of possible namespaces, also when there is only 1 + +Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[NameSpace](#namespace)>** An array of objects describing the namespaces ### login @@ -93,6 +127,7 @@ login - Logs into Cognos. - `user` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Cognos username - `password` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Password +- `namespace` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Namespace (optional, default `CognosDefaultnamespaceorthenamespacethatistheonlynamespace`) Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns a promise. @@ -108,12 +143,30 @@ reset - Create a new connection Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** When resolved we are logged in +### getCognosVersion + +getCognosVersion - Fetches Cognos Product Version + +Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** The promise resolves to a string that holds the version number + +### \_getPublicFolderId + +\_getPublicFolderId - Internal function to retrieve the ObjectId of the public folders + +Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise that results in an id as {String}. + ### listRootFolder listRootFolder - Returns the Public Folders and the My Content Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CognosObject](#cognosobject)>** Array of CognosObjects +### listPublicFolders + +listPublicFolders - List content of the Public Folders + +Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CognosObject](#cognosobject)>** List of sub-folders + ### listFolderById listFolderById - Lists the folder content by id @@ -156,10 +209,11 @@ This function is only supported by Node.js. In the browser this function returns #### Parameters -- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to the .zip file +- `filename` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to the .zip file - `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the module (as found in the spec.json) +- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of upload. Default is 'extensions', for themes use 'themes'. (optional, default `'extensions'`) -Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Whatever JSON Cognos returns +Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise that resolves to a string. ### loggedin @@ -174,10 +228,12 @@ at any time. ### Parameters -- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The URL of your Cognos installation -- `debug` (optional, default `false`) +- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The URL of your Cognos installation. If empty, this function becomes static and a Promise for the current jCognos object is returned. (optional, default `false`) +- `debug` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true, starts debugging into the console (optional, default `false`) +- `timeout` (optional, default `60000`) +- `Timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value for http(s) connections. In milliseconds. Default is 60000. -Returns **[Cognos](#cognos)** The Cognos object +Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** a promise that will return the jCognos object ## CognosObject @@ -188,6 +244,16 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa - `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Cognos Object Id - `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of object. +## NameSpace + +Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) + +### Properties + +- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The id of the namespace +- `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Displayname of the NameSpace +- `isDefault` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Set to true if this is the default namespace + ## cRequest Local Variable that holds the single CognosRequest instance diff --git a/dist/jcognos.cjs.js b/dist/jcognos.cjs.js index bbbdddf..3a78760 100644 --- a/dist/jcognos.cjs.js +++ b/dist/jcognos.cjs.js @@ -173,7 +173,7 @@ var CognosRequest = (function() { withCredentials: false, headers: firstheaders }) - .then(function(body) { + .then(function() { me.log('Unexpected success'); return me; }) @@ -210,11 +210,11 @@ var CognosRequest = (function() { cookieJar.setCookie( 'XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { cookieJar.setCookie( 'X-XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { me.cookies = cookieJar; } ); @@ -426,11 +426,20 @@ var CognosRequest = (function() { }) .catch(function(err) { var errormessage = ''; - me.error('CognosRequest : Error in delete', err); if (typeof err.response !== 'undefined') { + if (err.response.status === 441) { + errormessage = 'Access Denied'; + } + if (typeof err.response.data.messages !== 'undefined') { - errormessage = err.response.data.messages[0].messageString; + if (err.response.data.messages.length > 0) { + errormessage = err.response.data.messages[0].messageString; + } else { + if (err.response.data.errorCodeString) { + errormessage = err.response.data.errorCodeString; + } + } } else { errormessage = err.response.data; } @@ -700,6 +709,7 @@ var Cognos = (function() { this.username = ''; this.password = ''; this.timeout = timeout; + this.productVersion = ''; this.capabilities = {}; this.preferences = {}; this.defaultNamespace = ''; @@ -783,7 +793,7 @@ var Cognos = (function() { }; this.loginrequest = me.requester .post('bi/v1/login', params) - .then(function(body) { + .then(function() { me.loggedin = true; me.username = user; me.password = password; @@ -801,11 +811,11 @@ var Cognos = (function() { me.preferences = prefs; return prefs; }); - me.log('Successfully logged in'); + console.log('Successfully logged in'); return Promise.all([capabilities, preferences]); - return body; }) .then(function() { + console.log('surely logged in'); return me; }) .catch(function(err) { @@ -825,11 +835,11 @@ var Cognos = (function() { .delete('bi/v1/login') .then(function(body) { me.loggedin = false; - me.log('Successfully logged off'); + console.log('Successfully logged off'); return body; }) .catch(function(err) { - me.log('Cognos: Error when logging off.'); + me.log('Cognos: Error when logging off.', err); }); return result; } @@ -844,14 +854,14 @@ var Cognos = (function() { throw err; } - if (err.response.status == 441 || err.response.status == 403) { - me.log('going to reset'); - var result = me.reset(); - me.log('in handleError, returning promise', result); - return result; - } - if (typeof err.response !== 'undefined') { + if (err.response.status == 441 || err.response.status == 403) { + me.log('going to reset'); + var result = me.reset(); + me.log('in handleError, returning promise', result); + return result; + } + if (typeof err.response.data.messages !== 'undefined') { errormessage = err.response.data.messages[0].messageString; } else { @@ -919,12 +929,71 @@ var Cognos = (function() { return this.resetting; } }, + { + key: 'getCognosVersion', + value: function getCognosVersion() { + var me = this; + + if (this.productVersion !== '') { + return Promise.resolve(me.productVersion); + } + + var url = 'bi/v1/configuration/keys/Glass.productVersion'; + var result = me.requester + .get(url) + .then(function(version) { + me.productVersion = version['Glass.productVersion']; + console.log('version ' + me.productVersion); + return me.productVersion; + }) + .catch(function(err) { + me.error('Error while fetching Cognos Version.', err); + throw err; + }); + return result; + } + }, + { + key: '_getPublicFolderId', + value: function _getPublicFolderId() { + var me = this; + var url = ''; + return this.getCognosVersion().then(function(version) { + if (version.substr(0, 4) == '11.1') { + url = 'bi/v1/disp/icd/feeds/cm/?dojo='; + me.log('We are version 11. Going to fetch: ' + url); + } else { + url = 'bi/v1/objects/.public_folders?fields=permissions'; + } + + console.log(url); + var result = me.requester + .get(url) + .then(function(folders) { + var id; + + if (version.substr(0, 4) == '11.1') { + folders = eval('(' + folders + ')'); + id = folders.items[0].entry[2].cm$storeID; + } else { + id = folders.data[0].id; + } + + return id; + }) + .catch(function(err) { + console.error('There was an error fetching the folder id', err); + }); + return result; + }); + } + }, { key: 'listRootFolder', value: function listRootFolder() { var me = this; var rootfolders = []; - var result = me.requester + return me.requester .get('bi/v1/objects/.my_folders?fields=permissions') .then(function(folders) { me.log('Got the Private Folders'); @@ -937,20 +1006,18 @@ var Cognos = (function() { } }) .then(function() { - return me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - me.log('Got the Public Folders'); - - if (typeof folders !== 'undefined') { - rootfolders.push({ - id: folders.data[0].id, - name: 'Team Content' - }); - } + return me._getPublicFolderId().then(function(id) { + me.log('Got the Public Folders'); - return rootfolders; - }); + if (typeof id !== 'undefined') { + rootfolders.push({ + id: id, + name: 'Team Content' + }); + } + + return rootfolders; + }); }) .catch(function(err) { me.error('CognosRequest : Error in listRootFolder', err); @@ -960,22 +1027,22 @@ var Cognos = (function() { me.resetting = false; return me.listRootFolder(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); - return result; } }, { key: 'listPublicFolders', value: function listPublicFolders() { var me = this; - var result = me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - if (typeof folders !== 'undefined') { - return me.listFolderById(folders.data[0].id); + + var result = me + ._getPublicFolderId() + .then(function(id) { + if (typeof id !== 'undefined') { + return me.listFolderById(id); } return {}; @@ -988,10 +1055,11 @@ var Cognos = (function() { me.resetting = false; return me.listPublicFolders(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + return result; } }, @@ -1045,7 +1113,7 @@ var Cognos = (function() { me.resetting = false; return me.listFolderById(id, pattern, types); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -1085,7 +1153,7 @@ var Cognos = (function() { me.resetting = false; return me.addFolder(parentid, name); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -1111,8 +1179,8 @@ var Cognos = (function() { }; var result = me.requester .delete('bi/v1/objects/' + id, params, true) - .then(function(response) { - me.log('deleted folder'); + .then(function() { + me.log('Deleted folder'); return true; }) .catch(function(err) { @@ -1124,10 +1192,11 @@ var Cognos = (function() { me.resetting = false; return me.deleteFolder(id, force, recursive); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + me.log('Returning Delete Promise'); return result; } }, @@ -1169,7 +1238,7 @@ var Cognos = (function() { me.resetting = false; return me.getReportData(id, prompts, limit); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); diff --git a/dist/jcognos.esm.js b/dist/jcognos.esm.js index 0c05382..18e1662 100644 --- a/dist/jcognos.esm.js +++ b/dist/jcognos.esm.js @@ -165,7 +165,7 @@ var CognosRequest = (function() { withCredentials: false, headers: firstheaders }) - .then(function(body) { + .then(function() { me.log('Unexpected success'); return me; }) @@ -202,11 +202,11 @@ var CognosRequest = (function() { cookieJar.setCookie( 'XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { cookieJar.setCookie( 'X-XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { me.cookies = cookieJar; } ); @@ -418,11 +418,20 @@ var CognosRequest = (function() { }) .catch(function(err) { var errormessage = ''; - me.error('CognosRequest : Error in delete', err); if (typeof err.response !== 'undefined') { + if (err.response.status === 441) { + errormessage = 'Access Denied'; + } + if (typeof err.response.data.messages !== 'undefined') { - errormessage = err.response.data.messages[0].messageString; + if (err.response.data.messages.length > 0) { + errormessage = err.response.data.messages[0].messageString; + } else { + if (err.response.data.errorCodeString) { + errormessage = err.response.data.errorCodeString; + } + } } else { errormessage = err.response.data; } @@ -692,6 +701,7 @@ var Cognos = (function() { this.username = ''; this.password = ''; this.timeout = timeout; + this.productVersion = ''; this.capabilities = {}; this.preferences = {}; this.defaultNamespace = ''; @@ -775,7 +785,7 @@ var Cognos = (function() { }; this.loginrequest = me.requester .post('bi/v1/login', params) - .then(function(body) { + .then(function() { me.loggedin = true; me.username = user; me.password = password; @@ -793,11 +803,11 @@ var Cognos = (function() { me.preferences = prefs; return prefs; }); - me.log('Successfully logged in'); + console.log('Successfully logged in'); return Promise.all([capabilities, preferences]); - return body; }) .then(function() { + console.log('surely logged in'); return me; }) .catch(function(err) { @@ -817,11 +827,11 @@ var Cognos = (function() { .delete('bi/v1/login') .then(function(body) { me.loggedin = false; - me.log('Successfully logged off'); + console.log('Successfully logged off'); return body; }) .catch(function(err) { - me.log('Cognos: Error when logging off.'); + me.log('Cognos: Error when logging off.', err); }); return result; } @@ -836,14 +846,14 @@ var Cognos = (function() { throw err; } - if (err.response.status == 441 || err.response.status == 403) { - me.log('going to reset'); - var result = me.reset(); - me.log('in handleError, returning promise', result); - return result; - } - if (typeof err.response !== 'undefined') { + if (err.response.status == 441 || err.response.status == 403) { + me.log('going to reset'); + var result = me.reset(); + me.log('in handleError, returning promise', result); + return result; + } + if (typeof err.response.data.messages !== 'undefined') { errormessage = err.response.data.messages[0].messageString; } else { @@ -911,12 +921,71 @@ var Cognos = (function() { return this.resetting; } }, + { + key: 'getCognosVersion', + value: function getCognosVersion() { + var me = this; + + if (this.productVersion !== '') { + return Promise.resolve(me.productVersion); + } + + var url = 'bi/v1/configuration/keys/Glass.productVersion'; + var result = me.requester + .get(url) + .then(function(version) { + me.productVersion = version['Glass.productVersion']; + console.log('version ' + me.productVersion); + return me.productVersion; + }) + .catch(function(err) { + me.error('Error while fetching Cognos Version.', err); + throw err; + }); + return result; + } + }, + { + key: '_getPublicFolderId', + value: function _getPublicFolderId() { + var me = this; + var url = ''; + return this.getCognosVersion().then(function(version) { + if (version.substr(0, 4) == '11.1') { + url = 'bi/v1/disp/icd/feeds/cm/?dojo='; + me.log('We are version 11. Going to fetch: ' + url); + } else { + url = 'bi/v1/objects/.public_folders?fields=permissions'; + } + + console.log(url); + var result = me.requester + .get(url) + .then(function(folders) { + var id; + + if (version.substr(0, 4) == '11.1') { + folders = eval('(' + folders + ')'); + id = folders.items[0].entry[2].cm$storeID; + } else { + id = folders.data[0].id; + } + + return id; + }) + .catch(function(err) { + console.error('There was an error fetching the folder id', err); + }); + return result; + }); + } + }, { key: 'listRootFolder', value: function listRootFolder() { var me = this; var rootfolders = []; - var result = me.requester + return me.requester .get('bi/v1/objects/.my_folders?fields=permissions') .then(function(folders) { me.log('Got the Private Folders'); @@ -929,20 +998,18 @@ var Cognos = (function() { } }) .then(function() { - return me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - me.log('Got the Public Folders'); - - if (typeof folders !== 'undefined') { - rootfolders.push({ - id: folders.data[0].id, - name: 'Team Content' - }); - } + return me._getPublicFolderId().then(function(id) { + me.log('Got the Public Folders'); - return rootfolders; - }); + if (typeof id !== 'undefined') { + rootfolders.push({ + id: id, + name: 'Team Content' + }); + } + + return rootfolders; + }); }) .catch(function(err) { me.error('CognosRequest : Error in listRootFolder', err); @@ -952,22 +1019,22 @@ var Cognos = (function() { me.resetting = false; return me.listRootFolder(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); - return result; } }, { key: 'listPublicFolders', value: function listPublicFolders() { var me = this; - var result = me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - if (typeof folders !== 'undefined') { - return me.listFolderById(folders.data[0].id); + + var result = me + ._getPublicFolderId() + .then(function(id) { + if (typeof id !== 'undefined') { + return me.listFolderById(id); } return {}; @@ -980,10 +1047,11 @@ var Cognos = (function() { me.resetting = false; return me.listPublicFolders(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + return result; } }, @@ -1037,7 +1105,7 @@ var Cognos = (function() { me.resetting = false; return me.listFolderById(id, pattern, types); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -1077,7 +1145,7 @@ var Cognos = (function() { me.resetting = false; return me.addFolder(parentid, name); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -1103,8 +1171,8 @@ var Cognos = (function() { }; var result = me.requester .delete('bi/v1/objects/' + id, params, true) - .then(function(response) { - me.log('deleted folder'); + .then(function() { + me.log('Deleted folder'); return true; }) .catch(function(err) { @@ -1116,10 +1184,11 @@ var Cognos = (function() { me.resetting = false; return me.deleteFolder(id, force, recursive); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + me.log('Returning Delete Promise'); return result; } }, @@ -1161,7 +1230,7 @@ var Cognos = (function() { me.resetting = false; return me.getReportData(id, prompts, limit); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); diff --git a/dist/jcognos.js b/dist/jcognos.js index a217725..44b8413 100644 --- a/dist/jcognos.js +++ b/dist/jcognos.js @@ -14,7 +14,7 @@ : typeof define === 'function' && define.amd ? define(['exports'], factory) : factory((global.jcognos = {})); -})(this, function(exports) { +})(typeof self !== 'undefined' ? self : this, function(exports) { 'use strict'; function _classCallCheck(instance, Constructor) { @@ -16519,7 +16519,7 @@ withCredentials: false, headers: firstheaders }) - .then(function(body) { + .then(function() { me.log('Unexpected success'); return me; }) @@ -16556,11 +16556,11 @@ cookieJar.setCookie( 'XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { cookieJar.setCookie( 'X-XSRF-TOKEN=' + me.token, cookieurl, - function(err, cookje) { + function() { me.cookies = cookieJar; } ); @@ -16772,11 +16772,20 @@ }) .catch(function(err) { var errormessage = ''; - me.error('CognosRequest : Error in delete', err); if (typeof err.response !== 'undefined') { + if (err.response.status === 441) { + errormessage = 'Access Denied'; + } + if (typeof err.response.data.messages !== 'undefined') { - errormessage = err.response.data.messages[0].messageString; + if (err.response.data.messages.length > 0) { + errormessage = err.response.data.messages[0].messageString; + } else { + if (err.response.data.errorCodeString) { + errormessage = err.response.data.errorCodeString; + } + } } else { errormessage = err.response.data; } @@ -17272,7 +17281,6 @@ if (start < 0) start = str.length + start; return str.substr(start, len); }; - var concatMap = function(xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { @@ -18492,6 +18500,7 @@ this.username = ''; this.password = ''; this.timeout = timeout; + this.productVersion = ''; this.capabilities = {}; this.preferences = {}; this.defaultNamespace = ''; @@ -18575,7 +18584,7 @@ }; this.loginrequest = me.requester .post('bi/v1/login', params) - .then(function(body) { + .then(function() { me.loggedin = true; me.username = user; me.password = password; @@ -18593,11 +18602,11 @@ me.preferences = prefs; return prefs; }); - me.log('Successfully logged in'); + console.log('Successfully logged in'); return Promise.all([capabilities, preferences]); - return body; }) .then(function() { + console.log('surely logged in'); return me; }) .catch(function(err) { @@ -18617,11 +18626,11 @@ .delete('bi/v1/login') .then(function(body) { me.loggedin = false; - me.log('Successfully logged off'); + console.log('Successfully logged off'); return body; }) .catch(function(err) { - me.log('Cognos: Error when logging off.'); + me.log('Cognos: Error when logging off.', err); }); return result; } @@ -18636,14 +18645,14 @@ throw err; } - if (err.response.status == 441 || err.response.status == 403) { - me.log('going to reset'); - var result = me.reset(); - me.log('in handleError, returning promise', result); - return result; - } - if (typeof err.response !== 'undefined') { + if (err.response.status == 441 || err.response.status == 403) { + me.log('going to reset'); + var result = me.reset(); + me.log('in handleError, returning promise', result); + return result; + } + if (typeof err.response.data.messages !== 'undefined') { errormessage = err.response.data.messages[0].messageString; } else { @@ -18711,12 +18720,71 @@ return this.resetting; } }, + { + key: 'getCognosVersion', + value: function getCognosVersion() { + var me = this; + + if (this.productVersion !== '') { + return Promise.resolve(me.productVersion); + } + + var url = 'bi/v1/configuration/keys/Glass.productVersion'; + var result = me.requester + .get(url) + .then(function(version) { + me.productVersion = version['Glass.productVersion']; + console.log('version ' + me.productVersion); + return me.productVersion; + }) + .catch(function(err) { + me.error('Error while fetching Cognos Version.', err); + throw err; + }); + return result; + } + }, + { + key: '_getPublicFolderId', + value: function _getPublicFolderId() { + var me = this; + var url = ''; + return this.getCognosVersion().then(function(version) { + if (version.substr(0, 4) == '11.1') { + url = 'bi/v1/disp/icd/feeds/cm/?dojo='; + me.log('We are version 11. Going to fetch: ' + url); + } else { + url = 'bi/v1/objects/.public_folders?fields=permissions'; + } + + console.log(url); + var result = me.requester + .get(url) + .then(function(folders) { + var id; + + if (version.substr(0, 4) == '11.1') { + folders = eval('(' + folders + ')'); + id = folders.items[0].entry[2].cm$storeID; + } else { + id = folders.data[0].id; + } + + return id; + }) + .catch(function(err) { + console.error('There was an error fetching the folder id', err); + }); + return result; + }); + } + }, { key: 'listRootFolder', value: function listRootFolder() { var me = this; var rootfolders = []; - var result = me.requester + return me.requester .get('bi/v1/objects/.my_folders?fields=permissions') .then(function(folders) { me.log('Got the Private Folders'); @@ -18729,20 +18797,18 @@ } }) .then(function() { - return me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - me.log('Got the Public Folders'); - - if (typeof folders !== 'undefined') { - rootfolders.push({ - id: folders.data[0].id, - name: 'Team Content' - }); - } + return me._getPublicFolderId().then(function(id) { + me.log('Got the Public Folders'); - return rootfolders; - }); + if (typeof id !== 'undefined') { + rootfolders.push({ + id: id, + name: 'Team Content' + }); + } + + return rootfolders; + }); }) .catch(function(err) { me.error('CognosRequest : Error in listRootFolder', err); @@ -18752,22 +18818,22 @@ me.resetting = false; return me.listRootFolder(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); - return result; } }, { key: 'listPublicFolders', value: function listPublicFolders() { var me = this; - var result = me.requester - .get('bi/v1/objects/.public_folders?fields=permissions') - .then(function(folders) { - if (typeof folders !== 'undefined') { - return me.listFolderById(folders.data[0].id); + + var result = me + ._getPublicFolderId() + .then(function(id) { + if (typeof id !== 'undefined') { + return me.listFolderById(id); } return {}; @@ -18780,10 +18846,11 @@ me.resetting = false; return me.listPublicFolders(); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + return result; } }, @@ -18837,7 +18904,7 @@ me.resetting = false; return me.listFolderById(id, pattern, types); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -18877,7 +18944,7 @@ me.resetting = false; return me.addFolder(parentid, name); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); @@ -18903,8 +18970,8 @@ }; var result = me.requester .delete('bi/v1/objects/' + id, params, true) - .then(function(response) { - me.log('deleted folder'); + .then(function() { + me.log('Deleted folder'); return true; }) .catch(function(err) { @@ -18916,10 +18983,11 @@ me.resetting = false; return me.deleteFolder(id, force, recursive); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); + me.log('Returning Delete Promise'); return result; } }, @@ -18961,7 +19029,7 @@ me.resetting = false; return me.getReportData(id, prompts, limit); }) - .catch(function(rejecterr) { + .catch(function() { throw err; }); }); diff --git a/docs/assets/split.js b/docs/assets/split.js index 2c52481..5357e1d 100644 --- a/docs/assets/split.js +++ b/docs/assets/split.js @@ -6,8 +6,8 @@ typeof exports === 'object' && typeof module !== 'undefined' ? (module.exports = factory()) : typeof define === 'function' && define.amd - ? define(factory) - : (global.Split = factory()); + ? define(factory) + : (global.Split = factory()); })(this, function() { 'use strict'; // The programming goals of Split.js are to deliver readable, understandable and @@ -219,8 +219,8 @@ var b = elements[this.b]; var percentage = a.size + b.size; - a.size = offset / this.size * percentage; - b.size = percentage - offset / this.size * percentage; + a.size = (offset / this.size) * percentage; + b.size = percentage - (offset / this.size) * percentage; setElementSize(a.element, a.size, this.aGutterSize); setElementSize(b.element, b.size, this.bGutterSize); diff --git a/docs/index.html b/docs/index.html index 3b3586e..2fb89b8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -91,12 +91,30 @@
_getPublicFolderId - Internal function to retrieve the ObjectId of the public folders
+ + + +Promise
:
+ Promise that results in an id as {String}.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
listPublicFolders - List content of the Public Folders
+ + + +Array<CognosObject>
:
+ List of sub-folders
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1309,21 +1495,14 @@
(String)
- : The id of the namespace
-
-
- (String)
- : Displayname of the NameSpace
+ : Cognos Object Id
(Boolean)
- : Set to true if this is the default namespace
+ name (String)
+ : Name of object.
@@ -1387,14 +1566,21 @@
(String)
- : Cognos Object Id
+ : The id of the namespace
(Boolean)
+ : Set to true if this is the default namespace