123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2016, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([], function () {
- 'use strict'; //NOSONAR: meant to be strict
- var _singletonInstance = null;
- var ajaxURLS = {
- 'ldapStatus': 'ads_state',
- 'namespace': 'namespaces',
- 'datasources': 'datasources',
- 'test': 'datasourceconnection/test',
- 'testWithConn': 'datasourceconnection/test_with_credential',
- 'tenants': 'tenants'
- };
- var AJAXUtils = function AJAXUtils() {
- if (AJAXUtils.prototype._singletonInstance) {
- return AJAXUtils.prototype._singletonInstance;
- }
- };
- /*
- * returns the url assoicated with key
- */
- AJAXUtils.prototype.getAJAXURL = function (key) {
- return 'v1/' + ajaxURLS[key];
- };
- /*
- * returns a full rest url built from the partial one provided
- */
- AJAXUtils.prototype.getURL = function (partialURL) {
- return 'v1/' + partialURL;
- };
- /**
- * parse a friendly error message from response text
- */
- AJAXUtils.prototype._parseErrorMsg = function (response) {
- var result = "";
- if (response.responseJSON.messages !== undefined) {
- result = response.responseJSON.messages.join('\n');
- } else if (response.responseJSON.errors[0].messages !== undefined) {
- result = response.responseJSON.errors[0].messages.join('\n');
- }
- return result;
- };
- /*
- * Gets a url based on the static key and arguments passed in
- *
- * @param {String} req - the requested path, usually indicated by the name of the action
- * @optional {String} id - only required for some paths, which specifies the id or pid of an object
- */
- AJAXUtils.prototype.getPath = function (req, id) {
- //NOSONAR
- var urls = {
- /*
- * CONTENT MANAGER API CALLS
- */
- //(GET) Get all users/groups/roles based on search type, handler found in AccountAppService, lines 857 - 865
- 'contentManagerSearch': '/cmsearch',
- /*
- * DISK USAGE API CALLS
- */
- //(GET) Get disk usage, handler found in DiskUsageResource.java
- 'getDiskUsage': '/disk_usage',
- /*
- * DEPLOYMENT RESOURCE - EXPORTS
- */
- //(GET) Get all export specs, handler found in AccountAppService, lines 873 - 881
- 'getExports': '/exports',
- //(GET) Get an export spec, handler found in AccountAppService, lines 883 - 889
- 'getExport': '/exports/' + id,
- //(GET) Get an exporting status, handler found in AccountAppService, lines 891 - 897
- 'getExportStatus': '/exports/' + id + '/status',
- //(PUT) Import an export spec, handler found in AccountAppService, lines 907 - 913
- 'importExportSpec': '/exports/' + id + '/run',
- //(POST) Create new export spec, handler found in AccountAppService, lines 899 - 905
- 'createExport': '/exports',
- //(DELETE) Delete an export spec, handler found in AccountAppService, lines 915 - 921
- 'deleteExport': '/exports/' + id,
- /*
- * DEPLOYMENT RESOURCE - IMPORTS
- */
- //(GET) Get all import specs, handler found in AccountAppService, lines 930 - 938
- 'getImports': '/imports',
- //(GET) Get an import spec, handler found in AccountAppService, lines 940 - 946
- 'getImport': '/imports/' + id,
- //(GET) Get an importing status, handler found in AccountAppService, lines 948 - 954
- 'getImportStatus': '/imports/' + id + '/status',
- //(PUT) Import an import spec, handler found in AccountAppService, lines 964 - 970
- 'importImportSpec': '/imports/' + id + '/run',
- //(POST) Create new export spec, handler found in AccountAppService, lines 956 - 962
- 'createImport': '/imports',
- //(DELETE) Delete an export spec, handler found in AccountAppService, lines 972 - 978
- 'deleteImport': '/imports/' + id,
- /*
- * FILE UPLOAD API
- */
- //(POST) Upload a csv format file to create users, handler found in AccountAppService, lines 800 - 811
- 'uploadFile': '/uploadfile',
- /*
- * GROUPS API CALLS
- */
- //(GET) Get capabilities of group based on its storeid, handler found in GroupsResource, lines 45 - 57
- 'getGroupCapabilities': '/groups/' + id + '/capabilities',
- //(GET) Get license level of a group based on its capability assignments, handler found in GroupsResource, lines 59 - 71
- 'getGroupLicense': '/groups/' + id + '/license',
- //(GET) Get all groups in cm, handler found in AccountAppService, lines 573 - 579
- 'getGroups': '/groups',
- //(GET) Get a group from cm based on id, handler found in AccountAppService.java
- 'getGroup': '/groups/' + id,
- //(GET) Get all group members in cm based on its storeid, handler found in AccountAppService, lines 621 - 628
- 'getGroupMembers': '/groups/' + id + '/members',
- //(GET) Get all groups and roles that contain the group with given id, handler found in AccountAppService, lines 835 - 841
- 'getObjectsWithGroup': '/groups/' + id + '/memberof',
- //(POST) Creates a group in cm, handler found in AccountAppService, lines 598 - 611
- 'createGroup': '/groups?pid=' + id,
- //(POST) Add members to a group in cm with the given id, lines 630 - 668
- 'addGroupMembers': '/groups/' + id + '/members',
- //(PUT) Remove members from a group with the given id, handler found in AccountAppService, lines 670 - 707
- 'removeGroupMembers': '/groups/' + id + '/members',
- //(PUT) Update a group in cm, handler found in content-service
- /*
- * NOTE: This API call uses the content-service API, since its admin-service counterpart
- * is not behaving properly, this will be switched back to the admin API once changes have
- * been pushed in the future
- */
- 'updateGroup': '/objects/' + id,
- //(DELETE) Delete a group in cm found by storeid, handler found in AccountAppService, lines 613 - 619
- 'deleteGroup': '/objects/' + id,
- /*
- * LICENSES API CALLS
- */
- //(GET) Returns summary information of license use, handler found in LicensesResource, lines 79 - 103
- 'getLicenseUse': '/licenses',
- //(GET) Get current license status, handler found in LicenseResource
- 'getLicenseStatus': '/license',
- //(PUT) Update owned license count, handler found in LicensesResource, lines 125 - 150
- 'updateLicenseCount': '/licenses/owned',
- //(PUT) Switch to another valid license status, handler found in LicenseResource
- 'switchLicenseStatus': '/license',
- //(POST) Refresh license calculations, handler found in LicensesResource, lines 105 - 123
- 'refreshLicenses': '/licenses',
- /*
- * NAMESPACE API CALLS
- */
- //(GET) Search descendants of specified namespace location, handler found in NamespaceSearchResource, lines 52 - 78
- 'namespaceSearch': '/namespaces/' + id + '/search',
- //(GET) Get all namesapces, handler found in AccountAppService, lines 315 - 323
- 'getNamespaces': '/namespaces/',
- //(GET) Get a namespace based on its storeid, handler found in AccountAppService, lines 325 - 331
- 'getNamespace': '/namespaces/' + id,
- //(GET) Get all items of a namespace based on its storeid, handler found in AccountAppService, lines 350 - 363
- 'getNamesapceItems': '/namespaces/' + id + '/items',
- //(POST) Creates a namespace
- 'createNamespace': '/namespace?pid=' + id,
- //(PUT) Update a namespace, handler found in AccountAppService, lines 333 - 348
- 'updateNamespace': '/objects/' + id,
- /*
- * NAMESPACE FOLDER API CALLS
- */
- //(GET) Get all first level folders, handler found in AccountAppService, lines 712 - 725
- 'getNamespaceFolders': '/folders',
- //(GET) Get specific first level folder based on storeid, handler found in AccountAppService, lines 727 - 738
- 'getNamespaceFolder': '/folders/' + id,
- //(GET) Get all items in a folder based on folder storeid, handler found in AccountAppService, lines 740 - 752
- 'getNamespaceFolderItems': '/folders' + id + '/items',
- //(POST) Create a namespace folder, handler found in AccountAppService, lines 754 - 766
- 'createNamespaceFolder': '/folders?pid=' + id,
- //(PUT) Update a folder based on its storeid, handler found in AccountAppService, lines 776 - 791
- 'updateNamespaceFolder': '/folders/' + id,
- //(DELETE) Delete a namespace folder, handler found in AccountAppService, lines 768 - 774
- //NOTE: This path is confusing, as /folders/ actually represents the pathing for nameSpaceFolders
- //this should be patched in a future update to the API
- 'deleteNamespaceFolder': '/folders/' + id,
- /*
- * PRINTER API CALLS
- */
- //(GET) Get all printers under system, handler found in AccountAppService, lines 368 - 376
- 'getPrinters': '/system/printers',
- //(GET) Get the printer under a system specified by id, handler found in AccountAppService, lines 378 - 384
- 'getPrinter': '/systems/printers/' + id,
- /*
- * ROLES AND USER PROFILE SETTINGS CALLS
- */
- //(GET) Get all roles, handler found in AccountAppService, lines 174 - 188
- 'getRoles': '/roles/',
- //(GET) Get capabilities of a role based on its storeid, handler found in AccountAppService, lines 190 - 196
- 'getRoleCapabilities': '/roles/' + id + '/capabilities',
- //(GET) Get members of role based on its storeid, handler found in AccountAppService, lines 223 - 229
- 'getRoleMembers': '/roles/' + id + '/members',
- //(GET) Get license level of a role based on its capability assignments, handler found in RolesResource, lines 61 - 73
- 'getRoleLicense': '/roles/' + id + '/license',
- //(GET) Get user profile settings of a role, handler found in UserProfuleSettings.java
- 'getUserProfileSettings': '/roles/' + id + '/user_profile_settings',
- //(GET) Get a role based on its storeId, handler found in AccountAppService, lines 190 - 196
- 'getRole': '/roles/' + id,
- //(GET) Get all roles and objects that contain the role with given id, handler found in AccountAppService, lines 846 - 852
- 'getObjectsWithRole': '/roles/' + id + '/memberof',
- //(POST) Create a role, but this is NOT active for users, handler found in AccountAppService, lines 174 - 188
- 'createRole': '/roles?pid=' + id,
- //(POST or PUT) Add members to the role specified by id, handlers found in AccountAppService, lines 231 - 313
- 'addRoleMembers': '/roles/' + id + '/members',
- //(PUT) Updates a selected role, handler found in content-service
- /*
- * NOTE: This API call uses the content-service API, since its admin-service counterpart
- * is not behaving properly, this will be switched back to the admin API once changes have
- * been pushed in the future
- */
- 'updateRole': '/objects/' + id,
- //(PUT) Updates role capabilities, handler found in RolesResource, lines 75 - 85
- 'updateRoleCapabilities': '/roles/' + id + '/capabilities',
- //(PUT) Update user profile settings of a role, handler found in UserProfileSettings.java
- 'updateUserProfileSettings': '/roles/' + id + '/user_profile_settings',
- //(PUT) Modify properties for a role, handler found in AccountAppService, lines 198 - 213
- 'modifyRole': '/roles/' + id,
- //(DELETE) Delete a role, handler found in AccountAppService, lines 215 - 221
- 'deleteRole': '/roles/' + id,
- /*
- * USER ACCOUNTS API CALLS
- */
- //(GET) Get capabilities of user based on storeid
- 'getUserCapabilities': '/users/' + id + '/capabilities',
- //(GET) Get license level of a user based on its capability assignments
- 'getUserLicense': '/users/' + id + '/license',
- //(GET) Get all users, handler found in AccountAppService, lines 389 - 405
- 'getUsers': '/users/',
- //(GET) Get a user based on their storeid, handler found in AccountAppService, lines 407 - 413
- 'getUser': '/users/' + id,
- //(GET) Get all identities under cognos namespace, handler found in AccountAppService, lines 501 - 509
- 'getIdentities': '/identity',
- //(GET) Get a user properties based on its storeid, handler found in AccountAppService, lines 514 - 520
- 'getUserPreference': '/users/' + id + '/preference',
- //(GET) Get all groups and roles that contain a user with the given id, handler found in AccountAppService, lines 824 - 830
- 'getObjectsWithUser': '/users/' + id + '/memberof',
- //(POST) Create new user, handler found in AccountAppService, lines 465 - 487
- 'createUser': '/users?pid=' + id,
- //(PUT) Update a user based on their storeid, handler found in AccountAppService, lines 415 - 437
- 'updateUser': '/users/' + id,
- //(PUT) Update a user properties based on its storeid, handler found in AccountAppService, lines 522 - 551
- 'updateUserPreference': '/users/' + id + '/preference',
- //(PUT) Update an external user found by their storeid, handler found in AccountAppService, lines 439 - 463
- 'updateExternalUser': '/users_ex/' + id,
- //(DELETE) Delete a user with corresponding id, handler found in AccountAppService, lines 489 - 498
- 'deleteUser': '/users/' + id,
- //(DELETE) Delete a user's profile with corresponding id, handler in admin-service - UsersResource
- 'deleteUserProfile': '/users/' + id + '/profile',
- //(CREATE) Create a user's profile with corresponding id, handler in AccountAppService, lines 942- 948
- 'createUserProfile': '/users/' + id + '/createprofile',
- // (POST) Copy a users profile to target users
- 'copyUserProfile': '/users/' + id + '/copyProfile',
- //(GET) Get the default user profile
- 'get_default_user_profile': '/default_user_profile',
- //(PUT) Update the default user profile
- 'update_default_user_profile': '/default_user_profile',
- /*
- * Routing Rules Calls
- */
- // (GET) Get the routing rules table and routing hints
- 'routingRules': '/routingrules',
- // (PUT) Put the asset with latest routing hints
- 'routingHintAsset': '/objects/' + id,
- // (PUT) Put for the routing rules table
- 'routingRulesTable': '/objects/' + id,
- // (GET) Get for server group
- 'serverGroup': '/objects' + id + '/items',
- /*
- * Tenant API Calls
- */
- //(GET) Get tenant found in TenantsListController
- 'getTenant': '/tenants?tenantID=' + id,
- //(GET) Get tenant found in TenantsListController
- 'deleteTenant': '/tenants?tenantID=' + id,
- 'deleteTenantUserProfile': '/tenants/profile?tenantID=' + id,
- //(GET) Get tenant found in TenantsListController
- 'updateTenant': '/tenants?tenantID=' + id,
- //(GET) Get tenants found in TenantsListController
- 'tenants': '/tenants',
- //(GET) Get tenant Customizations found in TenantsListController
- 'tenantCustomizations': '/tenants/user_profile_settings?tenantID=' + id,
- //(DELETE) Kill Tenant Sessions
- 'killTenantSessions': '/tenants/sessions?tenantID=' + id,
- //(GET) Get tenantID for my user
- 'tenantIDForUser': '/objects/' + id,
- //(GET) Get notification settings for tenant
- 'tenantNotificationSettings': '/configuration/tenants?tenantID=' + id + '&subject=notification',
- //(GET) Get notification settings for System
- 'systemNotificationSettings': '/configuration/keys/NC.defaultSender',
- //(GET) Get tenant Customizations found in TenantsListController
- 'tenantPreferences': '/tenants/preferences?tenantID=' + id,
- /*
- * System API Calls
- */
- //(GET) Get System profile settings
- 'getSystemProfileSettings': '/system_profile_settings',
- //(PUT) Update system profile settings
- 'updateSystemProfileSettings': '/system_profile_settings',
- /*
- * Visualization Calls
- */
- 'deleteVisualization': '/objects/' + id,
- 'updateVisualization': '/objects/' + id,
- /*
- * Glass API Calls
- */
- //(GET) Get perspectives
- 'getPerspective': '/perspectives',
- /*
- * Config Setting API Calls
- */
- //(GET) Get mtCloudBuild status
- 'getMtCloudBuild': '/configuration/keys/mtCloudBuild',
- //(GET) get the ancestors of the object
- 'getAncestors': '/objects/' + id + '?fields=ancestors'
- };
- return 'v1' + urls[req];
- };
- AJAXUtils.prototype.isNamingConflictErrorMsg = function (message) {
- var errMsg = this._parseErrorMsg(message);
- if (errMsg) {
- return errMsg.indexOf("CM-REQ-4201") >= 0 || errMsg.indexOf("CM-REQ-4036") >= 0 || errMsg.indexOf("CM-REQ-4024") >= 0;
- } else {
- return false;
- }
- };
- /*
- * Method builds an error message from the glassContext errors array
- * errors :[{"message":"errorMessage"}]
- */
- AJAXUtils.prototype.buildErrorMessage = function (errors) {
- var errMessage = "";
- if (errors) {
- _.each(errors, function (elem, index, list) {
- errMessage += elem.message + '\n';
- });
- }
- return errMessage;
- };
- var _static = {
- getInstance: function getInstance() {
- if (!_singletonInstance) {
- _singletonInstance = new AJAXUtils();
- }
- return _singletonInstance;
- }
- };
- return _static.getInstance();
- });
|