validatePreview.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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. // utility function
  11. var PREVIEW_RESULT = "previewResult";
  12. var AGENT_STATE_PARAM = "param";
  13. var AGENT_STATE_NAME_ATTR = "name";
  14. var VALIDATE_CONDITION_ELEMENT = "validateCondition";
  15. var VALIDATE_CONDITION_DEFECTS = "defects";
  16. var VALIDATE_CONDITION_MESSAGE_ELEMENT = "message";
  17. var VALIDATE_CONDITION_CODE_ATTR = "code";
  18. var VALIDATE_CONDITION_LOCATION_ATTR = "location";
  19. var VALIDATE_CONDITION_SEVERITY_ATTR = "severity";
  20. var VALIDATE_CONDITION_TITLE_ATTR = "title";
  21. var VALIDATE_CONDITION_TYPE_ATTR = "type";
  22. var SOAP_SEVERITY = "severity";
  23. var SOAP_EXCEPTION_MESSAGE = "messageString";
  24. var VALIDATE_ERRORS_KEY = "VALIDATE_SOAP_EXCEPTION_MESSAGES";
  25. //"http://www.ibm.com/xmlns/prod/cognos/agentService/201101/";
  26. var AGENT_SERVICE_SOAP_ACTION = "AGENT_SERVICE_SOAPACTION";
  27. var AGENT_SERVICE = "http://developer.cognos.com/schemas/agentService/1";
  28. var doPreviewRequestURL;
  29. var doXHTTPValidateURL;
  30. function doPreview(style)
  31. {
  32. var cf = window.parent.getConfigFrame();
  33. if (style == "" || style == null) return;
  34. // If we are on condition page then we need to call RUN from cf
  35. var isConditionPage=false;
  36. var pageId = self.messageIFrame.document.getElementById("tabSelectedID");
  37. if(null!=pageId && pageId.value=='AgentTask-condition'){
  38. isConditionPage = true;
  39. }
  40. if (style == "preview_count") {
  41. // this is special - we always calls count regardless of where we are.
  42. cf.cfgSet("inlineSpec_forCount",true);
  43. cf.getCommandStackManager().initiateCommandStack("getReportSpec()","cf.runCount()");
  44. } else if (style == "preview_task" && isConditionPage) {
  45. // this is special for condition page - we fire up reportViewer and let it handle everything
  46. cf.getCommandStackManager().initiateCommandStack("getReportSpec()","cf.run()");
  47. } else {
  48. // we do our own preview - and the extent of the preview depends on whether or not we're running preview_task or preview_all.
  49. cf.getCommandStackManager().initiateCommandStack("getReportSpec()","commandStackHideDialogFrame()", "doWait('preview')", "getConditionParameters()", "doWait('preview')", "calcAgentState()", "preview('" + style + "')");
  50. }
  51. }
  52. function resendCalcAgentState() {
  53. getCommandStackManager().getCommandStack().push("calcAgentState()");
  54. }
  55. function calcAgentState()
  56. {
  57. // have to get the calcAgentState morphlet
  58. dlgReset();
  59. //set in form vars
  60. initialiseDialog();
  61. // set in the location of the morphlet
  62. dlgSetParm("m", "/ags/calcAgentState.xts");
  63. dlgSetParm("forceSOAPFault","false");
  64. // make sure that we don't have b_action set - we're adding that in the XHTTP dispatcher
  65. dlgRemoveParm("b_action");
  66. // dispatch the request (actually using internal dlg variable - slapped wrist).
  67. var dispatcher = new XHTTPDispatcher(calcAgentStateXMLResponse, dialogFormValues);
  68. applicationActionManager.httpStart();
  69. try {
  70. dispatcher.dispatch();
  71. } catch(ex){
  72. applicationActionManager.httpStop();
  73. }
  74. }
  75. function calcAgentStateXMLResponse(responseArray)
  76. {
  77. var responseXML = responseArray[0];
  78. var responseText = responseArray[1];
  79. // wibble
  80. applicationActionManager.httpStop();
  81. // create an object to return the calculated state into
  82. var agentState = new Object();
  83. // get the values element
  84. var paramElements = responseXML.getElementsByTagName(AGENT_STATE_PARAM);
  85. //Although it is unlikely but there is a chance this may fault when calling
  86. //back to current visible task in Event Studio.
  87. var parsedResponse = parseResponse(responseXML,responseText);
  88. // decide what we're going to do
  89. if (parsedResponse.isLogonFault()) {
  90. doPassportExpire(responseXML,resendCalcAgentState,parsedResponse);
  91. } else if (parsedResponse.isSoapFault()) {
  92. // we have a fault which is a genuine fault fault
  93. doSOAPFault(responseXML,null,parsedResponse);
  94. } else if(paramElements.length>0){
  95. for (var i = 0; i < paramElements.length; i++) {
  96. var paramName = paramElements[i].getAttribute(AGENT_STATE_NAME_ATTR);
  97. var paramValue = getTextNodeValue(paramElements[i]);
  98. // save the variable into the agent state
  99. agentState[paramName] = paramValue;
  100. }
  101. // save the agentState into global config for the time being
  102. cfgSet("AGENT_STATE", agentState);
  103. //do the next command whatever it is
  104. setTimeout("getCommandStackManager().processCommandStack();", 250);
  105. } else {
  106. // check the text response to see if we got a html page back in the response
  107. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  108. doHTMLResponse(responseText);
  109. // cleanup
  110. getCommandStackManager().getCommandStack().clear();
  111. // hide the wait dialog
  112. if(doClosePopUp){
  113. doClosePopUp();
  114. }
  115. } else {
  116. // tell the client what's going on
  117. alert(asyncSelectValuesError_string);
  118. }
  119. }
  120. }
  121. function resendSavePPState() {
  122. getCommandStackManager().getCommandStack().push("savePPState()");
  123. }
  124. function savePPState()
  125. {
  126. // have to get the calcAgentState morphlet
  127. dlgReset();
  128. //set in form vars
  129. initialiseDialog();
  130. // set in the location of the morphlet
  131. dlgSetParm("m", "/ags/savePPState.xts");
  132. dlgSetParm("forceSOAPFault","false");
  133. // make sure that we don't have b_action set - we're adding that in the XHTTP dispatcher
  134. dlgRemoveParm("b_action");
  135. // dispatch the request (actually using internal dlg variable - slapped wrist).
  136. var dispatcher = new XHTTPDispatcher(savePPStateXMLResponse, dialogFormValues);
  137. applicationActionManager.httpStart();
  138. try {
  139. dispatcher.dispatch();
  140. } catch(ex){
  141. applicationActionManager.httpStop();
  142. }
  143. }
  144. function savePPStateXMLResponse(responseArray)
  145. {
  146. var responseXML = responseArray[0];
  147. var responseText = responseArray[1];
  148. // wibble
  149. applicationActionManager.httpStop();
  150. // create an object to return the calculated state into
  151. var ppState = new Object();
  152. // get the values element
  153. var paramElements = responseXML.getElementsByTagName(AGENT_STATE_PARAM);
  154. //Although it is unlikely but there is a chance this may fault when calling
  155. //the xts.
  156. var parsedResponse = parseResponse(responseXML,responseText);
  157. // decide what we're going to do
  158. if (parsedResponse.isLogonFault()) {
  159. doPassportExpire(responseXML,resendSavePPState,parsedResponse);
  160. } else if (parsedResponse.isSoapFault()) {
  161. // we have a fault which is a genuine fault fault
  162. doSOAPFault(responseXML,null,parsedResponse);
  163. } else if(paramElements.length>0){
  164. for (var i = 0; i < paramElements.length; i++) {
  165. var paramName = paramElements[i].getAttribute(AGENT_STATE_NAME_ATTR);
  166. var paramValue = getTextNodeValue(paramElements[i]);
  167. // save the variable into the agent state
  168. ppState[paramName] = paramValue;
  169. }
  170. // save the variables into the config
  171. for (var x in ppState) {
  172. cfgSet(x, ppState[x]);
  173. }
  174. //do the next command whatever it is
  175. setTimeout("getCommandStackManager().processCommandStack();", 250);
  176. } else {
  177. // check the text response to see if we got a html page back in the response
  178. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  179. doHTMLResponse(responseText);
  180. // cleanup
  181. getCommandStackManager().getCommandStack().clear();
  182. // hide the wait dialog
  183. if(doClosePopUp){
  184. doClosePopUp();
  185. }
  186. } else {
  187. // tell the client what's going on
  188. alert(asyncSelectValuesError_string);
  189. }
  190. }
  191. }
  192. function doXHTTPPreview(method, agentState, ifrmcmd, tabSelectedID)
  193. {
  194. if(isAsynchRequestCancelled()){
  195. //if the cancel has been clicked between prompts and validate / preview
  196. processAsynchCancel();
  197. return;
  198. }
  199. // get the request string
  200. var sURL = getValidatePreviewRequestString(method, agentState, ifrmcmd, tabSelectedID);
  201. addDebugWaitMessage("sending preview request");
  202. // do the request
  203. doPreviewRequest(sURL);
  204. }
  205. function doXHTTPValidate(method, agentState, ifrmcmd, tabSelectedID)
  206. {
  207. if(isAsynchRequestCancelled()){
  208. //if the cancel has been clicked between prompts and validate / preview
  209. processAsynchCancel();
  210. return;
  211. }
  212. // get the request string
  213. var sURL = getValidatePreviewRequestString(method, agentState, ifrmcmd, tabSelectedID);
  214. addDebugWaitMessage("sending validate request");
  215. doXHTTPValidateURL = sURL;
  216. if (ifrmcmd == IFRM_ACTION_VALIDATE_SAVE) {
  217. // do the request
  218. doValidateSaveRequest(sURL);
  219. }else{
  220. // do the request
  221. doValidateRequest(sURL);
  222. }
  223. }
  224. function doXHTTPValidateCondition()
  225. {
  226. if(isAsynchRequestCancelled()){
  227. //if the cancel has been clicked between prompts and validate / preview
  228. processAsynchCancel();
  229. return;
  230. }
  231. var sURL = getValidateConditionRequestString();
  232. addDebugWaitMessage("sending validate request");
  233. // do the request
  234. doValidateConditionRequest(sURL);
  235. }
  236. function getValidatePreviewRequestString(method, agentState, ifrmcmd, tabSelectedID)
  237. {
  238. var sURL = "";
  239. var cl="";
  240. var pl="";
  241. //define the expression locale
  242. var el="";
  243. var clk = "cl";
  244. var plk = "pl";
  245. var locales = getLocales(clk, plk);
  246. sURL += URIEncode(clk, locales[clk]);
  247. sURL += URIEncode(plk, locales[plk]);
  248. sURL += URIEncode("el",getExpressionLocale());
  249. // need to send in the method - determine from the value of ifrmcmd
  250. if (ifrmcmd.match(/validate_save/)) {
  251. sURL += URIEncode("method", "validateAgent");
  252. sURL += URIEncode("severity", "error");
  253. } else if (ifrmcmd.match(/validate/)) {
  254. sURL += URIEncode("method", "validateAgent");
  255. // we also need to set an option for validate as well
  256. sURL += URIEncode("severity", "warning");
  257. } else if (ifrmcmd.match(/preview/)) {
  258. sURL += URIEncode("method", "previewAgent");
  259. } else {
  260. sURL += URIEncode("method", method);
  261. }
  262. // pass in the arguments from the agentState object
  263. for (var i in agentState) {
  264. sURL += URIEncode(i, agentState[i]);
  265. }
  266. // send in the command - either validate/preview
  267. sURL += URIEncode("ifrmcmd", ifrmcmd);
  268. // send in the currently selected tab
  269. sURL += URIEncode("tabSelectedID", tabSelectedID);
  270. // send in any relevant parameters
  271. sURL += URIEncode("parameterValues", getAllParameters());
  272. // pass in some other information which we seem to need
  273. sURL += URIEncode("model", cfgGet("cmLastModel"));
  274. sURL += URIEncode("packageRoot", cfgGet("PackageRoot"));
  275. if(ifrmcmd != IFRM_ACTION_VALIDATE_SAVE){
  276. var reportSpec = getConfigFrame().cfgGet("inlineSpec");
  277. sURL += URIEncode("inlineSpec", reportSpec);
  278. }
  279. return sURL;
  280. }
  281. function getValidateConditionRequestString()
  282. {
  283. var sURL = "";
  284. var clk = "cl";
  285. var plk = "pl";
  286. var locales = getLocales(clk, plk);
  287. sURL += URIEncode(clk, locales[clk]);
  288. sURL += URIEncode(plk, locales[plk]);
  289. // set the method that we're going to be calling
  290. sURL += URIEncode("method", "validateSpecification");
  291. // set the report spec
  292. var reportSpec = getConfigFrame().cfgGet("inlineSpec");
  293. sURL += URIEncode("inlineSpec", reportSpec);
  294. // set the run options
  295. sURL += URIEncode("checkMemberUniqueNames", "true");
  296. sURL += URIEncode("severity", "error");
  297. sURL += URIEncode("model", cfgGet("cmLastModel"));
  298. var params = getConnectionParameterValues();
  299. if(params){
  300. // send in any connection parameters we will be prompted for the others by rs
  301. sURL += URIEncode("parameterValues", params);
  302. sURL += URIEncode("prompt", "false");
  303. }
  304. return sURL;
  305. }
  306. function resendDoPreviewRequest() {
  307. getCommandStackManager().getCommandStack().push("doPreviewRequest()");
  308. }
  309. function doPreviewRequest(request,isSecondary)
  310. {
  311. if (request == undefined || request.length ==0) {
  312. request = doPreviewRequestURL;
  313. } else if (!isSecondary) {
  314. doPreviewRequestURL = request;
  315. }
  316. var url = "b_action=xts.run";
  317. url += URIEncode("m","/ags/async/asyncConv.xts");
  318. url += URIEncode("buildRequestXTS","/ags/async/validatePreviewRequest.xts");
  319. url += URIEncode("buildResponseXTS","/ags/async/previewResponse.xts");
  320. // and the soapAction seeing as we're not calling reportServer
  321. url += URIEncode("soapAction", AGENT_SERVICE_SOAP_ACTION);
  322. url += URIEncode("requestNamespace", AGENT_SERVICE);
  323. // force SOAPFault for passport expire instead of getting a logon page
  324. url += URIEncode("forceSOAPFault","false");
  325. url += request;
  326. if (cafContextId != "") {
  327. url += URIEncode("cafcontextid",cafContextId);
  328. }
  329. try{
  330. // send off the resquest - keep hold of the request object this time
  331. dataRequest = sendDispatcherRequestWithXMLTextResponse(url, previewXMLTextResponse);
  332. }catch(ex){
  333. processAsynchCancel();
  334. throw ex;
  335. }
  336. }
  337. function doValidateSaveRequest(request)
  338. {
  339. if (request == undefined || request.length ==0) {
  340. request = doXHTTPValidateURL;
  341. }
  342. var url = "b_action=xts.run";
  343. url += URIEncode("m","/ags/async/asyncConv.xts");
  344. url += URIEncode("buildRequestXTS","/ags/async/validatePreviewRequest.xts");
  345. url += URIEncode("buildResponseXTS","/ags/async/validateResponse.xts");
  346. // and the soapAction seeing as we're not calling reportServer
  347. url += URIEncode("soapAction", AGENT_SERVICE_SOAP_ACTION);
  348. url += URIEncode("requestNamespace", AGENT_SERVICE);
  349. // force SOAPFault for passport expire instead of getting a logon page
  350. url += URIEncode("forceSOAPFault","false");
  351. url += request;
  352. if (cafContextId != "") {
  353. url += URIEncode("cafcontextid",cafContextId);
  354. }
  355. try{
  356. // send off the resquest - keep hold of the request object this time
  357. dataRequest = sendDispatcherRequestWithXMLTextResponse(url, saveValidateXMLTextResponse);
  358. }catch(ex){
  359. processAsynchCancel();
  360. throw ex;
  361. }
  362. }
  363. function doValidateRequest(request)
  364. {
  365. if (request == undefined || request.length ==0) {
  366. request = doXHTTPValidateURL;
  367. }
  368. var url = "b_action=xts.run";
  369. url += URIEncode("m","/ags/async/asyncConv.xts");
  370. url += URIEncode("buildRequestXTS","/ags/async/validatePreviewRequest.xts");
  371. url += URIEncode("buildResponseXTS","/ags/async/validateResponse.xts");
  372. // and the soapAction seeing as we're not calling reportServer
  373. url += URIEncode("soapAction", AGENT_SERVICE_SOAP_ACTION);
  374. url += URIEncode("requestNamespace", AGENT_SERVICE);
  375. // force SOAPFault for passport expire instead of getting a logon page
  376. url += URIEncode("forceSOAPFault","false");
  377. url += request;
  378. if (cafContextId != "") {
  379. url += URIEncode("cafcontextid",cafContextId);
  380. }
  381. try{
  382. // send off the resquest - keep hold of the request object this time
  383. dataRequest = sendDispatcherRequestWithXMLTextResponse(url, nonSaveValidateXMLTextResponse);
  384. }catch(ex){
  385. processAsynchCancel();
  386. throw ex;
  387. }
  388. }
  389. function doValidateConditionRequest(request)
  390. {
  391. var url = "b_action=xts.run";
  392. url += URIEncode("m","/ags/async/asyncConv.xts");
  393. url += URIEncode("buildResponseXTS","/ags/async/validateConditionResponse.xts");
  394. // force SOAPFault for passport expire instead of getting a logon page
  395. url += URIEncode("forceSOAPFault","false");
  396. // and the soapAction seeing as we're not calling reportServer
  397. url += request;
  398. if (cafContextId != "") {
  399. url += URIEncode("cafcontextid",cafContextId);
  400. }
  401. try{
  402. // send off the resquest - keep hold of the request object this time
  403. dataRequest = sendDispatcherRequestWithXMLTextResponse(url, validateConditionXMLTextResponse);
  404. }catch(ex){
  405. processAsynchCancel();
  406. throw ex;
  407. }
  408. }
  409. function previewXMLTextResponse(responseArray)
  410. {
  411. // get the values returned
  412. var responseXML = responseArray[0];
  413. var responseText = responseArray[1];
  414. // the request is finished - we can just remove it
  415. dataRequest = null;
  416. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  417. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  418. var valuesRoot = responseXML.getElementsByTagName(ASYNC_RESPONSE);
  419. var cancelledRoot = responseXML.getElementsByTagName(CANCEL_RESPONSE);
  420. var parsedResponse = parseResponse(responseXML,responseText);
  421. // decide what we're going to do
  422. //This is a case when getContent in asyncConv faults with either session expiry or
  423. //external logon to a different name space fault.
  424. if (parsedResponse.isLogonFault()) {
  425. doPassportExpire(responseXML,resendDoPreviewRequest,parsedResponse);
  426. } else if (parsedResponse.isSoapFault()) {
  427. if (parsedResponse.isCancelledWait()) {
  428. //This was a server cancelled wait. We need to resubmit. This could happen
  429. //if we have a SSO on and we hit an password protected external datasource,
  430. //The dispacther will fire the same request again, in this wait fired twice
  431. //Will cancel conversation if first wait fails. WO1903, WO2338
  432. resendDoPreviewRequest();
  433. setTimeout("getCommandStackManager().processCommandStack()", 100);
  434. } else {
  435. // we have a fault which is a genuine fault fault
  436. doSOAPFault(responseXML,null,parsedResponse);
  437. }
  438. } else if (workingRoot.length == 1) {
  439. if(isAsynchRequestCancelled()){
  440. doCancel(workingRoot[0], "doPreviewRequest", AGENT_SERVICE_SOAP_ACTION);
  441. }else{
  442. addDebugWaitMessage("waiting for preview");
  443. // we have a working response
  444. doWorking(workingRoot[0], "doPreviewRequest");
  445. }
  446. } else if (cancelledRoot.length == 1 || isAsynchRequestCancelled()) {
  447. addDebugWaitMessage("cancelled in preview");
  448. // we are cancelled
  449. processAsynchCancel();
  450. } else if (valuesRoot.length == 1) {
  451. handlePreviewResponse(valuesRoot[0]);
  452. } else {
  453. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  454. // check the text response to see if we got a html page back in the response
  455. doHTMLResponse(responseText);
  456. } else {
  457. // tell the client what's going on
  458. alert(asyncSelectValuesError_string);
  459. }
  460. }
  461. }
  462. function resendValidateNoneSaveRequest() {
  463. getCommandStackManager().getCommandStack().push("doValidateRequest()");
  464. getCommandStackManager().getCommandStack().push("doWait('validate')");
  465. }
  466. function resendValidateSaveRequest() {
  467. getCommandStackManager().getCommandStack().push("doValidateSaveRequest()");
  468. if (cfgGet("NewReport") != true){
  469. getCommandStackManager().getCommandStack().push("doWait('save')");
  470. }
  471. }
  472. function validateXMLTextResponse(responseArray, isSave)
  473. {
  474. // get the values returned
  475. var responseXML = responseArray[0];
  476. var responseText = responseArray[1];
  477. // the request is finished - we can just remove it
  478. dataRequest = null;
  479. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  480. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  481. var valuesRoot = responseXML.getElementsByTagName(ASYNC_RESPONSE);
  482. var cancelledRoot = responseXML.getElementsByTagName(CANCEL_RESPONSE);
  483. var requestFunction = isSave ? "doValidateSaveRequest" : "doValidateRequest";
  484. var resendRequestFunction = isSave ? resendValidateSaveRequest : resendValidateNoneSaveRequest;
  485. var parsedResponse = parseResponse(responseXML,responseText);
  486. // decide what we're going to do
  487. //This is a case when getContent in asyncConv faults with either session expiry or
  488. //external logon to a different name space fault.
  489. if (parsedResponse.isLogonFault()) {
  490. doPassportExpire(responseXML,resendRequestFunction,parsedResponse);
  491. } else if (parsedResponse.isSoapFault()) {
  492. //This was a server cancelled wait. We need to resubmit. This could happen
  493. //if we have a SSO on and we hit an password protected external datasource,
  494. //The dispacther will fire the same request again, in this wait fired twice
  495. //Will cancel conversation if first wait fails. WO1903, WO2338
  496. if (parsedResponse.isCancelledWait()) {
  497. resendRequestFunction();
  498. setTimeout("getCommandStackManager().processCommandStack()", 100);
  499. } else {
  500. // we have a fault which is a genuine fault fault
  501. doValidateFault(responseXML,isSave, parsedResponse);
  502. }
  503. } else if (workingRoot.length == 1) {
  504. if(isAsynchRequestCancelled()){
  505. doCancel(workingRoot[0], requestFunction, AGENT_SERVICE_SOAP_ACTION);
  506. }else{
  507. addDebugWaitMessage("waiting for validate");
  508. // we have a working response
  509. doWorking(workingRoot[0], requestFunction);
  510. }
  511. } else if (cancelledRoot.length == 1 || isAsynchRequestCancelled()) {
  512. addDebugWaitMessage("cancelled in validate");
  513. // we are cancelled
  514. processAsynchCancel();
  515. } else if (valuesRoot.length == 1) {
  516. //check if we have any local errors
  517. doValidate(isSave);
  518. //just pass on the call to the handling xts.... there will be no errors, and if there is a cmdStack
  519. // then go on, otherwise show the "no errors"
  520. setTimeout("getCommandStackManager().processCommandStack();", 100);
  521. } else {
  522. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  523. // check the text response to see if we got a html page back in the response
  524. doHTMLResponse(responseText);
  525. } else {
  526. // tell the client what's going on
  527. // asyncSelectValuesError_string is constant string with value 'Unknown error in selectValues'
  528. setTimeout("displayUnknownAlert()");
  529. }
  530. }
  531. }
  532. function displayUnknownAlert()
  533. {
  534. alert(asyncSelectValuesError_string);
  535. }
  536. function saveValidateXMLTextResponse(responseArray)
  537. {
  538. validateXMLTextResponse(responseArray, false);
  539. }
  540. function nonSaveValidateXMLTextResponse(responseArray)
  541. {
  542. validateXMLTextResponse(responseArray, false);
  543. }
  544. function resendValidateConditionRequest() {
  545. getCommandStackManager().getCommandStack().push("doXHTTPValidateCondition()");
  546. }
  547. function validateConditionXMLTextResponse(responseArray)
  548. {
  549. // get the values returned
  550. var responseXML = responseArray[0];
  551. var responseText = responseArray[1];
  552. // the request is finished - we can just remove it
  553. dataRequest = null;
  554. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  555. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  556. var valuesRoot = responseXML.getElementsByTagName(ASYNC_RESPONSE);
  557. var cancelledRoot = responseXML.getElementsByTagName(CANCEL_RESPONSE);
  558. var parsedResponse = parseResponse(responseXML,responseText);
  559. // decide what we're going to do
  560. //This is a case when getContent in asyncConv faults with either session expiry or
  561. //external logon to a different name space fault.
  562. if (parsedResponse.isLogonFault()) {
  563. getCommandStackManager().getCommandStack().push("reloadMetadataTree(true)");
  564. doPassportExpire(responseXML,resendValidateConditionRequest,parsedResponse);
  565. // load the nodes after login succeeds
  566. keeploadingmdtNodes = true;
  567. } else if (parsedResponse.isSoapFault()) {
  568. //This was a server cancelled wait. We need to resubmit. This could happen
  569. //if we have a SSO on and we hit an password protected external datasource,
  570. //The dispacther will fire the same request again, in this wait fired twice
  571. //Will cancel conversation if first wait fails. WO1903, WO2338
  572. if (parsedResponse.isCancelledWait()) {
  573. resendValidateConditionRequest();
  574. setTimeout("getCommandStackManager().processCommandStack()", 100);
  575. } else {
  576. // we have a fault which is a genuine fault fault
  577. doSOAPFault(responseXML,null,parsedResponse);
  578. }
  579. } else if (workingRoot.length == 1) {
  580. if(isAsynchRequestCancelled()){
  581. doCancel(workingRoot[0], "doValidateConditionRequest", AGENT_SERVICE_SOAP_ACTION);
  582. }else{
  583. // we have a working response
  584. doWorking(workingRoot[0], "doValidateConditionRequest");
  585. }
  586. }
  587. else if (cancelledRoot.length == 1 || isAsynchRequestCancelled()) {
  588. addDebugWaitMessage("cancelled while validating condition");
  589. // we are cancelled
  590. processAsynchCancel();
  591. }
  592. else if (promptingRoot.length == 1) {
  593. // are we prompting
  594. //8. doPrompting(promptingRoot[0],'parent.getConfigFrame().promptValidateConditionResponse');
  595. doPrompting(promptingRoot[0], 8);
  596. }
  597. else if (valuesRoot.length == 1) {
  598. // have to process the messages
  599. handleValidateConditionResponse(valuesRoot[0]);
  600. } else {
  601. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  602. // check the text response to see if we got a html page back in the response
  603. doHTMLResponse(responseText);
  604. } else {
  605. // tell the client what's going on
  606. alert(asyncSelectValuesError_string);
  607. }
  608. }
  609. }
  610. function handleValidateConditionResponse(obj)
  611. {
  612. // shut down the popUP - eww eww eww
  613. doClosePopUp();
  614. var existing_messages = cfgGet(VALIDATE_ERRORS_KEY);
  615. // look to see if there are error messages
  616. var messageElements = obj.getElementsByTagName(VALIDATE_CONDITION_MESSAGE_ELEMENT);
  617. if (messageElements.length == 0 && !existing_messages) {
  618. // set the error condition to empty
  619. setConditionError(null);
  620. }
  621. else {
  622. // have to get all the messages
  623. var allMessages = new Array();
  624. var mustShowMessages = new Array();
  625. if(existing_messages){
  626. allMessages = existing_messages.allMessages;
  627. }
  628. for (var i = 0; i < messageElements.length; i++) {
  629. // get the attributes of the message
  630. var code = messageElements[i].getAttribute(VALIDATE_CONDITION_CODE_ATTR);
  631. var location = messageElements[i].getAttribute(VALIDATE_CONDITION_LOCATION_ATTR);
  632. var severity = messageElements[i].getAttribute(VALIDATE_CONDITION_SEVERITY_ATTR);
  633. var title = messageElements[i].getAttribute(VALIDATE_CONDITION_TITLE_ATTR);
  634. var type = messageElements[i].getAttribute(VALIDATE_CONDITION_TYPE_ATTR);
  635. var message = getTextNodeValue(messageElements[i]);
  636. // if we don't have a blank message
  637. if (message!='') {
  638. allMessages.push(new DefectMessage(message, 'warn', location));
  639. }
  640. if (type=='layout' && title != '' && message!='') {
  641. mustShowMessages.push(new DefectMessage(message, 'warn', location));
  642. }
  643. }
  644. // get the valid messages
  645. var validMessages = getValidMessages(allMessages);
  646. if(allMessages.length > validMessages.length){
  647. var message = validationErrorsElsewhere_string + "\n" + validationErrorsElsewhereAction_string;
  648. alert(message);
  649. }
  650. cfgRemove(VALIDATE_ERRORS_KEY);
  651. setConditionError(validMessages.concat(mustShowMessages));
  652. }
  653. // call the next command
  654. setTimeout("getCommandStackManager().processCommandStack();", 100);
  655. }
  656. function promptValidateConditionResponse(parameters, response, conversation, clientContext, tracking)
  657. {
  658. if (response == "Cancel" || response == "Error"){
  659. //close the pop up
  660. doClosePopUp();
  661. //and cancel the stack - users can set specific cancel behaviour, but the default is to clear
  662. getCommandStackManager().getCommandStack().cancel();
  663. }
  664. else
  665. {
  666. // send the context and the final response from prompts back
  667. var request = URIEncode("context", clientContext);
  668. request += URIEncode("promptResponse", response);
  669. request += URIEncode("disp_trackingInfo", tracking);
  670. getCommandStackManager().getCommandStack().push("doValidateConditionRequest('" + request + "');");
  671. // resubmit the request
  672. setTimeout("getCommandStackManager().processCommandStack()", 100);
  673. }
  674. }
  675. // go through the messages in the parser and check the location
  676. // against the validate state object, use it if it matches
  677. function getValidMessages(messages)
  678. {
  679. var validMessages = new Array();
  680. var validateState = cfgGet("ValidateCommandStackObject");
  681. cfgRemove("ValidateCommandStackObject");
  682. for(var i = 0; i < messages.length; i++){
  683. var location = messages[i].location;
  684. if(location && validateState){
  685. if(validateState.checkLocation(location)){
  686. validMessages.push(messages[i]);
  687. }
  688. }else {
  689. //benefit of doubt
  690. validMessages.push(messages[i]);
  691. }
  692. }
  693. return validMessages;
  694. }
  695. // obj we get is the <soapFault> element - parsed
  696. function doValidateFault(obj, isSave, parsedResponse)
  697. {
  698. // get all the soap fault message elements
  699. var messageStrings = parsedResponse.getErrorMessageNodes();
  700. if(!messageStrings || messageStrings.length == 0){
  701. doSOAPFault(obj);
  702. return;
  703. }
  704. // get the messages and severity
  705. var validateErrors = new Array();
  706. for(var i = 0; i < messageStrings.length; i++){
  707. // get the message + attributes
  708. var severityObj = selectSingleNode("ancestor::exception/severity", messageStrings[i]);
  709. var severityText = getTextNodeValue(severityObj);
  710. var severity = new Severity(severityText);
  711. if(isSave && severity.level >= ags_severity_enum.WARN){
  712. continue;
  713. }
  714. var messageText = getTextNodeValue(messageStrings[i]);
  715. // build the defect message
  716. validateErrors.push(new DefectMessage(messageText, severityText, null));
  717. }
  718. var defectMessagesHolder = cfgGet(VALIDATE_ERRORS_KEY);
  719. if(!defectMessagesHolder){
  720. defectMessagesHolder = new DefectMessages(validateErrors);
  721. }else{
  722. defectMessagesHolder.addMessages(validateErrors);
  723. }
  724. if(!isSave){
  725. defectMessagesHolder = addUIValidationMessages(defectMessagesHolder) ;
  726. }
  727. // save them.
  728. cfgSet(VALIDATE_ERRORS_KEY, defectMessagesHolder);
  729. // call the next command
  730. setTimeout("getCommandStackManager().processCommandStack();", 100);
  731. }
  732. function handlePreviewResponse(obj)
  733. {
  734. // shut down the popUP - eww eww eww
  735. doClosePopUp();
  736. // get the search path returned from the preview
  737. var previewResultElements = obj.getElementsByTagName(PREVIEW_RESULT);
  738. // if we got a searchPath back - get it and launch reportViewer
  739. if (previewResultElements[0].childNodes.length > 0) {
  740. var preview_searchPath = getTextNodeValue(previewResultElements[0]);
  741. // call report viewer
  742. if(preview_searchPath){
  743. viewReportOutput(preview_searchPath);
  744. }
  745. }
  746. }
  747. function doValidate(isSave) {
  748. //This is special if we don't return any soapfalts and we have local errors
  749. // such as no condition in condion page
  750. if(!isSave) {
  751. // get the messages and severity
  752. var validateErrors = new Array();
  753. var defectMessagesHolder = new DefectMessages(validateErrors);
  754. defectMessagesHolder = addUIValidationMessages(defectMessagesHolder);
  755. // save them.
  756. cfgSet(VALIDATE_ERRORS_KEY, defectMessagesHolder);
  757. }
  758. }
  759. //find and add a blank condition message if there is one
  760. function addUIValidationMessages(defectMessages){
  761. if(!cf.buildFilterCondition() || cf.buildFilterCondition() == ""){
  762. if(!defectMessages){
  763. defectMessages = new cf.DefectMessages(new Array());
  764. }
  765. //only one message from ui so far... if more use an array or Stack
  766. var ui_message = new cf.DefectMessage(cf.validateErrantCondition_string, "warn", null);
  767. defectMessages.addMessage(ui_message);
  768. }
  769. return defectMessages;
  770. }
  771. //Check if the agent has event key when do save action.
  772. function checkEventKey() {
  773. var element = document.getElementById('agentItemsTree0');
  774. if(element == undefined) {
  775. keyValidate();
  776. }
  777. getCommandStackManager().processCommandStack();
  778. }
  779. // Add event key warning
  780. function keyValidate() {
  781. var validateErrors = new Array();
  782. var defectMessagesHolder = new DefectMessages(validateErrors);
  783. var ui_message = new cf.DefectMessage(cf.suppEvtKeyWarn_string, "warn", null);
  784. // add event key warning to VALIDATE_ERRORS_KEY
  785. defectMessagesHolder.addMessage(ui_message);
  786. cfgSet(VALIDATE_ERRORS_KEY, defectMessagesHolder);
  787. }