<%
/******************************************************************************
*	Name            :       EgShowThresholdPolicies.jsp
*	Purpose         :		
*	Design Changes	:	Jaiwin
*******************************************************************************/
%>

<%@ page import = "java.util.*"%>
<%@ include file="../../EgTrackerAJSON.jsp"%>
<%@ page import ="com.eg.EgURLEncoder"%>
<%@ page import ="com.eg.EgServerGroupBean"%>
<%@ page import="com.eg.EgRoleInfo"%>
<%@ page import="com.eg.EgSpecsInfo"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="com.egurkha.ini.IniUI"%>
<%@ page import="com.eg.IniFile"%>

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

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

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

<%
	JSONObject rootJson = new JSONObject();

	EgRoleInfo ri = EgRoleInfo.getInstance(session.getId(),(String)session.getAttribute("sess_userid"));
	EgServerGroupBean descGrp = new EgServerGroupBean();
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	List listManagedComponents = ri.getAllServers();
	String[] componentTypes = ri.getServerTypes();
	String testMappingSection = "TEST_MAPPING";
	IniFile egSpecsIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_specs.ini");
	ArrayList aListEnabledTests = new ArrayList();
	if (componentTypes != null && componentTypes.length > 0)
	{
		for (int i=0;i<componentTypes.length;i++)
		{
			String componentType = componentTypes[i];
			String strEnabledTests = egSpecsIni.getValue(testMappingSection,componentType);
			StringTokenizer strTokens = new StringTokenizer(strEnabledTests,",");
			while (strTokens.hasMoreTokens())
			{
				String strToken = strTokens.nextToken().trim();
				if (EgInstallInfo.isConfigTest(strToken)) continue;
				aListEnabledTests.add(strToken);
			}
		}
	}
	IniUI iniUI = IniUI.getInstance();
	EgDbAdapterUI egDb;
	IniFile defaultIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
	String defaultThreshold = null;
	String subject = "DESCRIPTOR_DEFAULT_THRESHOLDS";
	String[] globalVars = defaultIni.getVariables(subject);
	ArrayList defGlobalDescTestList = new ArrayList();
	if(globalVars != null && globalVars.length > 0)
	{
		for(int i=0;i<globalVars.length;i++)
		{
			String tmpTestName = globalVars[i];
			String strTest = "";
			if(tmpTestName != null && tmpTestName.indexOf(":") != -1)
			{
				strTest = tmpTestName.substring(0,tmpTestName.indexOf(":"));
			}
			if (strTest != null && (aListEnabledTests  != null && aListEnabledTests.contains(strTest))) 
			{
				defGlobalDescTestList.add(tmpTestName);
			}
		}
	}
	
	if(defGlobalDescTestList != null && defGlobalDescTestList.size() > 0)
	{
		JSONArray descPatternGridDataArr = new JSONArray();
		for(int t=0;t<defGlobalDescTestList.size();t++)
		{
			JSONObject descPatternGridDataObj = new JSONObject();
			String tmpTestName = (String) defGlobalDescTestList.get(t);
			if(tmpTestName != null && tmpTestName.indexOf(":") != -1)
			{
				String pattName = tmpTestName.substring(tmpTestName.indexOf(":")+1);
				if(!StringUtils.isNull(pattName))
				{
					tmpTestName = tmpTestName.substring(0,tmpTestName.indexOf(":"));
					descPatternGridDataObj.put("TestName","Test name : "+_mapping.getTestDescription(tmpTestName));
					descPatternGridDataObj.put("DescPatterns",StringUtils.decodeSecurityChar(pattName));
					descPatternGridDataObj.put("modifyUrl","DescriptorPatternThreshold/data/EgDefinePatternJson.jsp?pattName="+EgURLEncoder.encode( StringUtils.encodeSecurityChar(pattName),"UTF-8")+"&from=modify&testName="+tmpTestName);
					descPatternGridDataObj.put("deleteUrl","DescriptorPatternThreshold/data/EgDefinePatternJson.jsp?operation=deleteThresholds&pattName="+EgURLEncoder.encode( StringUtils.encodeSecurityChar(pattName),"UTF-8")+"&from=update&testName="+tmpTestName);
					//descPatternGridDataObj.put("TestNameValue",tmpTestName);
					descPatternGridDataArr.add(descPatternGridDataObj);
				}
			}
		}
		rootJson.put("descPatternGridDataArr",descPatternGridDataArr);
	}
	else
	{
		rootJson.put("isNoData",true);
		rootJson.put("No_data",_mapping.getTextDescription("admin.threshold.There are no descriptor patterns currently available"));
	}
	out.println(rootJson.toString());

	
	if(request.getQueryString()!=null)
		session.setAttribute("adminLastAccessedURL","/final/admin/EgDescriptorPatternThresholds.jsp?"+request.getQueryString());
	else session.setAttribute("adminLastAccessedURL","/final/admin/EgDescriptorPatternThresholds.jsp");

%>



