asynchCommon.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2015 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. // General async constants.
  11. var ASYNC_CONTEXT = "context";
  12. var ASYNC_WORKING = "working";
  13. var ASYNC_PROMPTING = "prompting";
  14. var ASYNC_CONVERSATION = "conversation";
  15. var ASYNC_TRACKING = "tracking";
  16. var ASYNC_RESPONSE = "asyncResponse";
  17. var ASYNC_HTMLFRAGMENT = "htmlFragment";
  18. var ASYNC_ROUTINGSERVERGROUP = "routingServerGroup";
  19. var CANCEL_RESPONSE = "cancelResponse";
  20. // fault constants.
  21. var FAULT_SOAPFAULT = "soapFault";
  22. var FAULT_PASSPORT = "passport";
  23. var isAsynchRequestCancelledState = false;
  24. function setAsynchRequestCancelled(isCancelled){
  25. isAsynchRequestCancelledState = isCancelled;
  26. }
  27. function isAsynchRequestCancelled(){
  28. return isAsynchRequestCancelledState;
  29. }
  30. //a cancel call has been fulfilled
  31. function processAsynchCancel(){
  32. getCommandStackManager().getCommandStack().cancel();
  33. doClosePopUp();
  34. isAsynchRequestCancelledState = false;
  35. }
  36. /*
  37. function doLoginFromFault(){
  38. var soapFault = cfgGet("doLoginFromFault");
  39. if(soapFault != undefined && soapFault != null){
  40. applicationActionManager.allowActions();
  41. //Create a holder and set the htmlFragment.
  42. //You may set 'm' if you need to.
  43. var holder = new Object();
  44. //cam_passport will not be there if session expired. so then
  45. //when we fire the call to doLoginProxy, the dispatcher checks
  46. //the passport and if it is not there it prompts for a login.
  47. if (document.cookie.indexOf("cam_passport=") != -1) {
  48. //We have a passport, so then we attempt to add an htmlFragment.
  49. //This means that the session is fine and that we need to login,
  50. //maybe because we hit a secured external datasource.
  51. //Regex to remove <?xml version="1.0"..?>
  52. holder['htmlFragment'] = decode(getXML(soapFault).replace(new RegExp("<\\?xml.*\\?>\r\n","i"),""));
  53. }
  54. checkLogin(holder,"getCommandStackManager().processCommandStack()");
  55. }
  56. }
  57. */
  58. function doLoginFromFault(){
  59. // Get the XML Node fault object returned by EMF fault handler.
  60. var xmlNode = cfgGet( "doLoginFromFault" );
  61. // Create XMLResponseParser object from the node for easier processing.
  62. var parsedResponse = new XMLResponseParser( xmlNode, "" );
  63. // Get the HTML fault from the EMF rendered response.
  64. var htmlFaultObj = parsedResponse.getHtmlFault();
  65. if ( htmlFaultObj != null ) {
  66. var htmlFaultHtml = parsedResponse.getTextValueForXPath( "//fault//html" );
  67. var popUpFrame = getPopUpFrame();
  68. setResetOM( "/ags/doLoginProxy.xts" );
  69. popUpFrame.document.open();
  70. popUpFrame.document.write( htmlFaultHtml );
  71. popUpFrame.document.close();
  72. }
  73. return true;
  74. }
  75. function doPassportExpire(responseNode, tidyFunction,parsedResponse)
  76. {
  77. applicationActionManager.allowActions();
  78. if (typeof tidyFunction == "function") {
  79. tidyFunction();
  80. }
  81. if (responseNode) {
  82. if(parsedResponse.getErrorCode() == 'caf'){
  83. //
  84. cfgSet("CAN_CANCEL_LOGON", true);
  85. }
  86. //Set the fault so that we can pick it up later.
  87. //This call is in an XMLHTTP call back and so needs to end
  88. //in order to allow for another call to be initiated by
  89. //checkLogin.
  90. cfgSet("doLoginFromFault", responseNode);
  91. setTimeout("doLoginFromFault()",100);
  92. }else{
  93. setTimeout("checkLogin('getCommandStackManager().processCommandStack()')",100);
  94. }
  95. }
  96. function doSOAPFault(obj, tidyFunction,parsedResponse)
  97. {
  98. // we're not going any further here
  99. // so allow actions at least and clear the command stack
  100. getCommandStackManager().getCommandStack().doFail();
  101. applicationActionManager.allowActions();
  102. if (typeof tidyFunction == "function") {
  103. tidyFunction();
  104. }
  105. processAsynchCancel();
  106. //If we have error messages we send them through
  107. //otherwise send the entire fault as is.
  108. var msgs = parsedResponse.getErrorMessages();
  109. if (msgs.length > 0) {
  110. metadataFault(msgs);
  111. functionsTree.childrenReadyForNode(functionsTree.getRootNode());
  112. // say that we've not loaded the tree
  113. cfgSet("META_FunctionTreeLoadedFirstTime",null);
  114. }else{
  115. metadataFault(parsedResponse.getFaultAsMessage);
  116. }
  117. }
  118. function doCancel(obj, requestFunction, soapAction)
  119. {
  120. // get the conversation element
  121. var conversationElements = obj.getElementsByTagName(ASYNC_CONVERSATION);
  122. // get the tracking element
  123. var trackingElements = obj.getElementsByTagName(ASYNC_TRACKING);
  124. // get the context element
  125. var contextElements = obj.getElementsByTagName(ASYNC_CONTEXT);
  126. // get the routingServerGroup element
  127. var routingServerGroupElements = obj.getElementsByTagName(ASYNC_ROUTINGSERVERGROUP);
  128. // we want the actual values
  129. var conversation = getTextNodeValue(conversationElements[0]);
  130. var tracking = getTextNodeValue(trackingElements[0]);
  131. var context = getTextNodeValue(contextElements[0]);
  132. var routingServerGroup = getTextNodeValue(routingServerGroupElements[0]);
  133. // build the request
  134. var request = URIEncode("conversation", conversation);
  135. request += URIEncode("disp_trackingInfo", tracking);
  136. request += URIEncode("context", context);
  137. // only send the routingServerGroup if there was one defined
  138. if (routingServerGroup != null && routingServerGroup != "") {
  139. request += URIEncode("routingServerGroup", routingServerGroup);
  140. }
  141. request += URIEncode("method", "cancel");
  142. if(soapAction){
  143. request += URIEncode("soapAction", soapAction);
  144. }
  145. // send the request
  146. setTimeout(requestFunction + "(\'" + request + "\',true);", 100);
  147. }
  148. function doWorking(obj, requestFunction)
  149. {
  150. // get the conversation element
  151. var conversationElements = obj.getElementsByTagName(ASYNC_CONVERSATION);
  152. // get the tracking element
  153. var trackingElements = obj.getElementsByTagName(ASYNC_TRACKING);
  154. // get the context element
  155. var contextElements = obj.getElementsByTagName(ASYNC_CONTEXT);
  156. // get the routingServerGroup element
  157. var routingServerGroupElements = obj.getElementsByTagName(ASYNC_ROUTINGSERVERGROUP);
  158. // we want the actual values
  159. var conversation = getTextNodeValue(conversationElements[0]);
  160. var tracking = getTextNodeValue(trackingElements[0]);
  161. var context = getTextNodeValue(contextElements[0]);
  162. var routingServerGroup = getTextNodeValue(routingServerGroupElements[0]);
  163. // build the request
  164. var request = URIEncode("doWait","1");
  165. request += URIEncode("conversation", conversation);
  166. request += URIEncode("disp_trackingInfo", tracking);
  167. request += URIEncode("context", context);
  168. // only send the routingServerGroup if there was one defined
  169. if (routingServerGroup != null && routingServerGroup != "") {
  170. request += URIEncode("routingServerGroup", routingServerGroup);
  171. }
  172. //SEC_INFO request - javascript encode the request prior to firing setTimeout. The
  173. //setTimeout function will un-encode the request before it is submitted
  174. request = jsStrEncode(request);
  175. // send the request
  176. setTimeout(requestFunction + "(\'" + request + "\',true);", 100);
  177. }
  178. function doPrompting(obj, callbackFunctionId, xslURL)
  179. {
  180. // get the conversation element
  181. var conversationElements = obj.getElementsByTagName(ASYNC_CONVERSATION);
  182. // get the tracking element
  183. var trackingElements = obj.getElementsByTagName(ASYNC_TRACKING);
  184. // get the htmlFragment element
  185. var htmlFragmentElement = obj.getElementsByTagName(ASYNC_HTMLFRAGMENT);
  186. // get the context element
  187. var contextElements = obj.getElementsByTagName(ASYNC_CONTEXT);
  188. // get the routingServerGroup element
  189. var routingServerGroupElements = obj.getElementsByTagName(ASYNC_ROUTINGSERVERGROUP);
  190. // we want the actual values
  191. var conversation = getTextNodeValue(conversationElements[0]);
  192. var tracking = getTextNodeValue(trackingElements[0]);
  193. var htmlFragment = getTextNodeValue(htmlFragmentElement[0]);
  194. var context = getTextNodeValue(contextElements[0]);
  195. var routingServerGroup = getTextNodeValue(routingServerGroupElements[0]);
  196. // clear the dialogFrame
  197. dlgReset();
  198. // set all the following values
  199. dlgSetParm("m", "prompting/promptDataSource.xts");
  200. // callback function: WO2397
  201. dlgSetParm("ccs_cbdata", callbackFunctionId);
  202. dlgSetParm("ccs_invoke", "parent");
  203. // clientContext
  204. dlgSetParm("clientContext", context);
  205. // isEncoded
  206. dlgSetParm("isEncoded", "1");
  207. // conversation
  208. dlgSetParm("conversation", conversation);
  209. // tracking
  210. dlgSetParm("tracking", tracking);
  211. // release conversation
  212. dlgSetParm("releaseConversation", "1");
  213. // process recursion
  214. dlgSetParm("processRecursion", "1");
  215. // html fragment
  216. dlgSetParm("htmlFragment", htmlFragment);
  217. // set the routingServerGroup into the prompting kit (only set this if it's defined)
  218. if (routingServerGroup != null && routingServerGroup != "") {
  219. dlgSetParm("routingServerGroup", routingServerGroup);
  220. }
  221. // get the full response
  222. dlgSetParm("returnEntireResponse", "1");
  223. if (xslURL) {
  224. dlgSetParm("run.xslURL", xslURL);
  225. }
  226. changeMenu(TAB_MODEL)
  227. //if this has been in a command stack
  228. //the stack eval call may have re blocked by the time it comes back from the dispatcher
  229. var wasBlocked = applicationActionManager.isBlocked();
  230. applicationActionManager.allowActions();
  231. dlgSubmit("popUpFrame");
  232. if(wasBlocked ){
  233. applicationActionManager.blockActions();
  234. }
  235. }
  236. // WO 2397-Prompting JavaScript Callback
  237. function pdsCallback(pdsState)
  238. {
  239. // don't actually check on state - that's passed into the individual functions cause they might deal with error's/cancels differently
  240. // just call the function directly - pass in arguments based on attributes of pdsState. They're renamed "response" to "state" which is confusingly annoying.
  241. //1. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptFunctionResponse");
  242. //2. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptGetParametersResponse");
  243. //3. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptCollectResponse");
  244. //4. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptGetSpDetailsResponse");
  245. //5. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptMemberResponse");
  246. //6. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptMetadataResponse");
  247. //7. doPrompting(promptingRoot[0],"parent.getConfigFrame().promptSelectDataResponse","selectValue.xslt");
  248. //8. doPrompting(promptingRoot[0],'parent.getConfigFrame().promptValidateConditionResponse');
  249. var cmdId = pdsState.ccs_cbdata ;
  250. // command id would be passed back to us as pdsState.ccs_cbdata
  251. switch(cmdId){
  252. case '1': promptFunctionResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  253. case '2': promptGetParametersResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  254. case '3': promptCollectResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  255. case '4': promptGetSpDetailsResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  256. case '5': promptMemberResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  257. case '6': promptMetadataResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  258. case '7': promptSelectDataResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  259. case '8': promptValidateConditionResponse(pdsState.parameters, pdsState.state, pdsState.conversation, pdsState.clientContext, pdsState.tracking); break;
  260. default: alert('pdsCallBack: unknown cmd id '+cmdId);
  261. }
  262. }
  263. function doHTMLResponse(responseText)
  264. {
  265. // we got a html response back - so open a window to display it
  266. var error_window = window.open("", "asyncError", "height=480,width=640,resizable=yes");
  267. var error_window_doc = error_window.document;
  268. // write the text into the window
  269. error_window_doc.write(responseText);
  270. }
  271. function addDebugWaitMessage(message){
  272. var mArea = getPopUpFrame().document.getElementById("wait_debug_message");
  273. if(mArea){
  274. //mArea.innerHTML += "<br>" + message;
  275. mArea.innerHTML = message;
  276. }
  277. }
  278. function removeXMLNameSpaces(obj,responseText) {
  279. if(!obj)return null;
  280. var cleanXML = null;
  281. //Calls may contain namespace others do not, so we clean up all namespaces
  282. //and reload the xml into a new document.
  283. if(document.documentMode > 10){
  284. cleanXML = responseText.replace(new RegExp("</[a-zA-Z0-9-]*:","gim"),"</");
  285. cleanXML = cleanXML.replace(new RegExp("<[a-zA-Z0-9-]*:","gim"),"<");
  286. }else{
  287. cleanXML = getXML(obj).replace(new RegExp("</[a-zA-Z0-9-]*:","gim"),"</");
  288. cleanXML = cleanXML.replace(new RegExp("<[a-zA-Z0-9-]*:","gim"),"<");
  289. }
  290. //we have a new document
  291. obj = parseXMLString(cleanXML);
  292. if (window.clipboardData) {
  293. //This is so that we can use the contains xpath function, in IE xpath query of XML
  294. obj.setProperty("SelectionLanguage","XPath");
  295. }
  296. return obj;
  297. }
  298. function getXML(obj) {
  299. if (window.clipboardData) {
  300. return obj.xml;
  301. } else {
  302. return (new XMLSerializer( )).serializeToString(obj);
  303. }
  304. }
  305. function parseResponse(obj,responseText) {
  306. return new XMLResponseParser(obj,responseText);
  307. }
  308. function XMLResponseParser(obj,responseText) {
  309. this.responseXML = obj;
  310. //remove namespaces
  311. this.obj = removeXMLNameSpaces(obj,responseText);
  312. this.responseText = responseText?responseText:"";
  313. this.getTextValueForXPath = function(xpath) {
  314. var result = "";
  315. if (this.obj) {
  316. var node = selectSingleNode(xpath,this.obj);
  317. if (node) {
  318. result = getTextNodeValue(node);
  319. }
  320. }
  321. return (result);
  322. };
  323. this.isLogonFault = function() {
  324. var result = false;
  325. if (this.obj) {
  326. //find the cam action element
  327. var camAction = selectSingleNode("//item[./name = 'h_CAM_action']",this.obj);//.selectSingleNode("//item[./name = 'h_CAM_action']");
  328. if (camAction) {
  329. //Check the value if it is a logon or logonAs
  330. var value = selectSingleNode("./value",camAction);//camAction.selectSingleNode("./value");
  331. result = value && getTextNodeValue(value).indexOf("logon") > -1;
  332. }
  333. }
  334. return (result);
  335. };
  336. this.isCancelledWait = function() {
  337. var result = false;
  338. if (this.obj) {
  339. //find the wait element
  340. var isWait = selectSingleNode("//formFieldVars//item[./name = 'doWait']",this.obj);
  341. if (isWait) {
  342. result = selectSingleNode("//exception//message/messageString[contains(.,'RSV-BBP-0036') and contains(.,'asynchWait_Request')]",this.obj);
  343. }
  344. }
  345. return (result);
  346. };
  347. this.isSoapFault = function(){
  348. var result = false;
  349. if (this.obj) {
  350. //find the soap fault element
  351. var soapFault = selectSingleNode("//Body/Fault",this.obj);//this.obj.selectSingleNode("//Body/Fault");
  352. if (soapFault) {
  353. result = true;
  354. }
  355. }
  356. return (result);
  357. };
  358. this.getErrorCode = function(){
  359. var result = "";
  360. if (this.obj) {
  361. //find the soap fault error code
  362. var errorCodeNode = selectSingleNode("//Body//errorCode",this.obj);//this.obj.selectSingleNode("//Body//errorCode");
  363. if (errorCodeNode) {
  364. result = getTextNodeValue(errorCodeNode);
  365. }
  366. }
  367. return (result);
  368. };
  369. this.getErrorSeverity = function(){
  370. var result = "";
  371. if (this.obj) {
  372. //find the soap fault error code
  373. var errorSeverityNode = selectSingleNode("//Body//exception//severity",this.obj);//this.obj.selectSingleNode("//Body//exception//severity");
  374. if (errorCodeNode) {
  375. result = getTextNodeValue(errorSeverityNode);
  376. }
  377. }
  378. return (result);
  379. };
  380. this.getErrorMessages = function(){
  381. var result = new Array();
  382. if (this.obj) {
  383. //find the soap fault error code
  384. var msgStringNodes = selectNodes("//Body//exception//message//messageString",this.obj);//this.obj.selectNodes("//Body//exception//message//messageString");
  385. if (!msgStringNodes || msgStringNodes.length == 0 ) {
  386. //This is an error like null pointer from ASV.
  387. msgStringNodes = selectNodes("//Body//Fault//stackTrace",this.obj);
  388. }
  389. for (var i=0;msgStringNodes && i < msgStringNodes.length;i++) {
  390. result.push(getTextNodeValue(msgStringNodes[i]));
  391. }
  392. }
  393. return (result);
  394. };
  395. this.getErrorMessageNodes = function(){
  396. var result = new Array();
  397. if (this.obj) {
  398. //find the soap fault error code
  399. var msgStringNodes = selectNodes("//Body//exception//message//messageString",this.obj);//this.obj.selectNodes("//Body//exception//message//messageString");
  400. if (!msgStringNodes || msgStringNodes.length == 0 ) {
  401. //This is an error like null pointer from ASV.
  402. msgStringNodes = selectNodes("//Body//Fault//stackTrace",this.obj);
  403. }
  404. for (var i=0;msgStringNodes && i < msgStringNodes.length;i++) {
  405. result.push(msgStringNodes[i]);
  406. }
  407. }
  408. return (result);
  409. };
  410. this.getFaultAsMessage = function(){
  411. var result = new Array();
  412. if (this.obj) {
  413. result.push(getXML(obj));
  414. }
  415. return (result);
  416. };
  417. // Get the HTML fault for the EMF renderer.
  418. this.getHtmlFault = function() {
  419. var result = "";
  420. if (this.obj) {
  421. result = selectSingleNode("//fault//html", this.obj);
  422. }
  423. return ( result );
  424. };
  425. this.isHTML = function() {
  426. return new RegExp("<\s*\/?\s*html\s*.*?>","gim").test(this.cleanUpHTML());
  427. };
  428. this.isEmptyBody = function() {
  429. var response = true;
  430. if (this.isHTML()) {
  431. var cleanHTHML = this.cleanUpHTML();
  432. cleanHTHML.match(new RegExp("<body[^>]*>(.*)</body>","gim"));
  433. response = RegExp.$1.replace(/^\s+|\s+$/g,"").length == 0;
  434. }
  435. return response;
  436. };
  437. this.contains = function(pattern) {
  438. return this.responseText.indexOf(pattern) > -1;
  439. };
  440. this.cleanUpHTML = function() {
  441. var html = this.responseText.replace(new RegExp("[\r\n]*","gim"),"");
  442. html = html.replace(new RegExp("</[a-zA-Z0-9-]*:","gim"),"</");
  443. html = html.replace(new RegExp("<[a-zA-Z0-9-]*:","gim"),"<");
  444. return html;
  445. }
  446. }