AJAXUtils.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2016, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8.  */
  9. define([], function () {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var _singletonInstance = null;
  12. var ajaxURLS = {
  13. 'ldapStatus': 'ads_state',
  14. 'namespace': 'namespaces',
  15. 'datasources': 'datasources',
  16. 'test': 'datasourceconnection/test',
  17. 'testWithConn': 'datasourceconnection/test_with_credential',
  18. 'tenants': 'tenants'
  19. };
  20. var AJAXUtils = function AJAXUtils() {
  21. if (AJAXUtils.prototype._singletonInstance) {
  22. return AJAXUtils.prototype._singletonInstance;
  23. }
  24. };
  25. /*
  26. * returns the url assoicated with key
  27. */
  28. AJAXUtils.prototype.getAJAXURL = function (key) {
  29. return 'v1/' + ajaxURLS[key];
  30. };
  31. /*
  32. * returns a full rest url built from the partial one provided
  33. */
  34. AJAXUtils.prototype.getURL = function (partialURL) {
  35. return 'v1/' + partialURL;
  36. };
  37. /**
  38. * parse a friendly error message from response text
  39. */
  40. AJAXUtils.prototype._parseErrorMsg = function (response) {
  41. var result = "";
  42. if (response.responseJSON.messages !== undefined) {
  43. result = response.responseJSON.messages.join('\n');
  44. } else if (response.responseJSON.errors[0].messages !== undefined) {
  45. result = response.responseJSON.errors[0].messages.join('\n');
  46. }
  47. return result;
  48. };
  49. /*
  50. * Gets a url based on the static key and arguments passed in
  51. *
  52. * @param {String} req - the requested path, usually indicated by the name of the action
  53. * @optional {String} id - only required for some paths, which specifies the id or pid of an object
  54. */
  55. AJAXUtils.prototype.getPath = function (req, id) {
  56. //NOSONAR
  57. var urls = {
  58. /*
  59. * CONTENT MANAGER API CALLS
  60. */
  61. //(GET) Get all users/groups/roles based on search type, handler found in AccountAppService, lines 857 - 865
  62. 'contentManagerSearch': '/cmsearch',
  63. /*
  64. * DISK USAGE API CALLS
  65. */
  66. //(GET) Get disk usage, handler found in DiskUsageResource.java
  67. 'getDiskUsage': '/disk_usage',
  68. /*
  69. * DEPLOYMENT RESOURCE - EXPORTS
  70. */
  71. //(GET) Get all export specs, handler found in AccountAppService, lines 873 - 881
  72. 'getExports': '/exports',
  73. //(GET) Get an export spec, handler found in AccountAppService, lines 883 - 889
  74. 'getExport': '/exports/' + id,
  75. //(GET) Get an exporting status, handler found in AccountAppService, lines 891 - 897
  76. 'getExportStatus': '/exports/' + id + '/status',
  77. //(PUT) Import an export spec, handler found in AccountAppService, lines 907 - 913
  78. 'importExportSpec': '/exports/' + id + '/run',
  79. //(POST) Create new export spec, handler found in AccountAppService, lines 899 - 905
  80. 'createExport': '/exports',
  81. //(DELETE) Delete an export spec, handler found in AccountAppService, lines 915 - 921
  82. 'deleteExport': '/exports/' + id,
  83. /*
  84. * DEPLOYMENT RESOURCE - IMPORTS
  85. */
  86. //(GET) Get all import specs, handler found in AccountAppService, lines 930 - 938
  87. 'getImports': '/imports',
  88. //(GET) Get an import spec, handler found in AccountAppService, lines 940 - 946
  89. 'getImport': '/imports/' + id,
  90. //(GET) Get an importing status, handler found in AccountAppService, lines 948 - 954
  91. 'getImportStatus': '/imports/' + id + '/status',
  92. //(PUT) Import an import spec, handler found in AccountAppService, lines 964 - 970
  93. 'importImportSpec': '/imports/' + id + '/run',
  94. //(POST) Create new export spec, handler found in AccountAppService, lines 956 - 962
  95. 'createImport': '/imports',
  96. //(DELETE) Delete an export spec, handler found in AccountAppService, lines 972 - 978
  97. 'deleteImport': '/imports/' + id,
  98. /*
  99. * FILE UPLOAD API
  100. */
  101. //(POST) Upload a csv format file to create users, handler found in AccountAppService, lines 800 - 811
  102. 'uploadFile': '/uploadfile',
  103. /*
  104. * GROUPS API CALLS
  105. */
  106. //(GET) Get capabilities of group based on its storeid, handler found in GroupsResource, lines 45 - 57
  107. 'getGroupCapabilities': '/groups/' + id + '/capabilities',
  108. //(GET) Get license level of a group based on its capability assignments, handler found in GroupsResource, lines 59 - 71
  109. 'getGroupLicense': '/groups/' + id + '/license',
  110. //(GET) Get all groups in cm, handler found in AccountAppService, lines 573 - 579
  111. 'getGroups': '/groups',
  112. //(GET) Get a group from cm based on id, handler found in AccountAppService.java
  113. 'getGroup': '/groups/' + id,
  114. //(GET) Get all group members in cm based on its storeid, handler found in AccountAppService, lines 621 - 628
  115. 'getGroupMembers': '/groups/' + id + '/members',
  116. //(GET) Get all groups and roles that contain the group with given id, handler found in AccountAppService, lines 835 - 841
  117. 'getObjectsWithGroup': '/groups/' + id + '/memberof',
  118. //(POST) Creates a group in cm, handler found in AccountAppService, lines 598 - 611
  119. 'createGroup': '/groups?pid=' + id,
  120. //(POST) Add members to a group in cm with the given id, lines 630 - 668
  121. 'addGroupMembers': '/groups/' + id + '/members',
  122. //(PUT) Remove members from a group with the given id, handler found in AccountAppService, lines 670 - 707
  123. 'removeGroupMembers': '/groups/' + id + '/members',
  124. //(PUT) Update a group in cm, handler found in content-service
  125. /*
  126. * NOTE: This API call uses the content-service API, since its admin-service counterpart
  127. * is not behaving properly, this will be switched back to the admin API once changes have
  128. * been pushed in the future
  129. */
  130. 'updateGroup': '/objects/' + id,
  131. //(DELETE) Delete a group in cm found by storeid, handler found in AccountAppService, lines 613 - 619
  132. 'deleteGroup': '/objects/' + id,
  133. /*
  134. * LICENSES API CALLS
  135. */
  136. //(GET) Returns summary information of license use, handler found in LicensesResource, lines 79 - 103
  137. 'getLicenseUse': '/licenses',
  138. //(GET) Get current license status, handler found in LicenseResource
  139. 'getLicenseStatus': '/license',
  140. //(PUT) Update owned license count, handler found in LicensesResource, lines 125 - 150
  141. 'updateLicenseCount': '/licenses/owned',
  142. //(PUT) Switch to another valid license status, handler found in LicenseResource
  143. 'switchLicenseStatus': '/license',
  144. //(POST) Refresh license calculations, handler found in LicensesResource, lines 105 - 123
  145. 'refreshLicenses': '/licenses',
  146. /*
  147. * NAMESPACE API CALLS
  148. */
  149. //(GET) Search descendants of specified namespace location, handler found in NamespaceSearchResource, lines 52 - 78
  150. 'namespaceSearch': '/namespaces/' + id + '/search',
  151. //(GET) Get all namesapces, handler found in AccountAppService, lines 315 - 323
  152. 'getNamespaces': '/namespaces/',
  153. //(GET) Get a namespace based on its storeid, handler found in AccountAppService, lines 325 - 331
  154. 'getNamespace': '/namespaces/' + id,
  155. //(GET) Get all items of a namespace based on its storeid, handler found in AccountAppService, lines 350 - 363
  156. 'getNamesapceItems': '/namespaces/' + id + '/items',
  157. //(POST) Creates a namespace
  158. 'createNamespace': '/namespace?pid=' + id,
  159. //(PUT) Update a namespace, handler found in AccountAppService, lines 333 - 348
  160. 'updateNamespace': '/objects/' + id,
  161. /*
  162. * NAMESPACE FOLDER API CALLS
  163. */
  164. //(GET) Get all first level folders, handler found in AccountAppService, lines 712 - 725
  165. 'getNamespaceFolders': '/folders',
  166. //(GET) Get specific first level folder based on storeid, handler found in AccountAppService, lines 727 - 738
  167. 'getNamespaceFolder': '/folders/' + id,
  168. //(GET) Get all items in a folder based on folder storeid, handler found in AccountAppService, lines 740 - 752
  169. 'getNamespaceFolderItems': '/folders' + id + '/items',
  170. //(POST) Create a namespace folder, handler found in AccountAppService, lines 754 - 766
  171. 'createNamespaceFolder': '/folders?pid=' + id,
  172. //(PUT) Update a folder based on its storeid, handler found in AccountAppService, lines 776 - 791
  173. 'updateNamespaceFolder': '/folders/' + id,
  174. //(DELETE) Delete a namespace folder, handler found in AccountAppService, lines 768 - 774
  175. //NOTE: This path is confusing, as /folders/ actually represents the pathing for nameSpaceFolders
  176. //this should be patched in a future update to the API
  177. 'deleteNamespaceFolder': '/folders/' + id,
  178. /*
  179. * PRINTER API CALLS
  180. */
  181. //(GET) Get all printers under system, handler found in AccountAppService, lines 368 - 376
  182. 'getPrinters': '/system/printers',
  183. //(GET) Get the printer under a system specified by id, handler found in AccountAppService, lines 378 - 384
  184. 'getPrinter': '/systems/printers/' + id,
  185. /*
  186. * ROLES AND USER PROFILE SETTINGS CALLS
  187. */
  188. //(GET) Get all roles, handler found in AccountAppService, lines 174 - 188
  189. 'getRoles': '/roles/',
  190. //(GET) Get capabilities of a role based on its storeid, handler found in AccountAppService, lines 190 - 196
  191. 'getRoleCapabilities': '/roles/' + id + '/capabilities',
  192. //(GET) Get members of role based on its storeid, handler found in AccountAppService, lines 223 - 229
  193. 'getRoleMembers': '/roles/' + id + '/members',
  194. //(GET) Get license level of a role based on its capability assignments, handler found in RolesResource, lines 61 - 73
  195. 'getRoleLicense': '/roles/' + id + '/license',
  196. //(GET) Get user profile settings of a role, handler found in UserProfuleSettings.java
  197. 'getUserProfileSettings': '/roles/' + id + '/user_profile_settings',
  198. //(GET) Get a role based on its storeId, handler found in AccountAppService, lines 190 - 196
  199. 'getRole': '/roles/' + id,
  200. //(GET) Get all roles and objects that contain the role with given id, handler found in AccountAppService, lines 846 - 852
  201. 'getObjectsWithRole': '/roles/' + id + '/memberof',
  202. //(POST) Create a role, but this is NOT active for users, handler found in AccountAppService, lines 174 - 188
  203. 'createRole': '/roles?pid=' + id,
  204. //(POST or PUT) Add members to the role specified by id, handlers found in AccountAppService, lines 231 - 313
  205. 'addRoleMembers': '/roles/' + id + '/members',
  206. //(PUT) Updates a selected role, handler found in content-service
  207. /*
  208. * NOTE: This API call uses the content-service API, since its admin-service counterpart
  209. * is not behaving properly, this will be switched back to the admin API once changes have
  210. * been pushed in the future
  211. */
  212. 'updateRole': '/objects/' + id,
  213. //(PUT) Updates role capabilities, handler found in RolesResource, lines 75 - 85
  214. 'updateRoleCapabilities': '/roles/' + id + '/capabilities',
  215. //(PUT) Update user profile settings of a role, handler found in UserProfileSettings.java
  216. 'updateUserProfileSettings': '/roles/' + id + '/user_profile_settings',
  217. //(PUT) Modify properties for a role, handler found in AccountAppService, lines 198 - 213
  218. 'modifyRole': '/roles/' + id,
  219. //(DELETE) Delete a role, handler found in AccountAppService, lines 215 - 221
  220. 'deleteRole': '/roles/' + id,
  221. /*
  222. * USER ACCOUNTS API CALLS
  223. */
  224. //(GET) Get capabilities of user based on storeid
  225. 'getUserCapabilities': '/users/' + id + '/capabilities',
  226. //(GET) Get license level of a user based on its capability assignments
  227. 'getUserLicense': '/users/' + id + '/license',
  228. //(GET) Get all users, handler found in AccountAppService, lines 389 - 405
  229. 'getUsers': '/users/',
  230. //(GET) Get a user based on their storeid, handler found in AccountAppService, lines 407 - 413
  231. 'getUser': '/users/' + id,
  232. //(GET) Get all identities under cognos namespace, handler found in AccountAppService, lines 501 - 509
  233. 'getIdentities': '/identity',
  234. //(GET) Get a user properties based on its storeid, handler found in AccountAppService, lines 514 - 520
  235. 'getUserPreference': '/users/' + id + '/preference',
  236. //(GET) Get all groups and roles that contain a user with the given id, handler found in AccountAppService, lines 824 - 830
  237. 'getObjectsWithUser': '/users/' + id + '/memberof',
  238. //(POST) Create new user, handler found in AccountAppService, lines 465 - 487
  239. 'createUser': '/users?pid=' + id,
  240. //(PUT) Update a user based on their storeid, handler found in AccountAppService, lines 415 - 437
  241. 'updateUser': '/users/' + id,
  242. //(PUT) Update a user properties based on its storeid, handler found in AccountAppService, lines 522 - 551
  243. 'updateUserPreference': '/users/' + id + '/preference',
  244. //(PUT) Update an external user found by their storeid, handler found in AccountAppService, lines 439 - 463
  245. 'updateExternalUser': '/users_ex/' + id,
  246. //(DELETE) Delete a user with corresponding id, handler found in AccountAppService, lines 489 - 498
  247. 'deleteUser': '/users/' + id,
  248. //(DELETE) Delete a user's profile with corresponding id, handler in admin-service - UsersResource
  249. 'deleteUserProfile': '/users/' + id + '/profile',
  250. //(CREATE) Create a user's profile with corresponding id, handler in AccountAppService, lines 942- 948
  251. 'createUserProfile': '/users/' + id + '/createprofile',
  252. // (POST) Copy a users profile to target users
  253. 'copyUserProfile': '/users/' + id + '/copyProfile',
  254. //(GET) Get the default user profile
  255. 'get_default_user_profile': '/default_user_profile',
  256. //(PUT) Update the default user profile
  257. 'update_default_user_profile': '/default_user_profile',
  258. /*
  259. * Routing Rules Calls
  260. */
  261. // (GET) Get the routing rules table and routing hints
  262. 'routingRules': '/routingrules',
  263. // (PUT) Put the asset with latest routing hints
  264. 'routingHintAsset': '/objects/' + id,
  265. // (PUT) Put for the routing rules table
  266. 'routingRulesTable': '/objects/' + id,
  267. // (GET) Get for server group
  268. 'serverGroup': '/objects' + id + '/items',
  269. /*
  270. * Tenant API Calls
  271. */
  272. //(GET) Get tenant found in TenantsListController
  273. 'getTenant': '/tenants?tenantID=' + id,
  274. //(GET) Get tenant found in TenantsListController
  275. 'deleteTenant': '/tenants?tenantID=' + id,
  276. 'deleteTenantUserProfile': '/tenants/profile?tenantID=' + id,
  277. //(GET) Get tenant found in TenantsListController
  278. 'updateTenant': '/tenants?tenantID=' + id,
  279. //(GET) Get tenants found in TenantsListController
  280. 'tenants': '/tenants',
  281. //(GET) Get tenant Customizations found in TenantsListController
  282. 'tenantCustomizations': '/tenants/user_profile_settings?tenantID=' + id,
  283. //(DELETE) Kill Tenant Sessions
  284. 'killTenantSessions': '/tenants/sessions?tenantID=' + id,
  285. //(GET) Get tenantID for my user
  286. 'tenantIDForUser': '/objects/' + id,
  287. //(GET) Get notification settings for tenant
  288. 'tenantNotificationSettings': '/configuration/tenants?tenantID=' + id + '&subject=notification',
  289. //(GET) Get notification settings for System
  290. 'systemNotificationSettings': '/configuration/keys/NC.defaultSender',
  291. //(GET) Get tenant Customizations found in TenantsListController
  292. 'tenantPreferences': '/tenants/preferences?tenantID=' + id,
  293. /*
  294. * System API Calls
  295. */
  296. //(GET) Get System profile settings
  297. 'getSystemProfileSettings': '/system_profile_settings',
  298. //(PUT) Update system profile settings
  299. 'updateSystemProfileSettings': '/system_profile_settings',
  300. /*
  301. * Visualization Calls
  302. */
  303. 'deleteVisualization': '/objects/' + id,
  304. 'updateVisualization': '/objects/' + id,
  305. /*
  306. * Glass API Calls
  307. */
  308. //(GET) Get perspectives
  309. 'getPerspective': '/perspectives',
  310. /*
  311. * Config Setting API Calls
  312. */
  313. //(GET) Get mtCloudBuild status
  314. 'getMtCloudBuild': '/configuration/keys/mtCloudBuild',
  315. //(GET) get the ancestors of the object
  316. 'getAncestors': '/objects/' + id + '?fields=ancestors'
  317. };
  318. return 'v1' + urls[req];
  319. };
  320. AJAXUtils.prototype.isNamingConflictErrorMsg = function (message) {
  321. var errMsg = this._parseErrorMsg(message);
  322. if (errMsg) {
  323. return errMsg.indexOf("CM-REQ-4201") >= 0 || errMsg.indexOf("CM-REQ-4036") >= 0 || errMsg.indexOf("CM-REQ-4024") >= 0;
  324. } else {
  325. return false;
  326. }
  327. };
  328. /*
  329. * Method builds an error message from the glassContext errors array
  330. * errors :[{"message":"errorMessage"}]
  331. */
  332. AJAXUtils.prototype.buildErrorMessage = function (errors) {
  333. var errMessage = "";
  334. if (errors) {
  335. _.each(errors, function (elem, index, list) {
  336. errMessage += elem.message + '\n';
  337. });
  338. }
  339. return errMessage;
  340. };
  341. var _static = {
  342. getInstance: function getInstance() {
  343. if (!_singletonInstance) {
  344. _singletonInstance = new AJAXUtils();
  345. }
  346. return _singletonInstance;
  347. }
  348. };
  349. return _static.getInstance();
  350. });