<%
/*********************************************************************************************************
*	Name			:	EgVmwareCompGraphData.jsp
*	Version			:	eG 4.0
*	Purpose			:	To show the Topology graph for VMWARE components
*	Creation Date	:	20/06/2007
*	Author			:	Alagu sundaram
********************************************************************************************************/
%>
<%@ include file = "EgMonitorTracker.jsp" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page import="com.eg.EgInstallInfo" %>
<%@ page import="com.eg.EgExternalInfo" %>
<%@ page import="com.eg.IniFile" %>
<%@ page import="com.eg.EgStateZone" %>
<%@ page import="egurkha.EgAspLite" %>
<%@ page import = "com.egurkha.ini.*" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import="java.util.*" %>
<%@ page import = "com.eg.EgStateZone" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "com.egurkha.monitor.VMDesktopBean" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import = "com.eg.*" %>
<%@ page import = "net.sf.json.*" %>
<%@ page import = "com.egurkha.util.*"%>
<%@ page import = "com.egurkha.monitor.alarms.AlarmPriorities" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader ("Expires", -1);
%>

<%
	UserRegistry registry = UserRegistry.getInstance();
	String sessionID = null;
	User user = null;//registry.getUser(session.getId());
	/*if(from_sm)
	{
		sessionID = sessionId_sm;
		user = registry.getUser(sessionID);
	}
	else
	{*/
		sessionID = session.getId();
		user = registry.getUser(sessionID);
	//}
	String showVmDetails="";
	String ua = request.getHeader( "User-Agent" );
	boolean isFirefox = ( ua != null && ua.indexOf("Firefox/" ) != -1 );
	boolean isMSIE = ( ua != null && ua.indexOf( "MSIE " ) != -1 );

	boolean userViolated = false;
	ArrayList userBasedCompTypeList=new ArrayList();
	if(u_rs!=null && u_rs.trim().length()>0)
	{
		GroupCertValidator licenseChecker = new GroupCertValidator(u_rs);
		userViolated = licenseChecker.checkForUserViolation(u_rs);
		if(userViolated)
		{
			EgUsersInfo usersInfo = new EgUsersInfo();
			userBasedCompTypeList = (ArrayList)usersInfo.getAllUserBasedCompTypes();
		}
	}
	
	String isDivPopup=request.getParameter("isDivPopup");
	String isclick=request.getParameter("isclick");
	isDivPopup=(isDivPopup==null)?"":isDivPopup;
	isclick=(isclick==null)?"":isclick;
	String refFrequency = user.getRefreshFrequency();
	long refreshFrequency=60000L;
	if(refFrequency!=null && refFrequency.length()>0)
	{
		refreshFrequency =  Long.valueOf(refFrequency).longValue() * 1000L;
	}
	String strShowVmDetails=request.getParameter("showVmDetails");
	String fromMenu=request.getParameter("fromMenu");
	showVmDetails=(strShowVmDetails==null || strShowVmDetails.trim().length()==0)?"":strShowVmDetails;

	IniUI iniUI = IniUI.getInstance();
	String thisLanguage = iniUI.getDefaultLanguage();
	//EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);

	JSONObject json = new JSONObject();
	JSONObject screenLabels = new JSONObject();
	JSONObject hiddenFields = new JSONObject();
	JSONArray selectOptions = new JSONArray();
	JSONObject selectedField = new JSONObject();

	VMDesktopBean vmDesktopBean = new VMDesktopBean(request);
	AlarmPriorities ap = AlarmPriorities.getInstance();

	String state = request.getParameter("state");
	String s_userid = user.getLoginID();
	String segment = request.getParameter("Vmhost");
	String topolink=request.getParameter("fromTopology");
	String hostType = request.getParameter("vmcomp_type");
	boolean hideVMDetailsWin=false;
	if(hostType!=null && hostType.trim().length()>0 && hostType.equalsIgnoreCase("Docker_server"))
		hideVMDetailsWin=true;

	String port =request.getParameter("port");
	String fromSuper = (String)session.getAttribute("fromSuper");
	String showOtherVMs = request.getParameter("showOtherVMs");
	boolean showOtherVm = false;
	if(showOtherVMs != null && showOtherVMs.trim().length() > 0 && (showOtherVMs.equalsIgnoreCase("true") || showOtherVMs.equalsIgnoreCase("yes") || showOtherVMs.equalsIgnoreCase("y")) )
		showOtherVm = true;
	String serviceName = request.getParameter("serviceName");
	String segmentOrgName = request.getParameter("segmentOrgName");
	String topologySkin=user.getMonitorSkin();
	String Vmhost ="";
	StringTokenizer strtok = new StringTokenizer(segment,":");
	int counttok = strtok.countTokens();
	if(counttok>=3)
	{
		strtok.nextToken();
		segment = strtok.nextToken();
	}

	String isfromCitrix=request.getParameter("isfromCitrix");
	String isfromRum=request.getParameter("isfromRum");
	String filter = request.getParameter("filter");
	String filterBy = request.getParameter("filterBy");
	String isFromServiceMenu = request.getParameter("isFromServiceMenu");
	String isFromZoneMain = request.getParameter("isFromZoneMain");
	String isFromZoneMenu = request.getParameter("isFromZoneMenu");
	String isFromServiceGroup = request.getParameter("isFromServiceGroup");	
	String selectedRum = request.getParameter("selectedRum");
	String serviceTopology = request.getParameter("serviceTopology");

	String dashboard_mapping = request.getParameter("dashboard_mapping");
	String user_name = request.getParameter("user_name");	
	String view_name = request.getParameter("view_name");	
	String activeView = request.getParameter("activeView");
	String dashboard_name = request.getParameter("dashboard_name");
	String fromServiceHomePage = request.getParameter("fromServiceHomePage");
	String segmentName = request.getParameter("segmentName");
	String fromLayerModelVirtual = request.getParameter("fromLayerModelVirtual");

	String isFromZone = request.getParameter("isFromZone");
	String iszoneName = request.getParameter("iszoneName");
	String parentZone = request.getParameter("parentZone");
	boolean isfromLayerModelVirtual = false;
	if(fromLayerModelVirtual!= null && fromLayerModelVirtual.trim().length()>0 && !fromLayerModelVirtual.equalsIgnoreCase("null") && fromLayerModelVirtual.equalsIgnoreCase("true"))
	{
		isfromLayerModelVirtual = true;
	}
	boolean isJS = false;
	String jsOption = 	iniUI.getValue("TOPOLOGY_OPTIONS","Javascript");
	if(jsOption!=null && jsOption.length() > 0)
	{
		if(jsOption.equalsIgnoreCase("yes") || jsOption.equalsIgnoreCase("true"))
			isJS = true;
		else if(jsOption.equalsIgnoreCase("auto"))
		{
			String max_limit = iniUI.getValue("TOPOLOGY_OPTIONS","Max_limit");
			int max = 100; // Default value
			try{
				max = Integer.parseInt(max_limit);
			}
			catch(Exception exp){
				max = 100;
			}
			IniFile topologyIni=new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_topology.ini");
			String[] totalVariables =  topologyIni.getVariables(segment);
			int totalComps = 0;
			if(totalVariables!=null)
				totalComps = totalVariables.length;
			if(totalComps > max)
				isJS = false;
			else
				isJS = true;
		}
	}
	String zoomLevel = request.getParameter("zoom");
	if(zoomLevel==null)
	{
		zoomLevel = "100";
	}
	boolean isTopoLinkFlag = false;

	EgExternalInfo e = new EgExternalInfo("manager");
	Vector virtualhostname=new Vector();
	Vector virthostname=e.getvmWareHosts();
	Vector cloudhostname = new Vector();
	cloudhostname = e.getCloudHosts();
	Vector virtualcomps = e.getVirtualServers();
	Vector cloudComp = e.getCloudServers();
	if (virtualcomps!=null && hostType!=null && virtualcomps.contains(hostType))
	{
		virtualhostname = virthostname;
	}
	if (cloudComp!=null && hostType!=null && cloudComp.contains(hostType))
	{
		virtualhostname = cloudhostname;
	}
	String site = request.getParameter("site");
	boolean showOtherVMstate = true;
	if(site != null && !site.equals("") && site.trim().length() > 0)
	{
		if(showOtherVMs.equalsIgnoreCase("false"))
			showOtherVMstate = false;
	}

	ErUserData UBean = user.getReporterData();
	Vector vmassociatedcomp=UBean.getAllUserComponents(3);
	String hostState = "";
	if(site != null && !site.equals("") && site.trim().length() > 0)
		hostState=vmDesktopBean.getVmhostState(hostType+":"+segment+":"+port,site,showOtherVMstate);
	else
		hostState=vmDesktopBean.getVmhostState(hostType+":"+segment+":"+port);
	String pageStr=null;
	String title = "";
	String compType=request.getParameter("compType");
	String compName=request.getParameter("componentName");
	String QryStr="virtualCompdetails.jsp?vmHost="+EgURLEncoder.encode(hostType+":"+segment+":"+port,"UTF-8")+"&vmware="+EgURLEncoder.encode(hostType,"UTF-8")+"&fromPage=mainWindow&isclick="+isclick;

	if(topolink!=null && topolink.equalsIgnoreCase("yes"))
	{
		//compName = compName.substring(0,compName.indexOf(":"));
		if (compName != null && compName.endsWith(EgConstants.NULL_PORT) && (compName.indexOf(EgConstants.NULL_PORT) > -1))
		{
			compName  = Server.getServerNameWithoutPort(compName, false);
		}
		title = mappingInfo.getTextDescription("monitor.topology.Virtual Topology for")+" "+mappingInfo.getComponentTypeDescription(compType)+" "+mappingInfo.getTextDescription("monitor.topology.application")+" - "+compName;
		//pageStr = "header.jsp?title="+title+"&state_str="+hostState+"&vmHost="+hostType+":"+segment+":"+port+"&vmware="+hostType;
	}
	else
	{
		title = mappingInfo.getTextDescription("monitor.title.Component Topology")+" : "+segment;
		//pageStr = "header.jsp?title=+"&state_str="+hostState+"&vmHost="+hostType+":"+segment+":"+port+"&vmware="+hostType;
	}
	screenLabels.put("title",title);

	hiddenFields.put("showVmDetails",showVmDetails);
	hiddenFields.put("refreshFrequency",refreshFrequency);
	hiddenFields.put("currentState",hostState);

	if (virtualhostname!=null && virtualhostname.size()==1)
	{
		Vmhost =(String)virtualhostname.elementAt(0);
	}
	//else if(virtualhostname.size() > 1&&topolink==null)
	if(virtualhostname.size() > 0 && topolink==null)
	{
		screenLabels.put("SelectComponent",mappingInfo.getTextDescription("monitor.virtual.Select a Component"));
		hiddenFields.put("hidHostType",hostType);
		hiddenFields.put("hidPort",port);
		EgList egcompList = new EgList();
		
		CompositeComparator compObj = new CompositeComparator();
		Hashtable valueHash = new Hashtable();
		Hashtable stateHash = new Hashtable();
		for(int i=0;i<virtualhostname.size();i++)
		{
			String vmx=(String)virtualhostname.elementAt(i);
			String vmxvalue="";
			String vmType="";
			String vmPort="";

			StringTokenizer sttr=new StringTokenizer(vmx,":");
			int tok= sttr.countTokens();
			if(tok > 0)
			{
				vmType=sttr.nextToken();
				vmxvalue=sttr.nextToken();
				vmPort=sttr.nextToken();
			}
			else
			{
				vmxvalue=(String)virtualhostname.elementAt(i);
			}
			String temp=vmx.substring(vmx.indexOf(":")+1)+":"+vmx.substring(0,vmx.indexOf(":"));
			if(!vmassociatedcomp.contains(temp))
						continue;
			if(vmxvalue.equals(segment))
				Vmhost =(String)virtualhostname.elementAt(i);

			
			String state_of_comp= ap.getAlarmPriority(Server.getServerName(vmType+":"+vmxvalue+":"+vmPort), vmType,"NULL");
			state_of_comp=(state_of_comp==null || state_of_comp.trim().length()==0)?"GOOD":state_of_comp;
			
			EgObject tmp_compName = new EgObject(vmx, State.getState(state_of_comp));
			
			valueHash.put(vmx,vmxvalue);
			stateHash.put(vmx,state_of_comp);
			if(tmp_compName != null)
				egcompList.add(tmp_compName);
		}
		compObj.add(new StateComparatorDes());
		compObj.add(new NameComparatorAsc());
		Collections.sort(egcompList,compObj);

			
		if(egcompList!=null && egcompList.size()>0)
		{
			for(int s=0;s<egcompList.size();s++)
			{
				EgObject t_compName = (EgObject) egcompList.get(s);
				try
				{
					String conp_name = (String)t_compName.getName();
					String valueField = (String)valueHash.get(conp_name);
					String com_state = (String)stateHash.get(conp_name);

					JSONObject option  = new JSONObject();
					option.put("valueField", conp_name);
					option.put("state", com_state);
					option.put("displayField", valueField);
					selectOptions.add(option);

					if(segment.equals(valueField))
					{
						selectedField.put("chosenField",conp_name);
						selectedField.put("stateField",com_state);
					}
				}
				catch (Exception rret)
				{
				}
			}
		}

		selectedField.put("selectOptions",selectOptions);

		String defaultQryStr="virtualCompdetails.jsp?vmHost="+EgURLEncoder.encode(Vmhost,"UTF-8")+"&vmware="+EgURLEncoder.encode(hostType,"UTF-8")+"&fromPage=mainWindow";

		QryStr="virtualCompdetails.jsp?vmHost="+EgURLEncoder.encode(Vmhost,"UTF-8")+"&vmware="+EgURLEncoder.encode(hostType,"UTF-8")+"&fromPage=mainWindow&isclick="+isclick;

		screenLabels.put("VMDetails",mappingInfo.getTextDescription("monitor.topology.Click here for VM details"));
		hiddenFields.put("isDivPopup",isDivPopup);
		hiddenFields.put("popupUrl",QryStr);
		hiddenFields.put("isclick",isclick);
	}
	else if(topolink!=null&&topolink.equals("yes"))
	{
		Collections.sort(virtualhostname);
		for(int i=0;i<virtualhostname.size();i++)
		{
			String vmx=(String)virtualhostname.elementAt(i);
			String vmxvalue="";
  
			StringTokenizer sttr=new StringTokenizer(vmx,":");
			int tok= sttr.countTokens();
			if(tok > 0)
			{
				sttr.nextToken();
				vmxvalue=sttr.nextToken();
			}
			else
			{
				vmxvalue=(String)virtualhostname.elementAt(i);
			}
			String temp=vmx.substring(vmx.indexOf(":")+1)+":"+vmx.substring(0,vmx.indexOf(":"));
			if(!vmassociatedcomp.contains(temp))
						continue;
			if(vmxvalue.equals(segment))
				Vmhost =(String)virtualhostname.elementAt(i);
		}
		isTopoLinkFlag = true;
		screenLabels.put("InfraSupportedBy",mappingInfo.getTextDescription("monitor.topology.Virtual Infrastructure supported by ") + segment);

		QryStr="virtualCompdetails.jsp?vmHost="+EgURLEncoder.encode(Vmhost,"UTF-8")+"&vmware="+EgURLEncoder.encode(hostType,"UTF-8")+"&fromPage=mainWindow&isclick="+isclick;

		hiddenFields.put("isDivPopup",isDivPopup);
		hiddenFields.put("popupUrl",QryStr);
		hiddenFields.put("isclick",isclick);
	}

		String thisSite = request.getParameter("site");
		if(thisSite==null)	
		thisSite ="";
		/*String frameSrc = "EgTopologyJS.jsp?segment="+EgURLEncoder.encode(segment,"UTF-8")+
				"&physical_topology=2"+
				"&type=virtual" + "&Vmhost="+EgURLEncoder.encode(Vmhost,"UTF-8")+ "&site="+EgURLEncoder.encode(thisSite,"UTF-8")+
				"&vmware=true"+
				"&zoom="+EgURLEncoder.encode(zoomLevel,"UTF-8");//+"&sessionId_SM="+sessionId_sm;*/

				/**
				* EgTopologyJS.jsp for Raphael JS Library
				* "EgVMTopologyD3JS.jsp for D3JS
				*/
				String frameSrc = "EgVMTopologyD3JS.jsp?segment="+EgURLEncoder.encode(segment,"UTF-8")+
				"&physical_topology=2"+
				"&type=virtual" + "&Vmhost="+EgURLEncoder.encode(Vmhost,"UTF-8")+ "&site="+EgURLEncoder.encode(thisSite,"UTF-8")+
				"&vmware=true"+
				"&zoom="+EgURLEncoder.encode(zoomLevel,"UTF-8")+"&vmcomp_type="+hostType+"&state="+state+"&port="+port+"&showOtherVMs="+showOtherVMs;//+"&sessionId_SM="+sessionId_sm;
	if(segmentOrgName!=null && segmentOrgName.trim().length()>0)
	{
		frameSrc = frameSrc + "&segmentOrgName="+segmentOrgName;
	}
	//String graphData="<iframe id='topoIframeId'  width='100%' height='100%' src='"+frameSrc+"' border='0' scrolling='yes' marginwidth='0px' marginheight='0px' frameborder='0' color='blue' style='border-width:0px; border-style:solid; border-color:yellow;' ></iframe>";
	String graphData="";

	//Code to create JSON for new view in Virtual Topology
	List vmComponents = null;
	if(Vmhost!=null || (!Vmhost.equals("null")))
	{
		if(thisSite!=null && thisSite.trim().length()>0 && thisSite.equalsIgnoreCase("egurkha.physical.topology") && (segmentOrgName!=null && segmentOrgName.trim().length()>0))
		{
			vmComponents = vmDesktopBean.getVmComponentsList(Vmhost,thisSite,showOtherVm,segmentOrgName);
		}
		else if((thisSite == null || thisSite.trim().length() == 0 || thisSite.equalsIgnoreCase("NULL")) && serviceName != null && serviceName.trim().length() > 0)
		{
			vmComponents = vmDesktopBean.getVmComponentsList(Vmhost,thisSite,showOtherVm,serviceName);
		}
		else
		{
			vmComponents = vmDesktopBean.getVmComponentsList(Vmhost,thisSite,showOtherVm);
		}
	}

	if(vmComponents!=null && vmComponents.size()>0)
	{
		vmComponents = sortVMComponents(vmComponents);
	}

	JSONObject result = new JSONObject();
	JSONObject topoData = new JSONObject();
	JSONArray topoDataArray = new JSONArray();
	String component = "",comptype = "", compNick = "",compState = "",comCatogary = "", vmport = "", vmcomptype = "",vmcompNick = "";
	ArrayList tokens = null;
	eGComponentCategory egCompCategory = eGComponentCategory.getInstance();
	if(vmComponents!=null && vmComponents.size()>0)
	{
		// Adding Esx
		JSONObject configItems = new JSONObject();
		JSONArray configItemsArray = new JSONArray();
		String comp = (String)vmComponents.get(0);
		if(comp != null && comp.trim().length() > 0)
		{
			tokens = com.egurkha.util.StringUtils.egTokenizer(comp,"~^~",true,false,true);
			component = (String)tokens.get(0);
			vmcomptype=component.substring(0,component.indexOf(":"));
			vmcompNick=component.substring(component.indexOf(":")+1,component.length());
			vmport=component.substring(component.lastIndexOf(":")+1,component.length());
			String ConfigIp=vmcompNick;
			if (vmcompNick.endsWith(EgConstants.NULL_PORT) && (vmcompNick.indexOf(EgConstants.NULL_PORT) > -1))
			{
				ConfigIp  = Server.getServerNameWithoutPort(vmcompNick, false);
			}

			String vmstate = (String)tokens.get(1);
			comCatogary = egCompCategory.getCategoryforCompType(vmcomptype);
			topoData.put("ComponentSrc",comCatogary);
			topoData.put("componentState",vmstate);
			topoData.put("componentName",mappingInfo.getComponentTypeDescription(vmcomptype));
			
			configItems.put("Config_Ip",ConfigIp);
			configItemsArray.add(configItems);
			topoData.put("ConfigIp",configItemsArray);
			topoData.put("severs","");
			
			//String vmurl = "/final/servlet/com.eg.EgDashboardController?from=list&site="+thisSite+"&qctr=0&host="+(vmcompNick+":"+vmport)+"&comptype="+vmcomptype+"&comeFrom=topology"+"&Vmhost="+vmcompNick+"&vmcomp_type="+vmcomptype+"&state="+vmstate+"&port="+vmport+"&tab=LayerModel&toDashBoardLayer=true";
			
			String vmurl = "/final/servlet/com.eg.EgDashboardController?from=list&site="+thisSite+"&qctr=0&host="+EgURLEncoder.encode(vmcompNick,"UTF-8")+"&comptype="+vmcomptype+"&comeFrom=topology"+"&Vmhost="+EgURLEncoder.encode(vmcompNick,"UTF-8")+"&vmcomp_type="+vmcomptype+"&state="+vmstate+"&port="+vmport+"&tab=LayerModel&toDashBoardLayer=true&isfromCitrix="+isfromCitrix+"&isfromRum="+isfromRum+"&filter="+filter+"&filterBy="+filterBy+"&isFromServiceMenu="+isFromServiceMenu+"&isFromZoneMain="+isFromZoneMain+"&isFromZoneMenu="+isFromZoneMenu+"&isFromServiceGroup="+isFromServiceGroup+"&selectedRum="+selectedRum+"&serviceTopology="+serviceTopology+"&virtualTopology=true&dashboard_mapping="+dashboard_mapping+"&user_name="+user_name+"&fromServiceHomePage="+fromServiceHomePage+"&segmentName="+segmentName+"&view_name="+view_name+"&isFromZone="+isFromZone+"&iszoneName="+iszoneName+"&parentZone="+parentZone;

			if(isfromLayerModelVirtual)
				vmurl = vmurl +"&virtualIconBack=true";
			if(userViolated)
			{
				if(userBasedCompTypeList==null || userBasedCompTypeList.size()==0 || !userBasedCompTypeList.contains(vmcomptype))
				{
					topoData.put("popupurl",vmurl);
				}
				else
					topoData.put("popupurl","");
			}
			else
			{
				topoData.put("popupurl",vmurl);
			}
			
		}
		// Adding other VMs
		boolean hasEmptyValues = false;
		if(vmComponents.size() > 1)
		{
			JSONObject vmCompData = new JSONObject();
			JSONArray vmCompDataArray = new JSONArray();
			ArrayList appDetails = new ArrayList();

			Hashtable appVMData = new Hashtable();
			if(Vmhost!=null || (!Vmhost.equals("null")))
				appVMData = vmDesktopBean.getVMCompDetails(Vmhost);
			if(appVMData != null && appVMData.size() > 0 && appVMData.containsKey("hasEmptyValues"))
				hasEmptyValues = ((Boolean)appVMData.get("hasEmptyValues")).booleanValue();

			for(int kk=1; kk<vmComponents.size(); kk++)
			{
				comp = (String)vmComponents.get(kk);
				if(comp != null && comp.trim().length() > 0)
				{
					tokens = com.egurkha.util.StringUtils.egTokenizer(comp,"~^~",true,false,true);
					component = (String)tokens.get(0);
					comptype=component.substring(0,component.indexOf(":"));
					compNick=component.substring(component.indexOf(":")+1,component.length());
					comCatogary = egCompCategory.getCategoryforCompType(comptype);
					compState = (String)tokens.get(1);

					if(appVMData != null && appVMData.size() > 0 && !hasEmptyValues)
					{
						appDetails = (ArrayList)appVMData.get(component);
						if(appDetails != null && appDetails.size() > 0)
						{
							vmCompData = new JSONObject();
							configItems = new JSONObject();
							configItemsArray = new JSONArray();
							vmCompData.put("ComponentSrc",comCatogary);
							//vmCompData.put("componentState","state_component_combo_"+compState);
							vmCompData.put("componentState",compState);
							vmCompData.put("componentName",mappingInfo.getComponentTypeDescription(comptype)+"<br>"+(String)appDetails.get(0));
							String nickName = compNick;
							if (nickName.endsWith(EgConstants.NULL_PORT) && (nickName.indexOf(EgConstants.NULL_PORT) > -1))
							{
								nickName  = Server.getServerNameWithoutPort(nickName, false);
							}
							vmCompData.put("componentType",mappingInfo.getComponentTypeDescription(comptype)+"<br>"+nickName);

							String ip = (String)appDetails.get(1);
							if(ip != null && ip.trim().length() > 0)
							{
								if(ip.indexOf(",") > 0)
								{
									ArrayList ipTokens = com.egurkha.util.StringUtils.egTokenizer(ip,",",true,false,true);
									for(int l=0;l<ipTokens.size();l++)
									{
										configItems.put("Config_Ip",(String)ipTokens.get(l));
										configItemsArray.add(configItems);
									}
									vmCompData.put("MultipleDisplay","true");
								}
								else
								{
									configItems.put("Config_Ip",ip);
									configItemsArray.add(configItems);
									vmCompData.put("MultipleDisplay","false");
								}
							}
							vmCompData.put("ConfigIp",configItemsArray);
							vmCompData.put("severs",(String)appDetails.get(2));
						}
					}
					else
					{
						vmCompData = new JSONObject();
						configItems = new JSONObject();
						configItemsArray = new JSONArray();
						vmCompData.put("ComponentSrc",comCatogary);
						//vmCompData.put("componentState","state_component_combo_"+compState);
						vmCompData.put("componentState",compState);
						vmCompData.put("componentName",mappingInfo.getComponentTypeDescription(comptype));

						String nickName = compNick;
						if (nickName.endsWith(EgConstants.NULL_PORT) && (nickName.indexOf(EgConstants.NULL_PORT) > -1))
						{
							nickName  = Server.getServerNameWithoutPort(nickName, false);
						}
						configItems.put("Config_Ip",nickName);
						configItemsArray.add(configItems);
						vmCompData.put("ConfigIp",configItemsArray);
						vmCompData.put("severs","");
					}
					
					//String url = "/final/servlet/com.eg.EgDashboardController?from=list&site="+thisSite+"&qctr=0&host="+compNick+"&comptype="+comptype+"&comeFrom=topology&Vmhost="+vmcompNick+"&vmcomp_type="+vmcomptype+"&state="+compState+"&port="+vmport+"&tab=LayerModel&toDashBoardLayer=true";
					
					String url = "/final/servlet/com.eg.EgDashboardController?from=list&site="+thisSite+"&qctr=0&host="+EgURLEncoder.encode(compNick,"UTF-8")+"&comptype="+comptype+"&comeFrom=topology&Vmhost="+EgURLEncoder.encode(vmcompNick,"UTF-8")+"&vmcomp_type="+vmcomptype+"&state="+compState+"&port="+vmport+"&tab=LayerModel&toDashBoardLayer=true&isfromCitrix="+isfromCitrix+"&isfromRum="+isfromRum+"&filter="+filter+"&filterBy="+filterBy+"&isFromServiceMenu="+isFromServiceMenu+"&isFromZoneMain="+isFromZoneMain+"&isFromZoneMenu="+isFromZoneMenu+"&isFromServiceGroup="+isFromServiceGroup+"&selectedRum="+selectedRum+"&serviceTopology="+serviceTopology+"&virtualTopology=true&dashboard_mapping="+dashboard_mapping+"&user_name="+user_name+"&fromServiceHomePage="+fromServiceHomePage+"&segmentName="+segmentName+"&view_name="+view_name+"&isFromZone="+isFromZone+"&iszoneName="+iszoneName+"&parentZone="+parentZone;

					if(isfromLayerModelVirtual)
						url = url +"&virtualIconBack=true";
					if(userViolated)
					{
						if(userBasedCompTypeList==null || userBasedCompTypeList.size()==0 || !userBasedCompTypeList.contains(vmcomptype))
						{
							vmCompData.put("popupurl",url);
						}
						else
							vmCompData.put("popupurl","");
					}
					else
					{
						vmCompData.put("popupurl",url);
					}
					
					vmCompDataArray.add(vmCompData);
				}
			}
			topoData.put("Topology_data",vmCompDataArray);
		}
	}
	if(hideVMDetailsWin)
		topoData.put("displayMessage","No Container(s) Managed ");
	else
		topoData.put("displayMessage","No VM(s) Managed ");

	topoDataArray.add(topoData);
	result.put("Parent_data",topoDataArray);
	result.put("monitorSkin",topologySkin);
	
	if(result != null)
		json.put("vmTopologyData",result);

	json.put("hideVMDetailsWin",hideVMDetailsWin);
	//end

	json.put("graphData",graphData);
	json.put("screenLabels",screenLabels);
	json.put("hiddenFields",hiddenFields);
	json.put("selectedField",selectedField);
	if(request.getQueryString() != null)
	{
		String queryString = request.getQueryString()+"&fromPage=LayerModel&fromMenu=true";
		session.setAttribute("monitorLastSession","/final/monitor/EgVmwareCompGraphApp.jsp?"+queryString);
	}
	else
		session.setAttribute("monitorLastSession","/final/monitor/EgVmwareCompGraphApp.jsp?fromPage=LayerModel&fromMenu=true");
	response.getWriter().write(json.toString());
	
%>



<%!
	public List sortVMComponents(List compList)
	{
		List result = new ArrayList();
		if(compList == null || compList.size() == 0)
			return null;

		List highList = new ArrayList();
		List intermediateList = new ArrayList();
		List lowList = new ArrayList();
		List normalList = new ArrayList();
		List unknownList = new ArrayList();
		result.add((String)compList.get(0)); // Sort components except vmhost
		for(int kk=1;kk<compList.size();kk++)
		{
			String vmComp = (String)compList.get(kk); 
			if(vmComp != null && vmComp.trim().length() > 0)
			{
				if(vmComp.endsWith("HIGH"))
					highList.add(vmComp);
				else if(vmComp.endsWith("INTERMEDIATE"))
					intermediateList.add(vmComp);
				else if(vmComp.endsWith("LOW"))
					lowList.add(vmComp);
				else if(vmComp.endsWith("UNKNOWN"))
					unknownList.add(vmComp);
				else
					normalList.add(vmComp);
			}
		}

		if(highList != null && highList.size() >0)
		{
			EgSorter esort=new EgSorter(highList,1);
			highList=esort.sort(1,"String","asc");
			result.addAll(highList);
		}
		if(intermediateList != null && intermediateList.size() >0)
		{
			EgSorter esort=new EgSorter(intermediateList,1);
			intermediateList=esort.sort(1,"String","asc");
			result.addAll(intermediateList);
		}
		if(lowList != null && lowList.size() >0)
		{
			EgSorter esort=new EgSorter(lowList,1);
			lowList=esort.sort(1,"String","asc");
			result.addAll(lowList);
		}
		if(unknownList != null && unknownList.size() >0)
		{
			EgSorter esort=new EgSorter(unknownList,1);
			unknownList=esort.sort(1,"String","asc");
			result.addAll(unknownList);
		}
		if(normalList != null && normalList.size() >0)
		{
			EgSorter esort=new EgSorter(normalList,1);
			normalList=esort.sort(1,"String","asc");
			result.addAll(normalList);
		}
		return result;
	}


%>
