AccountParameterValues.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'bi/commons/ui/core/Class', 'doT', 'text!bi/admin/globalparameters/helpers/templates/updateAccountUserProfileSettings.xml', 'text!bi/admin/globalparameters/helpers/templates/getAccountUserProfileSettings.xml', 'bi/admin/globalparameters/helpers/SoapHelper', 'bi/admin/common/utils/XMLUtils'], function (_, Class, doT, UpdateUserProfileSettingsTemplate, GetUserProfileSettingsTemplate, SoapHelper, XMLUtilsPlaceholder) {
  9. var _gCachedAccountUserProfileSettings = null;
  10. var AccountParameterValues = Class.extend({
  11. init: function init(options) {
  12. AccountParameterValues.inherited('init', this, arguments);
  13. _.extend(this, options);
  14. },
  15. _getUserProfileValues: function _getUserProfileValues() {
  16. if (_gCachedAccountUserProfileSettings) {
  17. return Promise.resolve(_gCachedAccountUserProfileSettings);
  18. } else {
  19. var getRequest = doT.template(GetUserProfileSettingsTemplate)({
  20. 'cafContextId': this.glassContext.authInfo.cafContextId
  21. });
  22. return this.glassContext.services.fetch.post('v1/reports', {
  23. 'headers': {
  24. 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
  25. },
  26. 'contentType': 'text/xml; charset=UTF-8',
  27. 'data': getRequest
  28. }).then(function (response) {
  29. var $accountProfileSettings = $(response.data).selectNode('Envelope').selectNode('Body').selectNode('queryResponse').selectNode('result').selectNode('item').selectNode('userProfileSettings').selectNode('value');
  30. var accountUserProfileSettingsText = $accountProfileSettings.text();
  31. if (accountUserProfileSettingsText !== '') {
  32. _gCachedAccountUserProfileSettings = JSON.parse(accountUserProfileSettingsText);
  33. } else {
  34. _gCachedAccountUserProfileSettings = {};
  35. }
  36. return _gCachedAccountUserProfileSettings;
  37. });
  38. }
  39. },
  40. reset: function reset() {
  41. return this._getUserProfileValues().then(function (currentAccountUserProfileValues) {
  42. currentAccountUserProfileValues.parameter_values = {};
  43. return this._sendUpdateRequest(currentAccountUserProfileValues);
  44. }.bind(this));
  45. },
  46. update: function update(parameter_values) {
  47. return this._getUserProfileValues().then(function (currentAccountUserProfileValues) {
  48. if (!currentAccountUserProfileValues.parameter_values) {
  49. currentAccountUserProfileValues.parameter_values = {};
  50. }
  51. _.each(parameter_values, function (parameter_value) {
  52. currentAccountUserProfileValues.parameter_values[parameter_value.name] = parameter_value;
  53. });
  54. return this._sendUpdateRequest(currentAccountUserProfileValues);
  55. }.bind(this));
  56. },
  57. _sendUpdateRequest: function _sendUpdateRequest(accountUserProfileValues) {
  58. var updateRequest = doT.template(UpdateUserProfileSettingsTemplate)({
  59. 'cafContextId': this.glassContext.authInfo.cafContextId,
  60. 'userProfileSettings': SoapHelper.xml_encode(JSON.stringify(accountUserProfileValues))
  61. });
  62. return this.glassContext.services.fetch.post('v1/reports', {
  63. 'headers': {
  64. 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
  65. },
  66. 'contentType': 'text/xml; charset=UTF-8',
  67. 'data': updateRequest
  68. }).then(function () {
  69. _gCachedAccountUserProfileSettings = accountUserProfileValues;
  70. return _gCachedAccountUserProfileSettings.parameter_values || {};
  71. });
  72. }
  73. });
  74. return AccountParameterValues;
  75. });