[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / public / util / js / dgeToXml.js
1 function getDgStartNode(nodeList){
2                 for(var i=0;i<nodeList.length;i++){
3                         if(nodeList[i].type == 'dgstart' && nodeList[i].wires != null &&  nodeList[i].wires != undefined){
4                                 return nodeList[i];
5                         }       
6                 }
7                 RED.notify("DGSTART node not found.");
8                 return null;
9 }
10
11
12 var loopDetectionEnabled = true;
13
14 function detectLoopPrev(){
15                 var activeWorkspace=RED.view.getWorkspace();
16                 /*
17                 RED.nodes.links.filter(function(d) {
18                          if(d.source.z == activeWorkspace && d.target.z == activeWorkspace){
19                                  console.log(d.source.id+":"+d.sourcePort+":"+d.target.id);
20                          }
21                 });
22                 */      
23                 //console.dir(RED.nodes.links);
24                 var nSet=[];
25                 
26                 RED.nodes.eachNode(function(n) {
27                         if (n.z == activeWorkspace) {
28                                 nSet.push({'n':n});
29                         }
30                 });
31
32                 var nodeSet = RED.nodes.createExportableNodeSet(nSet);
33                 //console.dir(nodeSet);
34                 
35                 //console.log("nodeSet length:" + nodeSet.length);
36
37                 var isLoopDetected = false;     
38                 var dgStartNode = getDgStartNode(nodeSet);
39                 if(dgStartNode == null || dgStartNode == undefined) {
40                         console.log("dgstart node not linked.");
41                         return true;
42                 }
43
44                 var wires = dgStartNode.wires;
45                 var nodesInPath = {};
46                 var dgStartNodeId = dgStartNode.id;
47                 if(wires != null && wires != undefined && wires[0] != undefined){
48                         for(var k=0;k<wires[0].length;k++){
49                                 var val = wires[0][k];
50                                 nodesInPath[dgStartNodeId + "->" + val] = "";
51                         }
52                 }else{
53                                 nodesInPath[dgStartNodeId + "->" + ""] = "";
54                 }
55                         
56                 //console.dir(nodesInPath);
57                 var loopDetectedObj = {};
58                 /* the nodes will not be order so will need to loop thru again */
59         for(var m=0;nodeSet != null && m<nodeSet.length;m++){
60                 for(var i=0;nodeSet != null && i<nodeSet.length;i++){
61                         var link=nodeSet[i].id;
62                         //console.log("NAME:" + nodeSet[i].name + ":" + link);
63                         if(link == dgStartNodeId) continue;
64                         var wires = nodeSet[i].wires;
65                         //console.log("link:" + link);
66                         var delKeys = [];
67                         if(wires != null && wires != undefined && wires[0] != undefined){
68                                 for(var k=0;k<wires[0].length;k++){
69                                         var val = (wires[0])[k];
70                                         var keys = Object.keys(nodesInPath);
71                                         //console.log("keys:" + keys);
72                                         for (var j=0;j<keys.length;j++){
73                                                 //console.log("key:" + keys[j]);
74                                                 //console.log("val:" + val);
75                                                 var index = -1;
76                                                 if(keys[j] != null){
77                                                         index = keys[j].indexOf("->" + link);
78                                                 }
79                                                 var lastIndex = keys[j].lastIndexOf("->");
80                                                 if(index != -1 && index == lastIndex){
81                                                         //delete nodesInPath[key];
82                                                         var previousNodeId = keys[j].substr(lastIndex +2);
83                                                         var indexOfArrow = -1;
84                                                         if(previousNodeId != ""){
85                                                                 indexOfArrow = previousNodeId.indexOf("->");
86                                                         }
87                                                         if(previousNodeId != null && indexOfArrow != -1){
88                                                                 previousNodeId = previousNodeId.substr(0,indexOfArrow);
89                                                         }       
90                                                         nodesInPath[keys[j] + "->" + val] = "";
91                                                         //console.log("keys[j]:" + keys[j]);
92                                                         delKeys.push(keys[j]);
93                                                         var prevNodeIdIndex = keys[j].indexOf("->" + previousNodeId);
94                                                         var priorOccurence = keys[j].indexOf(val + "->");
95                                                         if(priorOccurence != -1 && priorOccurence<prevNodeIdIndex){
96                                                                 //console.log("previousNodeId:" + previousNodeId);
97                                                                 //console.log("val:" + val);
98                                                                 var n1 = getNode(nodeSet,previousNodeId);
99                                                                 var n2 = getNode(nodeSet,val);
100                                                                 //console.log("loop detected for node " + n1.name + " and " + n2.name); 
101                                                                 loopDetectedObj[n1.name + "->" + n2.name] ="looped";
102                                                                 //console.dir(loopDetectedObj);
103                                                                 isLoopDetected = true;
104                                                         }               
105                                                 } 
106                                         }
107                                 }
108                         }
109                         for(var l=0;delKeys != null && l<delKeys.length;l++){
110                                 delete nodesInPath[delKeys[l]];
111                         }
112                 }
113
114
115         }       
116         if(loopDetectedObj != null ){ 
117                 var msg = "";
118                 for(var key in loopDetectedObj){
119                         if(loopDetectedObj.hasOwnProperty(key)) {
120                                 console.log("Loop detected  " + key);
121                                 msg += "<strong>Loop detected for:" + key + "</strong><br>";
122                         }
123                 }
124                 if(msg != ""){
125                         isLoopDetected = true;
126                         RED.notify(msg);
127                 }
128         }       
129 /*
130                 for(var i=0;nodeSet != null && i<nodeSet.length;i++){
131                         var foundCount=0;
132                         var nodeId = nodeSet[i].id;
133                         var nodeName = nodeSet[i].name;
134                         for(var j=0;nodeSet != null && j<nodeSet.length;j++){
135                                 var node = nodeSet[j];
136                                 if(node.id == nodeId){
137                                          continue;
138                                 }
139                                 var wires = node.wires;
140                                 console.log(node.type + ":wires:" + wires);
141                                 for(var k=0;wires != null && wires != undefined && wires[0] != undefined && k<wires[0].length;k++){
142                                         var id = (wires[0])[k];
143                                         console.log(nodeName + ":" + nodeId + ":" + id);
144                                         if(id == nodeId ){
145                                                 foundCount++;
146                                                 if(foundCount>1){
147                                                         console.log("Loop detected for node " + nodeName + "with node:" + node.name);
148                                                         RED.notify("<strong>Flow error detected for node '" + nodeName + "' with node '" + node.name + "'</strong>");
149                                                         //RED.nodes.eachLink(function(d){
150                                                         //      if(d.source.id == nodeSet[i] || d.target.id == nodeSet[j]){
151                                                         //              d.selected = true;
152                                                         //      }else if(d.source.id == nodeSet[j] || d.target.id == nodeSet[i]){
153                                                         //              d.selected = true;
154                                                         //      }
155                                                         //});
156                                                         //RED.view.redraw();
157                                                         isLoopDetected = true;
158                                                         return true;
159                                                 }
160                                         }
161                                 }
162                                 
163                         }
164                 }
165 */
166                 //console.log("isLoopDetected:" + isLoopDetected);
167                 return isLoopDetected;
168 }
169
170 function generateNodePath(nodeIdToNodeObj,nodeId,pathStr,nodesInPath,errList){
171                 var node = nodeIdToNodeObj[nodeId];
172                 var wires = node.wires;
173                 if(wires != null && wires != undefined && wires[0] != undefined){
174                         for(var k=0;k<wires[0].length;k++){
175                                 var val = wires[0][k];
176                                 if(pathStr.indexOf(val + "->") != -1){
177                                         //console.log("pathStr:" + pathStr);
178                                         var n1= nodeIdToNodeObj[nodeId].name;
179                                         var n2= nodeIdToNodeObj[val].name;
180                                         errList.push("Loop detected between nodes '" +  n1 + "' and " + "'" +  n2 + "'");
181                                 }else{
182                                         pathStr += "->" + val ;
183                                         generateNodePath(nodeIdToNodeObj,val,pathStr,nodesInPath,errList);
184                                 }
185                         }
186                 }else{
187                                 //pathStr += nodeId + "->" + "";
188                                 nodesInPath.push(pathStr);
189                 }
190 }
191
192 function detectLoop(){
193                 var activeWorkspace=RED.view.getWorkspace();
194                 var nSet=[];
195                 var nodeIdToNodeObj = {};       
196                 RED.nodes.eachNode(function(n) {
197                         if (n.z == activeWorkspace) {
198                                 nSet.push({'n':n});
199                         }
200                 });
201
202                 var nodeSet = RED.nodes.createExportableNodeSet(nSet);
203                 nodeIdToNodeObj = getNodeIdToNodeMap(nodeSet);
204                 var isLoopDetected = false;     
205                 //var dgStartNode = getDgStartNode(nodeSet);
206                 var dgStartNode = nodeIdToNodeObj["dgstart"];
207                 var errList = [];
208                 var dgStartNodeId = dgStartNode.id;
209                 var nodesInPathArr = [];
210                 generateNodePath(nodeIdToNodeObj,dgStartNodeId,dgStartNodeId,nodesInPathArr,errList);
211                 if(errList != null && errList != undefined && errList.length  > 0){
212                         isLoopDetected = true;
213                         var htmlStr="<div id='loop-detect-err-list-div'><table id='loopErrListTable' border='1'><tr><th>Error List</th></tr>";  
214                         for(var j=0;errList != null && j<errList.length;j++){
215                                 var errSeq = j+1;
216                                 htmlStr += "<tr><td>" + errSeq + ")"  + errList[j] + "</td></tr>"; 
217                         }
218                         htmlStr += "</table></div>";
219
220                         $("#loop-detection-dialog").dialog({
221                               autoOpen : false,
222                               modal: true,
223                               title: "DG Flow validation Error List ",
224                               width: 500,
225                               buttons: {
226                                 Close: function () {
227                                   $("#loop-detection-dialog").dialog("close");
228                                 }
229                               }
230                          }).dialog("open").html(htmlStr); // end dialog div
231                 }
232                 nodesInPathArr=null;
233                 nodeSet ={};
234                 nodeIdToNodeObj={};
235                 return isLoopDetected;
236 }
237
238
239 var xmlNumberCnt = 0;
240 function processForXmlNumbers(nodeSet,node){
241         if( node != null && node.type != 'dgstart'){
242                 if(node.xmlnumber != null && node.xmlnumber){
243                         node.xmlnumber.push(++xmlNumberCnt);
244                 }else{
245                         node.xmlnumber =  [++xmlNumberCnt];
246                 }
247         }
248
249         if(node != null && node.wires != null && node.wires.length>0){
250                 var wiredNodes=node.wires[0];
251                 var wiredNodesArr=[];
252                 for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
253                         wiredNodesArr.push(getNode(nodeSet,wiredNodes[k]));
254                 }
255
256                 //use this sort to sort by y position
257                 wiredNodesArr.sort(function(a, b){
258                         return a.y-b.y;
259                 });
260
261                 for(var k=0;k<wiredNodesArr.length;k++){
262                         var n = wiredNodesArr[k];
263                         processForXmlNumbers(nodeSet,n);
264                 }
265         }
266 }
267
268 function updateXmlNumbers(){
269         xmlNumberCnt = 0;
270         var nodeSet = getCurrentFlowNodeSet();
271         if(nodeSet == null && nodeSet.length >0){
272                 nodeSet.forEach(function(n){
273                         if(n.xmlnumber){
274                                 delete n.xmlnumber;
275                         }
276                 });
277         }
278         var dgStartNode = getDgStartNode(nodeSet);
279         processForXmlNumbers(nodeSet,dgStartNode);
280         var activeWorkspace=RED.view.getWorkspace();
281         RED.nodes.eachNode(function(n) {
282                 //console.log("Node processed in eachNode");
283              if (n.z == activeWorkspace) {
284                 if(n != null){
285                         var updatedNode = getNode(nodeSet,n.id);
286                         //console.log("updated Node processed in eachNode");
287                         //console.dir(updatedNode);
288                         
289                         if (n.id == updatedNode.id) {
290                                 n.xmlnumber = updatedNode.xmlnumber;
291                                 n.dirty = true;
292                         }
293                 }
294             }   
295         });
296 }
297
298 function getOutcomeValue(node){
299         var xmlStr = "";
300         if(node != null && node.xml != undefined && node.xml !=""){
301                 xmlStr = node.xml + "</outcome>";
302         }
303         var xmlDoc;
304         if (window.DOMParser){
305                 try{
306                         var parser=new DOMParser();
307                         xmlDoc=parser.parseFromString(xmlStr,'text/xml');
308                         //console.log("Not IE");
309                         var n = xmlDoc.documentElement.nodeName;
310                         if(n == "html"){
311                                 resp=false;
312                                 console.log("Error parsing");
313                                 return resp;
314                         }
315                 }catch(e){
316                         console.log("xmlStr:" + xmlStr);
317                         console.log("Error parsing" +e);
318                         return null;
319                 }
320         }else{ 
321                 try{
322                         //console.log("IE");
323                         // code for IE
324                         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
325                         xmlDoc.async=false;
326                         xmlDoc.loadXMLString(xmlStr); 
327                 }catch(e){
328                         console.log("xmlStr:" + xmlStr);
329                         console.log("Error parsing" +e);
330                         return null;
331                 }
332         } 
333         if(xmlDoc != null){
334                 var xmlNode = xmlDoc.documentElement;
335                 //console.dir(xmlNode);
336                 var processedNode = xmlNode.nodeName;
337                 //console.log("processedNode:" + processedNode);
338                 var attrs = xmlNode.attributes;
339                 for(var i=0;i<attrs.length;i++){
340                         if(attrs[i].nodeName == "value"){
341                                 return  attrs[i].value;
342                         }
343                 }
344         }
345         return null;
346 }
347
348 var dgNumberCnt = 0;
349 function processForDgNumbers(nodeSet,node){
350                 var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ];
351         if( node != null && node.type != 'dgstart' && node.type != 'service-logic' && node.type != 'method' ){
352                 //console.log("child of " + parentNodeType + " :" + nodeType);
353                 //check if NOT outcome node
354                 if(outcomeTypes.indexOf(node.type) == -1){
355                         if(node.type == "GenericXML"){
356                                 if(node.xml != undefined && node.xml !=  null && node.xml.indexOf("<outcome ") != -1){
357                                         //this GenericXML node is used for outcome , so need to skip
358                                 }else{
359                                         if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){
360                                                 node.dgnumber.push(++dgNumberCnt);
361                                         }else{
362                                                 node.dgnumber =  [++dgNumberCnt];
363                                         }
364                                 }
365                         
366                         }else{
367                                 if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){
368                                         node.dgnumber.push(++dgNumberCnt);
369                                 }else{
370                                         node.dgnumber =  [++dgNumberCnt];
371                                 }
372                         }
373                 }
374         }
375         
376         var hasOutcomeNodes = false;
377         if(node != null && node.wires != null && node.wires.length>0){
378                 var wiredNodes=node.wires[0];
379                 var wiredNodesArr=[];
380                 for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
381                         var wiredNode = getNode(nodeSet,wiredNodes[k]);
382                         //check if outcome node
383                         if(outcomeTypes.indexOf(wiredNode.type) != -1){
384                                 hasOutcomeNodes = true;
385                         }
386                         if(wiredNode.type == "GenericXML"){
387                                 if( node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome ") != -1){
388                                         //this GenericXML node is used for outcome 
389                                         hasOutcomeNodes = true;
390                                 }
391                         }
392                         wiredNodesArr.push(wiredNode);
393
394                 }
395
396                 //use this sort to sort by y position
397                 wiredNodesArr.sort(function(a, b){
398                         return a.y-b.y;
399                 });
400
401                 /*
402                 //USE THIS LOGIC TO SORT BY OUTCOME VALUE FOR SPECIFIC NODES            
403                 var parentNodeType = node.type;
404                 if(hasOutcomeNodes && parentNodeType != 'switchNode' && parentNodeType != 'block'  && parentNodeType != 'configure' ){  
405                         //use the value of outcome to sort the wired nodes
406                         wiredNodesArr.sort(function(a, b){
407                                 var val1 = getOutcomeValue(a);
408                                 var val2 = getOutcomeValue(b);
409                                 //console.log("val1:" + val1);
410                                 //console.log("val2:" + val2);
411                                 if ( val1 < val2 ){
412                                         return -1;
413                                 }else if ( val1 > val2 ){
414                                         return 1;
415                                 }else{
416                                         return 0;
417                                 }
418                         });
419                 }else{
420                         //use this sort to sort by y position
421                         wiredNodesArr.sort(function(a, b){
422                                 return a.y-b.y;
423                         });
424                 }
425
426                 */
427
428                 for(var k=0;k<wiredNodesArr.length;k++){
429                         var n = wiredNodesArr[k];
430                         processForDgNumbers(nodeSet,n);
431                 }
432         }
433 }
434
435 function updateDgNumbers(){
436         dgNumberCnt = 0;
437         var nodeSet = getCurrentFlowNodeSet();
438         if(nodeSet == null && nodeSet.length >0){
439                 nodeSet.forEach(function(n){
440                         if(n.dgnumber){
441                                 delete n.dgnumber;
442                         }
443                 });
444         }
445         var dgStartNode = getDgStartNode(nodeSet);
446         processForDgNumbers(nodeSet,dgStartNode);
447         var activeWorkspace=RED.view.getWorkspace();
448         RED.nodes.eachNode(function(n) {
449                 //console.log("Node processed in eachNode");
450              if (n.z == activeWorkspace) {
451                 if(n != null){
452                         var updatedNode = getNode(nodeSet,n.id);
453                         //console.log("updated Node processed in eachNode");
454                         //console.dir(updatedNode);
455                         
456                         if (n.id == updatedNode.id) {
457                                 //console.log(n.type + ":" + updatedNode.dgnumber);
458                                 n.dgnumber = updatedNode.dgnumber;
459                                 n.dirty = true;
460                         }
461                 }
462             }   
463         });
464         return nodeSet; 
465 }
466
467 function customValidation(currNodeSet){
468         //validation to make sure there a block node infront of mutiple dgelogic nodes
469         flowDesignErrors=[];
470         var dgStartCnt=0;
471         var serviceLogicCnt=0;
472         var methodCnt=0;
473         for(var i=0;currNodeSet != null && i<currNodeSet.length;i++){
474                 var node = currNodeSet[i];
475                 var parentNodeName = node.name;
476                 var parentNodeType = node.type;
477                 var dgNumber = node.dgnumber;
478                 if(parentNodeType == 'dgstart'){
479                         dgStartCnt++;   
480                 }
481                 if(parentNodeType == 'service-logic'){
482                         serviceLogicCnt++;      
483                 }
484                 if(parentNodeType == 'method'){
485                         methodCnt++;    
486                 }
487                 if(parentNodeType == "GenericXML"){
488                         if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic ") != -1 ){
489                                 //this GenericXML node is used for service-logic 
490                                 serviceLogicCnt++;
491                         }else if( node.xml != undefined && node.xml != null &&  node.xml.indexOf("<method ") != -1 ){
492                                 //this GenericXML node is used for method
493                                 methodCnt++;
494                         }else if( node.xml != undefined && node.xml != null &&  node.xml.indexOf("<block") != -1 ){
495                                 //this GenericXML node is used for block
496                                 parentNodeType = "block";
497                         }
498                 }
499                 if(node != null && node.wires != null && node.wires.length>0){
500                         var wiredNodes=node.wires[0];
501                         var wiredNodesArr=[];
502                         for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
503                                 wiredNodesArr.push(getNode(currNodeSet,wiredNodes[k]));
504                         }
505                         var countChildLogicNodes =0;
506                         for(var k=0;k<wiredNodesArr.length;k++){
507                                 var n = wiredNodesArr[k];
508                                 var nodeType = n.type;
509                                 var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ];
510                                 var isOutcomeOrSetNode = false;
511                                 if(nodeType == "GenericXML"){
512                                         if( n.xml != undefined &&  n.xml != null &&  (n.xml.indexOf("<outcome ") != -1 || n.xml.indexOf("<set ") != -1)){
513                                                 //this GenericXML node is used for outcome 
514                                                 isOutcomeOrSetNode = true;
515                                         }
516                                 }
517                                 //console.log("child of " + parentNodeType + " :" + nodeType);
518                                 if(outcomeTypes.indexOf(nodeType) > -1 ||nodeType == 'set' || isOutcomeOrSetNode){
519                                         //its a outcome or set node
520                                 }else{
521                                         countChildLogicNodes++;
522                                 }
523
524                                 //console.log("parentNodeType:" + parentNodeType);
525                                 if(countChildLogicNodes >1 && parentNodeType != 'block' && parentNodeType != 'for' ){
526                                         if(node.dgnumber != undefined &&  node.dgnumber){
527                                                 flowDesignErrors.push("Warning:May need a block Node after Node. <br><span style='color:red'>Node Name:</span>" + node.name + "<br><span style='color:red'>DG Number:</span>" + node.dgnumber[0] );
528                                         }else{
529                                                 flowDesignErrors.push("Warning:May need a block Node after Node <br><span style='color:red'>Node name:</span>" + parentNodeName);
530                                         }
531                                         break;
532                                 }
533                         }
534                 }
535         }
536         if(dgStartCnt > 1){
537                 flowDesignErrors.push("Error:There should  only be 1 dgstart Node in the current workspace.");
538         }
539
540         if(serviceLogicCnt > 1){
541                 flowDesignErrors.push("Error:There should  only be 1 service-logic Node in the current workspace.");
542         }
543
544         if(methodCnt > 1){
545                 flowDesignErrors.push("Error:There should  only be 1 method Node in the current workspace.");
546         }
547
548         if(flowDesignErrors != null && flowDesignErrors.length >0){
549                 return false;
550         }
551         return true;
552 }
553
554 var flowDesignErrors = [];
555 function showFlowDesignErrorBox(){
556         if(flowDesignErrors != null && flowDesignErrors.length >0){
557                 var htmlStr="<div id='flowpath-err-list-div'><table id='fpeTable' border='1'><tr><th>Error List</th></tr>";     
558                 for(var j=0;flowDesignErrors != null && j<flowDesignErrors.length;j++){
559                         var errSeq = j+1;
560                         htmlStr += "<tr><td>" + errSeq + ")"  + flowDesignErrors[j] + "</td></tr>"; 
561                 }
562                 htmlStr += "</table></div>";
563
564                 //$('<div></div>').dialog({
565
566                 $('#flow-design-err-dialog').dialog({
567                               modal: true,
568                               title: "Flow design Error List ",
569                               width: 500,
570                               /*open: function () {
571                                 $(this).html(htmlStr);
572                               },*/
573                               buttons: {
574                                 Close: function () {
575                                   $(this).dialog("close");
576                                 }
577                               }
578                             }).html(htmlStr); // end dialog div
579         }
580 }
581
582
583 function getCurrentFlowNodeSet(){
584                 var nodeSet=[];
585                 //console.dir(RED);
586                 //RED.view.dirty();
587                 //RED.view.redraw();
588                 var activeWorkspace=RED.view.getWorkspace();
589                 RED.nodes.eachNode(function(n) {
590                         if (n.z == activeWorkspace) {
591                                 nodeSet.push({'n':n});
592                         }
593                 });
594
595                 var exportableNodeSet = RED.nodes.createExportableNodeSet(nodeSet);
596                 //console.dir(exportableNodeSet);
597                 //console.log(JSON.stringify(exportableNodeSet));
598                 return exportableNodeSet;
599 }
600
601 function getNode(nodeSet,id){
602                 for(var i=0;i<nodeSet.length;i++){
603                         if(nodeSet[i].id == id){
604                                 return nodeSet[i];
605                         }       
606                 }
607                 return null;
608 }
609 function getNodeIdToNodeMap(nodeSet){
610                 var nodeIdToNodeMap ={};        
611                 for(var i=0;i<nodeSet.length;i++){
612                                 nodeIdToNodeMap[nodeSet[i].id] = nodeSet[i];
613                                 if(nodeSet[i].type == "dgstart"){
614                                         nodeIdToNodeMap["dgstart"] =  nodeSet[i];
615                                 }
616                 }
617                 return nodeIdToNodeMap;
618 }
619
620 function validateEachNodeXml(){
621                 var activeWorkspace=RED.view.getWorkspace();
622                 RED.nodes.eachNode(function(n) {
623                         if (n.z == activeWorkspace) {
624                                 var xml = n.xml;        
625                                 if( xml != null && xml != ''){
626                                   var validationSuccess = validateXML(n.xml);
627                                         if(validationSuccess){
628                                                 n.status = {fill:"green",shape:"dot",text:"OK"};
629                                         }else{
630                                                 n.status = {fill:"red",shape:"dot",text:"ERROR"};
631                                         }
632                                 }
633                         }
634                 });
635 }
636
637
638 function getNodeToXml(inputNodeSet){
639                 var exportableNodeSet; 
640         //uses inputNodeSet if passed otherwise build the latest nodeSet
641         
642         //$("#btn-deploy").removeClass("disabled");
643
644
645                 function getNode(id){
646                         for(var i=0;i<exportableNodeSet.length;i++){
647                                 if(exportableNodeSet[i].id == id){
648                                         return exportableNodeSet[i];
649                                 }       
650                         }
651                         return null;
652                 }
653
654                 function getStartTag(node){
655                         var startTag="";
656                         var xmlStr="";
657                         if(node != null && node.type != 'dgstart'){
658                                 xmlStr=node.xml;
659                                 var regex = /(<)([\w-]+)(.*)?/;
660                                 var match = regex.exec(xmlStr);
661                                 if(match != null){
662                                         if(match[1] != undefined && match[2] != undefined){
663                                                 startTag = match[2];
664                                         }
665                                 }else{
666                                         console.log("startTag not found.");
667                                 }       
668                         }
669                         return startTag;
670                 }
671
672                 if(inputNodeSet == null || inputNodeSet == undefined){  
673                         exportableNodeSet = getCurrentFlowNodeSet();
674                 }else{
675                         exportableNodeSet = JSON.parse(inputNodeSet);
676                 }
677                 var dgstartNode = getDgStartNode(exportableNodeSet);
678
679                 var level=0;
680                 var fullXmlStr="";
681
682                 printXml(dgstartNode);
683                 
684
685                 function printXml(node){
686                         var xmlStr="";
687                         var startTag = "";
688                         if(node != null && node.type != 'dgstart'){
689                                 var comments=node.comments;
690                                 if(comments != null && comments != ""){
691                                         //if xml comments field already has the <!-- and --> remove them 
692                                         comments=comments.replace("<!--","");
693                                         comments=comments.replace("-->","");
694                                         xmlStr="<!--" + comments + "-->";
695                                 }       
696                                 xmlStr+=node.xml;
697                                 startTag = getStartTag(node);
698                                 fullXmlStr +=xmlStr;
699                                 /*
700                                 if(level > 0){
701                                         var spacing = Array(level).join("  ");  
702                                         xmlStr=xmlStr.replace(/\n/g,spacing);
703                                         fullXmlStr +=xmlStr;
704                                         
705                                         console.log(xmlStr);
706                                 }else{
707                                         fullXmlStr +=xmlStr;
708                                         console.log(xmlStr);
709                                 }
710                                 */
711                         }
712
713                         //console.log("startTag:" + startTag);
714         
715                         var wiredNodes = [];
716                         var wiredNodesArr = [];
717                         if(node != null && node.wires != null && node.wires[0] != null &&  node.wires[0] != undefined && node.wires[0].length >0 ){
718                                 wiredNodes=node.wires[0];
719                                 //console.log("Before sort");
720                                 for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
721                                         wiredNodesArr.push(getNode(wiredNodes[k]));
722                                 }
723                                 //console.dir(wiredNodesArr);
724                                 //sort based on y position
725                                 wiredNodesArr.sort(function(a, b){
726                                         return a.y-b.y;
727                                 });
728                                 //console.log("After sort");
729                                 //console.dir(wiredNodesArr);
730                         }
731
732                         for(var k=0;wiredNodesArr != null && k<wiredNodesArr.length;k++){
733                                 level++;
734                                 var nd = wiredNodesArr[k];
735                                 printXml(nd);
736                         }
737
738                         //append end tag
739                         if(startTag != ""){
740                                 fullXmlStr += "</" + startTag + ">";
741                                 /*
742                                 if(level >0){
743                                         var spacing = Array(level).join("  ");  
744                                         fullXmlStr += spacing + "</" + startTag + ">";
745                                         console.log(spacing + "</" + startTag + ">");
746                                 }else{
747                                         fullXmlStr += "</" + startTag + ">";
748                                         console.log("</" + startTag + ">");
749                                 }
750                                 */
751                         }       
752
753                         /*if(level>0){
754                                 level=level-1;
755                         }
756                         */
757                         //console.log("endTag:" + startTag);
758                         //console.log("xml:" + fullXmlStr);
759                 }
760                 //console.log("fullXmlStr:" + fullXmlStr);
761         return fullXmlStr;
762 }
763
764 function showFlow(filePath){
765 var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath})
766   .done(function(data) {
767         $( "#dgflow-browser-dialog").dialog("close");
768         var migratedNodes = migrateNodes(data);
769         //RED.view.importNodes(data)
770         RED.view.importNodes(JSON.stringify(migratedNodes));
771     //console.log( "import done");
772   })
773   .fail(function() {
774         RED.notify("Could not import user flow .");     
775         $( "#dgflow-browser-dialog").dialog("close");
776      console.log( "error occured importing flow.");
777   })
778   .always(function() {
779     //console.log( "complete" );
780   });
781 }
782
783 function showFlowXml(filePath){
784 var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath})
785   .done(function(data) {
786         //console.dir(data);
787         var xmlStr=getNodeToXml(data);
788         showImportedXml(xmlStr,this);
789   })
790   .fail(function() {
791         RED.notify("Could not convert to XML.");        
792         $( "#dgflow-browser-dialog").dialog("close");
793      console.log( "error occured importing flow.");
794   })
795   .always(function() {
796     //console.log( "complete" );
797   });
798 }
799
800 function showFlowFiles(userName){
801                 //var divStyle="color:#07c; margin-bottom: 1.2em; font-size: 16px;";
802                 //var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } </style>";
803                 var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
804
805                 var htmlStr=divStyle + "<div class='header'>List of Flow files of User " + userName + "</div><div id='data-container'><ul>" ;
806                 $.post( "/getFiles/" + userName)
807                          .done(function( data ) {
808                                 //console.dir(data);
809                                 //console.log("found " + data.length + " files");
810                                 if(data != null && data.length != undefined && data.length != 0){
811                                         if(data != null && data.length>0){
812                                                 for(var k=0;k<data.length;k++){
813                                                         htmlStr += "<li><a href=\"#\" onclick=\"showFlow('" +data[k].filePath + "')\">" + data[k].name + "</a></li>";
814                                                 /*
815                                                         //Use this code to display the View Xml Link 
816                                                         htmlStr += "<li><a href=\"#\" onclick=\"showFlow('" +data[k].filePath + "')\">" + data[k].name + "</a><span style=\"margin-left:15px;color:blue\"><a href=\#\" onclick=\"showFlowXml('" +data[k].filePath + "')\">[View Xml]</a></span></li>";
817                         */
818                                                 }
819                                                 htmlStr+="</ul></div>";
820                                         }
821                                         $( "#dgflow-browser-dialog").html(htmlStr);
822                                 }else{
823                                         //console.log("no flow files found for user " + userName);
824                                         var noFlowFilesHtml = divStyle + "<div id='data-container'><p>No downloaded Flow files found in " + userName + " directory</p><a href='#' onclick='javascript:closeAndShowFlowShareUsers()'>Back to List.</a></div>";
825                                         $( "#dgflow-browser-dialog").html(noFlowFilesHtml);
826                                 }
827                          })
828                          .fail(function(err) {
829                                  console.log( "error" + err );
830                          })
831                          .always(function() {
832                                 //console.log("done");
833                          });
834         
835 }
836
837         function  closeAndShowFlowShareUsers(){
838                 $("#dgflow-browser-dialog").dialog( "close" );
839                 var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
840                 $.get( "/flowShareUsers")
841                                .done(function( data ) {
842                                         
843                                         var header="<div class='header'>List of downloaded DG Flows </div>";
844                                         var html=  divStyle + header +  "<div id='data-container'>";
845                                         html+="<ul>";
846                                         if(data != null){
847                                                 var users=data.flowShareUsers;
848                                                 users.sort(function (a,b){
849                                                          if(a.name > b.name){
850                                                                  return 1;
851                                                          }else if(a.name <  b.name){
852                                                                  return -1;
853                                                          }else{
854                                                                  return 0;
855                                                          }
856                                                 });
857                                                 for(var i=0;users != null && i<users.length;i++){
858                                                         html+="<li><a href=\"#\" onclick=\"showFlowFiles('" + users[i].rootDir + "')\">" + users[i].name + "</a></li>";
859                                                 }
860                                         }
861                                         html+="</ul>";
862                                         html+="</div>";
863                                         $( "#dgflow-browser-dialog" ).dialog({
864                                         title: "Dowloaded DG Flow Browser",
865                                         modal: true,
866                                         autoOpen: true,
867                                         width: 530,
868                                         height: 530,
869                                         buttons: [
870                                                 {
871                                                         text: "Close",
872                                                         click: function() {
873                                                                 $( this ).dialog( "close" );
874                                                         }
875                                                 }
876                                                 ]
877                                         }).html(html);
878                                         $("#dgflow-browser-dialog").show();
879                                })
880                                 .fail(function(err) {
881                                          RED.notify("Failed to get users.");
882                                 })
883                                  .always(function() {
884                                 });
885         }
886
887 function showImportedXml(xmlStr,dialogBox){
888         var formattedXml=vkbeautify.xml(xmlStr);
889         var that = dialogBox;
890                 require(["orion/editor/edit"], function(edit) {
891                 that.editor = edit({
892                     parent:document.getElementById('dgflow-browser-dialog'),
893                     lang:"html",
894                     readonly:true,
895                     contents: formattedXml
896                 });
897                 RED.library.create({
898                     url:"functions", // where to get the data from
899                     type:"function", // the type of object the library is for
900                     editor:that.editor, // the field name the main text body goes to
901                     fields:['name','outputs']
902                 });
903                 });
904 }
905
906 function getTag(xmlStr){
907         var tag= null ;
908         if(xmlStr != null){
909                 xmlStr = xmlStr.trim();
910         }
911         try{
912                 var regex = new RegExp("(<)([^ >]+)");
913                 var match = regex.exec(xmlStr);
914                 if(match != null){
915                         if(match[1] != undefined && match[2] != undefined){
916                                 tag = match[2];
917                         }
918                 }
919         }catch(e){
920                 console.log(e);
921         }
922         return tag;
923
924 }
925
926 function getAttributeValue(xmlStr,attribute){
927
928         var attrVal=null;
929         try{
930                 var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
931                 var myArray = myRe.exec(xmlStr);
932                 if(myArray != null && myArray[1] != null){
933                         attrVal=myArray[1];
934                 }
935         }catch(err){
936                 console.log(err);
937         }
938         return attrVal;
939 }
940
941 function showOrHideTab(checkbox,idVal){
942
943         var activeWorkspace=RED.view.getWorkspace();
944         var table = $("#ftab02");
945         $('td input:checkbox',table).each(function(i){
946                 console.log(this.checked);
947         });
948         //console.dir($('td input:checkbox',table).prop('checked',this.checked));
949
950         $(".red-ui-tabs li a").each(function(i){
951                 var id=$(this).attr("href").replace('#','');
952                 if(id == idVal){
953                         $(this).parent().toggle();
954                         var isVisible = $(this).parent().is(":visible"); 
955                         if(isVisible){
956                                 checkbox.checked = true;
957                         }else{
958                                 checkbox.checked = false;
959                         }
960                         if(activeWorkspace == id){
961                                 //$("#chart").hide();
962                                 //var li = ul.find("a[href='#"+id+"']").parent();
963                                 var li = $(this).parent();
964                                 if (li.hasClass("active")) {
965                                         li.removeClass("active");
966                                         if(li.parent().children().size() != 0){
967                                         }
968                                         console.log("has Class active");
969                                         var tab = li.prev();
970                                         if (tab.size() === 0) {
971                                                 console.log("li prev size 0");
972                                                 tab = li.next();
973                                         }
974                                         if(tab.is(":visible")){
975                                                 console.log("added active");
976                                                 tab.addClass("active");
977                                                 tab.click();
978                                                 //tab.trigger("click");
979                                         }
980                                         //console.dir(tab);
981                                         //tab.parent().addClass("active");
982                                         //tab.click();
983                                 }
984                         }else{
985                                                 console.log("added active id" +id);
986                                                 if(isVisible){
987                                                         var li = $(this).parent();
988                                                         li.addClass("active");
989                                                         li.click();
990                                                         //console.dir(li);
991                                                 }else{
992                                                         var li = $(this).parent();
993                                                         li.removeClass("active");
994                                                 }
995                         }
996                 }
997         });
998 /*
999         $(".red-ui-tabs li a").each(function(i){
1000                 var id=$(this).attr("href").replace('#','');
1001                 if(id != idVal){
1002                         $(this).trigger("click");
1003                         if(activeWorkspace == idVal){
1004                                 $("#chart").show();
1005                         }
1006                         return false;
1007                 }
1008         });
1009 */
1010 }
1011
1012 function performGitCheckout(){
1013         $("#responseId").text("");
1014          if(!event) event = window.event;
1015          var target = $(event.target);
1016          target.val("Processing");
1017          target.css({ "background-image": "url('images/page-loading.gif')" });
1018          target.css({ "background-repeat": "no-repeat" });
1019          target.css({ "background-size": "25px 25px" });
1020
1021         var branch = document.getElementById("branchId").value.trim();
1022         var statusObj = document.getElementById("responseId");
1023         if(branch == null || branch == ''){
1024                 statusObj.innerText = "Branch is required.";
1025                 return;
1026         }
1027         var urlVal = "/gitcheckout?branch=" + branch;
1028         $.get(urlVal)
1029                 .done(function( data ) {
1030                         var output = data.output;
1031                         if(output != null){
1032                                 output=output.replace(/\n/g,"<br>");
1033                                 statusObj.innerHTML = output;
1034                         }
1035                  })
1036                 .fail(function(err) {
1037                         statusObj.innerText = "Failed to do git checkout.";
1038                 })
1039                 .always(function() {
1040                         $("#responseId").show();
1041                          target.val("Checkout");
1042                          target.css({ "background-image": "none" });
1043                  });
1044 }
1045
1046 function performGitPull(){
1047         $("#responseId").text("");
1048          if(!event) event = window.event;
1049          var target = $(event.target);
1050          target.val("Processing");
1051          target.css({ "background-image": "url('images/page-loading.gif')" });
1052          target.css({ "background-repeat": "no-repeat" });
1053          target.css({ "background-size": "25px 25px" });
1054
1055         var statusObj = document.getElementById("responseId");
1056         var urlVal = "/gitpull";
1057         $.get(urlVal)
1058                 .done(function( data ) {
1059                         var output = data.output;
1060                         if(output != null){
1061                                 output=output.replace(/\n/g,"<br>");
1062                                 statusObj.innerHTML = output;
1063                         }
1064                  })
1065                 .fail(function(err) {
1066                         statusObj.innerText = "Failed to do git pull.";
1067                 })
1068                 .always(function() {
1069                         $("#responseId").show();
1070                          target.val("Pull");
1071                          target.css({ "background-image": "none" });
1072                  });
1073 }
1074
1075
1076 function activateClickedTab(idVal) {
1077
1078         $("#filter-tabs-dialog").dialog( "close" );
1079         var ul = $("#workspace-tabs");
1080         ul.children().each(function(){
1081                 var li = $(this);
1082                 var link =li.find("a");
1083                 var href = link.prop("href");
1084                 var hrefId = href.split("#");
1085                 if(hrefId[1] == idVal){
1086                  link.trigger("click");
1087                 }
1088         });
1089 }
1090
1091 function deleteOrRenameTab(idVal) {
1092         $("#filter-tabs-dialog").dialog( "close" );
1093         var ul = $("#workspace-tabs");
1094         ul.children().each(function(){
1095                 var li = $(this);
1096                 var link =li.find("a");
1097                 var href = link.prop("href");
1098                 var hrefId = href.split("#");
1099                 if(hrefId[1] == idVal){
1100                         link.trigger("click");
1101                         link.trigger("dblclick");
1102                 }
1103         });
1104 }
1105
1106 function deleteSelectedTab(idVal,title,_module,rpc,version){
1107         var dgInfo = "<div><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;' ><th>Tab Title</th><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td>" + title + "</td><td>" + _module +"</td><td>" + rpc + "</td><td>" +version +  "</td></tr></table></div><br>";
1108         var alertMsg = dgInfo + "<p>Are you sure you want to Delete this Tab ?</p>"; 
1109
1110 $( "#tabAlertDialog" ).dialog({
1111   dialogClass: "no-close",
1112   modal:true,
1113   draggable : true,
1114   /*dialogClass: "alert",*/
1115   title: "Confirm Tab sheet Delete",
1116   width: 600,
1117   buttons: [
1118     {
1119       text: "Delete",
1120       class:"alertDialogButton",
1121       click: function() {
1122                 var ws = RED.nodes.workspace(idVal);
1123                 RED.view.removeWorkspace(ws);
1124                 var historyEvent = RED.nodes.removeWorkspace(idVal);
1125                 historyEvent.t = 'delete';
1126                 historyEvent.dirty = true;
1127                 historyEvent.workspaces = [ws];
1128                 RED.history.push(historyEvent);
1129                 RED.view.dirty(true);
1130                 $( this ).dialog( "close" );
1131                 $("#filter-tabs-dialog").dialog( "close" );
1132                 $("#btn-manage-tabs").trigger("click");
1133         }
1134     },
1135     {
1136       text: "Cancel",
1137       class:"alertDialogButton",
1138       click: function() {
1139         $( this ).dialog( "close" );
1140       }
1141     }
1142   ]
1143 }).html(alertMsg);
1144 }
1145
1146 function renameSelectedTab(idVal,title,_module,rpc,version){
1147         var dgInfo = "<div><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;' ><th>Tab Title</th><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td><input id='tab-name-" + idVal + "' type='text' value='" + title + "'></td><td>" + _module +"</td><td>" + rpc + "</td><td>" +version +  "</td></tr></table></div><br>";
1148         var alertMsg = dgInfo + "<p>Change the title and click Rename.</p>"; 
1149
1150 $( "#tabAlertDialog" ).dialog({
1151   dialogClass: "no-close",
1152   modal:true,
1153   draggable : true,
1154   /*dialogClass: "alert",*/
1155   title: "Rename Tab sheet",
1156   width: 600,
1157   buttons: [
1158     {
1159       text: "Rename",
1160       class:"alertDialogButton",
1161       click: function() {
1162                 var ws = RED.nodes.workspace(idVal);
1163                 var label = document.getElementById("tab-name-" + idVal).value; 
1164                 //console.log("label:" +label);
1165                 //console.log("ws.label:" + ws.label);
1166                 if (ws.label != label) {
1167                         ws.label = label;
1168                         var link = $("#workspace-tabs a[href='#"+idVal+"']");
1169                         link.attr("title",label);
1170                         link.text(label);
1171                         RED.view.dirty(true);
1172                 }
1173                 $("#tabAlertDialog").dialog('destroy').remove();
1174                 //$(this).dialog( "close" );
1175                 $("#filter-tabs-dialog").dialog( "close" );
1176                 $("#btn-manage-tabs").trigger("click");
1177         }
1178     },
1179     {
1180       text: "Cancel",
1181       class:"alertDialogButton",
1182       click: function() {
1183         $( this ).dialog( "close" );
1184       }
1185     }
1186   ]
1187 }).html(alertMsg);
1188 }
1189
1190 function performGitStatus(){
1191         $("#responseId").text("");
1192          if(!event) event = window.event;
1193          var target = $(event.target);
1194          target.val("Processing");
1195          target.css({ "background-image": "url('images/page-loading.gif')" });
1196          target.css({ "background-repeat": "no-repeat" });
1197          target.css({ "background-size": "25px 25px" });
1198
1199         var statusObj = document.getElementById("responseId");
1200         var urlVal = "/gitstatus";
1201         $.get(urlVal)
1202                 .done(function( data ) {
1203                         var output = data.output;
1204                         if(output != null){
1205                                 output=output.replace(/\n/g,"<br>");
1206                                 statusObj.innerHTML = output;
1207                         }
1208                         //statusObj.innerText = data.output;
1209                  })
1210                 .fail(function(err) {
1211                         statusObj.innerText = "Failed to do git status.";
1212                 })
1213                 .always(function() {
1214                         $("#responseId").show();
1215                          target.val("Status");
1216                          target.css({ "background-image": "none" });
1217                  });
1218 }
1219
1220 function migrateNodes(jsonStr){
1221         var nodes = JSON.parse(jsonStr);
1222         nodes.forEach( function(node) {
1223                 if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic") != -1){
1224                         //console.log(node.xml);
1225                         var module="";
1226                         var version="";
1227                         module=getAttributeValue(node.xml,"module");
1228                         /*
1229                         var myRe = new RegExp("module=\"(.*)\" ", "m");
1230                         var myArray = myRe.exec(node.xml);
1231                         if(myArray != null && myArray[1] != null){
1232                                 module=myArray[1];
1233                         }
1234                         myRe = new RegExp("version=\"(.*)\">", "m");
1235                          myArray = myRe.exec(node.xml);
1236                         if(myArray != null && myArray[1] != null){
1237                                 version=myArray[1];
1238                                 //console.dir(myArray);
1239                         }
1240                         */
1241                         version=getAttributeValue(node.xml,"version");
1242                         node.type="service-logic";
1243                         //node.category="DGEmain";
1244                         node.module=module;
1245                         node.version=version;
1246                         if(module != null && version != null){
1247                                 node.name=module+ " " + version;
1248                         }
1249                         console.log("module=" + module);
1250                         console.log("version=" + version);
1251                 }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<method") != -1){
1252                         var rpc=getAttributeValue(node.xml,"rpc");
1253                         node.type="method";
1254                         if(rpc != null){
1255                                 node.name=rpc;
1256                         }
1257                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome") != -1){
1258                          var uxml = node.xml.toUpperCase();
1259                         if(uxml.indexOf("FAILURE") != -1){
1260                                 node.type="failure";
1261                         }else if(uxml.indexOf("SUCCESS") != -1){
1262                                 node.type="success";
1263                         }else if(uxml.indexOf("TRUE") != -1){
1264                                 node.type="outcomeTrue";
1265                         }else if(uxml.indexOf("FALSE") != -1){
1266                                 node.type="outcomeFalse";
1267                         }else if(uxml.indexOf("ALREADY-ACTIVE") != -1){
1268                                 node.type="already-active";
1269                         }else if(uxml.indexOf("NOT-FOUND") != -1){
1270                                 node.type="not-found";
1271                         }else{
1272                                 node.type="other";
1273                         }
1274                 }else if( node.xml != undefined &&node.xml != null && node.xml.indexOf("<return") != -1){
1275                          var uxml = node.xml.toUpperCase();
1276                         if(uxml.indexOf("FAILURE") != -1){
1277                                 node.type="returnFailure";
1278                         }else if(uxml.indexOf("SUCCESS") != -1){
1279                                 node.type="returnSuccess";
1280                         }
1281                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<exists") != -1){
1282                         node.type="exists";
1283                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<block") != -1){
1284                         node.type="block";
1285                         var atomic=getAttributeValue(node.xml,"atomic");
1286                         
1287                         if(atomic=='true'){
1288                                 node.atomic="true";
1289                                 node.name="block : atomic";
1290                         }else{
1291                                 node.atomic="false";
1292                                 node.name="block";
1293                         }
1294                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<save") != -1){
1295                         node.type="save";
1296                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<switch") != -1){
1297                         node.type="switchNode";
1298                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<record") != -1){
1299                         node.type="record";
1300                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<call") != -1){
1301                         node.type="call";
1302                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<release") != -1){
1303                         node.type="release";
1304                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<set") != -1){
1305                         node.type="set";
1306                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<for") != -1){
1307                         node.type="for";
1308                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<is-available") != -1){
1309                         node.type="is-available";
1310                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<reserve") != -1){
1311                         node.type="reserve";
1312                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<get-resource") != -1){
1313                         node.type="get-resource";
1314                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<configure") != -1){
1315                         node.type="configure";
1316                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<delete") != -1){
1317                         node.type="delete";
1318                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<execute") != -1){
1319                         node.type="execute";
1320                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<notify") != -1){
1321                         node.type="notify";
1322                 }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<update") != -1){
1323                         node.type="update";
1324                 }
1325                 //console.dir(node);
1326         });     
1327         return nodes;
1328 }