
<%@ include file="../../EgTrackerAJSON.jsp" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Date"%>
<%@ page import="com.eg.EgDiscInfo" %>
<%@ page import="com.eg.EgTestInfo" %>
<%@ page import="com.eg.IniFile" %>
<%@ page import="com.eg.EgExternalInfo" %>
<%@ page import="com.eg.EgServicesInfo" %>
<%@ page import="com.eg.EgSpecsInfo" %>
<%@ page import ="egurkha.EgDbAdapterUI"%>
<%@ page import ="com.eg.EgDbAdapterTypeUI"%>
<%@ page import =" com.eg.EgRoleInfo"%> 
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgInstallInfo"%>
<%@ page import="com.eg.EgName"%>
<%@ page import="com.eg.MappingNameSorter"%>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import="com.egurkha.ini.IniUI"%>
<%@ page import = "com.egurkha.*"%>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import="com.egurkha.util.StringUtils" %>
<%@ page import="com.egurkha.util.ListUtils" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "net.sf.json.*" %>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%!
	String[] criterias = {"Zone","Service","Segment","Component"};

	String arrayTimePeriod[]={"30 mins", "1 hour","3 hours","6 hours","12 hours","1 day","3 days","5 days","1 week","2 weeks","3 weeks","4 weeks","Any time"};
	long defaultValue = 60000;

	private ArrayList getAssociatedComponents(HttpSession session, User user,String view,String option)
	{
		ArrayList aListAssociatedComponents = new ArrayList();

		EgGroupInfo egGroupInfo = new EgGroupInfo();
		EgTopoInfo egTopoInfo = egGroupInfo.getTopoInfoObject();

		if (option != null)
		{
			try
			{
				option = EgURLDecoder.decode(option,"UTF-8");
			}
			catch (Exception e)
			{
			}
		}

		Vector vecUserOptions = null;
		Vector vecUserAssociatedComponents = new Vector(user.getServers(false));

		if (view != null && view.equalsIgnoreCase("Zone"))
		{
			List zoneList = user.getZones();

			//To fetch all components from user associated zones
			ArrayList aListComponentsFromZone = new ArrayList();
			if (zoneList != null && !zoneList.isEmpty())
			{
				vecUserOptions = new Vector(zoneList);
				Collections.sort(vecUserOptions,String.CASE_INSENSITIVE_ORDER);

				for (int i=0;i<vecUserOptions.size();i++)
				{
					String strZone = (String)vecUserOptions.get(i);
					aListComponentsFromZone.addAll(egGroupInfo.getAllComponentsUnderZone(strZone,true));
				}
			}

			if (aListComponentsFromZone != null && !aListComponentsFromZone.isEmpty())
			{
				boolean defaultZoneExists = false;
				for (int i=0;i<vecUserAssociatedComponents.size();i++)
				{
					String component = (String)vecUserAssociatedComponents.get(i);
					if (!aListComponentsFromZone.contains(component))
					{
						defaultZoneExists = true;
						break;
					}
				}

				if (defaultZoneExists)
				{
					vecUserOptions.add(0,"--Default--");
				}
			}
			else
			{
				if (vecUserAssociatedComponents != null && !vecUserAssociatedComponents.isEmpty())
				{
					vecUserOptions = new Vector();
					vecUserOptions.add("--Default--");
				}
			}

			if (option == null && vecUserOptions != null && !vecUserOptions.isEmpty())
			{
				option = (String)vecUserOptions.get(0);
			}

			if (option != null)
			{
				if (!option.equalsIgnoreCase("--Default--"))
				{
					aListAssociatedComponents = egGroupInfo.getAllComponentsUnderZone(option,true);
				}
				else
				{
					aListAssociatedComponents = new ArrayList();
					for (int i=0;i<vecUserAssociatedComponents.size();i++)
					{
						String userComponent = (String)vecUserAssociatedComponents.get(i);
						int index = aListComponentsFromZone.indexOf(userComponent);
						if (index == -1)
						{
							aListAssociatedComponents.add(userComponent);
						}
					}
				}
			}
		}
		else if (view != null && view.equalsIgnoreCase("Service"))
		{
			List serviceList = new ArrayList();
			serviceList.addAll(user.getServices());
			ArrayList aListSites = new ArrayList();
			aListSites.addAll(user.getSites());
			aListSites.removeAll(serviceList);
			serviceList.addAll(aListSites);
			if (serviceList != null && !serviceList.isEmpty())
			{
				vecUserOptions = new Vector(serviceList);
				Collections.sort(vecUserOptions,String.CASE_INSENSITIVE_ORDER);
			}

			if (option == null && vecUserOptions != null && !vecUserOptions.isEmpty())
			{
				option = (String)vecUserOptions.get(0);
			}

			if (option != null)
			{
				Vector vecServiceComponents = egTopoInfo.getAssociatesForSite(option);
				if (vecServiceComponents != null)
				{
					aListAssociatedComponents = new ArrayList(vecServiceComponents);
				}
			}
		}
		else if (view != null && view.equalsIgnoreCase("Segment"))
		{
			List segmentList = user.getSegments();
			if (segmentList != null && !segmentList.isEmpty())
			{
				vecUserOptions = new Vector(segmentList);
				Collections.sort(vecUserOptions,String.CASE_INSENSITIVE_ORDER);
			}

			if (option == null && vecUserOptions != null && !vecUserOptions.isEmpty())
			{
				option = (String)vecUserOptions.get(0);
			}
			if (option != null)
			{
				Vector vecSegmentComponents = egTopoInfo.getAssociatesForSegment(option,2);
				if (vecSegmentComponents != null)
				{
					aListAssociatedComponents = new ArrayList(vecSegmentComponents);
				}
			}
		}
		else
		{
			aListAssociatedComponents = new ArrayList(vecUserAssociatedComponents);
		}
		session.setAttribute("ec_criteria",view);
		session.setAttribute("ec_userOption",option);
		session.setAttribute("vecUserOptions",vecUserOptions);

		return aListAssociatedComponents;
	}
%>

<%
	JSONObject rootJson  = new JSONObject();
	JSONObject screenLabels  = new JSONObject();

	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);
	EgDbAdapterUI egDb;
%>
<jsp:useBean id="testConfSpecsBean" scope ="page" class ="egurkha.TestConfigSpecsBean"/>
<jsp:useBean id="testParamBean" scope="page" class="egurkha.EgTestParamBean"/>

<%
	User user=registry.getUser(session.getId());
	com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();
	String thisLanguage = ui.getDefaultLanguage();
	if (user!=null)
	{
		String userLang = user.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	MappingNameSorter sorter = new MappingNameSorter(thisLanguage);

	boolean isConnected = false;
	String server = request.getParameter("server");
	String comp = request.getParameter("comp");
	String strTest = request.getParameter("testName");
	String qctr = request.getParameter("qctr");
	String requestFrom = request.getParameter("requestFrom");

	String whoami = "manager";
	int limit = 15;
	long duration = 0l;
	EgSpecsInfo specsInfo = new EgSpecsInfo(whoami);
	EgDiscInfo discInfo = new EgDiscInfo(whoami);
	EgTestInfo testInfo = new EgTestInfo(whoami);
    	EgTablesInfo tablesInfo = new EgTablesInfo(whoami);

	EgRoleInfo egRoleInfo=EgRoleInfo.getInstance(session.getId(),(String)session.getAttribute("sess_userid"));

	IniFile testInfoIni = new IniFile(EgConfigInfo.egMgrConfigDir + "eg_testinfo.ini");
	String showApplyToOtherComponentsList = testInfoIni.getValue("MISC_ARGS","ShowInApplyToOtherComponentsList");
	if(com.egurkha.util.StringUtils.isNull(showApplyToOtherComponentsList))
	{
		showApplyToOtherComponentsList = "Manangedcomponents";
		IniFile testInfoIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir() + "/manager/config/eg_testinfo.ini");
		testInfoIniWr.setValue("MISC_ARGS","ShowInApplyToOtherComponentsList",showApplyToOtherComponentsList);
		testInfoIniWr.saveFile();
		EgConfigFilesSync.releaseInstance(testInfoIniWr);
	}

	String criteria = request.getParameter("criteria");
	if (criteria == null) 
	{
		criteria = "Component";
	}

	Vector vecCriterias = new Vector();
	for (int g=0;g<criterias.length;g++)
	{
		String strCriteria = criterias[g];
		vecCriterias.add(strCriteria);
	}

	String userOption = request.getParameter("userOption");
	if (StringUtils.isNull(userOption) || userOption.equals("-1"))
	{
		userOption = null;
	}
	boolean isValidCompType = (!StringUtils.isNull(server) && !server.equals("-1"));

	rootJson.put("criteria",criteria);

	JSONObject viewByObj = new JSONObject();
	JSONArray viewByArr = new JSONArray();

	if (vecCriterias != null && !vecCriterias.isEmpty())
	{
		for(int i=0; i<vecCriterias.size(); i++)
		{
			String selected = "";
			String strCriteria = (String)vecCriterias.get(i);
			if(criteria != null && strCriteria.equals(criteria))
			{
				rootJson.put("selectedCriteria",criteria);
			}
			viewByObj.put("displayField",_mapping.getTextDescription("admin.common."+strCriteria));
			viewByObj.put("valueField",strCriteria);
			viewByArr.add(viewByObj);
		}
	}
	else
	{
		rootJson.put("selectedCriteria","-1");
		viewByObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
		viewByObj.put("valueField","-1");
		viewByArr.add(viewByObj);
	}
	rootJson.put("viewByArr",viewByArr);

	IniFile egUI = new IniFile(EgConfigInfo.egMgrConfigDir + "eg_ui.ini");
	String strLimit = egUI.getValue("MISC_ARGS","SEARCHBOX_ENABLE_LIMIT");
	if(strLimit != null)
	{
		limit = Integer.parseInt(strLimit);
	}
	
	String[] ComponentsType = egRoleInfo.getServerTypes();
	ArrayList a_ComponentsType = new ArrayList();
	String [] s_arr = null;
	for(int z=0;z < ComponentsType.length;z++)
	{
		if(!StringUtils.isNull(ComponentsType[z]) && ComponentsType[z].startsWith("Agg_"))
		{
			continue;
		}

		s_arr = egRoleInfo.getAllServersOfType(ComponentsType[z]);
		if(s_arr.length > 0)
		{
			a_ComponentsType.add(ComponentsType[z]);
		}
	}

	HashSet vec_componentTypes = new HashSet();
	Vector allcomps = new Vector();
	Vector vec_components = new Vector();

	ArrayList associatedComponents = getAssociatedComponents(session, _user, criteria, userOption);
	if (!criteria.equals("Component"))
	{
		allcomps.addAll(associatedComponents);
		if (!allcomps.isEmpty())
		{
			for (int i=0;i<allcomps.size();i++)
			{
				String str = (String) allcomps.get(i);
				String component_type = str.substring(0,str.indexOf(":"));
				vec_componentTypes.add(component_type);
				String component_name = str.substring(str.indexOf(":")+1);
				if (isValidCompType && str.startsWith(server))
				{
					vec_components.add(str);
				}
			}
		}

		Vector vecUserOptions = (Vector)session.getAttribute("vecUserOptions");
		if (StringUtils.isNull(userOption) && vecUserOptions != null && !vecUserOptions.isEmpty())
		{
			userOption = (String)vecUserOptions.get(0);
		}

		JSONArray specviewByArr = new JSONArray();
		if (criteria != null && !criteria.equalsIgnoreCase(criterias[3]) && !criteria.equals("-1"))
		{
			if (criteria.equalsIgnoreCase(criterias[0]))
			{
				rootJson.put("specViewByTitle",criterias[0]);
			}
			else if (criteria.equalsIgnoreCase(criterias[1]))
			{
				rootJson.put("specViewByTitle",criterias[1]);
			}
			else
			{
				rootJson.put("specViewByTitle",criterias[2]);
			}

			JSONObject specviewByObj = new JSONObject();
			if (vecUserOptions != null && !vecUserOptions.isEmpty())
			{
				for(int i=0; i<vecUserOptions.size(); i++)
				{
					String selected = "";
					String strUserOption = (String)vecUserOptions.get(i);
					if(userOption != null && strUserOption.equals(userOption))
					{
						rootJson.put("selectedUserOptionText",userOption);
					}
					specviewByObj.put("displayField",strUserOption);
					specviewByObj.put("valueField",strUserOption);
					specviewByArr.add(specviewByObj);
				}
			}
			else
			{
				rootJson.put("selectedUserOptionText","-1");
				specviewByObj.put("displayField",_mapping.getTextDescription("configmgmt.common.Not Applicable"));
				specviewByObj.put("valueField","-1");
				specviewByArr.add(specviewByObj);
			}
			rootJson.put("specViewByArr",specviewByArr);
		}

		// filtering server types...
		a_ComponentsType = new ArrayList();
		if (vec_componentTypes != null && !vec_componentTypes.isEmpty())
		{
			//a_ComponentsType = sorter.getSortedCompTypeList(vec_componentTypes);
			a_ComponentsType.addAll(vec_componentTypes);
		}
	}
	
	rootJson.put("userOption",userOption);

	ResultSet rs = null;
	ResultSet rs1 = null;
	String [] serverTypes = null;
	String [] compList = null;
	String [] allTestArr = null;
	String getTestsForServer="";
	String disabled = "";
	String userLanguage = "";
	String checkEnabledDesc = "";
	String checkDisabledDesc = "";

	ArrayList newEnableDescList = new ArrayList();
	ArrayList enabledSearchList = new ArrayList();
	ArrayList disabledSearchList = new ArrayList();
	ArrayList allCompTypeList = new ArrayList();
	ArrayList allCompList = new ArrayList();
	ArrayList totalTests = new ArrayList();
	ArrayList enabledTests = new ArrayList();
	ArrayList disabledTests = new ArrayList();
	ArrayList excludeServerTestList = new ArrayList();
	ArrayList excludeHostTestList = new ArrayList();
	ArrayList notInfoBasedTests = new ArrayList();
	ArrayList al = new ArrayList();
	Hashtable ht = new Hashtable();
	Hashtable tempMeasureLast = new Hashtable();
	Hashtable tmpHash = new Hashtable();

	// search function
	String strEnabledSearch = request.getParameter("strEnabledSearch");
	String strDisabledSearch = request.getParameter("strDisabledSearch");
	boolean isEnabledSearchResult = (strEnabledSearch != null && !strEnabledSearch.equalsIgnoreCase("") && !strEnabledSearch.equals("Search") && !strEnabledSearch.equals("undefined"));
	boolean isDisabledSearchResult =(strDisabledSearch != null && !strDisabledSearch.equalsIgnoreCase("") && !strDisabledSearch.equals("Search") && !strDisabledSearch.equals("undefined"));
	boolean isNeedAvailDescSearchBox = false;
	boolean isNeedDisableDescSearchBox = false;

	if (isEnabledSearchResult)
	{
		StringTokenizer strTokens = new StringTokenizer(strEnabledSearch);
		while (strTokens.hasMoreTokens())
		{
			String thisToken = strTokens.nextToken().trim();
			if (thisToken.equals("")) continue;
			enabledSearchList.add(thisToken);
		}
	}
	if (isDisabledSearchResult)
	{
		StringTokenizer strTokens = new StringTokenizer(strDisabledSearch);
		while (strTokens.hasMoreTokens())
		{
			String thisToken = strTokens.nextToken().trim();
			if (thisToken.equals("")) continue;
			disabledSearchList.add(thisToken);
		}
	}

	String selection = request.getParameter("duration");
	if(selection == null || selection.length() == 0)
	{
		selection = "1 week";
	}
	if (selection!=null && !selection.equalsIgnoreCase("Default"))
	{
		if(selection.equals("30 mins"))
		{
			duration = 1 * 30 * defaultValue;
		}
		else if(selection.equals("1 hour"))
		{
			duration = 1 * 60 * defaultValue;
		}
		else if(selection.equals("3 hours"))
		{
			duration = 3 * 60 * defaultValue;
		}
		else if(selection.equals("6 hours"))
		{
			duration = 6 * 60 * defaultValue;
		}
		else if(selection.equals("12 hours"))
		{
			duration = 12 * 60 * defaultValue;
		}
		else if(selection.equals("1 day"))
		{
			duration = 24 * 60 * defaultValue;
		}
		else if(selection.equals("3 days"))
		{
			duration =  3 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("5 days"))
		{
			duration = 5 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("1 week"))
		{
			duration = 7 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("2 weeks"))
		{
			duration = 2 * 7 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("3 weeks"))
		{
			duration = 3 * 7 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("4 weeks"))
		{
			duration = 4 * 7 * 24 * 60 * defaultValue;
		}
		else if(selection.equals("Any time"))
		{
			duration=0l;
		}
	}
// for db optimization 
	EgExternalInfo extInfo =new EgExternalInfo("manager");
	EgServicesInfo egserInfo = new EgServicesInfo("manager");
	String compB = "";
	boolean uniqueHostSystemData = egserInfo.isUniqueHostSystemData();
	Hashtable hash = extInfo.getInternalAgentMap();

	screenLabels.put("title","AGENTS - TEST DESCRIPTORS");
	JSONArray descCompTypeArr = new JSONArray();
	JSONObject descCompTypeObj = new JSONObject();

	JSONArray descCompNameArr = new JSONArray();
	JSONObject descCompNameObj = new JSONObject();

	JSONArray descTestNameArr = new JSONArray();
	JSONObject descTestNameObj = new JSONObject();

	screenLabels.put("admin.test.Show active descriptors for ",_mapping.getTextDescription("admin.test.Show active descriptors for "));
	JSONArray descTimeLimitArr = new JSONArray();
	for(int ti=0;ti<arrayTimePeriod.length;ti++)
	{
		JSONObject descTimeLimitObj = new JSONObject();
		String timeDis = arrayTimePeriod[ti];
		descTimeLimitObj.put("displayField",timeDis);
		descTimeLimitObj.put("valueField",timeDis);
		if(timeDis.equals(selection))
		{
			rootJson.put("selectedTime",selection);
		}
		else
		{
		}
		descTimeLimitArr.add(descTimeLimitObj);
	}
	rootJson.put("descTimeLimitArr",descTimeLimitArr);

	if (a_ComponentsType.size()>0)
	{
		rootJson.put("isNoData",false);
		server = (server != null)?server:"";	
		String s_tmp = "";
		ArrayList serverList = new ArrayList();
		screenLabels.put("admin.common.Component type",_mapping.getTextDescription("admin.common.Component type"));
		//JSONArray descCompTypeArr = new JSONArray();
		//JSONObject descCompTypeObj = new JSONObject();
		descCompTypeObj.put("displayField",_mapping.getTextDescription("admin.common.Choose a component type"));
		descCompTypeObj.put("valueField","-1");
		descCompTypeArr.add(descCompTypeObj);
		for(int i=0; i< a_ComponentsType.size(); i++)
		{
			s_tmp = (String)a_ComponentsType.get(i);
			if(!s_tmp.equals("Site_servers"))
				serverList.add(s_tmp);
		}
		userLanguage = _user.getLanguage();
		IniUI  iniUI = IniUI.getInstance();
		if (userLanguage == null)
			userLanguage = iniUI.getDefaultLanguage();

		serverList = sorter.getSortedCompTypeList(serverList );
		for(int j=0;j<serverList.size();j++)
		{
			descCompTypeObj = new JSONObject();
			EgName nameObj = (EgName)serverList .get(j);
			String tmpVal = nameObj.getActualName();
			String tmpDis = nameObj.getLocalName();
			descCompTypeObj.put("displayField",tmpDis);
			descCompTypeObj.put("valueField",tmpVal);
			if(tmpVal.equals(server))
			{
				rootJson.put("selectedCType",server);
			}
			else
			{
			}
			descCompTypeArr.add(descCompTypeObj);
		}
		rootJson.put("descCompTypeArr",descCompTypeArr);
		screenLabels.put("admin.common.Component name",_mapping.getTextDescription("admin.common.Component name"));
		if(server == null || server.length() == 0)
		{
			descCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			descCompNameObj.put("valueField","-1");
			descCompNameArr.add(descCompNameObj);
		}
		else
		{
			compList = egRoleInfo.getAllServersOfType(server);
			if (!criteria.equals("Component"))
			{
				compList =  (String[]) vec_components.toArray(new String[vec_components.size()]);
			}
			if(compList == null || compList.length == 0)
			{
				descCompNameObj = new JSONObject();
				descCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
				descCompNameObj.put("valueField","-1");
				descCompNameArr.add(descCompNameObj);
			}
			else
			{
				descCompNameObj = new JSONObject();
				descCompNameObj.put("displayField",_mapping.getTextDescription("admin.test.Select a component"));
				descCompNameObj.put("valueField","-1");
				descCompNameArr.add(descCompNameObj);
				Vector v_final = new Vector();
				for (int i=0;i<compList.length;i++)
				{
					String s_tmpFinal = (String) compList[i];
					String s_temp = s_tmpFinal.substring(s_tmpFinal.indexOf(":")+1);
					v_final.add(s_temp + "@" + s_tmpFinal);
				}
				Collections.sort(v_final,String.CASE_INSENSITIVE_ORDER);
				for(int i=0; i<v_final.size(); i++)
				{
					descCompNameObj = new JSONObject();
					String vectVal = (String) v_final.get(i);
					String dispVal =  vectVal.substring(0,vectVal.indexOf("@"));
					String optVal = vectVal.substring(vectVal.indexOf("@")+1);
					dispVal = Server.getServerNameWithoutPort(dispVal, false);
					descCompNameObj.put("displayField",dispVal);
					descCompNameObj.put("valueField",optVal);
					descCompNameArr.add(descCompNameObj);
					if(comp != null)
					{
						if(optVal.equals(comp))
						{
							rootJson.put("selectedCName",comp);
							continue;
						}
					}
				}
			}
		}
		rootJson.put("descCompNameArr",descCompNameArr);
		screenLabels.put("admin.test.Test",_mapping.getTextDescription("admin.test.Test"));

		if(server == null || server.length() == 0)
		{
			descTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			descTestNameObj.put("valueField","-1");
			descTestNameArr.add(descTestNameObj);
		}
		else
		{
			if((server !=null && !server.equalsIgnoreCase("null")) && (comp !=null && !comp.equalsIgnoreCase("null")) )
			{
				allTestArr = testConfSpecsBean.getTestList(server);
				if(allTestArr !=null && allTestArr.length > 0)
				{
					//Arrays.sort(allTestArr);
					for (int i=0;i<allTestArr.length;i++)
					{
						String testName = allTestArr[i].trim();
						if (!EgInstallInfo.isConfigTest(testName))
						{
							totalTests.add(testName);
						}
					}
					getTestsForServer = testConfSpecsBean.getCheckStatus(server);
					StringTokenizer enableTests = new StringTokenizer(getTestsForServer,",");
					while(enableTests.hasMoreTokens())
					{
						String enableTestName = enableTests.nextToken().trim();
						if (!EgInstallInfo.isConfigTest(enableTestName) && !enabledTests.contains(enableTestName))
						{
							enabledTests.add(enableTestName);
						}
					}
					disabledTests = (ArrayList)totalTests.clone();
					disabledTests.removeAll(enabledTests);
					//Collections.sort(totalTests);
					//Collections.sort(enabledTests);
					
					testParamBean.createFile("eg_disable.ini");
					String tmpComp = comp.substring(comp.indexOf(":")+1);
					String excludedTestForComp = testParamBean.getStrValue(server,server+":"+tmpComp);
					if (excludedTestForComp != null && !excludedTestForComp.equals(""))
					{
						StringTokenizer excludeCompTest =new StringTokenizer(excludedTestForComp,",");
						while (excludeCompTest.hasMoreTokens())
						{
							String excludeTestName = excludeCompTest.nextToken();
							excludeServerTestList.add(excludeTestName);
						}
					}
					String tmpCompForHost = comp.substring(comp.indexOf(":")+1);
					String excludedTestForHost = testParamBean.getStrValue("Default_server","Default_server"+":"+tmpCompForHost.substring(0,tmpCompForHost.indexOf(":")));
					if (excludedTestForHost != null && !excludedTestForHost.equals(""))
					{
						StringTokenizer excludeHostTest =new StringTokenizer(excludedTestForHost,",");
						while (excludeHostTest.hasMoreTokens())
						{
							String excludeHostTestName = excludeHostTest.nextToken();
							excludeHostTestList.add(excludeHostTestName);
						}
					}
					if(excludeHostTestList !=null && excludeHostTestList.size() > 0)
					{
						enabledTests.removeAll(excludeHostTestList);
					}
					if(excludeServerTestList != null && excludeServerTestList.size() > 0)
					{
						enabledTests.removeAll(excludeServerTestList);
					}
					for (int e=0;e < enabledTests.size(); e++)
					{
						String tmpTestName = (String)enabledTests.get(e);
						if(!specsInfo.isInfoRelevantForTest(tmpTestName,server))
						{
							notInfoBasedTests.add(tmpTestName);
						}
					}
				}
			}

			if(enabledTests == null || enabledTests.size() == 0)
			{
				descTestNameObj = new JSONObject();
				descTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
				descTestNameObj.put("valueField","-1");
				descTestNameArr.add(descTestNameObj);
			}
			else
			{
				descTestNameObj = new JSONObject();
				descTestNameObj.put("displayField",_mapping.getTextDescription("admin.test.Select a test"));
				descTestNameObj.put("valueField","-1");
				descTestNameArr.add(descTestNameObj);
				enabledTests = sorter.getSortedTestList(enabledTests);
				for (int i=0;i<enabledTests.size();i++)
				{
					descTestNameObj = new JSONObject();
					EgName nameObj = (EgName)enabledTests.get(i);
					String strTestName = nameObj.getActualName();
					String strTestDisplayValue = nameObj.getLocalName();
					descTestNameObj.put("displayField",strTestDisplayValue);
					descTestNameObj.put("valueField",strTestName);

					if(strTest != null)
					{
						if(strTestName.equals(strTest))
						{
							rootJson.put("selectedTestName",strTestName);
							continue;
						}
					}
					descTestNameArr.add(descTestNameObj);
				}
			}
		}
		rootJson.put("descTestNameArr",descTestNameArr);
		if((server == null || server.length() == 0) || (comp == null || comp.length() == 0) || (strTest == null || strTest.length() == 0))
		{
			disabled = "disabled";
			rootJson.put("disabled",disabled);
		}
	}
	else
	{
		descCompTypeObj = new JSONObject();
		descCompTypeObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
		descCompTypeObj.put("valueField","-1");
		descCompTypeArr.add(descCompTypeObj);

		rootJson.put("descCompTypeArr",descCompTypeArr);

		descCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
		descCompNameObj.put("valueField","-1");
		descCompNameArr.add(descCompNameObj);
		rootJson.put("descCompNameArr",descCompNameArr);

		descTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
		descTestNameObj.put("valueField","-1");
		descTestNameArr.add(descTestNameObj);
		rootJson.put("descTestNameArr",descTestNameArr);


		//rootJson.put("isNoData",true);
		//String noDataMsg = "<table><tr><td align='center' height='400'><table><tr><td align='center'><img src='/final/images/spacer.gif' class='iconInformation'></td></tr><tr><td align='center' class='commonErrorMsgText'>"+_mapping.getTextDescription("admin.test.No components have been managed")+".</td></tr></table></td></tr></table>";
		//rootJson.put("No_data",noDataMsg);
	}

	if(!StringUtils.isNull(comp) && !StringUtils.isNull(strTest))
	{
		rootJson.put("applyOtherComps",false);
		boolean isHostLevelTest = tablesInfo.isHostLevelTest(strTest);

		egDb=EgDbAdapterTypeUI.getObject();
		String status = egDb.setConnection();
		if(status.equals("CONNECTED"))
		{
			isConnected = true;
		}

		if(isConnected)
		{
			int ind = comp.indexOf(":");
			String compTy = comp.substring(0,ind);
			String compA = comp.substring(ind+1)+ ":" + comp.substring(0,ind);
			ind = compA.indexOf(":");
			String s_hostSysName = compA.substring(0, ind);
			if(uniqueHostSystemData && hash.containsKey(s_hostSysName))
				s_hostSysName =(String)hash.get(s_hostSysName);
			compB =s_hostSysName+ ":NULL:Host_system";
			String query;
			String measure_last_query="";
			EgDateInfo dateInfo = new EgDateInfo();
			java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date  now = dateInfo.egetRealDate();
			long nowdateandtime = now.getTime();
			nowdateandtime-=duration;
			String convertDate = dateInfo.egetDate(nowdateandtime);
			if(EgDbInfo.isSqlAdapter)
			{
				query = "SELECT distinct(info), test_name " +
				"FROM metatest WITH (NOLOCK) WHERE comp_name + ':' + comp_type in ('" + compA + "','"+compB+"') AND test_name='"+strTest+"'";
			}
			else
			{
				query = "SELECT distinct(info), test_name " +
				"FROM metatest WHERE comp_name || ':' || comp_type in ('" + compA + "','"+compB+"') AND test_name='"+strTest+"'";
			}

			Hashtable ht_measure_last = new Hashtable();
			ArrayList testAl = new ArrayList();
			ArrayList infoArrList = new ArrayList();
			ArrayList measure_last_test = new ArrayList();
			int j = 0;
			int q = 0;

			try
			{
				String nickName = compA.substring(0,compA.indexOf(":"));
				String port = "";
				if(compA.endsWith("Oracle_server"))
				{
					String msmtTemp = compA.substring(0,compA.indexOf(":Oracle_server"));
					port = msmtTemp.substring(msmtTemp.indexOf(":")+1,msmtTemp.lastIndexOf(":"));
				}
				else
				{
					port = compA.substring(compA.indexOf(":")+1,compA.lastIndexOf(":"));
				}
				rs = egDb.SelectExec(query);
				while(rs.next())
				{
					String test = rs.getString(2);	
					if(test.equals
						("WebSiteTransactionTest"))
						continue;
					if(test.equals
						("WebLogicEjbTest"))
						continue;
					if(test.equals
						("WsEjbTest"))
						continue;
					if(EgInstallInfo.isConfigTest(test))
						continue;
					String info = rs.getString(1);
					if(comp.startsWith("Oracle_server"))
					{
						ind = info.indexOf("+");
						info = info.substring(ind);
					}
					if(info.length() < 2)
						continue;
					j++;
					info = info.substring(1);
					infoArrList.add(info);
					int index = testAl.indexOf(test);
					if(index >= 0)
					{
						String temp = (String) ht.get(test);
						ht.put(test, temp+",  "+info);
						continue;
					}
					testAl.add(test);
					ht.put(test, info);
				}
				rs.close();
				if(duration > 0)
				{
					measure_last_query = egDb.getDetailsFromMeasureLast(nickName, port, strTest);
					rs1 = egDb.SelectExec(measure_last_query);
					while(rs1.next())
					{
						String test = rs1.getString(1);	
						String trgt_host = rs1.getString(2);	
						String port_no = rs1.getString(3);	
						if(test.equals
							("WebSiteTransactionTest"))
							continue;
						if(test.equals
							("WebLogicEjbTest"))
							continue;
						if(test.equals
							("WsEjbTest"))
							continue;
						if(EgInstallInfo.isConfigTest(test))
							continue;
						String info = rs1.getString(4);
						String sid = null;
						if(comp.startsWith("Oracle_server"))
						{
							ind = info.indexOf("+");
							sid = info.substring(0,ind);
							info = info.substring(ind);
						}
						if(info.length() < 2)
							continue;
						info = info.substring(1);
						if(!infoArrList.contains(info))
						{
							continue;
						}

						String msmt_time = rs1.getString(5);
						if(msmt_time.endsWith(".0"))
						{
							msmt_time = msmt_time.substring(0,msmt_time.lastIndexOf("."));
						}
						Date msmtDate =sdf.parse(msmt_time);

						long msmtDateandTime = msmtDate.getTime();
						if(nowdateandtime > msmtDateandTime)
							continue;

						String keyVal = "";
						if(sid !=null && sid.length() > 0)
						{
							keyVal = test+"~|~"+trgt_host+":"+port_no+":"+sid;
						}
						else
						{
							keyVal = test+"~|~"+trgt_host+":"+port_no;
						}
						int index = measure_last_test.indexOf(keyVal);
						if(index >= 0)
						{
							String newValue = "";
							String tempKeyVal = (String) ht_measure_last.get(keyVal);
							if(tempKeyVal.indexOf(",") == -1 && tempKeyVal.endsWith("~|~"+info))
							{
								Date existDate =sdf.parse(tempKeyVal.substring(0,tempKeyVal.indexOf("~|~")));
								long existDateandTime = existDate.getTime();
								if(existDateandTime > msmtDateandTime)
								{
									newValue = tempKeyVal;
								}
								else
								{
									newValue = msmt_time+"~|~"+info;
								}
								ht_measure_last.put(keyVal, newValue);
								continue;
							}
							else if(tempKeyVal.indexOf(",") != -1)
							{
								boolean isInfoMatch =false;
								StringTokenizer stVal = new StringTokenizer(tempKeyVal,",");
								while(stVal.hasMoreTokens())
								{
									String tempToken = (String) stVal.nextToken();
									if(tempToken.endsWith("~|~"+info))
									{
										isInfoMatch = true;
										Date existDate =sdf.parse(tempToken.substring(0,tempToken.indexOf("~|~")));
										long existDateandTime = existDate.getTime();
										if(existDateandTime > msmtDateandTime)
										{
											newValue +=","+tempToken;
										}
										else
										{
											newValue +=","+msmt_time+"~|~"+info;
										}
									}
									else
									{
										newValue +=","+tempToken;
									}
								}
								if(isInfoMatch)
								{
									newValue = newValue.substring(1);
									ht_measure_last.put(keyVal, newValue);
									continue;
								}
								else
								{
									newValue = newValue.substring(1);
									ht_measure_last.put(keyVal, newValue+","+msmt_time+"~|~"+info);
									continue;
								}
							}
							else
							{
								ht_measure_last.put(keyVal, tempKeyVal+","+msmt_time+"~|~"+info);
								continue;
							}
						}
						measure_last_test.add(keyVal);
						ht_measure_last.put(keyVal, msmt_time+"~|~"+info);
					}
					rs1.close();
				}
				egDb.releaseConnection(false);
				EgDbAdapterTypeUI.releaseObject(egDb);
			}
			catch(Exception e)
			{
				if(rs != null)
					rs.close();
				if(rs1 != null)
					rs1.close();
				egDb.releaseConnection(true);
				EgDbAdapterTypeUI.releaseObject(egDb);
			}
			
			String[] hostTests = specsInfo.getDefaultTestsForServer("Host_system");
			ArrayList tmpHostList = new ArrayList();
			if (hostTests != null)
			{
				tmpHostList = new ArrayList(Arrays.asList(hostTests));
			}

			boolean isHostSystemTest = tmpHostList.contains(strTest);
			if (strTest.endsWith("_ex") && !specsInfo.isPortRelevantForTest(strTest) )
			{
				isHostSystemTest = true;
			}
			if(comp.endsWith(":NULL"))
			{
				al = testInfo.getTestInfoFor(compA, server);
			}
			else
			{
				al = testInfo.getTestInfoFor(compA, server, isHostSystemTest);
			}
			for(int k=0; k<al.size(); k++)
			{
				String str = (String) al.get(k);
				int in = str.indexOf("=");
				String test = str.substring(0, in);
				if(test.equals("WebLogicEjbTest"))
					continue;
				if(test.equals("WsEjbTest"))
					continue;
				String info = str.substring(in + 1);
				info = getSpace(info);
				if(ht.containsKey(test))
				{
					String tempInfo = (String) ht.get(test);
					tempInfo = removeToken(tempInfo, info);
					ht.put(test, tempInfo + "0eGHash1" + info);
					continue;
				}
				ht.put(test, "0eGHash1" + info);
			}
			String[] arrDefaultTests = specsInfo.getDefaultTestsForServer(server);
			List defaultTestslist = new ArrayList();
				// Check whether the test is related to its serverType / compType
			if (arrDefaultTests != null)
			{
				defaultTestslist = Arrays.asList(arrDefaultTests); 
				String strKey = "";
				Enumeration enumHtKeys = ht.keys();
				while(enumHtKeys.hasMoreElements())
				{
					strKey =(String) enumHtKeys.nextElement();
					if(!defaultTestslist.contains(strKey))
					{
						ht.remove(strKey);
					}
				}
			}

			if(ht!=null && duration > 0)
			{
				Enumeration enumMeasureKeys = ht_measure_last.keys();
				while(enumMeasureKeys.hasMoreElements())
				{
					String strKeyMeasLast =(String) enumMeasureKeys.nextElement();
					String measTest = strKeyMeasLast.substring(0,strKeyMeasLast.indexOf("~|~"));
					String measCompType = strKeyMeasLast.substring(strKeyMeasLast.indexOf("~|~")+3);
					String sid = measCompType.substring(measCompType.indexOf(":")+1);
					String port = sid;
					if(!ht.containsKey(measTest) || !defaultTestslist.contains(measTest) || !compA.equalsIgnoreCase(measCompType))
					{
						String strNick = measCompType.substring(0,measCompType.indexOf(":"));
						measCompType +=":"+server;// measCompType
						String tempComp = strNick+":NULL:Host_system";
						if(!compA.equalsIgnoreCase(measCompType) && !compB.equalsIgnoreCase(tempComp))
						{
							ht_measure_last.remove(strKeyMeasLast);
							continue;
						}
						else if(sid.indexOf(":") != -1)
						{
							sid = sid.substring(sid.indexOf(":"))+":";
							if(compA.indexOf(sid) == -1)
							{
								ht_measure_last.remove(strKeyMeasLast);
								continue;
							}
						}
						if(!compA.equalsIgnoreCase(measCompType) || !compB.equalsIgnoreCase(tempComp))
						{
							if(port.indexOf(":") != -1)
							{
								port = port.substring(0,port.indexOf(":"));
							}
							if(specsInfo.isPortRelevantForTest(measTest) && port.equals("NULL"))
							{
								ht_measure_last.remove(strKeyMeasLast);
								continue;
							}
						}
					}
				}

				Iterator itrTempWithMeasTime =(ht_measure_last.keySet()).iterator();
				ArrayList aListTestsListWithMeasTime = new ArrayList();
				while(itrTempWithMeasTime.hasNext())
				{
					String tempTest = (String)itrTempWithMeasTime.next();
					aListTestsListWithMeasTime.add(tempTest);
				}
				for(int mt = 0;mt<aListTestsListWithMeasTime.size();mt++)
				{
					String strValMeasLast = (String) aListTestsListWithMeasTime.get(mt);
					String measLastTest = strValMeasLast.substring(0,strValMeasLast.indexOf("~|~"));
					if(ht.containsKey(measLastTest))
					{
						String tempTestValue = (String) ht_measure_last.get(strValMeasLast);
						ArrayList tempList = new ArrayList();
						if(tempTestValue.indexOf(",") != -1)
						{
							StringTokenizer st = new StringTokenizer(tempTestValue,",");
							while(st.hasMoreTokens())
							{
								String tempValue = (String) st.nextToken();
								tempList.add(tempValue);
							}
						}
						else
						{
							tempList.add(tempTestValue);
						}

						for(int i=0;i<tempList.size();i++)
						{
							String msmtInfo = (String) tempList.get(i);
							String msmt_info = msmtInfo.substring(msmtInfo.indexOf("~|~")+3);
							if(tempMeasureLast.containsKey(measLastTest))
							{
								String temp = (String) tempMeasureLast.get(measLastTest);
								tempMeasureLast.put(measLastTest,temp+",  "+msmt_info);
								continue;
							}
							tempMeasureLast.put(measLastTest,msmt_info);
						}
					}
				}

				ArrayList disabledAList = new ArrayList();
				if(comp.endsWith(":NULL"))
				{
					disabledAList = testInfo.getTestInfoFor(compA, server);
				}
				else
				{
					disabledAList = testInfo.getTestInfoFor(compA, server, isHostSystemTest);
				}
				for(int dis=0; dis<disabledAList.size(); dis++)
				{
					String disableData = (String) disabledAList.get(dis);
					int idx = disableData.indexOf("=");
					String disableTest = disableData.substring(0, idx);
					if(disableTest.equals("WebLogicEjbTest"))
						continue;
					if(disableTest.equals("WsEjbTest"))
						continue;
					String disableInfo = disableData.substring(idx + 1);
					disableInfo = getSpace(disableInfo);
					if(tempMeasureLast.containsKey(disableTest))
					{
						String tempDisableInfo = (String) tempMeasureLast.get(disableTest);
						tempDisableInfo = removeToken(tempDisableInfo, disableInfo);
						tempMeasureLast.put(disableTest, tempDisableInfo + "0eGHash1" + disableInfo);
						continue;
					}
					tempMeasureLast.put(disableTest, "0eGHash1" + disableInfo);
				}
			}

			if(duration > 0)   //for Any time period
			{
				ht = new Hashtable(tempMeasureLast);
			}
		}
	}

	String strEnableDesc = "";
	String strDisableDesc = "";
	ArrayList enableDescList = new ArrayList();
	ArrayList disableDescList = new ArrayList();
	if(ht != null && ht.size() > 0)
	{
		Iterator itr =(ht.keySet()).iterator();
		ArrayList hashTestKeys = new ArrayList();
		while(itr.hasNext())
		{
			String itrValue = (String) itr.next();
			hashTestKeys.add(itrValue);
		}
		if(hashTestKeys.contains(strTest))
		{
			String hashTestVals = (String) ht.get(strTest);
			
			int delim = hashTestVals.indexOf("0eGHash1");
			int sepLen = "0eGHash1".length();
			if(delim >= 0)
			{
				strEnableDesc = hashTestVals.substring(0, delim);
				strDisableDesc = hashTestVals.substring(delim+sepLen);
			}
			else
			{
				strEnableDesc = hashTestVals;
			}
			enableDescList = tokenizeInfo(strEnableDesc);
			disableDescList = tokenizeInfo(strDisableDesc);
			isNeedAvailDescSearchBox = (enableDescList != null && enableDescList.size() >= limit);
			isNeedDisableDescSearchBox = (disableDescList != null && disableDescList.size() >= limit);
		}

		Hashtable recentEnableValues = (Hashtable)session.getAttribute("recentEnableValues");
		if(recentEnableValues != null && recentEnableValues.size() > 0 )
		{
			Iterator itrRecent =(recentEnableValues.keySet()).iterator();
			ArrayList recentHashTestKeys = new ArrayList();
			while(itrRecent.hasNext())
			{
				String itrValue = (String) itrRecent.next();
				recentHashTestKeys.add(itrValue);
			}
			if(recentHashTestKeys.contains(strTest+":"+comp))
			{
				for(int re=0;re<recentHashTestKeys.size();re++)
				{
					String tmpRecentKey = (String) recentHashTestKeys.get(re);
					if(tmpRecentKey.equals(strTest+":"+comp))
					{
						List tmpRecentVal = (List) recentEnableValues.get(strTest+":"+comp);
						tmpRecentVal = removeDuplicates(tmpRecentVal);
						tmpHash.put(strTest,tmpRecentVal);
					}
				}
			}
		}
	}

	if (!StringUtils.isNull(server) && !StringUtils.isNull(comp) && !StringUtils.isNull(strTest) && enableDescList.isEmpty() && disableDescList.isEmpty() && tmpHash.isEmpty())
	{
		rootJson.put("No_descriptor",_mapping.getTextDescription("admin.test.No descriptors found for this test"));
	}
	else if(a_ComponentsType != null &&  a_ComponentsType.size() > 0 && !StringUtils.isNull(server) && !StringUtils.isNull(comp) && !StringUtils.isNull(strTest) )
	{
		if (requestFrom != null && requestFrom.equalsIgnoreCase("processUpdated"))
		{
			rootJson.put("requestFrom",requestFrom);
			rootJson.put("result_msg",_mapping.getTextDescription("admin.test.Changes have been updated successfully"));
		}
		if(isNeedAvailDescSearchBox)
		{
			rootJson.put("avail_desc_search","true");
		}

		if (!enableDescList.isEmpty() || !disableDescList.isEmpty())
		{
			boolean isHostLevelTest = tablesInfo.isHostLevelTest(strTest);

			Hashtable otherCompDetails = getOtherInfoComponentsFromMeasLast(server, comp, strTest, compList, isHostLevelTest, duration);
			if (otherCompDetails !=null && !otherCompDetails.isEmpty())
			{
				session.setAttribute("otherCompDetails",otherCompDetails);

				HashSet tmpCompsList = new HashSet();
				Iterator keys = otherCompDetails.keySet().iterator();
				while(keys.hasNext())
				{
					String strCompKey = (String) keys.next();
					if(strCompKey.startsWith(server))
					{
						String hashTestVals = (String) otherCompDetails.get(strCompKey);
						int delim = hashTestVals.indexOf("0eGHash1");
						int sepLen = "0eGHash1".length();

						String earlierDisableInfo = "";
						String strOtherInfos = "";
						if(delim >= 0)
						{
							strOtherInfos = hashTestVals.substring(0, delim);
							earlierDisableInfo = hashTestVals.substring(delim+sepLen);
						}
						else
						{
							strOtherInfos = hashTestVals;
						}

						ArrayList earlierDisableInfoList = tokenizeInfo(earlierDisableInfo);
						ArrayList otherInfosList = tokenizeInfo(strOtherInfos);
						if (enableDescList != null && !enableDescList.isEmpty())
						{
							otherInfosList.retainAll(enableDescList);
							if (otherInfosList != null && !otherInfosList.isEmpty())
							{
								tmpCompsList.add(strCompKey); //no break, looping entire hashtable
							}
						}

						if (disableDescList != null && !disableDescList.isEmpty())
						{
							earlierDisableInfoList.retainAll(disableDescList);
							if (earlierDisableInfoList != null && !earlierDisableInfoList.isEmpty())
							{
								tmpCompsList.add(strCompKey);
							}
						}
					}
				}

				if (tmpCompsList != null && !tmpCompsList.isEmpty())
				{
					rootJson.put("applyOtherComps",true);
				}
			}
		}

		JSONArray enableDescListArr = new JSONArray();
		JSONArray tmpEnableDescListArr = new JSONArray();
		JSONArray commonDescListArr = new JSONArray();
		Collections.sort(enableDescList,String.CASE_INSENSITIVE_ORDER);
		for (int i=0;i<enableDescList.size();i++)
		{
			JSONObject enableDescListObj = new JSONObject();
			String displayDesc = (String)enableDescList.get(i);
			checkEnabledDesc = checkEnabledDesc+","+displayDesc;
			enableDescListObj.put("displayField",displayDesc);
			enableDescListObj.put("valueField",displayDesc);
			enableDescListObj.put("groupField","");
			tmpEnableDescListArr.add(displayDesc);

			if(enableDescListObj != null && !enableDescListObj.isEmpty())
			{
				enableDescListArr.add(enableDescListObj);
				commonDescListArr.add(enableDescListObj);
			}
		}
		rootJson.put("enableDescListArr",enableDescListArr);
		//rootJson.put("enableDescListObj",tmpEnableDescListArr);
	
		if(isNeedDisableDescSearchBox)
		{
			rootJson.put("disable_desc_search","true");
		}
	
		screenLabels.put("admin.test.Disabled Descriptors",_mapping.getTextDescription("admin.test.Disabled Descriptors"));
		JSONArray disableDescListArr = new JSONArray();
		JSONArray tmpDisableDescListArr = new JSONArray();
		Collections.sort(disableDescList,String.CASE_INSENSITIVE_ORDER);
		for (int j=0;j<disableDescList.size();j++)
		{
			JSONObject disableDescListObj = new JSONObject();
			String displayDesc = (String)disableDescList.get(j);
			checkDisabledDesc = checkDisabledDesc+","+displayDesc;
			disableDescListObj.put("displayField",displayDesc);
			disableDescListObj.put("valueField",displayDesc);
			disableDescListObj.put("groupField","");

			tmpDisableDescListArr.add(displayDesc);

			if(disableDescListObj != null && !disableDescListObj.isEmpty())
			{
				disableDescListArr.add(disableDescListObj);
				commonDescListArr.add(disableDescListObj);
			}
		}

		rootJson.put("disableDescListArr",disableDescListArr);
		rootJson.put("disableDescListObj",tmpDisableDescListArr);
		if(disableDescList.size() > 0)
		{
			rootJson.put("enable_delete_btn","true");
		}
		if(tmpHash != null  && tmpHash.size() > 0)
		{
			JSONArray newEnableDescListArr = new JSONArray();
			JSONArray tmpNewEnableDescListArr = new JSONArray();
			if(tmpHash.containsKey(strTest))
			{
				newEnableDescList = (ArrayList) tmpHash.get(strTest);
				newEnableDescList.removeAll(enableDescList);
				newEnableDescList.removeAll(disableDescList);
				if(newEnableDescList != null && newEnableDescList.size() > 0)
				{
					if (enableDescList != null && enableDescList.size() > 0)
					{
						int newlyInfosSize = enableDescList.size() + newEnableDescList.size();
						isNeedAvailDescSearchBox = (newlyInfosSize >= limit);
						if(isNeedAvailDescSearchBox)
						{
							rootJson.put("avail_desc_search","true");
						}
					}

					String optGroupLabel = "";
					if(newEnableDescList.size() == 1)
					{
						optGroupLabel = "Recently enabled descriptor";
					}
					else
					{
						optGroupLabel = "Recently enabled descriptors";
					}
					Collections.sort(newEnableDescList,String.CASE_INSENSITIVE_ORDER);
					for (int nd=0;nd<newEnableDescList.size();nd++)
					{
						JSONObject newEnableDescListObj = new JSONObject();
						String displayNewDesc = (String) newEnableDescList.get(nd);
						newEnableDescListObj.put("displayField",displayNewDesc);
						newEnableDescListObj.put("valueField",displayNewDesc);
						newEnableDescListObj.put("groupField",optGroupLabel);
						tmpNewEnableDescListArr.add(displayNewDesc);
					
						if (newEnableDescListObj != null && !newEnableDescListObj.isEmpty())
						{
							//newEnableDescListArr.add(newEnableDescListObj);
							commonDescListArr.add(newEnableDescListObj);
							enableDescListArr.add(newEnableDescListObj);
						}
					}
				}
			}
			//rootJson.put("newEnableDescListArr",newEnableDescListArr);
			//rootJson.put("newEnableDescListObj",tmpNewEnableDescListArr);
		}

		if(!(checkEnabledDesc.equalsIgnoreCase("") || checkEnabledDesc.equalsIgnoreCase("null")))
		{
			if(checkEnabledDesc.startsWith(","))
			{
				checkEnabledDesc = checkEnabledDesc.substring(1,checkEnabledDesc.length());
			}
		}
		if(!(checkDisabledDesc.equalsIgnoreCase("") || checkDisabledDesc.equalsIgnoreCase("null")))
		{
			if(checkDisabledDesc.startsWith(","))
			{
				checkDisabledDesc = checkDisabledDesc.substring(1,checkDisabledDesc.length());
			}
		}
		rootJson.put("enableDescListArr",enableDescListArr);
		rootJson.put("commonDescListArr",commonDescListArr);
	}
	rootJson.put("checkEnabledDesc",checkEnabledDesc);
	rootJson.put("checkDisabledDesc",checkDisabledDesc);
	session.setAttribute("tempMeasureLast",tempMeasureLast);
	session.setAttribute("oldEnabledDescList",enableDescList);
	rootJson.put("screenLabels",screenLabels);
	out.println(rootJson.toString());
%>

<%!
	public ArrayList tokenizeInfo(String str)
	{
		ArrayList al = new ArrayList();
		StringTokenizer st = new StringTokenizer(str, ",");
		int count = st.countTokens();
		for(int i=0; i<count; i++)
		{
			al.add(st.nextToken().trim());
		}
		return al;
	}

	public String removeToken(String dbString, String fileString)
	{
		ArrayList dbAl = tokenizeInfo(dbString);
		ArrayList fileAl = tokenizeInfo(fileString);
		if(dbAl == null || dbAl.size() == 0)
			return dbString;
		if(fileAl == null || fileAl.size() == 0)
			return dbString;
		boolean changed = false;
		for(int i=0; i<dbAl.size(); i++)
		{
			String temp = (String) dbAl.get(i);
			if(fileAl.indexOf(temp) >= 0)
			{
				dbAl.remove(i);
				i--;
				changed = true;
			}
		}
		if(!changed)
			return dbString;
		String str = "";
		for(int i=0; i<dbAl.size(); i++)
		{
			str += (String) dbAl.get(i) + ", ";
		}
		if(str.length() > 1)
			str = str.substring(0, str.length()-2);
		return str;
	}

	public String getSpace(String str)
	{
		if(str == null || str.length() == 0)
			return "";
		StringTokenizer st = new StringTokenizer(str, ",");
		if(st.countTokens() == 0)
			return "";
		String temp = "";
		while(st.hasMoreTokens())
		{
			temp += st.nextToken() + ", ";
		}
		temp = temp.substring(0, temp.length()-2);
		return temp;
	}

	public Set getMetaTestInfos(Hashtable allData, String s_tmpFinal, String strTest, boolean isHostLevelTest)
	{
		Set result = new HashSet();
		
		if (allData == null || s_tmpFinal == null || strTest == null)
		{
			return result;
		}

		if (isHostLevelTest)
		{
			String strCompName = s_tmpFinal.substring(s_tmpFinal.indexOf(":")+1);
			s_tmpFinal = "Host_system:"+strCompName.substring(0,strCompName.indexOf(":"))+":NULL";
		}

		Hashtable compTestsData = (Hashtable) allData.get(s_tmpFinal);
		if (compTestsData != null && !compTestsData.isEmpty())
		{
			ArrayList testInfoList = (ArrayList) compTestsData.get(strTest);
			if (testInfoList == null || testInfoList.isEmpty())
			{
				return result;
			}

			for (int i=0;i<testInfoList.size();i=i+3)
			{
				String info = (String) testInfoList.get(i+1);

				if (info == null || info.length() < 2) 
				{
					continue;
				}
				info = info.substring(1);
				result.add(info);
			}
		}

		return result;
	}

	public Hashtable getOtherInfoComponentsFromMeasLast(String serverType, String selectedCompName, String strTest, String[] compList, boolean isHostLevelTest, long duration) throws SQLException
	{
		EgTestInfo testInfo = new EgTestInfo("manager");
		EgDateInfo dateInfo = new EgDateInfo();
		EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
		EgDbAdapterUI egDb;

		ResultSet rs1 = null;

		Hashtable result = new Hashtable();
		boolean isConnected = false;
		egDb=EgDbAdapterTypeUI.getObject();
		String status = egDb.setConnection();
		if(status.equals("CONNECTED"))
		{
			isConnected = true;
		}
		Hashtable allData = EgMetaThread.metaTest;

		String[] arrDefaultTests = specsInfo.getDefaultTestsForServer(serverType);
		List defaultTestslist = new ArrayList();
			// Check whether the test is related to its serverType / compType
		if (arrDefaultTests != null)
		{
			defaultTestslist = Arrays.asList(arrDefaultTests); 
		}

		Hashtable ht_measure_last = new Hashtable();
		ArrayList measure_last_test = new ArrayList();

		if(isConnected)
		{
			try
			{
				String query;
				String measure_last_query="";

				java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				Date  now = dateInfo.egetRealDate();
				long nowdateandtime = now.getTime();

				nowdateandtime-=duration;
				String convertDate = dateInfo.egetDate(nowdateandtime);
				String boundaryDate = sdf.format(nowdateandtime);

				if(EgDbInfo.isSqlAdapter)
				{
					measure_last_query = "SELECT test_name,trgt_host,port_no,info,msmt_time FROM measure_last WITH (NOLOCK) WHERE test_name='"+strTest+"' AND msmt_time >= '"+boundaryDate+"'";
				}
				else
				{
					measure_last_query = "SELECT test_name,trgt_host,port_no,info,msmt_time FROM measure_last WHERE test_name='"+strTest+"' AND msmt_time >= to_date ('"+boundaryDate+"','yyyy-MM-dd hh24:mi:ss')";
				}

				rs1 = egDb.SelectExec(measure_last_query);
				while(rs1.next())
				{
					String test = rs1.getString(1);	
					String trgt_host = rs1.getString(2);	
					String port_no = rs1.getString(3);	
					if(test.equals("WebSiteTransactionTest"))
						continue;
					if(test.equals("WebLogicEjbTest"))
						continue;
					if(test.equals("WsEjbTest"))
						continue;
					if(EgInstallInfo.isConfigTest(test))
						continue;

					String info = rs1.getString(4);
					String sid = null;
					if(serverType.startsWith("Oracle_server"))
					{
						int idx = info.indexOf("+");
						sid = info.substring(0,idx);
						info = info.substring(idx);
					}
					if(info.length() < 2)
						continue;
					info = info.substring(1);

					String msmt_time = rs1.getString(5);
					if(msmt_time.endsWith(".0"))
					{
						msmt_time = msmt_time.substring(0,msmt_time.lastIndexOf("."));
					}
					Date msmtDate =sdf.parse(msmt_time);
					long msmtDateandTime = msmtDate.getTime();

					String keyVal = "";
					if(sid !=null && sid.length() > 0)
					{
						keyVal = test+"~|~"+trgt_host+":"+port_no+":"+sid;
					}
					else
					{
						keyVal = test+"~|~"+trgt_host+":"+port_no;
					}
					int index = measure_last_test.indexOf(keyVal);

					if(index >= 0)
					{
						String newValue = "";
						String tempKeyVal = (String) ht_measure_last.get(keyVal);
						if(tempKeyVal.indexOf(",") == -1 && tempKeyVal.endsWith("~|~"+info))
						{
							Date existDate =sdf.parse(tempKeyVal.substring(0,tempKeyVal.indexOf("~|~")));
							long existDateandTime = existDate.getTime();
							if(existDateandTime > msmtDateandTime)
							{
								newValue = tempKeyVal;
							}
							else
							{
								newValue = msmt_time+"~|~"+info;
							}
							ht_measure_last.put(keyVal, newValue);
							continue;
						}
						else if(tempKeyVal.indexOf(",") != -1)
						{
							boolean isInfoMatch =false;
							StringTokenizer stVal = new StringTokenizer(tempKeyVal,",");
							while(stVal.hasMoreTokens())
							{
								String tempToken = (String) stVal.nextToken();
								if(tempToken.endsWith("~|~"+info))
								{
									isInfoMatch = true;
									Date existDate =sdf.parse(tempToken.substring(0,tempToken.indexOf("~|~")));
									long existDateandTime = existDate.getTime();
									if(existDateandTime > msmtDateandTime)
									{
										newValue +=","+tempToken;
									}
									else
									{
										newValue +=","+msmt_time+"~|~"+info;
									}
								}
								else
								{
									newValue +=","+tempToken;
								}
							}
							if(isInfoMatch)
							{
								newValue = newValue.substring(1);
								ht_measure_last.put(keyVal, newValue);
								continue;
							}
							else
							{
								newValue = newValue.substring(1);
								ht_measure_last.put(keyVal, newValue+","+msmt_time+"~|~"+info);
								continue;
							}
						}
						else
						{
							ht_measure_last.put(keyVal, tempKeyVal+","+msmt_time+"~|~"+info);
							continue;
						}
					}
					measure_last_test.add(keyVal);
					ht_measure_last.put(keyVal, msmt_time+"~|~"+info);
				}
				rs1.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
				//if(rs != null)
					//rs.close();
				//if(rs1 != null)
				//	rs1.close();
				//egDb.releaseConnection(true);
				//EgDbAdapterTypeUI.releaseObject(egDb);
			}
			finally
			{
				if(rs1 != null)
					rs1.close();
				egDb.releaseConnection(true);
				EgDbAdapterTypeUI.releaseObject(egDb);
			}
		}

	for (int i=0;i<compList.length;i++)
	{
		String s_tmpFinal = (String) compList[i];
		int ind = s_tmpFinal.indexOf(":");

		String s_temp = s_tmpFinal.substring(ind+1);
		String server = s_tmpFinal.substring(0,ind);

		String compA = s_tmpFinal.substring(ind+1)+ ":" + s_tmpFinal.substring(0,ind);
		String compB = s_temp.substring(0,s_temp.indexOf(":"))+ ":NULL:Host_system";

		if(s_tmpFinal.equals(selectedCompName))
		{
			continue;
		}

		Set metaTestInfos = getMetaTestInfos(allData, s_tmpFinal,strTest,isHostLevelTest);
		String qryCompType = server;
		String qryCompName = s_temp;
		if (isHostLevelTest)
		{
			qryCompType = "Host_system";
			qryCompName = qryCompName.substring(0,qryCompName.indexOf(":"))+":NULL";
		}

		String nickName = compA.substring(0,compA.indexOf(":"));
		String qryPort = "";
		if(compA.endsWith("Oracle_server"))
		{
			String msmtTemp = compA.substring(0,compA.indexOf(":Oracle_server"));
			qryPort = msmtTemp.substring(msmtTemp.indexOf(":")+1,msmtTemp.lastIndexOf(":"));
		}
		else
		{
			qryPort = compA.substring(compA.indexOf(":")+1,compA.lastIndexOf(":"));
		}

		if(ht_measure_last != null && !ht_measure_last.isEmpty())
		{
			Hashtable tempMeasureLast = new Hashtable();

			Enumeration enumMeasureKeys = ht_measure_last.keys();
			while(enumMeasureKeys.hasMoreElements())
			{
				String strKeyMeasLast =(String) enumMeasureKeys.nextElement();
				String measTest = strKeyMeasLast.substring(0,strKeyMeasLast.indexOf("~|~"));
				String measCompType = strKeyMeasLast.substring(strKeyMeasLast.indexOf("~|~")+3);
				String sid = measCompType.substring(measCompType.indexOf(":")+1);
				String port = sid;
				if (!strKeyMeasLast.endsWith("~|~"+qryCompName))
				{
					continue;
				}

				String tempTestValue = (String) ht_measure_last.get(strKeyMeasLast);
				ArrayList tempList = new ArrayList();
				if(tempTestValue.indexOf(",") != -1)
				{
					StringTokenizer st = new StringTokenizer(tempTestValue,",");
					while(st.hasMoreTokens())
					{
						String tempValue = (String) st.nextToken();
						tempList.add(tempValue);
					}
				}
				else
				{
					tempList.add(tempTestValue);
				}

				for(int in=0;in<tempList.size();in++)
				{
					String msmtInfo = (String) tempList.get(in);
					String msmt_info = msmtInfo.substring(msmtInfo.indexOf("~|~")+3);
					if(!metaTestInfos.contains(msmt_info))
					{
						continue;
					}

					if(tempMeasureLast.containsKey(measTest))
					{
						String temp = (String) tempMeasureLast.get(measTest);
						tempMeasureLast.put(measTest,temp+",  "+msmt_info);
						continue;
					}
					tempMeasureLast.put(measTest,msmt_info);
				}
			}

				ArrayList disabledAList = new ArrayList();
				if(s_tmpFinal.endsWith(":NULL"))
				{
					disabledAList = testInfo.getTestInfoFor(compA, server);
				}
				else
				{
					disabledAList = testInfo.getTestInfoFor(compA, server, isHostLevelTest);
				}
				for(int dis=0; dis<disabledAList.size(); dis++)
				{
					String disableData = (String) disabledAList.get(dis);
					int idx = disableData.indexOf("=");
					String disableTest = disableData.substring(0, idx);

					if(disableTest.equals("WebLogicEjbTest"))
						continue;
					if(disableTest.equals("WsEjbTest"))
						continue;

					if(!disableTest.equals(strTest))
						continue;
					String disableInfo = disableData.substring(idx + 1);
					disableInfo = getSpace(disableInfo);
					if(tempMeasureLast.containsKey(disableTest))
					{
						String tempDisableInfo = (String) tempMeasureLast.get(disableTest);
						tempDisableInfo = removeToken(tempDisableInfo, disableInfo);
						tempMeasureLast.put(disableTest, tempDisableInfo + "0eGHash1" + disableInfo);
						continue;
					}
					tempMeasureLast.put(disableTest, "0eGHash1" + disableInfo);
				}

				if(tempMeasureLast != null && !tempMeasureLast.isEmpty())   
				{
					result.put(s_tmpFinal,tempMeasureLast.get(strTest));
				}
			}
		}
		return result;
	}

	public List removeDuplicates(List list)
	{
		if (list==null)
			return list;
		Set myset = new HashSet(list);
		List list1 = new ArrayList(myset);
		return list1;
	}
%>
<%
	if(request.getQueryString()!=null)
		session.setAttribute("adminLastAccessedURL","/final/admin/EgTestInfoView.jsp?"+request.getQueryString());
	else
		session.setAttribute("adminLastAccessedURL","/final/admin/EgTestInfoView.jsp");
%>
