agentDefinition.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. /* ****************************************
  11. This is a couple of js object "classes" that will allow the creation of an action definition
  12. object in js that can write to and read from hidden form fields
  13. **************************************** */
  14. var AGENT_DEFINITION_REPORT = "agentDefinitionReport";
  15. function AgentDefinition(){
  16. //this is a non duplication items object
  17. this.summaryEventKey;
  18. this.m_agent_actions = new Array();
  19. this.agentDefinitionReport;
  20. this.setSummaryEventKeyValueFromPortalStyleTopics = function(portal_style_topics){
  21. var translated_item = decodeURIComponent(portal_style_topics);
  22. //convert it to ags stylee
  23. this.summaryEventKey.parseFromString(translated_item);
  24. }
  25. this.getSummaryEventKeyValueWithPortalStyleTopics = function(){
  26. //convert to portal stylee
  27. return this.summaryEventKey.toString();
  28. }
  29. /**
  30. * get the all items on all agent actions and check that they are not
  31. * in the event key
  32. */
  33. this.validateOngoingFilterTopics = function(){
  34. //check that the items in the summary
  35. var valid = true;
  36. var sek = this.summaryEventKey;
  37. for(var x_index = 0; x_index < this.getActionCount() & valid == true; x_index++){
  38. var an_action = this.getActionAt(x_index);
  39. if(an_action.nonDuplication && an_action.nonDuplication.size() > 0){
  40. var items = an_action.nonDuplication.items();
  41. for(j = 0; j < items.length & valid == true; j++){
  42. var la_item = items[j];
  43. valid = !sek.containsItem(la_item);
  44. }
  45. }
  46. }
  47. return valid;
  48. }
  49. /**
  50. * get all on all agent actions and check that it is not
  51. * in the event key, if it is remove it
  52. */
  53. this.removeInvalidFilterTopics = function(){
  54. for(var x_index= 0; x_index< this.getActionCount(); x_index++){
  55. var an_action = this.getActionAt(x_index);
  56. var finished = false;
  57. while(an_action.nonDuplication && !finished){
  58. //remove an item
  59. finished = !this.removeFirstInvalidTopic(an_action);
  60. }
  61. }
  62. }
  63. /**
  64. * sweep to the first invalid topic found and remove it
  65. * return true if a topic was found
  66. */
  67. this.removeFirstInvalidTopic = function(an_action){
  68. var removed = false;
  69. var items = an_action.nonDuplication.items();
  70. for(var x_index = 0; x_index < items.length; x_index++){
  71. var la_item = items[x_index];
  72. if(this.summaryEventKey.containsItem(la_item)){
  73. this.removeActionFilterItem(la_item);
  74. removed = true;
  75. break;
  76. }
  77. }
  78. return removed;
  79. }
  80. /**
  81. * get all items on the summary event key and check that they not
  82. * in any of the actions ongoing filter, if it returns the first action name its found in
  83. otherwise return undefined
  84. */
  85. this.validateSummaryEventKey = function (){
  86. //check that the items in the summary
  87. var offending_task = undefined;
  88. var items = this.summaryEventKey.items();
  89. for(var i = 0; i < items.length && offending_task == undefined; i++){
  90. offending_task = validateSummaryEventKeyTopic(items[i]);
  91. }
  92. return offending_task;
  93. }
  94. /**
  95. * check a new topic to be added to the sek that they are not already in an actions topic filter
  96. */
  97. this.validateSummaryEventKeyTopic = function (newEventKeyTopic){
  98. //check that the items in the summary
  99. var offending_task = undefined;
  100. for(i = 0; i < this.getActionCount(); i++){
  101. var an_action = this.getActionAt(i);
  102. if(an_action.nonDuplication && an_action.nonDuplication.containsItem(newEventKeyTopic)){
  103. if(offending_task != undefined){
  104. offending_task += ", "
  105. offending_task += an_action.name;
  106. }else{
  107. offending_task = an_action.name;
  108. }
  109. }
  110. }
  111. return offending_task;
  112. }
  113. /**
  114. * passed an item that shouldnt be in the action filters
  115. * remove it forthwith
  116. */
  117. this.removeActionFilterItem = function(nonDupeItem){
  118. for(var i = 0; i < this.getActionCount(); i++){
  119. var an_action = this.getActionAt(i);
  120. if(an_action.nonDuplication.size() > 0){
  121. an_action.nonDuplication.removeItem(nonDupeItem);
  122. an_action.setParam("Action_topic_filter", an_action.nonDuplication.toString());
  123. }
  124. }
  125. }
  126. /*
  127. *just a way of debug showing whats in the object
  128. */
  129. this.toString = function(){
  130. var description = new AttributeString();
  131. if(this.summaryEventKey){
  132. description.setAttribute("summaryEventKey",this.summaryEventKey.toString());
  133. }
  134. for(var i = 0; i < this.getActionCount(); i++){
  135. var task = this.getActionAt(i);
  136. description.setAttribute("action", task.toString());
  137. }
  138. return description.toString();
  139. }
  140. /*
  141. return an object from the string representation
  142. */
  143. this.fromString = function(attributeString){
  144. var attributes = new AttributeString(attributeString);
  145. if(this.summaryEventKey){
  146. this.summaryEventKey = this.summaryEventKey.parseFromString(attributes.getAttribute("summaryEventKey"));
  147. }
  148. var agent_actions_strings = attributes.getAttributes("action");
  149. for(var i = 0; i < agent_actions_strings.length; i++){
  150. var agentAction = new ActionDefinition();
  151. agentAction.fromString(agent_actions_strings[i]);
  152. this.addAction(agentAction);
  153. }
  154. return this;
  155. }
  156. /*
  157. array accessor
  158. */
  159. this.getActionCount = function(){
  160. return this.m_agent_actions.length;
  161. }
  162. /*
  163. array accessor
  164. */
  165. this.getActionAt = function(index){
  166. return this.m_agent_actions[index];
  167. }
  168. /*
  169. array accessor
  170. */
  171. this.removeActionAt = function(index){
  172. var new_array = new Array();
  173. for(var i = 0; i < this.m_agent_actions.length; i++){
  174. if(i != index){
  175. new_array.push(this.m_agent_actions[i]);
  176. }
  177. }
  178. this.m_agent_actions = new_array;
  179. }
  180. /*
  181. * add a new action to the collective
  182. */
  183. this.addAction = function(action){
  184. action.name_id = action.name + "_" + this.getActionCount();
  185. this.m_agent_actions[this.getActionCount()] = action;
  186. return true;
  187. }
  188. /*
  189. array accessor
  190. */
  191. this.getActionById = function(id){
  192. var selected_action;
  193. if(!id){
  194. window.alert("action with no id!");
  195. return;
  196. }
  197. for(var i = 0; i < this.getActionCount(); i++){
  198. var action = this.getActionAt(i);
  199. if(action.name_id == id){
  200. selected_action = action;
  201. break;
  202. }
  203. }
  204. return selected_action;
  205. }
  206. }
  207. function ActionDefinition(name, id, type, img_src,taskLevelFilter,runCondition){
  208. this.type = type ? type : "";
  209. this.id = id ? id : "";
  210. this.name_id= "";
  211. this.name = name ? name : "";
  212. this.img_src = img_src ? img_src : "";
  213. this.params = new Params();
  214. this.nonDuplication;
  215. this.taskLevelFilter = taskLevelFilter;
  216. this.runCondition = runCondition;
  217. this.getParams = function(){
  218. return this.params;
  219. }
  220. this.setParams = function(params){
  221. this.params = params;
  222. }
  223. this.setParam = function(name, value){
  224. this.params.setParam(name, value);
  225. }
  226. this.addParam = function(name, value){
  227. this.params.addParam(name, value);
  228. }
  229. this.addPortalStyleParam = function(name, value){
  230. this.params.addParam(name, decodeURIComponent(value));
  231. }
  232. this.removeParam = function(name){
  233. this.params.removeParam(name);
  234. }
  235. /*
  236. just a way of debug showing whats in the object
  237. */
  238. this.toString = function(){
  239. var description = new AttributeString();
  240. description.setAttribute("type",this.type);
  241. description.setAttribute("id",this.id);
  242. description.setAttribute("name",this.name);
  243. description.setAttribute("path" ,this.path) ;
  244. description.setAttribute("params",this.params.toString()) ;
  245. description.setAttribute("taskLevelFilter",this.taskLevelFilter) ;
  246. description.setAttribute("runCondition",this.runCondition) ;
  247. return description.toString();
  248. }
  249. /*
  250. return an object from the string representation
  251. */
  252. this.fromString = function(attributeString){
  253. var attributes = new AttributeString(attributeString);
  254. this.type = attributes.getAttribute("type");
  255. this.id = attributes.getAttribute("id");
  256. this.name_id= attributes.getAttribute("name_id");
  257. this.name = attributes.getAttribute("name");
  258. this.path = attributes.getAttribute("path");
  259. this.img_src = attributes.getAttribute("img_src");
  260. this.taskLevelFilter = attributes.getAttribute("taskLevelFilter");
  261. this.runCondition = attributes.getAttribute("runCondition");
  262. var params_string= attributes.getAttribute("params");
  263. this.params = new Params().fromString(params_string);
  264. return this;
  265. }
  266. }
  267. function Params(vals){
  268. this.m_params = new Array();
  269. if(isArray(vals)){
  270. for(var i = 0; i < this.vals.length; ){
  271. var name = vals[i++];
  272. var value = vals[i++];
  273. this.setParam(name, value);
  274. }
  275. }
  276. this.addParam = function(name, value){
  277. this.setParam(name, value);
  278. }
  279. this.setParam = function(p_name, p_value){
  280. if(p_value == undefined || p_value == ""){
  281. p_value = null;
  282. }
  283. if(p_value != null){
  284. p_value = decodeURIComponent(p_value);
  285. }
  286. var param = this.getParam(p_name);
  287. if(param == undefined && p_value != null){
  288. this.m_params.push(new Param(p_name, p_value));
  289. }else{
  290. if(p_value == null){
  291. this.removeParam(p_name);
  292. }else{
  293. param.param_value = p_value;
  294. }
  295. }
  296. }
  297. this.getParamCount= function(){
  298. return this.m_params.length;
  299. }
  300. this.getParamValue = function(name){
  301. for(var i = 0; i < this.m_params.length; i++){
  302. if(this.m_params[i].param_name == name){
  303. return this.m_params[i].param_value;
  304. }
  305. }
  306. }
  307. this.getParam = function(name){
  308. for(var i = 0; i < this.m_params.length; i++){
  309. if(this.m_params[i].param_name == name){
  310. return this.m_params[i];
  311. }
  312. }
  313. }
  314. this.getParamAt = function(index){
  315. return this.m_params[index];
  316. }
  317. this.removeParam = function(name){
  318. var new_array = new Array();
  319. for(var i = 0; i < this.m_params.length; i++){
  320. if(this.m_params[i].param_name != name){
  321. new_array.push(this.m_params[i]);
  322. }
  323. }
  324. this.m_params = new_array;
  325. }
  326. /*
  327. just a way of debug showing whats in the object
  328. */
  329. this.toString = function(){
  330. var description = new AttributeString(undefined);
  331. for(var i = 0; i < this.m_params.length; i++){
  332. if(i != 0){description += "&";}
  333. description.setAttribute("param",this.m_params[i].toString());
  334. }
  335. return description.toString();
  336. }
  337. /*
  338. return an object from the string representation
  339. */
  340. this.fromString = function(attributeString){
  341. var attributes = new AttributeString(attributeString);
  342. var params = attributes.getAttributes("param");
  343. for(var i = 0; i < params.length; i++){
  344. var param_attributes = new AttributeString(params[i]);
  345. this.setParam(param_attributes.getAttribute("param_name"), param_attributes.getAttribute("param_value"));
  346. }
  347. return this;
  348. }
  349. function isArray(a) {
  350. if (a != null && typeof a == "object") return true;
  351. return false;
  352. }
  353. }
  354. function Param(name, value){
  355. this.param_name = name;
  356. this.param_value = value;
  357. /**
  358. check for ![ ]! and use the agent tree to return the portal style
  359. */
  360. this.getPortalStyleValue = function(){
  361. if(this.param_value == undefined || this.param_value == null){
  362. return this.param_value;
  363. }
  364. return this.param_value;
  365. }
  366. /*
  367. just a way of debug showing whats in the object
  368. */
  369. this.toString = function(){
  370. var description = new AttributeString();
  371. description.setAttribute("param_name",this.param_name);
  372. description.setAttribute("param_value",this.param_value);
  373. return description;
  374. }
  375. }
  376. function AttributeString(attribute_String) {
  377. this.value_array = new Array();
  378. if(undefined != attribute_String){
  379. // parse out name/value pairs separated via &
  380. var args = attribute_String.split('&');
  381. for (var i=0;i<args.length;i++){
  382. this.value_array.push(args[i].split('='));
  383. }
  384. }
  385. this.setAttribute = function(name, value){
  386. this.value_array.push(new Array(name, encodeURIComponent(value)));
  387. }
  388. this.getAttributes = function(name){
  389. var attributes = new Array();
  390. // split out each name = value pair
  391. for (var i=0;i<this.value_array.length;i++){
  392. if(this.value_array[i][0] == name){
  393. attributes.push(decodeURIComponent(this.value_array[i][1]));
  394. break;
  395. }
  396. }
  397. return attributes;
  398. }
  399. this.getAttribute = function(name){
  400. var attribute;
  401. // split out each name = value pair
  402. for (var i=0;i<this.value_array.length;i++){
  403. if(this.value_array[i][0] == name){
  404. attribute = decodeURIComponent(this.value_array[i][1]);
  405. break;
  406. }
  407. }
  408. return attribute;
  409. }
  410. this.toString = function(){
  411. var buffer = "";
  412. // split out each name = value pair
  413. for (var i=0;i<this.value_array.length;i++){
  414. if(i != 0)buffer += "&";
  415. buffer += this.value_array[i][0];
  416. buffer += "=";
  417. buffer += this.value_array[i][1];
  418. }
  419. return buffer;
  420. }
  421. }