CollectParameterValues.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/common/templates/collectParameterValues.xml', 'bi/admin/common/utils/XMLUtils', 'bi/admin/globalparameters/helpers/SoapHelper', 'bi/admin/common/utils/parameters/ParameterValues', 'ba-react-admin/ba-react-admin.min', 'text!bi/admin/common/templates/queryForRoutingServerGroup.xml'], function (_, Class, doT, CollectParameterValuesTemplate, XMLUtilsPlaceholder, SoapHelper, ParameterValues, AdminReact, RoutingServerGroupQueryTemplate) {
  9. var CollectParameterValues = Class.extend({
  10. _cachedResponses: {},
  11. init: function init(options) {
  12. CollectParameterValues.inherited('init', this, arguments);
  13. _.extend(this, options);
  14. },
  15. get: function get() {
  16. if (this.parameter.source !== 'report') {
  17. return this._returnStaticValues();
  18. } else if (this._cachedResponses[this.parameter.report_id]) {
  19. return this._returnCachedResponse();
  20. } else {
  21. var routingServerGroupQuery = doT.template(RoutingServerGroupQueryTemplate)({
  22. 'cafContextId': this.glassContext.authInfo.cafContextId,
  23. 'objectPath': this.parameter.report_path ? SoapHelper.xml_encode(this.parameter.report_path) : 'storeID(\'' + this.parameter.report_id + '\')'
  24. });
  25. return this.glassContext.services.fetch.post('v1/reports', {
  26. 'headers': {
  27. 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
  28. },
  29. 'contentType': 'text/xml; charset=UTF-8',
  30. 'data': routingServerGroupQuery
  31. }).then(function (cmResponse) {
  32. var $routingServerGroupNode = $(cmResponse.data).selectNode('Envelope').selectNode('Body').selectNode('queryResponse').selectNode('result').selectNode('item').selectNode('routingServerGroup').selectNode('value');
  33. var collectParameterValuesRequest = doT.template(CollectParameterValuesTemplate)({
  34. 'cafContextId': this.glassContext.authInfo.cafContextId,
  35. 'objectPath': this.parameter.report_path ? SoapHelper.xml_encode(this.parameter.report_path) : 'storeID(\'' + this.parameter.report_id + '\')',
  36. 'parameterValues': this.parameterValues ? ParameterValues.toXML(this.parameterValues) : '<parameterValues xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:parameterValue[]"/>',
  37. 'routingServerGroup': $routingServerGroupNode.text()
  38. });
  39. return this.glassContext.services.fetch.post('v1/reports', {
  40. 'headers': {
  41. 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/reportService/201703/.high'
  42. },
  43. 'contentType': 'text/xml; charset=UTF-8',
  44. 'data': collectParameterValuesRequest
  45. }).then(function (response) {
  46. return SoapHelper.processResponse({
  47. id: this.parameter.report_id,
  48. defaultName: ''
  49. }, response.data);
  50. }.bind(this));
  51. }.bind(this)).catch(function (response) {
  52. return {
  53. status: 'error',
  54. report_id: this.parameter.report_id,
  55. message: response.message,
  56. code: response.code
  57. };
  58. }.bind(this));
  59. }
  60. },
  61. _returnStaticValues: function _returnStaticValues() {
  62. return new Promise(function (resolve, reject) {
  63. var values = [];
  64. _.each(this.parameter.values, function (item) {
  65. values.push({
  66. label: item.display,
  67. value: item.use
  68. });
  69. });
  70. var response = {
  71. status: 'success',
  72. type: 'json',
  73. promptControls: [this.parameter.name],
  74. name: this.parameter.name,
  75. json: {
  76. name: this.parameter.name,
  77. control: {
  78. multiSelect: true,
  79. type: 'checkBoxGroup',
  80. module: AdminReact.CheckboxGroupControl,
  81. autoSubmit: false
  82. },
  83. values: values
  84. },
  85. xml: null
  86. };
  87. if (this.parameter.name === '_as_of_date') {
  88. response.json.control = {
  89. multiSelect: false,
  90. type: 'selectDate',
  91. module: AdminReact.DateTimeControl,
  92. autoSubmit: false
  93. };
  94. }
  95. resolve(response);
  96. }.bind(this));
  97. },
  98. _returnCachedResponse: function _returnCachedResponse() {
  99. return new Promise(function (resolve, reject) {
  100. var xmlDoc = $.parseXML(this._cachedResponses[this.parameter.report_id]);
  101. resolve(SoapHelper.processResponse(xmlDoc));
  102. }.bind(this));
  103. }
  104. });
  105. return CollectParameterValues;
  106. });