<%@ include file = "../../EgTrackerAJSON.jsp" %>
<%@ page import="net.sf.json.*"%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "egurkha.*" %>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import = "com.eg.EgName" %>
<%@ page import = "com.eg.IniFile" %>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "com.eg.EgRoleInfo" %>
<%@ page import = "com.eg.EgSpecsInfo" %>
<%@ page import = "com.eg.EgTesterInfo" %>
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.EgThresholdInfo" %>
<%@ page import = "com.eg.MappingNameSorter" %>
<%@ page import = "com.eg.EgServerGroupBean" %>
<%@ page import = "com.egurkha.ini.IniUI" %>
<%@ page import = "com.egurkha.pdfmaker.*" %>
<%@ page import = "com.egurkha.util.*" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.EgGroupInfo"%>
<%@ page import = "com.eg.EgTopoInfo"%>
<%@ page import = "com.egurkha.util.StringUtils" %>

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

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

	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;
	}
%>

<%
	String csrfToken = request.getParameter("com.eg.CSRF_NONCE");

	JSONObject rootJson = new JSONObject();
	//JSONObject resultObj = new JSONObject();
	//JSONObject hiddenObj = new JSONObject();
	//JSONObject screenLabels = new JSONObject();

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

	EgDateInfo egDate = new EgDateInfo();
	EgServerGroupBean descGrp = new EgServerGroupBean();
	EgTesterInfo testerInfo=new EgTesterInfo("manager");
	ArrayList globalThresholds=testerInfo.getGlobalThresholds();
	//String date = egDate.egetDate();
	Vector v_con = new Vector();
	Vector contForparamAndData = new Vector();
	Hashtable h_container = new Hashtable();
	Hashtable hashForPDF = new Hashtable();
	String s_ForCmd = "Threshold";
	String s_forPdfTitle="";
	String defValue = "none";
	String[] val = new String[5];
	EgThresholdInfo threshInfo = new EgThresholdInfo("manager"); 
	EgDiscInfo disc_info = new EgDiscInfo("manager");
	EgSpecsInfo specs_info = new EgSpecsInfo("manager");
	EgTablesInfo tables_info=new EgTablesInfo("manager");
	List defaultPolicies=new ArrayList();
	defaultPolicies.add("immediate");
	defaultPolicies.add("shortterm");
	defaultPolicies.add("standard");
	defaultPolicies.add("longterm");
	defaultPolicies.add("not applicable");

	String uiFile = "eg_ui.ini";
	String iniFileDir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(iniFileDir + uiFile);
	String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	Date date = new Date(System.currentTimeMillis());
	String currentDateTime = DateUtil.formatDate(date,currentDateFormat+" HH:mm:ss");

	String userLanguage = _user.getLanguage();
	IniUI iniUI = IniUI.getInstance();
	if (userLanguage == null)
	{
		userLanguage = iniUI.getDefaultLanguage();
	}
	EgMappingInfo mappingInfo = new EgMappingInfo(userLanguage);
	MappingNameSorter sorter = new MappingNameSorter(userLanguage);

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

	String s_threshType = request.getParameter("eg_threshType");
	String s_compType = request.getParameter("eg_compType");
	String s_host = request.getParameter("eg_host");
	String req_test = request.getParameter("eg_test");
	String fromCompType = request.getParameter("fromCT");
	String onSubmitPage = request.getParameter("onSubmit");
	fromCompType=(fromCompType==null?"true":fromCompType);
	
	s_threshType = (!StringUtils.isNull(s_threshType) && s_threshType.length()>0 ? s_threshType:"");
	s_compType = (!StringUtils.isNull(s_compType) && s_compType.length()>0 ? s_compType:"");
	s_host = (!StringUtils.isNull(s_host) && s_host.length()>0 ? s_host:"");
	req_test = (!StringUtils.isNull(req_test) && req_test.length()>0 ? req_test:"");

	boolean isShowMeasWithoutThresholds = false;
	String showMeasWithoutThreshVal = egUI.getValue("MISC_ARGS","SHOW_MEASURES_WITHOUT_THRESHOLDS");
	if(!StringUtils.isNull(showMeasWithoutThreshVal) && showMeasWithoutThreshVal.equalsIgnoreCase("yes"))
	{
		isShowMeasWithoutThresholds = true;
	}

	if(fromCompType.equalsIgnoreCase("true"))
	{
		s_threshType = "All";
	}

	if(s_threshType==null)
	{
		s_threshType = "All";
	}
	if(req_test==null)
	{
		req_test="All";
	}

	//String s_pdf = request.getParameter("PDF");

	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;
	}

	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("configmgmt.common.Not Applicable"));
		viewByObj.put("valueField","-1");
		viewByArr.add(viewByObj);
	}
	rootJson.put("viewByArr",viewByArr);


	String tmp=(String)request.getQueryString();
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	String htmlFileName =mngrIProc+"/final/admin/ViewThreshold/data/EgPrintThreshDetailView.jsp;jsessionid="+session.getId()+"?"+tmp+"&print=pdfpage&com.eg.CSRF_NONCE="+csrfToken;
	session.setAttribute("PDF_URL",htmlFileName);
	session.setAttribute("REPORT_NAME","Thresholds_View");
	session.setAttribute("REPORT_LAYOUT","Portrait");
	session.setAttribute("PAGE_WIDTH_PDF","1100");


	String arr_threshTypes[] = {"All","Global","Default","Group","Component","Descriptor"};
	ArrayList thresholdTypes = new ArrayList(Arrays.asList(arr_threshTypes));
	Vector v_allComps = new Vector(disc_info.getAllManagedComponents());
	Vector v_compTypes = new Vector();
	Vector v_components = new Vector();
	Vector v_matchTypes = new Vector();
	ArrayList commonList = null;

	boolean isGlobalContainTest = false;
	boolean isGlobalContainAllTest = false;
	boolean isGlobalConSpecificTest = false;
	boolean isReqTestAll = req_test.equalsIgnoreCase("All");
	boolean global = (globalThresholds!=null && globalThresholds.size()>0);
	ArrayList serverList = null;
	
	String[] compTypes = egRoleInfo.getServerTypes();
	if (compTypes != null && compTypes.length >0)
	{
		for (int i=0;i<compTypes.length;i++)
		{
			ArrayList aListEnabledPTestForCompType = new ArrayList();
			aListEnabledPTestForCompType = specs_info.getEnabledTests(compTypes[i],false);
			if (aListEnabledPTestForCompType.size()>0 && !v_compTypes.contains(compTypes[i]))
			{
				v_compTypes.add(compTypes[i]);
			}
		}
	}

	HashSet vec_componentTypes = new HashSet();
	Vector allcomps = new Vector();
	Vector vec_components = new Vector();
	boolean isValidCompType = (!s_compType.equals("") && !s_compType.equals("-1"));

	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(s_compType))
				{
					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...
		v_compTypes = new Vector();
		if (vec_componentTypes != null && !vec_componentTypes.isEmpty())
		{
			v_compTypes.addAll(vec_componentTypes);
			//v_compTypes = sorter.getSortedCompTypeList(vec_componentTypes);
		}
	}
	rootJson.put("userOption",userOption);

	if (v_compTypes != null && v_compTypes.size() > 0)
	{
		serverList = new ArrayList(v_compTypes);
		serverList = sorter.getSortedCompTypeList(serverList);
	}

	boolean isCompTypeAll = (s_compType != null && s_compType.equalsIgnoreCase("All"));

	if(!StringUtils.isNull(s_compType)  && !s_compType.equals("-1"))
	{
		if(global)
		{
			//if(!isCompTypeAll)
			{
				if(isReqTestAll)
				{
					String tests[] = specs_info.getTestsForServer(s_compType);
					commonList = new ArrayList(Arrays.asList(tests));
					isGlobalContainAllTest = globalThresholds.containsAll(commonList);
					isGlobalConSpecificTest = isListContainsTest(globalThresholds,commonList);
					isGlobalConSpecificTest = !isGlobalConSpecificTest;
				}
				else
				{
					isGlobalContainTest = globalThresholds.contains(req_test);
					isGlobalConSpecificTest = !isGlobalContainTest;
				}
				if(isGlobalContainAllTest || isGlobalContainTest)
				{
					thresholdTypes.clear();
					thresholdTypes.add("Global");
				}
				if(isGlobalConSpecificTest)
				{
					thresholdTypes.remove(thresholdTypes.indexOf("Global"));
				}
			}
		}
		else
		{
			thresholdTypes.remove(thresholdTypes.indexOf("Global"));
		}
	}

	if (!StringUtils.isNull(s_compType) && s_compType.equalsIgnoreCase("ALL"))
	{
		commonList = egRoleInfo.getAllServers();
	}
	else if(!StringUtils.isNull(s_compType) && !s_compType.equals("-1"))
	{
		String[] compsforType = egRoleInfo.getAllServersOfType(s_compType);
		commonList = new ArrayList(Arrays.asList(compsforType));
	}

	if (!criteria.equals("Component"))
	{
		commonList = new ArrayList();
		commonList.addAll(vec_components);
	}

	if(commonList != null && commonList.size() > 0)
	{
		for(int i = 0;i < commonList.size();i++)
		{
			String temp = (String)commonList.get(i);
			int ind = temp.indexOf(":");
			String s_compTy = temp.substring(0,ind);
			String s_compName = temp.substring(ind+1);
			v_components.add(s_compName);
			v_matchTypes.add(s_compTy+'#'+s_compName);
		}
	}

	Collections.sort(v_components,String.CASE_INSENSITIVE_ORDER);
	if (s_host == null)
	{
		if (v_components != null && v_components.size() > 0)
		{
			s_host = (String)v_components.get(0);
		}
		else
		{
			s_host = "All";
		}
	}
	
	// Updated by JJ
	Vector v_allTests = new Vector();
	boolean isAllCompType = false;

	if (!StringUtils.isNull(s_compType) && s_compType.equalsIgnoreCase("All"))
	{
		isAllCompType = true;
		for (int i=0; i<v_compTypes.size();i++)
		{
			String arr_tests[]= specs_info.getTestsForServer((String)v_compTypes.get(i));
			if (arr_tests !=null && arr_tests.length > 0)
			{
				for(int j=0;j<arr_tests.length;j++)
				{
					if(!v_allTests.contains(arr_tests[j]))
					{
						v_allTests.add(arr_tests[j]);
					}
				}
			}
		}
	}
	else if(!StringUtils.isNull(s_compType) && !s_compType.equals("-1"))
	{
		String arr_tests[]= specs_info.getTestsForServer(s_compType);
		if (arr_tests !=null && arr_tests.length > 0)
		{
			for(int j=0;j<arr_tests.length;j++)
			{
				if(!v_allTests.contains(arr_tests[j]))
				{
					v_allTests.add(arr_tests[j]);
				}
			}
		}
	}

	//remove config tests
	TestBean testBean = new TestBean(true);
	ArrayList configTests = testBean.getAllConfigTests();
	v_allTests.removeAll(configTests);

	TreeMap tm_threshData = new TreeMap();

	boolean isAllThresh = s_threshType.equalsIgnoreCase("All");
	boolean isDefaultThresh = s_threshType.equalsIgnoreCase("Default");
	boolean isDefaultDescriptorThresh = isDefaultThresh; //s_threshType.equalsIgnoreCase("Default descriptor");
	boolean isDefThreshTemp = isDefaultThresh;
	boolean isSpecificThresh = s_threshType.equalsIgnoreCase("Component");
	boolean isGroupThresh = s_threshType.equalsIgnoreCase("Group");
	boolean isDescThresh = s_threshType.equalsIgnoreCase("Descriptor");
	boolean isFixedThresh = s_threshType.equalsIgnoreCase("Global");
	boolean isFixThreshTemp =isFixedThresh;


	boolean isCompTypeEnabled = !s_compType.equalsIgnoreCase("All");
	boolean isCompNameEnabled = !s_host.equalsIgnoreCase("All") && isCompTypeEnabled;
	boolean isTestNameEnabled = !req_test.equalsIgnoreCase("All") && isCompNameEnabled;

	if (isAllThresh)
	{
		if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +": "+_mapping.getTestDescription(req_test)+" ("+ currentDateTime +")";
		else if (isCompNameEnabled && isCompTypeEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+ ":" +removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompNameEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component")+"  : " +removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompTypeEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component Type")+"  : " +_mapping.getComponentTypeDescription(s_compType) +" ("+ currentDateTime +")";
		else
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.All Components")+" ("+ currentDateTime +")";
	}
	else if(isDefaultThresh)
	{
		if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Settings for")+" "+_mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +": "+_mapping.getTestDescription(req_test)+" ("+ currentDateTime +")";
		else if (isCompNameEnabled && isCompTypeEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Settings for")+" "+_mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompNameEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Settings for Component")+" "+ removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompTypeEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Settings for Component Type")+" "+ _mapping.getComponentTypeDescription(s_compType) +" ("+ currentDateTime +")";
		else
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Settings")+" ("+ currentDateTime +")";
	}
	//else if(isDefaultDescriptorThresh)
	//{
		//if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled)
			//s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Descriptor Settings for")+" "+_mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +": "+_mapping.getTestDescription(req_test)+" ("+ currentDateTime +")";
		//else if (isCompNameEnabled && isCompTypeEnabled)
			//s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Descriptor Settings for")+" "+_mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +" ("+ currentDateTime +")";
		//else if(isCompNameEnabled)
			//s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Descriptor Settings for Component")+" "+ removeNull(s_host) +" ("+ currentDateTime +")";
		//else if(isCompTypeEnabled)
			//s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Descriptor Settings for Component Type")+" "+ _mapping.getComponentTypeDescription(s_compType) +" ("+ currentDateTime +")";
		//else
			//s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Default Descriptor Settings")+" ("+ currentDateTime +")";
	//}
	else if(isSpecificThresh)
	{
		if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +": "+_mapping.getTestDescription(req_test)+" ("+ currentDateTime +")";
		else if (isCompNameEnabled && isCompTypeEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+":"+ removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompNameEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component")+"  : "+ removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompTypeEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component Type")+"  : "+ _mapping.getComponentTypeDescription(s_compType) +" ("+ currentDateTime +")";
		else
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.All Specific Components")+" ("+ currentDateTime +")";
	}
	else if(isDescThresh)
	{
		if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+ ":" + removeNull(s_host) +": "+_mapping.getTestDescription(req_test)+" ("+ currentDateTime +")";
		else if (isCompNameEnabled && isCompTypeEnabled)
			s_forPdfTitle = _mapping.getComponentTypeDescription(s_compType)+":"+ removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompNameEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component")+"  : "+ removeNull(s_host) +" ("+ currentDateTime +")";
		else if(isCompTypeEnabled)
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.Component Type")+"  : "+ _mapping.getComponentTypeDescription(s_compType) +" ("+ currentDateTime +")";
		else
			s_forPdfTitle = _mapping.getTextDescription("admin.threshold.All Descriptor Components")+" ("+ currentDateTime +")";
	}
	else
		s_forPdfTitle =  _mapping.getTextDescription("admin.threshold.Threshold Report")+" ("+ currentDateTime +")";

	if(isCompNameEnabled && isCompTypeEnabled && isTestNameEnabled && s_forPdfTitle.length()>80)
		s_forPdfTitle=s_forPdfTitle.substring(0,s_forPdfTitle.lastIndexOf("("))+"\n ("+ currentDateTime +")";

	//new changes (13Jul2007)

	ArrayList selectedTests = new ArrayList(v_allTests);
	if(!StringUtils.isNull(req_test) && !req_test.equalsIgnoreCase("All"))
	{
		v_allTests.clear();
		v_allTests.add(req_test);
	}

	String[] userThreshvariables = null;
	if(isSpecificThresh || (isAllThresh))
	{
		userThreshvariables =  threshInfo.getUserThresholds();
	}
	//end

	String finn = request.getParameter("fin");
	boolean isAllCompsSelected = (s_host.equalsIgnoreCase("All"));
	Hashtable ht = new Hashtable();

	if (finn != null && finn.equals("yes"))
	{
		ArrayList descriptorList = new ArrayList();
		for(int i=0;i<v_allTests.size();i++)
		{
			String s_test = (String)v_allTests.get(i);
			boolean contain = global && globalThresholds.contains(s_test);
			boolean isAvailThreshVal = false;
			Vector defaultThreshComps = new Vector();

			Vector v_data= new Vector();
			if(isAllThresh)
			{
				if(contain)
				{
					isFixedThresh = true;
					isDescThresh = false;
					isDefaultThresh = false;
					isDefaultDescriptorThresh = false;
					isSpecificThresh = false;
					isGroupThresh = false;
				}
				else
				{
					isDescThresh = true;
					isDefaultThresh = true;
					isDefaultDescriptorThresh = true;
					isSpecificThresh = true;
					isGroupThresh = true;
					isFixedThresh = false;
				}
			}
			else if (!isFixedThresh && contain)
			{
				continue;
			}
			//for Global Threshold (17 Jul 2007)
			if(isFixedThresh)
			{
				if(contain)
				{
					String s_val = threshInfo.getDefaultThresholdValue(s_test);
					if(s_val !=null && !s_val.equals(""))
					{
						isAvailThreshVal = isSetThresholdValues(s_val);
						if(isShowMeasWithoutThresholds || isAvailThreshVal)
						{
							v_data.add("Global Thresholds");
							v_data.add(s_val);
						}
					}
				}
			}

			if(isSpecificThresh || isDescThresh || isGroupThresh )//|| isDefaultDescriptorThresh)
			{
				Vector v_comps = null;
				if(!s_host.equalsIgnoreCase("All"))
				{
					v_comps = new Vector();
					v_comps.add(s_host);
				}
				else
				{
					v_comps =(Vector) v_components.clone();
				}
				//Vector v_defaultDescData = new Vector();
				Vector v_specData = new Vector();
				Vector v_descData = new Vector();
				Vector v_allData = new Vector();
				for(int j=0;j<v_comps.size();j++)
				{
					if (j>=v_matchTypes.size())
						break;
					if (isAllCompType)
					{
						String t = (String) v_matchTypes.get(j);
						int ind = t.indexOf('#');
						t = t.substring(0,ind);
						if (!specs_info.isTestRelevantForServer (t,s_test) ||contain)
						{
							continue;
						}
					}

					boolean hasCompSpecificThresh = false;

					String s_component = (String)v_comps.get(j);
					String s_userThreshKey = s_test;
					String s_descThreshKey = s_test;

					StringTokenizer st = new StringTokenizer(s_component,":");
					String s_cmp = st.nextToken();
					String s_port = st.nextToken();

					String s_sid = null;
					if(st.hasMoreTokens())
						s_sid = st.nextToken();

					boolean isPortRelevantForTest =specs_info.isPortRelevantForTest(s_test);
					boolean isInfoRelevantForTest =false;

					if (s_compType.equalsIgnoreCase("All"))
					{
						isInfoRelevantForTest = (s_sid!=null && specs_info.isInfoRelevantForTest(s_test));
					}
					else
					{
						isInfoRelevantForTest = (s_sid!=null && specs_info.isInfoRelevantForTest(s_test,s_compType));
					}
					if(isSpecificThresh)
					{
						String s_key = s_cmp;
						if(isPortRelevantForTest)
							s_key += ":" + s_port;
						if(isInfoRelevantForTest)
							s_key += ":" + s_sid;

						String s_title = s_key;
						if(v_specData.contains(s_title))
							continue;
						s_key = s_test + ":" + s_key;
						//************june 24******
						String s_val = "";

						//new change
						boolean check = false;
						if(userThreshvariables != null)
						{
							for(int inc=0; inc <userThreshvariables.length; inc++)
							{
								String localvar = userThreshvariables[inc];
								if(localvar != null && localvar.equals(s_key))
								{
									check = true;
									break;
								}
							}
						}
						//end
						if(check)
						{
							s_val = threshInfo.getUserThresholdValue(s_key);
						}
						if(s_val!=null && !s_val.equals(""))
						{
							hasCompSpecificThresh = true; // for getting default thresh following comps
							s_title = removeNull(s_title);
							//if(isAllThresh)
							{
								s_title =s_title+" [Component]" ;
							}
							isAvailThreshVal = isSetThresholdValues(s_val);
							if(isShowMeasWithoutThresholds || isAvailThreshVal)
							{
								v_specData.add(s_title);
								v_specData.add(s_val);
							}
						}
					}

					if(isDescThresh)
					{
						String s_key = s_cmp;
						String all_key="";
						String all_val="";
						String all_title="";
						if(isPortRelevantForTest)
							s_key += ":" + s_port;
						else
							s_key += ":NULL";
						if(isInfoRelevantForTest)
							s_key += ":" + s_sid;
						String s_title = "";//s_key;
						String inf = "";
						all_title = s_key;
						Vector v_info = threshInfo.getInfosForThresholds(s_test, s_key);
						s_key = s_test + ":" + s_key;
						all_key = s_key;
						if(v_info!=null && v_info.size()>0)
						{
							for(int k=0;k<v_info.size();k++)
							{
								String s_info = (String)v_info.get(k);
								if(s_info.indexOf('+')!=-1)
									s_info = s_info.substring(s_info.indexOf('+')+1);

								String s_orgKey = s_key + "#" + s_info;
								String s_val = "";
								s_val = threshInfo.getDescThresholdValue(s_orgKey);
								if(s_val!=null && !s_val.equals(""))
								{
									s_title = s_key.substring(s_key.indexOf(":")+1);
									s_title = removeNull(s_title);
									String tmpInfo = s_info;
									if (tmpInfo.indexOf("0eGHash1") > -1)
									{
										tmpInfo = StringUtils.replace(tmpInfo,"0eGHash1","#");
									}
									s_title = s_title+"#" + tmpInfo;
									//if(isAllThresh)
									{
										s_title =s_title+" [Descriptor]";
									}
									isAvailThreshVal = isSetThresholdValues(s_val);
									if(isShowMeasWithoutThresholds || isAvailThreshVal)
									{
										v_descData.add(s_title);
										v_descData.add(s_val);
									}
								}
							}
						}
					}// end of isDescThresh

					//if(isDefaultDescriptorThresh)
					//{
						//String s_key = s_test;
						//String s_title = "";//s_key;
						//Vector v_info = threshInfo.getInfosForDefaultDescThresholds(s_test);
						//if(v_info!=null && v_info.size()>0)
						//{
							//for(int k=0;k<v_info.size();k++)
							//{
								//String s_info = (String)v_info.get(k);
								//if (descriptorList != null && descriptorList.contains(s_info))
								//{
									//continue;
								//}
								//String s_orgKey = s_key + ":" + s_info;
								//String s_val = "";
								//s_val = threshInfo.getDescDefaultThresholdValue(s_orgKey);
								//if(s_val!=null && !s_val.equals(""))
								//{
									//s_title = _mapping.getTestDescription(s_test)+":"+s_info;
									////if(isAllThresh)
									//{
										//s_title = s_title+" [Default descriptor]";
									//}
									//isAvailThreshVal = isSetThresholdValues(s_val);
									//if(isShowMeasWithoutThresholds || isAvailThreshVal)
									//{
										//descriptorList.add(s_info);
										//v_defaultDescData.add(s_title);
										//v_defaultDescData.add(s_val);
									//}
								//}
							//}
						//}
					//}// end of isDefaultDescriptorThresh

					if(isGroupThresh)
					{
						String s_key = s_cmp;
						String grp_key="";
						String grp_val="";
						String grp_title="";
						if(isPortRelevantForTest)
							s_key += ":" + s_port;
						else
							s_key += ":NULL";
						if(isInfoRelevantForTest)
							s_key += ":" + s_sid;
						String s_title = "";//s_key;
						String inf = "";
						grp_title = s_key;
						Vector v_info = threshInfo.getInfosForThresholds(s_test, s_key);
						s_key = s_test + ":" + s_key;
						grp_key = s_key;

						if(v_allData.contains(grp_title))
						{
							continue;
						}

						if(v_info!=null && v_info.size()>0)
						{
							for(int k=0;k<v_info.size();k++)
							{
								String s_info = (String)v_info.get(k);
								if(s_info.indexOf('+')!=-1)
									s_info = s_info.substring(s_info.indexOf('+')+1);

								String s_orgKey = s_key + "#" + s_info;
								String s_val = "";
								s_val = descGrp.getThresholdsFromInfoGroupIni(s_orgKey,false);

								if(s_val!=null && !s_val.equals(""))
								{
									s_title = s_key.substring(s_key.indexOf(":")+1);
									s_title = removeNull(s_title);
									String tmpInfo = s_info;
									if (tmpInfo.indexOf("0eGHash1") > -1)
									{
										tmpInfo = StringUtils.replace(tmpInfo,"0eGHash1","#");
									}
									s_title = s_title+"#" + tmpInfo;
									//if(isAllThresh)
									{
										s_title =s_title+" [Group - Descriptor]";
									}
									isAvailThreshVal = isSetThresholdValues(s_val);
									if(isShowMeasWithoutThresholds || isAvailThreshVal)
									{
										v_descData.add(s_title);
										v_descData.add(s_val);
									}
								}
								//else
								//{
									//grp_val = descGrp.getThresholdsFromInfoGroupIni(grp_key,false);

									//if(grp_val!=null && !grp_val.equals(""))
									//{
										//grp_title = removeNull(grp_title);

										//grp_title =grp_title+" [Group]";
										//if (grp_title != null && v_allData.contains(grp_title))
										//{
											//continue;
										//}

										//isAvailThreshVal = isSetThresholdValues(grp_val);
										//if(isShowMeasWithoutThresholds || isAvailThreshVal)
										//{
											//v_allData.add(grp_title);
											//v_allData.add(grp_val);
										//}
									//}
								//}

							}
						}
						
						grp_val = descGrp.getThresholdsFromInfoGroupIni(grp_key,false);

						if(grp_val!=null && !grp_val.equals(""))
						{
							hasCompSpecificThresh = true; // for getting default thresh following comps

							grp_title = removeNull(grp_title);
							grp_title =grp_title+" [Group]";
							isAvailThreshVal = isSetThresholdValues(grp_val);
							if(isShowMeasWithoutThresholds || isAvailThreshVal)
							{
								v_allData.add(grp_title);
								v_allData.add(grp_val);
							}
						}
					}// end of isDescThresh

					if (!hasCompSpecificThresh) // for getting default thresh following comps
					{
						defaultThreshComps.add(s_cmp);
					}
				}

				if(v_descData.size()>0) v_data.addAll(v_descData);
				if(v_specData.size()>0) v_data.addAll(v_specData);
				if(v_allData.size()>0) v_data.addAll(v_allData);
				//if(v_defaultDescData.size()>0) v_data.addAll(v_defaultDescData);
			}

			if(isDefaultThresh)
			{
				if (defaultThreshComps != null && !defaultThreshComps.isEmpty())
				{
					ht.put(s_test,defaultThreshComps);
				}

				String s_val = threshInfo.getDefaultThresholdValue(s_test);
				if(s_val!=null && !s_val.equals(""))
				{
					isAvailThreshVal = isSetThresholdValues(s_val);
					if(isShowMeasWithoutThresholds || isAvailThreshVal)
					{
						v_data.add("Default Thresholds");
						v_data.add(s_val);
					}
				}

				// start of isDefaultDescriptorThresh
				Vector v_defaultDescData = new Vector();
				if(isDefaultDescriptorThresh)
				{
					String s_key = s_test;
					String s_title = "";//s_key;
					Vector v_info = threshInfo.getInfosForDefaultDescThresholds(s_test);
					if(v_info!=null && v_info.size()>0)
					{
						for(int k=0;k<v_info.size();k++)
						{
							String s_info = (String)v_info.get(k);
							if (descriptorList != null && descriptorList.contains(s_info))
							{
								continue;
							}
							String s_orgKey = s_key + ":" + s_info;
							String s_descval = "";
							s_descval = threshInfo.getDescDefaultThresholdValue(s_orgKey);
							if(s_descval!=null && !s_descval.equals(""))
							{
								s_title = _mapping.getTestDescription(s_test)+":"+s_info;
								//if(isAllThresh)
								{
									s_title = s_title+" [Descriptor default]";
								}
								isAvailThreshVal = isSetThresholdValues(s_descval);
								if(isShowMeasWithoutThresholds || isAvailThreshVal)
								{
									descriptorList.add(s_info);
									v_defaultDescData.add(s_title);
									v_defaultDescData.add(s_descval);
								}
							}
						}
					}
				}
				if(v_defaultDescData.size()>0) v_data.addAll(v_defaultDescData);
				// end of isDefaultDescriptorThresh
			}

			if(v_data.size() > 0)
			{
				tm_threshData.put(s_test,v_data);
				for (int x=1;x<v_data.size();x+=2)
				{
					Vector v_tokens = new Vector();
					String tok = (String) v_data.get(x);
					v_data.setElementAt(tok,x);
				}
			}
		}
	}

	if (onSubmitPage == null)
	{
		//screenLabels.put("title","THRESHOLDS VIEW");
		//screenLabels.put("admin.threshold.Component type",_mapping.getTextDescription("admin.threshold.Component type"));
		//screenLabels.put("admin.threshold.Component name",_mapping.getTextDescription("admin.threshold.Component name"));
		//screenLabels.put("admin.threshold.Test name",_mapping.getTextDescription("admin.threshold.Test name"));
		//screenLabels.put("admin.threshold.Threshold",_mapping.getTextDescription("admin.threshold.Threshold"));

		JSONArray threshCompTypeArr = new JSONArray();
		if(v_compTypes.size() == 0)
		{
			JSONObject threshCompTypeObj = new JSONObject();
			threshCompTypeObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			threshCompTypeObj.put("valueField","-1");
			threshCompTypeArr.add(threshCompTypeObj);
		}
		else
		{
			JSONObject tempObj = new JSONObject();
			tempObj.put("displayField",_mapping.getTextDescription("admin.common.Choose a component type"));
			tempObj.put("valueField","-1");
			threshCompTypeArr.add(tempObj);

			for(int i=0;i<serverList.size();i++)
			{
				JSONObject threshCompTypeObj = new JSONObject();
				EgName nameObj = (EgName)serverList.get(i);
				String tmpVal = nameObj.getActualName();
				String tmpDis = nameObj.getLocalName();
				threshCompTypeObj.put("displayField",tmpDis);
				threshCompTypeObj.put("valueField",tmpVal);

				if(tmpVal.equals(s_compType))
				{
					rootJson.put("selectedCompType",s_compType);
				}
				threshCompTypeArr.add(threshCompTypeObj);
			}
		}
		rootJson.put("threshCompTypeArr",threshCompTypeArr);
		String s_tmpname="";
		String s_tmpname1 = "";
		JSONArray threshCompNameArr = new JSONArray();
		if(v_compTypes.size() == 0)
		{
			JSONObject threshCompNameObj = new JSONObject();
			threshCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			threshCompNameObj.put("valueField","-1");
			threshCompNameArr.add(threshCompNameObj);
		}
		else
		{
			if(v_components == null || v_components.size() == 0)
			{
				JSONObject tempObj = new JSONObject();
				tempObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
				tempObj.put("valueField","-1");
				threshCompNameArr.add(tempObj);
			}
			else
			{
				JSONObject threshCompNameObj = new JSONObject();
				//threshCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.Select a component"));
				//threshCompNameObj.put("valueField","-1");
				//threshCompNameArr.add(threshCompNameObj);
				if(v_components.size() > 1)
				{
					threshCompNameObj.put("displayField",_mapping.getTextDescription("admin.common.All"));
					threshCompNameObj.put("valueField","All");
					threshCompNameArr.add(threshCompNameObj);
					rootJson.put("selectedCompName",(s_host.equals("All"))?"selected":"");
				}

				for(int i=0;i<v_components.size();i++)
				{
					JSONObject tempCompNameObj = new JSONObject();
					s_tmpname=(String)v_components.get(i);
					//new change
					if(s_tmpname.lastIndexOf(":") >= 0)
					{
						s_tmpname1 = s_tmpname.substring(s_tmpname.lastIndexOf(":")+1);
						if(s_tmpname1 != null && s_tmpname1.equalsIgnoreCase("NULL"))
						{
							s_tmpname1 = s_tmpname.substring(0,s_tmpname.lastIndexOf(":"));
						}
						else
							s_tmpname1 = s_tmpname;
					}
					else
						s_tmpname1 = s_tmpname;

					tempCompNameObj.put("displayField",s_tmpname1);
					tempCompNameObj.put("valueField",s_tmpname);
					if(s_tmpname.equals(s_host))
					{
						rootJson.put("selectedCompName",s_host);
					}
					threshCompNameArr.add(tempCompNameObj);
				}
			}
		}
		rootJson.put("threshCompNameArr",threshCompNameArr);
		JSONArray threshTestNameArr = new JSONArray();
		if(v_compTypes.size() == 0)
		{
			JSONObject threshTestNameObj = new JSONObject();
			threshTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			threshTestNameObj.put("valueField","-1");
			threshTestNameArr.add(threshTestNameObj);
		}
		else if(StringUtils.isNull(s_host) || s_host.equals("-1"))
		{
			JSONObject threshTestNameObj = new JSONObject();
			threshTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			threshTestNameObj.put("valueField","-1");
			threshTestNameArr.add(threshTestNameObj);
		}
		else if (!isAllCompType || v_components.size() == 1)
		{
			if(selectedTests.size()>0)
			{
				JSONObject tempObj = new JSONObject();
				//tempObj.put("displayField",_mapping.getTextDescription("admin.test.Select a test name"));
				//tempObj.put("valueField","-1");
				//threshTestNameArr.add(tempObj);
				tempObj.put("displayField",_mapping.getTextDescription("admin.threshold.All"));
				tempObj.put("valueField","All");
				threshTestNameArr.add(tempObj);
				rootJson.put("selectedTestName",req_test.equalsIgnoreCase("All")?"selected":"");
			}
			else if(selectedTests.size() == 0)
			{
				JSONObject threshTestNameObj = new JSONObject();
				threshTestNameObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
				threshTestNameObj.put("valueField","-1");
				threshTestNameArr.add(threshTestNameObj);
			}
				ArrayList sortedTestList = new ArrayList(selectedTests);
				sortedTestList = sorter.getSortedTestList(sortedTestList);
				for(int i=0;i<sortedTestList.size();i++)
				{
					JSONObject threshTestNameObj = new JSONObject();
					EgName nameObj = (EgName)sortedTestList.get(i);
					String tmpVal = nameObj.getActualName();
					String tmpDis = nameObj.getLocalName();
					threshTestNameObj.put("displayField",tmpDis);
					threshTestNameObj.put("valueField",tmpVal);
					threshTestNameArr.add(threshTestNameObj);
					if (req_test.equalsIgnoreCase(tmpVal))
					{
						rootJson.put("selectedTestName",req_test);
					}
				}
		}
		else
		{
			JSONObject tempObj = new JSONObject();
			tempObj.put("displayField",_mapping.getTextDescription("admin.threshold.All"));
			tempObj.put("valueField","All");
			threshTestNameArr.add(tempObj);
			rootJson.put("selectedTestName","All");
		}
		rootJson.put("threshTestNameArr",threshTestNameArr);
		JSONArray threshTypeArr = new JSONArray();
		if(v_compTypes.size() == 0)
		{
			JSONObject tempObj = new JSONObject();
			tempObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
			tempObj.put("valueField","-1");
			threshTypeArr.add(tempObj);
		}
		else
		{
			if(StringUtils.isNull(req_test) || req_test.equals("-1")) 
			{
				JSONObject tempObj = new JSONObject();
				tempObj.put("displayField",_mapping.getTextDescription("admin.common.Not Applicable"));
				tempObj.put("valueField","-1");
				threshTypeArr.add(tempObj);
			}
			else
			{
				JSONObject tempObj = new JSONObject();
				//tempObj.put("displayField",_mapping.getTextDescription("admin.test.Select a threshold type"));
				//tempObj.put("valueField","-1");
				//threshTypeArr.add(tempObj);
				arr_threshTypes = (String[])thresholdTypes.toArray(new String[0]);
				for (int x=0;x<arr_threshTypes.length;x++)
				{
					JSONObject tempThreshTypeObj = new JSONObject();
					String threshTypeVal = arr_threshTypes[x];
					tempThreshTypeObj.put("displayField",threshTypeVal);
					tempThreshTypeObj.put("valueField",threshTypeVal);

					if (threshTypeVal.equalsIgnoreCase(s_threshType))
					{
						rootJson.put("selectedThreshType",threshTypeVal);
					}
					threshTypeArr.add(tempThreshTypeObj);
				}
			}
		}
		rootJson.put("threshTypeArr",threshTypeArr);
		String disabled = "";
		if(v_compTypes.size() == 0)
		{
			rootJson.put("isSubmitDisabled",true);
			disabled = "disabled";
		}
		else
		{
			rootJson.put("isSubmitDisabled",false);
		}

		if(request.getQueryString()!=null)
		{
			session.setAttribute("adminLastAccessedURL","/final/admin/EgThreshDetailView.jsp?"+request.getQueryString());
		}
		else
		{
			session.setAttribute("adminLastAccessedURL","/final/admin/EgThreshDetailView.jsp");
		}
	}
	else if(!StringUtils.isNull(onSubmitPage) && onSubmitPage.equals("true"))
	{
		StringBuffer tableHtmlForm = new StringBuffer(" <table class='table_autitborder' align='center' cellspacing='0' cellpadding='0' width='100%' border='0' style='height:100%'><tr><td style='vertical-align:top'><table align='center' cellspacing='0' cellpadding='0' width='100%' border='0' style='table-layout:fixed;height:100%'>");;

		//if (s_pdf != null && s_pdf.equalsIgnoreCase("true") && tm_threshData.size()>0)
		//{
			//String tempoTableHtmlForm = "<table cellspacing='0' cellpadding='3' width='95%' border='0'><tr><td align='left' width='100%' id='eg_title'>&nbsp;</td><td align='right' valign='middle' width='25'><a class='head'><img class='mouse' src='/final/admin/eg_images/"+admin_Skin+"/print_audit.gif' border='0' title='PRINT' onClick='main.printData();'></a></td><td  width='25' nowrap align='center'><a class='head'><img class='mouse' src='../admin/eg_images/"+admin_Skin+"/pdf_audit.gif' border='0' title='SAVE' onClick='main.savePdf();'></a></td><td  width='25' nowrap><a class='head'><img class='mouse' src='../admin/eg_images/"+admin_Skin+"/csv_audit.gif' border='0' title='CSV' onClick='main.csvData();'></a></td></tr></table>";
			//rootJson.put("pdfUtilities",tempoTableHtmlForm);
		//}

		if (finn != null && finn.equals("yes"))
		{
			if(tm_threshData.size() > 0)
			{
				rootJson.put("isNoData",false);

				// pdf work
				ArrayList tableList = new ArrayList();
				EgPdfData pdfData = new EgPdfData();
				EgReportAttributes reportAttributes = new EgReportAttributes();
				reportAttributes.setMainTitle(mappingInfo.getTextDescription("admin.threshold.Threshold Report"));
				reportAttributes.setSubTitle(s_forPdfTitle);
				reportAttributes.setReportName("Threshold");
				reportAttributes.setModule("ADMIN");
				reportAttributes.setPortrait(true);
				pdfData.setAttributes(reportAttributes);


				//CSV work...
				ArrayList userColumnNames = new ArrayList();
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Measurements"));
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Min/Max"));
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Critical"));
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Major"));
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Minor"));
				userColumnNames.add(_mapping.getTextDescription("admin.threshold.Alarm Policy"));
				// CSV work...

				Iterator itr = tm_threshData.keySet().iterator();
				int cnt = 0;
				JSONArray viewAllDataArr = new JSONArray();
				while(itr.hasNext())
				{
					//JSONArray threshViewDataArr = new JSONArray();
					//JSONObject tmpObject = new JSONObject();
					String key = (String) itr.next();
					//tmpObject.put("display_testName",_mapping.getTestDescription(key));
					//threshViewDataArr.add(testNameObj);
					String HYPHEN = "";
					Vector v_title =(Vector) tm_threshData.get(key);
					//recent change
					if(v_title.size() == 2)
					{
						HYPHEN = " - ";
					}
					tableHtmlForm.append("<tr><td colspan='6' nowrap class='eg_subheadbg'><table width='100%' cellspacing='0' cellpadding='0'  style='height:100%'><tr><td width='100%' class='subHeadFontSize'> "+_mapping.getTestDescription(key)+"</td></tr></table></td></tr><tr><td colspan='6' class='table_border padding4'>");

					int count = 0;
					for (int x=0;x<v_title.size();x+=2)
					{
						tableHtmlForm.append("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
						//tmpObject = new JSONObject();
						String title = (String) v_title.get(x);
						if(title.equalsIgnoreCase("Default"))
							title = mappingInfo.getTestDescription(key);
						else if (title.equalsIgnoreCase("Global"))
							title = mappingInfo.getTestDescription(key)+" ["+_mapping.getTextDescription("admin.threshold.Global")+"]";
						else
							title = mappingInfo.getTestDescription(key) + ":" +title;
						//pdf work
						ArrayList aListData = new ArrayList();

						//recent change
						String tmpStr = ((String)v_title.get(x));
						boolean isDefaultDescriptor = false;
						if (!StringUtils.isNull(tmpStr) && tmpStr.indexOf(":") != -1 && tmpStr.endsWith("[Default descriptor]"))
						{
							isDefaultDescriptor = true;
						}
						boolean isDefaultThresholdBlock = false;
						if (!StringUtils.isNull(tmpStr) && tmpStr.equalsIgnoreCase("Default Thresholds"))
						{
							isDefaultThresholdBlock = true;
						}

						//if(v_title.size() > 2)
						if (isDefaultDescriptor)
						{
							String tempDispTest = tmpStr.substring(0,tmpStr.indexOf(":"));
							String tempInfo = tmpStr.substring(tmpStr.indexOf(":"),tmpStr.indexOf("["));
							String tempThreshType = tmpStr.substring(tmpStr.indexOf(" [")+1);
							tmpStr = tempDispTest.toUpperCase()+tempInfo+tempThreshType.toUpperCase();
							//tmpObject.put(_mapping.getTestDescription(key)+"_title_"+count,tmpStr);
							//tableHtmlForm += "<tr><td colspan='6' width='100%' nowrap class='padding4 subHeadFontSize'>"+tempDispTest.toUpperCase()+"<span class='fontNormalText'>"+tempInfo+"</span>"+tempThreshType.toUpperCase()+"</td></tr>";
							tableHtmlForm.append("<tr><td colspan='6' width='100%' nowrap class='subHeadFontSize'>"+tmpStr+"</td></tr>");
						}
						else
						{
							//tmpObject.put(_mapping.getTestDescription(key)+"_title_"+count,tmpStr);
							tableHtmlForm.append("<tr><td colspan='6' width='100%' nowrap class='subHeadFontSize'>"+((String)v_title.get(x)).toUpperCase()+"</td></tr>");
						}

						String v_data1 = (String)v_title.get(x+1);
						tableHtmlForm.append("<tr><td style='padding:0 4px 0 4px'><table align='center' width='100%' cellspacing='0' cellpadding='0' border='0' class='x-grid-rowprintwin'><col width='auto'><col width='65%'><col width='15%'>");

						// CSV work starts
						ArrayList aListColumnNames = new ArrayList();
						for(int k=0; k<6; k++) aListColumnNames.add("C"+k);

						EgTableAttributes egTableAttributes = new EgTableAttributes();
						egTableAttributes.setTitle(title);
						egTableAttributes.setStartX(0);
						egTableAttributes.setColumnNames(userColumnNames);
						//CSV work ends

						boolean heading_flag = false;
						ArrayList aListTestWithNoThresholds = new ArrayList();
						boolean cellFlag = false;
						StringTokenizer st = new StringTokenizer(v_data1,",");
						//JSONArray threshValArr = new JSONArray();
						boolean isMeasureWithThresholds = false;
						while (st.hasMoreTokens())
						{
							JSONObject threshTableObj = new JSONObject();
							String strTok = st.nextToken();
							StringTokenizer st1 = new StringTokenizer(strTok,":");
							while (st1.hasMoreTokens())
							{
								//JSONObject tempObj = new JSONObject();
								String measure = st1.nextToken();
								String policy = st1.nextToken();
								String min = st1.nextToken();
								String max = st1.nextToken();
								String alarmPolicy = st1.nextToken();
								String lastToken = st1.nextToken();

								String absMinCritical = "-";
								String relMinCritical = "-";

								String absMinMajor = "-";
								String relMinMajor = "-";

								String absMinMinor = "-";
								String relMinMinor = "-";

								String absMaxCritical = "-";
								String relMaxCritical = "-";

								String absMaxMajor = "-";
								String relMaxMajor = "-";

								String absMaxMinor = "-";
								String relMaxMinor = "-";

								if (policy.equalsIgnoreCase("none"))
								{
									policy = "mix";
								}
								else if (policy.equalsIgnoreCase("absolute"))
								{
									if (!min.equals("-1"))
									{
										StringTokenizer stAbsMin = new StringTokenizer(min,"/");
										absMinCritical = stAbsMin.nextToken();
										absMinMajor = stAbsMin.nextToken();
										absMinMinor = stAbsMin.nextToken();
									}

									if (!max.equals("-1"))
									{
										StringTokenizer stAbsMax = new StringTokenizer(max,"/");
										absMaxCritical = stAbsMax.nextToken();
										absMaxMajor = stAbsMax.nextToken();
										absMaxMinor = stAbsMax.nextToken();
									}
								}
								else if (policy.equalsIgnoreCase("relative"))
								{
									if (!min.equals("-1"))
									{
										StringTokenizer stRelMin = new StringTokenizer(min,"/");
										relMinCritical = stRelMin.nextToken();
										relMinMajor = stRelMin.nextToken();
										relMinMinor = stRelMin.nextToken();
									}

									if (!max.equals("-1"))
									{
										StringTokenizer stRelMax = new StringTokenizer(max,"/");
										relMaxCritical = stRelMax.nextToken();
										relMaxMajor = stRelMax.nextToken();
										relMaxMinor = stRelMax.nextToken();
									}
								}
								else if (policy.equalsIgnoreCase("mix"))
								{
									Vector vec = getAbsAndRel(min);
									String absA = (String) vec.get(0);
									String relA = (String) vec.get(1);
									Vector vec1 = getAbsAndRel(max);
									String absB = (String) vec1.get(0);
									String relB = (String) vec1.get(1);

									if (!absA.equals("none"))
									{
										StringTokenizer stmixMin = new StringTokenizer(absA,"/");
										absMinCritical = stmixMin.nextToken();
										absMinMajor = stmixMin.nextToken();
										absMinMinor = stmixMin.nextToken();
									}

									if (!absB.equals("none"))
									{
										StringTokenizer stmixMax = new StringTokenizer(absB,"/");
										absMaxCritical = stmixMax.nextToken();
										absMaxMajor = stmixMax.nextToken();
										absMaxMinor = stmixMax.nextToken();
									}

									if (!relA.equals("none"))
									{
										StringTokenizer stRelMin = new StringTokenizer(relA,"/");
										relMinCritical = stRelMin.nextToken();
										relMinMajor = stRelMin.nextToken();
										relMinMinor = stRelMin.nextToken();
									}

									if (!relB.equals("none"))
									{
										StringTokenizer stmixMax = new StringTokenizer(relB,"/");
										relMaxCritical = stmixMax.nextToken();
										relMaxMajor = stmixMax.nextToken();
										relMaxMinor = stmixMax.nextToken();
									}
								}

								String minCritical = getThresholdValue("min",absMinCritical,relMinCritical);
								String minMajor = getThresholdValue("min",absMinMajor,relMinMajor);
								String minMinor = getThresholdValue("min",absMinMinor,relMinMinor);

								String maxCritical = getThresholdValue("max",absMaxCritical,relMaxCritical);
								String maxMajor = getThresholdValue("max",absMaxMajor,relMaxMajor);
								String maxMinor = getThresholdValue("max",absMaxMinor,relMaxMinor);

								if (minCritical.equals("-") && minMajor.equals("-") && minMinor.equals("-") && 
								maxCritical.equals("-") && maxMajor.equals("-") && maxMinor.equals("-"))
								{
									aListTestWithNoThresholds.add(measure);
									cellFlag = !cellFlag;
									//continue;
								}

								if (!heading_flag)
								{
									if (!minCritical.equals("-") || !minMajor.equals("-") || !minMinor.equals("-") || !maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
									{
										heading_flag = true;
									tableHtmlForm.append("<tr><td align='center' class='lineright padding4 table_head' style='font-size: 12px !important'>Measure</td><td align='center' style='padding:0px'><table cellpadding='0' cellspacing='0' border='0' width='100%'><col width='19%'><col width='27%'><col width='27%'><col width='27%'><tr><td align='center' class='lineright padding4 table_head' style='font-size: 12px !important'>Min/Max</td><td align='center' class='lineright padding4 table_head' style='font-size: 12px !important'>Critical</td><td align='center' class='lineright padding4 table_head' style='font-size: 12px !important'>Major</td><td align='center' class='lineright padding4 table_head' style='font-size: 12px !important'>Minor</td></tr></table></td><td class='lineright padding4 table_head' align='center'>Alarm Policy</td></tr>");
									}
								}

								String unit = tables_info.getUnitForMeasure(key,measure);
								String temp ="cell_borderthresh";

								if (!minCritical.equals("-") || !minMajor.equals("-") || !minMinor.equals("-") || !maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
								{
								tableHtmlForm.append("<tr><td align='left' valign='middle' id='"+temp+"' class='padding4' style='border-left-width:1px'><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr style='background: transparent'><td width='95%' valign='middle' class='fontSizethrshold' nowrap>"+mappingInfo.getMeasureDescription(key,measure)+"</td><td class='fontSize10'>&nbsp;<i>("+unit+")</i>&nbsp;</td></tr></table></td><td align='left' valign='top' id='"+temp+"' class='padding4' ><table cellpadding='0' cellspacing='0' border='1' width='100%' class='tableborder_ad'><col width='19%'><col width='27%'><col width='27%'><col width='27%' >");
								}

								//tempObj.put("Measure",mappingInfo.getMeasureDescription(key,measure)+" ("+unit+" )");
				//				String measurePdf = mappingInfo.getMeasureDescription(key,measure);
								String measurePdf = mappingInfo.getMeasureDescription(key,measure) + " (" + tables_info.getUnitForMeasure(key,measure) + ")";
								aListData.add(measurePdf);

								boolean enterMinPart = false;
								boolean enterMaxPart = false;
								if(!minCritical.equals("-") || !minMajor.equals("-") || !minMinor.equals("-"))
								{
									tableHtmlForm.append("<tr class='linebottom'><td align='center' class='padding2 tdborder_ad fontSizethrshold'>Min</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+minCritical+"</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+minMajor+"</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+minMinor+"</td></tr>");

									//tempObj.put("minCritical",minCritical);
									//tempObj.put("minMajor",minMajor);
									//tempObj.put("minMinor",minMinor);

									enterMinPart = true;
								}

								if(!maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
								{
									tableHtmlForm.append("<tr><td align='center' class='padding2 tdborder_ad fontSizethrshold'>Max</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+maxCritical+"</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+maxMajor+"</td><td align='center' class='padding2 tdborder_ad fontSizethrshold'>"+maxMinor+"</td></tr>");

									//tempObj.put("maxCritical",maxCritical);
									//tempObj.put("maxMajor",maxMajor);
									//tempObj.put("maxMinor",maxMinor);

									enterMaxPart = true;
								}

								if (!minCritical.equals("-") || !minMajor.equals("-") || !minMinor.equals("-") || !maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
								{
								tableHtmlForm.append("</table></td><td id='"+temp+"' class='padding4 fontSizethrshold' align='left' valign='middle' title='"+alarmPolicy+"' >"+alarmPolicy+"</td></tr>");
								}

								//tempObj.put("AlarmPolicy",alarmPolicy);

								if(enterMinPart && !enterMaxPart)
								{
									aListData.add("Min");
									aListData.add(minCritical);
									aListData.add(minMajor);
									aListData.add(minMinor);
									aListData.add(alarmPolicy);
									isMeasureWithThresholds = true;
								}
								else if(!enterMinPart && enterMaxPart)
								{
									aListData.add("Max");
									aListData.add(maxCritical);
									aListData.add(maxMajor);
									aListData.add(maxMinor);
									aListData.add(alarmPolicy);
									isMeasureWithThresholds = true;
								}
								else if(enterMinPart && enterMaxPart)
								{
									//min data
									aListData.add("Min");
									aListData.add(minCritical);
									aListData.add(minMajor);
									aListData.add(minMinor);
									aListData.add(alarmPolicy);

									//max data
									aListData.add("");
									aListData.add("Max");
									aListData.add(maxCritical);
									aListData.add(maxMajor);
									aListData.add(maxMinor);
									aListData.add("");
									isMeasureWithThresholds = true;
								}
								else if (!enterMinPart && !enterMaxPart)
								{
									aListData.add("-");
									aListData.add(maxCritical);
									aListData.add(maxMajor);
									aListData.add(maxMinor);
									aListData.add(alarmPolicy);
								}

								//isMeasureWithThresholds = true;
								//threshValArr.add(tempObj);
							}
							cellFlag = !cellFlag;
						}
						//tmpObject.put(_mapping.getTestDescription(key)+"_thresh_"+count,threshValArr);
						EgTableModel egTableModel = new EgTableModel(aListData,aListColumnNames);
						EgTable egTable = new EgTable();
						egTable.setModel(egTableModel);
						egTable.setAttributes(egTableAttributes);
						tableList.add(egTable);
						tableHtmlForm.append("</table></td></tr>");

						if (isAllCompsSelected && isDefaultThresholdBlock)
						{
							// CSV work starts

							Vector defaultThreshComps = (Vector) ht.get(key);

							if (defaultThreshComps != null && defaultThreshComps.size() > 0)
							{
								ArrayList compColNames = new ArrayList();
								ArrayList aListCompColNames = new ArrayList();
								ArrayList aListCompData = new ArrayList();
								for(int k=0; k<6; k++) {
									aListCompColNames.add("C"+k);
									compColNames.add("");
								}

								EgTableAttributes egTableAttributes1 = new EgTableAttributes();
								egTableAttributes1.setTitle("Applicable Components");
								egTableAttributes1.setStartX(0);

								for (int c=0; c<defaultThreshComps.size(); c=c+6)
								{
									for (int e=c; e<c+6; e++)
									{
										if (e<defaultThreshComps.size())
										{
											String strCompName = (String)defaultThreshComps.get(e);
											aListCompData.add(strCompName);
										}
										else
										{
											aListCompData.add("");
										}
									}

									if (c == 0 && defaultThreshComps.size() > 6)
									{
										compColNames = new ArrayList();
										compColNames.addAll(aListCompData);
										aListCompData = new ArrayList();
									}
								}

								egTableAttributes1.setColumnNames(compColNames);
								//CSV work ends

								EgTableModel egTableModel1 = new EgTableModel(aListCompData,aListCompColNames);
								EgTable egTable1 = new EgTable();
								egTable1.setModel(egTableModel1);
								egTable1.setAttributes(egTableAttributes1);
								tableList.add(egTable1);
							}
						}

						//JSONArray threshNoMeasureArr = new JSONArray();
						if(isShowMeasWithoutThresholds)
						{
							if (aListTestWithNoThresholds != null && !aListTestWithNoThresholds.isEmpty())
							{
								if (isMeasureWithThresholds) 
								{
									tableHtmlForm.append("<tr><td><img src='/final/admin/eg_images/spacer.gif' border='0' width='7' height='10'></td></tr>");
								}
								tableHtmlForm.append("<tr><td class='padding4'><table align='center' width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td height='20' class='padding4 table_head'>Measures without thresholds</td></tr><tr><td width='100%'><table width='100%' cellspacing='0' cellpadding='0' border='0' class='tableborder_ad2' style='border-collapse: collapse;'><col width='33%'><col width='33%'><col width='34%'>");

								for (int d=0; d<aListTestWithNoThresholds.size(); d=d+3)
								{
									tableHtmlForm.append("<tr>");

									int k=1;
									for (int e=d; e<d+3; e++)
									{
										//JSONObject threshNoMeasureObj = new JSONObject();

										if (e<aListTestWithNoThresholds.size())
										{
											String strMeasure = (String)aListTestWithNoThresholds.get(e);
											//threshNoMeasureObj.put("noMeasure_"+e,mappingInfo.getMeasureDescription(key,strMeasure));

											String tmpStyple="";
											if(k==1)
											{
												tmpStyple="border-left-width:1px";
												k++;
											}
											tableHtmlForm.append("<td class='tdborder_ad2 padding4' valign='top' align='left' ><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr ><td width='5%' valign='center' valign='middle'></td><td width='95%' valign='middle' class='fontSizethrshold'>"+mappingInfo.getMeasureDescription(key,strMeasure)+"</td></tr></table></td>");

											//threshNoMeasureArr.add(threshNoMeasureObj);
										}
										else
										{
											tableHtmlForm.append("<td class='tdborder_ad2' >&nbsp;</td>");
										}
									}
									tableHtmlForm.append("</tr>");
								}
								//tableHtmlForm.append("</table></td></tr></table></td></tr><tr><td><img src='/final/admin/eg_images/spacer.gif' border='0' width='7' height='10'></td></tr>");
								tableHtmlForm.append("</table></td></tr></table></td></tr>");
							}
							else
							{
								tableHtmlForm.append("<tr><td colspan='6'>&nbsp;</td></tr>");
							}
						}
						else
						{
							tableHtmlForm.append("<tr><td colspan='6'>&nbsp;</td></tr>");
						}

						if (isAllCompsSelected && isDefaultThresholdBlock)
						{
							Vector defaultThreshComps = (Vector) ht.get(key);

							if (defaultThreshComps != null && defaultThreshComps.size() > 0)
							{
								tableHtmlForm.append("<tr><td><img src='/final/admin/eg_images/spacer.gif' border='0' width='7' height='10'></td></tr>");

								tableHtmlForm.append("<tr><td class='padding4'><table align='center' width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td height='20' class='padding4 table_head'>Applicable Components</td></tr><tr><td width='100%'><table width='100%' cellspacing='0' cellpadding='0' border='0' class='tableborder_ad2' style='border-collapse: collapse;'><col width='33%'><col width='33%'><col width='34%'>");

								for (int c=0; c<defaultThreshComps.size(); c=c+3)
								{
									tableHtmlForm.append("<tr>");

									int rec=1;
									for (int e=c; e<c+3; e++)
									{
										if (e<defaultThreshComps.size())
										{
											String strCompName = (String)defaultThreshComps.get(e);
											String tmpStyple="";
											if(rec==1)
											{
												tmpStyple="border-left-width:1px";
												rec++;
											}
											tableHtmlForm.append("<td class='tdborder_ad padding4' valign='top' align='left' ><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr ><td width='5%' valign='center' valign='middle'></td><td width='95%' valign='middle' class='fontSizethrshold'>"+strCompName+"</td></tr></table></td>");

										}
										else
										{
											tableHtmlForm.append("<td class='tdborder_ad' >&nbsp;</td>");
										}
									}
									tableHtmlForm.append("</tr>");
								}
								tableHtmlForm.append("</table></td></tr></table></td></tr><tr><td><img src='/final/admin/eg_images/spacer.gif' border='0' width='7' height='10'></td></tr>");
							}
						}

						tableHtmlForm.append("</table>");
						//tmpObject.put(_mapping.getTestDescription(key)+"_nothresh_"+count,threshNoMeasureArr);
						//threshViewDataArr.add(tmpObject);
						//resultObj.put("threshViewDataArr_"+cnt,threshViewDataArr);
						count++;
					}
					//tableHtmlForm.append("</td></tr><tr><td id='eg_blan kspace' height='20'>&nbsp;</td></tr>");
					cnt++;
				}
				//pdf work

				pdfData.setData(tableList);
				session.setAttribute("pdfData",pdfData);
			}
			else
			{
				tableHtmlForm.append("<tr><td colspan='7' align='center' valign='middle' class='eg_subhead'><img src='/final/images/spacer.gif' class='iconInformation'><div class='commonErrorMsgText' id='noCompAlrtDiv'>"+_mapping.getTextDescription("admin.threshold.No data available for the combination chosen")+".</div></td></tr>");

				rootJson.put("isNoData",true);
				rootJson.put("noDataMsg",_mapping.getTextDescription("admin.threshold.No data available for the combination chosen"));
			}
		}
		tableHtmlForm.append("</table></td></tr></table>");
		session.setAttribute("eg_compType",s_compType);
		session.setAttribute("eg_host",s_host);
		session.setAttribute("eg_test",req_test);
		session.setAttribute("eg_threshType",s_threshType);
		session.setAttribute("fromCT",fromCompType);
		session.setAttribute("fin",finn);
		rootJson.put("tableHtmlForm",tableHtmlForm.toString());
	}
	//rootJson.put("screenLabels",screenLabels);
	//rootJson.put("resultObj",resultObj);
	//rootJson.put("hiddenObj",hiddenObj);
	out.println(rootJson.toString());
	if(request.getQueryString()!=null)
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgViewThreshold.jsp?"+request.getQueryString());
	}
	else
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgViewThreshold.jsp");
	}
%>



<%!
	int alarmPolicyLength = 15;

	private String get1(String H)
	{
		String h;
		if (!(H.equals("-")))
		{
			if (H.indexOf("&") > -1)
			{
				StringTokenizer st = new StringTokenizer(H,"&");
				H = st.nextToken();
				h = st.nextToken();
			}
			else
			{
				if (H.indexOf("sqc") > -1)
				{
					h = H;
					H = "-";
				}
				else
				{
					h = "-";
				}
			}
		}
		else
		{
			h = "-";
		}
		return(H+"_"+h);
	}

	private Vector getAbsAndRel(String format)
	{
		Vector vect = new Vector();
		StringTokenizer stok1 = new StringTokenizer(format,"/");
		if (!format.equals("-1") && stok1.countTokens() == 3)
		{
			String H1 = stok1.nextToken();
			String h2=get1(H1);
			String M = stok1.nextToken();
			String m1=get1(M);
			String L = stok1.nextToken();
			String l1=get1(L);
			StringTokenizer h1 = new StringTokenizer(h2,"_");
			String High= h1.nextToken();
			String high = h1.nextToken();
			StringTokenizer m = new StringTokenizer(m1,"_");
			String Mid = m.nextToken();
			String mid = m.nextToken();
			StringTokenizer l = new StringTokenizer(l1,"_");
			String Low = l.nextToken();
			String low = l.nextToken();
			StringBuffer sb2 = new StringBuffer();
			StringBuffer sb1 = new StringBuffer();
			String s1 = null;
			if (High.equals("-") && Mid.equals("-") && Low.equals("-"))
			{
				s1 = "none";
			}
			else
			{
				sb1.append(High);
				sb1.append("/");
				sb1.append(Mid);
				sb1.append("/");
				sb1.append(Low);
				s1 = sb1.toString();
			}
			String s2 = null;
			if (high.equals("-") && mid.equals("-") && low.equals("-"))
			{
				vect.add(s1);
				vect.add("none");
			}
			else
			{
				sb2.append(high);
				sb2.append("/");
				sb2.append(mid);
				sb2.append("/");
				sb2.append(low);
				s2 = sb2.toString();
				vect.add(s1);
				vect.add(s2);
			}
		}
		else
		{
			vect.add("none");
			vect.add("none");
		}
		return vect;
	}

	private String getThresholdValue(String grpFunction, String absValue,String relValue)
	{
		String strValue = "-";

		if (absValue.equals("-") && relValue.equals("-"))
		{
			strValue = "-";
		}
		else if (!absValue.equals("-") && !relValue.equals("-"))
		{
			strValue = grpFunction+"("+absValue+", "+getRelativeThreshold(relValue)+")";
		}
		else if (!absValue.equals("-"))
		{
			strValue = absValue;
		}
		else if (!relValue.equals("-"))
		{
			strValue = getRelativeThreshold(relValue);
		}

		return strValue;
	}

	private String getRelativeThreshold(String relValue)
	{
		//relValue: 3*sqc
		String strValue = "";
		if (relValue.indexOf("*") != -1)
		{
			int idx = relValue.indexOf("*");
			String s1 = relValue.substring(0,idx);
			double d_value = Double.valueOf(s1.trim()).doubleValue();
			d_value = d_value * 100;
			int i_value = (new Double(d_value)).intValue();
			strValue = Integer.toString(i_value) + "% of auto";
		}
		else
		{
			strValue = "auto";
		}
		return strValue;
	}

	public String removeNull(String compName)
	{
		if (compName != null && compName.length()>0)
		{
			return (compName.endsWith(":NULL"))?compName.substring(0,compName.indexOf(":NULL")):compName;
		}
		else
		{
			return "";
		}
	}

	public boolean isSetThresholdValues(String str)
	{
		boolean isThreshVal = false;
		StringTokenizer st = new StringTokenizer(str,",");
		while(st.hasMoreElements())
		{
			String tmpVal = st.nextToken();
			StringTokenizer st1 = new StringTokenizer(tmpVal,":");
			String measName = st1.nextToken();
			String measType = st1.nextToken();
			String minVal = st1.nextToken();
			String maxVal = st1.nextToken();
			if(!minVal.equals("-1") || !maxVal.equals("-1"))
			{
				isThreshVal = true;
				break;
			}
		}
		return isThreshVal;
	}

	public boolean isListContainsTest(ArrayList a1,ArrayList a2)
	{
		boolean b = false;
		for(int i=0;i<a2.size();i++)
		{
			String temp = (String)a2.get(i);
			if(a1.contains(temp))
			{
				b = true;
				break;
			}
		}
		return b;
	}
%>



