getParameters.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2014 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var GET_PARAMETERS_RESPONSE_ROOT = "getParametersResponse";
  11. var GET_PARAMETERS_MARKUP = "markup";
  12. var GET_PARAMETERS_DISPLAY = "parametersDisplay";
  13. var GET_PARAMETERS_DISPLAY_PARAMETER = "parameter";
  14. var GET_PARAMETERS_NAME_ATTR = "name";
  15. var GET_PARAMETERS_CAPTION_ATTR = "caption";
  16. var GET_PARAMETERS_MULTIVALUED_ATTR = "multivalued";
  17. var GET_PARAMETERS_REQUIRED_ATTR = "required";
  18. var GET_PARAMETERS_TYPE_ATTR = "type";
  19. var GET_PARAMETERS_FORMAT_ATTR = "format";
  20. var GET_PARAMETERS_MODELVALUE_ATTR = "modelValue";
  21. var GET_PARAMETERS_VALUE_ATTR = "value";
  22. var current_gp_method;
  23. var current_task_id;
  24. var current_param_response_xts;
  25. var doGetParametersRequestURL;
  26. // utility function
  27. //pass in the taskId so that we can cache credential params
  28. //on a per task basis
  29. function getGetParameterRequestString(obj, context, taskId)
  30. {
  31. current_task_id = taskId;
  32. var sURL = "";
  33. var cl = "cl";
  34. var locales = getLocales(cl, "pl");
  35. sURL += URIEncode(cl, locales[cl]);
  36. sURL += URIEncode("obj", obj);
  37. sURL += URIEncode("context", context);
  38. sURL += URIEncode("method", "getParameters");
  39. sURL += URIEncode("displayedPage", "report");
  40. sURL += URIEncode("parameterValues", getConnectionParameterValues(taskId));
  41. sURL += URIEncode("prompt", "false");
  42. // always have to ask for credential parameters too
  43. sURL += URIEncode("credentialParameters", "true");
  44. var messageIFrame = getMessageIFrame();
  45. var messageIFrame_doc = getFrameDocument(messageIFrame);
  46. if(messageIFrame_doc){
  47. var model = messageIFrame_doc.getElementById('model');
  48. var modelValue = "";
  49. if(model && model.value != ""){
  50. modelValue = model.value;
  51. sURL += URIEncode("model", modelValue);
  52. } else {
  53. var routingServerGroup = messageIFrame_doc.getElementById('ui.routingServerGroup');
  54. var routingServerGroupValue = "";
  55. if(routingServerGroup && routingServerGroup.value != ""){
  56. routingServerGroupValue = routingServerGroup.value;
  57. sURL += URIEncode("routingServerGroup", routingServerGroupValue);
  58. }
  59. }
  60. }
  61. current_param_response_xts = URIEncode("buildResponseXTS","/ags/async/getParametersResponse.xts");
  62. // return the request
  63. //SEC_INFO sUrl - The request is not parsed as a string so should not be subject to an injection attack
  64. return sURL;
  65. }
  66. // utility function
  67. function getGetParametersQfSpecificationRequestString(sql_package, sql_procedure_name, context, taskId)
  68. {
  69. current_task_id = taskId;
  70. var sURL = "";
  71. var cl = "cl";
  72. var locales = getLocales(cl, "pl");
  73. sURL += URIEncode(cl, locales[cl]);
  74. sURL += URIEncode("inlineSpecType", "queryFrameworkSpecification");
  75. sURL += URIEncode("sql_package", sql_package);
  76. sURL += URIEncode("sql_procedure_name", sql_procedure_name);
  77. sURL += URIEncode("context", context);
  78. sURL += URIEncode("method", "getParametersSpecification");
  79. sURL += URIEncode("parameterValues", getConnectionParameterValues(taskId));
  80. sURL += URIEncode("displayedPage", "sql");
  81. sURL += URIEncode("prompt", "false");
  82. // always have to ask for credential parameters too
  83. sURL += URIEncode("credentialParameters", "true");
  84. var messageIFrame = getMessageIFrame();
  85. var messageIFrame_doc = getFrameDocument(messageIFrame);
  86. if(messageIFrame_doc){
  87. var model = messageIFrame_doc.getElementById('model');
  88. var modelValue = "";
  89. if(model && model.value != ""){
  90. modelValue = model.value;
  91. sURL += URIEncode("model", modelValue);
  92. } else {
  93. var routingServerGroup = messageIFrame_doc.getElementById('ui.routingServerGroup');
  94. var routingServerGroupValue = "";
  95. if(routingServerGroup && routingServerGroup.value != ""){
  96. routingServerGroupValue = routingServerGroup.value;
  97. sURL += URIEncode("routingServerGroup", routingServerGroupValue);
  98. }
  99. }
  100. }
  101. current_param_response_xts = URIEncode("buildResponseXTS","/ags/async/getSpParametersResponse.xts");
  102. current_param_response_xts += URIEncode("buildRequestXTS","/ags/async/spParamRequest.xts");
  103. //SEC_INFO sUrl - The request is not parsed as a string so should not be subject to an injection attack
  104. return sURL;
  105. }
  106. function getRequestFromMethod(clientContext, current_task_id) {
  107. if (typeof current_gp_method == "function") {
  108. //Get the function name
  109. var fName = current_gp_method.toString().match(/function (\w+)/)[1];
  110. if (fName == 'getGetParametersQfSpecificationRequestString') {
  111. return getGetParametersQfSpecificationRequestString(null,null,clientContext, current_task_id);
  112. } else if (fName == 'getGetParameterRequestString') {
  113. return getGetParameterRequestString(null,clientContext, current_task_id);
  114. }
  115. }
  116. }
  117. function promptGetParametersResponse(parameters, response, conversation, clientContext, tracking)
  118. {
  119. if (response == "Cancel" || response == "Error")
  120. {
  121. // we don't want to close everything down - so just cancel the prompt and parameter load
  122. injectHTML("");
  123. // hide the dialog frame
  124. hideDialogFrame();
  125. }
  126. else
  127. {
  128. // we're passed the parameters - so save them for the task
  129. saveParameterValues(parameters, current_task_id);
  130. // send the context and the final response from prompts back
  131. var request = getRequestFromMethod(clientContext, current_task_id);
  132. //request += URIEncode("context", clientContext);
  133. request += URIEncode("promptResponse", response);
  134. request += URIEncode("disp_trackingInfo", tracking);
  135. // hide the dialog frame
  136. hideDialogFrame();
  137. //SEC_INFO request - javascript encode the request prior to firing setTimeout. The
  138. //setTimeout function will un-encode the request before it is submitted
  139. request = jsStrEncode(request);
  140. // resubmit the request
  141. setTimeout("doGetParametersRequest(\'" + request + "\');",100);
  142. }
  143. }
  144. //called to initiate the asynch request
  145. function startGetParametersRequest(request, gp_method){
  146. applicationActionManager.blockActions();
  147. //ahh the beauty of function pointers!
  148. current_gp_method = gp_method ? gp_method : getGetParameterRequestString;
  149. doGetParametersRequest(request);
  150. }
  151. function resendLoadParameters() {
  152. getCommandStackManager().getCommandStack().push("doGetParametersRequest()");
  153. }
  154. function doGetParametersRequest(request,isSecondary)
  155. {
  156. if (request == undefined || request.length ==0) {
  157. request = doGetParametersRequestURL;
  158. } else if (!isSecondary) {
  159. doGetParametersRequestURL = request;
  160. }
  161. // build up the URL
  162. var url = "b_action=xts.run";
  163. url += URIEncode("m","/ags/async/asyncConv.xts");
  164. //url += URIEncode("buildResponseXTS","/ags/async/getParametersResponse.xts");
  165. // force SOAPFault for passport expire instead of getting a logon page
  166. url += URIEncode("forceSOAPFault","false");
  167. url += current_param_response_xts;
  168. url += request;
  169. if (cafContextId != "") {
  170. url += URIEncode("cafcontextid",cafContextId);
  171. //SEC_INFO url - The request is not parsed as a string so should not be subject to an injection attack
  172. }
  173. try{
  174. // send off the resquest
  175. sendDispatcherRequestWithXMLTextResponse(url, getParametersXMLTextResponse);
  176. }catch(ex){
  177. applicationActionManager.allowActions(ex);
  178. }
  179. }
  180. function getParametersXMLTextResponse(responseArray)
  181. {
  182. // get the values returned
  183. var responseXML = responseArray[0];
  184. var responseText = responseArray[1];
  185. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  186. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  187. var getParametersResponseRoot = responseXML.getElementsByTagName(GET_PARAMETERS_RESPONSE_ROOT);
  188. var httpStop = true;
  189. var parsedResponse = parseResponse(responseXML,responseText);
  190. // decide what we're going to do
  191. //This is a case when getContent in asyncConv faults with either session expiry or
  192. //external logon to a different name space fault.
  193. if (parsedResponse.isLogonFault()) {
  194. doPassportExpire(responseXML,resendLoadParameters,parsedResponse);
  195. } else if (parsedResponse.isSoapFault()) {
  196. if (parsedResponse.isCancelledWait()) {
  197. //This was a server cancelled wait. We need to resubmit. This could happen
  198. //if we have a SSO on and we hit an password protected external datasource,
  199. //The dispacther will fire the same request again, in this wait fired twice
  200. //Will cancel conversation if first wait fails. WO1903, WO2338
  201. resendLoadParameters();
  202. setTimeout("getCommandStackManager().processCommandStack()", 100);
  203. } else {
  204. // we have a fault which is a genuine fault fault
  205. doSOAPFault(responseXML,tidyParametersDiv,parsedResponse);
  206. }
  207. } else if (workingRoot.length == 1) {
  208. httpStop = false;
  209. // we have a working response
  210. doWorking(workingRoot[0], "doGetParametersRequest");
  211. } else if (promptingRoot.length == 1) {
  212. // are we prompting - promptGetParametersResponse
  213. doPrompting(promptingRoot[0], 2);
  214. } else if (getParametersResponseRoot.length == 1) {
  215. httpStop = false;
  216. // we have the actually information
  217. useGetParametersResponse(getParametersResponseRoot[0]);
  218. } else {
  219. tidyParametersDiv();
  220. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  221. // check the text response to see if we got a html page back in the response
  222. doHTMLResponse(responseText);
  223. } else {
  224. // send the alert
  225. alert(asyncGetParametersError_string);
  226. }
  227. }
  228. if(httpStop){
  229. applicationActionManager.allowActions();
  230. }
  231. }
  232. function useGetParametersResponse(responseRootNode)
  233. {
  234. // get the markup and the script which is returned
  235. var markupNode = responseRootNode.getElementsByTagName(GET_PARAMETERS_MARKUP);
  236. // get the actual values from here
  237. var markup = getTextNodeValue(markupNode[0]);
  238. // do the HTML injection - should be interesting
  239. injectHTML(markup);
  240. // also want to call a function in page - to set dropZones
  241. var parameterNodes = responseRootNode.getElementsByTagName(GET_PARAMETERS_DISPLAY_PARAMETER);
  242. var parameterArray = new Array();
  243. for (var i = 0; i < parameterNodes.length; ++i) {
  244. var obj = new Object();
  245. obj.name = parameterNodes[i].getAttribute(GET_PARAMETERS_NAME_ATTR);
  246. if (parameterNodes[i].getAttribute(GET_PARAMETERS_MODELVALUE_ATTR)) {
  247. obj.modelValue = parameterNodes[i].getAttribute(GET_PARAMETERS_MODELVALUE_ATTR);
  248. }
  249. var val = parameterNodes[i].getAttribute('value');
  250. val = val.replace(/\?/g, "");
  251. obj.sqlValue = val;
  252. // save the object
  253. parameterArray.push(obj);
  254. }
  255. // have to execute the function
  256. messageIFrame.initPromptPage(parameterArray);
  257. }
  258. //if we have an error, or if we move to a package with
  259. //no stored procedures, then the getParameters call is never made
  260. //we must manually clean up the pvs
  261. function clearParametersValues(){
  262. var messageIFrame = getMessageIFrame();
  263. var messageIFrame_doc = getFrameDocument(messageIFrame);
  264. if(messageIFrame_doc){
  265. var tps = messageIFrame_doc.getElementById('taskParameters');
  266. if(tps){
  267. tps.value = "";
  268. }
  269. }
  270. }
  271. function injectHTML(markup)
  272. {
  273. // do the HTML injection - should be interesting
  274. var messageIFrame = getMessageIFrame();
  275. var messageIFrame_doc = getFrameDocument(messageIFrame);
  276. // get the insertion location - and inject the HTML
  277. var promptValuesDiv = messageIFrame_doc.getElementById("promptValuesDiv");
  278. promptValuesDiv.innerHTML=markup;
  279. if(messageIFrame.initInjectedHtml){
  280. messageIFrame.initInjectedHtml();
  281. }
  282. applicationActionManager.allowActions();
  283. }
  284. function tidyParametersDiv() {
  285. var html = '<a href="#" onclick="loadParameters()">' + refresh_string + '</a>';
  286. // something went radically wrong - we want to tidy up a little
  287. injectHTML(html);
  288. // hide the dialog frame
  289. hideDialogFrame();
  290. }
  291. ////////////////////////////////////
  292. //collect stuff
  293. ///////////////////////////////////
  294. //called to initiate the asynch request
  295. function doXHTTPCollectParameterValues(){
  296. setAsynchRequestCancelled(false);
  297. addDebugWaitMessage("sending collect parameters request");
  298. doCollectParameterValuesSpecificationRequest(getCollectParameterValuesSpecificationRequestString());
  299. }
  300. function getCollectParameterValuesSpecificationRequestString()
  301. {
  302. var sURL = "";
  303. var cl = "cl";
  304. var locales = getLocales(cl, "pl");
  305. sURL += URIEncode(cl, locales[cl]);
  306. var spec = getConfigFrame().cfgGet("inlineSpec");
  307. sURL += URIEncode("inlineSpec",spec);
  308. //what is this?
  309. //sURL += URIEncode("context", context);
  310. sURL += URIEncode("method", "collectParameterValuesSpecification");
  311. //pass in any cached connection parameters
  312. sURL += URIEncode("parameterValues",getConnectionParameterValues());
  313. sURL += URIEncode("prompt", "false");
  314. sURL += URIEncode("model", cfgGet("cmLastModel"));
  315. // always have to ask for credential parameters too
  316. //sURL += URIEncode("credentialParameters", "true");
  317. // return the request
  318. return sURL;
  319. }
  320. function doCollectParameterValuesSpecificationRequest(request)
  321. {
  322. // build up the URL
  323. var url = "b_action=xts.run";
  324. url += URIEncode("m","/ags/async/asyncConv.xts");
  325. // force SOAPFault for passport expire instead of getting a logon page
  326. url += URIEncode("forceSOAPFault","false");
  327. url += request;
  328. if (cafContextId != "") {
  329. url += URIEncode("cafcontextid",cafContextId);
  330. }
  331. try{
  332. // send off the resquest
  333. sendDispatcherRequestWithXMLTextResponse(url, collectParametersXMLTextResponse);
  334. }catch(ex){
  335. processAsynchCancel();
  336. throw ex;
  337. }
  338. }
  339. function resendDoXHTTPCollectParameterValues() {
  340. getCommandStackManager().getCommandStack().push("doXHTTPCollectParameterValues()");
  341. }
  342. function collectParametersXMLTextResponse(responseArray)
  343. {
  344. // get the values returned
  345. var responseXML = responseArray[0];
  346. var responseText = responseArray[1];
  347. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  348. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  349. var asyncReply = responseXML.getElementsByTagName(ASYNC_RESPONSE);
  350. var cancelledRoot = responseXML.getElementsByTagName(CANCEL_RESPONSE);
  351. var parsedResponse = parseResponse(responseXML,responseText);
  352. // decide what we're going to do
  353. //This is a case when getContent in asyncConv faults with either session expiry or
  354. //external logon to a different name space fault.
  355. if (parsedResponse.isLogonFault()) {
  356. addDebugWaitMessage("Passport expired");
  357. doPassportExpire(responseXML,resendDoXHTTPCollectParameterValues,parsedResponse);
  358. } else if (parsedResponse.isSoapFault()) {
  359. if (parsedResponse.isCancelledWait()) {
  360. //This was a server cancelled wait. We need to resubmit. This could happen
  361. //if we have a SSO on and we hit an password protected external datasource,
  362. //The dispacther will fire the same request again, in this wait fired twice
  363. //Will cancel conversation if first wait fails. WO1903, WO2338
  364. resendDoXHTTPCollectParameterValues();
  365. setTimeout("getCommandStackManager().processCommandStack()", 100);
  366. } else {
  367. addDebugWaitMessage("Soap fault");
  368. // we have a fault which is a genuine fault fault
  369. doSOAPFault(responseXML,null,parsedResponse);
  370. }
  371. } else if (workingRoot.length == 1) {
  372. if(isAsynchRequestCancelled()){
  373. doCancel(workingRoot[0], "doCollectParameterValuesSpecificationRequest");
  374. }else{
  375. addDebugWaitMessage("waiting for parameters");
  376. // we have a working response
  377. doWorking(workingRoot[0], "doCollectParameterValuesSpecificationRequest");
  378. }
  379. } else if (cancelledRoot.length == 1 || isAsynchRequestCancelled()) {
  380. addDebugWaitMessage("cancelled");
  381. // we are cancelled
  382. processAsynchCancel();
  383. } else if (promptingRoot.length == 1) {
  384. addDebugWaitMessage("prompting");
  385. // are we prompting - promptCollectResponse
  386. doPrompting(promptingRoot[0], 3);
  387. } else if (asyncReply.length == 1) {
  388. addDebugWaitMessage("done.");
  389. if(!getCommandStackManager().getCommandStack().isEmpty()){
  390. // none of the above - there are no prompts to prompt
  391. setTimeout("getCommandStackManager().processCommandStack()", 100);
  392. } else {
  393. processAsynchCancel();
  394. }
  395. } else {
  396. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  397. addDebugWaitMessage("html response in getParameters");
  398. // check the text response to see if we got a html page back in the response
  399. doHTMLResponse(responseText);
  400. } else {
  401. // send the alert
  402. alert(asyncGetParametersError_string);
  403. }
  404. }
  405. }
  406. //we have values returned, save and continue
  407. function promptCollectResponse(parameters, response, conversation, clientContext)
  408. {
  409. if (response != "Cancel" && response != "Error")
  410. {
  411. //re write any connection ParameterValues saved
  412. saveParameterValues(parameters);
  413. //close the pop up when the prompt page reloads to finish
  414. doSetPopUpClosureFlag();
  415. //TODO save other params
  416. setTimeout("getCommandStackManager().processCommandStack()", 500);
  417. }else{
  418. //close the pop up
  419. doClosePopUp();
  420. //and clear the stack
  421. setTimeout("getCommandStackManager().getCommandStack().clear()", 100);
  422. }
  423. }