<%
	/*
	 *		Name		:	EgDispServerJson.jsp
	 *		Purpose		:	To view components under a type.
	 *		Navigation	:	Infrastructure > Add / Modify Components
	 */
%>

<%@ include file="../../EgTrackerAJSON.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ page import="com.eg.EgName"%>
<%@ page import="com.eg.EgDiscInfo"%>
<%@ page import="com.eg.EgSpecsInfo"%>
<%@ page import="com.eg.EgThresholdInfo"%>
<%@ page import="com.eg.EgAggregateInfo"%>
<%@ page import="com.eg.MappingNameSorter"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="com.egurkha.ini.IniUI"%>
<%@ page import="egurkha.ServerBean"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.ArrayList"%>

<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="net.sf.json.JSONArray"%>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);
	response.setContentType("application/json;charset=UTF-8");

	JSONObject rootJSON = new JSONObject();
	rootJSON.put("success","true");
	/*egurkha.TestsNotConfigured tnCon = new egurkha.TestsNotConfigured();
	Vector orasWithoutSIDs = tnCon.serversWithoutSID();*/
	EgRoleInfo roleInfo = EgRoleInfo.getInstance(session.getId(),(String)session.getAttribute("sess_userid"));
	boolean isLimitedAdmin = !roleInfo.hasAllComponentAccess();
	ArrayList userCompTypes = new ArrayList();
	if (isLimitedAdmin)
	{
		String[] serverTypes = roleInfo.getServerTypes();
		if (serverTypes != null)
		{ 
			userCompTypes = new ArrayList(Arrays.asList(serverTypes));
		}
	}
	/*if (orasWithoutSIDs != null && orasWithoutSIDs.size() >0)
	{
		int orasCount = orasWithoutSIDs.size();
		if(orasCount % 4 == 1)
		{
			orasWithoutSIDs.add("");
			orasWithoutSIDs.add("");
			orasWithoutSIDs.add("");
		}
		else if (orasCount % 4 == 2)
		{
			orasWithoutSIDs.add("");
			orasWithoutSIDs.add("");
		}
		else if(orasCount % 4 == 3)
		{
			orasWithoutSIDs.add("");
		}
		
		JSONArray oraGridArr =  new JSONArray();
		for (int a=0; a<orasWithoutSIDs.size(); a=a+4)
		{
			String oraComp = orasWithoutSIDs.get(a).toString();
			JSONObject gridVal = new JSONObject();
			gridVal.put("column_1",orasWithoutSIDs.get(a).toString());
			gridVal.put("column_2",orasWithoutSIDs.get(a+1).toString());
			gridVal.put("column_3",orasWithoutSIDs.get(a+2).toString());
			gridVal.put("column_4",orasWithoutSIDs.get(a+3).toString());
			oraGridArr.add(gridVal);
		}
		rootJSON.put("oraGridData",oraGridArr);
		rootJSON.put("showOraclAlert",true);	
	}*/

	EgDiscInfo egDisc = new EgDiscInfo("manager");
	ArrayList managedCompTypes = egDisc.getManagedComponentTypes();
	if (isLimitedAdmin)
	{
		managedCompTypes = new ArrayList(userCompTypes);
	}
	if(managedCompTypes == null)
	{
		managedCompTypes = new ArrayList();
	}
	boolean isAnyManagedCompExist = false;
	if (managedCompTypes != null && managedCompTypes.size() > 0)
	{
		isAnyManagedCompExist = true;
	}
	rootJSON.put("showManagedCompTypesOption",isAnyManagedCompExist);
	String activeCompTypes = request.getParameter("activeCompTypes");
	boolean activeCompCheck=false;
	if(activeCompTypes !=null && activeCompTypes.equalsIgnoreCase("true"))
	{
		activeCompCheck=true;
	}
	rootJSON.put("showManagedCompTypes",activeCompCheck);

	//Category
	String selectedServerGroup = request.getParameter("selectedServerGroup");
	if (selectedServerGroup == null || selectedServerGroup.trim().equals("") || selectedServerGroup.trim().equalsIgnoreCase("null"))
		selectedServerGroup = "-1";
	rootJSON.put("selectedServerGroup",selectedServerGroup);
	ArrayList serverGrps = getAllServerGroups(egDisc,managedCompTypes);
	JSONArray categoryArr = new JSONArray();
	JSONObject tempObj = new JSONObject();
	tempObj.put("valueField","-1");
	tempObj.put("displayField",_mapping.getTextDescription("admin.server.All"));
	categoryArr.add(tempObj);

	for(int i=0; i<serverGrps.size(); i++)
	{
		String serverGrp = (String)serverGrps.get(i);
		if (serverGrp.equals(selectedServerGroup))
		{
			rootJSON.put("selectedServerGroup",serverGrp);
		}
		JSONObject obj = new JSONObject();
		obj.put("valueField",serverGrp);
		obj.put("displayField",_mapping.getTextDescription("admin.category."+serverGrp));
		categoryArr.add(obj);
	}
	rootJSON.put("category",categoryArr);


	EgAggregateInfo aggregateInfo = new EgAggregateInfo("manager");
	Vector noAggSupportTypes = aggregateInfo.getNoAggregateSupportTypes();
	//Component type
	ArrayList serverList  = new ArrayList();
	for(int i=0; i<managedCompTypes.size(); i++)
	{
		String t = (String)managedCompTypes.get(i);
		if(noAggSupportTypes != null && noAggSupportTypes.contains(t))
		{
			continue;
		}
		if (!t.equals("Site_servers"))
		{
			if(!activeCompCheck)
			{
				if(t.startsWith("Agg_"))
				{
					continue;
				}
				String[] component = egDisc.getAllServersOfType(t);
				if(component != null && component.length>0)
				{
					serverList.add("Agg_" + t);
				}
			}
			else
			{
				serverList.add(t);
			}
		}
	}
	IniUI iniUI = IniUI.getInstance();
	String userLanguage = _user.getLanguage();
	if (userLanguage == null)
		userLanguage = iniUI.getDefaultLanguage();
	MappingNameSorter sorter = new MappingNameSorter(userLanguage);

	//Code starts to show managed comp types only
	List tempList=new ArrayList();
	List tempCategoryList = new ArrayList();
	if(activeCompTypes!=null && activeCompTypes.equalsIgnoreCase("true"))
	{
		rootJSON.put("selectedServerGroup","-1");
		for(int j=0;j<serverList.size();j++)
		{
			String compType = (String)serverList.get(j);
			if (isLimitedAdmin && !userCompTypes.contains(compType))
			{
				continue;
			}
			if(compType.startsWith("Agg_"))
			{
				continue;
			}
			String[] tempCompNames = roleInfo.getAllServersOfType("Agg_" + compType);
			if(tempCompNames !=null && tempCompNames.length > 0)
			{
				tempList.add("Agg_" + compType);
				String tmpCategory = getCategoryForCompononetType(compType);
				if(tmpCategory.equalsIgnoreCase("AGGREGATES"))
				{
					continue;
				}
				if (!tempCategoryList.contains(tmpCategory))
				{
					tempCategoryList.add(tmpCategory);
				}
			}
		}
		serverList = new ArrayList(tempList);
		categoryArr = new JSONArray();
		tempObj = new JSONObject();
		tempObj.put("valueField","-1");
		tempObj.put("displayField",_mapping.getTextDescription("admin.server.All"));
		categoryArr.add(tempObj);
		Collections.sort(tempCategoryList,String.CASE_INSENSITIVE_ORDER);
		for(int i=0; i<tempCategoryList.size(); i++)
		{
			String serverGrp = (String)tempCategoryList.get(i);
			if (serverGrp.equals(selectedServerGroup))
			{
				rootJSON.put("selectedServerGroup",serverGrp);
			}
			JSONObject obj = new JSONObject();
			obj.put("valueField",serverGrp);
			obj.put("displayField",getCapitalizedCategory(serverGrp));
			categoryArr.add(obj);
		}
		rootJSON.put("category",categoryArr);
		if (!tempCategoryList.contains(selectedServerGroup))
		{
			selectedServerGroup = "-1";
		}
	}
	serverList = sorter.getSortedCompTypeList(serverList);

	if (selectedServerGroup != null && !selectedServerGroup.equals("null") && !selectedServerGroup.equals("-1") && selectedServerGroup.length() > 0)
	{
		if (selectedServerGroup.equalsIgnoreCase("Others"))
		{
			ArrayList serversGrpList = getOtherServers();
			if(activeCompTypes!=null && activeCompTypes.equalsIgnoreCase("true"))
			{
				ArrayList tempList1 = new ArrayList();
				for(int j=0;j<serversGrpList.size();j++)
				{
					String compType = (String)serversGrpList.get(j);
					String[] tempCompNames = roleInfo.getAllServersOfType(compType);
					if(tempCompNames !=null && tempCompNames.length > 0)
					{
						tempList1.add(compType);
					}
				}
				serversGrpList = new ArrayList(tempList1);
			}
			serverList = sorter.getSortedCompTypeList(serversGrpList);
		}
		else if (selectedServerGroup.equalsIgnoreCase("USER-DEFINED_SERVERS"))
		{
			ArrayList serversGrpList = getAllUserDefinedServers();
			if(activeCompTypes!=null && activeCompTypes.equalsIgnoreCase("true"))
			{
				ArrayList tempList1 = new ArrayList();
				for(int j=0;j<serversGrpList.size();j++)
				{
					String compType = (String)serversGrpList.get(j);
					String[] tempCompNames = roleInfo.getAllServersOfType(compType);
					if(tempCompNames !=null && tempCompNames.length > 0)
					{
						tempList1.add(compType);
					}
				}
				serversGrpList = new ArrayList(tempList1);
			}
			serverList = sorter.getSortedCompTypeList(serversGrpList);
		}
		else if (selectedServerGroup.equalsIgnoreCase("CUSTOM_COMPONENTS"))
		{
			ArrayList serversGrpList = getAllUserDefinedServers();
			if(activeCompTypes!=null && activeCompTypes.equalsIgnoreCase("true"))
			{
				ArrayList tempList1 = new ArrayList();
				for(int j=0;j<serversGrpList.size();j++)
				{
					String compType = (String)serversGrpList.get(j);
					String[] tempCompNames = egDisc.getAllServersOfType(compType);
					if(tempCompNames !=null && tempCompNames.length > 0)
					{
						tempList1.add(compType);
					}
				}
				serversGrpList = new ArrayList(tempList1);
			}
			serverList = sorter.getSortedCompTypeList(serversGrpList);
		}
		else
		{
			ArrayList serversGrpList = getCategorizedComponents(selectedServerGroup,egDisc);
			if(activeCompTypes!=null && activeCompTypes.equalsIgnoreCase("true"))
			{
				ArrayList tempList1 = new ArrayList();
				for(int j=0;j<serversGrpList.size();j++)
				{
					String compType = (String)serversGrpList.get(j);
					String[] tempCompNames = roleInfo.getAllServersOfType(compType);
					if(tempCompNames !=null && tempCompNames.length > 0)
					{
						tempList1.add(compType);
					}
				}
				serversGrpList = new ArrayList(tempList1);
			}
			serverList = sorter.getSortedCompTypeList(serversGrpList);
		}
	}
	if (selectedServerGroup != null && selectedServerGroup.equalsIgnoreCase("Others"))
	{
		serverList = removeAggServers(serverList);
	}
	String strServer = request.getParameter("server");
	if (strServer==null || strServer.equalsIgnoreCase("null"))
		strServer="";
	JSONArray compTypesArray = new JSONArray();
	JSONObject tmpObj = new JSONObject();
	tmpObj.put("valueField","-1");
	tmpObj.put("displayField",_mapping.getTextDescription("admin.server.Choose an aggregate component type"));
	compTypesArray.add(tmpObj);
	String selectedCompType = "-1";
	for(int i=0; i<serverList.size(); i++)
	{
		EgName nameObj = (EgName)serverList.get(i);
		//searchItemFound=true;
		String tmpVal = nameObj.getActualName();
		String tmpDis = nameObj.getLocalName();
		if(tmpVal.startsWith("Agg_"))
		{
			//continue;
		}
		if (tmpVal.equals(strServer)) 
			selectedCompType = strServer;
		JSONObject obj = new JSONObject();
		obj.put("valueField",tmpVal);
		obj.put("displayField",tmpDis);
		compTypesArray.add(obj);
	}
	rootJSON.put("componentTypes",compTypesArray);
	rootJSON.put("selectedCompType",selectedCompType);

	//Aggregate test and measures for popup window starts here
	rootJSON.put("compTypeSelected",false);
	rootJSON.put("popupTitle",_mapping.getTextDescription("admin.common.Aggregate tests and measures"));
	if(!selectedCompType.equals("-1"))
	{
		EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
		EgThresholdInfo threshConfig = new EgThresholdInfo("manager");
		String[] tests = specsInfo.getDefaultTestsForServer(selectedCompType);
		if(tests != null && tests.length>0)
		{
			ArrayList testList = new ArrayList(Arrays.asList(tests));
			testList = sorter.getSortedTestList(testList);
			JSONArray gridArray =new JSONArray();
			for(int c=0;c<testList.size();c++)
			{
				EgName name = (EgName)testList.get(c);
				String aggTest = name.getActualName();
				String measures[] = threshConfig.getMeasurementsForTest(aggTest);

				JSONObject gridDataObject = new JSONObject();
				gridDataObject.put("aggTestName",name.getLocalName());
				gridDataObject.put("count",measures.length);

				String tmpStr = "<table class='mylink' border=\"0\" width=\"95%\" align=\"center\" cellpadding=\"4\"><tr><td colspan=\"3\" style=\"padding:4px\"><i>"+_mapping.getTextDescription("admin.server.Measures")+"</i></td></tr><tr>";

				if(measures != null && measures.length > 0)
				{
					int countColumn = 0;
					for (int i = 0;i<measures.length;i++)
					{
						String displayMeasure = _mapping.getMeasureDescription(aggTest,measures[i]);
						countColumn++;
						if(countColumn == 3)
						{
							tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%'>"+displayMeasure+"</td>";
							countColumn = 0;
							tmpStr = tmpStr + "</tr><tr>";
						}
						else
						{
							tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%'>"+displayMeasure+"</td>";
						}
					}
					if(countColumn == 2)
					{
						tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td>";
					}
					if(countColumn == 1)
					{
						tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td><td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td>";
					}
				}
				tmpStr = tmpStr + "</tr></table>";
				gridDataObject.put("measurenames",tmpStr);
				gridArray.add(gridDataObject);
			}
			rootJSON.put("measuresGridDataList",gridArray);
			rootJSON.put("popupTitle",_mapping.getTextDescription("admin.common.Aggregate tests and measures for")+" "+ _mapping.getComponentTypeDescription(selectedCompType));
			rootJSON.put("compTypeSelected",true);
			rootJSON.put("totalAggTests",_mapping.getTextDescription("admin.common.Total aggregate tests")+" : "+ tests.length);
		}
	}
	//Aggregate test and measures for popup window ends here

	//Components listing
	String egTitleSearchStr=request.getParameter("searchStr");
	boolean isSearchResult =(egTitleSearchStr!=null);
	if (egTitleSearchStr==null)
		egTitleSearchStr="";
	ArrayList searchList = new ArrayList();
	if (isSearchResult)
	{
		egTitleSearchStr = egurkha.EgUIUtils.decodeSecurityChar(egTitleSearchStr);
		StringTokenizer st = new StringTokenizer(egTitleSearchStr);
		while (st.hasMoreTokens())
		{
			String thisToken = st.nextToken().trim();
			if (thisToken.equals(""))
				continue;
			searchList.add(thisToken);
		}
	}
	String temp = "";
	String[] serversArray = roleInfo.getAllServersOfType(strServer);
	ArrayList servers = serversArray==null?new ArrayList():new ArrayList(Arrays.asList(serversArray));
	boolean serversFound = false;
	List minusList = new ArrayList();
	for(int j=0; j<servers.size(); j++)
	{
		String thisSrv = (String) servers.get(j);
		if(thisSrv.startsWith("Format:") || thisSrv.startsWith("#"))
		{
			minusList.add(thisSrv);
			continue;
		}
		temp=thisSrv.substring(thisSrv.indexOf(":")+1);
		if(strServer.equals("Oracle_server") && (temp.indexOf(":") != temp.lastIndexOf(":")))
		{
			temp = temp.substring(0,temp.lastIndexOf(":"));
		}

		String ipWithoutPort = Server.getServerNameWithoutPort(temp, false);
		if (isSearchResult && !doesExist(searchList,ipWithoutPort))
		{
				minusList.add(thisSrv);
				continue;
		}
		serversFound=true;
	}
	servers.removeAll(minusList);
	Collections.sort(servers,String.CASE_INSENSITIVE_ORDER);
	Vector vecStore = new Vector();
	JSONArray objArray = new JSONArray();
	com.eg.EgExternalInfo extInfo = new com.eg.EgExternalInfo("manager");
	if (!strServer.equals("null") && servers.size() > 0)
	{
		for(int j=0; j<servers.size(); j++)
		{
			String thisSrv = (String) servers.get(j);
			temp=thisSrv.substring(thisSrv.indexOf(":")+1);
			String ip = egDisc.getComponentIP(strServer,temp);
			String nickAlone = temp.substring(0,temp.indexOf(":"));
			if(strServer.equals("Oracle_server") && (temp.indexOf(":") != temp.lastIndexOf(":")))
			{
				temp = temp.substring(0,temp.lastIndexOf(":"));
			}
			if(!vecStore.contains(temp))
			{
				vecStore.addElement(temp);
				String ipWithoutPort = Server.getServerNameWithoutPort(temp, false);

				if (isSearchResult && !doesExist(searchList,ipWithoutPort))
					continue;
				serversFound=true;
				String agentType = "Agent-based";
				if(extInfo.isRemoteBased(nickAlone))
				{
					agentType = "Agentless";
				}
				
				JSONObject obj = new JSONObject();
				obj.put("Compname",ipWithoutPort);
				List associatedComponents = aggregateInfo.getAssociatedComponents(thisSrv, true);
				/*if(associatedComponents != null && !associatedComponents.isEmpty())
				{
					String nicks = "";
					for(int k=0;k<associatedComponents.size();k++)
					{
						String comp = (String)associatedComponents.get(k);
						if(comp.endsWith(":NULL"))
						{
							comp = comp.substring(0,comp.lastIndexOf(":"));
						}
						int idx = comp.indexOf(":");
						String ctype = comp.substring(0,idx);
						//comp = _mapping.getComponentTypeDescription(ctype) + comp.substring(idx);
						comp = comp.substring(idx+1);
						nicks += "," + comp;
					}
					obj.put("HostIP",nicks.substring(1));
				}
				else
				{
					obj.put("HostIP","");
				}*/

				String tmpStr = "<table class='mylink' border=\"0\" width=\"95%\" align=\"center\" cellpadding=\"4\"><tr><td colspan=\"3\" style=\"padding:4px\"><i>"+_mapping.getTextDescription("admin.server.Associated Components")+"</i></td></tr><tr>";
				if(associatedComponents != null && !associatedComponents.isEmpty())
				{
					int countColumn = 0;
					for (int i = 0;i<associatedComponents.size();i++)
					{
						String individualComponent = (String)associatedComponents.get(i);
						String arr[] = StringUtils.getTokens(individualComponent,":");
						String compTypeDescription = _mapping.getComponentTypeDescription(arr[0]);
						String displayComponent = null;
						if(arr[0].equals("Oracle_server"))
						{
							//displayComponent = _mapping.getComponentTypeDescription(arr[0]) + ":" + arr[1] + ":" + arr[2] + ":" + arr[3];
							displayComponent = arr[1];// + ":" + arr[2] + ":" + arr[3];
						}
						else if(!arr[2].equals("NULL"))
						{
							//displayComponent = _mapping.getComponentTypeDescription(arr[0]) + ":" + arr[1] + ":" + arr[2];
							displayComponent = arr[1];// + ":" + arr[2];
						}
						else
						{
							//displayComponent = _mapping.getComponentTypeDescription(arr[0]) + ":" + arr[1];
							displayComponent = arr[1];
						}
						countColumn++;
						if (countColumn == 3)
						{
							tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%'>"+displayComponent+"</td>";
							countColumn = 0;
							tmpStr = tmpStr + "</tr><tr>";
						}
						else
						{
							tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%'>"+displayComponent+"</td>";
						}
					}
					if (countColumn == 2)
					{
						tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td>";
					}
					if (countColumn == 1)
					{
						tmpStr = tmpStr + "<td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td><td style='padding-top:3px;padding-bottom:5px;width:33%' align='left'>&nbsp;</td>";
					}
				}
				tmpStr = tmpStr + "</tr></table>";
				obj.put("HostIP",tmpStr);
				obj.put("Monitoring",agentType);
				objArray.add(obj);
			}
		}
		rootJSON.put("serversFound",serversFound);
		rootJSON.put("components",objArray);
	}

	out.println(rootJSON);
%>

<%!
	public ArrayList tempServers = new ArrayList();
	public ServerBean serverBean = new ServerBean();

	private boolean doesExist(List searchList, String server)
	{
		Iterator i = searchList.iterator();
		while(i.hasNext())
		{
			String nextStr = (String) i.next();
			if (server.indexOf(nextStr)!=-1||(server.toUpperCase().indexOf(nextStr.toUpperCase()))!=-1)
			{
				return true;
			}
		}
		return false;
	}

	private ArrayList removeAggServers(ArrayList serverList)
	{
		ArrayList tmpList = new ArrayList();
		for(int i=0; i<serverList.size(); i++)
		{
			EgName nameObj1 = (EgName)serverList.get(i);
			String tmpVal = nameObj1.getActualName();
			String tmpDis = nameObj1.getLocalName();
			if(tmpVal.startsWith("Agg_"))
			{
				continue;
			}
			tmpList.add(serverList.get(i));
		}

		return tmpList;
	}
	
	public ArrayList getAllServerGroups(EgDiscInfo egDisc, ArrayList managedCompTypes)
	{
		ArrayList grp = new ArrayList();
		try
		{
			IniFile iniFile = new IniFile(EgInstallInfo.getInstallDir() +"/manager/config/eg_infrastructure.ini");
			String[] Subjects = iniFile.getSubjects();
			for (int i = 0;i<Subjects.length;i++ )
			{
				String groupName = Subjects[i];
				if(groupName.equalsIgnoreCase("AGGREGATES") || groupName.equalsIgnoreCase("OTHERS"))
				{
					continue;
				}
				String ctypes[] = iniFile.getVariables(groupName);
				if(ctypes != null && ctypes.length>0)
				{
					for(int j=0;j<ctypes.length;j++)
					{
						if(managedCompTypes.isEmpty() || !managedCompTypes.contains(ctypes[j]))
							continue;
						String components[] = egDisc.getAllServersOfType(ctypes[j]);
						if(components != null && components.length>0)
						{
							grp.add(groupName);
							break;
						}
					}
				}
			}
			String[] servertypes = egDisc.getComponentTypes();
			for(int i=0; i<servertypes.length; i++)
			{
				String t = servertypes[i];
				if(!t.startsWith("Agg_") && t.endsWith("_ex"))
				{
					String components[] = egDisc.getAllServersOfType(t);
					if(components != null && components.length>0)
					{
						if(!grp.contains("CUSTOM_COMPONENTS"))
						{
							grp.add("CUSTOM_COMPONENTS");
						}
						break;
					}
				}
			}
			if(!grp.isEmpty())
			{
				Collections.sort(grp,String.CASE_INSENSITIVE_ORDER);
			}
			//grp.add("OTHERS");
			//if (isICEnabled())
			//{
			//	grp.add("USER-DEFINED_SERVERS");
			//}
			//grp.remove("AGGREGATES");
			return grp;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return new ArrayList();
		}
	}
	public String getCapitalizedCategory(String categoryName)
	{
		StringBuffer buff = new StringBuffer();
		int j = 0;
		if (categoryName != null)
		{
			//for (int i = 0;i<grps.size();i++ )
			//{
				//String val = (String)grps.get(i);
				if (categoryName.indexOf("_") != -1)
				{
					categoryName = StringUtils.replace(categoryName,"_"," ");
				}
				StringTokenizer tokens = new StringTokenizer(categoryName," ");
				while(tokens.hasMoreTokens())
				{
					String token = tokens.nextToken();
					token = token.trim();
					token = token.toLowerCase();
					String sub = token.substring(1);
					String initial = (token.substring(0,1)).toUpperCase();
					initial = initial + sub;
					if (j == 0)
					{
						buff.append(initial);
					}
					else
					{
						buff.append(" ");
						buff.append(initial);
					}
					j++;
				}
			//}
		}
		return buff.toString();
	}

	public ArrayList getOtherServers()
	{
		getAllInfraServers();
		ArrayList serverList = new ArrayList();
		EgDiscInfo egDisc = new EgDiscInfo("manager");
		String[] otherServers = egDisc.getComponentTypes();
		if (otherServers == null || otherServers.length == 0)
		{
			return new ArrayList();
		}
		for(int i=0; i<otherServers.length; i++)
		{
			if (!otherServers[i].equals("Site_servers"))
			{
				if (!tempServers.contains(otherServers[i]))
				{
					serverList.add(otherServers[i]);
				}
			}
		}
		return serverList;
	}

	public void getAllInfraServers()
	{
		ArrayList comGroups = new ArrayList();
		try
		{
			IniFile iniFile = new IniFile(EgInstallInfo.getInstallDir() +"/manager/config/eg_infrastructure.ini");
			String[] Subjects= iniFile.getSubjects();
			for (int i = 0;i<Subjects.length;i++ )
			{
				if (Subjects[i] != null && Subjects[i].equalsIgnoreCase("AGGREGATES"))
				{
					continue;
				}

				String [] variables = iniFile.getVariables(Subjects[i]);
				for (int j = 0;j<variables.length;j++)
				{
					tempServers.add(variables[j]);
				}
			}
		}
		catch (Exception e)
		{
		}
	}

	public ArrayList getAllUserDefinedServers()
	{
		EgDiscInfo egDisc = new EgDiscInfo("manager");
		ArrayList udServers = new ArrayList();
		String[] servertypes = egDisc.getComponentTypes();
		if(servertypes != null)
		{
			for(int i=0; i<servertypes.length; i++)
			{
				String t = servertypes[i];
				if(!t.startsWith("Agg_") && t.endsWith("_ex"))
				{
					udServers.add("Agg_"+t);
				}
			}
		}
		return udServers;
	}
	public ArrayList getCategorizedComponents(String compGroup, EgDiscInfo egDisc)
	{
		ArrayList comGroups = new ArrayList();
		try
		{
			IniFile iniFile = new IniFile(EgInstallInfo.getInstallDir() +"/manager/config/eg_infrastructure.ini");
			String[] Subjects= iniFile.getSubjects();

			String [] variables = iniFile.getVariables(compGroup);
			for (int j = 0;j<variables.length;j++)
			{
				String comptype = variables[j];
				String components[] = egDisc.getAllServersOfType(comptype);
				if(components != null && components.length>0)
				{
					comGroups.add("Agg_"+comptype);
				}
			}
			if(compGroup != null && compGroup.equals("CUSTOM_COMPONENTS"))
			{
				EgAggregateInfo aggInfo = new EgAggregateInfo("manager");
				Vector temp = aggInfo.getVariables("AGGREGATE_TYPES",true);
				if(temp != null)
				{
					for(int i=0;i<temp.size();i++)
					{
						String atype = (String)temp.get(i);
						if(atype.endsWith("_ex"))
						{
							comGroups.add(atype);
						}
					}
				}
			}
		}
		catch (Exception e)
		{
			return new ArrayList();
		}
		return comGroups;
	}
	public String getCategoryForCompononetType(String compType)
	{
		IniFile iniFile = new IniFile(EgInstallInfo.getInstallDir() +"/manager/config/eg_infrastructure.ini");
		String[] subs = iniFile.getSubjects();
		String res ="";
		if(subs!=null)
		{
			for (int s=0; s<subs.length; s++)
			{
				String sub = subs[s];
				String[] vars = iniFile.getVariables(sub);
				if (vars!=null)
				{
					List compTypes = Arrays.asList(vars);
					if (compTypes.contains(compType))
					{
						res = sub;
					}
				}
			}
		}
		if(compType.endsWith("_ex"))
		{
			res = "CUSTOM_COMPONENTS";
		}
		return res;
	}
%>