
<%@ include file="../../EgTrackerAJSON.jsp" %>
<%@ page import = "java.util.*" %>
<%@ page import="com.eg.EgRoleInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import="com.eg.EgName"%>
<%@ page import="com.eg.EgInstallInfo"%>
<%@ page import="com.eg.EgThresholdInfo"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import="com.egurkha.ini.*" %>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="java.sql.*" %>
<%@ page import="net.sf.json.*"%>
<%@ page import ="egurkha.EgDbAdapterUI"%>
<%@ page import ="com.eg.EgDbAdapterTypeUI"%>
<%@ page import="com.eg.UpdateAndTransmitTrendInfo" %>
<%@ page import="com.eg.EgTesterInfo" %>
<%@ page import="com.eg.EgConfigInfo" %>
<%@ page import="com.eg.EgDiscInfo2" %>
<%@ page import="com.eg.EgServerGroupBean" %>
<%@ page import = "com.egurkha.admin.AuditLogThread"%>
<%@ page import="com.eg.MappingNameSorter"%>


<jsp:useBean id="prgBean" class="egurkha.EgTestParamBean" scope="page" />

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

<%!
	EgSpecsInfo egSpecs = new EgSpecsInfo("manager");
	EgTesterInfo testerInfo = new EgTesterInfo("manager");
	EgThresholdInfo egThresh = new EgThresholdInfo("manager");
	EgTablesInfo tablesInfo = new EgTablesInfo("manager");
%>

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

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


	JSONObject rootJson= new JSONObject();
	JSONObject hiddenObj= new JSONObject();

	IniUI iniUI = IniUI.getInstance();
	String subject = "DESCRIPTOR_DEFAULT_THRESHOLDS";

	IniFile threshIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
	String[] globalVars = threshIni.getVariables(subject);

	//user language
	String userLanguage = iniUI.getDefaultLanguage();
	ArrayList tmpList = new ArrayList();

	if (_user != null)
	{
		userLanguage = _user.getLanguage();
	}
	
	EgMappingInfo mappingInfo = new EgMappingInfo(userLanguage);
	String strTestName = request.getParameter("testName");
	String from = request.getParameter("from");
	EgDbAdapterUI egDb;
	EgDbInfo dbInfo=new EgDbInfo("manager");
	EgThresholdInfo dbThresh =new EgThresholdInfo("manager");
	EgTesterInfo testerInfo =new EgTesterInfo("manager");
	EgDiscInfo2 discInfo2 = new EgDiscInfo2("manager");
	EgConfigInfo configInfo = new EgConfigInfo("manager");
	EgServerGroupBean serverGrpBean = new EgServerGroupBean();
	MappingNameSorter sorter = new MappingNameSorter(userLanguage);

	ResultSet rs = null;
	String status ="";
	ArrayList threshGrpTestList = new ArrayList();
	TreeSet threshGrpTreeSet = serverGrpBean.getTestColnComponentsForServerType();
	threshGrpTestList.addAll(threshGrpTreeSet);
	UpdateAndTransmitTrendInfo updateHelper = new UpdateAndTransmitTrendInfo();
	IniFile servicesIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_services.ini");
	boolean isUpdateToDb= "true".equalsIgnoreCase(servicesIni.getValue("MISC_ARGS","updateDefaultThreshToDb"));
	ArrayList globalThresholds=testerInfo.getGlobalThresholds();
	if (globalThresholds == null || globalThresholds.isEmpty())
	{
		globalThresholds = new ArrayList();
	}

	String user_thresh = "USER_THRESHOLDS";
	String descr_thresh = "DESCRIPTOR_THRESHOLDS"; // SIFY

	/*
		NetworkTest=
		Avg_delay:mix:-1:-/-/0.3&3*sqc:longterm:HML,
		Min_delay:mix:-1:-1:immediate:HML,
		Pkt_loss_pct:mix:-1:60/-/-:shortterm:HML,
		Availability:mix:1/-/-:-1:immediate:HML
	*/
	hiddenObj.put("action",from);
	if (!StringUtils.isNull(from) && (from.equals("first") || from.equals("modify")))
	{
		String reqCompType = request.getParameter("compType");
		String reqTest = request.getParameter("testName");
		reqTest = (reqTest != null && !reqTest.equals("null") && reqTest.length()>0 ? reqTest:"");
		reqCompType = (reqCompType != null && !reqCompType.equals("null") && reqCompType.length()>0 ? reqCompType:"");
		String[] compTypesArray = egRoleInfo.getServerTypes(); //get the comp types for the specified User
		JSONObject screenLabels= new JSONObject();
		//if (from.equals("first")){
		if (compTypesArray != null && compTypesArray.length > 0)
		{
			rootJson.put("isManagedCompAvailable",true);
			if(!StringUtils.isNull(from) && from.equalsIgnoreCase("first"))
			{
				ArrayList compTypes = new ArrayList();
				ArrayList testForServer = new ArrayList();
				for(int i=0;i<compTypesArray.length;i++)
				{
					String tempTestList[] = egSpecs.getTestsForServer(compTypesArray[i]);
					if(tempTestList != null && tempTestList.length > 0)
					{
						ArrayList tests = new ArrayList(Arrays.asList(tempTestList));
						//if(!globalThresholds.containsAll(tests) && !compTypes.contains(compTypesArray[i])) 
						if(!compTypes.contains(compTypesArray[i])) 
						{
							//remove the global threshold tests from the "tests" List 
							compTypes.add(compTypesArray[i]);
							if(reqCompType.equalsIgnoreCase(compTypesArray[i]))
							{
								testForServer = tests;
								//testForServer.removeAll(globalThresholds);
							}
						}
					}
				}
				ArrayList configTests = egSpecs.getConfigTestsForServer(reqCompType);
				if(configTests != null)
					testForServer.removeAll(configTests);
				screenLabels.put("admin.groups.Component type",_mapping.getTextDescription("admin.groups.Component type"));
				JSONArray grpCompTypeArr = new JSONArray();
				JSONObject grpCompTypeObj = new JSONObject();
				if(compTypes.size()>0)
				{
					grpCompTypeObj.put("displayField",_mapping.getTextDescription("admin.common.Choose a component type"));
					grpCompTypeObj.put("valueField","-1");
					grpCompTypeArr.add(grpCompTypeObj);
				}
				tmpList = sorter.getSortedCompTypeList(compTypes);

				for(int i=0;i<tmpList.size();i++)
				{
					grpCompTypeObj = new JSONObject();
					EgName nameObj = (EgName)tmpList.get(i);
					String tmpVal = nameObj.getActualName();
					String tmpDis = nameObj.getLocalName();
					grpCompTypeObj.put("displayField",tmpDis);
					grpCompTypeObj.put("valueField",tmpVal);
					grpCompTypeArr.add(grpCompTypeObj);
					if(tmpVal.equalsIgnoreCase(reqCompType))
					{
						rootJson.put("selectedCType",reqCompType);
					}
				}

				rootJson.put("grpCompTypeArr",grpCompTypeArr);
				JSONArray grpTestNameArr = new JSONArray();
				JSONObject grpTestNameObj = new JSONObject();
				if(StringUtils.isNull(reqCompType))
				{
					grpTestNameObj.put("displayField",_mapping.getTextDescription("admin.groups.Not Applicable"));
					grpTestNameObj.put("valueField","-1");
					grpTestNameArr.add(grpTestNameObj);
				}
				else if(testForServer != null && testForServer.size()>0)
				{
					grpTestNameObj.put("displayField",_mapping.getTextDescription("admin.groups.Choose a test  name"));
					grpTestNameObj.put("valueField","-1");
					grpTestNameArr.add(grpTestNameObj);
					tmpList = sorter.getSortedTestList(testForServer);	
					for(int i=0;i<tmpList.size();i++)
					{
						grpTestNameObj = new JSONObject();
						EgName nameObj = (EgName)tmpList.get(i);
						String tmpVal = nameObj.getActualName();
						String tmpDis = nameObj.getLocalName();
						if(EgInstallInfo.isConfigTest(tmpVal))
						{
							continue;
						}
						grpTestNameObj.put("displayField",tmpDis);
						grpTestNameObj.put("valueField",tmpVal);
						grpTestNameArr.add(grpTestNameObj);
						if (tmpVal.equalsIgnoreCase(reqTest))
						{
							rootJson.put("selectedTestName",reqTest);
						}
					}
				}
				else if(testForServer != null && testForServer.size() == 0)
				{
					grpTestNameObj.put("displayField",_mapping.getTextDescription("admin.groups.Not Applicable"));
					grpTestNameObj.put("valueField","-1");
					grpTestNameArr.add(grpTestNameObj);
				}
				rootJson.put("grpTestNameArr",grpTestNameArr);
				if(!StringUtils.isNull(reqCompType) && !StringUtils.isNull(reqTest))
				{
					rootJson.put("text_box","true");
				}

				Vector vecPatterns = new Vector();
				if(globalVars != null && globalVars.length > 0)
				{
					for(int t=0;t<globalVars.length;t++)
					{
						String tmpTestName = globalVars[t];
						if(tmpTestName != null && tmpTestName.indexOf(":") != -1)
						{
							String pattName = tmpTestName.substring(tmpTestName.indexOf(":")+1);
							if(!StringUtils.isNull(pattName) && !vecPatterns.contains(pattName))
							{
								vecPatterns.add(pattName);
							}
						}
					}

					if (vecPatterns != null && vecPatterns.size() > 0)
					{
						String[] arr_len = new String[vecPatterns.size()];
						String[] arr_Threshgroup = (String[]) vecPatterns.toArray(arr_len);
					}
					String threshGrpString = StringUtils.getArrayAsString(globalVars); 
					rootJson.put("patternNames",threshGrpString);

				}
			}
	

			String patternName = request.getParameter("pattName");
			if (StringUtils.isNull(patternName))
			{
				patternName = "";
			}

			if (!StringUtils.isNull(patternName))
			{
				patternName = StringUtils.decodeSecurityChar(patternName);
				rootJson.put("pattName",patternName);
			}
			if (from.equalsIgnoreCase("modify"))
			{
				if(!StringUtils.isNull(patternName) && patternName.length() > 0)
				{
					screenLabels.put("admin.threshold.Descriptor Name",_mapping.getTextDescription("admin.threshold.Descriptor Name"));
					rootJson.put("patternName",patternName);
					rootJson.put("displayPattName","<b>"+patternName+"</b>");
				}
			}

			if (!StringUtils.isNull(strTestName) )
			{
				rootJson.put("testName",strTestName);
				rootJson.put("selectedTest",strTestName);
				rootJson.put("displayTestName",_mapping.getTestDescription(strTestName));
				
				JSONObject measureDataObj = new JSONObject();
				IniFile defaultIniObj = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
				String defaultThreshold = null;
				//defaultThreshold = defaultIniObj.getValue("DEFAULT_THRESHOLDS",strTestName);
				hiddenObj.put("strTestName",strTestName);

			String strVariable = strTestName+":"+StringUtils.encodeSecurityChar(patternName);
			defaultThreshold = defaultIniObj.getValue(subject,strVariable);
			if(StringUtils.isNull(defaultThreshold))
			{
				strVariable = strTestName+":"+patternName;
				defaultThreshold = defaultIniObj.getValue(subject,strVariable);
			}

			if(StringUtils.isNull(defaultThreshold))
			{
				List filterKeysList = Arrays.asList(globalVars);
				ArrayList filterKeys = new ArrayList();
				for (int fk = 0; fk < filterKeysList.size(); fk++)
				{
					String key = (String) filterKeysList.get(fk);
					if (!com.egurkha.util.StringUtils.isNull(key) && key.startsWith(strTestName+":") && key.indexOf("*") != -1)
					{
						String wildCardStr = key.substring(key.indexOf(":")+1);
						if (!com.egurkha.util.StringUtils.isNull(wildCardStr) && !filterKeys.contains(wildCardStr))
						{
							filterKeys.add(wildCardStr);
						}
					}
				}

				if (filterKeys != null && filterKeys.size() > 0)
				{
					for (int k=0;k<filterKeys.size() ;k++ )
					{
						String searchString = (String) filterKeys.get(k);
						if (com.egurkha.util.EgUtilities.isMatch(patternName, searchString) )
						{
							defaultThreshold = defaultIniObj.getValue(subject,strTestName+":"+searchString);
							break;
						}
					}
				}
				if(StringUtils.isNull(defaultThreshold))
				{
					defaultThreshold = defaultIniObj.getValue("DEFAULT_THRESHOLDS",strTestName);
				}
			}








				String measCount = "";
				EgTablesInfo tablesInfo = new EgTablesInfo("manager");

				boolean heading_flag = false;
				ArrayList aListTestWithNoThresholds = new ArrayList();
				boolean cellFlag = false;
				StringTokenizer st = new StringTokenizer(defaultThreshold,",");
				measCount = Integer.toString(st.countTokens());
				JSONArray threshValArr = new JSONArray();
				JSONArray measureValArr = new JSONArray();
				JSONObject hiddenDataObj = new JSONObject();
				JSONObject toolTipMsg = new JSONObject();

				while (st.hasMoreTokens())
				{
					JSONObject measHiddenObj = new JSONObject();
					measHiddenObj.put("testName",strTestName);
					measHiddenObj.put("strTestName",strTestName);
					measHiddenObj.put("old_testName",strTestName);

					String strTok = st.nextToken();
					StringTokenizer st1 = new StringTokenizer(strTok,":");
					while (st1.hasMoreTokens())
					{
						JSONObject threshValObj = new JSONObject();
						JSONObject tmpObject = new JSONObject();
						String measure = st1.nextToken();
						String policy = st1.nextToken();
						String min = st1.nextToken();
						String max = st1.nextToken();
						String alarmPolicy = st1.nextToken();
						threshValObj.put("AlarmPolicy",alarmPolicy);
						String lastToken = st1.nextToken();
						String unit = tablesInfo.getUnitForMeasure(strTestName,measure);
						measHiddenObj.put("alarmPolicy", alarmPolicy);
						measHiddenObj.put("measure", measure);

						String criticalMsg = mappingInfo.getThresholdPriorityDescription(strTestName+":"+measure+":Critical");
						
						if (!StringUtils.isNull(criticalMsg))
						{
							threshValObj.put("isToolTip",true);

							toolTipMsg.put("toolTipCritical",criticalMsg);
							criticalMsg = mappingInfo.getThresholdPriorityDescription(strTestName+":"+measure+":Major");

							toolTipMsg.put("toolTipMajor",criticalMsg);
						}
						else
						{
							threshValObj.put("isToolTip",false);
						}

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

						measHiddenObj.put("absMinCritical", absMinCritical);
						measHiddenObj.put("relMinCritical", relMinCritical);
						measHiddenObj.put("absMinMajor", absMinMajor);
						measHiddenObj.put("relMinMajor", relMinMajor);
						measHiddenObj.put("absMinMinor", absMinMinor);
						measHiddenObj.put("relMinMinor", relMinMinor);
						measHiddenObj.put("absMaxCritical", absMaxCritical);
						measHiddenObj.put("relMaxCritical", relMaxCritical);
						measHiddenObj.put("absMaxMajor", absMaxMajor);
						measHiddenObj.put("relMaxMajor", relMaxMajor);
						measHiddenObj.put("absMaxMinor", absMaxMinor);
						measHiddenObj.put("relMaxMinor", relMaxMinor);
						hiddenDataObj.put(measure,measHiddenObj);
						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);
							continue;
						}

						if (!heading_flag)
						{
							heading_flag = true;
						}
						String tmpThreshData = mappingInfo.getMeasureDescription(strTestName,measure)+"("+unit+")";
						tmpObject.put("measure",tmpThreshData);

						String tmpMinThresh  = "";
						if(!minCritical.equals("-") || !minMajor.equals("-") || !minMinor.equals("-"))
						{
							tmpMinThresh = minCritical+"$"+minMajor+"$"+minMinor;
						}
						tmpObject.put("MinThresh",tmpMinThresh);
						String tmpMaxThresh = "";

						if(!maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
						{					tmpMaxThresh = maxCritical+"$"+maxMajor+"$"+maxMinor;

						}
						tmpObject.put("MaxThresh",tmpMaxThresh);
						tmpObject.put("alarmPolicy",alarmPolicy);

						threshValArr.add(tmpObject);

						String tempThresh = "";
						boolean isMinData = false;
						if(!minCritical.equals("-")  || !minMajor.equals("-") || !minMinor.equals("-"))
						{
							tempThresh += "Min|"+minCritical+"|"+minMajor+"|"+minMinor;
							isMinData = true;
						}

						if(!maxCritical.equals("-") || !maxMajor.equals("-") || !maxMinor.equals("-"))
						{
							if (isMinData)
							{
								tempThresh += "#Max|"+maxCritical+"|"+maxMajor+"|"+maxMinor;
							}
							else
							{
								tempThresh += "Max|"+maxCritical+"|"+maxMajor+"|"+maxMinor;
							}
						}
						measureDataObj.put(mappingInfo.getMeasureDescription(strTestName,measure),measure);
						threshValObj.put("Measure",mappingInfo.getMeasureDescription(strTestName,measure)+"  ("+unit+")");
						threshValObj.put("Threshold",tempThresh);
						measureValArr.add(threshValObj);
					}
				}

				rootJson.put("toolTipMsg",toolTipMsg);
				rootJson.put("hiddenDataObj",hiddenDataObj);
				rootJson.put("measureValArr",measureValArr);
				rootJson.put("threshValArr",threshValArr);

				hiddenObj.put("measCount",measCount);
				if (aListTestWithNoThresholds != null && !aListTestWithNoThresholds.isEmpty())
				{
					JSONArray noMeasureValArr = new JSONArray();

					int d=0;
					while(d<aListTestWithNoThresholds.size())
					{
						JSONObject noMeasureThreshValObj = new JSONObject();
						String strMeasure1 = "";
						String strMeasure2 = "";
						String strMeasure = (String)aListTestWithNoThresholds.get(d);
						int count = d;
						if(!StringUtils.isNull(strMeasure))
						{
							measureDataObj.put(mappingInfo.getMeasureDescription(strTestName,strMeasure),strMeasure);
							strMeasure = mappingInfo.getMeasureDescription(strTestName,strMeasure);
						}
						else
							strMeasure = "";
						count = d+1;
						if(count < aListTestWithNoThresholds.size())
						{
							strMeasure1 = (String)aListTestWithNoThresholds.get(count);
							if(!StringUtils.isNull(strMeasure1))
							{
								measureDataObj.put(mappingInfo.getMeasureDescription(strTestName,strMeasure1),strMeasure1);
								strMeasure1 = mappingInfo.getMeasureDescription(strTestName,strMeasure1);
							}
						}
						count = d+2;
						if(count < aListTestWithNoThresholds.size())
						{
							strMeasure2 = (String)aListTestWithNoThresholds.get(count);
							if(!StringUtils.isNull(strMeasure2))
							{
								measureDataObj.put(mappingInfo.getMeasureDescription(strTestName,strMeasure2),strMeasure2);
								strMeasure2 = mappingInfo.getMeasureDescription(strTestName,strMeasure2);
							}
						}

						noMeasureThreshValObj.put("Measure1",strMeasure);
						noMeasureThreshValObj.put("Measure2",strMeasure1);
						noMeasureThreshValObj.put("Measure3",strMeasure2);
						noMeasureValArr.add(noMeasureThreshValObj);
						d = count+1;
					}
					rootJson.put("noMeasureValArr",noMeasureValArr);
				}
				rootJson.put("measureDataObj",measureDataObj);
			}
			rootJson.put("screenLabels",screenLabels);
			rootJson.put("hiddenObj",hiddenObj);
		}
		else
		{
			rootJson.put("isManagedCompAvailable",false);
			rootJson.put("NoData",_mapping.getTextDescription("admin.threshold.No Managed Components"));
		}
	}
	else if (!StringUtils.isNull(strTestName) && !StringUtils.isNull(from) && from.equals("update"))
	{
		IniFile defaultIniObj = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
		String threshold = request.getParameter("threshold");
		String operation = request.getParameter("operation");
		String strPattName = request.getParameter("pattName");
		String subjectVal = "Newtarget_Update_EgThresholdManager";
		if(!StringUtils.isNull(strPattName))
		{
			strPattName = StringUtils.decodeSecurityChar(strPattName);
		}

		prgBean.createFile("eg_thresholds.ini");
		String[] userThreshVal = prgBean.getVariables(user_thresh);
		ArrayList getAllCompsForServer = getAllManagedComps();

		ArrayList userThreshList = new ArrayList();
		ArrayList descThreshList = new ArrayList();
		//ArrayList hostLevelTests = (ArrayList) session.getAttribute("sessListHostLevelTests");
		List existGlobalDescList =  Arrays.asList(defaultIniObj.getVariables(subject));

		if(userThreshVal.length > 0)
		{
			for(int r=0; r<userThreshVal.length; r++)
			{
				if(userThreshVal[r].startsWith(strTestName))
				{
					userThreshList.add(userThreshVal[r]);
				}
			}
		}
		String []descThreshVal = prgBean.getVariables(descr_thresh);
		if(descThreshVal.length > 0)
		{
			for(int r=0; r<descThreshVal.length; r++)
			{
				if(descThreshVal[r].startsWith(strTestName))
				{
					descThreshList.add(descThreshVal[r]);
				}
			}
		}

		ArrayList infoBasedGroupList = new ArrayList();
		ArrayList groupTestsList = new ArrayList();
		ArrayList tmpManagedInfos = new ArrayList();
		TreeSet managedInfos = serverGrpBean.getAllManagedInfosForTest(strTestName);
		tmpManagedInfos.addAll(managedInfos);
		for(int g=0;g<getAllCompsForServer.size(); g++)
		{
			String component = (String) getAllCompsForServer.get(g);
			String tmpComp = "";
			if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
			{
				tmpComp = component.substring(0,component.indexOf(":"));
				tmpComp +=":NULL";
			}
			else
			{
				tmpComp = component;
			}

			if(!serverGrpBean.isServerAssociatedToTest(component,strTestName) && serverGrpBean.isServerAssociatedToTestUI(component,strTestName))
			{
				if(tmpManagedInfos != null && tmpManagedInfos.size() > 0)
				{
					for(int v=0;v<tmpManagedInfos.size();v++)
					{
						String vecInfo = (String) tmpManagedInfos.get(v);
						infoBasedGroupList.add(strTestName+":"+tmpComp+"#"+vecInfo);
					}
				}
			}

			if(serverGrpBean.isServerAssociatedToTest(component,strTestName))
			{
				groupTestsList.add(strTestName+":"+tmpComp);
				continue;
			}
		}

		Hashtable ht = new Hashtable();
		boolean isSaveIni = false;
		egDb=EgDbAdapterTypeUI.getObject();
		try
		{
			boolean isConnected = false;
			status = egDb.setConnection();
			if(status.equals("CONNECTED"))
			{
				isConnected = true;
			}
			if(isConnected)
			{
				String query ="SELECT TRGT_HOST,PORT_NO,SITE_NAME,INFO,MSMT_HOST FROM MEASURE_LAST WHERE TEST_NAME='"+strTestName+"'" ;
				rs = egDb.SelectExec(query);
				while(rs.next())
				{
					String hostVal = rs.getString(1);
					String portVal = rs.getString(2);
					String siteVal = rs.getString(3);
					String infoVal = rs.getString(4);
					String msmthostVal = rs.getString(5);

					String updateDbData = hostVal+"#&#"+portVal+"#&#"+siteVal+"#&#"+StringUtils.encodeSecurityChar(infoVal)+"#&#"+msmthostVal+"#&#"+strTestName;
					int r = infoVal.indexOf(EgConfigInfo.infoFieldSeparator);
					String str_info="";
					String sidVal="";
					if(r != -1)
					{
						str_info = infoVal.substring(r+1).trim();
						sidVal = infoVal.substring(0,r);
					}
					if(StringUtils.isNull(sidVal))
					{
						ht.put(hostVal+":"+portVal+"#"+infoVal+"#"+msmthostVal,updateDbData);
					}
					else
					{
						ht.put(hostVal+":"+portVal+":"+sidVal+"#"+infoVal+"#"+msmthostVal,updateDbData);
					}
				}
			}
			rs.close();
			egDb.releaseConnection(false);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		catch(Exception e)
		{
			if(rs != null)
			{
				rs.close();
			}
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		ArrayList htKeyValues = new ArrayList();
		if(ht != null && ht.size() > 0)
		{
			Iterator iterAll = ht.keySet().iterator();
			while(iterAll.hasNext())
			{
				String tempKeys = (String) iterAll.next();
				htKeyValues.add(tempKeys);
			}
		}


		if (!StringUtils.isNull(operation) && operation.equals("newpattern"))
		{
			IniFile defaultIni = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
			String defaultThreshold = defaultIni.getValue("DEFAULT_THRESHOLDS",strTestName);
			String variable = strTestName+":"+StringUtils.encodeSecurityChar(strPattName);

			/* code for auditlog starts */
			AuditLogThread auditLogThread = new AuditLogThread();	
			auditLogThread.setValue("Category","Admin");
			auditLogThread.setValue("User_id",_user.getLoginID());
			auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());
			auditLogThread.setValue("Module","Thresholds");
			auditLogThread.setValue("Activity","Descriptor Pattern");
			auditLogThread.setValue("Description","Descriptor pattern (" + strPattName+") has been created");
			auditLogThread.sendItToDB();
			/* code for auditlog ends */

			defaultIni.setValue(subject,variable,defaultThreshold);
			defaultIni.saveFile();
			EgConfigFilesSync.releaseInstance(defaultIni);
			rootJson.put("successUpdate",true);
		}
		if (!StringUtils.isNull(operation) && operation.equals("updatepattern"))
		{
			IniFile defaultIni = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
			String defaultThreshold = defaultIni.getValue("DEFAULT_THRESHOLDS",strTestName);
			String variable = strTestName+":"+StringUtils.encodeSecurityChar(strPattName);

			/* code for auditlog starts */
			AuditLogThread auditLogThread = new AuditLogThread();	
			auditLogThread.setValue("Category","Admin");
			auditLogThread.setValue("User_id",_user.getLoginID());
			auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());
			auditLogThread.setValue("Module","Thresholds");
			auditLogThread.setValue("Activity","Descriptor Pattern");
			auditLogThread.setValue("Description","Descriptor pattern (" + strPattName+") has been created");
			auditLogThread.sendItToDB();
			/* code for auditlog ends */

			// new ini entry code starts here
			if(!StringUtils.isNull(strTestName) && !globalThresholds.contains(strTestName))
			{
				IniFile serIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_threshupdate.ini");
				for(int ct = 0;ct<getAllCompsForServer.size();ct++)
				{
					String tempComp = (String)getAllCompsForServer.get(ct);
					String tmpTrgtHost = tempComp.substring(0,tempComp.indexOf(":"));
					if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
					{
						if(!tempComp.endsWith(":NULL"))
						{
							tempComp = tempComp.substring(0,tempComp.indexOf(":"));
							tempComp+=":NULL";
						}
					}
					if(ht != null && ht.size() > 0)
					{
						for(int h=0;h<htKeyValues.size();h++)
						{
							String htKey = (String) htKeyValues.get(h);
							String infoData = htKey.substring(htKey.indexOf("#")+1);
							infoData = infoData.substring(0,infoData.indexOf("#"));
							int r = infoData.indexOf(EgConfigInfo.infoFieldSeparator);
							String str_info="";
							String sidVal="";
							if(r != -1)
							{
								str_info = infoData.substring(r+1).trim();
								sidVal = infoData.substring(0,r);
							}

							if(htKey.startsWith(tempComp))
							{
								if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
								{
									String strUserVal = strTestName+":"+tmpTrgtHost;
									String strGrpVal = strTestName+":"+tempComp;
									String nickWithNullPort = tmpTrgtHost+":NULL";
									String strDescVal = strTestName+":"+nickWithNullPort+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+nickWithNullPort+"#"+str_info;
									if(userThreshList != null && userThreshList.contains(strUserVal))
									{
										break;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strGrpVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info))
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName))
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
								else
								{
									String strUserVal = strTestName+":"+tempComp;
									String strDescVal = strTestName+":"+tempComp+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+tempComp+"#"+str_info;

									if((userThreshList != null && userThreshList.contains(strUserVal))  )
									{
										break;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strUserVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info))
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName))
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
							}
						}
					}
				}
				if(isSaveIni)
				{
					serIniWr.saveFile();
				}
				EgConfigFilesSync.releaseInstance(serIniWr);
			}

			String descIniVal = defaultIni.getValue(subject,strTestName+":"+strPattName);
			if(!StringUtils.isNull(descIniVal))
			{
				defaultIni.deleteValue(subject,strTestName+":"+strPattName);
			}
			defaultIni.setValue(subject,variable,defaultThreshold);
			defaultIni.saveFile();
			EgConfigFilesSync.releaseInstance(defaultIni);
			rootJson.put("successUpdate",true);
		}
		else if (!StringUtils.isNull(operation) && operation.equals("modifypattern"))
		{
			String strApplyAllMeasure = request.getParameter("allMeasure");
			String measure = threshold.substring(0,threshold.indexOf(":"));
			measure+=":";
			String newDefaultThreshold = "";
			StringBuffer strbuffer = new StringBuffer();
			String defaultThreshold = defaultIniObj.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",strTestName+":"+StringUtils.encodeSecurityChar(strPattName));
			if(StringUtils.isNull(defaultThreshold))
			{
				defaultThreshold = defaultIniObj.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",strTestName+":"+strPattName);
			}
			if(StringUtils.isNull(defaultThreshold))
			{
				defaultThreshold = defaultIniObj.getValue("DEFAULT_THRESHOLDS",strTestName);
			}

			ArrayList previousValues = new ArrayList();
			ArrayList currentValues = new ArrayList();
			StringTokenizer st = new StringTokenizer(defaultThreshold,",");
			if(!StringUtils.isNull(strApplyAllMeasure))
			{
				String tmpThreshold = threshold.substring(threshold.indexOf(":")+1,threshold.lastIndexOf(":"));
				String commonThreshVal = tmpThreshold.substring(0,tmpThreshold.lastIndexOf(":"));
				while (st.hasMoreTokens())
				{
					String strTok = st.nextToken();
					previousValues.add(strTok);
					if (strTok.startsWith(measure+":"))
					{
						strbuffer.append(threshold).append(",");
						currentValues.add(threshold);
					}
					else
					{
						String tmpMeasureToken = strTok.substring(0,strTok.indexOf(":"));
						String tmpHmlToken = strTok.substring(strTok.lastIndexOf(":")+1);
						String tmpToken = strTok.substring(strTok.indexOf(":")+1,strTok.lastIndexOf(":"));
						String tmpAlarmToken = tmpToken.substring(tmpToken.lastIndexOf(":")+1);
						StringBuffer strBuffThresh = new StringBuffer();
						strBuffThresh.append(tmpMeasureToken);
						strBuffThresh.append(":");
						strBuffThresh.append(commonThreshVal);
						strBuffThresh.append(":");
						strBuffThresh.append(tmpAlarmToken);
						strBuffThresh.append(":");
						strBuffThresh.append(tmpHmlToken);
						strTok = strBuffThresh.toString();
						strbuffer.append(strTok).append(",");
						currentValues.add(strTok);
					}
				}
			}
			else
			{
				while (st.hasMoreTokens())
				{
					String strTok = st.nextToken();
					previousValues.add(strTok);
					if (strTok.startsWith(measure))
					{
						strbuffer.append(threshold).append(",");
					}
					else
					{
						strbuffer.append(strTok).append(",");
					}
				}
			}

			/* code for auditlog starts */
			AuditLogThread auditLogThread = new AuditLogThread();	
			auditLogThread.setValue("Category","Admin");
			auditLogThread.setValue("User_id",_user.getLoginID());
			auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());
			auditLogThread.setValue("Module","Thresholds");

			if(!StringUtils.isNull(strApplyAllMeasure))
			{
				for(int i=0;i<previousValues.size();i++)
				{
					String preData = (String) previousValues.get(i);
					String currData = (String) currentValues.get(i);
					ArrayList tempPrevious = StringUtils.egTokenizer(preData,":");
					ArrayList tempCurrent = StringUtils.egTokenizer(currData,":");

					String auditMeasure = tempPrevious.get(0).toString().trim();
					auditMeasure = mappingInfo.getMeasureDescription(strTestName,auditMeasure);
					String previousMin = tempPrevious.get(2).toString().trim();
					String previousMax = tempPrevious.get(3).toString().trim();
					String alarmPolicyPrevious = tempPrevious.get(4).toString().trim();

					String currentMin = tempCurrent.get(2).toString().trim();
					String currentMax = tempCurrent.get(3).toString().trim();
					String alarmPolicyCurrent = tempCurrent.get(4).toString().trim();

					if(!previousMin.equals(currentMin))
					{
						if(previousMin.equals("-1"))
						{
							previousMin = "none";
						}
						if(currentMin.equals("-1"))
						{
							currentMin = "none";
						}
						auditLogThread.setPreviousValue(auditMeasure,"Minimum-Threshold " + previousMin);
						auditLogThread.setCurrentValue(auditMeasure,"Minimum-Threshold " + currentMin);
					}

					if(!previousMax.equals(currentMax))
					{
						if(previousMax.equals("-1"))
						{
							previousMax = "none";
						}
						if(currentMax.equals("-1"))
						{
							currentMax = "none";
						}
						auditLogThread.setPreviousValue(auditMeasure,"Maximum-Threshold " + previousMax);
						auditLogThread.setCurrentValue(auditMeasure,"Maximum-Threshold " + currentMax);
					}

					if(!alarmPolicyPrevious.equals(alarmPolicyCurrent))
					{
						auditLogThread.setPreviousValue(auditMeasure,"Alarms " + alarmPolicyPrevious);
						auditLogThread.setCurrentValue(auditMeasure,"Alarms " + alarmPolicyCurrent);
					}
				}
			}
			else
			{
				for(int i=0;i<previousValues.size();i++)
				{
					String preData = (String) previousValues.get(i);
					if(preData.startsWith(measure))
					{
						ArrayList tempPrevious = StringUtils.egTokenizer(preData,":");
						ArrayList tempCurrent = StringUtils.egTokenizer(threshold,":");

						String auditMeasure = tempPrevious.get(0).toString().trim();
						auditMeasure = mappingInfo.getMeasureDescription(strTestName,auditMeasure);
						String previousMin = tempPrevious.get(2).toString().trim();
						String previousMax = tempPrevious.get(3).toString().trim();
						String alarmPolicyPrevious = tempPrevious.get(4).toString().trim();

						String currentMin = tempCurrent.get(2).toString().trim();
						String currentMax = tempCurrent.get(3).toString().trim();
						String alarmPolicyCurrent = tempCurrent.get(4).toString().trim();

						if(!previousMin.equals(currentMin))
						{
							if(previousMin.equals("-1"))
							{
								previousMin = "none";
							}
							if(currentMin.equals("-1"))
							{
								currentMin = "none";
							}
							auditLogThread.setPreviousValue(auditMeasure,"Minimum-Threshold " + previousMin);
							auditLogThread.setCurrentValue(auditMeasure,"Minimum-Threshold " + currentMin);
						}

						if(!previousMax.equals(currentMax))
						{
							if(previousMax.equals("-1"))
							{
								previousMax = "none";
							}
							if(currentMax.equals("-1"))
							{
								currentMax = "none";
							}
							auditLogThread.setPreviousValue(auditMeasure,"Maximum-Threshold " + previousMax);
							auditLogThread.setCurrentValue(auditMeasure,"Maximum-Threshold " + currentMax);
						}

						if(!alarmPolicyPrevious.equals(alarmPolicyCurrent))
						{
							auditLogThread.setPreviousValue(auditMeasure,"Alarms " + alarmPolicyPrevious);
							auditLogThread.setCurrentValue(auditMeasure,"Alarms " + alarmPolicyCurrent);
						}
					}
				}
			}
			auditLogThread.setValue("Activity","Configure Thresholds");
			if (!StringUtils.isNull(strTestName))
			{
				auditLogThread.setValue("Description","The thresholds for descriptor pattern of " + mappingInfo.getTestDescription(strTestName) + " test of " + strPattName + " has been modified");
			}
			else
			{
				auditLogThread.setValue("Description","The thresholds for descriptor pattern of " + strPattName + " has been modified");
			}
			auditLogThread.sendItToDB();
		
			/* code for auditlog ends */

			// new ini entry code starts here
			if(!StringUtils.isNull(strTestName) && !globalThresholds.contains(strTestName))
			{
				IniFile serIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_threshupdate.ini");
				for(int ct = 0;ct<getAllCompsForServer.size();ct++)
				{
					String tempComp = (String)getAllCompsForServer.get(ct);
					String tmpTrgtHost = tempComp.substring(0,tempComp.indexOf(":"));
					if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
					{
						if(!tempComp.endsWith(":NULL"))
						{
							tempComp = tempComp.substring(0,tempComp.indexOf(":"));
							tempComp+=":NULL";
						}
					}
					if(ht != null && ht.size() > 0)
					{
						for(int h=0;h<htKeyValues.size();h++)
						{
							String htKey = (String) htKeyValues.get(h);
							String infoData = htKey.substring(htKey.indexOf("#")+1);
							infoData = infoData.substring(0,infoData.indexOf("#"));
							int r = infoData.indexOf(EgConfigInfo.infoFieldSeparator);
							String str_info="";
							String sidVal="";
							if(r != -1)
							{
								str_info = infoData.substring(r+1).trim();
								sidVal = infoData.substring(0,r);
							}

							if(htKey.startsWith(tempComp))
							{
								if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
								{
									String strUserVal = strTestName+":"+tmpTrgtHost;
									String strGrpVal = strTestName+":"+tempComp;
									String nickWithNullPort = tmpTrgtHost+":NULL";
									String strDescVal = strTestName+":"+nickWithNullPort+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+nickWithNullPort+"#"+str_info;
									if(userThreshList != null && userThreshList.contains(strUserVal))
									{
										break;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strGrpVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info))
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName))
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
								else
								{
									String strUserVal = strTestName+":"+tempComp;
									String strDescVal = strTestName+":"+tempComp+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+tempComp+"#"+str_info;

									if((userThreshList != null && userThreshList.contains(strUserVal))  )
									{
										break;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strUserVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info))
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName))
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
							}
						}
					}
				}
				if(isSaveIni)
				{
					serIniWr.saveFile();
				}
				EgConfigFilesSync.releaseInstance(serIniWr);
			}
			rootJson.put("successUpdate",true);

			//DB updation code ends
			newDefaultThreshold = strbuffer.toString();
			int len = newDefaultThreshold.length()-1;
			newDefaultThreshold = newDefaultThreshold.substring(0,len);

			String strThresholdIni = EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini";
			IniFile ThresholdIniWrite = EgConfigFilesSync.getInstance(strThresholdIni);
			String descIniVal = ThresholdIniWrite.getValue(subject,strTestName+":"+strPattName);
			if(!StringUtils.isNull(descIniVal))
			{
				ThresholdIniWrite.deleteValue(subject,strTestName+":"+strPattName);
			}
			ThresholdIniWrite.setValue(subject,strTestName+":"+StringUtils.encodeSecurityChar(strPattName),newDefaultThreshold);
			ThresholdIniWrite.saveFile();
			EgConfigFilesSync.releaseInstance(ThresholdIniWrite);
		}
		else if(!StringUtils.isNull(operation) && operation.equals("deleteThresholds"))
		{
			String iniSubject = "";
			String iniVariable = "";

			/* code for auditlog starts */
			AuditLogThread auditLogThread = new AuditLogThread();	
			auditLogThread.setValue("Category","Admin");
			auditLogThread.setValue("User_id",_user.getLoginID());
			auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());
			auditLogThread.setValue("Module","Thresholds");
			auditLogThread.setValue("Activity","Delete Descriptor Pattern");
			if(!StringUtils.isNull(strPattName))
			{
				auditLogThread.setValue("Description","The descriptor pattern "+strPattName+" of "+ mappingInfo.getTestDescription(strTestName) + " test has been deleted");
			}
			auditLogThread.sendItToDB();
			/* code for auditlog ends */

			if(!StringUtils.isNull(strTestName) && !globalThresholds.contains(strTestName))
			{
				IniFile serIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_threshupdate.ini");
				for(int ct = 0;ct<getAllCompsForServer.size();ct++)
				{
					String tempComp = (String)getAllCompsForServer.get(ct);
					String tmpTrgtHost = tempComp.substring(0,tempComp.indexOf(":"));
					if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
					{
						if(!tempComp.endsWith(":NULL"))
						{
							tempComp = tempComp.substring(0,tempComp.indexOf(":"));
							tempComp+=":NULL";
						}
					}
					if(ht != null && ht.size() > 0)
					{
						for(int h=0;h<htKeyValues.size();h++)
						{
							String htKey = (String) htKeyValues.get(h);
							String infoData = htKey.substring(htKey.indexOf("#")+1);
							infoData = infoData.substring(0,infoData.indexOf("#"));
							int r = infoData.indexOf(EgConfigInfo.infoFieldSeparator);
							String str_info="";
							String sidVal="";
							if(r != -1)
							{
								str_info = infoData.substring(r+1).trim();
								sidVal = infoData.substring(0,r);
							}

							if(htKey.startsWith(tempComp))
							{
								if(egSpecs.isTestRelevantForServer("Host_system",strTestName))
								{
									String strUserVal = strTestName+":"+tmpTrgtHost;
									String strGrpVal = strTestName+":"+tempComp;
									String nickWithNullPort = tmpTrgtHost+":NULL";
									String strDescVal = strTestName+":"+nickWithNullPort+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+nickWithNullPort+"#"+str_info;
									if(userThreshList != null && userThreshList.contains(strUserVal))
									{
										continue;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strGrpVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info)) 
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName)) 
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
								else
								{
									String strUserVal = strTestName+":"+tempComp;
									String strDescVal = strTestName+":"+tempComp+"#"+StringUtils.encodeSecurityChar(str_info);
									String strGrpDescVal = strTestName+":"+tempComp+"#"+str_info;

									if(userThreshList != null && userThreshList.contains(strUserVal))
									{
										continue;
									}
									else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
									{
										continue;
									}
									else if(groupTestsList != null && groupTestsList.contains(strUserVal))
									{
										continue;
									}
									else
									{
										//if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName) && !existGlobalDescList.contains(strTestName+":"+str_info)) 
										if (com.egurkha.util.EgUtilities.isMatch(str_info, strPattName)) 
										{
											String htValues = (String) ht.get(htKey);
											isSaveIni = true;
											serIniWr.setValue(subjectVal,htValues,strTestName);
										}
									}
								}
							}
						}
					}
				}
				if(isSaveIni)
				{
					serIniWr.saveFile();
				}
				EgConfigFilesSync.releaseInstance(serIniWr);
			}

			String strThresholdIni = EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini";
			IniFile ThresholdIniWrite = EgConfigFilesSync.getInstance(strThresholdIni);
			iniSubject = "DESCRIPTOR_DEFAULT_THRESHOLDS";
			iniVariable = strTestName+":"+StringUtils.encodeSecurityChar(strPattName);
			String defaultDescIniVal = ThresholdIniWrite.getValue(iniSubject,strTestName+":"+strPattName);
			if(!StringUtils.isNull(defaultDescIniVal))
			{
				ThresholdIniWrite.deleteValue(iniSubject,strTestName+":"+strPattName);
			}
			ThresholdIniWrite.deleteValue(iniSubject,iniVariable);
			ThresholdIniWrite.saveFile();
			EgConfigFilesSync.releaseInstance(ThresholdIniWrite);
			EgThresholdInfo.setUpdated();
			rootJson.put("successUpdate",true);
		}
	}

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

	out.println(rootJson.toString());
%>
<%!
	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 ArrayList getAllManagedComps()
	{
		ArrayList aListPorts = new ArrayList();
		EgDiscInfo2 discInfo2 = new EgDiscInfo2("manager");
		List allHosts = discInfo2.getAllManagedComponents();
		for (int i=0;i<allHosts.size();i++)
		{
			String strTemp = "";
			String allData = (String)allHosts.get(i);
			StringTokenizer st = new StringTokenizer(allData,",");
			String serType = st.nextToken();
			String ipVal = st.nextToken();
			String nick = "";
			String port = "";
			String sid = "";
			if(serType.equals("Oracle_server"))
			{
				nick = st.nextToken();
				port = st.nextToken();
				String isPassive = st.nextToken();
				if (!st.hasMoreTokens())
					continue;
				sid = st.nextToken();
				strTemp = nick+":"+port+":"+sid;
			}
			else
			{
				nick = st.nextToken();
				port = st.nextToken();
				strTemp = nick+":"+port;
			}
			aListPorts.add(strTemp);
		}
		return aListPorts;
	}
%>