<%@ include file = "EgMonitorTracker.jsp" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.io.*"	%>
<%@ page import = "java.text.*"	%>
<%@ page import = "java.net.URLDecoder" %>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import = "com.eg.EgAgentInfo" %>
<%@ page import = "com.eg.EgExternalInfo" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "com.eg.EgSpecsInfo" %>
<%@ page import = "com.eg.EgDbaseInfo" %>
<%@ page import = "com.eg.EgManagersIniForManager" %>
<%@ page import = "com.eg.TransmitInfosToAllSMs" %>
<%@ page import = "com.eg.EgConfigFilesSync" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "com.eg.EgDbAdapterTypeUI" %>
<%@ page import = "egurkha.EgDbAdapterUI" %>
<%@ page import = "net.sf.json.*" %>
<%@ page import = "com.egurkha.EgTimeZoneConverter"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.egurkha.monitor.MonitorDAOFactory" %>
<%@ page import = "com.egurkha.monitor.MeasuresDAO" %>
<%@ page import = "com.egurkha.monitor.alarms.AlarmPriorities" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ 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);
	response.setContentType("application/json");
	request.setCharacterEncoding("UTF-8");

	String status = null;
	String message = null;
	ResultSet rs = null;
	EgDiscInfo discInfo = new EgDiscInfo("manager");
	EgTablesInfo tables = new EgTablesInfo("manager");
	EgDbInfo dbInfo = new EgDbInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	EgDbaseInfo dbaseInfo = new EgDbaseInfo("manager");

	EgDbAdapterUI egDb = null;
	AlarmPriorities ap = AlarmPriorities.getInstance();
	com.eg.IniFile egINI = new com.eg.IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini");
	com.eg.IniFile egServ = new com.eg.IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_services.ini");
	com.eg.IniFile externalIni = new com.eg.IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_external.ini", false);
	JSONArray dataArr = new JSONArray();
	JSONObject json = new JSONObject();
	
	SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

	IniFile egUI = new com.eg.IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_ui.ini");
	IniFile egAgentINI = new com.eg.IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_agents.ini");
	String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	UserRegistry registry = UserRegistry.getInstance();
	User user = registry.getUser(session.getId());
	EgDateInfo Datehandler = new EgDateInfo();
	com.egurkha.monitor.MonitorUtility mon = new com.egurkha.monitor.MonitorUtility();
	EgAgentInfo agentInfo = new EgAgentInfo("manager");
	EgExternalInfo egExternal=new EgExternalInfo("manager");
	String compType = request.getParameter("compType");
	String test = request.getParameter("test");
	if((test == null || test.trim().length()==0 ) &&  compType != null && compType.trim().length()>0)
	{
		test = egINI.getValue("Comp_Type_Based_Test",compType);	
		test =(test == null || test.trim().length()==0 )?"CitraTest":test;
			
	}
	
	String fromp = request.getParameter("fromp");
	String isFromMenu1 = request.getParameter("isFromMenu");
	String compName = request.getParameter("compName");
	String port = request.getParameter("port");
	String org_site = request.getParameter("site");
	String site="NULL";
	String keyMeasure = request.getParameter("keyMeasure");	

	if((keyMeasure == null || keyMeasure.equalsIgnoreCase("NULL") || keyMeasure.trim().length() == 0) && test != null && test.trim().length()>0)
	{
		String tempKeyMeasure = egINI.getValue("Emulation_Key_Measure",test);
		if(tempKeyMeasure == null || tempKeyMeasure.trim().length() == 0)
			keyMeasure = "RESPONSE_TIME";
		else
			keyMeasure = tempKeyMeasure;
	}
	String selectedScript = request.getParameter("selectedScript");
	String tempSelectedScript = selectedScript;
	String msmt_host_str = request.getParameter("msmtHost");
	if(msmt_host_str == null || msmt_host_str.equals("") || msmt_host_str.equalsIgnoreCase("null"))
	{
		List agents=egExternal.getAgentsFor(test,compType,compName);
		if(agents!=null && agents.size()>0)
			msmt_host_str=(String)agents.get(0);
		else
			msmt_host_str=compName;
	}
	
	boolean isSuccessScreenshotRequired = false;
	if(test.equalsIgnoreCase("GenericLogonSimTest"))
	{
		String tempStr = "";
		boolean flag = specsInfo.isPortRelevantForTest(test);

		if(flag)
			tempStr = test +"::"+compName+":"+port;				
		else
			tempStr = test +":"+compType+":"+ compName+":"+port;
						

		String agentData = egAgentINI.getValue(msmt_host_str,tempStr);
		if(agentData != null && agentData.trim().length()>0 && !agentData.equalsIgnoreCase("NULL"))
		{
			if(agentData.indexOf("-Success_screenshot_required ")>-1)
			{
				String aData = agentData.substring(agentData.indexOf("-Success_screenshot_required ")+29);
				String bData = aData.substring(0,aData.indexOf(" "));
				if(bData.equalsIgnoreCase("true") || bData.equalsIgnoreCase("yes"))
					isSuccessScreenshotRequired = true;
			}	
		}
	}

	String stateMeasure = request.getParameter("stateMeasure");
	String info = request.getParameter("info");
	String setImageValue = request.getParameter("setImageValue");
	String firstRequstCombo = request.getParameter("firstRequstCombo");	
	String selectedMsmtTime = request.getParameter("selectedMsmtTime");
	String scriptChange = request.getParameter("scriptChange");
	
	String ssParam = request.getParameter("getScreenshotID");
	String serviceName = request.getParameter("serviceName");
	String isFromMetricsPage = request.getParameter("isFromMetricsPage");
	String combochange = request.getParameter("combochange");
	String agentchange = request.getParameter("agentchange");
	
	boolean isAgentChange = false;
	if(agentchange!= null && agentchange.trim().length() > 0 && agentchange.equalsIgnoreCase("true"))
		isAgentChange = true;

	if(info != null)
	{
		info = com.egurkha.util.StringUtils.decodeSecurityChar(info);
	}

	if((combochange != null && combochange.equalsIgnoreCase("true")) || (agentchange != null && agentchange.equalsIgnoreCase("true")) || (scriptChange != null && scriptChange.equalsIgnoreCase("true")))
	{
		String qryString = (String)session.getAttribute("monitorLastSession");
		if(qryString.indexOf("&sesCombo=")>-1 || qryString.indexOf("&selectedScript=")>-1)
		{
			String tempQryString = qryString;
			if(tempQryString.indexOf("&sesCombo=")>-1)
			{
				
				String sesComboTemp = tempQryString.substring(tempQryString.indexOf("&sesCombo=")+1);
				String sesComboTempValue = sesComboTemp.substring(sesComboTemp.indexOf("=")+1);
				if(sesComboTemp.indexOf("&")>-1)
				{
					sesComboTempValue = sesComboTemp.substring(sesComboTemp.indexOf("=")+1,(sesComboTemp.indexOf("&")));
				}

				if(!sesComboTempValue.equalsIgnoreCase(compName+":"+port))
				{
					String paramLast = "&sesCombo="+sesComboTempValue;
					String replaceParam = "&sesCombo="+compName+":"+port;
					qryString = qryString.replace(paramLast,replaceParam);
				}			
			}
			if(tempQryString.indexOf("&selectedScript=")>-1)
			{
				String sesScriptTemp = tempQryString.substring(tempQryString.indexOf("&selectedScript=")+1);				
				String sesScriptTempValue = sesScriptTemp.substring(sesScriptTemp.indexOf("=")+1);
				if(sesScriptTemp.indexOf("&")>-1)
				{
					sesScriptTempValue = sesScriptTemp.substring(sesScriptTemp.indexOf("=")+1,(sesScriptTemp.indexOf("&")));
				}
				if(!sesScriptTempValue.equalsIgnoreCase(selectedScript))
				{
					String paramLast = "&selectedScript="+sesScriptTempValue;
					String replaceParam = "&selectedScript="+selectedScript;
					qryString =	qryString.replace(paramLast,replaceParam);
				}	
			}
			session.setAttribute("monitorLastSession",qryString);
		}
		else
		{
			qryString = qryString+"&sesCombo="+compName+":"+port;
			if(selectedScript != null && !selectedScript.equalsIgnoreCase("NULL") && selectedScript.trim().length()>0)
			{
				qryString = qryString+"&selectedScript="+selectedScript;
			}
			session.setAttribute("monitorLastSession",qryString);
		}
		String qryString1 = (String)session.getAttribute("monitorLastSession");
	}
	String DefaultTransaction = "Total";
	String extraParams="";

	String from = request.getParameter("from");
	boolean isFromList = false;
	if(from != null && (from.equalsIgnoreCase("MainDashboard") || from.equalsIgnoreCase("list") || from.equalsIgnoreCase("componentList")))
		isFromList = true;

	boolean isFrompList = false;
	if(fromp != null && fromp.equalsIgnoreCase("ctxLogonDashboard"))
		isFrompList = true;

	try
	{
		String qString = request.getQueryString();
		if(qString != null && qString.trim().length() > 0 )
		{
			StringTokenizer st4 = new StringTokenizer(qString,"&");
			boolean exPa = false;
			while(st4.hasMoreTokens())
			{
				String str = (String) st4.nextToken();

				if(!exPa && str.startsWith("extraparam"))
					exPa=true;

				if(exPa)
					extraParams += "&"+str;
				else
					continue;
			}
			if(extraParams != null && extraParams.trim().length() > 0)
			{
				if(isFromList)
					extraParams = "&isFromList=true&isFromSessionSim=true"+extraParams;
				else if(isFrompList)
					extraParams = "&isFromSessionToplogy=true&fromp="+fromp+"&isFromMenu="+isFromMenu1+"&isFromSessionSim=true"+extraParams;
				else
					extraParams = "&isfromCitrix=true&fromPageView=CitrixDashboard"+extraParams;
			}
		}
	}
	catch(Exception ee)
	{
	}
	String layerName = tables.getLayerForTest(test);
	if(layerName != null && layerName.trim().length() > 0 && layerName.indexOf(",") > 0){
		ArrayList layerList = tables.getLayersForComponent(compType);
		ArrayList testLayerList = com.egurkha.util.StringUtils.egTokenizer(layerName, ",",false,false,true);//3-->includeEmpty,4-->unique,5-->trim
		if(layerList != null && layerList.size() > 0 && testLayerList != null && testLayerList.size() > 0){
			for(int k=0;k<layerList.size();k++){
				String lay = (String)layerList.get(k);
				if(lay != null && lay.trim().length() > 0 && testLayerList.contains(lay)){
					layerName = lay;
					break;
				}
			}
		}
	}
	HashMap dbColMap = new HashMap();
	String measures = "";
	String[] meas = dbInfo.getColumnNamesForTest(test,layerName);
	String[] meas1 = dbInfo.getMeasurementColumnsForTest(test);
	if(meas != null && meas.length > 0){
		for(int k=0;k<meas.length;k++){
			if(meas[k] != null && !meas[k].endsWith("_ST")){
				measures += ","+meas[k];
				dbColMap.put(meas[k],meas1[k]);
			}
		}
		if(measures != null && measures.startsWith(","))
			measures = measures.substring(1);
	}

	if(isFromMetricsPage != null && isFromMetricsPage.equalsIgnoreCase("true"))
	{
		String ltype = request.getParameter("ltype");
		String ltest = request.getParameter("ltest");
		String monitorsBy = request.getParameter("monitorsBy");
		String externalAgent = request.getParameter("externalAgent");
		String treeTitle = request.getParameter("treeTitle");
	
		extraParams = "&isFromMetricsPage=true&isFromSessionSim=true&ltype="+ltype+"&ltest="+ltest+"&monitorsBy="+monitorsBy+"&externalAgent="+externalAgent+"&treeTitle="+treeTitle;
	}
	if(compType == null || compType.trim().length() == 0)
		compType = discInfo.getServerTypesForComponentNamePort(compName+":"+port);

	List UserComponentList=user.getServersForType(compType);
	JSONArray agentDataArr = new JSONArray();

	if(setImageValue != null && setImageValue.trim().length() > 0 && setImageValue.equalsIgnoreCase("true")){
		String iconName = request.getParameter("iconName");
		if(info != null && info.trim().length() > 0 && iconName != null && iconName.trim().length() > 0){
			/*if(serviceName != null && serviceName.trim().length() > 0 && !serviceName.equalsIgnoreCase("null"))
				egINI.setValue("TRANSACTION_ICON",serviceName+":"+compName+":"+port+":"+info,iconName);
			else*/
			if(EgInstallInfo.isClusterSupported)
			{
				EgManagersIniForManager mi = EgManagersIniForManager.getInstance();
				if(mi != null && mi.isPrimaryManager())
				{
					com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
					egINISave.setValue("TRANSACTION_ICON",compName+":"+port+":"+info,iconName);
					egINISave.saveFile();
					EgConfigFilesSync.releaseInstance(egINISave);
					egINISave = null;
					json.put("SUCCESS","true");
				}
				else
				{
					com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
					egINISave.setValue("TRANSACTION_ICON",compName+":"+port+":"+info,iconName);
					egINISave.saveFile();
					EgConfigFilesSync.releaseInstance(egINISave);
					egINISave = null;

					Vector savedValuesForOtherManagers = new Vector(); //REDUNDANT MANAGER
					savedValuesForOtherManagers.addElement("1~TRANSACTION_ICON~"+ compName+":"+port+":"+info + "~" + iconName); //REDUNDANT MANAGER
					
					TransmitInfosToAllSMs transmitInfoToSecondaryManagers = TransmitInfosToAllSMs.getInstance();
					Vector data = new Vector();
					data.add(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini");
					data.add(savedValuesForOtherManagers);
					
					Vector iniInfo = new Vector();
					iniInfo.add("UpdateIni");
					iniInfo.add(data);
					

					transmitInfoToSecondaryManagers.setData(iniInfo);
					json.put("SUCCESS","true");
				}
			}
			else
			{
				com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
				egINISave.setValue("TRANSACTION_ICON",compName+":"+port+":"+info,iconName);
				egINISave.saveFile();
				EgConfigFilesSync.releaseInstance(egINISave);
				egINISave = null;
				json.put("SUCCESS","true");
			}
			response.getWriter().write(json.toString());
			return;
		}
	}
	else if((combochange!= null && combochange.trim().length() > 0 && combochange.equalsIgnoreCase("true")) || isAgentChange)
	{		
		if(!isAgentChange)
		{
			List agentNameSort = new ArrayList();
			if (UserComponentList != null && UserComponentList.size() > 0)
			{
				String tempCompName = compName;
				if(compName != null && compName.equalsIgnoreCase("NULL") && compName.indexOf(":")>-1)
					tempCompName = compName.substring(0,compName.indexOf(":"));
				
				for(int k=0;k<UserComponentList.size();k++)
				{
					String server=(String)UserComponentList.get(k);
					
					String compTypeStr=server.substring(0,server.indexOf(":"));			
					String serverName=server.substring(server.indexOf(":")+1);			
					String nickNameField = serverName.substring(0,serverName.indexOf(":"));	
					
					String extUser = externalIni.getValue("Test_Mapping_Section",nickNameField);			
						
					
					if(tempCompName.equals(nickNameField))
					{
						agentNameSort = com.egurkha.util.StringUtils.egTokenizer(extUser, ",",false,false,true);
					}
				}
			}

			int agentNameSortSize = agentNameSort.size();
			if(agentNameSortSize>0)
			{
				if(agentNameSortSize==1)
					agentNameSort = new ArrayList();
				
				agentNameSortSize = agentNameSort.size();

				if(agentNameSortSize>1)
					Collections.sort(agentNameSort);
			
				
				if(agentNameSortSize>0)
				{
					for(int i=0;i<agentNameSortSize;i++)
					{
						JSONObject agentJson = new JSONObject();
						String agentName = (String)agentNameSort.get(i);
						
						agentJson.put("displayName",agentName);
						agentJson.put("value",agentName);			
						agentDataArr.add(agentJson);

						if(msmt_host_str==null || msmt_host_str.equalsIgnoreCase("NULL") || msmt_host_str.trim().length()==0 || (msmt_host_str!=null && msmt_host_str.trim().length()>0 && msmt_host_str.equalsIgnoreCase("ALL")))	
							msmt_host_str = agentName;
					}
					
					json.put("agentNames",agentDataArr);
					json.put("selectedAgent",msmt_host_str);
					json.put("MultiAgent",true);
				}
			}
		}

		String cutOff = egServ.getValue("CUT_OFF_FACTOR",test);
		int cutOff_tem = 2;
		try
		{
			if(cutOff == null || cutOff.trim().length()==0)
			{
				cutOff = egServ.getValue("CUT_OFF_FACTOR","Default");
				cutOff_tem = Integer.parseInt(cutOff);
				if(cutOff_tem>2)
					cutOff_tem = 2;
				
			}
			else
			{
				cutOff_tem = Integer.parseInt(cutOff);
			}
		}
		catch(Exception ee)
		{
			cutOff_tem = 2;
		}
		
		String testFrequency = agentInfo.getTestFrequency(compType+":"+compName+":"+port,test);	
		long time_diff = 0;
		String msmt_time_where="";
		try
		{
			long t_freq = Long.parseLong(testFrequency);
			time_diff = t_freq * cutOff_tem; 

			java.util.Date tmpday = Datehandler.egetRealDate();
			tmpday.setTime(tmpday.getTime() - (time_diff * 1000));
			msmt_time_where = dateFormat.format(tmpday);
		}
		catch(Exception ee)
		{
			//cutOff_tem = 2;
		}
		String s_info = "";
		String msmt_Time = "";
		Hashtable a_info = new Hashtable();
		ArrayList infosList = new ArrayList();
		egDb = EgDbAdapterTypeUI.getObject();
		try
		{	status = egDb.setConnection();
			rs = egDb.getSimulationInfos(site,compName,port,test,measures,msmt_time_where,msmt_host_str);
			try
			{
				if (rs != null)
				{					
					while (rs.next())
					{
						s_info = rs.getString("info");
						msmt_Time = rs.getString("msmt_time");						
						if (s_info.equals("+")) //No info
							continue;
						else
						{	
							if(s_info.startsWith("+"))
								s_info = s_info.substring(1, s_info.length());
							
							if (!infosList.contains(s_info))
								infosList.add(s_info);

							if (!a_info.containsKey(s_info))
								a_info.put(s_info,msmt_Time);
						}
					}
					rs.close();
					rs = null;
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();			
			}
			if(a_info.size()>1 && a_info.containsKey("Total"))
			{
				a_info.remove("Total");
				infosList.remove("Total");
			}

			boolean isMultiScript = false;
			if(infosList != null && infosList.size()>1)
				isMultiScript = true;		
			if(isMultiScript)
			{
				JSONArray infoDataArr = new JSONArray();
				
				for(int i=0;i<infosList.size();i++)
				{
					JSONObject infoJson = new JSONObject();
					String infoKey = (String)infosList.get(i);
					String msmtTime = (String)a_info.get(infoKey);
					msmtTime = mon.formatDateStrToDDMMYYFormat(msmtTime,"MM/DD"); 
					String tem_info = infoKey;
					if(infoKey.indexOf(":Total")>-1)
						tem_info = tem_info.substring(0,tem_info.indexOf(":Total"));

					infoJson.put("displayName",tem_info);
					infoJson.put("value",tem_info);
					infoJson.put("msmtTime",msmtTime);
					infoDataArr.add(infoJson);
				}
				json.put("MultiScriptCombo",infoDataArr);
			}
			json.put("MultiScript",isMultiScript);

			egDb.releaseConnection(false);
		}
		catch (Exception e)
		{	
			e.printStackTrace();
			if(!status.equals("CONNECTED"))
			{
				message = "Could not establish connection";
			}
			else
			{
				if (rs != null)
				{
					try {
						rs.close();
					} catch (Exception bug123) {}
				}
				egDb.releaseConnection(true);
			}
		}
		finally
		{			
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
	}
	else if( firstRequstCombo!= null && firstRequstCombo.trim().length() > 0 && firstRequstCombo.equalsIgnoreCase("true"))
	{
		List agentNameSort = new ArrayList();
		if (UserComponentList != null && UserComponentList.size() > 0)
		{
			String tempCompName = compName;
			if(compName != null && compName.equalsIgnoreCase("NULL") && compName.indexOf(":")>-1)
				tempCompName = compName.substring(0,compName.indexOf(":"));			
			
			for(int k=0;k<UserComponentList.size();k++)
			{
				String server=(String)UserComponentList.get(k);
				
				String compTypeStr=server.substring(0,server.indexOf(":"));			
				String serverName=server.substring(server.indexOf(":")+1);			
				String nickNameField = serverName.substring(0,serverName.indexOf(":"));	
				
				String extUser = externalIni.getValue("Test_Mapping_Section",nickNameField);
				if(tempCompName.equals(nickNameField))
				{					
					agentNameSort = com.egurkha.util.StringUtils.egTokenizer(extUser, ",",false,false,true);
				}

			}
		}
		
		int agentNameSortSize = agentNameSort.size();
		if(agentNameSortSize>0)
		{
			if(agentNameSortSize==1)
				agentNameSort = new ArrayList();
			
			agentNameSortSize = agentNameSort.size();

			if(agentNameSortSize>1)
				Collections.sort(agentNameSort);
		
			if(agentNameSortSize>0)
			{
				for(int i=0;i<agentNameSortSize;i++)
				{
					JSONObject agentJson = new JSONObject();
					String agentName = (String)agentNameSort.get(i);					
					
					agentJson.put("displayName",agentName);
					agentJson.put("value",agentName);			
					agentDataArr.add(agentJson);

					if(msmt_host_str==null || msmt_host_str.equalsIgnoreCase("NULL") || msmt_host_str.trim().length()==0 || (msmt_host_str!=null && msmt_host_str.trim().length()>0 && msmt_host_str.equalsIgnoreCase("ALL")))	
						msmt_host_str = agentName;
				}
				
				json.put("agentNames",agentDataArr);
				json.put("selectedAgent",msmt_host_str);
				json.put("MultiAgent",true);
			}
		}		

		String cutOff = egServ.getValue("CUT_OFF_FACTOR",test);
		int cutOff_tem = 2;
		try
		{
			if(cutOff == null || cutOff.trim().length()==0)
			{
				cutOff = egServ.getValue("CUT_OFF_FACTOR","Default");
				cutOff_tem = Integer.parseInt(cutOff);
				if(cutOff_tem>2)
					cutOff_tem = 2;
				
			}
			else
			{
				cutOff_tem = Integer.parseInt(cutOff);
			}
		}
		catch(Exception ee)
		{
			cutOff_tem = 2;
		}
		
		String testFrequency = agentInfo.getTestFrequency(compType+":"+compName+":"+port,test);	
		long time_diff = 0;
		String msmt_time_where="";
		try
		{
			long t_freq = Long.parseLong(testFrequency);
			time_diff = t_freq * cutOff_tem; 

			java.util.Date tmpday = Datehandler.egetRealDate();
			tmpday.setTime(tmpday.getTime() - (time_diff * 1000));
			msmt_time_where = dateFormat.format(tmpday);
		}
		catch(Exception ee)
		{
			//cutOff_tem = 2;
		}
		String s_info = "";
		String msmt_Time = "";
		Hashtable a_info = new Hashtable();
		ArrayList infosList = new ArrayList();
		egDb = EgDbAdapterTypeUI.getObject();
		try
		{	status = egDb.setConnection();
			rs = egDb.getSimulationInfos(site,compName,port,test,measures,msmt_time_where,msmt_host_str);
			try
			{
				if (rs != null)
				{					
					while (rs.next())
					{
						s_info = rs.getString("info");
						msmt_Time = rs.getString("msmt_time");						
						if (s_info.equals("+")) //No info
							continue;
						else
						{	
							if(s_info.startsWith("+"))
								s_info = s_info.substring(1, s_info.length());
							
							if (!infosList.contains(s_info))
								infosList.add(s_info);

							if (!a_info.containsKey(s_info))
								a_info.put(s_info,msmt_Time);
						}
					}
					rs.close();
					rs = null;
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();			
			}
			if(a_info.size()>1 && a_info.containsKey("Total"))
			{
				a_info.remove("Total");
				infosList.remove("Total");
			}

			boolean isMultiScript = false;
			if(infosList != null && infosList.size()>1)
				isMultiScript = true;		
			if(isMultiScript)
			{
				JSONArray infoDataArr = new JSONArray();
				
				for(int i=0;i<infosList.size();i++)
				{
					JSONObject infoJson = new JSONObject();
					String infoKey = (String)infosList.get(i);
					String msmtTime = (String)a_info.get(infoKey);
					msmtTime = mon.formatDateStrToDDMMYYFormat(msmtTime,"MM/DD"); 
					String tem_info = infoKey;
					if(infoKey.indexOf(":Total")>-1)
						tem_info = tem_info.substring(0,tem_info.indexOf(":Total"));

					infoJson.put("displayName",tem_info);
					infoJson.put("value",tem_info);
					infoJson.put("msmtTime",msmtTime);
					infoDataArr.add(infoJson);
				}
				json.put("MultiScriptCombo",infoDataArr);
			}
			json.put("MultiScript",isMultiScript);

			egDb.releaseConnection(false);
		}
		catch (Exception e)
		{	
			e.printStackTrace();
			if(!status.equals("CONNECTED"))
			{
				message = "Could not establish connection";
			}
			else
			{
				if (rs != null)
				{
					try {
						rs.close();
					} catch (Exception bug123) {}
				}
				egDb.releaseConnection(true);
			}
		}
		finally
		{
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		response.getWriter().write(json.toString());
		return;
	}
	else if(ssParam != null && ssParam.trim().length() > 0 && ssParam.equalsIgnoreCase("true"))
	{	
		
		if(dbaseInfo.isTableExistInDB(test+"_DDD"))
		{
			egDb = EgDbAdapterTypeUI.getObject();
			try
			{
				status = egDb.setConnection();
				String msmt_time = request.getParameter("msmt");
				String ss = egDb.getScreenshotID(site,compName,port,test+"_DDD",stateMeasure,info,msmt_time);
				json.put("ScreenshotID",ss);

				egDb.releaseConnection(false);			
			}
			catch (Exception e)
			{
				e.printStackTrace();
				if(!status.equals("CONNECTED"))
				{
					message = "Could not establish connection";
				}
				else
				{
					if (rs != null)
					{
						try {
							rs.close();
						} catch (Exception bug123) {}
					}
					egDb.releaseConnection(true);
				}
			}
			finally
			{			
				EgDbAdapterTypeUI.releaseObject(egDb);
			}
		}
		response.getWriter().write(json.toString());
		return;
	}
	
	egDb = EgDbAdapterTypeUI.getObject();
	String icons = "iconAccessDesktop,iconBrowseOpenItems,iconLogout,iconOpenFolder,iconDownloadCatalog,iconRegistration,iconSubmitContacts,iconUserLogin";
	ArrayList iconsList = com.egurkha.util.StringUtils.egTokenizer(icons, ",", false,true,true);

	
	String msmt_host = "",trgthost ="",portno="",msmt_time="",dbinfo="", lastInfoForSuccessSS="";
	try
	{
		HashMap state= new HashMap();
		HashMap values= new HashMap();
		boolean hasDefaultTrans = true;
		
		status = egDb.setConnection();
		com.eg.IniFile extMonIni = new com.eg.IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_extmondash.ini", false);
		JSONObject dataObj = new JSONObject();
		int y = 20, index = 1;
		MonitorDAOFactory monitorDaoFactory = MonitorDAOFactory.getInstance();
		MeasuresDAO MeasuresDao = monitorDaoFactory.getMeasuresDAO();
			
		if(selectedScript != null && !selectedScript.equalsIgnoreCase("NULL") && selectedScript.trim().length()>0)
		{	
			DefaultTransaction=selectedScript+":Total";
			selectedScript = selectedScript+":##"+selectedMsmtTime;
			rs = egDb.getSimulationData(site,compName,port,test,measures,msmt_host_str,selectedScript);
		}
		else
		{
			rs = egDb.getSimulationData(site,compName,port,test,measures,msmt_host_str);
		}
		
		ArrayList measList = com.egurkha.util.StringUtils.egTokenizer(measures, ",",false,false,true);
		String genericTestMeasure = egINI.getValue("GENERIC_MEASURES_TOPOLOGY",test);
		if(genericTestMeasure != null && genericTestMeasure.trim().length()>0)
		{
			measList = com.egurkha.util.StringUtils.egTokenizer(genericTestMeasure, ",",false,false,true);
		}
			
		HashMap hm = new HashMap();
		String infoList = "";
		if (rs != null)
		{
			while(rs.next()){
				trgthost = rs.getString("trgt_host");
				portno = rs.getString("port_no");
				msmt_host = rs.getString("msmt_host");
				msmt_time = rs.getString("msmt_time");
				String maxMsmtTimeParse = mon.formatDateStrToDDMMYYFormat(msmt_time,"MM/DD"); 
				boolean isTimeOut = false;
				isTimeOut=MeasuresDao.isTimeOut(maxMsmtTimeParse,test+"#"+msmt_host,trgthost+":"+portno,compType);
				
				dbinfo = rs.getString("info");
				dbinfo = (dbinfo != null && dbinfo.startsWith("+"))?dbinfo.substring(1):dbinfo;
				if(!isTimeOut)
				{
					for(int k=0;k<measList.size();k++){
						String measure = (String)measList.get(k);
						String orgMeasure = (String)dbColMap.get(measure);
						String val = "", stateVal = "";
						if(hm.containsKey(dbinfo)){
							HashMap vals = (HashMap)hm.get(dbinfo);
							val = rs.getString(measure);
							vals.put(orgMeasure,val);
							stateVal = (String)ap.getTestMeasurePriority(compName+":"+port, compType, layerName, test+"-+"+dbinfo, orgMeasure);
							vals.put(orgMeasure+"_State",stateVal);
							
						}
						else{
							HashMap vals = new HashMap();
							val = rs.getString(measure);
							vals.put(orgMeasure,val);
							stateVal = (String)ap.getTestMeasurePriority(compName+":"+port, compType, layerName, test+"-+"+dbinfo, orgMeasure);
							vals.put(orgMeasure+"_State",stateVal);
							hm.put(dbinfo,vals);
							infoList += ","+dbinfo;
							hm.put("Trgthost",trgthost);
							hm.put("Portno",portno);
							hm.put("Msmthost",msmt_host);
							hm.put("MsmtTime",msmt_time);
						}

						if(values.containsKey(orgMeasure)){
							ArrayList al = (ArrayList)values.get(orgMeasure);
							al.add(val);
							
						}
						else{
							ArrayList al = new ArrayList();
							al.add(val);
							values.put(orgMeasure,al);
						}

						if(state.containsKey(orgMeasure)){
							ArrayList al = (ArrayList)state.get(orgMeasure);
							if(!al.contains(stateVal))
								al.add(stateVal);
							
						}
						else{
							ArrayList al = new ArrayList();
							al.add(stateVal);
							state.put(orgMeasure,al);
						}
					}
				}
			}
			try
			{
				rs.close();
			}
			catch (Exception bug123) {}
		}
		List infoOrderList = new ArrayList();
		List tempInfoOrderList = new ArrayList();

		if(test != null && test.equalsIgnoreCase("GenericLogonSimTest"))
		{
			if(selectedScript != null && !selectedScript.equalsIgnoreCase("NULL") && selectedScript.trim().length()>0)
				tempInfoOrderList = (ArrayList)egDb.getSimulationInfoOrder(site,compName,port,test,msmt_host_str,selectedScript);
			else
				tempInfoOrderList = (ArrayList)egDb.getSimulationInfoOrder(site,compName,port,test,msmt_host_str);
		}
		else if(test != null && test.equalsIgnoreCase("CitraTest"))
		{
			if(selectedScript != null && !selectedScript.equalsIgnoreCase("NULL") && selectedScript.trim().length()>0)
				infoOrderList = (ArrayList)egDb.getSimulationInfoOrder(site,compName,port,test,msmt_host_str,selectedScript);
			else
				infoOrderList = (ArrayList)egDb.getSimulationInfoOrder(site,compName,port,test,msmt_host_str);
		}

		JSONArray defaultDataArr = new JSONArray();
		JSONArray dataObjArr = new JSONArray();
		if(tempInfoOrderList.size()>0)
		{	
			try
			{
				TreeMap infoOrder = new TreeMap();
				ArrayList total_info_List = new ArrayList();
				for(int i=0;i<tempInfoOrderList.size();i++)
				{
					String infoData = (String)tempInfoOrderList.get(i);
					String key = infoData.substring(infoData.lastIndexOf(":")+1);	
					if(!key.equalsIgnoreCase("Total"))
						infoOrder.put(new Integer(key),infoData);
					else
						total_info_List.add(infoData);
				}
				
				Iterator it =  infoOrder.entrySet().iterator();
				while(it.hasNext())
				{
					Map.Entry entry = (Map.Entry)it.next();
					String _treeInfo = (String)entry.getValue();
					infoOrderList.add(_treeInfo);
				}
				infoOrderList.addAll(total_info_List);

			}
			catch(Exception eer)
			{
				eer.printStackTrace();
			}		
		}
		boolean isDataPresent = false;

		if(hm != null && hm.size() > 0)
		{
			isDataPresent = true;
			trgthost = (String)hm.get("Trgthost");
			portno = (String)hm.get("Portno");
			msmt_time = (String)hm.get("MsmtTime");

			try
			{
				if(msmt_time!=null && (msmt_time.endsWith(".0") || msmt_time.endsWith(".00") || msmt_time.endsWith(".000") || msmt_time.endsWith(".0000")))
					msmt_time = msmt_time.substring(0,msmt_time.lastIndexOf("."));

				msmt_time = DateUtil.changeDateFormat(msmt_time,"yyyy-MM-dd HH:mm:ss","MM/dd/yyyy HH:mm:ss");	
			}
			catch(Exception e)
			{	
				e.printStackTrace();
			}

			if((infoOrderList == null || infoOrderList.size() == 0) && tempSelectedScript != null && tempSelectedScript.trim().length()>0 && !tempSelectedScript.equalsIgnoreCase("NULL"))
			{
				infoOrderList = com.egurkha.util.StringUtils.egTokenizer(egINI.getValue("TRANSACTION_ORDER",trgthost+":"+tempSelectedScript), ",", false,true,true);
			}
			else if(infoOrderList == null || infoOrderList.size() == 0)
			{
				infoOrderList = com.egurkha.util.StringUtils.egTokenizer(egINI.getValue("TRANSACTION_ORDER",trgthost), ",", false,true,true);
			}
			
			if(EgInstallInfo.isClusterSupported)
			{
				EgManagersIniForManager mi = EgManagersIniForManager.getInstance();
				if(mi != null && mi.isPrimaryManager())
				{
					if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0) && tempSelectedScript != null && tempSelectedScript.trim().length()>0 && !tempSelectedScript.equalsIgnoreCase("NULL")){
						com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
						egINISave.setValue("TRANSACTION_ORDER",trgthost+":"+tempSelectedScript,infoList.substring(1));
						egINISave.saveFile();
						EgConfigFilesSync.releaseInstance(egINISave);
						egINISave = null;
						infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
					}
					else if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0))
					{
						com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
						egINISave.setValue("TRANSACTION_ORDER",trgthost,infoList.substring(1));
						egINISave.saveFile();
						EgConfigFilesSync.releaseInstance(egINISave);
						egINISave = null;
						infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
					}
				}
				else
				{
					Vector savedValuesForOtherManagers = new Vector(); //REDUNDANT MANAGER

					if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0) && tempSelectedScript != null && tempSelectedScript.trim().length()>0 && !tempSelectedScript.equalsIgnoreCase("NULL")){
						com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
						egINISave.setValue("TRANSACTION_ORDER",trgthost+":"+tempSelectedScript,infoList.substring(1));
						egINISave.saveFile();
						EgConfigFilesSync.releaseInstance(egINISave);
						egINISave = null;

						savedValuesForOtherManagers.addElement("1~TRANSACTION_ORDER~"+ trgthost+":"+tempSelectedScript + "~" + infoList.substring(1)); //REDUNDANT MANAGER
						infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
						TransmitInfosToAllSMs transmitInfoToSecondaryManagers = TransmitInfosToAllSMs.getInstance();
						Vector data = new Vector();
						data.add(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini");
						data.add(savedValuesForOtherManagers);
						
						Vector iniInfo = new Vector();
						iniInfo.add("UpdateIni");
						iniInfo.add(data);
						

						transmitInfoToSecondaryManagers.setData(iniInfo);
					}
					else if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0))
					{
						com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
						egINISave.setValue("TRANSACTION_ORDER",trgthost,infoList.substring(1));
						egINISave.saveFile();
						EgConfigFilesSync.releaseInstance(egINISave);
						egINISave = null;
						savedValuesForOtherManagers.addElement("1~TRANSACTION_ORDER~"+ trgthost + "~" + infoList.substring(1)); //REDUNDANT MANAGER
						infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
						TransmitInfosToAllSMs transmitInfoToSecondaryManagers = TransmitInfosToAllSMs.getInstance();
						Vector data = new Vector();
						data.add(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini");
						data.add(savedValuesForOtherManagers);
						
						Vector iniInfo = new Vector();
						iniInfo.add("UpdateIni");
						iniInfo.add(data);
						
	
						transmitInfoToSecondaryManagers.setData(iniInfo);
					}
					
				}
			}
			else
			{
				if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0) && tempSelectedScript != null && tempSelectedScript.trim().length()>0 && !tempSelectedScript.equalsIgnoreCase("NULL")){
					com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
					egINISave.setValue("TRANSACTION_ORDER",trgthost+":"+tempSelectedScript,infoList.substring(1));
					egINISave.saveFile();
					EgConfigFilesSync.releaseInstance(egINISave);
					egINISave = null;
					infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
				}
				else if(infoList != null && (infoOrderList == null || infoOrderList.size() == 0))
				{
					com.eg.IniFile egINISave = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+ "/manager/config/eg_dashboardConfig.ini",true);
					egINISave.setValue("TRANSACTION_ORDER",trgthost,infoList.substring(1));
					egINISave.saveFile();
					EgConfigFilesSync.releaseInstance(egINISave);
					egINISave = null;
					infoOrderList = com.egurkha.util.StringUtils.egTokenizer(infoList.substring(1), ",", false,true,true);
				}
			}
			int infoOrderListSize= infoOrderList.size();
			if(infoOrderList != null && infoOrderListSize > 0){
				if( !(selectedScript != null && !selectedScript.equalsIgnoreCase("NULL") && selectedScript.trim().length()>0 ) && !isDefaultPresent(infoOrderList)){
					infoOrderList.add(0,"Total");
					hasDefaultTrans = false;
				}
				if(infoOrderListSize >= 2)
				{
					String lastInfoForSeccess = (String)infoOrderList.get(infoOrderListSize-2);
					lastInfoForSuccessSS = (lastInfoForSeccess != null && lastInfoForSeccess.startsWith("+"))?lastInfoForSeccess.substring(1):lastInfoForSeccess;	
				}

				Iterator itr = infoOrderList.iterator();
				while(itr.hasNext()){
					dbinfo = (String)itr.next();
					dbinfo = (dbinfo != null && dbinfo.startsWith("+"))?dbinfo.substring(1):dbinfo;
					String displayName = dbinfo;

					if(dbinfo.indexOf(":")>-1)					
						displayName = dbinfo.substring(dbinfo.indexOf(":")+1,dbinfo.length());
					
					if(displayName.indexOf(":")>-1)					
						displayName = displayName.substring(0,displayName.lastIndexOf(":"));
					
					HashMap vals = (HashMap)hm.get(dbinfo);

					if(vals == null && hasDefaultTrans)
						continue;
					if(dbinfo != null && dbinfo.endsWith("Total")){
						msmt_host = (String)hm.get("Msmthost");
						if(msmt_host != null && msmt_host.trim().length() > 0){
							dataObj = new JSONObject();
							String loc = extMonIni.getValue("Eg_External_Agents_Locations",msmt_host);
							if(loc != null  && loc.trim().length() > 0 && !loc.equalsIgnoreCase("NULL")){
								dataObj.put("DispName","Location");
								dataObj.put("Val",loc);
								dataObj.put("State","");
								dataObj.put("yaxis",new Integer(y));
								y = y+40;
								defaultDataArr.add(dataObj);
							}
								
							dataObj = new JSONObject();
							//dataObj.put("DispName","Agent");
							dataObj.put("DispName","Simulated by");
							dataObj.put("Val",msmt_host);
							dataObj.put("State","");
							dataObj.put("yaxis",new Integer(y));
							y = y+40;
							defaultDataArr.add(dataObj);
							
						}
						
						boolean isAvalShow = true;
						boolean isRespTimeShow = true;
						boolean isNeedURL = true;
						for(int k=0;k<measList.size();k++){
							String measure = (String)measList.get(k);
							String orgMeasure = (String)dbColMap.get(measure);
							if(measure != null && !measure.endsWith("_ST")){
								dataObj = new JSONObject();
								String val = "";
								/*if(serviceName != null && serviceName.trim().length() > 0 && !serviceName.equalsIgnoreCase("null"))
									val = egINI.getValue("TRANSACTION_ICON",serviceName+":"+trgthost+":"+portno+":"+dbinfo);
								else*/
									val = egINI.getValue("TRANSACTION_ICON",trgthost+":"+portno+":"+dbinfo);
								if(val == null || val.trim().length() == 0)
									val = egINI.getValue("TRANSACTION_ICON","DefaultIcon");
								dataObj.put("msmt_time",msmt_time);
								dataObj.put("Image",val);

								
								if(!hasDefaultTrans){
									val = mon.getoverAllTotal((ArrayList)values.get(measure));
									if(val.equalsIgnoreCase("N/A"))
										val = mon.getoverAllTotal((ArrayList)values.get(orgMeasure));
								}
								else
									val = (String)vals.get(orgMeasure);

								String dispName = mappingInfo.getMeasureDescription(test,orgMeasure);
								dataObj.put("Transaction_Name",displayName);
								dataObj.put("Info_Name",dbinfo);
								dataObj.put("DispName",dispName);

								if(measure != null && measure.equalsIgnoreCase("AVAILABILITY")){
									if(val != null && (val.equals("-5") || val.equals("-5.00") ||val.equals("-5.0000")))
									{
										isAvalShow = false;
										continue;
									}
									else
										val = (val != null && val.startsWith("100."))?"Yes":"No";
								}
								else if(!isRespTimeShow && !isAvalShow && measure != null && measure.equalsIgnoreCase("APPSMONSTATUS")){
									if(val != null && (val.equals("-5") || val.equals("-5.00") ||val.equals("-5.0000") || val.equals("0") || val.equals("0.00") ||val.equals("0.0000")))
										continue;
									else
									{	
										isNeedURL = false;								
										if(val.indexOf(".")>-1)
										{
											val = val.substring(0,val.indexOf("."));
										}
										
										val = egUI.getValue("Measure_value_display",test+":AppsMonStatus:"+val);
									}
								}
								else if(measure != null && !measure.equalsIgnoreCase("APPSMONSTATUS"))
								{
									if(val != null && (val.equals("-5") || val.equals("-5.00") ||val.equals("-5.0000")))
									{
										isRespTimeShow = false;
										continue;
									}
									else
										val = mon.formatDbValue(val,2);
								}
								else
									continue;

								dataObj.put("Val",val);

								//Getting state for total from state high transcation
								if(test != null && test.equalsIgnoreCase("GenericLogonSimTest") && measure != null && measure.equalsIgnoreCase("AVAILABILITY"))
								{
									HashMap stateFind = (HashMap)hm.get(lastInfoForSuccessSS);

									val = "GOOD";
									if(stateFind !=null && stateFind.size()>0)
										val = (String)stateFind.get(orgMeasure+"_State");
									dataObj.put("State",val);
								}
								else
								{
									if(!hasDefaultTrans){
										ArrayList al = (ArrayList)state.get(orgMeasure);
										if(al != null && al.size() > 0){
											if(al.contains("HIGH"))
												val = "HIGH";
											else if(al.contains("INTERMEDIATE"))
												val = "INTERMEDIATE";
											else if(al.contains("LOW"))
												val = "LOW";
											else if(al.contains("UNKNOWN"))
												val = "UNKNOWN";
											else if(al.contains("GOOD"))
												val = "GOOD";
										}
									}
									else
										val = (String)vals.get(orgMeasure+"_State");
									dataObj.put("State",val);
								}
								

								dataObj.put("yaxis",new Integer(y));
								y = y+40;

								try
								{
									if(isNeedURL)
									{
										String layerLinkUrl=mon.getSiteInfraLayerLInkUrl(org_site,compType,compName+":"+port,msmt_host,test,dbinfo,null,val,extraParams);
										dataObj.put("defaultTrans_link",layerLinkUrl+"&tab=layermodel&toDashBoardLayer=true");
									}
								}
								catch(Exception ee)
								{
								}

								defaultDataArr.add(dataObj);
							}
						}
						hasDefaultTrans = true;
					}
					else{
						dataObj = new JSONObject();
						dataObj.put("Transaction_Name",displayName);
						dataObj.put("Info_Name",dbinfo);
						String val = "";
						/*if(serviceName != null && serviceName.trim().length() > 0 && !serviceName.equalsIgnoreCase("null"))
							val = egINI.getValue("TRANSACTION_ICON",serviceName+":"+trgthost+":"+portno+":"+dbinfo);
						else*/
							val = egINI.getValue("TRANSACTION_ICON",trgthost+":"+portno+":"+dbinfo);
						if(val == null || val.trim().length() == 0)
							val = egINI.getValue("TRANSACTION_ICON","DefaultIcon");
						dataObj.put("msmt_time",msmt_time);
						dataObj.put("Transaction_Image",val);
						dataObj.put("index",index);
						index += 1;
						
						String sta_val = (String)vals.get("Availability");
						sta_val = (sta_val != null && sta_val.startsWith("100"))?"Yes":"No";
						dataObj.put("sta_val",sta_val);
						
						val = (String)vals.get((String)dbColMap.get(keyMeasure));
						try
						{
							val = mon.formatDbValue(val,2);
						}
						catch(Exception e)
						{
							val = val;
						}
						
						dataObj.put("Transaction_Val",val);
						

						String unitMeasure = tables.getUnitForMeasure(test,(String)dbColMap.get(keyMeasure));
						unitMeasure = (unitMeasure.equalsIgnoreCase("Seconds"))?"s":unitMeasure;
						dataObj.put("Transaction_Val_Unit",unitMeasure);

						String trans_org_state = (String)vals.get(stateMeasure+"_State");
						val = (String)vals.get((String)dbColMap.get(keyMeasure)+"_State");
						dataObj.put("Transaction_Val_State",val);
						
						Object[] ob=new Object[]{trans_org_state,val};
						String trans_state =(String)ap.getHighestPriority(ob);
						dataObj.put("Transaction_State",trans_state);
						
						/*if(sta_val.equalsIgnoreCase("Yes"))
							dataObj.put("Transaction_Avail_State","GOOD");
						else if(trans_org_state.equalsIgnoreCase("GOOD"))
							dataObj.put("Transaction_Avail_State","GOOD");
						else
							dataObj.put("Transaction_Avail_State","HIGH");*/
						
						dataObj.put("Transaction_Avail_State",trans_org_state);
						dataObj.put("Transaction_Avail_State_val",sta_val);

						//if(trans_state.equalsIgnoreCase("GOOD"))
						{
							try
							{
								String layerLinkUrl=mon.getSiteInfraLayerLInkUrl(org_site,compType,compName+":"+port,msmt_host,test,dbinfo,null,trans_state,extraParams);
								dataObj.put("Transaction_link",layerLinkUrl+"&tab=layermodel&toDashBoardLayer=true");
							}
							catch(Exception ee)
							{
							}
						}

						dataObjArr.add(dataObj);
					}
				}
			}
		}

		
		if(defaultDataArr.size()>0)
		{
			dataObj = new JSONObject();
			dataObj.put("DefaultTrans",defaultDataArr);		
			dataArr.add(dataObj);
		}
		dataObj = new JSONObject();
		if(dataObjArr == null || dataObjArr.size() == 0){
			dataObj.put("ERROR","No data found");
			dataObjArr.add(dataObj);
			dataObj = new JSONObject();
			dataObj.put("Transactions",dataObjArr);
		}
		else
			dataObj.put("Transactions",dataObjArr);
		dataArr.add(dataObj);

		dataObj = new JSONObject();
		String tt_msmt_time = msmt_time;

		try
		{
			if(isDataPresent)			
				tt_msmt_time = DateUtil.changeDateFormat(tt_msmt_time,"MM/dd/yyyy HH:mm:ss",currentDateFormat + " HH:mm:ss");		
			else
			{

				if(tt_msmt_time!=null && (tt_msmt_time.endsWith(".0") || tt_msmt_time.endsWith(".00") || tt_msmt_time.endsWith(".000") || tt_msmt_time.endsWith(".0000")))
					tt_msmt_time = tt_msmt_time.substring(0,tt_msmt_time.lastIndexOf("."));
				
				tt_msmt_time = DateUtil.changeDateFormat(tt_msmt_time,"yyyy-MM-dd HH:mm:ss",currentDateFormat + " HH:mm:ss");				
			}	
			
			EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(tt_msmt_time,user);
			String loginUserDateTime = (String)timeZoneConverter.getDateTime();
			dataObj.put("time",loginUserDateTime);
		}
		catch(Exception ee)
		{
			dataObj.put("time",tt_msmt_time);
		}
		dataArr.add(dataObj);

		egDb.releaseConnection(false);
	}
	catch (Exception e)
	{
		e.printStackTrace();
		if(!status.equals("CONNECTED"))
		{
			message = "Could not establish connection";
		}
		else
		{
			if (rs != null)
			{
				try {
					rs.close();
				} catch (Exception bug123) {}
			}
			egDb.releaseConnection(true);
		}
	}
	finally
	{
		EgDbAdapterTypeUI.releaseObject(egDb);
	}
	
	json.put("Result",dataArr);
	json.put("TestName",test);
	json.put("compType",compType);
	json.put("msmtHost",msmt_host_str);
	json.put("lastInfoForSuccessSS",lastInfoForSuccessSS);
	json.put("isSuccessScreenshotRequired",isSuccessScreenshotRequired);
	response.getWriter().write(json.toString());
%>
<%!
	private boolean isDefaultPresent(List info_list )
	{
		try
		{
			for(int i=0;i<info_list.size();i++)
			{
				String infoData = (String)info_list.get(i);
				if(infoData.endsWith("Total"))
					return true;
			}
		}
		catch(Exception ee)
		{
			return false;
		}
		return false;
	}
%>
