<%@ include file = "EgMonitorTracker.jsp" %>
<%@ page errorPage = "EgProbsM.jsp" %>
<%@ page import = "com.eg.EgDbAdapterTypeUI"%>
<%@ page import = "com.eg.EgDiscInfo"%>
<%@ page import = "com.eg.EgGroupInfo"%>
<%@ page import = "com.eg.EgTablesInfo"%>
<%@ page import = "com.eg.EgSpecsInfo"%>
<%@ page import = "com.eg.EgURLEncoder"%>
<%@ page import = "com.egurkha.*"%>
<%@ page import = "com.egurkha.monitor.*"%>
<%@ page import = "com.egurkha.monitor.alarms.*"%>
<%@ page import = "egurkha.*"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "com.eg.EgTopoInfo"%>
<%@ page import="com.egurkha.monitor.EgServerDashboardModel" %>
<%@ page import = "com.eg.EgDbInfo"%>
<%@ page import = "com.eg.EgAgentInfo"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="net.sf.json.*"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import="egurkha.reporter.ErUtils"%>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.ini.IniUI" %>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.IniFile" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import="com.egurkha.util.*"%>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import="egurkha.reporter.ErUserData"%>
<%@ page import = "com.eg.EgMetaThread"%>


<%! 
	EgDiscInfo discInfo = new EgDiscInfo("manager");
	IniUI ui = (IniUI)com.egurkha.ini.IniUI.getInstance();
	
%>

<%
/* This is for SuperManager - starts */
if(com.eg.EgInstallInfo.isSuperManager)
{
	String currentSession = session.getId();
	String hostname = request.getParameter("host");
	//System.out.println("egDashboardDispCompLayers.jsp hostname " + hostname);
	if(hostname != null)
	{
		if(hostname.indexOf(":")>-1)
		{
			hostname = hostname.substring(0,hostname.indexOf(":"));
		}
		//System.out.println("egDashboardDispCompLayers.jsp host " + hostname);
		ArrayList managerIds = EgElementInfo.getInstance().getManagerIDs("component",hostname);
		//System.out.println("egDashboardDispCompLayers.jsp managerIds " + managerIds);
		if(managerIds != null && !managerIds.isEmpty())
		{
			session.setAttribute("mgr_id_sm",managerIds.get(0));
			SmSessionData smsData = new SmSessionData(currentSession,managerIds);
			EgThreadLocal egtl = new EgThreadLocal();
			egtl.set(smsData);
		}
	}
}
/* This is for SuperManager - ends */
try{	
	String layerModelLink=ui.getValue("MISC_ARGS","LAYERMODEL_LINK_TO_VIRTUAL");
	response.setHeader("Cache-Control", "no-store");
	response.setHeader("Pragma", "no-cache");
	response.setDateHeader("Expires", -1);
	response.setContentType("application/json");
	JSONObject json_mobile = new JSONObject();
	EgDbAdapterUI egDb; 
	String vmhost=request.getParameter("vmhost");
	String vmcomp_type=request.getParameter("vmcomp_type");
	EgServerDashboardModel  egDashboard=new  EgServerDashboardModel();
	String host=request.getParameter("host");
	String hostType=request.getParameter("comptype"); 
	String site    = request.getParameter("site");
	site = com.eg.EgURLDecoder.decode(site,"UTF-8");
	String componentstate=egDashboard.getServerState(host,hostType,site);
	String dispDate = request.getParameter("dispDate");
	String msmt_host = request.getParameter("msmt_host");
	String egQuickLaunchStr=request.getParameter("egQuickLaunch");

	String search_Type = request.getParameter("searchtype");
	String component_Name = request.getParameter("componentName");
	String user_name = request.getParameter("username");
	String search_val = request.getParameter("searchval");
	String comp_Name = request.getParameter("compName");
	String search_info = request.getParameter("info");
	String fromPage=request.getParameter("fromPage");

	boolean isFromQuickLaunch=true;
	if(egQuickLaunchStr==null || egQuickLaunchStr.trim().length()==0)
	{
		isFromQuickLaunch = false;
	}

	boolean isLicenseViolatedType = false;
	boolean userViolated = false;
	ArrayList userBasedCompTypeList = new ArrayList(); 
	String userId = u_ser.getLoginID();
	if(userId !=null && userId.trim().length()>0 && !EgInstallInfo.isSuperManager)
	{
		com.eg.GroupCertValidator licenseChecker = new com.eg.GroupCertValidator(userId);
		userViolated = licenseChecker.checkForUserViolation(userId);
		if(userViolated)
		{
			com.eg.EgUsersInfo usersInfo = new com.eg.EgUsersInfo();
			userBasedCompTypeList = (ArrayList)usersInfo.getAllUserBasedCompTypes();
		}

		if(hostType != null && hostType.trim().length() > 0 && userBasedCompTypeList != null && userBasedCompTypeList.size() >0 && userBasedCompTypeList.contains(hostType))
			isLicenseViolatedType = true;

		if(!isLicenseViolatedType && hostType !=null && hostType.equalsIgnoreCase("Host_system"))
		{
			com.eg.EgDiscInfo discInfo=new com.eg.EgDiscInfo("manager");
			String temphostName = (host != null && host.indexOf(":") >0)?host:host+":NULL";
			String tempServerType = discInfo.getServerTypesForComponentNamePort(temphostName);
			if(userBasedCompTypeList != null && userBasedCompTypeList.size() > 0 && userBasedCompTypeList.contains(tempServerType))
				isLicenseViolatedType = true;
		}
	}

	boolean isMoreInfosTreeView=false;
	String MoreInfosTreeView = request.getParameter("MoreInfosTreeView");
	if(MoreInfosTreeView!=null && MoreInfosTreeView.trim().length()>0 && (MoreInfosTreeView.equalsIgnoreCase("true") || MoreInfosTreeView.equalsIgnoreCase("yes")))
	{
		isMoreInfosTreeView=true;
	}
	String virtualLiveGraphURL = "/final/monitor/livegraph/EgVmwareLiveGraphHome.jsp?comptype="+EgURLEncoder.encode(hostType,"UTF-8")+"&er_component="+EgURLEncoder.encode(host,"UTF-8");
%>

<jsp:useBean id = "sitebean" scope = "page" class = "egurkha.ConfigSiteBean"/>
<% 

					JSONObject json = new JSONObject();
					if(isLicenseViolatedType){
						json.put("errormsg","You have exceeded the number of User License. Please contact the administrator");
						request.setAttribute("strJson",json.toString());
						return;
					}
					
					EgGroupInfo groupinfo = new EgGroupInfo();
					//out.println("The Query String is " + request.getQueryString());
					AlarmPriorities ap = AlarmPriorities.getInstance();
						EgTablesInfo tablesInfo = new EgTablesInfo("manager");
					Vector comp = new Vector();
					Vector v = new Vector();
					Vector serversNoSites = new Vector();

					String hostImg = null;
					String image = null;
					String compTopoLayer = null;
					String conn = null;
					String tmpLayer = request.getParameter("layer");
					String test  = request.getParameter("test");
					if(test!=null)
					{
						test=com.eg.EgURLEncoder.encode(test, "UTF-8");
					}
					String flagAlarm = request.getParameter("fromalarm");
					String flagState  = AlarmPriorities.GOOD_STATE;
					String serverType  = "";
					String layerQueryStr=(String)request.getQueryString();
					
					
					HashMap layerQueryHash = new HashMap();
					if(layerQueryStr!=null)
					{
						StringTokenizer layerQueryTokens1 = new StringTokenizer(layerQueryStr,"&");
						while (layerQueryTokens1.hasMoreTokens()) 
						{
							String layerQueryValueTemp = (String)layerQueryTokens1.nextToken();
							StringTokenizer layerQueryTokens2 = new StringTokenizer(layerQueryValueTemp,"=");
							int layerQueryTokens2Count = layerQueryTokens2.countTokens();
							String key = "";
							String value = "";
							if(layerQueryTokens2Count==2)
							{
								 key = (String)layerQueryTokens2.nextToken();
								 value = (String)layerQueryTokens2.nextToken();
								 layerQueryHash.put(key,value);
							}
							else
							{
								 key = (String)layerQueryTokens2.nextToken();
								 layerQueryHash.put(key,"");
							}
						}
					}					
					
					String qctrValue = "";
					if(layerQueryHash.size()>0)
					qctrValue= (String)layerQueryHash.get("qctr");
														
					if (tmpLayer!=null && !qctrValue.equals("0") )
					{
						session.setAttribute("layer", layerQueryStr);
					}
					
					EgTopoInfo topoinfo    = new EgTopoInfo("manager");
					boolean isThisCompAssociatedToSite = false;
					if (site != null && !site.equals(""))
					{
						Vector compVec = topoinfo.getAssociatesForSite(site);
						if (compVec != null && compVec.size() > 0)
						{
							for (int x = 0; x < compVec.size(); x++)
							{
								String thisComp = (String)compVec.get(x);
								if (!thisComp.startsWith("Group"))
								{
									if (thisComp.equals(hostType + ":" + host))
									{
										isThisCompAssociatedToSite = true;
									}
								}
								else
								{
									String thisGrp    = thisComp.substring(thisComp.indexOf(":") + 1,
															               thisComp.lastIndexOf(":"));

									ArrayList grpCmps = groupinfo.getAllComponentsUnderGroup(thisGrp);


									if (grpCmps.contains(hostType + ":" + host))
									{
										isThisCompAssociatedToSite = true;
									}
								}
							}
						}
					}

					ResultSet rsReport = null;
					boolean transactions = false;
					String org_comp_type=hostType;
					String org_host_name=host;

					//Get the running tests for this component from MetaThread
					Hashtable metaTest=(Hashtable)EgMetaThread.metaTest;
					if(metaTest == null)
						metaTest=new Hashtable();
					ArrayList layersForHostSystem = tablesInfo.getLayersForComponent("Host_system");
					Hashtable testDetails =(Hashtable) metaTest.get(org_comp_type+":"+org_host_name);
					Hashtable hostSystestDetails = null;
					Hashtable allTests = new Hashtable();
					if(layersForHostSystem!=null)
					{
						StringTokenizer st = new StringTokenizer(org_host_name,":");
						String tmpHost = null;
						if(st.countTokens()>0)
						{
							tmpHost = st.nextToken()+":NULL";
						}
						if(tmpHost!=null)
							hostSystestDetails =(Hashtable) metaTest.get("Host_system"+":"+tmpHost);
					}

					//Get the layers and its state for this component from state_hist table
					egDb = EgDbAdapterTypeUI.getObject();
					conn = egDb.setConnection();
					Hashtable layersState = new Hashtable();
					boolean isAllLayerGood=true;
					boolean isVirtualInsideViewLayer=false;
					try
					{
						
						if (conn != null && conn.equalsIgnoreCase("CONNECTED"))
						{
							
					        rsReport
					            = egDb.SelectDispLayers_2(site, flagAlarm, hostType, host);
					        while (rsReport != null && rsReport.next())
					        {
					            String strLayer = rsReport.getString("layer_name");
					            String strState = rsReport.getString("priority");
					            layersState.put(strLayer, strState);
								if(strState!=null && (strState.equalsIgnoreCase("HIGH") || strState.equalsIgnoreCase("INTERMEDIATE") || strState.equalsIgnoreCase("LOW") || strState.equalsIgnoreCase("UNKNOWN")))
								{
									isAllLayerGood=false;
								}
					        }

					        if (rsReport != null)
					            rsReport.close();

					        rsReport = null;
					        egDb.releaseConnection(false);
					    }

					    EgDbAdapterTypeUI.releaseObject(egDb);
					}
					catch (Exception e)
					{
					    e.printStackTrace();
					    String errMsg = "";

					    if (!conn.equals("CONNECTED"))
					    {
					        errMsg = "<egui:intnl text='Connection could not be established with the database'/>";
					    }
					    else
					    {
					        errMsg = e.toString();
					    }

					    if (rsReport != null)
					    {
					        try
					        {
					            rsReport.close();
					        }
					        catch (Exception bug123)
					        {
					        }
					    }

					    try
					    {
					        egDb.releaseConnection(true);
					    }
					    catch (Exception ex)
					    {
					    }

					    EgDbAdapterTypeUI.releaseObject(egDb);
					    errMsg = "EgErrorLayersSmall.jsp?msg=" + errMsg;

					    //Forwarding to the errorhandler
					%>

					    <!-- <jsp:forward page = "<%= errMsg %>"/> -->

					<% return;
					}
					// Prem
					String titleComponentName,portCheck;
					portCheck = host.substring(host.indexOf(":")+1,host.length());
					if(portCheck.equalsIgnoreCase("NULL"))
						titleComponentName = host.substring(0,host.indexOf(":"));
					else
						titleComponentName = host;

					boolean colorChanger = false;
					EgAgentInfo agentInfo = new EgAgentInfo("manager");
					EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
					String disable = EgInstallInfo.getInstallDir()+"/manager/config/eg_disable.ini";
					IniFile disableIniObj = new IniFile(disable);
					boolean tableEnd = false;
					boolean tableStart = false;
					//added
					String tname = "";
					String sType = "";

					String variables [];
					StringTokenizer st;

					if (hostType.equalsIgnoreCase(Server.HOST_SYSTEM))
					{
						String temp_test=test;
						if (temp_test != null && temp_test.indexOf("-") > -1)
						{
							temp_test = temp_test.substring(0, temp_test.indexOf("-"));
						}

						String cname = host;
						cname = cname.substring(0, cname.indexOf(":"));

						serverType = discInfo.getTypeForHostTest(cname, temp_test);
						comp = tablesInfo.getLayersRelevantForHost_system(serverType, comp);
					}
					//End of new code

					//Get the layers associated for this component and remove the Good State layer with no running tests
					ArrayList layerList=(ArrayList)tablesInfo.getSortedLayersForComponent(hostType,"desc");
					if(layerList==null)
						layerList=new ArrayList();
					String [] serversNoSitesArray = discInfo.getAllServersOfType("Site_servers");

					for (int a = 0; a < serversNoSitesArray.length; a++)
					{
					     serversNoSites.add(serversNoSitesArray[a]);
					}
					com.eg.EgAggregateInfo ainfo = new com.eg.EgAggregateInfo("manager");
					if(ainfo.isAggregateSite(site))
					{
						transactions=true;
					}
					ArrayList excludeList = new ArrayList();
					for(int k=0;k<layerList.size();k++)
					{
						String tmp =(String)layerList.get(k);
						String layerState = AlarmPriorities.GOOD_STATE;
					     if (tmp == null)
					        continue;
						if( layersState!=null&layersState.containsKey(tmp))
						{
							 layerState = (String)layersState.get(tmp);
						}
					    if (serversNoSites.contains(hostType) && site.equals("NULL")
										&& (tmp.equals("WEB_TRANSACTIONS") || tmp.equals("WEB_SITE")))
					    {
					        continue;
					    }
					    else if (sitebean.isAService(site) && ((tmp.equals("WEB_TRANSACTIONS"))
															                   || (tmp.equals("WEB_SITE"))))
					    {
					        continue;
					    }
					    else if (!isThisCompAssociatedToSite && ((tmp.equals("WEB_TRANSACTIONS"))
															                 || (tmp.equals("WEB_SITE"))))
					    {
					        continue;
					    }
						else if(layerState!=null&&layerState.equals(AlarmPriorities.GOOD_STATE))
						{
					
							ArrayList listOfTest=(ArrayList)tablesInfo.getTestsForLayer(tmp,hostType);
							if(tmp!=null && layersForHostSystem!=null && layersForHostSystem.contains(tmp))
							{
								allTests = hostSystestDetails;
							}
							else
							{
								allTests = testDetails;
							}
							if(allTests == null)
								allTests = new Hashtable();
							
							ArrayList runningTests = new ArrayList();
							Enumeration enuTestDetails;
							if(allTests.size() >0)
							{
								enuTestDetails = allTests.keys();
								
								while(enuTestDetails.hasMoreElements())
								{
									String strTest= (String) enuTestDetails.nextElement();
									if(strTest !=null && strTest.trim().length() >0)
										runningTests.add(strTest);
								}
								if(runningTests !=null && runningTests.size() >0 && listOfTest!=null && listOfTest.size()>0)
								{
									int testsCount = listOfTest.size();
									int excludedCount = 0;
									for(int i=0;i<testsCount;i++)
									{
										String testTemp = (String)listOfTest.get(i);
										if(runningTests.contains(testTemp))
										{
											comp.add(tmp);
											break;
										}
										else
										{
											excludedCount++;
										}
									
									}
									if(excludedCount==testsCount)
										excludeList.add(tmp);
								}
							}
							else
							{
								excludeList.add(tmp);
							}
						}
						else
						{
							comp.add(tmp);
						}

						if(tmp!=null && (tmp.equals("VIRTUAL_DESKTOP") || tmp.equals("VIRTUAL_SERVERS") || tmp.equals("ZONES")))
						{
							isVirtualInsideViewLayer = true;
						}
					}


					if(comp.size() == 0)
					{
						comp.addAll(excludeList);
					}
						 //Removal of unwanted same level layers
					if (tmpLayer != null)
					{
						if (comp.contains("TCP") && comp.contains("UDP"))
						{
							if (!tmpLayer.equals("UDP"))
							{
								comp.removeElement("UDP");
							}
							else
							{
								comp.removeElement("TCP");
							}
						}
					}

					//ended
					if(comp!=null&&comp.size()>0)
					{
						String cname = host;
						if(cname!=null && cname.trim().length()>0 && cname.indexOf(":")>-1)
							cname = cname.substring(0, cname.indexOf(":"));

						int layerSize = comp.size();
						int actLayerSize = layerSize-1;
						int layerwithTests = 0;

						JSONArray nodeinfo_array = new JSONArray(); 
						JSONArray nodeinfo_array_mobile = new JSONArray(); 

						JSONObject moreInfosSingleLayer = new JSONObject();
						for (int cntr = 0; cntr < layerSize; cntr++)
						{
							JSONObject nodeinfo = new JSONObject();
							JSONObject nodeinfo_mobile = new JSONObject();
							flagState = AlarmPriorities.GOOD_STATE;
							compTopoLayer = (String)comp.elementAt(cntr);

							if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && !tmpLayer.equals(compTopoLayer))
								continue;
							
							// To remove a layer when no tests are mapped to that layer for the selected component type
							// by Saravanan.A on 13-10-2011,20-10-2011
							ArrayList listOfTest=(ArrayList)tablesInfo.getTestsForLayer(compTopoLayer,hostType);
							String serverTempType = null;

							if (hostType!=null && hostType.equalsIgnoreCase(Server.HOST_SYSTEM) && listOfTest!=null && listOfTest.size()>0)
							{
								ArrayList listOfTempTest=new ArrayList();
								for (int k = 0; k < listOfTest.size(); k++)
								{
									String t_test=(String)listOfTest.get(k);
									serverTempType = discInfo.getTypeForHostTest(cname, t_test);
									if(serverTempType!=null && serverTempType.trim().length()>0)
									{
										listOfTempTest=(ArrayList)tablesInfo.getTestsForLayer(compTopoLayer,serverTempType);
										break;
									}
								}

								if(listOfTempTest!=null)
								{
									listOfTest = new ArrayList();
									listOfTest=listOfTempTest;
								}
							}
							if(listOfTest==null || listOfTest.size()==0)
								continue;

							if(listOfTest!=null && listOfTest.size()>0)
							{
								boolean isAppLayer = tablesInfo.isPortRelevantForLayer(hostType,compTopoLayer);
								String disable_value=null;
								
								if(isAppLayer)
								{
									disable_value=disableIniObj.getValue(hostType,hostType+":"+host);
								}
								else
								{
									disable_value=disableIniObj.getValue("Default_server","Default_server:"+cname);
								}

								if(disable_value!=null)
									disable_value=disable_value.trim();

								if(disable_value!=null && disable_value.trim().length()>0)
								{
									StringTokenizer st1 =new StringTokenizer(disable_value,",");
									while(st1.hasMoreTokens())
									{
										String value=st1.nextToken();
										if(value!=null && value.trim().length()>0 && listOfTest.contains(value))
										{
											listOfTest.remove(value);
										}

										if(listOfTest==null || listOfTest.size()==0)
											break;
									}
								}
							}

							if(listOfTest==null || listOfTest.size()==0)
								continue;

							// To remove a layer when the tests are irrelavant for the agentless component.
							// by Saravanan.A on 9-11-2011

							boolean isAgentlessServer=false;
							if (hostType!=null && hostType.equalsIgnoreCase(Server.HOST_SYSTEM))
							{
								isAgentlessServer=agentInfo.isAgentlessServer(cname,serverTempType);
							}
							else
							{
								isAgentlessServer=agentInfo.isAgentlessServer(cname,hostType);
							}

							if(isAgentlessServer)
							{
								ArrayList listOfTempTest=new ArrayList();
								for (int k = 0; k < listOfTest.size(); k++)
								{
									String t_test=(String)listOfTest.get(k);
									boolean isExternalTest = specsInfo.isExternalTest(t_test);
									if(isExternalTest)
										continue;
									boolean isAgentlessTest=false;
									if (hostType!=null && hostType.equalsIgnoreCase(Server.HOST_SYSTEM))
									{
										isAgentlessTest=specsInfo.isAgentlessTest(t_test,serverTempType);
									}
									else
									{
										isAgentlessTest=specsInfo.isAgentlessTest(t_test,hostType);
									}
									if(!isAgentlessTest)
									{
										if(t_test!=null && t_test.trim().length()>0 && listOfTest.size()>0 && listOfTest.contains(t_test))
										{
											listOfTempTest.add(t_test);
										}
									}
								}

								if(listOfTempTest!=null && listOfTempTest.size()>0)
								{
									for (int k = 0; k < listOfTempTest.size(); k++)
									{
										String t_test=(String)listOfTempTest.get(k);
										if(t_test!=null && t_test.trim().length()>0 && listOfTest.size()>0 && listOfTest.contains(t_test))
										{
											listOfTest.remove(t_test);
										}
	
										if(listOfTest==null || listOfTest.size()==0)
											break;
									}
								}
							}

							if(listOfTest==null || listOfTest.size()==0)
								continue;
							layerwithTests++;

							if (!tableStart)
							{
								tableStart=true;
							}
							//---end---
							
							if( layersState!=null&layersState.containsKey(compTopoLayer))
							{
								flagState = (String)layersState.get(compTopoLayer);
							}
							colorChanger = !colorChanger;
							boolean selLayer = tmpLayer!=null&&tmpLayer.equals(compTopoLayer);
							boolean selDefalutLayer = (tmpLayer==null || tmpLayer.equalsIgnoreCase("null") || tmpLayer.trim().length()==0)?true:false;

							if (test != null && test.indexOf("-") == -1)
							{
								test = test+ "-+";
							}

							String Url ="site="+site+"&host="+host+"&qctr=1&layer="+compTopoLayer +"&comptype="+hostType+"&fromalarm="+flagAlarm+"&layerpriority="+flagState+"&test="+test+"&faketype="+serverType+"&dispDate="+dispDate;

							if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
							{
								Url = Url+"&MoreInfosTreeView=true&showAll=yes";
							}

							String UrlForVM="dispLayers.jsp?vmhost="+vmhost+"&vmcomp_type="+vmcomp_type+"&site="+site+"&host="+host+"&qctr=1&layer="+compTopoLayer+"&comptype="+hostType+"&fromalarm="+flagAlarm+"&layerpriority="+flagState+"&test="+test+"&faketype="+serverType+"&dispDate="+dispDate;
							boolean UrlForVmRequired = false;
							String testURLforLoading = "";

							if (layerModelLink!=null && (layerModelLink.equalsIgnoreCase("yes") || layerModelLink.equalsIgnoreCase("true")) && (compTopoLayer.equalsIgnoreCase("VIRTUAL_DESKTOP") || compTopoLayer.equalsIgnoreCase("VIRTUAL_SERVERS") ||  compTopoLayer.equalsIgnoreCase("ZONES")))
							{
								if(hostType.startsWith("Agg_") || serverType.startsWith("Agg_"))
								{
									String layerModelPageLink=response.encodeURL("/final/servlet/com.eg.EgDashboardController?")+"from=list&site=NULL&qctr=1&host="+EgURLEncoder.encode(host,"UTF-8")+"&comptype="+hostType+"&layer="+compTopoLayer+"&test=null&faketype=&tab=LayerModel&toDashBoardLayer=true";
									testURLforLoading = Url;
									nodeinfo.put("onclickurl",Url);
									nodeinfo.put("onclicklink",layerModelPageLink);
									nodeinfo.put("iconCls","state_"+flagState);
									nodeinfo_mobile.put("status",flagState);

									if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
									{
										moreInfosSingleLayer.put("onclickurl",Url);
										moreInfosSingleLayer.put("onclicklink",layerModelPageLink);
										moreInfosSingleLayer.put("iconCls","state_"+flagState);
									}
								}
								else
								{
									UrlForVM="";
									UrlForVM=response.encodeURL("/final/monitor/EgVmwareDesktop.jsp?")+"comp="+EgURLEncoder.encode(host,"UTF-8")+"&comptype="+hostType+"&Layer="+compTopoLayer;
									if(fromPage!=null && fromPage.equalsIgnoreCase("globalsearch"))
									{
										UrlForVM = UrlForVM+"&searchtype="+search_Type+"&componentName="+component_Name+"&username="+user_name+"&searchval="+search_val+"&compName="+comp_Name+"&info="+EgURLEncoder.encode(search_info,"UTF-8")+"&msmt_host="+msmt_host;
									}
									testURLforLoading = Url;
									UrlForVmRequired = true;
									nodeinfo.put("onclickurl",Url);
									nodeinfo.put("link",UrlForVM);
									nodeinfo.put("iconCls","state_"+flagState);
									nodeinfo_mobile.put("status",flagState);

									if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
									{
										moreInfosSingleLayer.put("onclickurl",Url);
										moreInfosSingleLayer.put("link",UrlForVM);
										moreInfosSingleLayer.put("iconCls","state_"+flagState);
									}
								}
							}
							else
							{
								if(selLayer && msmt_host != null && !msmt_host.equals("null") && !msmt_host.isEmpty()){
									Url += "&msmt_host="+msmt_host;
								}
								testURLforLoading = Url;
								nodeinfo.put("onclickurl",Url);
							
								nodeinfo.put("iconCls","state_"+flagState);
								nodeinfo_mobile.put("status",flagState);

								if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
								{
									moreInfosSingleLayer.put("onclickurl",Url);
									moreInfosSingleLayer.put("iconCls","state_"+flagState);
								}
							}
							
							String virtualLiveGraph = new String("");
							if(compTopoLayer.equals("VIRTUAL_GUESTS") || compTopoLayer.equals("XEN_GUESTS") || compTopoLayer.equals("HYPERV_GUESTS") || compTopoLayer.equals("LPAR_GUESTS") )
							{
								//virtualLiveGraph = "<div style=\"position:relative;float:right\"><div id=\"virtualLive\" style=\"position:absolute;top:10px;left:-225px;top:2px\"class=\"iconLiveGraph\" href=\"javascript:void(0);\" data-qtip=\""+mappingInfo.getTextDescription("monitor.livegraph.Virtual Metrics")+"\" onclick=goToLiveGraph(\""+virtualLiveGraphURL+"\") data-qclass=\"yellowTip\"></div></div>";
								virtualLiveGraph = "<div class=\"virtualLiveImg\" id=\"virtualLiveImg\"></div>";
							}

							if(selLayer)
							{
								nodeinfo.put("text",(UrlForVmRequired?"<a href=\"javascript:void(0);\" onclick=gotoTopology(\""+UrlForVM+"\");>":"")+mappingInfo.getLayerDescription(compTopoLayer)+(UrlForVmRequired?"</a>":"") + virtualLiveGraph + "<div style=\"float:right;height:16px;\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger2\" ><div style=\"right:0px;position:absolute;height:20px;width:180px;\" class=\"test-search-hidden layer_search\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger\"   ></div><div style=\"right:0px;position:absolute;height:20px;width:60px;\" class=\"test-search-hidden  layer_toggle\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_checkbox\" ></div><div  class=\"layer_collapse \" style=\"position:absolute;right:20px;height:16px;width:16px;background:transparent url('/final/images/clear.png') left top repeat;\"></div></div>");
								
								nodeinfo.put("leaf", "false");
								nodeinfo.put("hiddenvalue",testURLforLoading);
								nodeinfo.put("rootCauseUrl","true");
								nodeinfo_mobile.put("layer",mappingInfo.getLayerDescription(compTopoLayer));
								
								if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
								{
									//moreInfosSingleLayer.put("text",(UrlForVmRequired?"<a href=\"javascript:void(0);\" onclick=gotoTopology(\""+UrlForVM+"\");>":"")+mappingInfo.getLayerDescription(compTopoLayer)+(UrlForVmRequired?"</a>":"") + virtualLiveGraph + "<div style=\"float:right;height:16px;\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger2\" ><div style=\"right:0px;position:absolute;height:20px;width:180px;\" class=\"test-search-hidden layer_search\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger\"   ></div><div style=\"right:0px;position:absolute;height:20px;width:60px;\" class=\"test-search-hidden  layer_toggle\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_checkbox\" ></div><div  class=\"layer_collapse \" style=\"position:absolute;right:20px;height:16px;width:16px;background:transparent url('/final/images/clear.png') left top repeat;\"></div></div>");

									moreInfosSingleLayer.put("text",mappingInfo.getLayerDescription(compTopoLayer));
									if(virtualLiveGraph!=null && virtualLiveGraph.trim().length()>0)
									{
										moreInfosSingleLayer.put("VirtualIcon",new Boolean(true));
										moreInfosSingleLayer.put("virtualURL",virtualLiveGraphURL);
									}
									else
										moreInfosSingleLayer.put("VirtualIcon",new Boolean(false));
								
									moreInfosSingleLayer.put("leaf", "false");
									moreInfosSingleLayer.put("hiddenvalue",testURLforLoading);
									moreInfosSingleLayer.put("rootCauseUrl","true");
								}
							}
							else
							{
								nodeinfo.put("text",(UrlForVmRequired?"<a href=\"javascript:void(0);\" onclick=gotoTopology(\""+UrlForVM+"\");>":"")+mappingInfo.getLayerDescription(compTopoLayer)+(UrlForVmRequired?"</a>":"") + virtualLiveGraph + "<div style=\"float:right;height:16px;\"><div style=\"right:0px;position:absolute;height:20px;width:180px;\" class=\"test-search-hidden layer_search\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger\" ></div><div style=\"right:0px;position:absolute;height:20px;width:60px;\" class=\"test-search-hidden\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_checkbox\" ></div><div style=\"position:absolute;right:20px;height:16px;width:16px;background:transparent url('/final/images/clear.png') left top repeat;\"  class=\"layer_collapse \" ></div></div>");
								nodeinfo.put("leaf", "false");
								if(isAllLayerGood && selDefalutLayer && (!isFromQuickLaunch) && layerwithTests==1 && (!selLayer))
								{
									if(isVirtualInsideViewLayer)
									{
										nodeinfo.put("rootCauseUrl","false");
									}
									else
									{
										nodeinfo.put("rootCauseUrl","true");
									}
								}
								else
								{
									nodeinfo.put("rootCauseUrl","false");
								}
								nodeinfo_mobile.put("layer",mappingInfo.getLayerDescription(compTopoLayer));
								if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
								{
									//moreInfosSingleLayer.put("text",(UrlForVmRequired?"<a href=\"javascript:void(0);\" onclick=gotoTopology(\""+UrlForVM+"\");>":"")+mappingInfo.getLayerDescription(compTopoLayer)+(UrlForVmRequired?"</a>":"") + virtualLiveGraph + "<div style=\"float:right;height:16px;\"><div style=\"right:0px;position:absolute;height:20px;width:180px;\" class=\"test-search-hidden layer_search\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_trigger\" ></div><div style=\"right:0px;position:absolute;height:20px;width:60px;\" class=\"test-search-hidden\" id=\"searchTests_"+(mappingInfo.getLayerDescription(compTopoLayer)).replace(" ","_")+"_checkbox\" ></div><div style=\"position:absolute;right:20px;height:16px;width:16px;background:transparent url('/final/images/clear.png') left top repeat;\"  class=\"layer_collapse \" ></div></div>");

									moreInfosSingleLayer.put("text",mappingInfo.getLayerDescription(compTopoLayer));
									if(virtualLiveGraph!=null && virtualLiveGraph.trim().length()>0)
									{
										moreInfosSingleLayer.put("VirtualIcon",new Boolean(true));
										moreInfosSingleLayer.put("virtualURL",virtualLiveGraphURL);
									}
									else
										moreInfosSingleLayer.put("VirtualIcon",new Boolean(false));

									moreInfosSingleLayer.put("leaf", "false");

									if(isAllLayerGood && selDefalutLayer && (!isFromQuickLaunch) && layerwithTests==1 && (!selLayer))
									{
										if(isVirtualInsideViewLayer)
										{
											moreInfosSingleLayer.put("rootCauseUrl","false");
										}
										else
										{
											moreInfosSingleLayer.put("rootCauseUrl","true");
										}
									}
									else
									{
										moreInfosSingleLayer.put("rootCauseUrl","false");
									}
								}
							}
							nodeinfo.put("hiddenvalue",testURLforLoading);
							nodeinfo.put("iconCls","state_"+flagState);
							nodeinfo.put("state",flagState);
							nodeinfo_mobile.put("status",flagState);
							if(cntr == 0)
								nodeinfo.put("cls","firstNode commonNode layers-tree-"+flagState);
							else
								nodeinfo.put("cls","commonNode layers-tree-"+flagState);

							if(isMoreInfosTreeView && tmpLayer!=null && compTopoLayer!=null && tmpLayer.equals(compTopoLayer))
							{
								moreInfosSingleLayer.put("hiddenvalue",testURLforLoading);
								moreInfosSingleLayer.put("iconCls","state_"+flagState);
								moreInfosSingleLayer.put("state",flagState);
								if(cntr == 0)
									moreInfosSingleLayer.put("cls","firstNode commonNode layers-tree-"+flagState);
								else
									moreInfosSingleLayer.put("cls","commonNode layers-tree-"+flagState);
							}
					
							if (cntr>=actLayerSize)
							{
								tableEnd=true;
							}
							nodeinfo_array.add(nodeinfo);
							
							nodeinfo_array_mobile.add(nodeinfo_mobile);
						}
						JSONObject nodeInfoParent = new JSONObject();
						if(!nodeinfo_array.isEmpty())
						{
							nodeInfoParent.put("leaf",false);
							nodeInfoParent.put("children",nodeinfo_array);
						}
						else 
						{
							json.put("errormsg",mappingInfo.getTextDescription("monitor.layermodel.No layers are mapped/enabled for this component!"));
						}
						json.put("Nodeinfo",nodeInfoParent);

						if(isMoreInfosTreeView)
						{
							json.put("MoreInfosNodeInfo",moreInfosSingleLayer);
						}

						json_mobile.put("output",nodeinfo_array_mobile);
					}
					else
					{
						json.put("errormsg",mappingInfo.getTextDescription("monitor.layermodel.No layers are mapped/enabled for this component!"));
					}
					//cleanup
					comp.removeAllElements();
					v.removeAllElements();
					serversNoSites.removeAllElements();


					if(isMobileCall)
		response.getWriter().write(json_mobile.toString());
					
	else
		request.setAttribute("strJson",json.toString());
		//response.getWriter().write(json.toString());

}
				

catch(Throwable e){

	response.getWriter().write(e.toString());
}
    
%>

    <%!
          public String checkForNULL(String str)
          {
              if (str != null && str.equals("NULL"))
              {
                  return "NONE";
              }
              else
              {
                  return str;
              }
          }
    
%>