<%
/*
 *   File		:	EgExcludeComponents.jsp
 *   Purpose	:	Provides a mechanism to exclude components for a test
 *   Author		:	S.Anand (2009)
 *   UI Design	:	Jaiwin & Krishnamurthi
*/
%>

<%@ include file="../../EgTrackerAJSON.jsp" %>
<%@ page import="java.util.*" %>
<%@ page import="com.eg.EgRoleInfo" %>
<%@ page import="com.eg.EgExternalInfo" %>
<%@ page import="com.eg.EgSpecsInfo" %>
<%@ page import="com.eg.IniFile" %>
<%@ page import="com.eg.EgURLEncoder"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="com.eg.EgCompositeInfo"%>
<%@ page import="net.sf.json.*"%>

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

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

<%!
	EgExternalInfo egExternalInfo = new EgExternalInfo("manager");
	EgSpecsInfo egSpecs = new EgSpecsInfo("manager");

	//provide a set of agents(internal or remote agent,external agent(s)) for a component
	private List getAgents(String componentName)
	{
		List agentsList = new ArrayList();

		Hashtable internalAgentMap = egExternalInfo.getInternalAgentMap();
		String componentNickName = componentName.substring(0,componentName.indexOf(":"));
		String agentNickName = "";
		boolean isRemote = false;

		//To fetch the exact agent for the selected component - start
		isRemote = egExternalInfo.isRemoteBased(componentNickName);
		if (isRemote)
		{
			//Agentless
			agentNickName = egExternalInfo.getRemoteAgentForHost(componentNickName);
		}
		else
		{
			//Auto or Manual
			String agentName = egExternalInfo.getAgentFor(componentNickName);
			if (agentName != null) //Manual
			{
				if (internalAgentMap != null && internalAgentMap.containsKey(agentName))
				{
					agentNickName = (String)internalAgentMap.get(agentName);
				}
				else
				{
					agentNickName = agentName;
				}
			}
			else //Auto
			{
				agentNickName = componentNickName;
			}
		}

		//adding an internal agent (or) a remote agent
		agentsList.add(agentNickName);
		//To fetch the exact agent for the selected component - end

		//To fetch the external agent for the selected component type - starts
		boolean hasExternalAgent = egExternalInfo.hasExternalAgent(componentNickName);
		if (hasExternalAgent)
		{
			String extAgents[] = egExternalInfo.getExternalAgentsForHost(componentNickName);
			//adding one or more external agent(s)
			agentsList.addAll(Arrays.asList(extAgents));
		}
		//To fetch the external agent for the selected component type - ends

		return agentsList;
	}

	//Will provide the right agent (subject) for a component and its test
	private String getAgentNickName(String componentType,String componentName,String testName)
	{
		boolean isExternalTest = egSpecs.isExternalTest(testName,componentType);
		List aListTempAgentsForComponent = getAgents(componentName);
		String agentName = null;
		if (isExternalTest)
		{
			//external agent for external test
			agentName = (String)aListTempAgentsForComponent.get(1);
		}
		else
		{
			//internal agent or remote agent for host level test and application level test.
			agentName = (String)aListTempAgentsForComponent.get(0);
		}

		return agentName;
	}

	//Will provide the right pattern (variable) for a component
	private String getResultantPattern(String componentType,String componentName,String testName,String[] testVariables)
	{
		String tempResultantPattern = null;
		String componentNickName = componentName.substring(0,componentName.indexOf(":"));

		String specificPattern_A = testName + ":" + componentType + ":" + componentName;
		String specificPattern_B = testName + ":" + componentType + ":" + componentNickName;
		String defaultPattern_A = testName + "::" + componentName;
		String defaultPattern_B = testName + "::" + componentNickName;

		List listTestVariables = Arrays.asList(testVariables);
		if(listTestVariables.contains(specificPattern_A))
		{
			tempResultantPattern = specificPattern_A;
		}
		else if(listTestVariables.contains(specificPattern_B))
		{
			tempResultantPattern = specificPattern_B;
		}
		else if(listTestVariables.contains(defaultPattern_A))
		{
			tempResultantPattern = defaultPattern_A;
		}
		else if(listTestVariables.contains(defaultPattern_B))
		{
			tempResultantPattern = defaultPattern_B;
		}

		return tempResultantPattern;
	}

	public boolean hasUnConfiguredParam(String paramValue)
	{
		boolean hasUnconfiguredParam = false;
		StringTokenizer st = new StringTokenizer(paramValue,",");
		st.nextToken();
		StringTokenizer st1 = new StringTokenizer(st.nextToken());
		ArrayList aListParamNameValue = new ArrayList();

		StringBuffer eachStr = null;
		while(st1.hasMoreTokens())
		{
			String token = st1.nextToken();
			token = token.trim();
			if (token.startsWith("-"))
			{
				if (eachStr!=null && eachStr.toString().length()>0)
				{
					aListParamNameValue.add((eachStr.toString()).substring(0,(eachStr.toString()).length()-1));
				}
				aListParamNameValue.add(token.toLowerCase());
				eachStr = new StringBuffer();
			}
			else
			{
				eachStr.append(token + " ");
			}
		}
		aListParamNameValue.add((eachStr.toString()).trim());

		String snmpVersion = null;
		boolean isSnmp = aListParamNameValue.contains("-snmpversion");

		if (isSnmp)
		{
			//put snmp version before snmp community.
			int snmpCommunityIdx = aListParamNameValue.indexOf("-snmpcommunity");
			String snmpCommunityVal = (String)aListParamNameValue.get(snmpCommunityIdx+1);
			aListParamNameValue.remove(snmpCommunityIdx);
			aListParamNameValue.remove(snmpCommunityIdx);

			int snmpVerIdx = aListParamNameValue.indexOf("-snmpversion");
			snmpVersion = (String)aListParamNameValue.get(snmpVerIdx+1);

			aListParamNameValue.add(snmpVerIdx+2,"-snmpcommunity");
			aListParamNameValue.add(snmpVerIdx+3,snmpCommunityVal);
		}

		for (int i=0;i<aListParamNameValue.size();i=i+2)
		{
			String strParamName = (String)aListParamNameValue.get(i);
			String strParamValue = (String)aListParamNameValue.get(i+1);

			if (strParamName.equalsIgnoreCase("-password") || 
				strParamName.equalsIgnoreCase("-proxypassword") || 
				strParamName.equalsIgnoreCase("-authpass") || 
				strParamName.equalsIgnoreCase("-encryptpassword") || 
				strParamName.equalsIgnoreCase("-admin_password") || 
				strParamName.equalsIgnoreCase("-vc_password") || 
				strParamName.equalsIgnoreCase("-esx_password") || 
				strParamName.equalsIgnoreCase("-sendpassword") || 
				strParamName.equalsIgnoreCase("-receivepassword") || 
				strParamName.equalsIgnoreCase("-xen_password") || 
				strParamName.equalsIgnoreCase("-From_User_Password"))
			{
				continue;
			}

			if (isSnmp && snmpVersion != null)
			{
				if (snmpVersion.equalsIgnoreCase("v3"))
				{
					if (strParamName.equalsIgnoreCase("-snmpcommunity"))
					{
						continue;
					}
				}
			}

			strParamValue = strParamValue.trim();
			if (strParamValue.startsWith("$"))
			{
				hasUnconfiguredParam = true;
				break;
			}
		}

		return hasUnconfiguredParam;
	}
%>

<%
	IniFile mgrmiscIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_mgrmisc.ini");
	String componentsLimit = mgrmiscIni.getValue("MISC_ARGS","IncludeExcludeComponentsLimit");
	int limit = 100;
	if (!StringUtils.isNull(componentsLimit))
	{
		limit = Integer.parseInt(componentsLimit);
	}

	String showUnconfigCompType = request.getParameter("showUnconfigCompType");
	showUnconfigCompType = (showUnconfigCompType == null)?"false":showUnconfigCompType;
	ArrayList filterUnconfigCompList = new ArrayList();
	String enableConfTestSize = request.getParameter("enableConfTestSize");
	EgRoleInfo ri = EgRoleInfo.getInstance(session.getId(),(String)session.getAttribute("sess_userid"));

	String componentType = request.getParameter("componentType");
	String componentName = request.getParameter("componentName");
	String testForExclusion = request.getParameter("TestsForExclusion");

	String testType = request.getParameter("testType");
	testType = testType != null?testType:"PerformanceTest";

	String[] strComponents = ri.getAllServersOfType(componentType);
	List listComponents = Arrays.asList(strComponents);
	String currentComponentPattern = componentType + ":" + componentName;
	//String query = "";
	//Scenario : Only one component is managed.
	rootJson.put("hasMoreComponents",true);
	if ((listComponents.size() == 1 && listComponents.contains(currentComponentPattern)) || (listComponents.size() > limit))
	{
		rootJson.put("hasMoreComponents",false);
		//query = "EgExcludeComponentTests.jsp?componentType="+EgURLEncoder.encode(componentType,"UTF-8")+"&componentName="+EgURLEncoder.encode(componentName,"UTF-8")+"&TestsForExclusion="+EgURLEncoder.encode(testForExclusion,"UTF-8")+"&testType="+EgURLEncoder.encode(testType,"UTF-8");
	}

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

	String pageRefreshed = request.getParameter("pageRefreshed");
	boolean isPageRefreshed = false;
	if (pageRefreshed == null)
	{
		pageRefreshed = "false";
	}
	else
	{
		pageRefreshed = "true";
		isPageRefreshed = true;
	}

	LinkedHashMap superHt = new LinkedHashMap();
	LinkedHashMap innerHt = new LinkedHashMap();
	IniFile compositeInfo = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_composite.ini");
	String variables2[] = compositeInfo.getVariables("COMPOSITE_TEST_INFOS_EXCLUDED");

	Vector v1=new Vector();
	Vector v2=null;
	int excludeInfosCount=0;
	IniFile aggIni = null;
	String excludedInfos[] = null;
	if(componentType.startsWith("Agg_"))
	{
		aggIni = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_aggregate.ini");
		excludedInfos = aggIni.getVariables("AGGREGATE_TEST_INFOS_EXCLUDED");
		v2=new Vector();
		excludeInfosCount=(excludedInfos != null)?excludedInfos.length:0;
	}
	ArrayList aListTests = new ArrayList();
	StringTokenizer st = new StringTokenizer(testForExclusion,",");
	while (st.hasMoreTokens())
	{
		String temp = st.nextToken();
		aListTests.add(temp);
		if(variables2 != null)
		{
			int varCount=variables2.length;
			String key = temp + ":";
			for(int i=0;i<varCount;i++)
			{
				String var = variables2[i];
				if(var.startsWith(key))
				{
					String compComp = var.substring(var.indexOf(":")+1);
					String compCompType = compComp.substring(0,compComp.indexOf(":"));
					compComp = compComp.substring(compComp.indexOf(":")+1,compComp.indexOf("#"));
					if(componentType.equals(compCompType))
					{
						if(componentType.equals(compComp))
						{
							v1.add(var);
							innerHt.put(var,"");
						}
					}
				}
			}
		}
		if(excludedInfos != null)
		{
			String key = temp + ":"+componentType+":"+componentName;
			for(int i=0;i<excludeInfosCount;i++)
			{
				String var = excludedInfos[i];
				if(var.startsWith(key))
				{
					v2.add(var);
				}
			}
		}
	}
	if(!v1.isEmpty())
	{	
		compositeInfo.deleteValues("COMPOSITE_TEST_INFOS_EXCLUDED",v1);
		compositeInfo.saveFile();
	}
	EgConfigFilesSync.releaseInstance(compositeInfo);
	if(aggIni != null)
	{
		if(!v2.isEmpty())
		{
			aggIni.deleteValues("AGGREGATE_TEST_INFOS_EXCLUDED",v2);
			aggIni.saveFile();
		}
		EgConfigFilesSync.releaseInstance(aggIni);
	}
	if(EgInstallInfo.isClusterSupported && !innerHt.isEmpty())
	{
		superHt.put("COMPOSITE_TEST_INFOS_EXCLUDED",innerHt);
		Vector vec = new Vector();
		vec.add(superHt);
		new com.eg.UpdateAndTransmitICInfo().updateCompositeIni(vec);
	}
	ArrayList aListChoosenManagedComps = new ArrayList();
	boolean hasManagedComp = false;
	String managed = null;
	String unmanaged = null;
	if (pageRefreshed != null && pageRefreshed.equals("true"))
	{
		componentName = request.getParameter("mainComponentName");

		managed = request.getParameter("strManage");
		unmanaged = request.getParameter("strunManage");

		if (managed != null && managed.length() > 0)
		{
			hasManagedComp = true;
			StringTokenizer stComponents = new StringTokenizer(managed,",");
			while (stComponents.hasMoreTokens())
			{
				String eachComponent = stComponents.nextToken();
				if (!aListChoosenManagedComps.contains(eachComponent))
				{
					aListChoosenManagedComps.add(eachComponent);
				}
			}
		}
	}
	else
	{
		hasManagedComp = true;
		for (int i=0;i<aListTests.size();i++)
		{
			String strTest = (String)aListTests.get(i);
			aListChoosenManagedComps.add(componentName);
		}
	}

	IniFile agentIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_agents.ini");
	ArrayList aListTempComponents = new ArrayList(listComponents);
	if (!StringUtils.isNull(showUnconfigCompType) && showUnconfigCompType.equals("true"))
	{
		filterUnconfigCompList = (ArrayList) session.getAttribute("unconfigCompList");
		if (filterUnconfigCompList != null && filterUnconfigCompList.size() > 0)
		{
			if (aListTempComponents != null && aListTempComponents.size() > 0)
			{
				for(int i=0;i<aListTempComponents.size();i++)
				{
					String tempUnconfigComp = (String) aListTempComponents.get(i);
					if (!filterUnconfigCompList.contains(tempUnconfigComp))
					{
						filterUnconfigCompList.remove(tempUnconfigComp);
					}
				}
			}
			aListTempComponents = filterUnconfigCompList;
		}
	}
	TreeMap tmapIncludedComps = null;
	TreeMap tmapCompsToBeExcluded = null;
	if (isPageRefreshed)
	{
		if (managed != null && managed.length() > 0)
		{
			tmapCompsToBeExcluded = new TreeMap();
			StringTokenizer st1 = new StringTokenizer(managed,",");
			while (st1.hasMoreTokens())
			{
				String str = st1.nextToken();
				int hashIdx = str.indexOf("#");
				String strComponent = str.substring(0,hashIdx);
				String strTest = str.substring(hashIdx+1);
				boolean isCompUnconfigured=false;
				if (strTest.indexOf("$") > -1)
				{
					strTest = strTest.substring(0,strTest.indexOf("$"));
					isCompUnconfigured = true;
				}
				ArrayList aListResultant = (ArrayList)tmapCompsToBeExcluded.get(strTest);
				if (aListResultant == null)
				{
					ArrayList aListUnConfiguredComps = null;
					ArrayList aListConfiguredComps = null;

					if (isCompUnconfigured)
					{
						aListUnConfiguredComps = new ArrayList();
						aListUnConfiguredComps.add(strComponent);
					}
					else
					{
						aListConfiguredComps = new ArrayList();
						aListConfiguredComps.add(strComponent);
					}

					aListResultant = new ArrayList();
					aListResultant.add(aListUnConfiguredComps);
					aListResultant.add(aListConfiguredComps);

					tmapCompsToBeExcluded.put(strTest,aListResultant);
				}
				else
				{
					if (isCompUnconfigured)
					{
						ArrayList aListUnConfiguredComps = (ArrayList)aListResultant.get(0);
						if (aListUnConfiguredComps == null)
						{
							aListResultant.remove(0);//remove the null reference
							aListUnConfiguredComps = new ArrayList();
							aListResultant.add(0,aListUnConfiguredComps);
						}
						aListUnConfiguredComps.add(strComponent);
					}
					else
					{
						ArrayList aListConfiguredComps = (ArrayList)aListResultant.get(1);
						if (aListConfiguredComps == null)
						{
							aListResultant.remove(1);//remove the null reference
							aListConfiguredComps = new ArrayList();
							aListResultant.add(1,aListConfiguredComps);
						}
						aListConfiguredComps.add(strComponent);
					}
				}
			}
		}

		if (unmanaged != null && unmanaged.length() > 0)
		{
			tmapIncludedComps = new TreeMap();
			StringTokenizer st2 = new StringTokenizer(unmanaged,",");
			while (st2.hasMoreTokens())
			{
				String str = st2.nextToken();
				int hashIdx = str.indexOf("#");
				String strComponent = str.substring(0,hashIdx);
				String strTest = str.substring(hashIdx+1);
				boolean isCompUnconfigured=false;
				if (strTest.indexOf("$") > -1)
				{
					strTest = strTest.substring(0,strTest.indexOf("$"));
					isCompUnconfigured = true;
				}
				ArrayList aListResultant = (ArrayList)tmapIncludedComps.get(strTest);
				if (aListResultant == null)
				{
					ArrayList aListUnConfiguredComps = null;
					ArrayList aListConfiguredComps = null;

					if (isCompUnconfigured)
					{
						aListUnConfiguredComps = new ArrayList();
						aListUnConfiguredComps.add(strComponent);
					}
					else
					{
						aListConfiguredComps = new ArrayList();
						aListConfiguredComps.add(strComponent);
					}

					aListResultant = new ArrayList();
					aListResultant.add(aListUnConfiguredComps);
					aListResultant.add(aListConfiguredComps);

					tmapIncludedComps.put(strTest,aListResultant);
				}
				else
				{
					if (isCompUnconfigured)
					{
						ArrayList aListUnConfiguredComps = (ArrayList)aListResultant.get(0);
						if (aListUnConfiguredComps == null)
						{
							aListResultant.remove(0);//remove the null reference
							aListUnConfiguredComps = new ArrayList();
							aListResultant.add(0,aListUnConfiguredComps);
						}
						aListUnConfiguredComps.add(strComponent);
					}
					else
					{
						ArrayList aListConfiguredComps = (ArrayList)aListResultant.get(1);
						if (aListConfiguredComps == null)
						{
							aListResultant.remove(1);//remove the null reference
							aListConfiguredComps = new ArrayList();
							aListResultant.add(1,aListConfiguredComps);
						}
						aListConfiguredComps.add(strComponent);
					}
				}
			}
		}
	}
	else
	{
		//ensure whether there are more than one components to be excluded.if not donot show this page
		boolean hasMoreThanOneCompToExcl = false;
		int compCount=0;
		int prevCompIdx=-1;
		for (int i=0;i<aListTests.size();i++)
		{
			String strTest = (String)aListTests.get(i);

			ArrayList aListStrUnconfiguredComponents = null;
			ArrayList aListStrConfiguredComponents = null;

			for (int j=0;j<aListTempComponents.size();j++)
			{
				String strTempPattern = (String)aListTempComponents.get(j);
				String tempComponent = strTempPattern.substring(strTempPattern.indexOf(":")+1);
				String tempAgentNickName = getAgentNickName(componentType,tempComponent,strTest);
				String[] tempTestVariables = agentIni.getVariables(tempAgentNickName);
				String tempResultantPattern = getResultantPattern(componentType,tempComponent,strTest,tempTestVariables);
				if (tempResultantPattern == null) continue;
				String tempTestValue = agentIni.getValue(tempAgentNickName,tempResultantPattern);

				if (tempTestValue.indexOf("-auto") > -1 && 
					tempTestValue.indexOf(" $") > -1 && 
					hasUnConfiguredParam(tempTestValue))
				{
					if (!hasMoreThanOneCompToExcl)
					{
						if (prevCompIdx == -1)
						{
							compCount++;
						}
						else
						{
							if (j != prevCompIdx)
							{
								compCount++;
							}
						}
						prevCompIdx=j;

						if (compCount > 1)
						{
							hasMoreThanOneCompToExcl = true;
						}
					}

					if (!tempComponent.equals(componentName))
					{
						if (aListStrUnconfiguredComponents == null)
						{
							aListStrUnconfiguredComponents = new ArrayList();
						}

						aListStrUnconfiguredComponents.add(tempComponent);
					}
				}
				else if (tempTestValue.indexOf("-auto") > -1 || tempTestValue.indexOf("-manual") > -1)
				{
					if (!hasMoreThanOneCompToExcl)
					{
						if (prevCompIdx == -1)
						{
							compCount++;
						}
						else
						{
							if (j != prevCompIdx)
							{
								compCount++;
							}
						}
						prevCompIdx=j;

						if (compCount > 1)
						{
							hasMoreThanOneCompToExcl = true;
						}
					}

					if (!tempComponent.equals(componentName))
					{
						if (aListStrConfiguredComponents == null)
						{
							aListStrConfiguredComponents = new ArrayList();
						}
						aListStrConfiguredComponents.add(tempComponent);
					}
				}
			}

			if (aListStrUnconfiguredComponents != null || 
				aListStrConfiguredComponents != null)
			{
				ArrayList aListResultant = new ArrayList();
				aListResultant.add(aListStrUnconfiguredComponents);
				aListResultant.add(aListStrConfiguredComponents);
				if (tmapIncludedComps == null)
				{
					tmapIncludedComps = new TreeMap();
				}
				tmapIncludedComps.put(strTest,aListResultant);
			}
		}

		//has only one to component to exclude
		//if (!hasMoreThanOneCompToExcl)
		//{
			//query = "EgExcludeComponentTests.jsp?componentType="+EgURLEncoder.encode(componentType,"UTF-8")+"&componentName="+EgURLEncoder.encode(componentName,"UTF-8")+"&TestsForExclusion="+EgURLEncoder.encode(testForExclusion,"UTF-8")+"&testType="+EgURLEncoder.encode(testType,"UTF-8");
		//}
		rootJson.put("hasMoreThanOneCompToExcl",hasMoreThanOneCompToExcl);
	}

	if (!isPageRefreshed)
	{
		tmapCompsToBeExcluded = new TreeMap();
		for (int i=0;i<aListTests.size();i++)
		{
			String strTest = (String)aListTests.get(i);
			ArrayList aListTempUnconfiguredComponents = null;
			ArrayList aListTempconfiguredComponents = null;
			if (excludingState.equals("unconfiguredstate"))
			{
				aListTempUnconfiguredComponents = new ArrayList();
				aListTempUnconfiguredComponents.add(componentName);
			}
			else if (excludingState.equals("configuredstate"))
			{
				aListTempconfiguredComponents = new ArrayList();
				aListTempconfiguredComponents.add(componentName);
			}

			ArrayList aListTempResultant = new ArrayList();
			aListTempResultant.add(aListTempUnconfiguredComponents);
			aListTempResultant.add(aListTempconfiguredComponents);

			tmapCompsToBeExcluded.put(strTest,aListTempResultant);
		}
	}

	JSONArray selectedTestsArr = new JSONArray();
	JSONObject selectedTestsActualNameObj = new JSONObject();

	int d=0;
	while(d<aListTests.size())
	{
		JSONObject selectedTestsObj = new JSONObject();
		String strTestName1 = "";
		String strTestName2 = "";
		String strTestName = (String)aListTests.get(d);
		int count = d;
		if(!StringUtils.isNull(strTestName))
		{
			selectedTestsActualNameObj.put( _mapping.getTestDescription(strTestName),strTestName);
			strTestName = _mapping.getTestDescription(strTestName);
		}
		else
			strTestName = "";
		count = d+1;
		if(count < aListTests.size())
		{
			strTestName1 = (String)aListTests.get(count);
			if(!StringUtils.isNull(strTestName1))
			{
				selectedTestsActualNameObj.put(_mapping.getTestDescription(strTestName1),strTestName1);
				strTestName1 = _mapping.getTestDescription(strTestName1);
			}
		}
		count = d+2;
		if(count < aListTests.size())
		{
			strTestName2 = (String)aListTests.get(count);
			if(!StringUtils.isNull(strTestName2))
			{
				selectedTestsActualNameObj.put(_mapping.getTestDescription(strTestName2),strTestName2);
				strTestName2 = _mapping.getTestDescription(strTestName2);
			}
		}

		selectedTestsObj.put("Test1",strTestName);
		selectedTestsObj.put("Test2",strTestName1);
		selectedTestsObj.put("Test3",strTestName2);
		selectedTestsArr.add(selectedTestsObj);
		d = count+1;
	}
	rootJson.put("selectedTestsActualNameObj",selectedTestsActualNameObj);
	rootJson.put("selectedTestsArr",selectedTestsArr);
	rootJson.put("fieldTitleComponentType",_mapping.getComponentTypeDescription(componentType)+"&nbsp;components");

	if (tmapCompsToBeExcluded != null)
	{
		JSONArray excludeComponentsArr = new JSONArray();
		JSONObject excludeComponentsObj = new JSONObject();

		for (int i=0;i<aListTests.size();i++)
		{
			String strTest = (String)aListTests.get(i);
			ArrayList aListResultant = (ArrayList)tmapCompsToBeExcluded.get(strTest);
			if (aListResultant != null)
			{
				ArrayList aListUnConfiguredComps = (ArrayList)aListResultant.get(0);
				ArrayList aListConfiguredComps = (ArrayList)aListResultant.get(1);

				if (aListUnConfiguredComps != null)
				{
					Collections.sort(aListUnConfiguredComps,String.CASE_INSENSITIVE_ORDER);
					String strLabel =_mapping.getTestDescription(strTest) + " - " +  "Unconfigured component(s)";
					for (int j=0;j<aListUnConfiguredComps.size();j++)
					{
						String strComp = (String)aListUnConfiguredComps.get(j);
						String strDispComp = null;
						if (strComp.indexOf(":NULL") > -1)
						{
							strDispComp = strComp.substring(0,strComp.indexOf(":"));
						}
						else
						{
							strDispComp = strComp;
						}
						excludeComponentsObj.put("valueField",strComp+"#"+strTest+"$");
						excludeComponentsObj.put("displayField",strDispComp);
						excludeComponentsObj.put("groupField",strLabel);

						excludeComponentsArr.add(excludeComponentsObj);
					}
				}

				if (aListConfiguredComps != null)
				{
					Collections.sort(aListConfiguredComps,String.CASE_INSENSITIVE_ORDER);
					String strLabel =_mapping.getTestDescription(strTest) + " - " +  "Configured component(s)";
					for (int j=0;j<aListConfiguredComps.size();j++)
					{
						String strComp = (String)aListConfiguredComps.get(j);
						String strDispComp = null;
						if (strComp.indexOf(":NULL") > -1)
						{
							strDispComp = strComp.substring(0,strComp.indexOf(":"));
						}
						else
						{
							strDispComp = strComp;
						}
						excludeComponentsObj.put("valueField",strComp+"#"+strTest);
						excludeComponentsObj.put("displayField",strDispComp);
						excludeComponentsObj.put("groupField",strLabel);
						excludeComponentsArr.add(excludeComponentsObj);
					}
				}
			}
		}
		rootJson.put("excludeComponentsArr",excludeComponentsArr);
	}

	if (tmapIncludedComps != null)
	{
		JSONArray includeComponentsArr = new JSONArray();
		JSONObject includeComponentsObj = new JSONObject();
		for (int i=0;i<aListTests.size();i++)
		{
			String strTest = (String)aListTests.get(i);
			ArrayList aListResultant = (ArrayList)tmapIncludedComps.get(strTest);
			if (aListResultant != null)
			{
				ArrayList aListUnConfiguredComps = (ArrayList)aListResultant.get(0);
				ArrayList aListConfiguredComps = (ArrayList)aListResultant.get(1);

				if (aListUnConfiguredComps != null)
				{
					Collections.sort(aListUnConfiguredComps,String.CASE_INSENSITIVE_ORDER);
					String strLabel =_mapping.getTestDescription(strTest) + " - " +  "Unconfigured component(s)";
					for (int j=0;j<aListUnConfiguredComps.size();j++)
					{
						String strComp = (String)aListUnConfiguredComps.get(j);
						String strDispComp = null;
						if (strComp.indexOf(":NULL") > -1)
						{
							strDispComp = strComp.substring(0,strComp.indexOf(":"));
						}
						else
						{
							strDispComp = strComp;
						}
						includeComponentsObj.put("valueField",strComp+"#"+strTest+"$");
						includeComponentsObj.put("displayField",strDispComp);
						includeComponentsObj.put("groupField",strLabel);
						includeComponentsArr.add(includeComponentsObj);
					}
				}

				if (aListConfiguredComps != null)
				{
					Collections.sort(aListConfiguredComps,String.CASE_INSENSITIVE_ORDER);
					String strLabel =_mapping.getTestDescription(strTest) + " - " +  "Configured component(s)";
					for (int j=0;j<aListConfiguredComps.size();j++)
					{
						String strComp = (String)aListConfiguredComps.get(j);
						String strDispComp = null;
						if (strComp.indexOf(":NULL") > -1)
						{
							strDispComp = strComp.substring(0,strComp.indexOf(":"));
						}
						else
						{
							strDispComp = strComp;
						}
						includeComponentsObj.put("valueField",strComp+"#"+strTest);
						includeComponentsObj.put("displayField",strDispComp);
						includeComponentsObj.put("groupField",strLabel);
						includeComponentsArr.add(includeComponentsObj);

					}
				}
			}
		}
		rootJson.put("includeComponentsArr",includeComponentsArr);
	}
	hiddenObj.put("componentType",componentType);
	hiddenObj.put("mainComponentName",componentName);
	hiddenObj.put("testType",testType);
	hiddenObj.put("TestsForExclusion",testForExclusion);
	hiddenObj.put("showPopup",request.getParameter("showPopup"));
	hiddenObj.put("pageRefreshed","true");
	hiddenObj.put("enableConfTestSize",enableConfTestSize);
	rootJson.put("showUnconfigCompType",showUnconfigCompType);
	rootJson.put("hiddenObjExcludePage",hiddenObj);

	out.println(rootJson.toString());

%>




