JdbcConnectionStringPane.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['bi/admin/datasource/slideout/ConnectionStringEditorPane', 'bi/admin/datasource/services/ConnectionUtils', 'bi/admin/nls/StringResource', 'jquery', 'text!bi/admin/datasource/services/datasources.json', 'react-dom', 'react', 'mobx', 'ba-react-admin/ba-react-admin.min', 'baglass/core-client/js/core-client/utils/BidiUtil'], function (ConnectionStringEditorPane, ConnectionUtils, StringResource, $, datasources, ReactDOM, React, mobx, AdminReact, BidiUtil) {
  10. /**
  11. * Sample content view that extends the glass View class
  12. */
  13. var JdbcConnectionStringPane = ConnectionStringEditorPane.extend({
  14. _connectParametersHelpLink: 'https://www.ibm.com/support/knowledgecenter/SSEP7J_11.1.0/com.ibm.swg.ba.cognos.ag_manage.doc/c_connection_properties.html',
  15. _secureGatewayHelpLink: 'https://www.ibm.com/support/knowledgecenter/SSEP7J_11.1.0/com.ibm.swg.ba.cognos.ag_manage.doc/c_ca_manage_secure_gateway_connecting_destination.html',
  16. _secretKeyHelpLink: 'https://www.ibm.com/support/knowledgecenter/SSEP7J_11.1.0/com.ibm.swg.ba.cognos.ag_manage.doc/c_ca_manage_data_source_secret_key.html',
  17. init: function init(options) {
  18. JdbcConnectionStringPane.inherited('init', this, arguments);
  19. $.extend(this, options);
  20. this.objectInfo = options.objectInfo;
  21. },
  22. refresh: function refresh() {
  23. this.$body.empty();
  24. this.renderBody();
  25. },
  26. renderBody: function renderBody() {
  27. var options = {
  28. 'el': this.$el.find(".bi-admin-pane-body"),
  29. 'glassContext': this.glassContext,
  30. 'items': []
  31. };
  32. options.items.push({
  33. 'id': 'adminJdbcUrl',
  34. 'name': 'jdbcUrl',
  35. 'label': StringResource.get('jdbcUrl'),
  36. 'type': 'TextArea',
  37. 'multiline': true,
  38. 'editable': this.isEditable(),
  39. 'onChange': function (name, value) {
  40. this.parseInfo.jdbcURL = value;
  41. }.bind(this),
  42. 'value': this.parseInfo.jdbcURL
  43. });
  44. options.items.push({
  45. 'id': 'adminDriverClass',
  46. 'name': 'driverClass',
  47. 'label': StringResource.get('driverClassName'),
  48. 'type': 'TextArea',
  49. 'multiline': true,
  50. 'editable': this.isEditable(),
  51. 'onChange': function (name, value) {
  52. this.parseInfo.metadata.driverName = value;
  53. }.bind(this),
  54. 'value': this.parseInfo.metadata.driverName
  55. });
  56. if (this.isEditable()) {
  57. options.items.push({
  58. 'id': 'admindriverClassRestore',
  59. 'name': 'driverClassRestore',
  60. 'label': StringResource.get('restore'),
  61. 'type': 'Button',
  62. 'onSelect': function () {
  63. try {
  64. var ds = JSON.parse(datasources).data;
  65. for (var i = 0; i < ds.length; i++) {
  66. if (this.parseInfo.metadata.code === ds[i].code) {
  67. //NOSONAR
  68. this.parseInfo.metadata.driverName = ds[i].driverName;
  69. this.refresh();
  70. break;
  71. }
  72. }
  73. } catch (err) {
  74. this.logger.error("Could not load datasource metadata: " + err);
  75. }
  76. }.bind(this)
  77. });
  78. }
  79. options.items.push({
  80. 'type': 'CollapsibleSection',
  81. 'label': StringResource.get('exampleURL'),
  82. 'name': 'exampleURLCol',
  83. 'styleAsSimpleRow': true,
  84. 'items': []
  85. });
  86. options.items.push({
  87. 'id': 'adminConnectionParameters',
  88. 'name': 'connectionParameters',
  89. 'label': StringResource.get('connectionParameters'),
  90. 'type': 'TextArea',
  91. 'multiline': true,
  92. 'editable': this.isEditable(),
  93. 'onChange': function (name, value) {
  94. this.parseInfo.connectionProperties = value;
  95. }.bind(this),
  96. 'value': this.parseInfo.connectionProperties
  97. });
  98. if (this._showSecretKeyOptions()) {
  99. options.items.push({
  100. 'id': 'adminAuthKey',
  101. 'name': 'key',
  102. 'label': StringResource.get('key'),
  103. 'value': this.parseInfo.apiToken && this.parseInfo.apiToken.authKey ? 'secret' : '',
  104. 'type': 'SingleLineValue',
  105. 'multiline': true,
  106. 'editable': this.isEditable(),
  107. 'inputType': 'password',
  108. 'onChange': function (name, value) {
  109. if (!this.parseInfo.apiToken) {
  110. this.parseInfo.apiToken = {};
  111. }
  112. this.parseInfo.apiToken.authKey = value.toString();
  113. }.bind(this)
  114. });
  115. options.items.push({
  116. 'id': 'adminSecretKey',
  117. 'name': 'secretKey',
  118. 'label': StringResource.get('secretKey'),
  119. 'type': 'SingleLineValue',
  120. 'value': this.parseInfo.apiToken && this.parseInfo.apiToken.secretKey ? 'secret' : '',
  121. 'multiline': true,
  122. 'editable': this.isEditable(),
  123. 'inputType': 'password',
  124. 'onChange': function (name, value) {
  125. if (!this.parseInfo.apiToken) {
  126. this.parseInfo.apiToken = {};
  127. }
  128. this.parseInfo.apiToken.secretKey = value.toString();
  129. }.bind(this)
  130. });
  131. }
  132. return ConnectionUtils.checkForSecuredGatewayExtension(this.glassContext).then(function (resp) {
  133. if (resp === null || resp === undefined) {
  134. this.isSecureGateway = false;
  135. } else {
  136. this.isSecureGateway = true;
  137. options.items.push({
  138. 'id': 'secureGatewayInfo',
  139. 'name': 'secureGatewayInfo',
  140. 'label': StringResource.get('secureGatewayDestination'),
  141. 'type': 'SectionLabel'
  142. });
  143. options.items.push({
  144. 'type': 'Separator'
  145. });
  146. }
  147. return this._renderBody(options);
  148. }.bind(this));
  149. },
  150. _showSecretKeyOptions: function _showSecretKeyOptions() {
  151. if (this.objectInfo.vendor && this.objectInfo.vendor.authKey || this.objectInfo.connectionString.indexOf('ibmcognos.subcode=AUTOREST') > -1) {
  152. return true;
  153. }
  154. return false;
  155. },
  156. _postRender: function _postRender() {
  157. if (this.isSecureGateway) {
  158. this._addSecuredGateway();
  159. this._addSecureGatewayHelp();
  160. }
  161. if (this._showSecretKeyOptions()) {
  162. this._addSecretKeyHelp();
  163. }
  164. this._addConnectionParamsHelp();
  165. this._addSampleText();
  166. return this.$el;
  167. },
  168. _addSecretKeyHelp: function _addSecretKeyHelp() {
  169. var $secHelp = $(this.$el.find('.property_adminAuthKey .l_key'));
  170. $secHelp.css('display', 'inline-flex');
  171. var $helpEl = $('<div tabindex="0" style="padding-left: 10px;" role="img" title="' + StringResource.get('adminAuthKeyHelpInfo') + '"><svg class="svgIcon dsSvgInfoIcon" role="presentation"><text>' + StringResource.get('adminAuthKeyHelpInfo') + '</text><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#common-titan_help"></use></svg></div>');
  172. $helpEl.on('primaryaction', function () {
  173. window.open(this._secretKeyHelpLink, '_blank');
  174. }.bind(this));
  175. $secHelp.append($helpEl);
  176. },
  177. _addSecureGatewayHelp: function _addSecureGatewayHelp() {
  178. var $secGWHelp = $(this.$el.find('.property_secureGatewayInfo'));
  179. $secGWHelp.css('display', 'inline-flex');
  180. var $helpEl = $('<div tabindex="0" style="padding-left: 10px;" role="img" title="' + StringResource.get('sgGatewayHelpInfo') + '"><svg class="svgIcon dsSvgInfoIcon" role="presentation"><text>' + StringResource.get('sgGatewayHelpInfo') + '</text><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#common-titan_help"></use></svg></div>');
  181. $helpEl.on('primaryaction', function () {
  182. window.open(this._secureGatewayHelpLink, '_blank');
  183. }.bind(this));
  184. $secGWHelp.append($helpEl);
  185. },
  186. _addSecuredGateway: function _addSecuredGateway() {
  187. $(this.$el.find('.separator')[0]).after($('<div id=secGatewayElement>'));
  188. if (this.$el.find('#secGatewayElement')[0]) {
  189. ReactDOM.unmountComponentAtNode(this.$el.find('#secGatewayElement')[0]);
  190. }
  191. var secureGatewayElement = React.createElement(AdminReact.DSSecureGatewayElementView, {
  192. 'glassContext': this.glassContext,
  193. 'slideout': this.slideout,
  194. 'StringResource': StringResource,
  195. 'ConnectionUtils': ConnectionUtils,
  196. 'objectInfo': this.objectInfo,
  197. 'textDir': BidiUtil.userPreferredTextDir,
  198. 'parent': this
  199. });
  200. this.secureGateway = ReactDOM.render(secureGatewayElement, this.$el.find('#secGatewayElement')[0]);
  201. },
  202. _addConnectionParamsHelp: function _addConnectionParamsHelp() {
  203. var $connParamsSec = $(this.$el.find(".l_connectionParameters"));
  204. $connParamsSec.css("display", "inline-flex");
  205. var $helpEl = $('<div tabindex="0" style="padding-left: 10px;" role="img" title="' + StringResource.get('connectionPropertiesHelp') + '"><svg class="svgIcon dsSvgInfoIcon" role="presentation"><text>' + StringResource.get('connectionPropertiesHelp') + '</text><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#common-titan_help"></use></svg></div>');
  206. $helpEl.on("primaryaction", function () {
  207. window.open(this._connectParametersHelpLink, '_blank');
  208. }.bind(this));
  209. $connParamsSec.append($helpEl);
  210. },
  211. _addSampleText: function _addSampleText() {
  212. var jdbcCollSec = this.$el.find(".collapsibleSection");
  213. var exampleText = $('<div><div style="padding-left: 25px" class="jdbcSampleText"></div></div>');
  214. exampleText.find('.jdbcSampleText').text(this.parseInfo.metadata.urlTemplate);
  215. $(jdbcCollSec).append(exampleText);
  216. var colSectEl = this.$el.find(".rightAlign");
  217. $(colSectEl).removeClass("rightAlign");
  218. },
  219. setFocus: function setFocus() {
  220. var textArea = this.$el.find(".v_jdbcUrl");
  221. $(textArea).focus();
  222. $(textArea).select();
  223. },
  224. closeClick: function closeClick() {
  225. JdbcConnectionStringPane.inherited('closeClick', this, arguments);
  226. if (this.$el.find('#secGatewayElement')[0]) {
  227. ReactDOM.unmountComponentAtNode(this.$el.find('#secGatewayElement')[0]);
  228. }
  229. },
  230. updateSecureGWConnectionString: function updateSecureGWConnectionString(connString, gwId, gatewayDestinationId, destinationKey) {
  231. this.parseInfo.gwConnStr = connString;
  232. var jdbcString = ConnectionUtils.buildConnection(this.parseInfo, this.objectInfo);
  233. this.objectInfo.connectionString = ConnectionUtils.getUpdatedConnectionString(this.parseInfo, jdbcString);
  234. this.parseInfo.gwStringUpdated = true;
  235. if (gatewayDestinationId && destinationKey) {
  236. this.objectInfo.gatewayDestination = [{
  237. type: 'gatewayDestination',
  238. gwParentId: gwId,
  239. id: gatewayDestinationId,
  240. searchPath: "storeID('" + gatewayDestinationId + "')"
  241. }];
  242. this.objectInfo.secureKey = [{
  243. type: 'secureKey',
  244. searchPath: "storeID('" + destinationKey + "')"
  245. }];
  246. } else {
  247. this.objectInfo.gatewayDestination = null;
  248. this.objectInfo.secureKey = null;
  249. }
  250. }
  251. });
  252. return JdbcConnectionStringPane;
  253. });