<commit_before><?xml version="1.0" encoding="utf-8"?>

<mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="vertical" dragEnter="doDragEnter(event)" dragDrop="onDragDrop(event)" 
xmlns:Components="Components.*" xmlns:display="flash.display.*"
creationComplete="initApp()"  width="100%" height="100%" paddingTop="0" paddingBottom="0" paddingLeft="0" paddingRight="0">
<mx:Script>
<![CDATA[
	import Components.DAGPath;
	
	import mx.controls.ComboBase;
	import Components.DAGConstants;
	import mx.containers.HBox;
	import mx.controls.ComboBox;
    import mx.controls.ToolTip;
    import mx.managers.ToolTipManager;
	import mx.containers.VBox;
	import mx.controls.Button;
	import mx.utils.ArrayUtil;
	import mx.controls.DataGrid;
	import mx.containers.Accordion;
	import mx.controls.List;
	import Components.Association;
	import Components.DAGPath;
	import mx.collections.ArrayCollection;
	import mx.states.SetEventHandler;
	import mx.core.UIComponent;
	import Components.DAGNode;
	import mx.containers.Canvas;
	import mx.core.IUIComponent;
	import mx.controls.Alert;
	import mx.events.DragEvent;
	import mx.core.DragSource;
	import mx.managers.DragManager;
	import mx.events.MenuEvent;
	import flash.external.ExternalInterface;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import mx.rpc.events.FaultEvent;
	import flash.net.registerClassAlias;
	import Components.AmbiguityPanel;
	import mx.managers.PopUpManager;
   	import mx.core.IFlexDisplayObject;
   	import mx.containers.ControlBar;
    import mx.controls.Spacer;
    import mx.containers.ControlBar;
   	import mx.controls.Menu;
    import Util.HashMap;
	
	public var readyTimer:Timer;
	private var dynamicNodeNum:int = 1;
	private var linkNum:int = 1;
	private var node1:String = "";
	private var node2:String = "";
	private var selectedLink:String = "";
	private var selectedNode:DAGNode=null;
	//------------------------
	private var textData:Object = null;
    private var panel:AmbiguityPanel; 
    private var title:String  = new String();
    private var selectedNodeList:ArrayCollection = new ArrayCollection();
    private var count:int = 0;
    private var resultStr:String = "failed";
    private var firstNode:String;
    private var secondNode:String;
    //private var linkCount:int =0;
	private var pathStr:String
	private	var isQuery:String = "false";
	public var isOutputView:Boolean=false;
	public var rpcService: RemoteObject;
	public var view:String ="";
	public var dagPathUIMap:HashMap;
	public var totalNodeMap:HashMap;
	
	
	public function timerHandler():void
	{
		if (isContainerReady())
		{
			// If the container is ready, register the SWF�s functions.
			setUpCall();
			readyTimer.stop();
		}
	}

	public function setUpCall():void 
	{
		ExternalInterface.addCallback("createNode",createNode);		
		ExternalInterface.addCallback("editLimit",editLimit);	
		ExternalInterface.addCallback("searchResult",searchResult);	
		ExternalInterface.addCallback("addNodeToView",addNodeToView);
	}
	
	//setup the callback function so that HTML can call flex methods
	//Checks wheather HTML page is loaded or not.
	private function isContainerReady():Boolean
	{
		var result:Boolean = ExternalInterface.call("isReady");
		return result;
	}
		
	private function faultHandler (event:FaultEvent):void
	{
		// Deal with event.fault.faultString, etc.
		Alert.show(event.fault.faultString, 'Error');
	}
	
		//-----------------
	private function doDrag(event:MouseEvent):void
	{
		var dragInitiator:DAGNode = DAGNode(event.currentTarget);
		var ds:DragSource = new DragSource();
		
		var canvasProxy:DAGNode = new DAGNode();
		canvasProxy.nodeNumber = dragInitiator.nodeNumber;
		canvasProxy.nodeName =dragInitiator.nodeName;
		
		
		var pointOffSet:Point = new Point(dragInitiator.mouseX,dragInitiator.mouseY);
		ds.addData(pointOffSet,"point");
		
		DragManager.doDrag(dragInitiator,ds,event,canvasProxy,0,0);
	}
	
	private function doDragEnter(event:DragEvent):void{
		DragManager.acceptDragDrop(event.currentTarget as IUIComponent)
	}
	
	private function onDragDrop(event:DragEvent):void{
		var dagNode:DAGNode = DAGNode(event.dragInitiator) ;
		var pointOffSet:Point = Point(event.dragSource.dataForFormat("point") );
		
		var pt:Point = new Point(event.stageX-pointOffSet.x, event.stageY-pointOffSet.y);
		pt = panel1.globalToContent(pt);
		
		dagNode.x = pt.x;
		dagNode.y = pt.y;
		
		//positioning line
		var ass:Association;
		var inAssociations:ArrayCollection;
		var inAsslength:int;
		var outAssociations:ArrayCollection;
		var outAsslength:int;
		var displayoutAssociations:ArrayCollection=dagNode.displayoutAssociations;
		var displaylength:int=displayoutAssociations.length
		var path:DAGPath=null;
		//Outgoing associations
		var operatorIndex:int =0; 
		outAssociations = dagNode.outAssociations;
		outAsslength = outAssociations.length;
		for(var i:int=0;i<outAsslength;i++)
		{
			ass = Association(outAssociations.getItemAt(i));
			//dagNode.name)//src
			panel1.removeChild(panel1.getChildByName(ass.associatedLink));
			path = dagPathUIMap.getValue(ass.associatedLink);
			dagPathUIMap.remove(ass.associatedLink);
			if(panel1.getChildByName(dagNode.name) == null || panel1.getChildByName(ass.associatedNode) == null)
			{
				Alert.show("Please select two nodes to link");
			}
			else
			{
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeInAssociation(dagNode.name,ass.associatedLink);
				linkNodes(dagNode.name,ass.associatedNode,path);
			}
		}
		for(var j:int=0;j<outAsslength;j++)
		{
			outAssociations.removeItemAt(j);
//			outAsslength--;
			
		}
		for(var j:int=0;j<displaylength;j++)
		{
			displayoutAssociations.removeItemAt(j);
//			displaylength--;
			
		}
		
		//Incoming associations
		inAssociations = dagNode.inAssociations;
		inAsslength = inAssociations.length;
		for(var k:int=0;k<inAsslength;k++)
		{
			ass = Association(inAssociations.getItemAt(k));
			//ass.associatedNode);//src
			panel1.removeChild(panel1.getChildByName(ass.associatedLink));
			path = dagPathUIMap.getValue(ass.associatedLink);
			dagPathUIMap.remove(ass.associatedLink);
			if(panel1.getChildByName(dagNode.name) == null || panel1.getChildByName(ass.associatedNode) == null)
			{
				Alert.show("Please select two nodes to link");
			}
			else
			{	
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeDisplayOutAssociation(dagNode.name,ass.associatedLink);
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeOutAssociation(dagNode.name,ass.associatedLink);
				linkNodes(ass.associatedNode,dagNode.name,path);
			}
			
		}
		for(var l:int=0;l<inAsslength;l++)
		{
			inAssociations.removeItemAt(l);
//			inAsslength--;
		}
	}
			
	private function initFlexInterfaceHandler(event: ResultEvent):void
	{
		//Alert.show("Intialized .....")
		rpcService.removeEventListener(ResultEvent.RESULT,initFlexInterfaceHandler,false);
	}
	
	private function restoreQueryObjectHandler(event: ResultEvent):void
	{
	//	Alert.show("restoring .....")
		rpcService.removeEventListener(ResultEvent.RESULT,restoreQueryObjectHandler,false);
		rpcService.addEventListener(ResultEvent.RESULT,repaintHandler);
	 	rpcService.repaintDAG();
		
	}
	/**
	
	**/
	private function initApp():void
	{
		registerClassAlias("edu.wustl.catissuecore.flex.dag.DAGNode", DAGNode);
		registerClassAlias("edu.wustl.catissuecore.flex.dag.DAGPath", DAGPath);
		rpcService= new RemoteObject();
		rpcService.destination="cdeService";
		isQuery =Application.application.parameters.isQuery;
		view= Application.application.parameters.view;
		dagPathUIMap = new HashMap();
		totalNodeMap = new HashMap();
		if (isContainerReady())
			{
			// If the container is ready, register the SWF functions.
				setUpCall();
			}
			else
			{
				/* If the container is not ready, set up a Timer to call the
				container at 100ms intervals. Once the container responds that
				is ready, the timer will be stopped. */
				readyTimer = new Timer(100);
				readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
				readyTimer.start();
			}
		
			if(view==DAGConstants.ADD_LIMIT_VIEW)
			{
				if(isQuery=="true")
				{
					rpcService.addEventListener(ResultEvent.RESULT,restoreQueryObjectHandler);
					rpcService.restoreQueryObject();
				}
				else
				{
					rpcService.initFlexInterface();
					rpcService.addEventListener(ResultEvent.RESULT,initFlexInterfaceHandler);
					rpcService.addEventListener(FaultEvent.FAULT, faultHandler);
				}
		    
			}
			else
		 	{
		 		rpcService.addEventListener(ResultEvent.RESULT,restoreQueryObjectHandler);
				rpcService.restoreQueryObject();
		 //	 	rpcService.addEventListener("result",repaintHandler);
		//	 	rpcService.repaintDAG();
		    }
		  
	}
	
	private function repaintHandler(event: ResultEvent):void
	{
		var nodeList:ArrayCollection = event.result  as ArrayCollection;
		var xpos:int =0;
		var ypos:int =0;
		for(var i:int=0;i<nodeList.length;i++)
		{
			var node:DAGNode = nodeList.getItemAt(i) as DAGNode;
			if(panel1.getChildren().length==1)
			{
				node.x = 20;
				node.y = (panel1.y+50);
			}
			else
			{ 
				var length:int=panel1.getChildren().length;
				node.x = 20;
				node.y = (panel1.y+50)+(40*length);
			}	
						
			node.name =  node.expressionId+"";
			node.nodeNumber = node.expressionId+"";
		
			node.addEventListener(MouseEvent.MOUSE_MOVE,doDrag);
			node.addEventListener(MouseEvent.CLICK,updateNodeSelection);

			if(isQuery == "true")
			{
				if(node.nodeType==DAGConstants.CONSTRAINT_ONLY_NODE)
				{
					node.nodeColor=0xffb693;
					panel1.addChild(node);
				}
				if(node.nodeType==DAGConstants.CONSTRAINT_VIEW_NODE)
				{
					panel1.addChild(node);
				}
			}
			else
			{
				if(node.nodeType==DAGConstants.CONSTRAINT_ONLY_NODE)
				{
					node.nodeColor=0xffb693;

				}
				if(node.nodeType==DAGConstants.VIEW_ONLY_NODE)
				{
					node.nodeColor =0xff8080;
				}
				panel1.addChild(node);
			}
			totalNodeMap.put(node.name,node);
			
		}
		for(var i:int=0;i<nodeList.length;i++)
		{

			var sourceNode:DAGNode = nodeList.getItemAt(i) as DAGNode;	
			var associationList:ArrayCollection = sourceNode.associationList;
//			var pathList:ArrayCollection  = sourceNode.pathList;
			var dagPathList:ArrayCollection = sourceNode.dagpathList;
			var operatorList:ArrayCollection = sourceNode.operatorList;

			 for(var j:int=0;j<associationList.length;j++)
			 {	
			    var targetNode:DAGNode = associationList.getItemAt(j) as DAGNode;	
				var path:DAGPath = dagPathList.getItemAt(j) as DAGPath;
			    var operator:String = operatorList.getItemAt(j) as String;
				var operatorSelectedIndex:int=0;
			    if(operator=="OR")
			    {
			     	path.operatorIndex=1;
			    }
			  	if(isQuery == "true")
				{
	                sourceNode.enable=true;
				}
				else
				 {
	                sourceNode.enable=false;
				 }
                try
                {
					linkNodes(sourceNode.expressionId.toString(),targetNode.expressionId.toString(),path);
                }catch(error:TypeError)
                {
                	Alert.show("Error:"+error.message);	
                }
			 	
			 }
		}
		rpcService.removeEventListener(ResultEvent.RESULT,repaintHandler,false)
	}
	

	public function addNodeToView(nodesStr:String):void
	{
		rpcService.removeEventListener(ResultEvent.RESULT,repaintHandler);
		rpcService.addEventListener(ResultEvent.RESULT,addNodeToViewHandler);
		rpcService.addNodeToView(nodesStr);
	}	
		
	private function addNodeToViewHandler(event: ResultEvent):void 		
	{
		textData = event.result;
		if(textData!=null)
		{
			isOutputView = true;
			this.addNode();
		}
		rpcService.removeEventListener(ResultEvent.RESULT,addNodeToViewHandler,false);
	}
			
	public function searchResult():void
	{
		rpcService.addEventListener(ResultEvent.RESULT,searchResultHandler);
		rpcService.getSearchResult();
	}
	
	private function searchResultHandler(event: ResultEvent):void 
	{
		var status:int =event.result as int;
		
		
		switch(status)
		{
			case DAGConstants.SUCCESS:
							ExternalInterface.call("showViewSearchResultsJsp");
							break;
			case DAGConstants.NO_RESULT_PRESENT:
							showValidationMessagesToUser(DAGConstants.NO_RESULT_PRESENT_MESSAGE);
							break;
			case DAGConstants.EMPTY_DAG:
							ExternalInterface.call("showErrorPage");
							break;
			case DAGConstants.MULTIPLE_ROOT:
							showValidationMessagesToUser(DAGConstants.MULTIPLE_ROOT_MESSAGE);
							break;
			case DAGConstants.CLASS_NOT_FOUND:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.SQL_EXCEPTION:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.DAO_EXCEPTION:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.TREE_NODES_LIMIT:		
							ExternalInterface.call("openDecisionMakingPage");		
							break;
			default:break; 				
		}
		rpcService.removeEventListener(ResultEvent.RESULT,searchResultHandler,false);
		
	}
	
	public function showValidationMessagesToUser(errorMessage:String):void
	{
		var paramArray:Array = new Array(errorMessage);
		ExternalInterface.call("showValidationMessages",paramArray);
	}
	
	public function createNode(strToCreateQueyObject:String,entityName:String):void
	{
		if(strToCreateQueyObject=="")	
		{
			showValidationMessagesToUser(DAGConstants.EMPTY_LIMIT_ERROR_MESSAGE);
		}
		else
		{
			rpcService.addEventListener(ResultEvent.RESULT,getNodeResultHandler);
			rpcService.createNode(strToCreateQueyObject,entityName);
			showValidationMessagesToUser("");
		}
	}
	
	public function linkNodesHandler(event: ResultEvent):void
	{
		var selectedList:ArrayCollection =  event.result  as  ArrayCollection;

		var path:DAGPath =null;
		if(selectedList!=null)
		{
		//	linkCount=0;
			if(selectedList.length > 1)
			{
				Alert.show("Multiple associations not yet supoorted.");		
			}
			else
			{
				path = selectedList.getItemAt(0) as DAGPath;
				linkNodes(firstNode,secondNode,path);
			}
		}
		else
		{
			Alert.show("No association present or no association selected.");
		}
		rpcService.removeEventListener(ResultEvent.RESULT,linkNodesHandler,false);
	}
/*	//code for multiple association
		if(selectedList.length > 0 )
			{
				
				var numAssociation:int=selectedList.length
				for(var i:int;i<numAssociation;i++)
				{
					
					path = selectedList.getItemAt(i) as DAGPath;
					path.operatorIndex=0;
					linkNodes(firstNode,secondNode,path);
				}
				selectedList=null;
			}
			else
			{
				path = selectedList.getItemAt(0) as IDAGPath;
				linkNodes(firstNode,secondNode,path);
			}
			//linkCount++;
		}*/

	<commit_msg>Multi association condition removed from here and placed it in ambiguity resolver<commit_after><?xml version="1.0" encoding="utf-8"?>

<mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="vertical" dragEnter="doDragEnter(event)" dragDrop="onDragDrop(event)" 
xmlns:Components="Components.*" xmlns:display="flash.display.*"
creationComplete="initApp()"  width="100%" height="100%" paddingTop="0" paddingBottom="0" paddingLeft="0" paddingRight="0">
<mx:Script>
<![CDATA[
	import Components.DAGPath;
	
	import mx.controls.ComboBase;
	import Components.DAGConstants;
	import mx.containers.HBox;
	import mx.controls.ComboBox;
    import mx.controls.ToolTip;
    import mx.managers.ToolTipManager;
	import mx.containers.VBox;
	import mx.controls.Button;
	import mx.utils.ArrayUtil;
	import mx.controls.DataGrid;
	import mx.containers.Accordion;
	import mx.controls.List;
	import Components.Association;
	import Components.DAGPath;
	import mx.collections.ArrayCollection;
	import mx.states.SetEventHandler;
	import mx.core.UIComponent;
	import Components.DAGNode;
	import mx.containers.Canvas;
	import mx.core.IUIComponent;
	import mx.controls.Alert;
	import mx.events.DragEvent;
	import mx.core.DragSource;
	import mx.managers.DragManager;
	import mx.events.MenuEvent;
	import flash.external.ExternalInterface;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import mx.rpc.events.FaultEvent;
	import flash.net.registerClassAlias;
	import Components.AmbiguityPanel;
	import mx.managers.PopUpManager;
   	import mx.core.IFlexDisplayObject;
   	import mx.containers.ControlBar;
    import mx.controls.Spacer;
    import mx.containers.ControlBar;
   	import mx.controls.Menu;
    import Util.HashMap;
	
	public var readyTimer:Timer;
	private var dynamicNodeNum:int = 1;
	private var linkNum:int = 1;
	private var node1:String = "";
	private var node2:String = "";
	private var selectedLink:String = "";
	private var selectedNode:DAGNode=null;
	//------------------------
	private var textData:Object = null;
    private var panel:AmbiguityPanel; 
    private var title:String  = new String();
    private var selectedNodeList:ArrayCollection = new ArrayCollection();
    private var count:int = 0;
    private var resultStr:String = "failed";
    private var firstNode:String;
    private var secondNode:String;
    //private var linkCount:int =0;
	private var pathStr:String
	private	var isQuery:String = "false";
	public var isOutputView:Boolean=false;
	public var rpcService: RemoteObject;
	public var view:String ="";
	public var dagPathUIMap:HashMap;
	public var totalNodeMap:HashMap;
	
	
	public function timerHandler():void
	{
		if (isContainerReady())
		{
			// If the container is ready, register the SWF�s functions.
			setUpCall();
			readyTimer.stop();
		}
	}

	public function setUpCall():void 
	{
		ExternalInterface.addCallback("createNode",createNode);		
		ExternalInterface.addCallback("editLimit",editLimit);	
		ExternalInterface.addCallback("searchResult",searchResult);	
		ExternalInterface.addCallback("addNodeToView",addNodeToView);
	}
	
	//setup the callback function so that HTML can call flex methods
	//Checks wheather HTML page is loaded or not.
	private function isContainerReady():Boolean
	{
		var result:Boolean = ExternalInterface.call("isReady");
		return result;
	}
		
	private function faultHandler (event:FaultEvent):void
	{
		// Deal with event.fault.faultString, etc.
		Alert.show(event.fault.faultString, 'Error');
	}
	
		//-----------------
	private function doDrag(event:MouseEvent):void
	{
		var dragInitiator:DAGNode = DAGNode(event.currentTarget);
		var ds:DragSource = new DragSource();
		
		var canvasProxy:DAGNode = new DAGNode();
		canvasProxy.nodeNumber = dragInitiator.nodeNumber;
		canvasProxy.nodeName =dragInitiator.nodeName;
		
		
		var pointOffSet:Point = new Point(dragInitiator.mouseX,dragInitiator.mouseY);
		ds.addData(pointOffSet,"point");
		
		DragManager.doDrag(dragInitiator,ds,event,canvasProxy,0,0);
	}
	
	private function doDragEnter(event:DragEvent):void{
		DragManager.acceptDragDrop(event.currentTarget as IUIComponent)
	}
	
	private function onDragDrop(event:DragEvent):void{
		var dagNode:DAGNode = DAGNode(event.dragInitiator) ;
		var pointOffSet:Point = Point(event.dragSource.dataForFormat("point") );
		
		var pt:Point = new Point(event.stageX-pointOffSet.x, event.stageY-pointOffSet.y);
		pt = panel1.globalToContent(pt);
		
		dagNode.x = pt.x;
		dagNode.y = pt.y;
		
		//positioning line
		var ass:Association;
		var inAssociations:ArrayCollection;
		var inAsslength:int;
		var outAssociations:ArrayCollection;
		var outAsslength:int;
		var displayoutAssociations:ArrayCollection=dagNode.displayoutAssociations;
		var displaylength:int=displayoutAssociations.length
		var path:DAGPath=null;
		//Outgoing associations
		var operatorIndex:int =0; 
		outAssociations = dagNode.outAssociations;
		outAsslength = outAssociations.length;
		for(var i:int=0;i<outAsslength;i++)
		{
			ass = Association(outAssociations.getItemAt(i));
			//dagNode.name)//src
			panel1.removeChild(panel1.getChildByName(ass.associatedLink));
			path = dagPathUIMap.getValue(ass.associatedLink);
			dagPathUIMap.remove(ass.associatedLink);
			if(panel1.getChildByName(dagNode.name) == null || panel1.getChildByName(ass.associatedNode) == null)
			{
				Alert.show("Please select two nodes to link");
			}
			else
			{
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeInAssociation(dagNode.name,ass.associatedLink);
				linkNodes(dagNode.name,ass.associatedNode,path);
			}
		}
		for(var j:int=0;j<outAsslength;j++)
		{
			outAssociations.removeItemAt(j);
//			outAsslength--;
			
		}
		for(var j:int=0;j<displaylength;j++)
		{
			displayoutAssociations.removeItemAt(j);
//			displaylength--;
			
		}
		
		//Incoming associations
		inAssociations = dagNode.inAssociations;
		inAsslength = inAssociations.length;
		for(var k:int=0;k<inAsslength;k++)
		{
			ass = Association(inAssociations.getItemAt(k));
			//ass.associatedNode);//src
			panel1.removeChild(panel1.getChildByName(ass.associatedLink));
			path = dagPathUIMap.getValue(ass.associatedLink);
			dagPathUIMap.remove(ass.associatedLink);
			if(panel1.getChildByName(dagNode.name) == null || panel1.getChildByName(ass.associatedNode) == null)
			{
				Alert.show("Please select two nodes to link");
			}
			else
			{	
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeDisplayOutAssociation(dagNode.name,ass.associatedLink);
				DAGNode(panel1.getChildByName(ass.associatedNode)).removeOutAssociation(dagNode.name,ass.associatedLink);
				linkNodes(ass.associatedNode,dagNode.name,path);
			}
			
		}
		for(var l:int=0;l<inAsslength;l++)
		{
			inAssociations.removeItemAt(l);
//			inAsslength--;
		}
	}
			
	private function initFlexInterfaceHandler(event: ResultEvent):void
	{
		//Alert.show("Intialized .....")
		rpcService.removeEventListener(ResultEvent.RESULT,initFlexInterfaceHandler,false);
	}
	
	private function restoreQueryObjectHandler(event: ResultEvent):void
	{
	//	Alert.show("restoring .....")
		rpcService.removeEventListener(ResultEvent.RESULT,restoreQueryObjectHandler,false);
		rpcService.addEventListener(ResultEvent.RESULT,repaintHandler);
	 	rpcService.repaintDAG();
		
	}
	/**
	
	**/
	private function initApp():void
	{
		registerClassAlias("edu.wustl.catissuecore.flex.dag.DAGNode", DAGNode);
		registerClassAlias("edu.wustl.catissuecore.flex.dag.DAGPath", DAGPath);
		rpcService= new RemoteObject();
		rpcService.destination="cdeService";
		isQuery =Application.application.parameters.isQuery;
		view= Application.application.parameters.view;
		dagPathUIMap = new HashMap();
		totalNodeMap = new HashMap();
		if (isContainerReady())
			{
			// If the container is ready, register the SWF functions.
				setUpCall();
			}
			else
			{
				/* If the container is not ready, set up a Timer to call the
				container at 100ms intervals. Once the container responds that
				is ready, the timer will be stopped. */
				readyTimer = new Timer(100);
				readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
				readyTimer.start();
			}
		
			if(view==DAGConstants.ADD_LIMIT_VIEW)
			{
				if(isQuery=="true")
				{
					rpcService.addEventListener(ResultEvent.RESULT,restoreQueryObjectHandler);
					rpcService.restoreQueryObject();
				}
				else
				{
					rpcService.initFlexInterface();
					rpcService.addEventListener(ResultEvent.RESULT,initFlexInterfaceHandler);
					rpcService.addEventListener(FaultEvent.FAULT, faultHandler);
				}
		    
			}
			else
		 	{
		 		rpcService.addEventListener(ResultEvent.RESULT,restoreQueryObjectHandler);
				rpcService.restoreQueryObject();
		 //	 	rpcService.addEventListener("result",repaintHandler);
		//	 	rpcService.repaintDAG();
		    }
		  
	}
	
	private function repaintHandler(event: ResultEvent):void
	{
		var nodeList:ArrayCollection = event.result  as ArrayCollection;
		var xpos:int =0;
		var ypos:int =0;
		for(var i:int=0;i<nodeList.length;i++)
		{
			var node:DAGNode = nodeList.getItemAt(i) as DAGNode;
			if(panel1.getChildren().length==1)
			{
				node.x = 20;
				node.y = (panel1.y+50);
			}
			else
			{ 
				var length:int=panel1.getChildren().length;
				node.x = 20;
				node.y = (panel1.y+50)+(40*length);
			}	
						
			node.name =  node.expressionId+"";
			node.nodeNumber = node.expressionId+"";
		
			node.addEventListener(MouseEvent.MOUSE_MOVE,doDrag);
			node.addEventListener(MouseEvent.CLICK,updateNodeSelection);

			if(isQuery == "true")
			{
				if(node.nodeType==DAGConstants.CONSTRAINT_ONLY_NODE)
				{
					node.nodeColor=0xffb693;
					panel1.addChild(node);
				}
				if(node.nodeType==DAGConstants.CONSTRAINT_VIEW_NODE)
				{
					panel1.addChild(node);
				}
			}
			else
			{
				if(node.nodeType==DAGConstants.CONSTRAINT_ONLY_NODE)
				{
					node.nodeColor=0xffb693;

				}
				if(node.nodeType==DAGConstants.VIEW_ONLY_NODE)
				{
					node.nodeColor =0xff8080;
				}
				panel1.addChild(node);
			}
			totalNodeMap.put(node.name,node);
			
		}
		for(var i:int=0;i<nodeList.length;i++)
		{

			var sourceNode:DAGNode = nodeList.getItemAt(i) as DAGNode;	
			var associationList:ArrayCollection = sourceNode.associationList;
//			var pathList:ArrayCollection  = sourceNode.pathList;
			var dagPathList:ArrayCollection = sourceNode.dagpathList;
			var operatorList:ArrayCollection = sourceNode.operatorList;

			 for(var j:int=0;j<associationList.length;j++)
			 {	
			    var targetNode:DAGNode = associationList.getItemAt(j) as DAGNode;	
				var path:DAGPath = dagPathList.getItemAt(j) as DAGPath;
			    var operator:String = operatorList.getItemAt(j) as String;
				var operatorSelectedIndex:int=0;
			    if(operator=="OR")
			    {
			     	path.operatorIndex=1;
			    }
			  	if(isQuery == "true")
				{
	                sourceNode.enable=true;
				}
				else
				 {
	                sourceNode.enable=false;
				 }
                try
                {
					linkNodes(sourceNode.expressionId.toString(),targetNode.expressionId.toString(),path);
                }catch(error:TypeError)
                {
                	Alert.show("Error:"+error.message);	
                }
			 	
			 }
		}
		rpcService.removeEventListener(ResultEvent.RESULT,repaintHandler,false)
	}
	

	public function addNodeToView(nodesStr:String):void
	{
		rpcService.removeEventListener(ResultEvent.RESULT,repaintHandler);
		rpcService.addEventListener(ResultEvent.RESULT,addNodeToViewHandler);
		rpcService.addNodeToView(nodesStr);
	}	
		
	private function addNodeToViewHandler(event: ResultEvent):void 		
	{
		textData = event.result;
		if(textData!=null)
		{
			isOutputView = true;
			this.addNode();
		}
		rpcService.removeEventListener(ResultEvent.RESULT,addNodeToViewHandler,false);
	}
			
	public function searchResult():void
	{
		rpcService.addEventListener(ResultEvent.RESULT,searchResultHandler);
		rpcService.getSearchResult();
	}
	
	private function searchResultHandler(event: ResultEvent):void 
	{
		var status:int =event.result as int;
		
		
		switch(status)
		{
			case DAGConstants.SUCCESS:
							ExternalInterface.call("showViewSearchResultsJsp");
							break;
			case DAGConstants.NO_RESULT_PRESENT:
							showValidationMessagesToUser(DAGConstants.NO_RESULT_PRESENT_MESSAGE);
							break;
			case DAGConstants.EMPTY_DAG:
							ExternalInterface.call("showErrorPage");
							break;
			case DAGConstants.MULTIPLE_ROOT:
							showValidationMessagesToUser(DAGConstants.MULTIPLE_ROOT_MESSAGE);
							break;
			case DAGConstants.CLASS_NOT_FOUND:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.SQL_EXCEPTION:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.DAO_EXCEPTION:
							showValidationMessagesToUser(DAGConstants.GENERIC_MESSAGE)
							break;
			case DAGConstants.TREE_NODES_LIMIT:		
							ExternalInterface.call("openDecisionMakingPage");		
							break;
			default:break; 				
		}
		rpcService.removeEventListener(ResultEvent.RESULT,searchResultHandler,false);
		
	}
	
	public function showValidationMessagesToUser(errorMessage:String):void
	{
		var paramArray:Array = new Array(errorMessage);
		ExternalInterface.call("showValidationMessages",paramArray);
	}
	
	public function createNode(strToCreateQueyObject:String,entityName:String):void
	{
		if(strToCreateQueyObject=="")	
		{
			showValidationMessagesToUser(DAGConstants.EMPTY_LIMIT_ERROR_MESSAGE);
		}
		else
		{
			rpcService.addEventListener(ResultEvent.RESULT,getNodeResultHandler);
			rpcService.createNode(strToCreateQueyObject,entityName);
			showValidationMessagesToUser("");
		}
	}
	
	public function linkNodesHandler(event: ResultEvent):void
	{
		var selectedList:ArrayCollection =  event.result  as  ArrayCollection;

		var path:DAGPath =null;
		if(selectedList!=null)
		{
		//	linkCount=0;
			path = selectedList.getItemAt(0) as DAGPath;
			linkNodes(firstNode,secondNode,path);
			
		}
		else
		{
			Alert.show("No association present or no association selected.");
		}
		rpcService.removeEventListener(ResultEvent.RESULT,linkNodesHandler,false);
	}
/*	//code for multiple association
		if(selectedList.length > 0 )
			{
				
				var numAssociation:int=selectedList.length
				for(var i:int;i<numAssociation;i++)
				{
					
					path = selectedList.getItemAt(i) as DAGPath;
					path.operatorIndex=0;
					linkNodes(firstNode,secondNode,path);
				}
				selectedList=null;
			}
			else
			{
				path = selectedList.getItemAt(0) as IDAGPath;
				linkNodes(firstNode,secondNode,path);
			}
			//linkCount++;
		}*/

	
{'fraction_non_alphanumeric': 0.1144214014827975, 'fraction_numerical': 0.006320680583552564, 'mean_word_length': 4.099303135888502, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 2, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1841956', 'n_tokens_mistral': 10940, 'n_tokens_neox': 9355, 'n_words': 1453}