<%

/**
/***********************************************************************************
 *		Name				:	EgAlarmHistoryTable.jsp
 *		Version				:	5.0
 *		CreationDate		:	9/03/2010
 *		Author				:	Nehru.C
 *								20/12/2011  Sri Devi G User - VM Changes
 ***********************************************************************************/
%>
<%@ include file = "EgMonitorTracker.jsp" %>
<%@ page errorPage = "EgProbsM.jsp" %>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "com.egurkha.util.DateUtil"%>
<%@ page import = "com.eg.EgDbAdapterTypeUI" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.eg.EgDiscInfoHelper" %>
<%@ page import = "com.eg.EgMemInfo" %>
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgSpecsInfo"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgAgentInfo"%>
<%@ page import = "com.eg.LangInfo" %>
<%@ page import = "com.eg.EgSmConfigInfo" %>
<%@ page import = "com.eg.EgConfigChangeThread" %>
<%@ page import = "com.eg.EgLastMeasureThread" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "com.egurkha.ini.*" %>
<%@ page import = "com.egurkha.util.*" %>
<%@ page import = "com.egurkha.monitor.alarms.*" %>
<%@ page import = "com.egurkha.monitor.EgAlarmsBean"%>
<%@ page import = "egurkha.EgDbAdapterUI" %>
<%@ page import = "egurkha.EgSettingsTimeStamp" %>
<%@ page import = "egurkha.TestBean" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*"  %>
<%@ page import = "com.eg.IniFile"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.egurkha.monitor.EgAlarmComparator"%>
<%@ page import = "com.egurkha.pdfmaker.*"%>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.eg.EgURLDecoder" %>
<%@ page import="com.egurkha.monitor.EgServerDashBoardDAO"%>
<%@ page import="com.egurkha.monitor.EgServerDashboardModel"%>
<%@ page import="com.egurkha.monitor.MonitorDAOFactory"%>
<%@ page import = "com.eg.EgTestInfo"%>
<%@ page import ="com.eg.EgViewInfo" %>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import ="com.eg.EgTopoInfo"%>
<%@ page import ="com.eg.EgGroupInfo"%>
<%@ page import = "com.egurkha.monitor.*" %>
<%@ page import = "com.egurkha.monitor.EgServiceMappingBean"%>
<%@ page import ="com.egurkha.monitor.EgComponentUserMappingBean"%>
<%@ page import="net.sf.json.*"%>
<%@ page import ="com.eg.supermanager.*"%>
<%@ page import = "com.egurkha.EgTimeZoneConverter"%>
<%@ page import = "java.util.Date"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.eg.EgFormatInfo"%>
<%@ page import = "com.egurkha.admin.AuditLogHashtable"%>
<%@ page import = "com.eg.EgManagersInfo"%>

<jsp:useBean id="esmb" scope="page" class="com.egurkha.monitor.EgServiceMappingBean" />
<jsp:useBean id="ecumb" scope="page" class="com.egurkha.monitor.EgComponentUserMappingBean" />

<%
	JSONObject json  = new JSONObject();
	MonitorUtility Monutil=new MonitorUtility();
	JSONArray  historyJson = new JSONArray();
	JSONObject labelObj= new JSONObject();
	
	Hashtable resultServiceNamesForComp=(Hashtable)esmb.getServiceNamesForComponentMap();
	//Hashtable resultUserCompMap = (Hashtable)ecumb.getUserNamesForComponentMap();
	Hashtable resultUserCompMap = null;
	boolean enableDD = false;
	boolean enableUser = false;
	boolean enableLogon = false;
	boolean enableConfig = false;
	boolean enableScreenShot = false;
	currentSessionId = session.getId();
	EgFormatInfo formatInfo = new EgFormatInfo ("manager");
	managerRowCount = new AuditLogHashtable ();
	rowManager = new AuditLogHashtable ();
%>
<%!
	AuditLogHashtable  rowManager = null;
	AuditLogHashtable  managerRowCount = null;
	MonitorDAOFactory monitorDaoFactory = MonitorDAOFactory.getInstance();
	EgServerDashBoardDAO dashboardDAO=monitorDaoFactory.getServerDashBoardDAO();

	int compNameLength=32;
	int displayLength=18;
	String infoRandom="";
	String testList="";
	public String replace (String s,String s_search,String s_replace)
		{
			StringBuffer sb_tmp = new StringBuffer();
			while(s.indexOf(s_search) > -1)
			{
			   sb_tmp.append(s.substring(0,s.indexOf(s_search)) + s_replace);
				s = s.substring(s.indexOf(s_search) + s_search.length(),s.length());
			}
			if(s.length() > 0)
			sb_tmp.append(s);
			return sb_tmp.toString();
		}
		public String replaceMsg (String message,String Compname,String CompType,String Service,String Priority,String Layer,String Test,String info,String Measure,String LastMeasurevalue)
		{
			message = replace(message,"$Compname",Compname);
			message = replace(message,"$CompType",CompType);
			message = replace(message,"$Service",Service);
			message = replace(message,"$Priority",Priority);
			message = replace(message,"$Layer",Layer);
			message = replace(message,"$Test",Test);
			String tempInfoStr="";
			if(info!=null && !info.trim().equals("+"))
			{
				tempInfoStr=info;
			}
			message = replace(message,"$info",tempInfoStr);
			message = replace(message,"$Measure",Measure);
			message = replace(message,"$LastMeasurevalue",LastMeasurevalue);
			return message.toString();
		}
		Hashtable infoSearchCount = new Hashtable();
%>
<%!
	String licenseCheck = "me";
	String thisLanguage="";
	public Vector syncVector = new Vector();
	boolean isFromDashBoard=false;
	boolean isFromInsideviewDashboard=false;
	Hashtable ht = new Hashtable();
	String insideViewInfo=null;
	String currentSessionId = null;
	//declare murugan
	String measureLink = null;
	String compgraphLink = null;
	String graphLink = null;
	String compsummarygraphLink = null;
	String summarygraphLink = null;
	String comptrendgraphLink = null;
	String trendgraphLink = null;
	String historyLink = null;
	String feedbackLink = null;
	String aggLink = null;
	String aggregateLink = null;
	String compddLink =null;
	String dLink = null;
	String feedLink = null;
	String ddLink =null;
	String logonLink =null;
	String histLink=null;
	String displayname = null;
	String temp_ddLink=null;
	String sessionId = null;
	String tmp_srvers = null; //for Monitor role Users - query 
	boolean isdd =  false;
	boolean isCustomAlertMessages = false;//for customize the problem description 
	String CustomAlertMessages = "No";//for customize the problem description 
	//String infoForFirstAlert=""; 
	//MonitorDAOFactory	monitorDaoFactory = MonitorDAOFactory.getInstance();
	//EgServerDashBoardDAO dashboardDAO=monitorDaoFactory.getServerDashBoardDAO();
	TreeMap linksMap = new TreeMap();
	//murugan ends
%>

<%
	session.removeAttribute("REPORT_NAME_Ack");
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);
	response.setContentType("application/json");
	isFromDashBoard=(request.getParameter("fromDashBoard")!=null && request.getParameter("fromDashBoard").equals("true"));
	isFromInsideviewDashboard=(request.getParameter("from_page")!=null && ( request.getParameter("from_page").equalsIgnoreCase("insideviewDashboard")||  request.getParameter("from_page").equalsIgnoreCase("VMTabView")));
	String tab=request.getParameter("tab");
	boolean checkIsVM = false;
	String source = "";
	if(isFromInsideviewDashboard)
	{
		String s_isVM = request.getParameter("isVM");
		checkIsVM = (new Boolean(s_isVM)).booleanValue();
		insideViewInfo=request.getParameter("insideview_info");
		source = request.getParameter("source");
		
		if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
		{
			insideViewInfo=com.egurkha.util.StringUtils.replace(insideViewInfo,"|amp|","&");
			insideViewInfo=com.egurkha.util.StringUtils.decodeSecurityChar(insideViewInfo);
		}
		
		if(insideViewInfo!=null && insideViewInfo.trim().length()>0 && !insideViewInfo.startsWith("+"))
		{
			if(checkIsVM)
			{
				insideViewInfo="+"+insideViewInfo;
			}
			else
			{
				//insideViewInfo="+"+insideViewInfo.toLowerCase();
				insideViewInfo="+"+insideViewInfo;
			}
		}
		else if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
		{
			if(checkIsVM)
			{
				insideViewInfo=insideViewInfo;
			}
			else
			{
				//insideViewInfo=insideViewInfo.toLowerCase();
				insideViewInfo=insideViewInfo;
			}
		}
	}
	boolean isAllComp=false;
	boolean  ddEnabled=false;
	UserRegistry registry = UserRegistry.getInstance();
	user = registry.getUser(session.getId());
	userRole = EgUserRole.getRoleObject(user.getLoginType());
	isAllComp = userRole.hasAllComponentAccess();
	String showUserValue = request.getParameter("showuser");
	String ddTimeAlt = request.getParameter("ddTimeAlt");
	if(showUserValue!=null)
		showUserValue=EgURLDecoder.decode(showUserValue,"UTF-8");
	showUserValue=(showUserValue==null || showUserValue.trim().length()==0 || showUserValue.equals("null") || showUserValue.equals(""))?"":showUserValue;
	IniUI ui = (IniUI)com.egurkha.ini.IniUI.getInstance();
	
	String loginid = user.getLoginID();
	LangInfo langinfo = null;

	String LABELS = "LABELS";
	thisLanguage = ui.getDefaultLanguage();
	boolean hasVMs = false;
	boolean onlyVMAssigned = false;
	boolean vmAssigned = false;
	List a_userVMs = new LinkedList();	
	String vmType = "";
	List checkComps = new LinkedList();
	boolean dispHeader = true;
	List userTypes = new LinkedList();
	if (user!=null)
	{
		vmType = user.getVMType();
		String userLang = user.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
		
		if(!isAllComp)
		{
			onlyVMAssigned = user.isOnlyVMAssigned();
			vmAssigned = user.isVMAssigned();
			//a_userVMs = user.getOnlyVMs();
			a_userVMs = user.getAlluserDesktopVms();
			if(a_userVMs!=null && a_userVMs.size() > 0)
			{
				hasVMs = true;
			}
		}
		userTypes = user.getServerTypes();
	}

	boolean isUserLanguageEnglish=true;
	if(thisLanguage!=null && !thisLanguage.equals("en_US"))
	{
		isUserLanguageEnglish=false;
	}
	User selectedUser = null;
	if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1"))
	{
		ErUserData userData = new ErUserData(showUserValue,false);
		if(userData!=null)
		{
			selectedUser=userData.usr;
			if(selectedUser==null)
			{
				selectedUser = userData.getUser(showUserValue);
			}
		}
	}
	
	EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
	EgMappingInfo mappingInfo_state = new EgMappingInfo("en_US");
	hasAllComponentAccess=userRole.hasAllComponentAccess();
	siteNames           = new LinkedList();
	siteNames.addAll(user.getSites());
	siteNames.addAll(user.getServices());
	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	String formatFile = "eg_format.ini";
	String serviceFile = "eg_services.ini";
	String dashboardConfig = "eg_dashboardConfig.ini";
	IniFile formatIniFile = new IniFile(s_iniFile_dir + formatFile);
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	IniFile serviceini = new IniFile(s_iniFile_dir + serviceFile);
	IniFile dashboardConfigIni = new IniFile(s_iniFile_dir + dashboardConfig);
	String loadByDefault = egUI.getValue("ALARM_HISTORY","LoadByDefault");
	boolean loadbydefault = true;
	if(loadByDefault != null && loadByDefault.trim().length() > 0){
		if(loadByDefault.equalsIgnoreCase("yes") || loadByDefault.equalsIgnoreCase("true"))
			loadbydefault = true;
		else
			loadbydefault = false;
	}
	IniFile egINI = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_endUserDetails.ini");
	String eventHistFlag = egUI.getValue("ALARM_HISTORY","ShowEventHistory");
	boolean showEventHistory = true;
	if(eventHistFlag != null && eventHistFlag.trim().length() > 0 && (eventHistFlag.equalsIgnoreCase("yes") || eventHistFlag.equalsIgnoreCase("true") || eventHistFlag.equalsIgnoreCase("y") ))
		showEventHistory = true;
	else
		showEventHistory = false;

	String showEventHistoryFlag=request.getParameter("showEventHistory");
	if(showEventHistoryFlag != null && showEventHistoryFlag.trim().length() > 0)
	{
		if(showEventHistoryFlag.equalsIgnoreCase("yes") || showEventHistoryFlag.equalsIgnoreCase("true") || showEventHistoryFlag.equalsIgnoreCase("y") )
			showEventHistory = true;
		else
			showEventHistory = false;
	}
	String pageSize = egUI.getValue("ALARMS","Row_Multiplier");
	if(pageSize==null || pageSize.trim().equals(""))
		pageSize = "10";

	
	//String pageSize  = serviceini.getValue("HISTORY_ALARM","PageSize");
	
	infoRandom = request.getParameter("infoRandom");
	boolean isCount =false;

	String countRec = request.getParameter("count");
	if(countRec!=null)
		isCount = true;

	ArrayList excludeDDTestList = formatInfo.getHideDDTestList();



	int startIndex = 0; 
	int endIndex = 0;
	int evtPerPage = 10;	
	try
	{
		evtPerPage = Integer.parseInt(pageSize.trim());
	}
		catch(Exception e)
	{
		pageSize = "10";
		evtPerPage = 10;
	}
	String pageNo = request.getParameter("pageNo");
	if(pageNo==null || pageNo.trim().equals(""))
		pageNo = "1";
	int pageNum = 1; 
	try
	{
		pageNum = Integer.parseInt(pageNo.trim());
	}
	catch(NumberFormatException e)
	{
		pageNum = 1;
	}
	
	
	String logon_Details_Support_types = dashboardConfigIni.getValue("Logon_Details_Support_Types","Types");

	ArrayList supported_types_list = new ArrayList();
	if(logon_Details_Support_types!=null && logon_Details_Support_types.trim().length()>0)
	{
		supported_types_list = com.egurkha.util.StringUtils.egTokenizer(logon_Details_Support_types,",",false,true,true);//param 3-->includeEmpty,4-->unique,5-->trim
	}

	ArrayList logonSupportedTests = new ArrayList();
	String logonSupportTest = dashboardConfigIni.getValue("Logon_Details_Support","ShowInAlarmHistory");
	if(logonSupportTest!=null && logonSupportTest.trim().length()>0)
	{
		logonSupportedTests = com.egurkha.util.StringUtils.egTokenizer(logonSupportTest,",",false,true,true);//param 3-->includeEmpty,4-->unique,5-->trim
	}

	String showUsers = egUI.getValue("ALARM_HISTORY","Show_Users");
	String dd_Timeline = egUI.getValue("ALARMS","DD_TIMELINE");
	int dd_Min = Integer.parseInt("-"+dd_Timeline);
	String currDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	currentDateFormat = currentDateFormat + " HH:mm";
	String selectedArrangeOption= request.getParameter("arrangeAlarms");
	CustomAlertMessages = serviceini.getValue("MISC_ARGS","EnableCustomAlertMessages");
	if(CustomAlertMessages!=null && CustomAlertMessages.equalsIgnoreCase("Yes"))
		isCustomAlertMessages=true;

	String layerName = request.getParameter("selectedLayer");
	String comFormat = "";
	if(isAllComp && showUsers != null && showUsers.equalsIgnoreCase("true") && (showUserValue == null || showUserValue.trim().equals("-1") || showUserValue.trim().equals("")))	// Prem
	{
		enableUser = true;
	}

	synchronized(licenseCheck)
	{
		ddEnabled = EgMemInfo.ddEnabled;
	}
	EgSpecsInfo specsInfo = new EgSpecsInfo(EgConstants.MANAGER);
	EgAgentInfo agentInfo = new EgAgentInfo(EgConstants.MANAGER);
	EgDiscInfo discInfo = new EgDiscInfo(EgConstants.MANAGER);
	EgDiscInfoHelper discInfoHelper = new EgDiscInfoHelper();
	Vector vpdfData=new Vector();
	List lst=new LinkedList();//to store into the session object
	List data_list=new LinkedList();//to store the data for CSV format
	Vector heads=new Vector();//to store table heading to CSV format
	Vector date=new Vector();
	
	lst.add(mappingInfo.getTextDescription("monitor.history.Alarm History"));

	String pdfHeading="";


	List all = null;	//Result from the database
	List history = null;//Same as all, but contains data as is from database. all undergoes modifications for display.
	int size = 0;		//The size of the Vector all

	//---For indexer-taglib.jar
	String index = "center";
	//int maxPageItems = 10;

	//added by ahamed
	String count = request.getParameter("eventsCount");
	String eventsPerPage = request.getParameter("limit");
	if(eventsPerPage == null)
	{
		eventsPerPage = egUI.getValue("ALARMS","Row_Multiplier");
		pageSize = eventsPerPage;
		evtPerPage = Integer.parseInt(eventsPerPage.trim());
	}
	
	int eventsperPage_int = 10;
	if(eventsPerPage != null && !eventsPerPage.equalsIgnoreCase("null") && !eventsPerPage.equalsIgnoreCase(""))
	{
		eventsperPage_int = Integer.parseInt(eventsPerPage);
	}
	//end
	
	String ackValue = request.getParameter("showacknowledge");

	int maxPageItems = eventsperPage_int;//ui.getMaxPageItems();
	evtPerPage = eventsperPage_int;
	pageSize = String.valueOf(eventsperPage_int);
	startIndex = (pageNum-1)*evtPerPage;
	endIndex = startIndex+evtPerPage;
	int maxIndexPages = 10;
	int thisPageNumber = 1;
	int maxWidth = 0;

	String durationStr = request.getParameter("filterOut");
	char condition = '>';			//Filter out by more than or less than?
	long minDuration = 0;
	if (durationStr != null)
	{
		minDuration = Long.parseLong(durationStr);
		if (durationStr.startsWith("-"))
		{
			condition = '<';
		}
	}

	int eventCount = 0;
	int offsetCount = 0;

	String alertTest=request.getParameter("alertTest");
	String infosearch=request.getParameter("infosearch");
	if(infosearch!=null && infosearch.trim().length()>0)
	{
		infosearch=com.egurkha.util.StringUtils.replace(infosearch,"|plus|","+");
		infosearch = com.egurkha.util.StringUtils.decodeSecurityChar(infosearch);
	}
	String compsearch=request.getParameter("compsearch");
	String s_event = request.getParameter("s_event");
	String subevent = request.getParameter("subevent");
	if(subevent!=null)
		subevent=EgURLDecoder.decode(subevent,"UTF-8");
	String selectedsubzone = request.getParameter("selectedsubzone");
	String startTime = request.getParameter("startDate");
	String endTime = request.getParameter("endDate");
	String s_state = request.getParameter("state");
	String selectedCompName = request.getParameter("compName");
	String selectedCompType = request.getParameter("compType");
	List t_compTypeList=null;
	if(selectedCompName!=null && selectedCompName.trim().length()>0)
		t_compTypeList = discInfo.getServerTypesForNick(selectedCompName);
	if(t_compTypeList!=null && t_compTypeList.size()>0 && selectedCompType!=null && selectedCompType.trim().length()>0 && selectedCompType.equalsIgnoreCase("Host_system"))
	{
		selectedCompType = (String)t_compTypeList.get(0);
	}

	session.setAttribute("monitorLastSession","/final/monitor/EgAlarmHistoryView.jsp?analysisBy="+s_event+"&analysis="+selectedCompType+"&selectedsubzone="+selectedsubzone+"&subevent="+subevent+"&compstate="+s_state+"&compNameList="+EgURLEncoder.encode(selectedCompName,"UTF-8"));
	if(selectedCompName!=null && selectedCompName.trim().length()>0)
	{
		selectedCompName=com.egurkha.util.StringUtils.replace(selectedCompName,"|amp|","&");
	}
	
	if(checkIsVM)
	{
		selectedCompType = vmType;
		if(insideViewInfo!=null && insideViewInfo.startsWith("+"))
			selectedCompName = insideViewInfo.substring(1);
		else
			selectedCompName = insideViewInfo;
	}
	if(selectedCompName!=null && selectedCompName.trim().length()>0)
	{
		selectedCompName=com.egurkha.util.StringUtils.replace(selectedCompName,"|amp|","&");
		selectedCompName=com.egurkha.util.StringUtils.replace(selectedCompName,"|slash|","\\");
	}
	if(selectedCompName!=null)
		selectedCompName=selectedCompName;//EgURLDecoder.decode(selectedCompName,"UTF-8");
	if(selectedCompName.equals("-1")) selectedCompName="Component Name (Optional)";
	String dashboardcomptype=request.getParameter("dashboardcomptype");
	if(selectedCompType!=null)
		selectedCompType=EgURLDecoder.decode(selectedCompType,"UTF-8");
	if( selectedCompType.equals("-1") || selectedCompType.equals("undefined") )
		selectedCompType="Component Type (Optional)";
	if(selectedCompType!=null && selectedCompType.length() ==0) 
		selectedCompType="Component Type (Optional)";
	int selection=0;
	
	
	String pdfHeading1="";
	String pdfHeading2="";
	String pdfHeading3="";
	String pdfHeading4="";
	String pdfHeading5="";
	String zonepdf="";
	String infosearchpdf="";
	String compsearchpdf="";
	String userforpdf="";
	if(s_event!=null && s_event.trim().length()>0 && (s_event.equalsIgnoreCase("Service") || s_event.equalsIgnoreCase("Segment") || s_event.equalsIgnoreCase("Zone")))
	{
		Vector v=new Vector();
		String str= mappingInfo.getTextDescription("monitor.history.Analysis By")+" : "+s_event;
		pdfHeading1=str;
		v.add(str);
		lst.add(v);
	}

	if(s_event!=null && s_event.trim().length()>0 && (s_event.equalsIgnoreCase("Service") || s_event.equalsIgnoreCase("Segment") || s_event.equalsIgnoreCase ("Zone")))
	{
		if(subevent!=null && subevent.trim().length()>0)
		{
			Vector v=new Vector();
			String str= mappingInfo.getTextDescription("monitor.history.Name") +" : "+subevent;
			
			pdfHeading2=" "+str;
			v.add(str);
			lst.add(v);
		}
	}

	if(s_event!=null && s_event.equals("Zone") && subevent!=null && subevent.trim().length()>0 && !subevent.equals("null"))
	{
		if(selectedsubzone!=null && selectedsubzone.trim().length()>0)
		{
			Vector v=new Vector();
			zonepdf= mappingInfo.getTextDescription("monitor.history.IncludeSubZone")+ ":"+selectedsubzone;
			if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0)
				pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+zonepdf;
			v.add(zonepdf);
			lst.add(v);
		}
	}

	if(compsearch!=null && compsearch.trim().length()>0)
	{
		Vector v=new Vector();
		compsearchpdf= mappingInfo.getTextDescription("monitor.history.Component Search")+" : "+compsearch;
		pdfHeading4=compsearchpdf;
		v.add(compsearchpdf);
		lst.add(v);
	}

	if(infosearch!=null && infosearch.trim().length()>0)
	{
		Vector v=new Vector();
		infosearchpdf= mappingInfo.getTextDescription("monitor.history.Description Search")+" : "+infosearch;
		pdfHeading3=infosearchpdf;
		v.add(infosearchpdf);
		lst.add(v);
	}

	if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1"))
	{
		Vector v=new Vector();
		userforpdf= mappingInfo.getTextDescription("monitor.history.User(s)")+" : "+showUserValue;
		pdfHeading5=userforpdf;
		v.add(userforpdf);
		lst.add(v);
	}

	if((selectedCompName.length()==0 || selectedCompName.equals("Component Name (Optional)")) && (selectedCompType.length()==0 || selectedCompType.equals("Component Type (Optional)")))
	{
		String str=mappingInfo.getTextDescription("monitor.history.Events : All ");
		pdfHeading=mappingInfo.getTextDescription("monitor.history.Events : All ");

		if(compsearch!=null && compsearch.trim().length()>0 && !compsearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading4;
		}

		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading3;
		}

		if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading5;
		}

		Vector v=new Vector();
		v.add(str);
		lst.add(v);
		selection=0;
	}
	else
	selection=1;

	if(selectedCompName.length()==0 && (selectedCompType.length()!=0 && !selectedCompType.equals("Component Type (Optional)") && !selectedCompType.equals("-1")))
	{
		String str=mappingInfo.getTextDescription("monitor.history.Component Type")+" : "+mappingInfo.getComponentTypeDescription(selectedCompType);
		if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0 && zonepdf!=null && zonepdf.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+zonepdf+ " , "+str;
		else if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+str;

		if(compsearch!=null && compsearch.trim().length()>0 && !compsearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading4;
		}

		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading3;
		}
		if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading5;
		}
		Vector v=new Vector();
		v.add(str);
		lst.add(v);
		selection=0;
	}

	if((selectedCompName.length() !=0 && !selectedCompName.equals("Component Name (Optional)") && !selectedCompName.equals("-1"))  && selectedCompType.length() == 0)
	{
		String str=mappingInfo.getTextDescription("monitor.history.Component Name")+" : "+selectedCompName;
		if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0 && zonepdf!=null && zonepdf.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+zonepdf+ " , "+str;
		else if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+str;

		if(compsearch!=null && compsearch.trim().length()>0 && !compsearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading4;
		}

		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading3;
		}
		if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading5;
		}
		Vector v=new Vector();
		v.add(str);
		lst.add(v);
		selection=0;
	}

	if((selectedCompName.length() !=0 && !selectedCompName.equals("-1")) && (selectedCompType.length()!=0 && !selectedCompType.equals("-1")))
	{
		String str = "";

		if(selectedCompType.equalsIgnoreCase("Component Type (Optional)") && selectedCompName.equalsIgnoreCase("Component Name (Optional)"))
		{
			str = mappingInfo.getTextDescription("monitor.history.Events : All ");
		}
		else if(selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
		{
			str=mappingInfo.getTextDescription("monitor.history.Component Name")+" : " +selectedCompName;
		}
		else if(selectedCompName.equalsIgnoreCase("Component Name (Optional)"))
		{
			str=mappingInfo.getTextDescription("monitor.history.Component Type")+" : " + mappingInfo.getComponentTypeDescription(selectedCompType);
		}
		else if(!selectedCompType.equalsIgnoreCase("Component Type (Optional)") && !selectedCompName.equalsIgnoreCase("Component Name (Optional)"))
		{
			if ( !StringUtils.isNull(selectedCompName) && selectedCompName.indexOf(":NULL") > -1 )
			{
				selectedCompName = selectedCompName.substring(0, selectedCompName.indexOf(":") );
			}
			str="Component Type : " + mappingInfo.getComponentTypeDescription(selectedCompType)+" , Component Name : "+selectedCompName;
		}

		if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0 && zonepdf!=null && zonepdf.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+zonepdf+ " , "+str;
		else if(pdfHeading1!=null && pdfHeading1.trim().length()>0 && pdfHeading2!=null && pdfHeading2.trim().length()>0)
			pdfHeading=pdfHeading1+" , "+pdfHeading2+" , "+str;
		else
			pdfHeading=str;

		if(compsearch!=null && compsearch.trim().length()>0 && !compsearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading4;
		}

		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading3;
		}
		if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("null"))
		{
			pdfHeading=pdfHeading+" , "+pdfHeading5;
		}
		Vector v=new Vector();
		v.add(str);
		lst.add(v);
		selection=0;
	}

	StringBuffer sbuf=new StringBuffer(pdfHeading);	
	for(int i=sbuf.length();i<=100;i++)
	{
		sbuf.append(" ");
	}
	
	pdfHeading=sbuf.toString();
	pdfHeading=pdfHeading.trim();
	if(s_state.length()==0)
	{
		String str=mappingInfo.getTextDescription("monitor.history.Priorities : All ");
		if(pdfHeading!=null && pdfHeading.endsWith(","))
			pdfHeading+=" "+mappingInfo.getTextDescription("monitor.history.Priorities : All ");
		else
			pdfHeading+=" , "+mappingInfo.getTextDescription("monitor.history.Priorities : All ");
		Vector v=new Vector();
		v.add(str);
		lst.add(v);
		selection=0;
	}
	else
	{
		String str=mappingInfo.getTextDescription("monitor.history.Priority")+" : ";
		if(s_state.equalsIgnoreCase("HIGHINTERMEDIATE"))
			str+=mappingInfo.getLabelDescription("Critical")+" & "+mappingInfo.getLabelDescription( "Major");	
		else if(s_state.equalsIgnoreCase("HIGH"))
			str+=" "+mappingInfo.getLabelDescription("Critical");		
		else if(s_state.equalsIgnoreCase("INTERMEDIATE"))
			str+=" "+mappingInfo.getLabelDescription("Major");
		else
			str+=" "+mappingInfo.getLabelDescription("Minor");
		if(pdfHeading!=null && pdfHeading.endsWith(","))
			pdfHeading+=str;
		else
			pdfHeading+=" , "+str;
		Vector v=new Vector();
		v.add(" , "+str);
		lst.add(v);
		selection=0;
	}

	String startDateValue ="";
	startDateValue = DateUtil.changeDateFormat(startTime,"MM/dd/yyyy HH:mm",currentDateFormat);
	EgMonTimeZoneConverter timeZoneConverter1= new EgMonTimeZoneConverter(startDateValue,user);
	String loginUserDateTime = (String)timeZoneConverter1.getDateTime();

	if(loginUserDateTime != null && !loginUserDateTime.trim().equals(""))
	{
		startDateValue = loginUserDateTime;
	}


	String endDateValue ="";
	endDateValue = DateUtil.changeDateFormat(endTime,"MM/dd/yyyy HH:mm",currentDateFormat);
	EgMonTimeZoneConverter timeZoneConverter2= new EgMonTimeZoneConverter(endDateValue,user);
	String loginUserDateTime1 = (String)timeZoneConverter2.getDateTime();

	if(loginUserDateTime1 != null && !loginUserDateTime1.trim().equals(""))
	{
		endDateValue = loginUserDateTime1;
	}

	String timelineStr = null;
	if(startTime != null && !endTime.equals(""))
	{
		
		date.add("\""+mappingInfo.getTextDescription("monitor.history.Start Date") + ":" +startDateValue+"\"");
		timelineStr = mappingInfo.getTextDescription("monitor.history.Timeline")+" : "+startDateValue;
	}
	if(endTime != null && !endTime.equals(""))
	{
		
		date.add("\""+mappingInfo.getTextDescription("monitor.history.End Date")+ ":" +endDateValue+"\"");
		if(timelineStr != null && timelineStr.length() > 0)
			timelineStr += "-"+endDateValue;
	}

	lst.add(date);
	
	String offsetStr = request.getParameter("start");
	if (offsetStr != null && !offsetStr.equals("NaN"))
	{
		offsetCount = Integer.parseInt(offsetStr);
	}
	if(startTime != null && startTime.indexOf(":") >-1 && startTime.indexOf(":") == startTime.lastIndexOf(":"))
	{
		startTime+=":00";
	}
	if(endTime != null && endTime.indexOf(":")>-1 && endTime.indexOf(":") == endTime.lastIndexOf(":"))
	{
		endTime+=":00";
	}
	if (StringUtils.isNull(count))
	{
		count = EgConstants.BLANK_STRING;
	}
	else
	{
		eventCount = Integer.parseInt(count);
	}
	
	logToTmpFile("INFO"," ","User = " + user.getLoginID()+"  HasAllCompAccess = " + isAllComp);
	//ErUserData erdata = new ErUserData(loginid,false);
	Vector v_zone=new Vector();
	Vector v_site=new Vector();
	Vector v_segment=new Vector();
	Vector v_availComps=new Vector();
	Vector v_segComp=new Vector();
	
	List servers = user.getServers(false);
	List vmUserCompList = new LinkedList();
	//Added by chandrasekhar to get real type for Host system.
	List userCompList=new LinkedList();
	if(!hasAllComponentAccess)
	{
		userCompList=user.getServers(false);
		vmUserCompList= getHostSystemServers(userCompList);
		if(userCompList!=null && userCompList.size()>0)
		{
			List userCompList_host=new LinkedList();
			for(int r=0; r<userCompList.size(); r++)
			{
				String s = (String) userCompList.get(r);
				if(s!=null && !s.endsWith(":NULL"))
				{
					StringTokenizer st=new StringTokenizer(s,":");
					String ctype=st.nextToken();
					String cname=st.nextToken();
					if(ctype!=null && cname!=null && ctype.trim().length()>0 && cname.trim().length()>0)
						userCompList_host.add(ctype+":"+cname+":NULL");
				}
			}
			if(userCompList_host!=null && userCompList_host.size()>0)
				userCompList.addAll(userCompList_host);
		}
	}//ended here
	List getServers = null;
	List getCompTypes = null;
	List getCompNames = null;
	List zoneComps=new ArrayList();
	boolean subzone=false;
	logToTmpFile("INFO","","Servers ... "+ servers);

	List newServers = new LinkedList();
	List vmServerTypes = new LinkedList();
	List vmNames = new LinkedList();
	List serverNames = new LinkedList();
	List serverTypes = new LinkedList();
	boolean showAll = false;
	boolean showAllTypes = false;
	boolean showAllComps = false;
	boolean dispAll = false;
		String nameList = null;
		
		String typeList = null;

		boolean allEvents = StringUtils.isNull(selectedCompName) && StringUtils.isNull(selectedCompType);
		
		EgTopoInfo topoInfo = new EgTopoInfo("manager");
		EgGroupInfo groupInfo = new EgGroupInfo();
		if(selectedCompName!=null && selectedCompName.length() == 0)
			selectedCompName = "Component Name (Optional)";
		if(selectedCompType!=null && (selectedCompType.length() == 0 || selectedCompType.equals("undefined")))
			selectedCompType = "Component Type (Optional)";
		if(selectedCompName!=null && selectedCompName.equalsIgnoreCase("Component Name (Optional)") && selectedCompType!=null && selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
		{
			showAll = true;
		}
		if(selectedCompName !=null && selectedCompName.equalsIgnoreCase("Component Name (Optional)"))
		{
			showAllComps = true;
		}
		if(selectedCompType!=null && selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
		{
			showAllTypes = true;
		}
		if(showAllTypes && showAllComps)
		{
			showAll = true;
		}
		if(allEvents || showAll)
		{
			dispAll = true;
		}
	if (servers.size() > 0 || hasVMs)
	{
		
		logToTmpFile("INFO","","All Events is " + allEvents);

		if(s_event!=null && s_event.trim().length()>0 && (s_event.equals("Service") || s_event.equals("Segment") || s_event.equals("Zone")) && subevent!=null && subevent.trim().length()>0)
		{
			v_availComps = topoInfo.getComponentsForSite(subevent);
			v_segComp = topoInfo.getComponentsForSegment(subevent);
			if(selectedsubzone!=null && selectedsubzone.trim().length()>0 && selectedsubzone.equalsIgnoreCase("Yes"))
			{
				subzone=true;
			}
			zoneComps = groupInfo.getAllComponentsUnderZone(subevent,subzone);
		}

		boolean flageToHitUser=false;

		if((!isAllComp) && (subevent!=null & subevent.equals("-1")))
			s_event = "Component";
		if(s_event!=null && s_event.trim().length()>0 && s_event.equals("Component"))
		{
			if (allEvents || showAll)
			{
				List xx = new LinkedList();
				if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
				{
					servers = new LinkedList();

					servers = selectedUser.getServers(false);

					List ls = selectedUser.getServerTypes();
					for (int i=0;i<ls.size();i++)
						serverTypes.add((String)ls.get(i));

					if(serverTypes!=null && !serverTypes.contains(Server.HOST_SYSTEM))
						serverTypes.add(Server.HOST_SYSTEM);
					List HostSysServers = new LinkedList();
					for (int r=0; r<servers.size(); r++)
					{
						String temp_comp = (String) servers.get(r);
						String t_selectedCompName = temp_comp.substring(temp_comp.indexOf(":")+1);
						int ind = t_selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							String s = t_selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							t_selectedCompName = t_selectedCompName + ":NULL";
						}
						serverNames.add(t_selectedCompName);
					}
					xx = Server.getHostSystems(servers, true);
					for (int r=0; r<xx.size(); r++)
					{
						String s = (String) xx.get(r);
						s =Server.HOST_SYSTEM+":"+s;
						if (!HostSysServers.contains(s))
						{
							HostSysServers.add(s);
						}
					}
					HostSysServers.addAll(servers);
					servers = HostSysServers;

					if(servers!=null && servers.size()>0)
					{
						flageToHitUser=true;
					}
				}
				else
				{
					if (isAllComp)
					{
						servers = new LinkedList();
					}
					else
					{
						List ls = user.getServerTypes();
						for (int i=0;i<ls.size();i++)
							serverTypes.add((String)ls.get(i));
						if(servers.size() > 0)
						{
						if(serverTypes!=null && !serverTypes.contains(Server.HOST_SYSTEM))
							serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
							xx = Server.getHostSystems(servers, true);
						for (int r=0; r<xx.size(); r++)
							{
								String s = (String) xx.get(r);
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							HostSysServers.addAll(servers);
							servers = HostSysServers;
						}
						if(hasVMs)
						{
							vmServerTypes = user.getOnlyVMTypes();
							//vmNames.addAll(user.getOnlyVMs());
							vmNames.addAll(user.getAlluserDesktopVms());
							Hashtable vmHostMap = EgLastMeasureThread.vmMapDbForHistory;
							if(vmNames!=null)
							{
								List allHostList = user.getAllUserAssignedHostList();
								if(allHostList != null && allHostList.size() > 0)
								{
									for(int a =0; a < allHostList.size();a++)
									{
										String host = (String)allHostList.get(a);
										String comp = host.substring(0,host.lastIndexOf(":"));
										String type = host.substring(host.lastIndexOf(":")+1);
										String forServer = type+":"+comp;
										if(!newServers.contains(forServer))
											newServers.add(forServer);
									}
									
								}
								else
								{
									for(int v =0; v< vmNames.size(); v++)
									{
										String vm = (String)vmNames.get(v);
										String user_vm_host = user.getVMHost(vm);
										if(user_vm_host != null && user_vm_host.trim().length() > 0)
										{
											String host = user_vm_host;
											String comp = host.substring(0,host.lastIndexOf(":"));
											String type = host.substring(host.lastIndexOf(":")+1);
											String forServer = type+":"+comp;
											if(!newServers.contains(forServer))
												newServers.add(forServer);
										}
										else if(vmHostMap!=null)
										{
											ArrayList hosts = (ArrayList)vmHostMap.get(vm);
											if(hosts!=null && hosts.size()  > 0)
											{
												for(int h =0; h < hosts.size(); h++)
												{
													String host = (String)hosts.get(h);
													String comp = host.substring(0,host.lastIndexOf(":"));
													String type = host.substring(host.lastIndexOf(":")+1);
													String forServer = type+":"+comp;
													if(!newServers.contains(forServer))
														newServers.add(forServer);
												}
											}
											else
											{
												newServers.addAll(user.getOnlyVMServers());
											}
										}
									}
								}
							}
							if(servers.size() == 0)
							{
								servers = new LinkedList();

							}
							else
							{
								newServers.addAll(servers);
							}
							servers = new LinkedList();
							servers.addAll(newServers);
							if(vmServerTypes!=null)
							{
								for(int v=0;v<vmServerTypes.size();v++)
								{
										String s_vmType = (String)vmServerTypes.get(v);
										if(!serverTypes.contains(s_vmType))
										{
											serverTypes.add(s_vmType);
										}
								}
							}
						}
					}
				}
				logToTmpFile("INFO","","Servers for this User = "+servers);
			}
			else
			{
				if(showAllTypes && !showAllComps)
				{
					List xx = new LinkedList();
					boolean flageToHit=true;
					if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
					{
						List showUserServers = selectedUser.getServers(true);
						int ind = selectedCompName.indexOf(":");
						if (ind < 0)
						{
							selectedCompName = selectedCompName + ":NULL";
						}

						if(showUserServers!=null && showUserServers.size()>0 && showUserServers.indexOf(selectedCompName)>-1)
						{
							flageToHitUser=true;
						}
						else
							flageToHit=false;
					}

					if(flageToHit)
					{
						List ls = user.getServerTypes();
						String ss_nick = selectedCompName;
						if(ss_nick.indexOf(":") != -1)
							ss_nick = ss_nick.substring(0,ss_nick.indexOf(":"));

						List foundoutServerTypes=discInfo.getServerTypesForNick(ss_nick);
						for (int i=0;i<ls.size();i++)
						{
							String cc_type = (String)ls.get(i);
							if(foundoutServerTypes== null || !foundoutServerTypes.contains(cc_type))
								continue;
							serverTypes.add(cc_type);
						}
						if(servers.size() > 0)
						{
							serverTypes.add(Server.HOST_SYSTEM);
						}
						if(!hasAllComponentAccess)
						{
							//selectedCompName = selectedCompName + ":NULL";
							if(userCompList!=null && userCompList.size() > 0)
							{
								for(int u =0 ; u < userCompList.size() ; u++)
								{

									String userComp = (String)userCompList.get(u);
									if(userComp.indexOf(selectedCompName) <0)
									{
										//Get the server for the vm
										Hashtable vmHostMap = EgLastMeasureThread.vmMapDbForHistory;
										ArrayList hostHitList = user.getVMHostHistory(selectedCompName);
										if(hostHitList != null && hostHitList.size() > 0)
										{
											for(int h=0;h< hostHitList.size();h++)
											{
												String host = (String)hostHitList.get(h);
												String comp = host.substring(0,host.lastIndexOf(":"));
												String type = host.substring(host.lastIndexOf(":")+1);
												String forServer = type + ":" + comp;
												serverNames.add(comp);
												serverTypes.add(type);
												xx.add(forServer);
												vmNames.add(selectedCompName);
											}
										}
										else if(vmHostMap!=null && vmHostMap.containsKey(selectedCompName))
										{
											ArrayList hosts = (ArrayList)vmHostMap.get(selectedCompName);
											String user_vm_host = user.getVMHost(selectedCompName);
											if(user_vm_host != null && user_vm_host.trim().length() > 0)
											{
												String host = user_vm_host;
												String comp = host.substring(0,host.lastIndexOf(":"));
												String type = host.substring(host.lastIndexOf(":")+1);
												serverNames.add(comp);
												serverTypes.add(type);
												vmNames.add(selectedCompName);
												xx.add(type+":"+comp);
											}
											else if(hosts!=null && hosts.size() > 0)
											{
												for(int h=0; h< hosts.size();h++)
												{
													String host = (String)hosts.get(h);
													String comp = host.substring(0,host.lastIndexOf(":"));
													String type = host.substring(host.lastIndexOf(":")+1);
													serverNames.add(comp);
													serverTypes.add(type);
													vmNames.add(selectedCompName);
													xx.add(type+":"+comp);
												}
											}
											else
											{
												newServers.addAll(user.getOnlyVMServers());
												if(newServers!=null && newServers.size() >0)
												{
													for(int n=0; n < newServers.size();n++)
													{
														String host = (String)newServers.get(n);
														String type = host.substring(0,host.indexOf(":"));
														String comp = host.substring(host.indexOf(":")+1);
														
														serverNames.add(comp);
														serverTypes.add(type);
														xx.add(host);
														vmNames.add(selectedCompName);
													}
												}
											}

										}
									}
								}
							}
							
						}
						
						if(servers!=null && servers.size() > 0)
						{
							for(int u =0 ; u < servers.size() ; u++)
							{

								String userComp = (String)servers.get(u);
								if(userComp.indexOf(selectedCompName) >-1)
								{
									int ind = selectedCompName.indexOf(":");
									if (ind >= 0)
									{
										String s = selectedCompName.substring(0,ind);
										serverNames.add(s+":NULL");
									}
									else
									{
										selectedCompName = selectedCompName + ":NULL";
									}
						serverNames.add(selectedCompName);

						String search = ":"+selectedCompName;

						//---added by saravanan--- // get only servers of the name we want
						List HostSysServers = new LinkedList();
						// In this following method, when used parameter as true , its make problem in IC comp. so now used false.
						//List xx_host_ser = Server.getHostSystems(servers, true);
						List xx_host_ser = Server.getHostSystems(servers, false);
						if(xx_host_ser!=null && xx_host_ser.size()>0)
						{
							for (int r=0; r<xx_host_ser.size(); r++)
							{
								String ss = (String) servers.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
								}

								ss = (String) xx_host_ser.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
											}
										}
										
									}
								}
							}
						}
					}
					servers = xx;
					//--end---
				}
				if(!showAllTypes && showAllComps)
				{
					List xx = new LinkedList();
					boolean flageToHit=true;
					if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
					{
						List ls = selectedUser.getServerTypes();
						if(ls!=null && ls.size()>0 && selectedCompType!=null && ls.contains(selectedCompType))
						{
							flageToHitUser=true;
							flageToHit=true;
							servers = new LinkedList();
							servers = selectedUser.getServers(false);
						}
						else
							flageToHit=false;
					}

					if(flageToHit)
					{
						if(selectedCompType.equals(vmType))
						{

							List allHostList = user.getAllUserAssignedHostList();
							if(allHostList != null && allHostList.size() > 0)
							{
								for(int a =0; a < allHostList.size();a++)
								{
									String host = (String)allHostList.get(a);
									String comp = host.substring(0,host.lastIndexOf(":"));
									String type = host.substring(host.lastIndexOf(":")+1);
									String forServer = type+":"+comp;
									serverNames.add(comp);
									serverTypes.add(type);
									xx.add(forServer);
								}
								logToTmpFile("INFO","","serverNames = "+serverNames);
								vmNames.addAll(a_userVMs);
							}
							else
							{
								Hashtable vmHostMap = EgLastMeasureThread.vmMapDbForHistory;
								for(int a =0; a < a_userVMs.size();a++)
								{
									String vm = (String)a_userVMs.get(a);
									if(vmHostMap!=null)
									{
										ArrayList hosts = (ArrayList)vmHostMap.get(vm);
										String user_vm_host = user.getVMHost(vm);
										if(user_vm_host != null && user_vm_host.trim().length() > 0)
										{
											String host = user_vm_host;
											String comp = host.substring(0,host.lastIndexOf(":"));
											String type = host.substring(host.lastIndexOf(":")+1);
											String forServer = type+":"+comp;
											serverNames.add(comp);
											serverTypes.add(type);
											xx.add(forServer);
											vmNames.add(vm);
										}
										else if(hosts!=null)
										{
											for(int h=0; h < hosts.size();h++)
											{
												String host = (String)hosts.get(h);
												String comp = host.substring(0,host.lastIndexOf(":"));
												String type = host.substring(host.lastIndexOf(":")+1);
												String forServer = type+":"+comp;
												serverNames.add(comp);
												serverTypes.add(type);
												xx.add(forServer);
												vmNames.add(vm);
											}
										}
										else
										{
											newServers.addAll(user.getOnlyVMServers());
											if(newServers!=null && newServers.size() >0)
											{
												for(int n=0; n < newServers.size();n++)
												{
													String host = (String)newServers.get(n);
													String type = host.substring(0,host.indexOf(":"));
													String comp = host.substring(host.indexOf(":")+1);
													
													serverNames.add(comp);
													serverTypes.add(type);
													xx.add(host);
													vmNames.add(selectedCompName);
												}
											}
										}
									}
								}
							}
						
						}
						else
						{
							serverTypes.add(selectedCompType);
						//---added by Saravanan.A--- for remove Host_system type in Alarm History 
						serverTypes.add(Server.HOST_SYSTEM);
						}
						if(!selectedCompType.equals(vmType))
						{
						String[] comp_name_arr=discInfo.getAllServersOfType(selectedCompType);
						List comp_name_list=new ArrayList();
						List comp_name_host_list = new LinkedList();
						if(comp_name_arr!=null && comp_name_arr.length>0)
						{
							comp_name_list=Arrays.asList(comp_name_arr);
							comp_name_host_list = Server.getHostSystems(comp_name_list, true);
						}
						// get only servers of the type we want
							
							for (int r=0; r<comp_name_list.size(); r++)
							{
								String s = (String) comp_name_list.get(r);
								if(servers.contains(s))
								{
									xx.add(s);// add real comp
									// add comp with host
									if(comp_name_host_list!=null && comp_name_host_list.size()>0)
									{
										String hs =(String) comp_name_host_list.get(r);
										if(showEventHistory)
											hs =Server.HOST_SYSTEM+":"+hs;
										else
											hs = selectedCompType+":"+hs;
										xx.add(hs);
									}
									//--end--
								}
							}
						}
						//--end by Saravanan.A for Host system removed from type list---
					}
					servers = xx;
					logToTmpFile("INFO","","Servers for this User for compType " +selectedCompType+ " = "+servers);
				}
				if(!showAllComps && !showAllTypes)
				{
					List xx = new LinkedList();
					boolean flageToHit=true;
					if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
					{
						List ls = selectedUser.getServerTypes();
						if(ls!=null && ls.size()>0 && selectedCompType!=null && ls.contains(selectedCompType))
						{
							List showUserServers = selectedUser.getServers(true);
							int ind = selectedCompName.indexOf(":");
							if (ind < 0)
							{
								selectedCompName = selectedCompName + ":NULL";
							}

							if(showUserServers!=null && showUserServers.size()>0 && showUserServers.indexOf(selectedCompName)>-1)
							{
								flageToHitUser=true;
							}
							else
								flageToHit=false;
						}
						else
							flageToHit=false;
					}

					if(flageToHit)
					{
						if(selectedCompType.equals(Server.HOST_SYSTEM))
						{
							serverTypes.add(Server.HOST_SYSTEM);
						}
						else
						{
							if(!selectedCompType.equals(vmType))
							{
							serverTypes.add(selectedCompType);
							serverTypes.add(Server.HOST_SYSTEM);
							}
							else
							{
							//Populate serverTypes and serverNames for vm
							//Type - VM , SelComp -> a VM
							//It may contain not only the current reporting host all other hosts
							//too which were initially assigned.
							Hashtable vmHostMap = EgLastMeasureThread.vmMapDbForHistory;
							ArrayList hostHitList = user.getVMHostHistory(selectedCompName);
							if(hostHitList != null && hostHitList.size() > 0)
							{
								for(int h=0;h< hostHitList.size();h++)
								{
									String host = (String)hostHitList.get(h);
									String comp = host.substring(0,host.lastIndexOf(":"));
									String type = host.substring(host.lastIndexOf(":")+1);
									String forServer = type + ":" + comp;
									serverNames.add(comp);
									serverTypes.add(type);
									xx.add(forServer);
									vmNames.add(selectedCompName);
								}
							}
							else if(vmHostMap!=null && vmHostMap.containsKey(selectedCompName))
							{
								ArrayList hosts = (ArrayList)vmHostMap.get(selectedCompName);
								String user_vm_host = user.getVMHost(selectedCompName);
								if(user_vm_host != null && user_vm_host.trim().length() > 0)
								{
									String host = user_vm_host;
									String comp = host.substring(0,host.lastIndexOf(":"));
									String type = host.substring(host.lastIndexOf(":")+1);
									String forServer = type + ":" + comp;
									serverNames.add(comp);
									serverTypes.add(type);
									xx.add(forServer);
									vmNames.add(selectedCompName);
								}
								else if(hosts!=null)
								{
									for(int h=0;h< hosts.size();h++)
									{
										String host = (String)hosts.get(h);
										String comp = host.substring(0,host.lastIndexOf(":"));
										String type = host.substring(host.lastIndexOf(":")+1);
										String forServer = type + ":" + comp;
										serverNames.add(comp);
										serverTypes.add(type);
										xx.add(forServer);
										vmNames.add(selectedCompName);
									}
								}
								else
								{
									newServers.addAll(user.getOnlyVMServers());
									if(newServers!=null && newServers.size() >0)
									{
										for(int n=0; n < newServers.size();n++)
										{
											String host = (String)newServers.get(n);
											String type = host.substring(0,host.indexOf(":"));
											String comp = host.substring(host.indexOf(":")+1);
											
											serverNames.add(comp);
											serverTypes.add(type);
											xx.add(host);
											vmNames.add(selectedCompName);
										}
									}
								}
							}
						}
						int ind = selectedCompName.indexOf(":");
						if(!selectedCompType.equals(vmType))
						{
					
							if (ind >= 0)
							{
							serverNames.add(selectedCompName);
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
							serverNames.add(selectedCompName);
						}
							
							String search = ":" + selectedCompName;
							for (int r=0; r<servers.size(); r++)
							{
								String ss = (String) servers.get(r);
								ind = ss.indexOf(":");
								
								if (ind >= 0)
								{
									String t_ss = "";
									String typ = ss.substring(0,ind);
									if(selectedCompType!=null && !selectedCompType.equals("Host_system"))
									{
										t_ss = ss;
										ss = ss.substring(ss.indexOf(":")+1,ss.length());
										if (!serverTypes.contains(typ))
											continue;
										if(serverNames.contains(ss.trim()))
										{
											xx.add(t_ss);
											// for host system
											if(ss.indexOf(":") > 0)
											{
												ss = ss.substring(0,ss.indexOf(":"));
											}
											String host_sys =  Server.getHostSystem(t_ss,true);
											if(host_sys!=null)
											{
												if(showEventHistory)
													xx.add("Host_system:" + ss + ":NULL");
												else
													xx.add(selectedCompType +":"+ ss + ":NULL");
											}
											//---end---
										}
									}
									else
									{
										t_ss = ss;

										ss = ss.substring(ss.indexOf(":")+1,ss.length());
										if(selectedCompType.equals("Host_system"))
										{
											if(ss.indexOf(":") > 0)
											{
												ss = ss.substring(0,ss.indexOf(":"));
											}
										}
										if(serverNames.contains(ss + ":NULL"))
										{
											String host_sys =  Server.getHostSystem(t_ss,true);
											if(host_sys!=null)
											{
												if(showEventHistory)
													xx.add("Host_system:" + ss + ":NULL");
												else
													xx.add(selectedCompType+":"+ss + ":NULL");
											}
										}
									}
								}
							}
						}
						servers = xx;
					}
				}
				}
			}
				if(selectedCompType.equalsIgnoreCase("Host_system") || selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
				{
					List xx = new LinkedList();
					List HostSysServers = new LinkedList();
					if(hasAllComponentAccess || vmAssigned)
					{
						xx = Server.getHostSystems(servers, true);
						for (int r=0; r<xx.size(); r++)
						{
						String s = (String) xx.get(r);

						s =Server.HOST_SYSTEM+":"+s;
						if (!HostSysServers.contains(s))
							HostSysServers.add(s);
					}
					HostSysServers.addAll(servers);
					logToTmpFile("INFO","","Host_System servers  = "+HostSysServers);
					servers = HostSysServers;
					}
				}
		}
		else if(s_event!=null && s_event.trim().length()>0 && s_event.equals("Service") && subevent!=null && subevent.trim().length()>0)
		{
			boolean flageToHit=true;
			if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
			{
				List selectedUserSiteServi           = new LinkedList();
				selectedUserSiteServi.addAll(selectedUser.getSites());
				selectedUserSiteServi.addAll(selectedUser.getServices());
				if(selectedUserSiteServi!=null && selectedUserSiteServi.size()>0 && selectedUserSiteServi.contains(subevent))
				{
					flageToHitUser=true;
				}
				else
					flageToHit=false;
			}

			if(flageToHit)
			{
				getServers = new ArrayList();
				getCompNames = new ArrayList();
				getCompTypes = new ArrayList();
				for(int i=0;i<v_availComps.size();i++)
				{
					String compTypes = (String)v_availComps.get(i);
					String comp_type=null;
					String comp_name=null;
					if(compTypes!=null && compTypes.trim().length()>0)
					{
						comp_name = compTypes.substring(0,compTypes.lastIndexOf(":"));
						comp_type = compTypes.substring(compTypes.lastIndexOf(":")+1);
						getServers.add(comp_type+":"+comp_name);
						if(!getCompNames.contains(comp_name))
						{
							getCompNames.add(comp_name);
						}
						if(!getCompTypes.contains(comp_type))
						{
							getCompTypes.add(comp_type);
						}
					}
				}
				if (showAll)
				{
					if (isAllComp)
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(getServers);
						servers = HostSysServers;
					}
					else
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(getServers);
						servers = HostSysServers;
					}
					logToTmpFile("INFO","","Servers for this User = "+servers);
				}
				else
				{
					if(showAllTypes && !showAllComps)
					{
						String ss_nick = selectedCompName;
						if(ss_nick.indexOf(":") != -1)
							ss_nick = ss_nick.substring(0,ss_nick.indexOf(":"));

						List foundoutServerTypes=discInfo.getServerTypesForNick(ss_nick);
						for (int i=0;i<getCompTypes.size();i++)
						{
							String cc_type = (String)getCompTypes.get(i);
							if(foundoutServerTypes== null || !foundoutServerTypes.contains(cc_type))
								continue;
							serverTypes.add(cc_type);
						}

						//for (int i=0;i<getCompTypes.size();i++)
						//	serverTypes.add((String)getCompTypes.get(i));
						if(!serverTypes.contains(Server.HOST_SYSTEM))
							serverTypes.add(Server.HOST_SYSTEM);

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
						}
						serverNames.add(selectedCompName);

						List xx = new LinkedList();
						String search = ":"+selectedCompName;

						//---added by saravanan--- // get only servers of the name we want
						List HostSysServers = new LinkedList();
						// In this following method, when used parameter as true , its make problem in IC comp. so now used false.
						//List xx_host_ser = Server.getHostSystems(getServers, true);
						List xx_host_ser = Server.getHostSystems(getServers, false);
						if(xx_host_ser!=null && xx_host_ser.size()>0)
						{
							if(xx_host_ser!=null && xx_host_ser.size()>0)
							{
								for (int r=0; r<xx_host_ser.size(); r++)
								{
									String ss = (String) getServers.get(r);
									if (ss.endsWith(search))
									{
										xx.add(ss);
									}

									ss = (String) xx_host_ser.get(r);
									if (ss.endsWith(search))
									{
										xx.add(ss);
									}
								}
							}
							servers = xx;
						}
						//--end---
					}
					if(!showAllTypes && showAllComps)
					{
						serverTypes.add(selectedCompType);
						//---added by saravanan---
						serverTypes.add(Server.HOST_SYSTEM);
						String[] comp_name_arr=discInfo.getAllServersOfType(selectedCompType); // get the comp from selected comp_type from EgDiscInfo.java 
						List comp_name_list=new ArrayList();
						List comp_name_host_list = new LinkedList();
						if(comp_name_arr!=null && comp_name_arr.length>0)
						{
							comp_name_list=Arrays.asList(comp_name_arr);
							comp_name_host_list = Server.getHostSystems(comp_name_list, true);
						}

						// get only servers of the type we want
						List xx = new LinkedList();
						for (int r=0; r<comp_name_list.size(); r++)
						{
							String s = (String) comp_name_list.get(r);
							if(getServers.contains(s))
							{
								xx.add(s);// add real comp
								// add comp with host
								if(comp_name_host_list!=null && comp_name_host_list.size()>0)
								{
									String hs =(String) comp_name_host_list.get(r);
									if(showEventHistory)
										hs =Server.HOST_SYSTEM+":"+hs;
									else
										hs = selectedCompType+":"+hs;
									xx.add(hs);
								}
								//--end--
							}
						}
						servers = xx;
						//--end by Saravanan.A for Host system removed from type list---
						logToTmpFile("INFO","","Servers for this User for compType " +selectedCompType+ " = "+servers);
					}
					if(!showAllComps && !showAllTypes)
					{
						if(selectedCompType.equals(Server.HOST_SYSTEM))
						{
							serverTypes.add(Server.HOST_SYSTEM);
						}
						else
						{
							serverTypes.add(selectedCompType);
							serverTypes.add(Server.HOST_SYSTEM);
						}

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							serverNames.add(selectedCompName);
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
							serverNames.add(selectedCompName);
						}

						List xx = new LinkedList();
						String search = ":" + selectedCompName;
						for (int r=0; r<getServers.size(); r++)
						{
							String ss = (String)getServers.get(r);
							ind = ss.indexOf(":");
							if (ind >= 0)
							{
								String t_ss = "";
								String typ = ss.substring(0,ind);
								if(selectedCompType!=null && !selectedCompType.equals("Host_system"))
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if (!serverTypes.contains(typ))
										continue;
									if(serverNames.contains(ss.trim()))
									{
										xx.add(t_ss);
										// for host system
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
										//---end---
									}
								}
								else
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if(selectedCompType.equals("Host_system"))
									{
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
									}
									if(serverNames.contains(ss + ":NULL"))
									{
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
									}
								}
							}
						}
						servers = xx;
					}
					if(selectedCompType.equalsIgnoreCase("Host_system") || selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
					{
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							s =Server.HOST_SYSTEM+":"+s;
							if (!HostSysServers.contains(s))
								HostSysServers.add(s);
						}
						HostSysServers.addAll(getServers);
						logToTmpFile("INFO","","Host_System servers  = "+HostSysServers);
						servers = HostSysServers;
					}
				}
			}
		}
		else if(s_event!=null && s_event.trim().length()>0 && s_event.equals("Segment") && subevent!=null && subevent.trim().length()>0)
		{
			boolean flageToHit=true;
			if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
			{
				List selectedUserSegments           = new LinkedList();
				selectedUserSegments.addAll(selectedUser.getSegments());
				if(selectedUserSegments!=null && selectedUserSegments.size()>0 && selectedUserSegments.contains(subevent))
				{
					flageToHitUser=true;
				}
				else
					flageToHit=false;
			}

			if(flageToHit)
			{
				getServers = new ArrayList();
				getCompNames = new ArrayList();
				getCompTypes = new ArrayList();
				for(int i=0;i<v_segComp.size();i++)
				{
					String compTypes = (String)v_segComp.get(i);
					String comp_type=null;
					String comp_name=null;
					if(compTypes!=null && compTypes.trim().length()>0)
					{
						comp_name = compTypes.substring(0,compTypes.lastIndexOf(":"));
						comp_type = compTypes.substring(compTypes.lastIndexOf(":")+1);
						getServers.add(comp_type+":"+comp_name);
						if(!getCompNames.contains(comp_name))
						{
							getCompNames.add(comp_name);
						}
						if(!getCompTypes.contains(comp_type))
						{
							getCompTypes.add(comp_type);
						}
					}
				}
				if (showAll)
				{
					if (isAllComp)
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(getServers);
						servers = HostSysServers;
					}
					else 
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(getServers);
						servers = HostSysServers;
					}
					logToTmpFile("INFO","","Servers for this User = "+servers);
				}
				else
				{
					if(showAllTypes && !showAllComps)
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
						}
						serverNames.add(selectedCompName);
						// get only servers of the name we want
						List xx = new LinkedList();
						String search = ":"+selectedCompName;

						//---added by saravanan--- // get only servers of the name we want
						List HostSysServers = new LinkedList();
						// In this following method, when used parameter as true , its make problem in IC comp. so now used false.
						//List xx_host_ser = Server.getHostSystems(getServers, true);
						List xx_host_ser = Server.getHostSystems(getServers, false);
						if(xx_host_ser!=null && xx_host_ser.size()>0)
						{
							for (int r=0; r<xx_host_ser.size(); r++)
							{
								String ss = (String) getServers.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
								}

								ss = (String) xx_host_ser.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
								}
							}
							servers = xx;
						}
						//--end---
					}

					if(!showAllTypes && showAllComps)
					{
						serverTypes.add(selectedCompType);
						serverTypes.add(Server.HOST_SYSTEM);
						String[] comp_name_arr=discInfo.getAllServersOfType(selectedCompType); // get the comp from selected comp_type from EgDiscInfo.java 
						List comp_name_list=new ArrayList();
						List comp_name_host_list = new LinkedList();
						if(comp_name_arr!=null && comp_name_arr.length>0)
						{
							comp_name_list=Arrays.asList(comp_name_arr);
							comp_name_host_list = Server.getHostSystems(comp_name_list, true);
						}

						// get only servers of the type we want
						List xx = new LinkedList();
						for (int r=0; r<comp_name_list.size(); r++)
						{
							String s = (String) comp_name_list.get(r);
							if(getServers.contains(s))
							{
								xx.add(s);// add real comp
								// add comp with host
								if(comp_name_host_list!=null && comp_name_host_list.size()>0)
								{
									String hs =(String) comp_name_host_list.get(r);
									if(showEventHistory)
										hs =Server.HOST_SYSTEM+":"+hs;
									else
										hs =selectedCompType+":"+hs;

									xx.add(hs);
								}
								//--end--
							}
						}
						servers = xx;
						//--end by Saravanan.A for Host system removed from type list---

						logToTmpFile("INFO","","Servers for this User for compType " +selectedCompType+ " = "+servers);
					}
					if(!showAllComps && !showAllTypes)
					{
						if(selectedCompType.equals(Server.HOST_SYSTEM))
						{
							serverTypes.add(Server.HOST_SYSTEM);
						}
						else
						{
							serverTypes.add(selectedCompType);
							serverTypes.add(Server.HOST_SYSTEM);
						}

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							serverNames.add(selectedCompName);
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
							serverNames.add(selectedCompName);
						}
						List xx = new LinkedList();
						String search = ":" + selectedCompName;
						for (int r=0; r<getServers.size(); r++)
						{
							String ss = (String)getServers.get(r);
							ind = ss.indexOf(":");
							if (ind >= 0)
							{
								String t_ss = "";
								String typ = ss.substring(0,ind);
								if(selectedCompType!=null && !selectedCompType.equals("Host_system"))
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if (!serverTypes.contains(typ))
										continue;
									if(serverNames.contains(ss.trim()))
									{
										xx.add(t_ss);
										// for host system
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
										//---end---
									}
								}
								else
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if(selectedCompType.equals("Host_system"))
									{
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
									}
									if(serverNames.contains(ss + ":NULL"))
									{
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
									}
								}
							}
						}
						servers = xx;
					}
					if(selectedCompType.equalsIgnoreCase("Host_system") || selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
					{
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(getServers, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							s =Server.HOST_SYSTEM+":"+s;
							if (!HostSysServers.contains(s))
								HostSysServers.add(s);
						}
						HostSysServers.addAll(getServers);
						logToTmpFile("INFO","","Host_System servers  = "+HostSysServers);
						servers = HostSysServers;
					}
				}
			}
		}
		else if(s_event!=null && s_event.trim().length()>0 && s_event.equals("Zone") && subevent!=null && subevent.trim().length()>0 && selectedsubzone!=null && selectedsubzone.trim().length()>0 && !zoneComps.isEmpty())
		{
			boolean flageToHit=true;
			if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
			{
				List selectedUserZones           = new LinkedList();
				selectedUserZones.addAll(selectedUser.getZones());
				if(selectedUserZones!=null && selectedUserZones.size()>0 && selectedUserZones.contains(subevent))
				{
					flageToHitUser=true;
				}
				else
					flageToHit=false;
			}

			if(flageToHit)
			{
				getCompNames = new ArrayList();
				getCompTypes = new ArrayList();
				for(int i=0;i<zoneComps.size();i++)
				{
					String compTypes = (String)zoneComps.get(i);
					String comp_type=null;
					String comp_name=null;
					if(compTypes!=null && compTypes.trim().length()>0)
					{
						comp_type = compTypes.substring(0,compTypes.indexOf(":"));
						comp_name = compTypes.substring(compTypes.indexOf(":")+1);
						if(!getCompNames.contains(comp_name))
						{
							getCompNames.add(comp_name);
						}
						if(!getCompTypes.contains(comp_type))
						{
							getCompTypes.add(comp_type);
						}
					}
				}
				if (showAll)
				{
					if (isAllComp)
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(zoneComps, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(zoneComps);
						servers = HostSysServers;
					}
					else 
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(zoneComps, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							if(showEventHistory)
							{
								s =Server.HOST_SYSTEM+":"+s;
								if (!HostSysServers.contains(s))
								{
									HostSysServers.add(s);
								}
							}
							else
							{
								List foundoutServerTypes=discInfo.getServerTypesForNick(s.substring(0,s.indexOf(":NULL")));
								if(foundoutServerTypes != null && foundoutServerTypes.size() == 1)
								{
									s = (String)foundoutServerTypes.get(0)+":"+s;
									if (!HostSysServers.contains(s))
									{
										HostSysServers.add(s);
									}
								}
								else if (foundoutServerTypes != null && foundoutServerTypes.size() > 1)
								{
									for (int i=0;i<foundoutServerTypes.size();i++)
									{
										String ctype = (String)foundoutServerTypes.get(i);
										String s1 = ctype+":"+s;
										if (!HostSysServers.contains(s1))
										{
											HostSysServers.add(s1);
										}
									}
								}
							}
						}
						HostSysServers.addAll(zoneComps);
						servers = HostSysServers;
					}
					logToTmpFile("INFO","","Servers for this User = "+servers);
				}
				else
				{
					if(showAllTypes && !showAllComps)
					{
						for (int i=0;i<getCompTypes.size();i++)
							serverTypes.add((String)getCompTypes.get(i));
						serverTypes.add(Server.HOST_SYSTEM);

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
						}
						serverNames.add(selectedCompName);
						// get only servers of the name we want
						List xx = new LinkedList();
						String search = ":"+selectedCompName;
						//---added by saravanan--- // get only servers of the name we want
						// In this following method, when used parameter as true , its make problem in IC comp. so now used false.
						//List xx_host_ser = Server.getHostSystems(zoneComps, true);
						List xx_host_ser = Server.getHostSystems(zoneComps, false);
						if(xx_host_ser!=null && xx_host_ser.size()>0)
						{
							for (int r=0; r<xx_host_ser.size(); r++)
							{
								String ss = (String) zoneComps.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
								}

								ss = (String) xx_host_ser.get(r);
								if (ss.endsWith(search))
								{
									xx.add(ss);
								}
							}
							servers = xx;
						}
						//--end---
					}

					if(!showAllTypes && showAllComps)
					{
						serverTypes.add(selectedCompType);
						serverTypes.add(Server.HOST_SYSTEM);
						String[] comp_name_arr=discInfo.getAllServersOfType(selectedCompType); // get the comp from selected comp_type from EgDiscInfo.java 
						List comp_name_list=new ArrayList();
						List comp_name_host_list = new LinkedList();
						if(comp_name_arr!=null && comp_name_arr.length>0)
						{
							comp_name_list=Arrays.asList(comp_name_arr);
							comp_name_host_list = Server.getHostSystems(comp_name_list, true);
						}
						// get only servers of the type we want
						List xx = new LinkedList();
						for (int r=0; r<comp_name_list.size(); r++)
						{
							String s = (String) comp_name_list.get(r);
							if(zoneComps.contains(s))
							{
								xx.add(s);// add real comp
								// add comp with host
								if(comp_name_host_list!=null && comp_name_host_list.size()>0)
								{
									String hs =(String) comp_name_host_list.get(r);
									if(showEventHistory)
										hs =Server.HOST_SYSTEM+":"+hs;
									else
										hs =selectedCompType+":"+hs;
									xx.add(hs);
								}
								//--end--
							}
						}
						servers = xx;
						//--end by Saravanan.A for Host system removed from type list---
						logToTmpFile("INFO","","Servers for this User for compType " +selectedCompType+ " = "+servers);
					}
					if(!showAllComps && !showAllTypes)
					{
						if(selectedCompType.equals(Server.HOST_SYSTEM))
						{
							serverTypes.add(Server.HOST_SYSTEM);
						}
						else
						{
							serverTypes.add(selectedCompType);
							serverTypes.add(Server.HOST_SYSTEM);
						}

						int ind = selectedCompName.indexOf(":");
						if (ind >= 0)
						{
							serverNames.add(selectedCompName);
							String s = selectedCompName.substring(0,ind);
							serverNames.add(s+":NULL");
						}
						else
						{
							selectedCompName = selectedCompName + ":NULL";
							serverNames.add(selectedCompName);
						}
						List xx = new LinkedList();
						String search = ":" + selectedCompName;
						for (int r=0; r<zoneComps.size(); r++)
						{
							String ss = (String)zoneComps.get(r);
							ind = ss.indexOf(":");
							if (ind >= 0)
							{
								String t_ss = "";
								String typ = ss.substring(0,ind);
								if(selectedCompType!=null && !selectedCompType.equals("Host_system"))
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if (!serverTypes.contains(typ))
										continue;
									if(serverNames.contains(ss.trim()))
									{
										xx.add(t_ss);
										// for host system
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
										//---end---
									}
								}
								else
								{
									t_ss = ss;
									ss = ss.substring(ss.indexOf(":")+1,ss.length());
									if(selectedCompType.equals("Host_system"))
									{
										if(ss.indexOf(":") > 0)
										{
											ss = ss.substring(0,ss.indexOf(":"));
										}
									}
									if(serverNames.contains(ss + ":NULL"))
									{
										String host_sys =  Server.getHostSystem(t_ss,true);
										if(host_sys!=null)
										{
											if(showEventHistory)
												xx.add("Host_system:" + ss + ":NULL");
											else
												xx.add(selectedCompType+":"+ss + ":NULL");
										}
									}
								}
							}
						}
						servers = xx;
					}
					if(selectedCompType.equalsIgnoreCase("Host_system") || selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
					{
						List HostSysServers = new LinkedList();
						List xx = Server.getHostSystems(zoneComps, true);
						for (int r=0; r<xx.size(); r++)
						{
							String s = (String) xx.get(r);
							s =Server.HOST_SYSTEM+":"+s;
							if (!HostSysServers.contains(s))
								HostSysServers.add(s);
						}
						HostSysServers.addAll(zoneComps);
						logToTmpFile("INFO","","Host_System servers  = "+HostSysServers);
						servers = HostSysServers;
					}
				}
			}
			servers = ListUtils.removeDuplicates(servers);
		}

		String ctypes = "";
		if (serverTypes.size() > 0)
		{
			// To find out if a component type have host system level layer or not.
			if(selectedCompType!=null && !selectedCompType.equals(vmType))
			{
				ArrayList layersForComp = tablesInfo.getLayersForComponent(selectedCompType);
				ArrayList layersForHostSystem = tablesInfo.getLayersForComponent("Host_system");
				if(layersForComp!=null && layersForComp.size()>0)
				{
					boolean isHostLayers=false;
					if(layersForHostSystem!=null && layersForHostSystem.size()>0)
					{
						for(int j=0;j<layersForHostSystem.size();j++)
						{
							String host_layer=(String)layersForHostSystem.get(j);
							if(host_layer!=null && layersForComp.contains(host_layer))
							{
								isHostLayers=true;
								break;
							}
						}
					}

				if(!isHostLayers)
				{
					if(serverTypes.contains("Host_system"))
						serverTypes.remove("Host_system");
					}
				}
			}
			//---end--
			ctypes = StringUtils.getArrayAsString(serverTypes.toArray(), '\'');
		}

		String cnames = "";
		if (serverNames.size() > 0)
			cnames = StringUtils.getArrayAsString(serverNames.toArray(), '\'');

		/*if (serverTypes.indexOf(Server.HOST_SYSTEM) == -1)
		{
			serverTypes.add(Server.HOST_SYSTEM);
		}*/
		List serversWithHost = null;
		if (selectedCompName!=null || selectedCompType.equals(Server.HOST_SYSTEM) || selectedCompType.equalsIgnoreCase("Component Type (Optional)"))
		{
			/*
			 * When a component name is selected, the component type will not be known
			 */
			serversWithHost = Server.getServersWithHostIp(serverNames, false);
		}
		else
		{
			serversWithHost = Server.getServersWithHostIp(serverNames, true);
		}
		
		nameList = StringUtils.getArrayAsString(serversWithHost.toArray(), '\'');
		typeList = StringUtils.getArrayAsString(serverTypes.toArray(), '\'');
		if(isFromDashBoard)
		{
			
			EgServerDashboardModel dashboardModel=new EgServerDashboardModel();
			StringBuffer sb_layer=new StringBuffer();
			String  layerList="";
			String isNoComponentsSelected=request.getParameter("NoComponentsSelected");
			//Vector layers=dashboardModel.getLayersForModule(ctypes,"System");
			Vector layers = new Vector();
			if(isFromInsideviewDashboard)
			{
				layers.add(request.getParameter("Layer"));
			}
			else if(isNoComponentsSelected!=null && isNoComponentsSelected.equals("true"))
			{
				if(layerName!=null && layerName.equalsIgnoreCase("All"))
				{
					String selCompType=com.egurkha.util.StringUtils.replace(ctypes,"'","");
					Vector hostLayers=dashboardModel.getLayersForModule(selCompType,"System");
					Vector networkLayers=dashboardModel.getLayersForModule(selCompType,"Network");
					Vector applicationLayers=dashboardModel.getLayersForModule(selCompType,"Application");
					if(hostLayers!=null && !hostLayers.isEmpty())
					{
						layers.addAll(hostLayers);
					}
					if(networkLayers!=null && !networkLayers.isEmpty())
					{
						layers.addAll(networkLayers);
					}
					if(applicationLayers!=null && !applicationLayers.isEmpty())
					{
						layers.addAll(applicationLayers);
					}
				}
			}
			else
			{
				if((layerName!=null && layerName.equalsIgnoreCase("network")))
				{
					layers=dashboardModel.getLayersForModule(dashboardcomptype,"Network");
				}
				else if(layerName!=null && layerName.equalsIgnoreCase("application"))
				{
					layers=dashboardModel.getLayersForModule(dashboardcomptype,"Application");
				}
				else if(layerName!=null && layerName.equalsIgnoreCase("system"))
				{
					layers=dashboardModel.getLayersForModule(dashboardcomptype,"System");
				}
				else if(layerName!=null && layerName.equalsIgnoreCase("HOST"))
				{
					layers=dashboardModel.getLayersForModule(dashboardcomptype,"System");
				}
				else if((layerName!=null && layerName.equalsIgnoreCase("all")) || (tab!=null && tab.equalsIgnoreCase("custom")))
				{
					layers=dashboardModel.getLayersForModule(dashboardcomptype,"custom");
				}
			}
			if(layerName!=null && (layerName.equalsIgnoreCase("all") || layerName.equalsIgnoreCase("system") || layerName.equalsIgnoreCase("network") || layerName.equalsIgnoreCase("application")))
			{
				if(layers!=null && layers.size()>0)
				{
					for(int  i=0;i<layers.size();i++)
					{
						String tmp_layer=(String)layers.get(i);
						sb_layer.append("'");
						sb_layer.append(tmp_layer);
						sb_layer.append("'");
						if(i!=layers.size()-1)
						{
							sb_layer.append(",");
						}
					}
				}
				layerList=sb_layer.toString();
				if(layerList.endsWith(","))
				{
					layerList=layerList.substring(0,layerList.lastIndexOf(","));
				}
			}
			else
			{
				if(isFromInsideviewDashboard && layers!=null && layers.size()>0)
				{
					for(int  i=0;i<layers.size();i++)
					{
						String tmp_layer=(String)layers.get(i);
						sb_layer.append("'");
						sb_layer.append(tmp_layer);
						sb_layer.append("'");
						if(i!=layers.size()-1)
						{
							sb_layer.append(",");
						}
					}
					layerList=sb_layer.toString();
				}
				else
				{
					layerList="'"+layerName+"'";
				}
				if(layerList.endsWith(","))
				{
					layerList=layerList.substring(0,layerList.lastIndexOf(","));
				}
				
			}
			String cnames1="",ctypes1="";
			if(cnames!=null && cnames.indexOf("'")!=-1)
			{
				cnames1=cnames.substring(1,cnames.length()-1);
			}
			if(ctypes!=null && ctypes.indexOf("'")!=-1)
			{
				ctypes1=ctypes.substring(1,ctypes.length()-1);
				if(ctypes1!=null && ctypes1.indexOf("'")>-1 && ctypes1.indexOf(",")>-1)
				{
					ctypes1=ctypes1.substring(0,ctypes1.indexOf("'"));
				}
			}
			if(dashboardcomptype.equalsIgnoreCase("Network_node"))
			{
					ctypes1="Network_node";
			}
			Vector tests=dashboardDAO.getTestsForLayer(cnames1,dashboardcomptype,layerList);
			StringBuffer sb_test=new StringBuffer();
			Vector systemTests = new Vector();
			Vector netTests = new Vector();
			systemTests.add("VmgDiskActivityTest");			systemTests.add("VmgSystemTest");
			systemTests.add("VmgDiskSpaceTest");systemTests.add("VmgUptimeTest");
			systemTests.add("VmgOsHandleTest");systemTests.add("VmgWinMemoryTest");
			systemTests.add("VmgOSMemoryTest");systemTests.add("VmgWinServiceTest");
			netTests.add("VmgTcpTest");netTests.add("VmgTcpTrafficTest");netTests.add("VmgWinNetTrafficTest");//netTests.add("VmgNetworkTrafficTest");
			if(tests!=null && tests.size()>0)
			{
				for(int  i=0;i<tests.size();i++)
				{
					String tmp_test=(String)tests.get(i);
					//Fix for restricting the tests of system /network
					//otherwise all tests are returned.
					if(isFromInsideviewDashboard)
					{
						if(checkIsVM)
						{
							
												
							if(source!=null && !source.equals("null") && source.equals("systemDash"))
							{
								//if(systemTests!=null && !systemTests.contains(tmp_test))
								if(netTests!=null && netTests.contains(tmp_test))
								{
									continue;
								}
							}
							if(source!=null && !source.equals("null") && source.equals("netDash"))
							{
								if(netTests!=null && !netTests.contains(tmp_test))
								{
									continue;
								}
							}
						}
						else
						{
								if(tab!=null && !tab.equals("null") && tab.equalsIgnoreCase("Network"))
								{
									if(netTests!=null && !netTests.contains(tmp_test))
									{
										continue;
									}
								}
								if(tab!=null && !tab.equals("null") && tab.equalsIgnoreCase("System"))
								{
									//if(systemTests!=null && !systemTests.contains(tmp_test))
									if(netTests!=null && netTests.contains(tmp_test))
									{
										continue;
									}
								}
							}
					}
					sb_test.append("'");
					sb_test.append(tmp_test);
					sb_test.append("'");
					if(i!=tests.size()-1)
					{
						sb_test.append(",");
					}
				}
			}
			testList=sb_test.toString();
			if(testList.endsWith(","))
				testList=testList.substring(0,testList.lastIndexOf(","));

		}
		
		boolean reverseList = false;

		EgDbAdapterUI egDb = EgDbAdapterTypeUI.getObject();
		String status = egDb.setConnection();
		try
		{
			
			//if (eventCount == 0)
			{
				if(tab!=null && tab.equalsIgnoreCase("custom"))
				{
					String selCompName=com.egurkha.util.StringUtils.replace(cnames,"'","");
					if(selCompName!=null && selCompName.indexOf(":")!=-1)
					{
						String temp_compname=selCompName.substring(0,selCompName.indexOf(":"));
						cnames+=",'"+temp_compname+":NULL'";
						servers.add("Host_system:"+temp_compname+":NULL");
					}
					ctypes+=",";
					ctypes+="'Host_system'";
					typeList+=",'Host_system'";
				}

				String infosearch_for_jsp=infosearch;

				if(compsearch!=null && compsearch.trim().length()>0 && !compsearch.equalsIgnoreCase("null"))
				{
					if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
					{
						infosearch_for_jsp=infosearch+"^egsep^"+compsearch;
					}
					else
					{
						// don't remove the space in that string.
						infosearch_for_jsp=" ^egsep^"+compsearch;
					}
				}
				if(servers!=null && servers.size()>0)
				{
					StringBuffer tmp_srvrs = new StringBuffer();
					for(int sr = 0; sr<servers.size(); sr++)
					{
						String tmp_cmp = (String)servers.get(sr);
						tmp_cmp = tmp_cmp.substring(tmp_cmp.indexOf(":")+1);
						if(tmp_cmp!=null && tmp_srvrs.indexOf(tmp_cmp)==-1)
						{
							tmp_srvrs.append("'");
							tmp_srvrs.append(tmp_cmp);
							tmp_srvrs.append("'");
							tmp_srvrs.append(",");
						}
					}
					tmp_srvers = tmp_srvrs.toString();
					if(tmp_srvers!=null && tmp_srvers.lastIndexOf(",")>-1)
						tmp_srvers = tmp_srvers.substring(0,tmp_srvers.lastIndexOf(","));
				}

				if(showUserValue!=null && showUserValue.trim().length()>0 && !showUserValue.equalsIgnoreCase("-1") && selectedUser!=null)
				{
					if(flageToHitUser)
					{
						String db_sdate = startTime;
						//String db_sdate = DateUtil.changeDateFormat(startTime,currentDateFormat,"MM/dd/yyyy HH:mm");
						String db_edate = endTime; 
						//String db_edate = DateUtil.changeDateFormat(endTime,currentDateFormat,"MM/dd/yyyy HH:mm");
							if(isCount)
							{
								int cRec = 0;
								if(showEventHistory || hasVMs)
									cRec = getEventHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex);
								else
									cRec = getAlarmHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,alertTest);
							
								int pgCount = cRec/evtPerPage;

								if(cRec%evtPerPage!=0)
								pgCount++;							
								response.getWriter().write(""+pageSize+"^"+pgCount+"^"+cRec+"|");
							}
							else
							{
								if(loadbydefault || request.getParameter("fromDashBoard") != null)
								{
									if(EgInstallInfo.isSuperManager)
									{
										int cRec=0;
										if(showEventHistory || hasVMs)
											cRec = getEventHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex);
										else
											cRec = getAlarmHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,alertTest);
										//System.out.println();
										//System.out.println("first is called with startIndex " + startIndex + " and endIndex " + endIndex + " " + managerRowCount);
										int myStartIndex = startIndex+1;
										boolean started=false;
										boolean isOver = false;
										int rowNumber = 1;
										rowManager.clear();
										Iterator mitr = managerRowCount.iterator();
										while(mitr.hasNext())
										{
											String mgrid = (String)mitr.next();
											int rows = ((Integer)managerRowCount.get(mgrid)).intValue();
											for(int j=1;j<=rows;j++)
											{
												if(rowNumber==myStartIndex)
												{
													started = true;
													Vector v = new Vector();
													v.add(j);
													rowManager.put(mgrid,v);
												}
												else if(started)
												{
													if(rowManager.containsKey(mgrid))
													{
														Vector v = (Vector)rowManager.get(mgrid);
														v.add(j);
													}
													else
													{
														Vector v = new Vector();
														v.add(j);
														rowManager.put(mgrid,v);
													}
												}
												if(rowNumber==endIndex)
												{
													isOver =true;
													break;
												}
												rowNumber++;
											}
											if(isOver)
												break;
										}
										//System.out.println("second rowManager " + rowManager);
									}
									if(showEventHistory || hasVMs)
										history = getEventHistory(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,evtPerPage,Monutil);
									else
										history = getAlarmHistory(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,evtPerPage,alertTest,Monutil);
								}
							}
					}
					else
					{
						history = new LinkedList();
					}
				}
				else
				{
					String db_sdate = startTime;
					//String db_sdate = DateUtil.changeDateFormat(startTime,currentDateFormat,"MM/dd/yyyy HH:mm");
					String db_edate = endTime;
					//String db_edate = DateUtil.changeDateFormat(endTime,currentDateFormat,"MM/dd/yyyy HH:mm");
					
						if(isCount)
						{
							int cRec = 0;
							if(showEventHistory || hasVMs)
								cRec = getEventHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex);
							else
								cRec = getAlarmHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,alertTest);

							int pgCount = cRec/evtPerPage;
							if(cRec%evtPerPage!=0)
								pgCount++;							
							response.getWriter().write(""+pageSize+"^"+pgCount+"^"+cRec+"|");

						}
						else
						{
							if(loadbydefault || request.getParameter("fromDashBoard") != null)
							{
								if(EgInstallInfo.isSuperManager)
								{
									int cRec=0;
									if(showEventHistory || hasVMs)
										cRec = getEventHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex);
									else
										cRec = getAlarmHistoryCount(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,alertTest);
									//System.out.println();
									//System.out.println("second is called with startIndex " + startIndex + " and endIndex " + endIndex + " " + managerRowCount);
									int myStartIndex = startIndex+1;
									boolean started=false;
									boolean isOver = false;
									int rowNumber = 1;
									rowManager.clear();
									Iterator mitr = managerRowCount.iterator();
									while(mitr.hasNext())
									{
										String mgrid = (String)mitr.next();
										int rows = ((Integer)managerRowCount.get(mgrid)).intValue();
										for(int j=1;j<=rows;j++)
										{
											if(rowNumber==myStartIndex)
											{
												started = true;
												Vector v = new Vector();
												v.add(j);
												rowManager.put(mgrid,v);
											}
											else if(started)
											{
												if(rowManager.containsKey(mgrid))
												{
													Vector v = (Vector)rowManager.get(mgrid);
													v.add(j);
												}
												else
												{
													Vector v = new Vector();
													v.add(j);
													rowManager.put(mgrid,v);
												}
											}
											if(rowNumber==endIndex)
											{
												isOver =true;
												break;
											}
											rowNumber++;
										}
										if(isOver)
											break;
									}
									//System.out.println("second rowManager " + rowManager);
								}
								if(showEventHistory || hasVMs)
									history = getEventHistory(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,evtPerPage,Monutil);
								else
									history = getAlarmHistory(servers, cnames, ctypes, db_sdate, db_edate, null, minDuration,s_state,egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch_for_jsp,vmUserCompList,dispAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList,s_event,startIndex,endIndex,evtPerPage,alertTest,Monutil);
							}
						}
				}

				List history2 = new LinkedList();
				for (int z=0; z<history.size(); z++)
				{
					String[] values = (String[])history.get(z);
					if(values!=null && values.length>0)
					{
						String[] row = new String[values.length];
						System.arraycopy(values, 0, row, 0, row.length);

						String t_site_name=row[1];
						if(EgInstallInfo.isSuperManager)
						{
							t_site_name=row[2];
						}
						t_site_name=(t_site_name==null || t_site_name.trim().length()==0)?"NULL":t_site_name;
						if ((!t_site_name.equals("NULL")) && (!t_site_name.equals("NONE")) && (!siteNames.contains(t_site_name)))
							continue;

						history2.add((String[])values);
					}
				}

				if(history2!=null)
				{
					history=new LinkedList();
					history=history2;
				}
				eventCount = history.size();
				json.put("total",String.valueOf(eventCount));
				/*if(infosearch==null || infosearch.trim().length()==0 || StringUtils.isNull(infosearch) || infosearch.equals(""))
				{
					eventCount = getEventsCount(servers, cnames, ctypes, startTime, endTime, minDuration,s_state, egDb);
				}
				if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equalsIgnoreCase("null"))
				{
					eventCount = getEventsCount(servers, cnames, ctypes, startTime, endTime, minDuration,s_state, egDb,infosearch,mappingInfo);
				}*/
				//if("ALL".equalsIgnoreCase(request.getParameter("eventsPerPage")))
				//{
					maxPageItems = eventCount;
				//}
				logToTmpFile("INFO","","Event Count for the selection is " + eventCount);
			}
			//if (eventCount > 0)
			{
				/*if (offsetCount > eventCount/2)
				{
					if(selectedArrangeOption==null)
					{
						reverseList = true;
						offsetCount = eventCount - offsetCount;
					}
					else
					{
						reverseList = false;
						offsetCount += maxPageItems;
					}
				}
				else
				{
					reverseList = false;
					offsetCount += maxPageItems;
				}*/
				if (offsetCount > eventCount/2)
				{
					reverseList = true;
					offsetCount = eventCount - offsetCount;
					Collections.reverse(history);
					if (history.size() > offsetCount)
					{
						history.subList(offsetCount , history.size()).clear();
					}
					
				}
				else
				{
					reverseList = false;
					offsetCount += maxPageItems;
					if (history.size() > offsetCount)
					{
						history.subList(offsetCount , history.size()).clear();
					}
				}
				
				String fromLink  =request.getParameter("fromLink");
				//history = getEventHistory(servers, cnames, ctypes, startTime, endTime, null,
					//		offsetCount, minDuration,s_state, !reverseList, //egDb,mappingInfo,langinfo,selectedArrangeOption,infosearch);
				// session objects created here which is used to store the request parameters needed for pdf and csv format

				String offset = Integer.toString(offsetCount);
				String ev_count = Integer.toString(eventCount);
				String min_duration = Long.toString(minDuration);
				
				HashMap eventHist = new HashMap();
				eventHist.put("pdfheading",pdfHeading.trim());
				eventHist.put("lst", lst);
				eventHist.put("servers",servers);
				eventHist.put("cnames", cnames);
				eventHist.put("ctypes", ctypes);
				eventHist.put("startTime", startTime);
				eventHist.put("endTime", endTime);
				eventHist.put("offsetCount", offset);
				eventHist.put("arrangeAlarms", selectedArrangeOption);
				eventHist.put("minDuration", min_duration);
				eventHist.put("s_state", s_state);
				eventHist.put("infosearch", infosearch);
				eventHist.put("compsearch", compsearch);
				eventHist.put("s_event", s_event);
				eventHist.put("isFromInsideviewDashboard", new Boolean(isFromInsideviewDashboard));
				eventHist.put("isFromDashBoard", new Boolean(isFromDashBoard));
				eventHist.put("insideViewInfo", (String)insideViewInfo);
				eventHist.put("testList", (String)testList);
				eventHist.put("user", (User)user);
				if(selectedUser!=null)
				{
					eventHist.put("selectedUser", (User)selectedUser);
					eventHist.put("flageToHitUser", new Boolean(flageToHitUser));
				}
				
				HashMap eventHistDB = new HashMap();

				eventHistDB.put("nameList",nameList);
				eventHistDB.put("typeList", typeList);
				eventHistDB.put("startTime", startTime);
				eventHistDB.put("endTime", endTime);
				eventHistDB.put("eventCount", ev_count);
				eventHistDB.put("arrangeAlarms", selectedArrangeOption);
				eventHistDB.put("minDuration", min_duration);
				eventHistDB.put("s_state", s_state);
				eventHistDB.put("infosearch", infosearch);
				eventHistDB.put("compsearch", compsearch);
				eventHistDB.put("s_event", s_event);
				eventHistDB.put("isFromInsideviewDashboard", new Boolean(isFromInsideviewDashboard));
				eventHistDB.put("isFromDashBoard", new Boolean(isFromDashBoard));
				eventHistDB.put("insideViewInfo", (String)insideViewInfo);
				eventHistDB.put("testList", (String)testList);
				eventHistDB.put("user", (User)user);
				eventHist.put("showAll", new Boolean(showAll));
				eventHist.put("hasVMs", new Boolean(hasVMs));
				eventHist.put("selectedCompType", selectedCompType);
				eventHist.put("selectedCompName", selectedCompName);
				eventHist.put("showAllTypes", new Boolean(showAllTypes));
				eventHist.put("showAllComps", new Boolean(showAllComps));
				eventHist.put("vmUserCompList", vmUserCompList);
				eventHist.put("showEventHistory",new Boolean(showEventHistory));
				if(selectedUser!=null)
				{
					eventHistDB.put("selectedUser", (User)selectedUser);
					eventHistDB.put("flageToHitUser", new Boolean(flageToHitUser));
				}
				
				session.setAttribute("eventdata", eventHist); //session object for all component access
				session.setAttribute("eventdatadb", eventHistDB); //session object for selected components

				/*int recordCount = history.size();
				if (recordCount > maxPageItems)
				{
					if (reverseList)
					{
						history.subList(0 , recordCount-maxPageItems).clear();
						Collections.reverse(history);
					}
					else 
					{
						
						history.subList(Math.min(offsetCount, recordCount), recordCount).clear();
						history.subList(0, offsetCount-maxPageItems).clear();
					}
				}
				else
				{
					 // If the user directly goes to the last page
					if (reverseList)
					{
						Collections.reverse(history);
					}
				}*/
				//rs.close();

				//Change maxWidth to any number for splitting the line
				maxWidth = 20;
				if (allEvents)
				{
					maxWidth = 15;
				}
				if(EgInstallInfo.isSuperManager)
				{
					all = (List)this.processResults(history, maxWidth,mappingInfo,hasVMs,Monutil);
				}
				else
				{
					all = (List)this.processResults(history, maxWidth,langinfo,hasVMs,Monutil);
				}
			}
			egDb.releaseConnection(false);
		}
		catch(Exception se)
		{
			
			egDb.releaseConnection(true);
		}
		finally
		{
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
	}
%>
<%
			String selectedType = null;
			String selectedName = null;
			if (!StringUtils.isNull(selectedCompType))
			{
				selectedType = "type";
			}
			else if (!StringUtils.isNull(selectedCompName))
			{
				selectedName = "name";
			}
	if (selectedType == null || selectedType.equals("type"))
		{
			labelObj.put("monitor.history.Comp Type",mappingInfo.getTextDescription("monitor.history.Component Type"));
		}

		if (selectedName == null || selectedName.equals("name"))
		{
				if(hasVMs)
				{
					if(onlyVMAssigned && !vmAssigned)
					{
						labelObj.put("monitor.history.Comp Name",mappingInfo.getTextDescription("monitor.history.VM Name"));					// Prem
					}
					else
					{
						labelObj.put("monitor.history.Comp Name",mappingInfo.getTextDescription("monitor.history.Component Name/VM Name"));			// Prem
					}
				}
				else
				{
					labelObj.put("monitor.history.Comp Name",mappingInfo.getTextDescription("monitor.history.Component Name"));
				}
		}
		labelObj.put("monitor.common.Service(s)",mappingInfo.getTextDescription("monitor.common.Service(s)"));
		labelObj.put("monitor.common.Test",mappingInfo.getTextDescription("monitor.common.Test"));
		labelObj.put("monitor.common.Description",mappingInfo.getTextDescription("monitor.common.Description"));

		if(hasAllComponentAccess && selectedUser==null && showUsers!=null && (showUsers.equalsIgnoreCase("true") || showUsers.equalsIgnoreCase("yes")))
		{
			labelObj.put("monitor.common.User(s)",mappingInfo.getTextDescription("monitor.common.User(s)"));
		}

		labelObj.put("monitor.history.Start Time",mappingInfo.getTextDescription("monitor.history.Start Time"));
		labelObj.put("monitor.history.Duration",mappingInfo.getTextDescription("monitor.history.Duration"));
		labelObj.put("monitor.common.Manager ID",mappingInfo.getTextDescription("monitor.common.Manager ID"));
		json.put("screenLabels",labelObj);

		if (eventCount > 0 && all!=null) 
		{
			size = all.size();

			//---Configure DateTimeTokenizer for results
			DateTimeTokenizer dtt = new DateTimeTokenizer();
			dtt.setDateFormat(DateTimeTokenizer._YMD);
			dtt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
			dtt.setTimeFormat(DateTimeTokenizer.HMS);
			dtt.setYearAsYY(false);
%>
	
		
		
																	
<%
		String manager_id = "-";
		int historyCount = 0;
		EgDbInfo dbInfo = new EgDbInfo(EgConstants.MANAGER);
		EgTestInfo tokInfo = new EgTestInfo(EgConstants.MANAGER);
		TestBean testBean = new TestBean();
		Hashtable ht_changeHash = EgConfigChangeThread.ht_changeHash;

		if(hasAllComponentAccess && !onlyVMAssigned && selectedUser==null && showUsers!=null && (showUsers.equalsIgnoreCase("true") || showUsers.equalsIgnoreCase("yes")))
		{
			resultUserCompMap = (Hashtable)ecumb.getUserNamesForComponentMap();
		}

		//for config icon
		String changeQs = "";
		String compNameForConfig = "";
		String cNameForConfig = "";

		Hashtable comp_service_hash=new Hashtable();

		try
		{
		if(all!=null)
		for (int i=0;i<all.size();i++)
		{
			JSONObject hist = new JSONObject();
%>
<%
			String[] row = (String[])all.get(i);
			if(EgInstallInfo.isSuperManager)
			{
				manager_id = row[0];
				String row_copy[] = new String[row.length-1];
				System.arraycopy(row, 1, row_copy, 0, row_copy.length);
				row=row_copy;
			}
			String t_site_name=row[1];
			t_site_name=(t_site_name==null || t_site_name.trim().length()==0)?"NULL":t_site_name;
			if ((!t_site_name.equals("NULL")) && (!t_site_name.equals("NONE")) && (!siteNames.contains(t_site_name)))
				continue;
			
			String[] data1 = (String[])history.get(i);
			if(EgInstallInfo.isSuperManager)
			{
				String data_copy[] = new String[data1.length-1];
				System.arraycopy(data1, 1, data_copy, 0, data_copy.length);
				data1=data_copy;
			}
			long timeDiff = Long.parseLong((String)row[10]);

			String fileName = null;
			
			if (AlarmPriorities.HIGH_PRIORITY.equals(row[8]))
			{
				fileName = "/final/monitor/eg_images/bullet_s_HIGH.gif";
			}
			else if (AlarmPriorities.MEDIUM_PRIORITY.equals(row[8]))
			{
				fileName = "/final/monitor/eg_images/bullet_s_INTERMEDIATE.gif";
			}
			else if (AlarmPriorities.LOW_PRIORITY.equals(row[8]))
			{
				fileName = "/final/monitor/eg_images/bullet_s_LOW.gif";
			}
			else if (AlarmPriorities.UNKNOWN_STATE.equals(row[8]))
			{
				fileName = "/final/monitor/eg_images/bullet_s_UNKNOWN.gif";
			}
			else //if (AlarmPriorities.GOOD_STATE.equals(row[8]))
			{
				fileName = "/final/monitor/eg_images/bullet_s_GOOD.gif";
			}
			/*
			 * 0	EVENT_ID				
			 * 1	SITE_NAME 
			 * 2	COMP_NAME 
			 * 3	COMP_TYPE 
			 * 4	INFO
			 * 5	TEST_NAME
			 * 6	MEASURE
			 * 7	MSMT_HOST 
			 * 8	EVENT_SVRTY
			 * 9	START TIME
			 * 10	END TIME
			 */
			String screenShot="";
			if(formatInfo.isSSHandledTest(row[5]) && row[6].toLowerCase().indexOf("availability") != -1 )
			{
				String trgt_host = row[2];
				String port_no = "NULL";
				if(row[2].indexOf(":") != -1)
				{
					trgt_host = row[2].substring(0,row[2].indexOf(":"));
					port_no = row[2].substring(row[2].indexOf(":")+1);
				}
				String t_info = row[4];				
				t_info = t_info.substring(t_info.indexOf("$info$"));

				t_info = t_info.substring(t_info.indexOf("+"));
				
				String changedInfo =  t_info;
				if(row[5].equalsIgnoreCase("GenericLogonSimTest"))				
					changedInfo = t_info.substring(0,t_info.indexOf(":")+1)+"Total";
				
				String strTime1 = row[9];
				String time1 = strTime1.substring(strTime1.indexOf(" ") + 1);
				strTime1 = strTime1.substring(0, strTime1.indexOf(" "));
				
				String str_msmt_time = DateUtil.changeDateFormat(strTime1, "MM/dd/yy", "MM/dd/yyyy")+ " " + time1;

				screenShot = Monutil.getScreenShot(row[1],trgt_host,port_no,row[5]+"_DDD",row[6],changedInfo,str_msmt_time);
			}

			String test_name_value=row[5];
			String testLabel_for_display=row[4];
			String info = "";
			String testMeasureAlert=null;
			boolean ifInside=false;
			boolean infoAdded = false;
			if(testLabel_for_display!=null && testLabel_for_display.lastIndexOf("{")>-1 && testLabel_for_display.lastIndexOf("}")>-1)
			{
				testMeasureAlert=testLabel_for_display.substring(0,testLabel_for_display.lastIndexOf("{"));
				testLabel_for_display=testLabel_for_display.substring(testLabel_for_display.lastIndexOf("{")+1,testLabel_for_display.lastIndexOf("}"));
				ifInside=true;
				if(testMeasureAlert != null && testMeasureAlert.indexOf("~!~") != -1){
					infoAdded = Boolean.parseBoolean(testMeasureAlert.substring(testMeasureAlert.indexOf("~!~")+3));
					testMeasureAlert = testMeasureAlert.substring(0,testMeasureAlert.indexOf("~!~"));
					ifInside = !infoAdded;
				}
				if(testLabel_for_display!=null && testLabel_for_display.startsWith("+"))
				{
					testLabel_for_display=testLabel_for_display.substring(1);
				}
				info = testLabel_for_display;
			}
			else if(testLabel_for_display.indexOf("$info$") > 0){
				testMeasureAlert = testLabel_for_display.substring(0,testLabel_for_display.indexOf("$info$"));
				if(testMeasureAlert != null && testMeasureAlert.indexOf("~!~") != -1){
					infoAdded = Boolean.parseBoolean(testMeasureAlert.substring(testMeasureAlert.indexOf("~!~")+3));
					testMeasureAlert = testMeasureAlert.substring(0,testMeasureAlert.indexOf("~!~"));
				}
				testLabel_for_display = testLabel_for_display.substring(testLabel_for_display.indexOf("$info$")+6);
				testLabel_for_display = testLabel_for_display.startsWith("+")?testLabel_for_display.substring(1):testLabel_for_display;
				if(testLabel_for_display!=null && testLabel_for_display.trim().length()>0)
					ifInside = !infoAdded;
				info = testLabel_for_display;
			}
			
			String isSymbol=(String)egUI.getValue("Tests_For_LayerModel_Images",test_name_value);
			String skipInfos=(String)egUI.getValue("MISC_ARGS","FINAL_INFO");
									
			boolean symbolBlock=true;
			ArrayList exclude_info_list = new ArrayList();
			if(skipInfos!=null && skipInfos.trim().length()>0)
				exclude_info_list = tokInfo.egTokenizer(skipInfos, ",");
			
			if(exclude_info_list!=null && testLabel_for_display!=null && exclude_info_list.contains(testLabel_for_display.trim()))
				symbolBlock=false;

			if(symbolBlock && isSymbol!=null && isSymbol.trim().equalsIgnoreCase("::") && testLabel_for_display!=null && testLabel_for_display.trim().length()>0)
			{
				String temp_testLabel="";
				ArrayList token_list = tokInfo.egTokenizer(testLabel_for_display, "::");
				
				if(token_list!=null && token_list.size()>0)
				{
					String end_image_name_value="";
					String tooltip_value="";
					for(int ind_no=0;ind_no<token_list.size();ind_no++)
					{
						String path=(String)token_list.get(ind_no);

						if(ind_no==0)
						{
							if(test_name_value!=null && test_name_value.equals("RHEVMDataCenTest") || test_name_value.equals("RHEVMStorageTest") || test_name_value.equals("RHEVMClusterTest"))
							{
								end_image_name_value="rhev_datacenter";
								tooltip_value="monitor.layermodel.Datacenter";
							}
							else
							{
								end_image_name_value="vsphere_datacenter_11";
								tooltip_value="monitor.layermodel.Datacenter";
							}
						}
						else if(ind_no==1)
						{
							if(test_name_value!=null && test_name_value.equals("RHEVMStorageTest"))
							{
								end_image_name_value="rhev_datastore";
								tooltip_value="monitor.layermodel.Data&nbsp;Storage";
							}
							else if(test_name_value!=null && test_name_value.equals("RHEVMClusterTest"))
							{
								end_image_name_value="rhev_cluster";
								tooltip_value="monitor.layermodel.Cluster";
							}
							else
							{
								end_image_name_value="vsphere_cluster_11";
								tooltip_value="monitor.layermodel.Cluster";
							}
						}
						else if(ind_no==2)
						{
							end_image_name_value="vsphere_resourcepool_11";
							tooltip_value="monitor.layermodel.monitor.layermodel.Resource&nbsp;pool";
						}

						if(path!=null && path.trim().length()>0)
						{
							ArrayList path_list = tokInfo.egTokenizer(path, "->");
							if(path_list!=null && path_list.size()==2)
							{
								String folder_part=(String)path_list.get(0);
								if(folder_part!=null && folder_part.trim().length()>0)
								{
									ArrayList folder_list = tokInfo.egTokenizer(folder_part, "\\");
									if(folder_list!=null && folder_list.size()>0)
									{
										for(int w=0;w<folder_list.size();w++)
										{
											String folder_name=(String)folder_list.get(w);

											temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png'  border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+folder_name.trim();
										}
									}
								}

								String dc_or_cl_rp_path=(String)path_list.get(1);
								if(dc_or_cl_rp_path!=null && dc_or_cl_rp_path.trim().length()>0)
								{
									ArrayList dc_or_cl_rp_list = tokInfo.egTokenizer(dc_or_cl_rp_path,"/");
						
									if(dc_or_cl_rp_list!=null && dc_or_cl_rp_list.size()>0)
									{
										for(int w=0;w<dc_or_cl_rp_list.size();w++)
										{
											String dc_or_cl_rp_name=(String)dc_or_cl_rp_list.get(w);
											temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+end_image_name_value+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value)+"'/> "+dc_or_cl_rp_name.trim();
										}
									}
								}
							}
							else if(path_list!=null && path_list.size()==1)
							{
								String dc_or_cl_rp_path=(String)path_list.get(0);
								if(dc_or_cl_rp_path!=null && dc_or_cl_rp_path.trim().length()>0)
								{
									ArrayList dc_or_cl_rp_list = tokInfo.egTokenizer(dc_or_cl_rp_path,"/");
						
									if(dc_or_cl_rp_list!=null && dc_or_cl_rp_list.size()>0)
									{
										for(int w=0;w<dc_or_cl_rp_list.size();w++)
										{
											String dc_or_cl_rp_name=(String)dc_or_cl_rp_list.get(w);
											temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+end_image_name_value+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value)+"'/> "+dc_or_cl_rp_name.trim();
										}
									}
								}
							}
						}
					}
					if(temp_testLabel!=null && temp_testLabel.trim().length()>0){
						if(ifInside)
							testLabel_for_display=temp_testLabel;
						else{
							String tmp_testMeasureAlert = testMeasureAlert;
								if(tmp_testMeasureAlert!=null && !tmp_testMeasureAlert.equalsIgnoreCase("NULL") && tmp_testMeasureAlert.trim().length()>0 && tmp_testMeasureAlert.indexOf(testLabel_for_display)>-1)
									testMeasureAlert = tmp_testMeasureAlert.substring(0,tmp_testMeasureAlert.indexOf(testLabel_for_display))+""+temp_testLabel+""+tmp_testMeasureAlert.substring(tmp_testMeasureAlert.indexOf(testLabel_for_display)+testLabel_for_display.length());
						}
					}
				}
			}
			else if(symbolBlock && isSymbol!=null && isSymbol.trim().equalsIgnoreCase("/") && testLabel_for_display!=null && testLabel_for_display.trim().length()>0)
			{
				String temp_testLabel="";
				ArrayList resourcepool_list = tokInfo.egTokenizer(testLabel_for_display,"/");
				if(resourcepool_list!=null && resourcepool_list.size()>0)
				{
					for(int w=0;w<resourcepool_list.size();w++)
					{
						String resourcepool_name=(String)resourcepool_list.get(w);
						temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_resourcepool_11.png'  border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Resource&nbsp;pool")+"'/> "+resourcepool_name.trim();
					}
				}
				if(temp_testLabel!=null && temp_testLabel.trim().length()>0){
					if(ifInside)
						testLabel_for_display=temp_testLabel;
					else{
						String tmp_testMeasureAlert = testMeasureAlert;
							if(tmp_testMeasureAlert!=null && !tmp_testMeasureAlert.equalsIgnoreCase("NULL") && tmp_testMeasureAlert.trim().length()>0 && tmp_testMeasureAlert.indexOf(testLabel_for_display)>-1)
								testMeasureAlert = tmp_testMeasureAlert.substring(0,tmp_testMeasureAlert.indexOf(testLabel_for_display))+""+temp_testLabel+""+tmp_testMeasureAlert.substring(tmp_testMeasureAlert.indexOf(testLabel_for_display)+testLabel_for_display.length());
					}
				}
			}
			//code added
			else if(symbolBlock && isSymbol!=null && isSymbol.trim().equalsIgnoreCase("$eg^") && testLabel_for_display!=null && testLabel_for_display.trim().length()>0)
			{
				String temp_testLabel="";
				if(test_name_value.equals("MsSqlDatabaseTest") || test_name_value.equals("MsSqlDBStatusTest") || test_name_value.equals("MsSqlLongRunQryTest") || test_name_value.equals("MsSqlMissingIdxTest") || test_name_value.equals("MsSqlNetTest") || test_name_value.equals("MsSqlSpaceTest") || test_name_value.equals("MsSqlTabSizeTest") || test_name_value.equals("MsSqlTransSpaceTest") || test_name_value.equals("MsSqlUnusedIdxTest"))
				{
					temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/db_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.DB")+"'/> "+testLabel_for_display.trim();
				}
				else if(test_name_value.equals("MsSqlAppsTest") || test_name_value.equals("MsSqlSessionStTest"))
				{
					temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+testLabel_for_display.trim();
				}
				else if(test_name_value.equals("CtxAppTest")|| test_name_value.equals("CtxXcXAAppTest"))
				{
					String testLabel_for_display_name=testLabel_for_display.trim();
					if(testLabel_for_display_name.indexOf(':') != -1)
					{
						StringTokenizer strToken = new StringTokenizer(testLabel_for_display_name,":");
						String firstString=strToken.nextToken();
						String secondString=strToken.nextToken();
						if(firstString!=null && firstString.indexOf('\\') != -1)
						{
							String folderName=firstString.substring(0,firstString.lastIndexOf('\\'));
							StringTokenizer stringToken = new StringTokenizer(folderName,"\\");
							while (stringToken.hasMoreElements())
							{
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
							}
							String workGroup=firstString.substring(firstString.lastIndexOf('\\')+1);
							temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/workerGroup_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.WorkerGroup")+"'/> "+workGroup;
						}
						else
						{
							if(firstString!=null && firstString.indexOf('/') != -1)
							{
								String folderName=firstString.substring(0,firstString.lastIndexOf('/'));
								StringTokenizer stringToken = new StringTokenizer(folderName,"/");
								while (stringToken.hasMoreElements())
								{
									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
								}
								String workGroup=firstString.substring(firstString.lastIndexOf('/')+1);
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/workerGroup_small12.png' border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.WorkerGroup")+"'/> "+workGroup;
							}
							else
							{
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/workerGroup_small12.png' border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.WorkerGroup")+"'/> "+firstString;
							}
						}
						if(secondString!=null && secondString.indexOf('\\') != -1)
						{
							String folderName=secondString.substring(0,secondString.lastIndexOf('\\'));
							StringTokenizer stringToken = new StringTokenizer(folderName,"\\");
							while (stringToken.hasMoreElements())
							{
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
							}
							String applicationName=secondString.substring(secondString.lastIndexOf('\\')+1);
							temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+applicationName;
						}
						else
						{	
							if(secondString!=null && secondString.indexOf('/') != -1)
							{
								String folderName=secondString.substring(0,secondString.lastIndexOf('/'));
								StringTokenizer stringToken = new StringTokenizer(folderName,"/");
								while(stringToken.hasMoreElements())
								{
									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
								}
								String applicationName=secondString.substring(secondString.lastIndexOf('/')+1);
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+applicationName;
							}
							else
							{
								temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+secondString;
							}
						}
					}//end if :
					else if(testLabel_for_display_name.indexOf('\\') != -1)
					{
						String folderName=testLabel_for_display_name.substring(0,testLabel_for_display_name.lastIndexOf('\\'));
						StringTokenizer stringToken = new StringTokenizer(folderName,"\\");
						while(stringToken.hasMoreElements())
						{
							temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
						}
						String applicationName=testLabel_for_display_name.substring(testLabel_for_display_name.lastIndexOf('\\')+1);
						temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+applicationName;
						
					}
					else if(testLabel_for_display_name.indexOf('/') != -1)
					{
						String folderName=testLabel_for_display_name.substring(0,testLabel_for_display_name.lastIndexOf('/'));
						StringTokenizer stringToken = new StringTokenizer(folderName,"/");
						while(stringToken.hasMoreElements())
						{
							temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+stringToken.nextElement();
						}
						String applicationName=testLabel_for_display_name.substring(testLabel_for_display_name.lastIndexOf('/')+1);
						temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+applicationName;
					}
					else
					{
						temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/application_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Application")+"'/> "+testLabel_for_display.trim();
					}
				} //end if for citrix
				else
				{
					temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/user_small12.png' border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.User")+"'/> "+testLabel_for_display.trim();
				}
				if(temp_testLabel!=null && temp_testLabel.trim().length()>0){
					if(ifInside)
						testLabel_for_display=temp_testLabel;
					else{
						String tmp_testMeasureAlert = testMeasureAlert;
						if(tmp_testMeasureAlert!=null && !tmp_testMeasureAlert.equalsIgnoreCase("NULL") && tmp_testMeasureAlert.trim().length()>0 && tmp_testMeasureAlert.indexOf(testLabel_for_display)>-1)
							testMeasureAlert = tmp_testMeasureAlert.substring(0,tmp_testMeasureAlert.indexOf(testLabel_for_display))+""+temp_testLabel.trim()+""+tmp_testMeasureAlert.substring(tmp_testMeasureAlert.indexOf(testLabel_for_display)+testLabel_for_display.length());
					}
				}
			}
			//code ended
			else if(symbolBlock && isSymbol!=null && isSymbol.trim().equalsIgnoreCase(":") && testLabel_for_display!=null && testLabel_for_display.trim().length()>0)
			{
				String temp_testLabel="";
				ArrayList token_list = tokInfo.egTokenizer(testLabel_for_display, ":");
				if(token_list!=null && token_list.size()>0)
				{
					String end_image_name_value="";
					String image_name_value2="";
					String tooltip_value="";
					String tooltip_value2="";
					for(int ind_no=0;ind_no<token_list.size();ind_no++)
					{
						String path=(String)token_list.get(ind_no);

						if(ind_no==0)
						{
							end_image_name_value="xen_small_desktopcontroller";
							tooltip_value="monitor.layermodel.Controller";

							image_name_value2="xen_small_desktopgroup";
							tooltip_value2="monitor.layermodel.Desktop&nbsp;Groups";
						}
						else if(ind_no==1)
						{
							end_image_name_value="xen_small_desktop";
							tooltip_value="monitor.layermodel.Desktop";
						}

						if(path!=null && path.trim().length()>0)
						{
							if(ind_no==0)
							{
								ArrayList path_list = tokInfo.egTokenizer(path, "->");
								if(path_list!=null && path_list.size()==2)
								{
									String controller=(String)path_list.get(0);
									
									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+end_image_name_value+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value)+"'/> "+controller.trim();
									
									String folder_and_groupName=(String)path_list.get(1);

									if(folder_and_groupName!=null && folder_and_groupName.trim().length()>0)
									{
										ArrayList f_and_g_list = tokInfo.egTokenizer(folder_and_groupName, "\\");

										if(f_and_g_list!=null && f_and_g_list.size()>0)
										{
											if(f_and_g_list.size()==2)
											{
												String  folder_name=(String)f_and_g_list.get(0);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png'  border = '0'  title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+folder_name.trim();

												String group_name=(String)f_and_g_list.get(1);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+image_name_value2+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value2)+"'/> "+group_name.trim();
											}
											else if(f_and_g_list.size()==1)
											{
												String groupName=(String)f_and_g_list.get(0);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+image_name_value2+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value2)+"'/> "+groupName.trim();
											}
										}
									}
								}
								else if(path_list!=null && path_list.size()==1)
								{
									String folder_and_groupName=(String)path_list.get(0);

									if(folder_and_groupName!=null && folder_and_groupName.trim().length()>0)
									{
										ArrayList f_and_g_list = tokInfo.egTokenizer(folder_and_groupName, "\\");

										if(f_and_g_list!=null && f_and_g_list.size()>0)
										{
											if(f_and_g_list.size()==2)
											{
												String  folder_name=(String)f_and_g_list.get(0);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/vsphere_folder_11.png'  border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Folder")+"'/> "+folder_name.trim();
												
												String group_name=(String)f_and_g_list.get(1);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+image_name_value2+".png'  border = '0' title='"+mappingInfo.getTextDescription(tooltip_value2)+"'/> "+group_name.trim();
											}
											else if(f_and_g_list.size()==1)
											{
												String groupName=(String)f_and_g_list.get(0);
												temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+image_name_value2+".png'  border = '0' title='"+mappingInfo.getTextDescription(tooltip_value2)+"'/> "+groupName.trim();
											}
										}
									}
								}
							}
							else if(ind_no==1)
							{
								ArrayList path_list = tokInfo.egTokenizer(path, "\\");
								if(path_list!=null && path_list.size()==2)
								{
									String  domain_name=(String)path_list.get(0);
									
									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/domain_name.png'  border = '0' title='"+mappingInfo.getTextDescription("monitor.layermodel.Domain")+"'/> "+domain_name.trim();
									
									String deskTopName=(String)path_list.get(1);

									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+end_image_name_value+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value)+"'/> "+deskTopName.trim();
								}
								else if(path_list!=null && path_list.size()==1)
								{
									String deskTopName=(String)path_list.get(0);

									temp_testLabel=temp_testLabel+" <img src ='/final/monitor/eg_images/"+end_image_name_value+".png'  border = '0'  title='"+mappingInfo.getTextDescription(tooltip_value)+"'/> "+deskTopName.trim();
								
								}
							}
						}
					}
				}
				if(temp_testLabel!=null && temp_testLabel.trim().length()>0){
					if(ifInside)
						testLabel_for_display=temp_testLabel;
					else{
						String tmp_testMeasureAlert = testMeasureAlert;
							if(tmp_testMeasureAlert!=null && !tmp_testMeasureAlert.equalsIgnoreCase("NULL") && tmp_testMeasureAlert.trim().length()>0 && tmp_testMeasureAlert.indexOf(testLabel_for_display)>-1)
								testMeasureAlert = tmp_testMeasureAlert.substring(0,tmp_testMeasureAlert.indexOf(testLabel_for_display))+""+temp_testLabel+""+tmp_testMeasureAlert.substring(tmp_testMeasureAlert.indexOf(testLabel_for_display)+testLabel_for_display.length());
					}
				}
			}
			if(testLabel_for_display!=null && testMeasureAlert!=null && testMeasureAlert.trim().length()>0)
			{
				testLabel_for_display=ifInside?testMeasureAlert+" {"+testLabel_for_display+"}":testMeasureAlert;
			}
			String sinfo ="";
			String shost = Server.getServerNameWithoutPort(data1[2]);
			String scomp = shost + ":" +Server.getServerPort(data1[2], false);
			if(data1[2].startsWith(scomp + ":"))
				sinfo = data1[2].substring(scomp.length() + 1);
			String infospl=data1[4];
			if(infospl!=null && infospl.startsWith("+"))
				infospl="*"+infospl.substring(1);
			if(infospl!=null && infospl.indexOf("+")>-1)
			{
				infospl=com.egurkha.util.StringUtils.replace(infospl,"+","|plus|");
			}
			if(infospl!=null && infospl.indexOf("&")>-1)
			{
				infospl=com.egurkha.util.StringUtils.replace(infospl,"&","|amp|");
			}
			if(infospl!=null && infospl.indexOf("%")>-1)
			{
				infospl=com.egurkha.util.StringUtils.replace(infospl,"%","|pct|");
			}
			if(infospl!=null && infospl.indexOf("#")>-1)
			{
				infospl=com.egurkha.util.StringUtils.replace(infospl,"#","|hash|");
			}
			if(infospl!=null && infospl.indexOf("*")>-1)
			{
				infospl=com.egurkha.util.StringUtils.replace(infospl,"*","+");
			}
			sinfo += infospl;

			String mgrIdFromRow=null;
			String[] data = (String[])history.get(historyCount);
			if(EgInstallInfo.isSuperManager)
			{
				mgrIdFromRow=data[0];
				String data_copy[] = new String[data.length-1];
				System.arraycopy(data, 1, data_copy, 0, data_copy.length);
				data=data_copy;
			}
			StringBuffer urlForImages = new StringBuffer(128);
			StringBuffer urlForVMImages = new StringBuffer(128);
			urlForImages.append("site=");
			if(hasVMs)
				urlForVMImages.append("site=");
			if(data[1].equals("NULL"))
			{
				urlForImages.append("-1");
				if(hasVMs)
					urlForVMImages.append("-1");
			}
			else
			{
				urlForImages.append(data[1]);
				if(hasVMs)
					urlForVMImages.append(data[1]);
			}
			String s_host = Server.getServerNameWithoutPort(data[2]);
			String s_port = Server.getServerPort(data[2], false);
			String compTypeOriginal = null;
			if(data[3]!=null && data[3].equals("Host_system"))
			{
				compTypeOriginal = data[3];
				List foundoutServerTypes=discInfo.getServerTypesForNick(shost);
				if(foundoutServerTypes!=null && foundoutServerTypes.size()>1)
				{
					String fakeType = discInfo.getTypeForHostTest(shost,data[5]);
					data[3]=fakeType;
				}
				else if(foundoutServerTypes!=null && foundoutServerTypes.size()>0)
				{
					data[3]=(String)foundoutServerTypes.get(0);
				}

				if(data[3]!=null && s_host!=null)
				{
					String t_s_port = (String)discInfo.getPortForHost(s_host,data[3]);

					if(t_s_port!=null && t_s_port.trim().length()>0)
						s_port=t_s_port;
				}
			}
			urlForImages.append("&comptype=");
			urlForImages.append(data[3]);
			urlForImages.append("&host=");
			urlForImages.append(s_host);
			urlForImages.append("&port=");
			urlForImages.append(s_port);

			String comp_name=data[1];
			String sid="";
			StringTokenizer st=new StringTokenizer(comp_name,":");
			if(st.countTokens()==3)
			{
				if(comp_name!=null && comp_name.trim().length()>0)
					sid=comp_name.substring(comp_name.lastIndexOf(":")+1);
			}
			if(sid!=null && sid.trim().length()>0 && !sid.equalsIgnoreCase("NULL"))
			{
				urlForImages.append("&sid=");
				urlForImages.append(sid);
			}
			String layer = tablesInfo.getRelevantLayer(data[3], data[5], data[6]);
			urlForImages.append("&layer=");
			urlForImages.append(layer);

			urlForImages.append("&test=");
			urlForImages.append(data[5]);
			String s_info ="";
			String s_comp = s_host + ":" +s_port;
			if(data[2].startsWith(s_comp + ":")) 
				s_info = data[2].substring(s_comp.length() + 1);
			String info_spl=data[4];
			if(info_spl!=null && info_spl.startsWith("+"))
				info_spl="*"+info_spl.substring(1);
			if(info_spl!=null && info_spl.indexOf("+")>-1)
			{
				info_spl=com.egurkha.util.StringUtils.replace(info_spl,"+","|plus|");
			}
			if(info_spl!=null && info_spl.indexOf("&")>-1)
			{
				info_spl=com.egurkha.util.StringUtils.replace(info_spl,"&","|amp|");
			}
			if(info_spl!=null && info_spl.indexOf("%")>-1)
			{
				info_spl=com.egurkha.util.StringUtils.replace(info_spl,"%","|pct|");
			}
			if(info_spl!=null && info_spl.indexOf("#")>-1)
			{
				info_spl=com.egurkha.util.StringUtils.replace(info_spl,"#","|hash|");
			}
			//s_info += data[3].replace('+', '*');
			s_info += info_spl;
			//if(s_info.indexOf("*") > 0)
			{
				//s_info = s_info.substring(s_info.indexOf("*"));
			}
			urlForImages.append("&stest=");
			//urlForImages.append(data[4]+"-" + data[3].replace('+','*'));
			urlForImages.append(data[5]+"-" + info_spl);
			urlForImages.append("&info=");
			urlForImages.append(s_info);
			urlForImages.append("&msmt_host=");
			urlForImages.append(data[7]);
			urlForImages.append("&time=Any");
			urlForImages.append("&timeline=Any");

			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if(ddTimeAlt != null && ddTimeAlt.trim().length() > 0 && ddTimeAlt.equalsIgnoreCase("true"))
			{
				Calendar calendar_start = Calendar.getInstance();
				ParsePosition pos = new ParsePosition(0);
				java.util.Date startPreDate = sdf1.parse(data[9], pos);
				calendar_start.setTime(startPreDate);
				if(ddTimeAlt != null && ddTimeAlt.trim().length() > 0)
				{
					calendar_start.add(Calendar.MINUTE, dd_Min);
				}
				else
					calendar_start.add(Calendar.MINUTE, -10);

				dtt.setStartDateTime(sdf1.format(calendar_start.getTime()));
			}
			else
				dtt.setStartDateTime(data[9]);

			urlForImages.append("&starttime=");
			urlForImages.append(dtt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));

			urlForImages.append("&starthr=");
			String graphStartTime = dtt.getStartTime();
			urlForImages.append(graphStartTime.substring(0, graphStartTime.indexOf(EgConstants.COLON)));

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar calendar = Calendar.getInstance();
			if (timeDiff < 0)
			{
				//calendar.setTime(new java.util.Date(new EgDateInfo().egetUTCDate(false)));
				java.util.Date tmpday = new EgDateInfo().egetRealDate();
				calendar.setTime(tmpday);
			}
			else
			{
				ParsePosition pos = new ParsePosition(0);
				java.util.Date endDate = sdf.parse(data[10], pos);
				calendar.setTime(endDate);
			}

			calendar.add(Calendar.HOUR_OF_DAY, 1);
			dtt.setEndDateTime(sdf.format(calendar.getTime()));

			urlForImages.append("&endtime=");
			urlForImages.append(dtt.getEndDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));

			urlForImages.append("&endhr=");
			String graphEndTime = dtt.getEndTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR);
			urlForImages.append(graphEndTime.substring(0, graphEndTime.indexOf(EgConstants.COLON)));

			String urlStr = urlForImages.toString();
			String strType        = row[3];
			String comp_with_port = row[2];
			//Added by chandrasekhar
			String comp_info=discInfoHelper.getCompTypeForHostSystem(strType,row[2],row[5], hasAllComponentAccess,mappingInfo,userCompList);
			if(onlyVMAssigned || vmAssigned)
			{
				if(EgInstallInfo.isSuperManager && (comp_info == null || comp_info.trim().length()==0 || comp_info.trim().indexOf("Unmanaged/Deleted")>-1))
				{
					continue;
				}
			}
			else
			{
				if(selectedCompType != null && !selectedCompType.equals("-1") && !selectedCompType.equalsIgnoreCase("Component Type (Optional)")){
					String dispType = mappingInfo.getComponentTypeDescription(selectedCompType);
					ArrayList dispCompTypes =  com.egurkha.util.StringUtils.egTokenizer(comp_info.trim(), ",",false,true,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(dispCompTypes != null && dispCompTypes.size() > 0){
						if(dispCompTypes.contains(dispType))
							comp_info = dispType;
						else
							continue;
					}
				}
				if(EgInstallInfo.isSuperManager && (comp_info == null || comp_info.trim().length()==0 || comp_info.trim().indexOf("Unmanaged/Deleted")>-1))
				{
					continue;
				}
			}
			
			//Ended here..
			boolean isVM = false;
			String hostForVM = row[3]+":"+row[2];
			boolean rowDisp = true;
			if(info!=null && info.startsWith("+"))
			{
					info=info.substring(1);
			}
			String desc = "";
			if(info.indexOf(":") > -1)
			{
				desc = info.substring(info.indexOf(":")+1);
				info = info.substring(0,info.indexOf(":"));

			}

			if(!hasAllComponentAccess)
			{
					//UserCompList will not have host_system.
					if((vmUserCompList!=null && (vmUserCompList.size() > 0 && !vmUserCompList.contains(hostForVM)) || (onlyVMAssigned && !vmAssigned)) && s_event.equals("Component"))
					{
						if(!vmUserCompList.contains(hostForVM))
						{
							//It is a vm so check if it is assigned to the user.					
							if(a_userVMs!=null && a_userVMs.size() > 0)
							{
								isVM = true;
								if(showAllTypes && showAllComps)
								{
									
										if(!hostForVM.startsWith("Host_system"))
										{	
								
										
											if(!a_userVMs.contains(info))
											{
												rowDisp = false;
											}
											else
											{
												rowDisp=true;
												isVM=true;
											}
										}
										else
										{
											rowDisp = false;
										}
									
								
								
								}
								else if(showAllTypes && !showAllComps)
								{
										
									if(selectedCompName!=null && selectedCompName.equals(info))
									{
										if(!a_userVMs.contains(info))
										{
											rowDisp = false;
										}
										else
										{
											rowDisp=true;
											isVM=true;
										}
									}
									else
									{
										rowDisp = false;
									}
								}
								else if(!showAllTypes && showAllComps)
								{
									if(selectedCompType!=null && selectedCompType.equals(vmType))
									{
										
										if(!a_userVMs.contains(info))
										{
											rowDisp = false;
										}
										
									}
								}
								else if(!showAllTypes && !showAllComps)
								{
									if(selectedCompType!=null && selectedCompType.equals(vmType))
									{
										if(selectedCompName!=null && selectedCompName.equals(info))
										{
											
											if(!a_userVMs.contains(info))
											{
												rowDisp = false;
											}
											else
											{
												rowDisp =true;
											}
										}
										else
										{
											rowDisp = false;
										}
									}
									
								}
							}
							else
							{
								isVM = false;
							}
						}
						else
						{
							//when services,site,segments,zones are associated to onlyVMs.
							isVM = false;
							rowDisp = true;
						}
					}
					else
					{
								if(showAll)
								{
									if(vmUserCompList!=null && vmUserCompList.size() > 0)
									{
										if(vmUserCompList.contains(hostForVM))
										{
											rowDisp = true;
											isVM = false;
											
										}
									}
								}
								else if(showAllTypes && !showAllComps)
								{
									if(vmUserCompList!=null && vmUserCompList.size() > 0)
									{
										for(int u = 0; u < vmUserCompList.size(); u++)
										{
											String server = (String)vmUserCompList.get(u);
											if(server.indexOf(selectedCompName) >-1)
											{
												rowDisp = true;
												isVM = false;
												
											}
											else
											{
												if(selectedCompName!=null && selectedCompName.equals(info))
												{
													if(!a_userVMs.contains(info))
													{
														rowDisp = false;
													}
													else
													{
														rowDisp=true;
														isVM=true;
													}
												}
												
											}
											
										}
									}
								}
								else if(!showAllTypes && !showAllComps)
								{
									if(selectedCompType!=null && selectedCompType.equals(vmType))
									{
											if(selectedCompName!=null && selectedCompName.equals(info))
											{
												
												if(!a_userVMs.contains(info))
												{
													rowDisp = false;
												}
											}
											else
											{
												rowDisp = false;
											}
											isVM=true;
									}
									else
									{
										if(vmUserCompList.contains(hostForVM))
										{
											rowDisp = true;
											
											
										}
									}
								}
								else if(!showAllTypes && showAllComps)
								{
									if(selectedCompType!=null && selectedCompType.equals(vmType))
									{
										
												if(!a_userVMs.contains(info))
												{
													rowDisp = false;
													
												}
												isVM = true;
										
									}
									else
									{
										if(vmUserCompList.contains(hostForVM))
										{
												rowDisp = true;
										}
									}
								}

							}
						}
				
				if(!rowDisp)
				{
					continue;
				}
				String infoplus=com.egurkha.util.StringUtils.replace(sinfo,"+","*");
				String en_infoplus = infoplus;
				if(infoplus!=null && infoplus.trim().length()>0)
				{
					en_infoplus = com.egurkha.util.StringUtils.replace(infoplus, "#", "|hash|");
					en_infoplus = com.egurkha.util.StringUtils.replace(en_infoplus, "=", "|equ|");
					en_infoplus=com.egurkha.util.StringUtils.encodeSecurityChar(en_infoplus);
				}
				String popupVal = row[0]+","+row[3]+","+row[2]+","+row[1]+","+row[5]+","+row[6]+","+
				en_infoplus+","+row[7]+","+isVM+"&userLang="+thisLanguage;
				hist.put("priority",mappingInfo_state.getLabelDescription(row[8])+"#~#"+mappingInfo.getLabelDescription(row[8]));
				hist.put("popupVal",popupVal);
				String componentWithPort = row[2];
%>
<%
			if (selectedType == null || selectedType.equals("type"))
			{
				
				//row[3]= mappingInfo.getComponentTypeDescription(row[3]);
%>
															
<%
				if(isVM)
				{
					comp_info=mappingInfo.getComponentTypeDescription("Virtual_Machine");
				}
				if (comp_info.length() <= displayLength && comp_info.indexOf(" ")<0)
				{
					hist.put("type",comp_info);
%>
<%				}
				else
				{
					hist.put("type",comp_info);
%>
<%
				}
%>
<%
			}
			if (selectedName == null || selectedName.equals("name"))
			{
				if (((String)row[2]).endsWith(EgConstants.NULL_PORT))
				{
					row[2] = Server.getServerNameWithoutPort((String)row[2], false);
				}
%>
<%
				if (row[2].length() <= displayLength)
				{
%>					
<%
																			  if(isVM)
																			  {
																				  hist.put("name",info);
%>
<%
																				}
																				else
																				{
																					hist.put("name",row[2]);
%>
<%
																				}
%>
<%					
				}
				else
				{
%>
<%
																			if(isVM)
																			{
																				hist.put("name",info);
%>
<%
																			}
																			else
																			{
																				hist.put("name",row[2]);
%>
<%
																			}	
%>
<%
				}
%>
<%				
			}

			String salign="left";
			String s_id = "eg_alarmcontenthist";
			String display_Str="";
			if(comp_service_hash!=null && comp_service_hash.containsKey(strType+":"+comp_with_port))
			{
				display_Str = (String)comp_service_hash.get(strType+":"+comp_with_port);
			}
			else
			{
				display_Str=esmb.getServiceNamesForComponent(resultServiceNamesForComp,strType,comp_with_port,row[1],siteNames,hasAllComponentAccess);

				if(display_Str!=null && display_Str.trim().length()>0)
					comp_service_hash.put(strType+":"+comp_with_port,(String)display_Str);
			}
			
			if(display_Str.equals("NULL"))
			{
				display_Str= "-";
				salign="center";
				s_id = "eg_alarmcontenthistcnt";
			}
%>
		
			<%-- Service --%>
<%
			if (display_Str.equals("-"))
			{
				hist.put("services",display_Str);
%>
<%				
			}
			else
			{
				if (display_Str.length() <= displayLength-2)
				{
					hist.put("services",display_Str);
%>					
<%					
				}
				else
				{
					hist.put("services",display_Str);
%>
<%
				}
			}
%>
			<%-- Test --%>
<%
			row[5]= mappingInfo.getTestDescription(row[5]);
			String vmInfo = "";
			if(isVM)
			{
				
				if(desc!=null && desc.length() > 0 && !infoAdded)
				{
					vmInfo = testMeasureAlert + "{" + desc + "}";
				}
				else
				{
					vmInfo = testMeasureAlert;
				}
				
			}
			hist.put("test",row[5]);
			//hist.put("test",(split(row[5],25)));
%>
<%
			if(isVM)
			{
				hist.put("description",vmInfo);
%>
<%			}
			else
			{

				if(screenShot != null && screenShot.trim().length() > 0 && !screenShot.equals("-"))
				{
					if(!enableScreenShot)
						enableScreenShot = true;
					if(EgInstallInfo.isSuperManager)
					{
						screenShot=screenShot+"|"+manager_id;
					}
					String fun="javascript:openScreenShot(&quot;"+screenShot+"&quot;)";
					hist.put("screenshot","&nbsp;<a data-qtip='Screenshot' style='display:inline-block' data-qclass='yellowTip' href='"+fun+"' ><img src='/final/monitor/eg_scripts/sessionSimulation/svg/iconSnapshot.svg' style='vertical-align:middle;'/></a>");
				}
				//else
				hist.put("description",testLabel_for_display);
%>
<%
			}
%>
<%
			if(hasAllComponentAccess && !onlyVMAssigned && selectedUser==null && showUsers!=null && (showUsers.equalsIgnoreCase("true") || showUsers.equalsIgnoreCase("yes")))
			{
				Vector resultVect=new Vector();
				String displayUsers=new String();
				String displayUsersInTitle=new String();
				String strUsers = "";
				if(resultUserCompMap!=null && resultUserCompMap.size()>0)
				{
					resultVect=(Vector)resultUserCompMap.get(strType+":"+comp_with_port);
				}

				if(resultVect==null || resultVect.size()==0)
				{
					strUsers="-";
				}
				else
				{
					displayUsers=resultVect.toString();

					if(displayUsers!=null && displayUsers.trim().length()>0 && displayUsers.startsWith("["))
					{
						displayUsers=displayUsers.substring(1);
					}

					if(displayUsers!=null && displayUsers.trim().length()>0 && displayUsers.endsWith("]"))
					{
						displayUsers=displayUsers.substring(0,displayUsers.length()-1);
					}

					strUsers = displayUsers;
					ArrayList aListUsers = new ArrayList();
					StringTokenizer strTokens = new StringTokenizer(strUsers,",");
					while (strTokens.hasMoreTokens())
					{
						String strToken = strTokens.nextToken();
						strToken = strToken.trim();
						if (strToken.indexOf("/Grp/") != -1)
						{
							String grpDelimiter = "/Grp/";
							int idx = strToken.indexOf(grpDelimiter);
							String str_uname_A = strToken.substring(0,idx);
							int nextIdx = idx + grpDelimiter.length();
							String str_uname_B = strToken.substring(nextIdx);
							strToken = str_uname_A + "/" + str_uname_B + " (Group)";
						}
						aListUsers.add(strToken);
					}
					strUsers = aListUsers.toString();
					strUsers = strUsers.substring(1,strUsers.length()-1);

					displayUsersInTitle = strUsers;

					/*if(strUsers!=null && strUsers.length()>15)
					{
						displayUsers=displayUsers.substring(0,13)+"..";
					}*/
					strUsers = egSubString(strUsers,isUserLanguageEnglish,15,12);
				}
				hist.put("users",strUsers);
%>
<%
			}
			//out.println(row[3]);
			//out.println(testLabel_for_display);
			String displayDate = "";
			String s_displayDate="";
			if(row[9] != null && !row[6].equals(""))
			{
				displayDate = DateUtil.changeDateFormat(row[9],"MM/dd/yy HH:mm",currentDateFormat);
				EgMonTimeZoneConverter timeZoneConverter = new EgMonTimeZoneConverter(displayDate,user); 
				s_displayDate = timeZoneConverter.getDateTime();				
			}
			hist.put("stdate",s_displayDate);
			//hist.put("stdate",s_displayDate);
			if (timeDiff < 0)
			{
				String urlType = row[2];
				String urlComp = row[1];
				hist.put("duration",mappingInfo.getTextDescription("monitor.history.Current"));
%>				
<%				
			}
			else
			{
				hist.put("duration",DateTimeTokenizer.getTimeDifference(timeDiff));
%>
<%
			}
%>
<%
			String mes = dbInfo.getColumnForMeasure(data[5], data[6]);
																
			//urlStr=com.egurkha.util.StringUtils.replace(urlStr, "\\", "\\\\");
			String thisQuery = urlStr + "&measure=" + mes +"&gtype=0&draw=1&gformat=graph&from=test&mode=3D&qctr=5&search=&thisIs=event&showRange=Range&isVM="+isVM;
			//vadivel starts for ComponentMeasureTabset
			String TabSetLink = urlStr + "&measure=" + mes;

			StringTokenizer stringTokens = new StringTokenizer(TabSetLink,"&");
			String tabSetSite=null;
			String tabSetCompType=null;
			String tabSetHost=null;
			String tabSetPort=null;
			String tabSetLayer=null;
			String tabSetTest=null;
			String tabSetSTest=null;
			String tabSetInfo=null;
			String tabSetMsmtHost=null;
			String tabSetMeasure=null;

			while(stringTokens.hasMoreTokens())
			{
				String value = stringTokens.nextToken();
				if(value!=null)
				{
					if(value.indexOf("=") > -1)
					{
						String paramName = value.substring(0,value.indexOf("="));
						String paramValue = value.substring(value.indexOf("=")+1,value.length());
						//System.out.println("paramName--------------->"+paramName);
						if(paramName!=null)
						{
							if(paramName.equalsIgnoreCase("site"))
							{
								if(paramValue!=null && paramValue.equals("-1"))
								{
									paramValue = "NULL";
									tabSetSite = paramValue;
								}
								//System.out.println("tabSetSite-------------->"+tabSetSite);
							}
							else if(paramName.equalsIgnoreCase("comptype"))
							{
								if(compTypeOriginal!=null && compTypeOriginal.equalsIgnoreCase("Host_system"))
								{
									paramValue = compTypeOriginal;
								}
								tabSetCompType = paramValue;

								//System.out.println("tabSetCompType-------------->"+tabSetCompType);
							}
							else if(paramName.equalsIgnoreCase("host"))
							{
								tabSetHost = paramValue;
								//System.out.println("tabSetHost-------------->"+tabSetHost);
							}
							else if(paramName.equalsIgnoreCase("port"))
							{
								tabSetPort = paramValue;
								//System.out.println("tabSetPort-------------->"+tabSetPort);
							}
							else if(paramName.equalsIgnoreCase("layer"))
							{
								tabSetLayer = paramValue;
								//System.out.println("tabSetLayer-------------->"+tabSetLayer);
							}
							else if(paramName.equalsIgnoreCase("test"))
							{
								tabSetTest = paramValue;
								//System.out.println("tabSetTest-------------->"+tabSetTest);
							}
							else if(paramName.equalsIgnoreCase("stest"))
							{
								tabSetSTest = paramValue;
								//System.out.println("tabSetSTest-------------->"+tabSetSTest);
							}
							else if(paramName.equalsIgnoreCase("info"))
							{
								tabSetInfo = paramValue;
								if(tabSetInfo.indexOf("|plus|")>-1)
									tabSetInfo = StringUtils.replace(tabSetInfo, "|plus|", "+");								
							}
							else if(paramName.equalsIgnoreCase("msmt_host"))
							{
								tabSetMsmtHost = paramValue;
								//System.out.println("tabSetMsmtHost-------------->"+tabSetMsmtHost);
							}
							else if(paramName.equalsIgnoreCase("measure"))
							{
								tabSetMeasure = paramValue;
								//System.out.println("tabSetMeasure-------------->"+tabSetMeasure);
							}
						}
					}
				}
			}
			if (tabSetInfo.startsWith("+"))
			{
				tabSetInfo = tabSetInfo.substring(1);
			}
			String infoFordd = null;
			if(tabSetInfo==null || tabSetInfo.trim().equals(""))
			{
				infoFordd = "NONE";
			}
			else if(tabSetInfo!=null && tabSetInfo.equals("*"))
			{
				infoFordd = "NONE";
			}
			else
			{
				infoFordd = tabSetInfo;
			}
			String portForMsmtTime="NULL";
			boolean isPortRelevantForTest=false;
			if(specsInfo.isPortRelevantForTest(tabSetTest))
			{
				isPortRelevantForTest=true;
				portForMsmtTime=tabSetPort;
			}
			String msmtTimeStr2="";
			String keyy=tabSetHost+":"+portForMsmtTime+":"+tabSetTest+":"+tabSetMsmtHost;
			if(!EgInstallInfo.isSuperManager)
			{
				String msmtTimeStr=dashboardDAO.getMeasureLastMsmtTime(keyy,tabSetInfo);
				try
				{
					SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
					SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					if(msmtTimeStr != null && msmtTimeStr.trim().length() > 0 && msmtTimeStr.indexOf(":") != -1){
						java.util.Date msd=sdf2.parse(msmtTimeStr);
						msmtTimeStr2 =df.format(msd);
					}
				}
				catch(Exception eex)
				{
					System.out.println("Exception--->"+eex.getMessage());
					eex.printStackTrace();
				}
			}

			dLink = "/final/monitor/EgDiagnosis.jsp?site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&test="+tabSetTest+"&isPopUp=true"+"&isVM="+isVM;

			compddLink = dLink+"&info="+EgURLEncoder.encode(infoFordd,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&measure="+data[6]+"&from=0&firsttime=true&flag=1"+"&isVM="+isVM+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8");

			feedLink="/final/monitor/dispComponentFeedback.jsp?site="+tabSetSite+"&trgthost="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&test="+tabSetTest+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&isVM="+isVM;

			String strName = comp_with_port;
			if (strName.endsWith(EgConstants.NULL_PORT) && (strName.indexOf(EgConstants.NULL_PORT) > -1))
			{
				strName = Server.getServerNameWithoutPort(strName, false);
			}
			if(compTypeOriginal==null)
				compTypeOriginal = tabSetCompType;
			if(strName!=null)
			{
				String temp_info="";
				temp_info=tabSetInfo;
				temp_info="";
				
				String component_temp = "";
				if(compTypeOriginal != null && compTypeOriginal.equalsIgnoreCase("Oracle_server") && tabSetInfo != null && !tabSetInfo.startsWith("*"))
					component_temp = tabSetHost+":"+tabSetPort+":"+tabSetInfo.substring(0,tabSetInfo.indexOf("*"))+":"+compTypeOriginal;
				else
					component_temp = tabSetHost+":"+tabSetPort+":"+compTypeOriginal;

				if(isVM)
					temp_info = tabSetInfo;
					
				
				histLink="/final/monitor/dispComponentHistory.jsp?site="+tabSetSite+"&info=" +EgURLEncoder.encode(temp_info,"UTF-8") + "&test="+tabSetTest+ "&component=" +EgURLEncoder.encode(component_temp,"UTF-8")+"&isVM="+isVM;
			}
			else
			{
				String temp_info="";
				temp_info=tabSetInfo;
				temp_info="";
				if(isVM)
					temp_info = tabSetInfo;
				String component_temp = "";
				if(compTypeOriginal != null && compTypeOriginal.equalsIgnoreCase("Oracle_server") && tabSetInfo != null && !tabSetInfo.startsWith("*"))
					component_temp = tabSetHost+":"+tabSetPort+":"+tabSetInfo.substring(0,tabSetInfo.indexOf("*"))+":"+compTypeOriginal;
				else
					component_temp = tabSetHost+":"+tabSetPort+":"+compTypeOriginal;

				histLink="/final/monitor/dispComponentHistory.jsp?site="+tabSetSite+"&info=" +EgURLEncoder.encode(temp_info,"UTF-8") + "&test="+tabSetTest+ "&component="+component_temp+"&isVM="+isVM;;
			}
			String strPriority = row[8];
			
			String stTime = data[9];
			String enTime = data[10];

			//................This is for CtxXcXDUserTest to display Icon ..........
			String mgr_startTime_minus_dtime="";
			String mgr_endtime_minus_dtime="";
			
			String timeDifferent = dashboardConfigIni.getValue("Logon_Details_Support","TimeDifferent");
			timeDifferent=(timeDifferent==null || timeDifferent.length()==0 )?"5":timeDifferent;
			
			DateTimeTokenizer dt2 = new DateTimeTokenizer();
			dt2.setDateFormat(DateTimeTokenizer._YMD);
			dt2.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
			dt2.setTimeFormat(DateTimeTokenizer.HMS);
			//dt2.setYearAsYY(false);

			StringBuffer value_date = new StringBuffer();
			dt2.setStartDateTime((String)stTime);
			value_date.append(dt2.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
			value_date.append(DateTimeTokenizer.BLANK_SPACE);
			value_date.append(dt2.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));

			String stTimesubString = value_date.toString();
			SimpleDateFormat sdfF = new SimpleDateFormat("MM/dd/yyyy HH:mm");
			java.util.Date tmpday = sdfF.parse(value_date.toString());
			java.util.Date tmpdayEnd = sdfF.parse(value_date.toString());

			java.util.Date startNew = tmpday;
			java.util.Date endNew = tmpdayEnd;

			if(stTimesubString!=null && stTimesubString.trim().length()>0)
			{
				int blankSpaceIndex = 0;
				int value22 = 0;
				String unit22 ="min";
				if(timeDifferent!=null && timeDifferent.indexOf(" ")>-1)
				{
					blankSpaceIndex = timeDifferent.indexOf(DateTimeTokenizer.BLANK_SPACE);
					value22 = Integer.parseInt(timeDifferent.substring(0, blankSpaceIndex));
					unit22 = timeDifferent.substring(blankSpaceIndex+1).toLowerCase();
				}
				else 
					value22 = Integer.parseInt(timeDifferent);

				if (unit22.startsWith("min"))
				{//minites
					value22 *= 60;
				}
				else if (unit22.startsWith("h"))
				{//hours
					value22 *= 3600;
				}
				else if (unit22.startsWith("d"))
				{//days
					value22 *= (24 * 3600);
				}
				else if (unit22.startsWith("w"))
				{//weeks
					value22 *= (7 * 24 * 3600);
				}
				/*else if (unit22.startsWith("mo"))
				{//months
					value22 *=((ErUtils.getMaxDaysInMonth()) * 24 * 3600);
				}*/

				long valueToLong=value22;

				startNew.setTime(tmpday.getTime() - (valueToLong * 1000));
				mgr_startTime_minus_dtime = sdfF.format(startNew);

				endNew.setTime(tmpdayEnd.getTime() + (valueToLong * 1000));
				mgr_endtime_minus_dtime = sdfF.format(endNew);
			}
			
			/*String isLogon_Details_Support = dashboardConfigIni.getValue("Logon_Details_Support",data[5]);
			if(supported_types_list!=null && tabSetCompType!=null && supported_types_list.contains(tabSetCompType) && isLogon_Details_Support!=null && isLogon_Details_Support.length()>0 && isLogon_Details_Support.equalsIgnoreCase("yes"))*/
			if(supported_types_list!=null && tabSetCompType!=null && supported_types_list.contains(tabSetCompType) && logonSupportedTests!=null && logonSupportedTests.size()>0 && logonSupportedTests.contains(data[5]))
			{
				if(tabSetInfo!=null && tabSetInfo.trim().length()>0 && tabSetInfo.indexOf("\\")>-1)
				{
					enableLogon=true;
					String tmpTabSetInfo="";
					if(tabSetInfo!=null && tabSetInfo.startsWith("*"))
					{
						tmpTabSetInfo = StringUtils.replace(tabSetInfo, '*', '+');
					}
					else
					{
						tmpTabSetInfo=tabSetInfo;
					}
					JSONObject Logon_Details_SupportJson = new JSONObject();
					String msmtTimeForLogonDetails=(String)getMsmtTimeForLogon(mgr_startTime_minus_dtime+":00",mgr_endtime_minus_dtime+":59",tabSetTest,tmpTabSetInfo,mgrIdFromRow);
					StringBuffer value_dateinside = new StringBuffer();
					String mgr_Stime_minus_dtimeInside="";
					String mgr_Etime_minus_dtimeInside="";
					if(msmtTimeForLogonDetails!=null && !msmtTimeForLogonDetails.equalsIgnoreCase("null") && msmtTimeForLogonDetails.length()>0)
					{
						DateTimeTokenizer dt3 = new DateTimeTokenizer();
						dt3.setDateFormat(DateTimeTokenizer._YMD);
						dt3.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
						dt3.setTimeFormat(DateTimeTokenizer.HMS);
						
						dt3.setStartDateTime((String)msmtTimeForLogonDetails);
						value_dateinside.append(dt3.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
						value_dateinside.append(DateTimeTokenizer.BLANK_SPACE);
						value_dateinside.append(dt3.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
						
						String stTimesubStringInside = value_dateinside.toString();
						SimpleDateFormat sdfFInside = new SimpleDateFormat("MM/dd/yyyy HH:mm");
						java.util.Date tmpdayInside = sdfFInside.parse(value_dateinside.toString());
						java.util.Date tmpdayInsideend = sdfFInside.parse(value_dateinside.toString());

						java.util.Date startNewInside = tmpdayInside;
						java.util.Date endNewInside = tmpdayInsideend;

						if(stTimesubStringInside!=null && stTimesubStringInside.trim().length()>0)
						{
							int blankSpaceIndex = 0;
							int value22 = 0;
							String unit22 ="min";
							if(timeDifferent!=null && timeDifferent.indexOf(" ")>-1)
							{
								blankSpaceIndex = timeDifferent.indexOf(DateTimeTokenizer.BLANK_SPACE);
								value22 = Integer.parseInt(timeDifferent.substring(0, blankSpaceIndex));
								unit22 = timeDifferent.substring(blankSpaceIndex+1).toLowerCase();
							}
							else 
								value22 = Integer.parseInt(timeDifferent);
							
							if (unit22.startsWith("min"))
							{//minites
								value22 *= 60;
							}
							else if (unit22.startsWith("h"))
							{//hours
								value22 *= 3600;
							}
							else if (unit22.startsWith("d"))
							{//days
								value22 *= (24 * 3600);
							}
							else if (unit22.startsWith("w"))
							{//weeks
								value22 *= (7 * 24 * 3600);
							}
							/*else if (unit22.startsWith("mo"))
							{//months
								value22 *=((ErUtils.getMaxDaysInMonth()) * 24 * 3600);
							}*/
							long valueToLong=value22;

							startNewInside.setTime(tmpdayInside.getTime() - (valueToLong * 1000));
							mgr_Stime_minus_dtimeInside = sdfFInside.format(startNewInside);

							endNewInside.setTime(tmpdayInsideend.getTime() + (valueToLong * 1000));
							mgr_Etime_minus_dtimeInside = sdfFInside.format(endNewInside);
						}
					}
					
					String userType="XenApp7";
					if(tabSetTest!=null && tabSetTest.length()>0 && (tabSetTest.equalsIgnoreCase("CtxXcXDUserTest") || tabSetTest.equalsIgnoreCase("CtxCdUserTest")))
					{
						String userTypeForLogon=(String)getUserTypeForLogon(tabSetTest,tmpTabSetInfo,mgr_startTime_minus_dtime+":00",mgr_endtime_minus_dtime+":59");
						if(userTypeForLogon!=null && (userTypeForLogon.startsWith("+Server") || userTypeForLogon.startsWith("+Windows Server")))
						{
							userType="XenApp7";
						}
						else if(userTypeForLogon!=null && (userTypeForLogon.startsWith("+Desktop") || userTypeForLogon.startsWith("+Windows Desktop")))
						{
							userType="VDI";
						}
					}
					else if(tabSetTest!=null && tabSetTest.length()>0 && tabSetTest.equalsIgnoreCase("CtxXcXAEuemTest"))
					{
						userType="XenApp7";
					}
					else if(tabSetTest!=null && tabSetTest.length()>0 && (tabSetTest.equalsIgnoreCase("VmgCtxXcXAEuemTest") || tabSetTest.startsWith("Vmg")))
					{
						userType="VDI";
					}

					String director_types = egINI.getValue("Enable_Director_Link",userType);
					director_types=(director_types==null || director_types.trim().length()==0)?"":director_types;
					ArrayList directorSupportedTypes =  com.egurkha.util.StringUtils.egTokenizer(director_types.trim(), ",",false,true,true);//param 3-->includeEmpty,4-->unique,5-->trim

					boolean isUserHaveDirector=false;
					if(directorSupportedTypes!=null && directorSupportedTypes.size()>0)
					{
						for (int k=0;k<directorSupportedTypes.size() ; k++)
						{
							String supp_type=(String)directorSupportedTypes.get(k);
							if(userTypes != null && supp_type!=null && userTypes.contains(supp_type))
							{
								isUserHaveDirector = true;
								break;
							}
						}
					}

					boolean isShowLogonIcon=true;
					if(userType!=null && userType.length()>0 && userType.equalsIgnoreCase("VDI") && tabSetInfo.toLowerCase().indexOf("_on_")<0 && tabSetTest!=null && tabSetTest.length()>0 && tabSetTest.startsWith("Vmg"))
					{
						isShowLogonIcon=false;
					}
					
					if(mgr_Stime_minus_dtimeInside != null && mgr_Stime_minus_dtimeInside.trim().length()>0 && mgr_Etime_minus_dtimeInside != null && mgr_Etime_minus_dtimeInside.trim().length()>0)
					{
						mgr_Stime_minus_dtimeInside = mgr_Stime_minus_dtimeInside+":00";
						mgr_Etime_minus_dtimeInside = mgr_Etime_minus_dtimeInside+":59";
					}
					else
						isShowLogonIcon=false;

					if(isUserHaveDirector && isShowLogonIcon)
					{
						String tInfo=tabSetInfo;
						if(userType!=null && userType.length()>0 && userType.equalsIgnoreCase("VDI"))
						{
							if(tInfo!=null && tInfo.indexOf(":")>-1 && tInfo.toLowerCase().indexOf("_on_")>-1)
							{
								tInfo=tInfo.substring(0,tInfo.indexOf(":"));
							}
						}
						logonLink = response.encodeURL("/final/monitor/endUserLogonDetails.jsp?access=allusers&userType="+userType+"&fromMenu=true")+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&compName="+EgURLEncoder.encode(tabSetHost+":"+tabSetPort+":"+tabSetCompType,"UTF-8")+"&info="+EgURLEncoder.encode(tInfo,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&tab=alarmHistory&startTimeforLogon="+EgURLEncoder.encode(mgr_Stime_minus_dtimeInside,"UTF-8")+"&endTimeforLogon="+EgURLEncoder.encode(mgr_Etime_minus_dtimeInside,"UTF-8")+"&testNameForLogon="+tabSetTest;

						Logon_Details_SupportJson.put("urlParam1",logonLink);
						String titleInfo ="";
						String getInfoTitle = "";
						if(tInfo!=null && tInfo.trim().length()>0)
						{
							titleInfo = StringUtils.replace(tInfo, '*', '+');
							titleInfo=com.egurkha.util.StringUtils.replace(titleInfo, "\\", "\\\\");
							getInfoTitle = StringUtils.replace(titleInfo, "+", "");
						}
						
						String titleforLogon=mappingInfo.getTestDescription("monitor.common.Logon Details for user :")+" "+getInfoTitle+" ";

						Logon_Details_SupportJson.put("titleforLogon",titleforLogon);
						Logon_Details_SupportJson.put("logonTooltip",mappingInfo.getTextDescription("monitor.common.Logon Details"));
						hist.put("Logon_Details_Support",Logon_Details_SupportJson);
						//Logon_Details_SupportJson.put("stackTooltip",mappingInfo.getTextDescription("monitor.layermodel.Logon Details"));
					}
				}
			}


			ddLink = "/final/monitor/componentMeasureTabSet.jsp?type="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&state="+strPriority+"&messy="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&from=measurespage&dd=yes&userID="+EgURLEncoder.encode(user.getLoginID(),"UTF-8")+"&clicked=dd"+ "&test=" +tabSetTest+"&stTime="+stTime+"&mapHostKey="+EgURLEncoder.encode(comp_with_port,"UTF-8")+"&isVM="+isVM;

			measureLink = "/final/monitor/componentMeasureTabSet.jsp?type="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&state="+strPriority+"&messy="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&from=measurespage&userID="+EgURLEncoder.encode(user.getLoginID(),"UTF-8")+"&clicked=graph"+"&layer="+EgURLEncoder.encode(tabSetLayer,"UTF-8")+ "&test=" + tabSetTest+"&stTime="+stTime+"&mapHostKey="+EgURLEncoder.encode(comp_with_port,"UTF-8")+"&isVM="+isVM;

			compgraphLink = "/final/monitor/dispComponentGraphs.jsp?site="+tabSetSite+"&host=" +EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&layer="+EgURLEncoder.encode(tabSetLayer,"UTF-8")+"&test="+tabSetTest+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&isVM="+isVM;

			if(tabSetTest.equalsIgnoreCase("GenericLogonSimTest"))
			{
				ddLink = ddLink+"&isScreenShotEnabled="+enableScreenShot;
				measureLink = measureLink+"&isScreenShotEnabled="+enableScreenShot;
			}

			boolean isAgentlessServer = agentInfo.isAgentlessServer(s_host, data[3],true);
			boolean isTestExternal =specsInfo.isTestExternal(data[5]);

			
			
			//add timeline by ramesh

			String	stDate = dtt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR);
			String graphStartTime1 = dtt.getStartTime();
			String	stHr = graphStartTime1.substring(0, graphStartTime1.indexOf(EgConstants.COLON)).trim();

			String stMin=graphStartTime1.substring((graphStartTime1.indexOf(EgConstants.COLON)+1), graphStartTime1.lastIndexOf(EgConstants.COLON)).trim();

			String enDate = dtt.getEndDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR);
			
			//get end hr..
			String graphEndTime1 = dtt.getEndTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR);
			String enHr = graphEndTime1.substring(0, graphEndTime1.indexOf(EgConstants.COLON)).trim();
		
			String enMin="";
			try{
			enMin=graphEndTime1.substring((graphEndTime1.indexOf(EgConstants.COLON)+1), graphEndTime1.lastIndexOf(EgConstants.COLON)).trim();
			}
			catch(Exception e)
			{
			}
			if(enMin.equals("")){
			enMin=graphEndTime1.substring((graphEndTime1.lastIndexOf(EgConstants.COLON)+1)).trim();
			}
	
		
			graphLink = compgraphLink+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&gtype=1&measure="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&state="+strPriority;
			
			///change to user format......


			String userFormat = user.getUserDateFormat();					
			if(stDate!=null && !stDate.equals(""))
			{
				if(DateUtil.isDate(stDate,"MM/dd/yyyy"))
				{
					comFormat = "MM/dd/yyyy";
				}
				else
				{
					comFormat = currDateFormat;
				}
				//stDate = DateUtil.changeDateFormat(stDate,"MM/dd/yyyy",userFormat);
				stDate = DateUtil.changeDateFormat(stDate,comFormat,currDateFormat);
				stDate += " "+stHr+":"+stMin;
			}
			EgMonTimeZoneConverter timeZoneConverterStart = new EgMonTimeZoneConverter(stDate,user);
			
			stDate = (String)timeZoneConverterStart.getDate(false);
			stDate = DateUtil.changeDateFormat(stDate,userFormat,"MM/dd/yyyy");
			stHr = timeZoneConverterStart.getHour();
			stMin = timeZoneConverterStart.getMinute();

			if(enDate!=null && !enDate.equals(""))
			{
				if(DateUtil.isDate(enDate,"MM/dd/yyyy"))
				{
					comFormat = "MM/dd/yyyy";
				}
				else
				{
					comFormat = currDateFormat;
				}
				//enDate = DateUtil.changeDateFormat(enDate,"MM/dd/yyyy",userFormat);
				enDate = DateUtil.changeDateFormat(enDate,comFormat,currDateFormat);
				enDate += " "+enHr+":"+enMin;
			}

			EgMonTimeZoneConverter timeZoneConverterEnd = new EgMonTimeZoneConverter(enDate,user);
			
			enDate = (String)timeZoneConverterEnd.getDate(false);
			enDate = DateUtil.changeDateFormat(enDate,userFormat,"MM/dd/yyyy");
			enHr = timeZoneConverterEnd.getHour();
			enMin = timeZoneConverterEnd.getMinute();
			String ss_date = enDate+" "+enHr+":"+enMin;
			//graphLink = graphLink+"&timeLine=Any&starttime="+stDate+"&endtime="+enDate+"&starthr="+stHr+"&endhr="+enHr+"&startmin="+stMin+"&endmin="+enMin+"&dummy=$";

			graphLink = graphLink+"&timeLine=Any&starttime="+stDate+"&endtime="+enDate+"&starthr="+stHr+"&endhr="+enHr+"&startmin="+stMin+"&endmin="+enMin+"&dummy=$";
			
			//compddLink = compddLink+"&timeline=Any&starttime="+stDate+"&endtime="+enDate+"&starthr="+stHr+"&endhr="+enHr+"&startmin="+stMin+"&endmin="+enMin+"&dummy=$";

			compddLink = compddLink+"&timeline=Any&starttime="+stDate+"&endtime="+enDate+"&starthr="+stHr+"&endhr="+enHr+"&startmin="+stMin+"&endmin="+enMin+"&dummy=$"+"&isVM="+isVM+"&fromHistPage=true";;

			compsummarygraphLink="/final/monitor/dispComponentSummaryGraphs.jsp?site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&layer="+EgURLEncoder.encode(tabSetLayer,"UTF-8")+"&test="+tabSetTest+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&isVM="+isVM;;

			summarygraphLink = compsummarygraphLink+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&gtype=1&measure="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&state="+strPriority+"&isVM="+isVM;;

			comptrendgraphLink="/final/monitor/dispComponentTrendGraphs.jsp?site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&layer="+EgURLEncoder.encode(tabSetLayer,"UTF-8")+"&test="+tabSetTest+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&isVM="+isVM;;

			trendgraphLink = comptrendgraphLink+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&gtype=1&measure="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&state="+strPriority+"&isVM="+isVM;;

			aggLink = "/final/monitor/dispAggComponentGraphs.jsp?site="+tabSetSite+"&host="+EgURLEncoder.encode(tabSetHost,"UTF-8")+"&port="+tabSetPort+"&layer="+EgURLEncoder.encode(tabSetLayer,"UTF-8")+"&test="+tabSetTest+"&comptype="+EgURLEncoder.encode(tabSetCompType,"UTF-8")+"&isVM="+isVM;;
							
			historyLink = histLink+"&measure="+tabSetMeasure;
			feedbackLink = feedLink +"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&measure="+tabSetMeasure+"&msmttime="+msmtTimeStr2+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&isVM="+isVM;
		
			aggregateLink = aggLink+"&info="+EgURLEncoder.encode(tabSetInfo,"UTF-8")+"&gtype=1&measure="+tabSetMeasure+"&msmt_host="+EgURLEncoder.encode(tabSetMsmtHost,"UTF-8")+"&state="+strPriority+"&isVM="+isVM;

			// Rights Symbol replace
			tabSetInfo = com.egurkha.util.StringUtils.replace(tabSetInfo,"\u00AE","|rights|");
			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"compfeedbacklink", aggregateLink);

			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"compgraphlink", graphLink);


			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"compsummarygraphlink", summarygraphLink);

			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"comptrendgraphlink", trendgraphLink);

			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"comphistorylink", historyLink);

			linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"compfeedbacklink", feedbackLink);

			//vadivel ends for Tabset
			boolean showDDIcon = true;
			//Fix to hide DD icon based on Ini entry
			if(excludeDDTestList != null && excludeDDTestList.size() > 0 && excludeDDTestList.contains(data[5]))
			{
				showDDIcon = false;
			}
			//end
			boolean ddPresents = false;
			if ((ddEnabled && testBean.isDdEnabled(data[5], data[6])  && (!isAgentlessServer || isTestExternal)) || (ddEnabled && testBean.isDdEnabled(data[5], data[6])))
			{
				enableDD = true;
				thisQuery = urlStr + "&measure=" + data[6] + "&from=0&firsttime=true&flag=1&isVM="+isVM;	

				if(s_info!=null && s_info.indexOf("*")>-1)
					s_info=com.egurkha.util.StringUtils.replace(s_info,"*","+");
				String s_info_to_db = null;
				String ddWithoutInfo = formatIniFile.getValue("Tests_For_DDWithoutInfos", data[5] + ":" + data[6]);
				boolean lookforActualDes = false;

				if(ddWithoutInfo!=null && ddWithoutInfo.equalsIgnoreCase("yes"))
				{
					lookforActualDes = true;
					s_info_to_db = "+";
				}
				else
				{
					s_info_to_db = s_info;
				}
				
				/*showDDIcon = dd.ShowDDData(data[1],s_host,data[5],data[6],s_info_to_db,data[7]);

				if(lookforActualDes && !showDDIcon)
				{
					showDDIcon = dd.ShowDDData(data[1],s_host,data[5],data[6],s_info,data[7]);
				}*/
				// Rights Symbol replace
				tabSetInfo = com.egurkha.util.StringUtils.replace(tabSetInfo,"\u00AE","|rights|");

				if(showDDIcon)
				{
					//code added by vadivel for tabset
					linksMap.put(tabSetTest+"#"+tabSetMeasure+"#"+tabSetInfo+"#"+tabSetMsmtHost+"#"+stTime+"#"+comp_with_port+"compddlink", compddLink);
					//temp_ddLink=ddLink+"&dd_disp=yes";
					measureLink =measureLink+"&show=dd";
					//code ended here for tabset

					JSONObject ddDetails = new JSONObject();
					//ddDetails.put("url", thisQuery);
					ddDetails.put("url", ddLink);
					ddDetails.put("subParam","dd");
					ddDetails.put("popup_selection","true");
					hist.put("ddparams",ddDetails);												// Prem
					//ddPresents = true;

				}
				else
				{
					/* out.println("<img src='/final/monitor/eg_images/spacer.gif' width='18'>"); */
				}
			}
			else
			{
				/* out.print("<img src='/final/monitor/eg_images/spacer.gif' width='18'>"); */
			}
		
				JSONObject graph = new JSONObject();
				//graph.put("url", thisQuery);
			
				measureLink += "&isVM="+isVM;
				graph.put("url", measureLink);
				graph.put("subParam","data");
				graph.put("popup_selection","true");
				hist.put("graphParams",graph);

			/*else
			{
				String vmGraphQuery = "";
				if(hasVMs)
				{
					urlForVMImages.append("&comptype=");
					urlForVMImages.append(data[3]);
					urlForVMImages.append("&host=");
					urlForVMImages.append(s_host);
					urlForVMImages.append("&port=");
					urlForVMImages.append(s_port);
					urlForVMImages.append("&sid=");
					urlForVMImages.append(sid);
					urlForVMImages.append("&layer=");
					urlForVMImages.append(layer);
					urlForVMImages.append("&test=");
					urlForVMImages.append(data[5]);
					urlForVMImages.append("&info=");
					urlForVMImages.append(s_info);
					urlForVMImages.append("&msmt_host=");
					urlForVMImages.append(data[7]);
					urlForVMImages.append("&starttime=");
					urlForVMImages.append(dtt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
					urlForVMImages.append("&starthr=");
					urlForVMImages.append(graphStartTime.substring(0, graphStartTime.indexOf(EgConstants.COLON)));
					urlForVMImages.append("&endtime=");
					urlForVMImages.append(dtt.getEndDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
					urlForVMImages.append("&endhr=");
					urlForVMImages.append(graphEndTime.substring(0, graphEndTime.indexOf(EgConstants.COLON)));
					urlForVMImages.append("&showRange=Range&newWindow=true&mode=3D&gtype=0");
					urlForVMImages.append("&measure=");
					urlForVMImages.append(mes);
					urlForVMImages.append("&isVM=");
					urlForVMImages.append(isVM);
				}
				vmGraphQuery = "/final/monitor/EgGraphs.jsp?" + urlForVMImages.toString();
				JSONObject graph = new JSONObject();
				graph.put("url", vmGraphQuery);
				graph.put("subParam","vmgraph");
				graph.put("popup_selection","true");
				hist.put("graphParams",graph);
			}*/
						
			// config Icon added ---- code started ---
			if (comp_with_port != null && comp_with_port.indexOf(":") > -1)
			{
				compNameForConfig = comp_with_port;
			}
			else
			{
				compNameForConfig = comp_with_port + ":NULL";
			}

			cNameForConfig = compNameForConfig+":"+tabSetCompType;

			if (cNameForConfig != null && cNameForConfig.indexOf("/") > -1)
			{
				compNameForConfig = "All components";
				changeQs = "/final/monitor/EgConfigChange.jsp?componentName=" + compNameForConfig;
			}
			else
			{				
				changeQs = "/final/monitor/EgConfigChange.jsp?componentName=" + EgURLEncoder.encode(compNameForConfig, "UTF-8") + ":" + tabSetCompType;
			}

			boolean hasConfigSupport = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);

			if ((ht_changeHash.containsKey(tabSetCompType) || ht_changeHash.containsKey(comp_with_port)) && EgInstallInfo.isConfigSupported && hasConfigSupport)
			{
				boolean isTestRelevantForServer = false;
				boolean configChanged = true;
				ArrayList temp_list = (ArrayList) ht_changeHash.get(tabSetCompType);
				if (temp_list == null || temp_list.size() == 0)
					temp_list = (ArrayList) ht_changeHash.get(comp_with_port);

				if (temp_list != null && temp_list.size() > 0)
				{
					for (int k2 = 0; k2 < temp_list.size(); k2++)
					{
						String temp_test_name = (String) temp_list.get(k2);
						if (temp_test_name != null && temp_test_name.trim().length() > 0)
						{
							isTestRelevantForServer = specsInfo.isTestRelevantForServer(tabSetCompType, temp_test_name);
						}
						if (isTestRelevantForServer)
							break;
					}
					if (isTestRelevantForServer)
					{
						configChanged = true;
						enableConfig = true;
					}
					else
						configChanged = false;
				}
				else
					configChanged = false;

				if (!isVM)
				{
					if (configChanged)
					{
						hist.put("COLUMN_Config_url", changeQs);
					}
					else
					{
						hist.put("COLUMN_Config_url", "-");
					}
				}
				else
				{
					hist.put("COLUMN_Config_url", "-");
				}
			}
			else
			{
				hist.put("COLUMN_Config_url", "-");
			}
			
			//--- code ended ---
%>

<% 
			//to display acknowledgement details as a sub-table in event history page
			//start

			//String showAcks = egUI.getValue("ALARM_HISTORY","showAcknowledgements");
			if(ackValue!=null && ackValue.equalsIgnoreCase("Yes"))
			{
				Hashtable hTable = putAcknowledgeDetails(row[0]);
				ArrayList ackData_aList_outer = new ArrayList();
				ArrayList ackData_aList_inner = new ArrayList();

				String user_ID = "";
				String ack_Desc = "";
				String ack_Time = "";
				String action = "";
			
				if(hTable.containsKey(row[0]))
				{
					
					JSONObject acknowledgeHeader_json = new JSONObject();
					acknowledgeHeader_json.put("user",mappingInfo.getTextDescription("monitor.currentAlarms.USER"));
					acknowledgeHeader_json.put("ackDetail",mappingInfo.getTextDescription("monitor.currentAlarms.ACKNOWLEDGEMENT DETAIL"));
					acknowledgeHeader_json.put("action",mappingInfo.getTextDescription("monitor.currentAlarms.ACTION"));
					acknowledgeHeader_json.put("time",mappingInfo.getTextDescription("monitor.currentAlarms.TIME"));
				
%>

<%
					ackData_aList_outer = (ArrayList)hTable.get(row[0]);

					JSONArray  acknowledgeDataArray_json = new JSONArray();
					
					for(int kk=0; kk<ackData_aList_outer.size(); kk++)
					{
						ackData_aList_inner =  (ArrayList) ackData_aList_outer.get(kk);
					
						user_ID = (String) ackData_aList_inner.get(0);
						ack_Desc = (String) ackData_aList_inner.get(1);
						action = (String) ackData_aList_inner.get(2);
						ack_Time = (String) ackData_aList_inner.get(3);
						ack_Time = DateUtil.changeDateFormat(ack_Time,"yyyy-MM-dd HH:mm:ss",currentDateFormat);
						EgMonTimeZoneConverter timeZoneConverter = new EgMonTimeZoneConverter(ack_Time,user);
						JSONObject acknowledgeData_json = new JSONObject();
						acknowledgeData_json.put("user",user_ID);
						acknowledgeData_json.put("ackDetail",ack_Desc);
						acknowledgeData_json.put("action",action);
						acknowledgeData_json.put("time",timeZoneConverter.getDateTime());
						
						acknowledgeDataArray_json.add(acknowledgeData_json);
%>
<%
					}
					hist.put("acknowledgeHeader",acknowledgeHeader_json);
					hist.put("acknowledgeData",acknowledgeDataArray_json);
				}
			}
			hist.put("mgrid",manager_id);
%>					
<%
			if(!showEventHistory && !hasVMs)
			{
				if(row.length == 13)
				{
					String evtpopupVal = row[0]+","+row[3]+","+componentWithPort+","+row[11];
					String showEventIcon = row[12];
					if(showEventIcon != null && showEventIcon.length() > 0 && showEventIcon.equals("true"))
					{
						JSONObject eventObj = (JSONObject)getEventDetails(evtpopupVal,thisLanguage,user,currentDateFormat,selectedUser,showUsers,resultUserCompMap,isUserLanguageEnglish,isVM,Monutil);
						hist.put("children",eventObj.get("alarmDetailJson"));
					}
					else
						hist.put("leaf",true);
				}
			}
			hist.put("rowIndexValue",i);
			historyCount++;
			historyJson.add(hist);
			}
		}
		catch(Exception exp)
		{
			exp.printStackTrace();
		} 
%>

<%
	} //---end of the Show smiley Else
	json.put("enableUser",String.valueOf(enableUser));
	json.put("showManagerID",new Boolean(EgInstallInfo.isSuperManager));
	json.put("enableDD",String.valueOf(enableDD));
	json.put("enableConfig",String.valueOf(enableConfig));
	json.put("enableScreenShot",String.valueOf(enableScreenShot));
	json.put("enableLogon",String.valueOf(enableLogon));
	json.put("timeline",timelineStr);
	if(showEventHistory || hasVMs)
	{
		json.put("history",historyJson);
	}
	else
	{
		JSONObject treeJson = new JSONObject();
		treeJson.put("expanded",true);
		treeJson.put("text",".");
		treeJson.put("children",historyJson);
		json.put("history",treeJson);
	}
	session.setAttribute("Tablinks", linksMap);
	if(eventsPerPage.equalsIgnoreCase("0"))
	{
		eventsPerPage = String.valueOf(historyJson.size());
	}
	json.put("eventsPerPage",String.valueOf(eventsPerPage));
	json.put("isSuperManager",new Boolean(EgInstallInfo.isSuperManager));
	response.getWriter().write(json.toString());
%>

<%!
	List siteNames =null;
	List userCompList=new LinkedList();
	User user=null;
	EgUserRole userRole=null; 
	boolean hasAllComponentAccess=false;

	String blank = "&nbsp;";
	private String tmpFile = EgInstallInfo.getInstallDir()+"/manager/logs/tmp.log";
	private boolean tmpLog = false;

	public List processResults(List list, int maxWidth,LangInfo langinfo, boolean hasVMs, MonitorUtility Monutil) 
	{
		List results = new LinkedList();

		int length = 0;
		int oldWidth = maxWidth;

		String nullStr = EgConstants.NULL_STRING.toUpperCase();

		DateTimeTokenizer dt = new DateTimeTokenizer();
		dt.setDateFormat(DateTimeTokenizer._YMD);
		dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
		dt.setTimeFormat(DateTimeTokenizer.HMS);
		dt.setYearAsYY(true);

		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		EgMappingInfo mappingInfo1 = new EgMappingInfo(thisLanguage);
		for (int z=0; z<list.size(); z++)
		{
			String[] values = (String[])list.get(z);
			String[] row = new String[values.length];
			System.arraycopy(values, 0, row, 0, row.length);

			int a = 0;
			//Site name
			if (StringUtils.isNull(row[2]) || row[2].equals(nullStr))
			{
				//-->row[a] = "NONE";
			}
			else
			{
				if (row[2].length() > maxWidth)
				{
					//row[a] = split(row[a], maxWidth);
				}
			}

			//a++;	//a = 2
			//Comp Name
			if (row[2].endsWith(EgConstants.NULL_PORT))
			{
				//-->row[a] = Server.getServerNameWithoutPort(row[a], false).trim();
			}

			if (row[2].length() > maxWidth)
			{
				//row[a] = mergeSplitStr(StringUtils.split(row[a], EgConstants.COLON));
				//row[a] = split(row[a], maxWidth);
			}

			//a++;	//a = 3 
			//Comp Type

			//a++;	// a = 4
			//Info
			StringBuffer key = new StringBuffer();
			String tmp_Test=row[5];
			String tmp_CmpName=row[2];
			String tmp_cmpType=row[3];
			if(tmp_CmpName != null && tmp_CmpName.endsWith(":NULL"))
				tmp_CmpName= tmp_CmpName.substring(0,tmp_CmpName.indexOf(":NULL"));
				
			key.append(row[5]);
			key.append(EgConstants.COLON);
			key.append(row[6]);
			String description ="";
			int len = 0;
			//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
			//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
			if(isCustomAlertMessages)
			{
				String custom_info=row[4];
				String site1=row[1];
				if(StringUtils.isNull(site1))
					site1="NONE";
				if(row[4]!=null && row[4].length()>1 && row[4].startsWith("+"))
				{
					custom_info=row[4].substring(1);
				}
				
				String layer=dashboardDAO.getLayerForTest(row[3],row[5],row[6]);
				description = tablesInfo.getCustomMeasureAlert(key.toString(), row[4],thisLanguage);
				len = description.trim().length();
				if(description != null && len > 0){
					description =replaceMsg(description,Server.getServerNameWithoutPort(row[2], false),mappingInfo1.getComponentTypeDescription(row[3]),site1,mappingInfo1.getLabelDescription(row[8]),mappingInfo1.getLayerDescription(layer),mappingInfo1.getTestDescription(row[5]),custom_info,mappingInfo1.getMeasureDescription(row[5],row[6]),"");
				}
			}
			if(description == null || len == 0 || description.startsWith(row[6]))
			{
				Hashtable alertParams = new Hashtable();
				alertParams.put("$componentType",mappingInfo1.getComponentTypeDescription(row[3]));
				alertParams.put("$componentName",Server.getServerNameWithoutPort(row[2], false));
				if(row[4]!=null && row[4].trim().length()>1){
					if(row[4].startsWith("+"))
						alertParams.put("$info",row[4].substring(1));
					else
						alertParams.put("$info",row[4]);
				}
				alertParams.put("hasVMs",hasVMs);

				description = tablesInfo.getMeasureAlert(key.toString(), row[4],thisLanguage,alertParams)+"$info$"+row[4];
			}
			row[4] = description;


			a++;
			//Test name
			if (row[a].length() > maxWidth)
			{
				//String tagTest = langinfo.getValue("TEST_NAME_MAPPING",row[a]);
				/*if(tagTest != null && !tagTest.equals(""))
				{
					row[a] = tagTest;
				}*/
				//row[a] = split(row[a], maxWidth);
			}

			a++;
			//Measure
			//Ignored because it will be taken care of while displaying meaningful messages

			a++;
			//Start time
			StringBuffer value = new StringBuffer();
			dt.setStartDateTime((String)row[9]);
			value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
			value.append(DateTimeTokenizer.BLANK_SPACE);
			value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
			row[9] = value.toString();
			a++;
			//End time
			String temp = row[10];
			value = new StringBuffer();
			if ((row[10] != null) && (row[10].indexOf("1900") == -1))
			{
				dt.setEndDateTime(row[10]);
				long tDiff = dt.getDateDifference();
				value.append(tDiff);
			}
			else
			{
				java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				sdf.setTimeZone(EgDateInfo.getRealTimeZone());
				java.util.Date today = new java.util.Date((new EgDateInfo()).egetUTCDate());
				
				dt.setEndDateTime(sdf.format(today));
				value.append("-");
				value.append(dt.getDateDifference());
			}

			row[10] = value.toString();
			
			results.add(row);
		}
		return results;
	}

	private String mergeSplitStr(String[] splits)
	{
		StringBuffer value = new StringBuffer();

		for (int a=0; a<splits.length; a++)
		{
			value.append(splits[a]);
			value.append("<br>");
		}

		return value.toString();
	}

	private String split (String string, int width)
	{
		/*String breakStr = "<br>&nbsp;";
		StringBuffer splitStr = new StringBuffer();

		int times = string.length()/width;
		int start = 0;
		for (int a=0; a<times; a++)
		{
			splitStr.append(string.substring(start, start+width));
			splitStr.append(blank);
			start += width;
			splitStr.append(breakStr);
		}

		splitStr.append(string.substring(width*times));*/
		StringBuffer splitStr = new StringBuffer();
		String[] tokens;
		String delimiter = ":";
		if (string.indexOf(delimiter) == -1)
		{
			/*tokens = new String[1];
			tokens[0] = string;*/
			int count = string.length()/width;
			if (string.length()%width > 0)
			{
				count++;
			}
			
			tokens = new String[count];
			for (int a=0; a<count; a++)
			{
				tokens[a] = string.substring(a*width, Math.min(string.length(), (a+1)*width));
				splitStr.append(tokens[a]);
				if(a < count-1)
				{
					splitStr.append("<br>&nbsp;");
				}

			}

		}
		else
		{
			StringTokenizer tokenizer = new StringTokenizer(string, delimiter);
			int count = tokenizer.countTokens();

			tokens = new String[count];
			for (int a=0; a<count; a++)
			{
				tokens[a] = tokenizer.nextToken();
				splitStr.append(tokens[a]);
				if(a < count-1)
				{
					splitStr.append(":<br>&nbsp;");
				}
			}
		}
		return splitStr.toString();
	}
	
	/*public int getEventsCount(
		List servers,
		String compNames,
		String compTypes,
		String fromDate,
		String toDate,
		long durationFilter,String state, EgDbAdapterUI egDb)
	{
		EgDateInfo dateInfo = new EgDateInfo();
		int count = 0;
		//TODO Check the date format for compatibility
		
		StringBuffer sb = new StringBuffer();
		if (servers.isEmpty())
		{//all component access and choosing all events
			if (durationFilter != 0)
			{
				if (EgDbInfo.isOraAdapter)
				{
					sb.append("SELECT START_TIME,END_TIME FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
					sb.append(fromDate);
					sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
					sb.append(toDate);
					sb.append("','mm/dd/yyyy hh24:mi') ");
				}
				else
				{
					sb.append("SELECT START_TIME,END_TIME FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' '");
					sb.append(" AND START_TIME BETWEEN convert(datetime,'");
					sb.append(fromDate);
					sb.append("', 101) AND convert(datetime,'");
					sb.append(toDate);
					sb.append("', 101) ");
				}

				if(EgDbInfo.isOraAdapter)
				{
					sb.append("AND (END_TIME IS NOT NULL) ");
				}
				else
				{
					sb.append("AND (END_TIME <> convert(datetime,'01/01/1900 00:00', 101)) ");
				}

				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);

				logToTmpFile("INFO","","Query for events count 1 "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());
				try
				{
					if(rs != null)
					{
						DateTimeTokenizer dt = new DateTimeTokenizer();
						dt.setDateFormat(DateTimeTokenizer._YMD);
						dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
						dt.setTimeFormat(DateTimeTokenizer.HMS);
						dt.setYearAsYY(true);
						while (rs.next())
						{
							String start_time_value=rs.getString(1);
							String end_time_value=rs.getString(2);

							//Start time
							StringBuffer value = new StringBuffer();
							if(start_time_value!=null && start_time_value.trim().length()>0)
							{
								dt.setStartDateTime((String)start_time_value);
								value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
								value.append(DateTimeTokenizer.BLANK_SPACE);
								value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
								start_time_value = value.toString();
							}
							value = new StringBuffer();

							if ((end_time_value != null) && (end_time_value.trim().length()>0) && (end_time_value.indexOf("1900") == -1))
							{
								dt.setEndDateTime(end_time_value);
								long tDiff = dt.getDateDifference();
								
								if (lessThanZero)
								{
									if(tDiff<durationFilter)
									{
										count++;
									}
								}
								else
								{
									if(tDiff>durationFilter)
									{
										count++;
									}
								}
							}
						}
					}
					try
					{
						rs.close();
						rs = null;
					}
					catch (Exception grrr)
					{
					}
				}
				catch (SQLException e)
				{
					// TODO Auto-generated catch block
					// logger.error("Error retrieving events count ", e);
				}
				return count;
			}
			else
			{
				if (EgDbInfo.isOraAdapter)
				{
					sb.append("SELECT COUNT(EVENT_ID) FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
					sb.append(fromDate);
					sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
					sb.append(toDate);
					sb.append("','mm/dd/yyyy hh24:mi') ");
				}
				else
				{
					sb.append("SELECT COUNT(EVENT_ID) FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' '");
					sb.append(" AND START_TIME BETWEEN convert(datetime,'");
					sb.append(fromDate);
					sb.append("', 101) AND convert(datetime,'");
					sb.append(toDate);
					sb.append("', 101) ");
				}
				
				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				logToTmpFile("INFO","","Query for events count 1 "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());
				try
				{
					if (rs != null && rs.next())
					{
						count = rs.getInt(1);
						try {
							rs.close();
							rs = null;
						} catch (Exception grrr)
						{
						}
					}
				}
				catch (SQLException e)
				{
					// TODO Auto-generated catch block
					// logger.error("Error retrieving events count ", e);
				}
				return count;
			}
		}
		else
		{
			if (durationFilter != 0)
			{
				// restricted access or using specific comp-name and type 
				if (EgDbInfo.isOraAdapter)
					sb.append("SELECT COMP_TYPE||':'||COMP_NAME,START_TIME,END_TIME FROM EVENT_HIST WHERE SITE_NAME>' ' and ");
				else
					sb.append("SELECT COMP_TYPE+':'+COMP_NAME,START_TIME,END_TIME FROM EVENT_HIST WHERE SITE_NAME> ' ' AND ");


				if (compNames.length()==0)
				{// filter based on comp_type
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						//sb.append("', 101) AND convert(datetime,'")
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
				else 
				{ // filter based on comp_name 
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);

						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}

						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
				
				if(EgDbInfo.isOraAdapter)
				{
					sb.append("AND (END_TIME IS NOT NULL) ");
				}
				else
				{
					sb.append("AND (END_TIME <> convert(datetime,'01/01/1900 00:00', 101)) ");
				}

				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);

				logToTmpFile("INFO","","Query for events count "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());

				count = 0;
				try
				{
					if (rs != null)
					{
						DateTimeTokenizer dt = new DateTimeTokenizer();
						dt.setDateFormat(DateTimeTokenizer._YMD);
						dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
						dt.setTimeFormat(DateTimeTokenizer.HMS);
						dt.setYearAsYY(true);
						while (rs.next())
						{
							String s = rs.getString(1);
							if (servers.contains(s))
							{
								String start_time_value=rs.getString(2);
								String end_time_value=rs.getString(3);

								//Start time
								StringBuffer value = new StringBuffer();
								if(start_time_value!=null && start_time_value.trim().length()>0)
								{
									dt.setStartDateTime((String)start_time_value);
									value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
									value.append(DateTimeTokenizer.BLANK_SPACE);
									value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
									start_time_value = value.toString();
								}
								value = new StringBuffer();
								if ((end_time_value != null) && end_time_value.trim().length()>0 && (end_time_value.indexOf("1900") == -1))
								{
									dt.setEndDateTime(end_time_value);
									long tDiff = dt.getDateDifference();
									
									if (lessThanZero)
									{
										if(tDiff<durationFilter)
										{
											count++;
										}
									}
									else
									{
										if(tDiff>durationFilter)
										{
											count++;
										}
									}
									
								}
							}
						}
						try 
						{
							rs.close();
							rs = null;
						} 
						catch (Exception grrr)
						{
						}
					}
				}
				catch (SQLException e)
				{
					try 
					{
						rs.close();
						rs = null;
					} 
					catch (Exception grrr)
					{
					}
				}
				return count;
			}
			else
			{
				// restricted access or using specific comp-name and type 
				if (EgDbInfo.isOraAdapter)
					sb.append("SELECT COMP_TYPE||':'||COMP_NAME FROM EVENT_HIST WHERE SITE_NAME>' ' and ");
				else
					sb.append("SELECT COMP_TYPE+':'+COMP_NAME FROM EVENT_HIST WHERE SITE_NAME> ' ' AND ");

				if (compNames.length()==0)
				{// filter based on comp_type
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						//sb.append("', 101) AND convert(datetime,'")
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
				else 
				{ // filter based on comp_name 
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
			
				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				logToTmpFile("INFO","","Query for events count "+sb.toString());

				ResultSet rs = egDb.dbselect(sb.toString());
				count = 0;
				try
				{
					if (rs != null)
					{
						while (rs.next())
						{
							String s = rs.getString(1);
							if (servers.contains(s))
							{
								count ++;
							}
						}
						try {
							rs.close();
							rs = null;
						} catch (Exception grrr)
						{
						}
					}
				}
				catch (SQLException e)
				{
					try {
						rs.close();
						rs = null;
					} catch (Exception grrr)
					{
					}
				}
				return count;
			}
		}
	}
	
	public int getEventsCount(
		List servers,
		String compNames,
		String compTypes,
		String fromDate,
		String toDate,
		long durationFilter,String state, EgDbAdapterUI egDb,String infosearch,EgMappingInfo mappingInfo)
	{
		EgDateInfo dateInfo = new EgDateInfo();
		int count = 0;
		//TODO Check the date format for compatibility
		StringBuffer sb = new StringBuffer();
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		if (servers.isEmpty())
		{//all component access and choosing all events
			if (durationFilter != 0)
			{
				if (EgDbInfo.isOraAdapter)
				{
					sb.append("SELECT START_TIME,END_TIME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
					sb.append(fromDate);
					sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
					sb.append(toDate);
					sb.append("','mm/dd/yyyy hh24:mi') ");
				}
				else
				{
					sb.append("SELECT START_TIME,END_TIME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' '");
					sb.append(" AND START_TIME BETWEEN convert(datetime,'");
					sb.append(fromDate);
					sb.append("', 101) AND convert(datetime,'");
					sb.append(toDate);
					sb.append("', 101) ");
				}

				if(EgDbInfo.isOraAdapter)
				{
					sb.append("AND (END_TIME IS NOT NULL) ");
				}
				else
				{
					sb.append("AND (END_TIME <> convert(datetime,'01/01/1900 00:00', 101)) ");
				}

				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				logToTmpFile("INFO","","Query for events count 1 "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());
				try
				{
					if(rs != null)
					{
						DateTimeTokenizer dt = new DateTimeTokenizer();
						dt.setDateFormat(DateTimeTokenizer._YMD);
						dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
						dt.setTimeFormat(DateTimeTokenizer.HMS);
						dt.setYearAsYY(true);
						while (rs.next())
						{
							String start_time_value=rs.getString(1);
							String end_time_value=rs.getString(2);
							StringBuffer desc_key=new StringBuffer();
							String test = rs.getString(4);
							String measure = rs.getString(5);
							String info = rs.getString(3);
							desc_key.append(test);
							desc_key.append(EgConstants.COLON);
							desc_key.append(measure);
							String description = tablesInfo.getMeasureAlert(desc_key.toString(),info,thisLanguage);

							//Start time
							StringBuffer value = new StringBuffer();
							if(start_time_value!=null && start_time_value.trim().length()>0)
							{
								dt.setStartDateTime((String)start_time_value);
								value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
								value.append(DateTimeTokenizer.BLANK_SPACE);
								value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
								start_time_value = value.toString();
							}
							value = new StringBuffer();

							if ((end_time_value != null) && (end_time_value.trim().length()>0) && (end_time_value.indexOf("1900") == -1))
							{
								dt.setEndDateTime(end_time_value);
								long tDiff = dt.getDateDifference();
								if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
								{
									if(infosearch.startsWith("*"))
									{
										infosearch=infosearch.substring(1);
									}
									if(infosearch.endsWith("*"))
									{
										infosearch=infosearch.substring(0,infosearch.length()-1);
									}
									if(infosearch.startsWith("*") && infosearch.endsWith("*"))
									{
										infosearch=infosearch.substring(1);
										infosearch=infosearch.substring(0,infosearch.length()-1);
									}
								}
								if (lessThanZero)
								{
									if(tDiff<durationFilter)
									{
										if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
										{
											infosearch=infosearch.toLowerCase();
											description=description.toLowerCase();
											if(description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
											{
												count++;
											}
										}
									}
								}
								else
								{
									if(tDiff>durationFilter)
									{
										if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
										{
											infosearch=infosearch.toLowerCase();
											description=description.toLowerCase();
											if(description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
											{
												count++;
											}
										}
									}
								}
							}
						}
					}
					try
					{
						rs.close();
						rs = null;
					}
					catch (Exception grrr)
					{
					}
				}
				catch (SQLException e)
				{
					// TODO Auto-generated catch block
					// logger.error("Error retrieving events count ", e);
				}
				return count;
			}
			else 
			{
				if (EgDbInfo.isOraAdapter)
				{
					sb.append("SELECT INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
					sb.append(fromDate);
					sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
					sb.append(toDate);
					sb.append("','mm/dd/yyyy hh24:mi') ");
				}
				else
				{
					sb.append("SELECT INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' and COMP_NAME>' ' and COMP_TYPE>' ' and INFO>' ' and TEST_NAME>' ' and MEASURE>' '");
					sb.append(" AND START_TIME BETWEEN convert(datetime,'");
					sb.append(fromDate);
					sb.append("', 101) AND convert(datetime,'");
					sb.append(toDate);
					sb.append("', 101) ");
				}
				
				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}
				logToTmpFile("INFO","","Query for events count 1 "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());
				
				try
				{
					if (rs != null)
					{
						while(rs.next())
						{
							StringBuffer desc_key=new StringBuffer();
							String test = rs.getString(2);
							String measure = rs.getString(3);
							String info = rs.getString(1);
							desc_key.append(test);
							desc_key.append(EgConstants.COLON);
							desc_key.append(measure);
							String description = tablesInfo.getMeasureAlert(desc_key.toString(),info,thisLanguage);
							if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
							{
								if(infosearch.startsWith("*"))
								{
									infosearch=infosearch.substring(1);
								}
								if(infosearch.endsWith("*"))
								{
									infosearch=infosearch.substring(0,infosearch.length()-1);
								}
								if(infosearch.startsWith("*") && infosearch.endsWith("*"))
								{
									infosearch=infosearch.substring(1);
									infosearch=infosearch.substring(0,infosearch.length()-1);
								}
								infosearch=infosearch.toLowerCase();
								description=description.toLowerCase();
								if(description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
								{
									count++;
								}
							}
						}
					}
					try 
					{
						rs.close();
						rs = null;
					}
					catch (Exception grrr)
					{
					}
				}
				catch (SQLException e)
				{
					// TODO Auto-generated catch block
					// logger.error("Error retrieving events count ", e);
				}
				return count;
			}
		}
		else
		{
			if (durationFilter != 0)
			{
				// restricted access or using specific comp-name and type 
				if (EgDbInfo.isOraAdapter)
					sb.append("SELECT COMP_TYPE||':'||COMP_NAME,START_TIME,END_TIME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME>' ' and ");
				else
					sb.append("SELECT COMP_TYPE+':'+COMP_NAME,START_TIME,END_TIME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' AND ");


				if (compNames.length()==0)
				{// filter based on comp_type
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						//sb.append("', 101) AND convert(datetime,'")
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
				else 
				{ // filter based on comp_name 
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);

						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}

						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");
					}
				}
				
				if(EgDbInfo.isOraAdapter)
				{
					sb.append("AND (END_TIME IS NOT NULL) ");
				}
				else
				{
					sb.append("AND (END_TIME <> convert(datetime,'01/01/1900 00:00', 101)) ");
				}

				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				logToTmpFile("INFO","","Query for events count "+sb.toString());
				ResultSet rs = egDb.dbselect(sb.toString());

				count = 0;
				try
				{
					if (rs != null)
					{
						DateTimeTokenizer dt = new DateTimeTokenizer();
						dt.setDateFormat(DateTimeTokenizer._YMD);
						dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
						dt.setTimeFormat(DateTimeTokenizer.HMS);
						dt.setYearAsYY(true);
						while (rs.next())
						{
							String s = rs.getString(1);
							if (servers.contains(s))
							{
								String start_time_value=rs.getString(2);
								String end_time_value=rs.getString(3);
								StringBuffer desc_key=new StringBuffer();
								String test = rs.getString(5);
								String measure = rs.getString(6);
								String info = rs.getString(4);
								desc_key.append(test);
								desc_key.append(EgConstants.COLON);
								desc_key.append(measure);
								String description = tablesInfo.getMeasureAlert(desc_key.toString(),info,thisLanguage);
								//Start time
								StringBuffer value = new StringBuffer();
								if(start_time_value!=null && start_time_value.trim().length()>0)
								{
									dt.setStartDateTime((String)start_time_value);
									value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
									value.append(DateTimeTokenizer.BLANK_SPACE);
									value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
									start_time_value = value.toString();
								}
								value = new StringBuffer();
								if ((end_time_value != null) && end_time_value.trim().length()>0 && (end_time_value.indexOf("1900") == -1))
								{
									dt.setEndDateTime(end_time_value);
									long tDiff = dt.getDateDifference();
									if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
									{
										if(infosearch.startsWith("*"))
										{
											infosearch=infosearch.substring(1);
										}
										if(infosearch.endsWith("*"))
										{
											infosearch=infosearch.substring(0,infosearch.length()-1);
										}
										if(infosearch.startsWith("*") && infosearch.endsWith("*"))
										{
											infosearch=infosearch.substring(1);
											infosearch=infosearch.substring(0,infosearch.length()-1);
										}
									}
									if (lessThanZero)
									{
										if(tDiff<durationFilter)
										{
											if(!StringUtils.isNull(infosearch))
											{
												infosearch=infosearch.toLowerCase();
												description=description.toLowerCase();
												if(description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
												{
													count++;
												}
											}
										}
									}
									else
									{
										if(tDiff>durationFilter)
										{
											if(!StringUtils.isNull(infosearch))
											{
												infosearch=infosearch.toLowerCase();
												description=description.toLowerCase();
												if(description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
												{
													count++;
												}
											}
										}
									}
								}
							}
						}
						try 
						{
							rs.close();
							rs = null;
						}
						catch (Exception grrr)
						{
						}
					}
				}
				catch (SQLException e)
				{
					try 
					{
						rs.close();
						rs = null;
					} 
					catch (Exception grrr)
					{
					}
				}
				return count;
			}
			else
			{
				// restricted access or using specific comp-name and type 
				if (EgDbInfo.isOraAdapter)
					sb.append("SELECT COMP_TYPE||':'||COMP_NAME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME>' ' and ");
				else
					sb.append("SELECT COMP_TYPE+':'+COMP_NAME,INFO,TEST_NAME,MEASURE FROM EVENT_HIST WHERE SITE_NAME> ' ' AND ");
				if (compNames.length()==0)
				{// filter based on comp_type
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME>' ' and COMP_TYPE IN (");
						sb.append(compTypes);
						sb.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						//sb.append("', 101) AND convert(datetime,'")
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
				else 
				{ // filter based on comp_name 
					if (EgDbInfo.isOraAdapter)
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						sb.append(fromDate);
						sb.append("','mm/dd/yyyy hh24:mi') AND to_date('");
						sb.append(toDate);
						sb.append("','mm/dd/yyyy hh24:mi') ");
					}
					else
					{
						sb.append("COMP_NAME IN (");
						sb.append(compNames);
						sb.append(") and ");
						sb.append("COMP_TYPE IN(");
						sb.append(compTypes);
						//sb.append(") and INFO>' ' ");
						if(isFromInsideviewDashboard)
						{
							if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
								sb.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							else
								sb.append(") and INFO>' ' ");
						}
						else
						{
							sb.append(") and INFO>' ' ");
						}
						if(isFromDashBoard)
						{
							sb.append(" and test_name in("+testList+") ");
						}
						else
						{
							sb.append("and TEST_NAME>' '"); 
						}
						sb.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sb.append(fromDate);
						sb.append("', 101) AND convert(datetime,'");
						sb.append(toDate);
						sb.append("', 101) ");

					}
				}
			
				if(state!=null && !state.equals(""))
				{
					if(state.equals("HIGHINTERMEDIATE"))
					{
						sb.append(" AND event_svrty in('HIGH','INTERMEDIATE')");
					}
					else
					{
						sb.append(" AND event_svrty='");
						sb.append(state);
						sb.append("'");
					}
				}

				logToTmpFile("INFO","","Query for events count "+sb.toString());
				
				ResultSet rs = egDb.dbselect(sb.toString());

				count = 0;
				try
				{
					if (rs != null)
					{
						while (rs.next())
						{
							String s = rs.getString(1);
							StringBuffer desc_key=new StringBuffer();
							String info = rs.getString(2);
							String test = rs.getString(3);
							String measure = rs.getString(4);
							desc_key.append(test);
							desc_key.append(EgConstants.COLON);
							desc_key.append(measure);
							String description = tablesInfo.getMeasureAlert(desc_key.toString(),info,thisLanguage);
							if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
							{
								if(infosearch.startsWith("*"))
								{
									infosearch=infosearch.substring(1);
								}
								if(infosearch.endsWith("*"))
								{
									infosearch=infosearch.substring(0,infosearch.length()-1);
								}
								if(infosearch.startsWith("*") && infosearch.endsWith("*"))
								{
									infosearch=infosearch.substring(1);
									infosearch=infosearch.substring(0,infosearch.length()-1);
								}
							}
							if(s!=null && s.trim().length()>0 && (infosearch==null || infosearch.trim().length()==0 || infosearch.equals("null")))
							{
								if (servers.contains(s))
								{
									count ++;
								}
							}
							else if(s!=null && s.trim().length()>0 && (infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch)))
							{
								infosearch=infosearch.toLowerCase();
								description=description.toLowerCase();
								if((servers.contains(s)) && description!=null && description.trim().length()>0 && description.indexOf(infosearch)>-1)
								{
									count++;
								}
							}
						}
						try {
							rs.close();
							rs = null;
						} catch (Exception grrr)
						{
						}
					}
				}
				catch (SQLException e)
				{
					try {
						rs.close();
						rs = null;
					} catch (Exception grrr)
					{
					}
				}
				return count;
			}
		}
	}*/
	
	
	
	public int getEventHistoryCount(
		List servers,
		String serverNames,
		String serverTypes,
		String fromTime,
		String toTime,
		String eventID,
		//int offsetCount,
		long durationFilter,
		String state,
		//boolean reverseList, 
		EgDbAdapterUI egDb,EgMappingInfo mappingInfo,LangInfo langinfo,String selectedArrangeOption,String infosearch,List userCompList,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List vmUserCompList,String s_event,int startIndex,int endIndex)
	{
		int recCount = 0;

		


		
//		if(EgInstallInfo.isSuperManager)
//		{
//			SmSessionData smsData = new SmSessionData(currentSessionId);
//			EgThreadLocal egtl = new EgThreadLocal();
//			egtl.set(smsData);
//			new SMDateTimeConverter("MM/dd/yyyy HH:mm",fromTime,toTime);
//		}

		EgUserRole userRole = user.getUserRole();
		boolean isAllCompnt = userRole.hasAllComponentAccess();
		String comp_name_search="";
		if(infosearch!=null && infosearch.trim().length()>0 && infosearch.indexOf("^egsep^")>0)
		{
			ArrayList emptyColumnsList =  com.egurkha.util.StringUtils.egTokenizer(infosearch, "^egsep^",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			if(emptyColumnsList!=null && emptyColumnsList.size()>=2)
			{
				infosearch=(String)emptyColumnsList.get(0);
				if(infosearch!=null)
					infosearch=infosearch.trim();
				comp_name_search=(String)emptyColumnsList.get(1);
				if(comp_name_search!=null)
					comp_name_search=comp_name_search.trim();
			}
		}


	
		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
		{
		
			Integer infoCount = (Integer)infoSearchCount.get(infoRandom);	
			recCount =infoCount.intValue();
			infoSearchCount.remove(infoRandom);
			return recCount;
			//infoSearchCount.put(,new Integer(result.size()));
		}
	

		if(hasVMs)
		{
			Integer infoCount = (Integer)infoSearchCount.get(infoRandom);	
			recCount =infoCount.intValue();
			infoSearchCount.remove(infoRandom);		
			return recCount;
		}


		//EgDateInfo dateInfo = new EgDateInfo();
		StringBuffer query = new StringBuffer(320);
		StringBuffer ora_query = new StringBuffer(320);
		StringBuffer sql_query = new StringBuffer(320);
		StringBuffer sb_time =new StringBuffer();
		List result = new LinkedList();
		//TODO Check the date format for compatibility
		if (servers.isEmpty())
		{

			
			query.append("SELECT count(*) as count FROM ALARM_HISTORY_SUMMARY WHERE ");

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  EVENT_SEVERITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  EVENT_SEVERITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			sb_time.append("EVENT_ID > ' ' AND ");
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(s_event!=null && s_event.equals("Component"))
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						if(hasVMs)
						{
							query.append(" test_name like ('");
							query.append("Vmg");
							query.append("%')");

							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
							}
							//what if type is all , selected comp is not.
						}
					}
					else
					{
						query.append(" ( lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%') ");
						if(hasVMs)
						{
							
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" OR (test_name like ('");
								query.append("Vmg");
								query.append("%')");

								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')) ");
							}
							//what if type is all , selected comp is not.
						}
						query.append(" ) ");
					}
				}
				else
				{
					query.append("  lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
				query.append(" AND ");
				
			}
			ora_query.append(query);
			sql_query.append(query);
			if (EgInstallInfo.isSuperManager)
			{
				StringBuffer ora_sb_time = new StringBuffer();
				StringBuffer sql_sb_time = new StringBuffer();
				ora_sb_time.append(sb_time);
				sql_sb_time.append(sb_time);
				if(isFromInsideviewDashboard)
				{
					ora_sb_time.append(" START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_query.append(sql_sb_time);
				}
				else
				{
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(END_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(");
					ora_sb_time.append(" (START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME >= to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(")) OR ");
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME = to_date('");
					ora_sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					ora_sb_time.append("))) ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME >= convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME = convert(datetime,'");
					sql_sb_time.append("01/01/1900 00:00");
					sql_sb_time.append("',101)))) ");
					sql_query.append(sql_sb_time);
				}
			}
			else if (EgDbInfo.isOraAdapter)
			{
				/*sb_time.append("(");
				sb_time.append("(START_TIME BETWEEN to_date('");
				sb_time.append(fromTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
				sb_time.append(toTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
				sb_time.append(") OR ");
				sb_time.append("(END_TIME BETWEEN to_date('");
				sb_time.append(fromTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
				sb_time.append(toTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
				sb_time.append("))");*/

				// query commend and changed on 3-aug-2010
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					query.append(sb_time);
					
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append(" (START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(")) OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = to_date('");
					sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					sb_time.append("))) ");
					query.append(sb_time);
				}
			}
			else
			{
				/*sb_time.append("(");
				sb_time.append("(START_TIME BETWEEN convert(datetime,'");
				sb_time.append(fromTime);
				sb_time.append("', 101) AND convert(datetime,'");
				sb_time.append(toTime);
				sb_time.append("',101) ");
				sb_time.append(") OR ");
				sb_time.append("(END_TIME BETWEEN convert(datetime,'");
				sb_time.append(fromTime);
				sb_time.append("', 101) AND convert(datetime,'");
				sb_time.append(toTime);
				sb_time.append("',101) ");
				sb_time.append("))");*/

				// query commend and changed on 3-aug-2010
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					query.append(sb_time);
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101)) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = convert(datetime,'");
					sb_time.append("01/01/1900 00:00");
					sb_time.append("',101)))) ");
					query.append(sb_time);
				}
			}

			if(durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				if (lessThanZero)
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");

						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
			}
		
		
			logToTmpFile("INFO","","Query for Count event history is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					Hashtable ht = new Hashtable();
					ht.put("OracleQuery",ora_query.toString());
					ht.put("SqlQuery",sql_query.toString());
					ht.put("AddMgrIdToRs","yes");
					if(fromTime != null && fromTime.indexOf(":")==fromTime.lastIndexOf(":"))
					{
						ht.put("sourceDateFormat","MM/dd/yyyy HH:mm");
					}
					else
					{
						ht.put("sourceDateFormat","MM/dd/yyyy HH:mm:ss");
					}
					ht.put("startDate",fromTime);
					ht.put("endDate",toTime);
					if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
					{
						ArrayList al = (ArrayList) EgManagersInfo.sessionManagerMap.get(currentSessionId);
						if(al != null && !al.isEmpty())
						{
							ht.put("special_case_mgr_ids",al);
						}
					}
					rs = new EgSMDBHelper().getResultSet(ht);
				}
				else
				{
					qry = query.toString();
					rs = egDb.dbselect(qry);
				}
				if(EgInstallInfo.isSuperManager)
				{
					while(rs.next())
					{
						String mgr_id = rs.getString("ManagerID");
						int mgr_alarms_count = rs.getInt("count");
						managerRowCount.put(mgr_id,mgr_alarms_count);
						recCount += mgr_alarms_count;
					}
				}
				else
				{
					if(rs.next())
					{
						 recCount  = rs.getInt("count");
					}
				}				
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				return recCount;
			}
			catch (Exception jpm)
			{
				logToTmpFile("INFO","","Error "+jpm.toString());
				jpm.printStackTrace();
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return 0;
			}
		}
		else
		{
			
			query.append("SELECT COUNT(*) as count FROM ALARM_HISTORY_SUMMARY WHERE ");			

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  EVENT_SEVERITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  EVENT_SEVERITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			query.append("EVENT_ID > ' ' AND SITE_NAME>' ' AND ");
			ora_query.append(query);
			sql_query.append(query);
			if (serverNames.length()==0)
			{
				// filter based on comp_type
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(" COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(") and TEST_NAME>' ' and MEASURE>' ' and ");
					sql_query.append(" COMP_TYPE IN (");
					sql_query.append(serverTypes);
					sql_query.append(")  and TEST_NAME>' ' and MEASURE>' ' and ");

					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									ora_query.append(" test_name like ('");
									ora_query.append("Vmg");
									ora_query.append("%')");
									sql_query.append(" test_name like ('");
									sql_query.append("Vmg");
									sql_query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										ora_query.append(" and lower(INFO) like ('+%");
										ora_query.append(comp_name_search.toLowerCase());
										ora_query.append("%')");
										sql_query.append(" and lower(INFO) like ('+%");
										sql_query.append(comp_name_search.toLowerCase());
										sql_query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								ora_query.append(" ( lower(COMP_NAME) like ('%");
								ora_query.append(comp_name_search.toLowerCase());
								ora_query.append("%')");
								sql_query.append(" ( lower(COMP_NAME) like ('%");
								sql_query.append(comp_name_search.toLowerCase());
								sql_query.append("%')");
								if(hasVMs)
								{
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										ora_query.append(" OR (test_name like ('");
										ora_query.append("Vmg");
										ora_query.append("%')");
										ora_query.append(" AND lower(INFO) like ('+%");
										ora_query.append(comp_name_search.toLowerCase());
										ora_query.append("%')) ");
										sql_query.append(" OR (test_name like ('");
										sql_query.append("Vmg");
										sql_query.append("%')");
										sql_query.append(" AND lower(INFO) like ('+%");
										sql_query.append(comp_name_search.toLowerCase());
										sql_query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								ora_query.append(" ) ");
								sql_query.append(" ) ");
							}
						}
						else
						{
							ora_query.append("  lower(COMP_NAME) like ('%");
							ora_query.append(comp_name_search.toLowerCase());
							ora_query.append("%')");
							sql_query.append("  lower(COMP_NAME) like ('%");
							sql_query.append(comp_name_search.toLowerCase());
							sql_query.append("%')");
						}
						ora_query.append(" AND ");
						sql_query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							ora_query.append("COMP_NAME IN(");
							ora_query.append(tmp_srvers);
							ora_query.append(") and  INFO>' ' AND ");

							sql_query.append("COMP_NAME IN(");
							sql_query.append(tmp_srvers);
							sql_query.append(") and  INFO>' ' AND ");
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL")&& s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								ora_query.append("COMP_NAME IN(");
								ora_query.append(tmp_srvers);
								ora_query.append(") and  INFO>' ' AND ");
								
								sql_query.append("COMP_NAME IN(");
								sql_query.append(tmp_srvers);
								sql_query.append(") and  INFO>' ' AND ");
							}
							else
							{
								//query.append("COMP_NAME>' ' and  INFO>' ' AND ");//commented by raj-26.05.2016
								ora_query.append("COMP_NAME IN(");
								ora_query.append(tmp_srvers);
								ora_query.append(") and  INFO>' ' AND ");

								sql_query.append("COMP_NAME IN(");
								sql_query.append(tmp_srvers);
								sql_query.append(") and  INFO>' ' AND ");
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
					}
					else
					{
						ora_query.append("	((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append(" END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
						sql_query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{

					// query commend and changed on 3-aug-2010

					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and");
					}
					query.append(" TEST_NAME>' ' and MEASURE>' ' and ");
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									query.append(" test_name like ('");
									query.append("Vmg");
									query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" and lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								query.append(" ( lower(COMP_NAME) like ('%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
								if(hasVMs)
								{
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" OR (test_name like ('");
										query.append("Vmg");
										query.append("%')");
										query.append(" AND lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								query.append(" ) ");
							}
						}
						else
						{
							query.append("  lower(COMP_NAME) like ('%");
							query.append(comp_name_search.toLowerCase());
							query.append("%')");
						}
						query.append(" AND ");
						
					}
					else
					{
							if(!isAllCompnt)
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND ");
							}
							else
							{
								if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
								{
									query.append("COMP_NAME IN(");
									query.append(tmp_srvers);
									query.append(") and  INFO>' ' AND "); 
								}
								else{
									//query.append("COMP_NAME>' ' and  INFO>' ' AND "); 
									query.append("COMP_NAME IN(");
									query.append(tmp_srvers);
									query.append(") and  INFO>' ' AND ");
								} 
							}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append("	((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append(" END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					
					// query commend and changed on 3-aug-2010
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and");	
					}
					query.append(" TEST_NAME>' ' and MEASURE>' ' and ");
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									
									query.append(" test_name like ('");
									query.append("Vmg");
									query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" and lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								query.append(" ( lower(COMP_NAME) like ('%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
								if(hasVMs)
								{
									
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" OR (test_name like ('");
										query.append("Vmg");
										query.append("%')");
										query.append(" AND lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								query.append(" ) ");
							}
						}
						else
						{
							query.append("  lower(COMP_NAME) like ('%");
							query.append(comp_name_search.toLowerCase());
							query.append("%')");
						}
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") and  INFO>' ' AND ");
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL")&& s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND "); 
							}
							else{
								//query.append("COMP_NAME>' ' and  INFO>' ' AND ");//commented by raj-26.05.2016
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND ");
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
					}
					else
					{
						query.append(" ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
						query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			else 
			{
				// filter based on comp_name 
				if (EgInstallInfo.isSuperManager)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						ora_query.append("COMP_NAME IN (");
						ora_query.append(serverNames);
						ora_query.append(") and ");
						sql_query.append("COMP_NAME IN (");
						sql_query.append(serverNames);
						sql_query.append(") and ");
					}
					ora_query.append("COMP_TYPE IN (");
					ora_query.append(serverTypes);
					sql_query.append("COMP_TYPE IN(");
					sql_query.append(serverTypes);
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							//query.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							ora_query.append(") and INFO like ('"+insideViewInfo+"%')");
							sql_query.append(") and INFO like ('"+insideViewInfo+"%')");
						}
						else
						{
							ora_query.append(") and INFO>' ' ");
							sql_query.append(") and INFO>' ' ");
						}
					}
					else
					{
						ora_query.append(") and INFO>' ' ");
						sql_query.append(") and INFO>' ' ");
					}

					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						ora_query.append(" and test_name in("+testList+") ");
						sql_query.append(" and test_name in("+testList+") ");
					}
					else
					{
						sql_query.append("and TEST_NAME>' ' ");
					}
					
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)");
					}
					else
					{
						ora_query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append("COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN (");
					query.append(serverTypes);
		
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							//query.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							query.append(") and INFO like ('"+insideViewInfo+"%')");
						}
						else
							query.append(") and INFO>' ' ");
					}
					else
					{
						query.append(") and INFO>' ' ");
					}

					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						query.append(" and test_name in("+testList+") ");
					}
					else
					{
						query.append("and TEST_NAME>' ' ");
					}
					/*query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss')) ");
					query.append(" OR (END_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss'))) ");*/
					if(isFromInsideviewDashboard)
					{
						query.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append("COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN(");
					query.append(serverTypes);
			
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							if(insideViewInfo.indexOf("[")>-1)
							{
								insideViewInfo=insideViewInfo.substring(0,insideViewInfo.indexOf("["));
								insideViewInfo=insideViewInfo.substring(insideViewInfo.lastIndexOf("]")+1);
								insideViewInfo=insideViewInfo.trim();
								query.append(") and INFO like ('"+insideViewInfo+"%')");
							}
							else
							{
								query.append(") and INFO like ('"+insideViewInfo+"%')");
							}
						}
						else
							query.append(") and INFO>' ' ");
					}
					else
					{
						query.append(") and INFO>' ' ");
					}

					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						query.append(" and test_name in("+testList+") ");
					}
					else
					{
						query.append("and TEST_NAME>' ' ");
					}
				
					if(isFromInsideviewDashboard)
					{
						query.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)");
					}
					else
					{
						query.append(" and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			if (durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				if (lessThanZero)
				{
					durationFilter = Math.abs(durationFilter);
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");

					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");

					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
			}
	
			if (EgInstallInfo.isSuperManager)
			{
				query = new StringBuffer();
			}
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(s_event!=null && s_event.equals("Component"))
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						if(hasVMs)
						{
							
							query.append(" AND test_name like ('");
							query.append("Vmg");
							query.append("%')");
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
							}
							//what if type is all , selected comp is not.
						}
					}
					else
					{
						query.append(" AND ( lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%') ");
						if(hasVMs)
						{
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" OR (test_name like ('");
								query.append("Vmg");
								query.append("%')");
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								//query.append(" OR INFO like ('+%");
								//query.append(comp_name_search);
								query.append("%')) ");
							}
							//what if type is all , selected comp is not.
						}
						query.append(" ) ");
					}
				}
				else
				{
					query.append(" AND lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
			}
			//query.append(" ORDER BY START_TIME DESC");
		


			logToTmpFile("INFO","","Query for event history2 is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(query);
					sql_query.append(query);
					Hashtable ht = new Hashtable();
					ht.put("OracleQuery",ora_query.toString());
					ht.put("SqlQuery",sql_query.toString());
					ht.put("AddMgrIdToRs","yes");
					if(fromTime != null && fromTime.indexOf(":")==fromTime.lastIndexOf(":"))
					{
						ht.put("sourceDateFormat","MM/dd/yyyy HH:mm");
					}
					else
					{
						ht.put("sourceDateFormat","MM/dd/yyyy HH:mm:ss");
					}
					ht.put("startDate",fromTime);
					ht.put("endDate",toTime);
					if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
					{
						ArrayList al = (ArrayList) EgManagersInfo.sessionManagerMap.get(currentSessionId);
						if(al != null && !al.isEmpty())
						{
							ht.put("special_case_mgr_ids",al);
						}
					}
					rs = new EgSMDBHelper().getResultSet(ht);
				}
				else
				{
					qry = query.toString();
					rs = egDb.dbselect(qry);
				}
				if(EgInstallInfo.isSuperManager)
				{
					while(rs.next())
					{
						String mgr_id = rs.getString("ManagerID");
						int mgr_alarms_count = rs.getInt("count");
						managerRowCount.put(mgr_id,mgr_alarms_count);
						recCount += mgr_alarms_count;
					}
				}
				else
				{
					if(rs.next())
					{
						 recCount  = rs.getInt("count");
					}
				}				
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				
			return recCount;
			
				
			}
			catch (Exception chasegrrr)
			{
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return 0;
			}
		}
	}

	/**
	 * Returns all the events in the Report table for the specified component
	 * name, component type, start and end times.
	 *
	 * @see 	Event History
	 *
	 * @param 	serverNmes	Comma-separated component names
	 * @param 	serverTypes	Comma-separated component types
	 * @param 	fromTime
	 * @param 	toTime
	 *
	 * @return	java.sql.ResultSet
	 */

	public List getEventHistory(
		List servers,
		String serverNames,
		String serverTypes,
		String fromTime,
		String toTime,
		String eventID,
		//int offsetCount,
		long durationFilter,
		String state,
		//boolean reverseList, 
		EgDbAdapterUI egDb,EgMappingInfo mappingInfo,LangInfo langinfo,String selectedArrangeOption,String infosearch,List userCompList,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List vmUserCompList,String s_event,int startIndex,int endIndex,int evtPerPage,MonitorUtility Monutil)
	{
		if(EgInstallInfo.isSuperManager)
		{
			ArrayList managerIds = null;
			if(!servers.isEmpty())
			{
				if(serverNames != null && serverNames.trim().length()>1)
				{
					String hostname = serverNames.substring(1,serverNames.length()-1);
					hostname = hostname.substring(0,hostname.indexOf(":"));
					managerIds = EgElementInfo.getInstance().getManagerIDs("component",hostname);
					if(managerIds != null && managerIds.isEmpty())
					{
						managerIds=null;
					}
				}
			}
			Hashtable paramHt = new Hashtable();
			paramHt.put("AddMgrIdToRs","true");
			paramHt.put("PaginationDetails",rowManager);
			paramHt.put("Index",new int[]{startIndex,endIndex});	
			EgSMDBHelper.paramsOfJSP.put(currentSessionId,paramHt);
			SmSessionData smsData = new SmSessionData(currentSessionId,managerIds);
			EgThreadLocal egtl = new EgThreadLocal();
			egtl.set(smsData);
			new SMDateTimeConverter("MM/dd/yyyy HH:mm",fromTime,toTime);
		}
		EgUserRole userRole = user.getUserRole();
		boolean isAllCompnt = userRole.hasAllComponentAccess();
		String comp_name_search="";
		if(infosearch!=null && infosearch.trim().length()>0 && infosearch.indexOf("^egsep^")>0)
		{
			ArrayList emptyColumnsList =  com.egurkha.util.StringUtils.egTokenizer(infosearch, "^egsep^",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			if(emptyColumnsList!=null && emptyColumnsList.size()>=2)
			{
				infosearch=(String)emptyColumnsList.get(0);
				if(infosearch!=null)
					infosearch=infosearch.trim();
				comp_name_search=(String)emptyColumnsList.get(1);
				if(comp_name_search!=null)
					comp_name_search=comp_name_search.trim();
			}
		}

		//EgDateInfo dateInfo = new EgDateInfo();
		StringBuffer query = new StringBuffer(320);
		StringBuffer ora_query = new StringBuffer(320);
		StringBuffer sql_query = new StringBuffer(320);
		StringBuffer sb_time =new StringBuffer();
		List result = new LinkedList();
		//selectedArrangeOption = "-1";	
		boolean isArrangeOpt = false;		
		if(selectedArrangeOption.equalsIgnoreCase("-1") || selectedArrangeOption.equalsIgnoreCase("comp_name"))
			isArrangeOpt = true;	
		if(infosearch!=null && !infosearch.equalsIgnoreCase("null") && !infosearch.trim().equals("")) 
		{			
			isArrangeOpt = false;
		}
		
		if(hasVMs)
			isArrangeOpt = false;

		//TODO Check the date format for compatibility
		if (servers.isEmpty())
		{
			if(isArrangeOpt)
				query.append("SELECT * FROM(");
			query.append(
			"SELECT EVENT_ID,SITE_NAME,COMP_NAME,COMP_TYPE,INFO,TEST_NAME,MEASURE,MSMT_HOST,EVENT_SEVERITY,START_TIME,END_TIME");

			
			if(selectedArrangeOption.equalsIgnoreCase("comp_name"))
				query.append(",ROW_NUMBER() OVER (ORDER BY COMP_NAME,START_TIME DESC) as r");
			else if(isArrangeOpt)
				query.append(",ROW_NUMBER() OVER (ORDER BY START_TIME DESC) as r");
			
			



			query.append(" FROM ALARM_HISTORY_SUMMARY WHERE ");

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  EVENT_SEVERITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  EVENT_SEVERITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			sb_time.append("EVENT_ID > ' ' AND ");
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(s_event!=null && s_event.equals("Component"))
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						if(hasVMs)
						{
							query.append(" test_name like ('");
							query.append("Vmg");
							query.append("%')");

							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
							}
							//what if type is all , selected comp is not.
						}
					}
					else
					{
						query.append(" ( lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%') ");
						if(hasVMs)
						{
							
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" OR (test_name like ('");
								query.append("Vmg");
								query.append("%')");

								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')) ");
							}
							//what if type is all , selected comp is not.
						}
						query.append(" ) ");
					}
				}
				else
				{
					query.append("  lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
				query.append(" AND ");
				
			}
			ora_query.append(query);
			sql_query.append(query);
			if (EgInstallInfo.isSuperManager)
			{
				StringBuffer ora_sb_time = new StringBuffer();
				StringBuffer sql_sb_time = new StringBuffer();
				ora_sb_time.append(sb_time);
				sql_sb_time.append(sb_time);
				if(isFromInsideviewDashboard)
				{
					ora_sb_time.append(" START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					query.append(sql_sb_time);
					
				}
				else
				{
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(END_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(");
					ora_sb_time.append(" (START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME >= to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(")) OR ");
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME = to_date('");
					ora_sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					ora_sb_time.append("))) ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME >= convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME = convert(datetime,'");
					sql_sb_time.append("01/01/1900 00:00");
					sql_sb_time.append("',101)))) ");
					sql_query.append(sql_sb_time);
				}
			}
			else if (EgDbInfo.isOraAdapter)
			{
				/*sb_time.append("(");
				sb_time.append("(START_TIME BETWEEN to_date('");
				sb_time.append(fromTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
				sb_time.append(toTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
				sb_time.append(") OR ");
				sb_time.append("(END_TIME BETWEEN to_date('");
				sb_time.append(fromTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
				sb_time.append(toTime);
				sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
				sb_time.append("))");*/

				// query commend and changed on 3-aug-2010
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					query.append(sb_time);
					
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append(" (START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(")) OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = to_date('");
					sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					sb_time.append("))) ");
					query.append(sb_time);
				}
			}
			else
			{
				/*sb_time.append("(");
				sb_time.append("(START_TIME BETWEEN convert(datetime,'");
				sb_time.append(fromTime);
				sb_time.append("', 101) AND convert(datetime,'");
				sb_time.append(toTime);
				sb_time.append("',101) ");
				sb_time.append(") OR ");
				sb_time.append("(END_TIME BETWEEN convert(datetime,'");
				sb_time.append(fromTime);
				sb_time.append("', 101) AND convert(datetime,'");
				sb_time.append(toTime);
				sb_time.append("',101) ");
				sb_time.append("))");*/

				// query commend and changed on 3-aug-2010
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					query.append(sb_time);
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101)) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = convert(datetime,'");
					sb_time.append("01/01/1900 00:00");
					sb_time.append("',101)))) ");
					query.append(sb_time);
				}
			}

			if(durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				if (lessThanZero)
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");

						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
			}

			if(!isArrangeOpt)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" ORDER BY START_TIME DESC");
					sql_query.append(" ORDER BY START_TIME DESC");
				}
				else
				{
					query.append(" ORDER BY START_TIME DESC");
				}
			}
			else
			{
				if(EgInstallInfo.isSuperManager)
				{
					if(startIndex==1)
					{
						ora_query.append(") where r>="+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						ora_query.append(") where r>"+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>"+startIndex+" and r<="+endIndex);
					}
				}
				else if(EgDbInfo.isOraAdapter)
				{
					if(startIndex==1)
						query.append(") where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(") where r>"+startIndex+" and r<="+endIndex);
				}
				else
				{
					if(startIndex==1)
						query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(")as s where r>"+startIndex+" and r<="+endIndex);
				}

				
			}
			
			logToTmpFile("INFO","","Query for event history is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				rs = egDb.dbselect(qry);
				ArrayList sortEvent=new ArrayList();

				//if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !selectedArrangeOption.equalsIgnoreCase("-1") && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
				if(userRole.hasAllComponentAccess())
				{
					/*if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
					{
						if(selectedArrangeOption!=null && selectedArrangeOption.equalsIgnoreCase("comp_type") || selectedArrangeOption.equalsIgnoreCase("Service"))
						{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,hasAllComponentAccess,userCompList,siteNames);
						}
						else
						{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage);
						}
					}
					else
					{
						result = (List)egDb.getResultSetAsList(rs);
					}*/

					//result = (List)egDb.getResultSetAsList(rs);
					
					if(infosearch!=null && !infosearch.equalsIgnoreCase("null") &&  !infosearch.equalsIgnoreCase("undefined")  && infosearch.length()>0)
					{
						result = (List)egDb.getResultSetAsList(rs,infosearch,thisLanguage,isCustomAlertMessages);
					}
					else
					{
						result = (List)egDb.getResultSetAsList(rs);
					}

				}
				else
				{
					/*if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
					{
						if(selectedArrangeOption!=null && selectedArrangeOption.equalsIgnoreCase("comp_type") || selectedArrangeOption.equalsIgnoreCase("Service"))
						{
							if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && (s_event.equals("Service") || s_event.equals("Segment") || s_event.equals("Zone")))
							{
								sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,hasAllComponentAccess,userCompList,siteNames);
							}
							else if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && s_event.equals("Component"))
							{
								logToTmpFile("INFO","","ALARM HIST TABLE>> sort block 1 ");
								sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers,hasAllComponentAccess,userCompList,siteNames,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList);
							}
							else
							{
								sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage);
							}
						}
						else
						{
							if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && (s_event.equals("Service") || s_event.equals("Segment") || s_event.equals("Zone")))
							{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers);
							}
							else if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && s_event.equals("Component"))
							{
								logToTmpFile("INFO","","ALARM HIST TABLE>> sort block 2 ");
								sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
							}
							else
							{
								sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage);
							}
							
						}
					}
					else
					{
						logToTmpFile("INFO","","ALARM HIST TABLE>>> showAll ... b4 calling getevent as list " + showAll);
						result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
					}
*/
					logToTmpFile("INFO","","ALARM HIST TABLE>>> showAll ... b4 calling getevent as list " + showAll);
					if(infosearch!=null && !infosearch.equalsIgnoreCase("null") &&  !infosearch.equalsIgnoreCase("undefined")  && infosearch.length()>0)
					{
						result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList,infosearch,thisLanguage,Monutil);
					}
					else
					{
						result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList,Monutil);
					}
				}
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				
				if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
				{
					if(sortEvent!=null && sortEvent.size()>0)
					{
						int arrCnt = 11;
						if(hasVMs)
						{
							arrCnt = 12;
						}
						if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
						{
							EgAlarmComparator.compareValue=3;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}

								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							EgAlarmComparator.compareValue=2;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];
								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
					
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							if(hasVMs)
							{
								if(user.isOnlyVMAssigned() && !user.isVMAssigned())
								{
									EgAlarmComparator.compareValue=7;
									
								}
								else
								{
									//EgAlarmComparator.compareValue=8;
									EgAlarmComparator.compareValue=1;
								}
							}
							else
							{
							EgAlarmComparator.compareValue=1;
							}
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Service"))
						{
							EgAlarmComparator.compareValue=6;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Test"))
						{
							EgAlarmComparator.compareValue=5;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
					}
					//end here
				}
				if (result != null && result.size()>0)
				{
					if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
					{
						//result = getDescriptionSearch(result,infosearch);
						result=result;
						infoSearchCount.put(infoRandom,new Integer(result.size()));
					}
				}

				if(hasVMs)
				{
					infoSearchCount.put(infoRandom,new Integer(result.size()));
				}



				
					
					if(!isArrangeOpt){
						
						if(endIndex>=(result.size()-1))
							result = result.subList((startIndex),(result.size()));
						else
							result = result.subList((startIndex),(endIndex));
						}				
				return result;
			}
			catch (Exception jpm)
			{
				logToTmpFile("INFO","","Error "+jpm.toString());
				jpm.printStackTrace();
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return null;
			}
		}
		else
		{
			
		
			if(isArrangeOpt)
				query.append("SELECT * FROM(");
			
			
			query.append(
			"SELECT EVENT_ID,SITE_NAME,COMP_NAME,COMP_TYPE,INFO,TEST_NAME,MEASURE,MSMT_HOST,EVENT_SEVERITY,START_TIME,END_TIME");

			//if(selectedArrangeOption.equalsIgnoreCase("comp_type") && !EgDbInfo.isOraAdapter)
			if(selectedArrangeOption.equalsIgnoreCase("comp_name"))
				query.append(",ROW_NUMBER() OVER (ORDER BY COMP_NAME,START_TIME DESC) as r");
			//else if(isArrangeOpt && !EgDbInfo.isOraAdapter)
			else if(isArrangeOpt)
				query.append(",ROW_NUMBER() OVER (ORDER BY START_TIME DESC) as r");
			
			query.append(" FROM ALARM_HISTORY_SUMMARY WHERE ");

			

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  EVENT_SEVERITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  EVENT_SEVERITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			query.append("EVENT_ID > ' ' AND SITE_NAME>' ' AND ");
			ora_query.append(query);
			sql_query.append(query);
			if (serverNames.length()==0)
			{
				// filter based on comp_type
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(" COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(") and TEST_NAME>' ' and MEASURE>' ' and ");
					sql_query.append(" COMP_TYPE IN (");
					sql_query.append(serverTypes);
					sql_query.append(")  and TEST_NAME>' ' and MEASURE>' ' and ");

					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									ora_query.append(" test_name like ('");
									ora_query.append("Vmg");
									ora_query.append("%')");
									sql_query.append(" test_name like ('");
									sql_query.append("Vmg");
									sql_query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										ora_query.append(" and lower(INFO) like ('+%");
										ora_query.append(comp_name_search.toLowerCase());
										ora_query.append("%')");
										sql_query.append(" and lower(INFO) like ('+%");
										sql_query.append(comp_name_search.toLowerCase());
										sql_query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								ora_query.append(" ( lower(COMP_NAME) like ('%");
								ora_query.append(comp_name_search.toLowerCase());
								ora_query.append("%')");
								sql_query.append(" ( lower(COMP_NAME) like ('%");
								sql_query.append(comp_name_search.toLowerCase());
								sql_query.append("%')");
								if(hasVMs)
								{
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										ora_query.append(" OR (test_name like ('");
										ora_query.append("Vmg");
										ora_query.append("%')");
										ora_query.append(" AND lower(INFO) like ('+%");
										ora_query.append(comp_name_search.toLowerCase());
										ora_query.append("%')) ");
										sql_query.append(" OR (test_name like ('");
										sql_query.append("Vmg");
										sql_query.append("%')");
										sql_query.append(" AND lower(INFO) like ('+%");
										sql_query.append(comp_name_search.toLowerCase());
										sql_query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								ora_query.append(" ) ");
								sql_query.append(" ) ");
							}
						}
						else
						{
							ora_query.append("  lower(COMP_NAME) like ('%");
							ora_query.append(comp_name_search.toLowerCase());
							ora_query.append("%')");
							sql_query.append("  lower(COMP_NAME) like ('%");
							sql_query.append(comp_name_search.toLowerCase());
							sql_query.append("%')");
						}
						ora_query.append(" AND ");
						sql_query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							ora_query.append("COMP_NAME IN(");
							ora_query.append(tmp_srvers);
							ora_query.append(") and  INFO>' ' AND ");							
							sql_query.append("COMP_NAME IN(");
							sql_query.append(tmp_srvers);
							sql_query.append(") and  INFO>' ' AND ");
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								ora_query.append("COMP_NAME IN(");
								ora_query.append(tmp_srvers);
								ora_query.append(") and  INFO>' ' AND ");								
								sql_query.append("COMP_NAME IN(");
								sql_query.append(tmp_srvers);
								sql_query.append(") and  INFO>' ' AND "); 
							}
							else
							{
								ora_query.append("COMP_NAME IN(");
								ora_query.append(tmp_srvers);
								ora_query.append(") and  INFO>' ' AND ");								
								sql_query.append("COMP_NAME IN(");
								sql_query.append(tmp_srvers);
								sql_query.append(") and  INFO>' ' AND ");
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
					}
					else
					{
						ora_query.append("	((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append(" END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
						sql_query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					/*query.append("COMP_NAME>' ' and COMP_TYPE IN (");
					query.append(serverTypes);
					query.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') ");
					query.append(") OR (END_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss'))) ");*/

					// query commend and changed on 3-aug-2010

					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and");
					}
					query.append(" TEST_NAME>' ' and MEASURE>' ' and ");
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									query.append(" test_name like ('");
									query.append("Vmg");
									query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" and lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								query.append(" ( lower(COMP_NAME) like ('%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
								if(hasVMs)
								{
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" OR (test_name like ('");
										query.append("Vmg");
										query.append("%')");
										query.append(" AND lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								query.append(" ) ");
							}
						}
						else
						{
							query.append("  lower(COMP_NAME) like ('%");
							query.append(comp_name_search.toLowerCase());
							query.append("%')");
						}
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") and  INFO>' ' AND ");	
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND "); 
							}
							else{
								//query.append("COMP_NAME>' ' and  INFO>' ' AND "); 
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND "); 
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append("	((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append(" END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					/*query.append("COMP_NAME>' ' and COMP_TYPE IN (");
					query.append(serverTypes);
					query.append(") and INFO>' ' and TEST_NAME>' ' and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
					query.append("',101 ) AND convert(datetime,'");
					query.append(toTime);
					query.append("',101) ");
					query.append(") OR (END_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
					query.append("',101 ) AND convert(datetime,'");
					query.append(toTime);
					query.append("',101))) ");*/

					// query commend and changed on 3-aug-2010
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and");	
					}
					query.append(" TEST_NAME>' ' and MEASURE>' ' and ");
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						if(s_event!=null && s_event.equals("Component"))
						{
							if(user.isOnlyVMAssigned() && !user.isVMAssigned())
							{
								if(hasVMs)
								{
									
									query.append(" test_name like ('");
									query.append("Vmg");
									query.append("%')");

									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" and lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')");
									}
									//what if type is all , selected comp is not.
								}
							}
							else
							{
								query.append(" ( lower(COMP_NAME) like ('%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
								if(hasVMs)
								{
									
									
									if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
									{
										query.append(" OR (test_name like ('");
										query.append("Vmg");
										query.append("%')");
										query.append(" AND lower(INFO) like ('+%");
										query.append(comp_name_search.toLowerCase());
										query.append("%')) ");
									}
									//what if type is all , selected comp is not.
								}
								query.append(" ) ");
							}
						}
						else
						{
							query.append("  lower(COMP_NAME) like ('%");
							query.append(comp_name_search.toLowerCase());
							query.append("%')");
						}
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") and  INFO>' ' AND ");	
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND "); 
							}
							else{
								//query.append("COMP_NAME>' ' and  INFO>' ' AND "); //commented by raj-26.05.2016
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") and  INFO>' ' AND "); 
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
					}
					else
					{
						query.append(" ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
						query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			else 
			{
				// filter based on comp_name 
				if (EgInstallInfo.isSuperManager)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						ora_query.append("COMP_NAME IN (");
						ora_query.append(serverNames);
						ora_query.append(") and ");
						sql_query.append("COMP_NAME IN (");
						sql_query.append(serverNames);
						sql_query.append(") and ");
					}
					ora_query.append("COMP_TYPE IN (");
					ora_query.append(serverTypes);
					sql_query.append("COMP_TYPE IN(");
					sql_query.append(serverTypes);
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							//query.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							ora_query.append(") and INFO like ('"+insideViewInfo+"%')");
							sql_query.append(") and INFO like ('"+insideViewInfo+"%')");
						}
						else
						{
							ora_query.append(") and INFO>' ' ");
							sql_query.append(") and INFO>' ' ");
						}
					}
					else
					{
						ora_query.append(") and INFO>' ' ");
						sql_query.append(") and INFO>' ' ");
					}

					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						ora_query.append(" and test_name in("+testList+") ");
						sql_query.append(" and test_name in("+testList+") ");
					}
					else
					{
						sql_query.append("and TEST_NAME>' ' ");
					}
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)");
					}
					else
					{
						ora_query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append("COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN (");
					query.append(serverTypes);
		
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							//query.append(") and lower(INFO) like ('"+insideViewInfo+"%')");
							query.append(") and INFO like ('"+insideViewInfo+"%')");
						}
						else
							query.append(") and INFO>' ' ");
					}
					else
					{
						query.append(") and INFO>' ' ");
					}

					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						query.append(" and test_name in("+testList+") ");
					}
					else
					{
						query.append("and TEST_NAME>' ' ");
					}
					/*query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss')) ");
					query.append(" OR (END_TIME BETWEEN to_date('");
					query.append(fromTime);
					query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					query.append(toTime);
					query.append("','mm/dd/yyyy hh24:mi:ss'))) ");*/
					if(isFromInsideviewDashboard)
					{
						query.append(" and MEASURE>' ' and START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append(" and MEASURE>' ' and ((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append("COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN(");
					query.append(serverTypes);
			
					if(isFromInsideviewDashboard)
					{
						if(insideViewInfo!=null && insideViewInfo.trim().length()>0)
						{
							if(insideViewInfo.indexOf("[")>-1)
							{
								insideViewInfo=insideViewInfo.substring(0,insideViewInfo.indexOf("["));
								insideViewInfo=insideViewInfo.substring(insideViewInfo.lastIndexOf("]")+1);
								insideViewInfo=insideViewInfo.trim();
								query.append(") and INFO like ('"+insideViewInfo+"%')");
							}
							else
							{
								query.append(") and INFO like ('"+insideViewInfo+"%')");
							}
						}
						else
							query.append(") and INFO>' ' ");
					}
					else
					{
						query.append(") and INFO>' ' ");
					}
					if(isFromDashBoard && testList != null && testList.trim().length() > 0 )
					{
						query.append(" and test_name in("+testList+") ");
					}
					else
					{
						query.append("and TEST_NAME>' ' ");
					}
					/*
					query.append(" and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
					query.append("',101) AND convert(datetime,'");
					query.append(toTime);
					query.append("',101)) ");
					query.append(" OR (END_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
					query.append("',101) AND convert(datetime,'");
					query.append(toTime);
					query.append("',101))) ");
					*/
					if(isFromInsideviewDashboard)
					{
						query.append(" and MEASURE>' ' and START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)");
					}
					else
					{
						query.append(" and MEASURE>' ' and ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			if (durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				if (lessThanZero)
				{
					durationFilter = Math.abs(durationFilter);
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");

					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");

					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
			}
			/*if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_type"))
				query.append(" ORDER BY COMP_TYPE ");
			else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
				query.append(" ORDER BY COMP_NAME ");
			else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Service"))
				query.append(" ORDER BY SITE_NAME ");
			else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Test"))
				query.append(" ORDER BY TEST_NAME ");
			else
				query.append(" ORDER BY START_TIME DESC");*/
			if (EgInstallInfo.isSuperManager)
			{
				query = new StringBuffer();
			}
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(s_event!=null && s_event.equals("Component"))
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						if(hasVMs)
						{
							
							query.append(" AND test_name like ('");
							query.append("Vmg");
							query.append("%')");
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								query.append("%')");
							}
							//what if type is all , selected comp is not.
						}
					}
					else
					{
						query.append(" AND ( lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%') ");
						if(hasVMs)
						{
							if(showAll || (selectedCompType!=null && selectedCompType.equals(user.getVMType()) || (selectedCompName!=null && !selectedCompName.equals("Component Name (Optional)"))))
							{
								query.append(" OR (test_name like ('");
								query.append("Vmg");
								query.append("%')");
								query.append(" AND lower(INFO) like ('+%");
								query.append(comp_name_search.toLowerCase());
								//query.append(" OR INFO like ('+%");
								//query.append(comp_name_search);
								query.append("%')) ");
							}
							//what if type is all , selected comp is not.
						}
						query.append(" ) ");
					}
				}
				else
				{
					query.append(" AND lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
			}
			
		

			if(!isArrangeOpt)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" ORDER BY START_TIME DESC");
					sql_query.append(" ORDER BY START_TIME DESC");
				}
				else
				{
					query.append(" ORDER BY START_TIME DESC");
				}
			}
			else
			{
				if(EgInstallInfo.isSuperManager)
				{
					if(startIndex==1)
					{
						ora_query.append(") where r>="+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						ora_query.append(") where r>"+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>"+startIndex+" and r<="+endIndex);
					}
				}
				else if(EgDbInfo.isOraAdapter)
				{
					if(startIndex==1)
						query.append(") where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(") where r>"+startIndex+" and r<="+endIndex);
				}
				else
				{
					if(startIndex==1)
						query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(")as s where r>"+startIndex+" and r<="+endIndex);
				}
			}
			
			logToTmpFile("INFO","","Query for event history2 is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(query);
					sql_query.append(query);
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				rs = egDb.dbselect(qry);
				ArrayList sortEvent=new ArrayList();
				//if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !selectedArrangeOption.equalsIgnoreCase("-1") && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
				/*if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
				{
					if(selectedArrangeOption!=null && selectedArrangeOption.equalsIgnoreCase("comp_type") || selectedArrangeOption.equalsIgnoreCase("Service"))
					{
						if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && (s_event.equals("Service") || s_event.equals("Segment") || s_event.equals("Zone")))
						{
						sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers,hasAllComponentAccess,userCompList,siteNames);
						}
						else if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && s_event.equals("Component"))// && servers!=null && servers.size()>0)
						{
							logToTmpFile("INFO","","ALARM HIST TABLE>> sort block 1 ");
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers,hasAllComponentAccess,userCompList,siteNames,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,vmUserCompList);
						}
						else
						{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,hasAllComponentAccess,userCompList,siteNames);	
						}
					}
					else
					{
						if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && (s_event.equals("Service") || s_event.equals("Segment") || s_event.equals("Zone")))
						{
						sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers);
						}
						else if(s_event!=null && s_event.trim().length()>0 && !s_event.equalsIgnoreCase("null") && s_event.equals("Component"))// && servers!=null && servers.size()>0)
						{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage,servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
						}
						else
						{
							sortEvent= (ArrayList)egDb.getResultSetAsList(rs,mappingInfo,thisLanguage);
						}
					}
				}
				else
				{
					result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
				}*/

					if(infosearch!=null && !infosearch.equalsIgnoreCase("null") &&  !infosearch.equalsIgnoreCase("undefined")  && infosearch.length()>0)
					{
						result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList,infosearch,thisLanguage,Monutil);
					}
					else
					{
						result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList,Monutil);
					}
					//result = (List)getEventHistAsList(rs, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
				{
					int arrCnt =11;
					if(hasVMs)
					{
						arrCnt = 12;
					}
					//here start thendral
					if(sortEvent!=null && sortEvent.size()>0)
					{
						if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
						{
							EgAlarmComparator.compareValue=3;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							
							EgAlarmComparator.compareValue=2;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							if(hasVMs)
							{
								if(user.isOnlyVMAssigned() && !user.isVMAssigned())
								{
									EgAlarmComparator.compareValue=7;
								}
								else
								{
									//EgAlarmComparator.compareValue=8;
									EgAlarmComparator.compareValue=1;
								}
							}
							else
							{
							EgAlarmComparator.compareValue=1;
							}
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Service"))
						{
							EgAlarmComparator.compareValue=6;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Test"))
						{
							EgAlarmComparator.compareValue=5;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
					}
					//here end thendral
				}
				if (result != null && result.size()>0)
				{
					if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
					{
						//result = getDescriptionSearch(result,infosearch);
						result=result;
						infoSearchCount.put(infoRandom,new Integer(result.size()));
					}
				}

				if(hasVMs)
				{
					infoSearchCount.put(infoRandom,new Integer(result.size()));
				}
			
			
				if(!isArrangeOpt)
				{
					if(endIndex>=(result.size()-1))
							result = result.subList((startIndex),(result.size()));
						else
							result = result.subList((startIndex),(endIndex));
					
					//result = result.subList((startIndex),(endIndex));
				}

			
				return result;
			}
			catch (Exception chasegrrr)
			{
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return null;
			}
		}
	}
	public List getDescriptionSearch(List result,String infosearch,boolean hasVMs,MonitorUtility Monutil)throws SQLException
	{
		List descSearch=new LinkedList();
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		EgMappingInfo mappingInfo1 = new EgMappingInfo(thisLanguage);
		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null"))
		{
			if(infosearch.startsWith("*"))
			{
				infosearch=infosearch.substring(1);
			}
			if(infosearch.endsWith("*"))
			{
				infosearch=infosearch.substring(0,infosearch.length()-1);
			}
			if(infosearch.startsWith("*") && infosearch.endsWith("*"))
			{
				infosearch=infosearch.substring(1);
				infosearch=infosearch.substring(0,infosearch.length()-1);
			}
		}
		for (Iterator i=result.iterator(); i.hasNext();)
		{
			String[] row = (String[])i.next();
			String tmp_cmpType=row[3];
			StringBuffer desc_key=new StringBuffer();
			desc_key.append(row[5]);
			desc_key.append(EgConstants.COLON);
			desc_key.append(row[6]);
			String description ="";
			int len = 0;
			//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
			//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
			if(isCustomAlertMessages)
			{
				String custom_info=row[4];
				String site1=row[1];
				if(StringUtils.isNull(site1))
					site1="NONE";
				if(row[4]!=null && row[4].length()>1 && row[4].startsWith("+"))
				{
					custom_info=row[4].substring(1);
				}
				
				String layer=dashboardDAO.getLayerForTest(row[3],row[5],row[6]);
				description = tablesInfo.getCustomMeasureAlert(desc_key.toString(), row[4],thisLanguage);
				len = description.trim().length();
				if(description != null && len > 0){
					description =replaceMsg(description,Server.getServerNameWithoutPort(row[2], false),mappingInfo1.getComponentTypeDescription(row[3]),site1,mappingInfo1.getLabelDescription(row[8]),mappingInfo1.getLayerDescription(layer),mappingInfo1.getTestDescription(row[5]),custom_info,mappingInfo1.getMeasureDescription(row[5],row[6]),"");
				}
			}
			if(description == null || len == 0 || description.startsWith(row[6]))
			{
				Hashtable alertParams = new Hashtable();
				alertParams.put("$componentType",mappingInfo1.getComponentTypeDescription(row[3]));
				alertParams.put("$componentName",Server.getServerNameWithoutPort(row[2], false));
				if(row[4]!=null && row[4].trim().length()>1){
					if(row[4].startsWith("+"))
						alertParams.put("$info",row[4].substring(1));
					else
						alertParams.put("$info",row[4]);
				}
				alertParams.put("hasVMs",hasVMs);
				 description = tablesInfo.getMeasureAlert(desc_key.toString(),row[4],thisLanguage,alertParams);
				 description = (description.indexOf("~!~") != -1)?description.substring(0,description.indexOf("~!~")):description;
				 description = description+"$info$"+row[4];
			}
			if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
			{
				infosearch=infosearch.toLowerCase();
				description=description.toLowerCase();
				if (description!=null && description.indexOf(infosearch) >-1)
				{
					descSearch.add((String[])row);
				}
			}
		}
		return descSearch;
	}
	public final List getEventHistAsList(ResultSet rs, List servers,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List userCompList,MonitorUtility Monutil) throws SQLException
	{
		List list = new LinkedList();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		List userServ = userCompList;
		List a_userVMs = new LinkedList();
		String vm  = "";
		while (rs.next())
		{
			//if (count > 1)
			{
				String[] row = new String[count];
				for (int a = 0; a < count; a++)
				{
					row[a] = rs.getString(a + 1);
				}
				String ctypeName = null;//row[3]+":"+row[2];
				String testName = null;//row[5];
				if(EgInstallInfo.isSuperManager)
				{
					ctypeName = row[4]+":"+row[3];
					testName = row[6];
				}
				else
				{
					ctypeName = row[3]+":"+row[2];
					testName = row[5];
				}
				if(hasVMs)
				{
					a_userVMs = user.getAlluserDesktopVms();
					//a_userVMs = user.getOnlyVMs();
					if(showAll)
					{	
								if(!userServ.contains(ctypeName))
								{
									if(!ctypeName.startsWith("Host_system"))
									{
										if(EgInstallInfo.isSuperManager)
										{
											if(!row[6].startsWith("Vmg"))
												continue;
										}
										else if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
										if(EgInstallInfo.isSuperManager)
										{
											vm = rs.getString(6);
										}
										else 
										{
											vm = rs.getString(5);
										}
										vm = vm.substring(1);
										
										if(a_userVMs!=null && a_userVMs.size() > 0)
										{
											if(vm.indexOf(":") > -1)
											{
												vm = vm.substring(0,vm.indexOf(":"));
											}
											
											if(!a_userVMs.contains(vm))
											{
												
												continue;
											}
										}
									}
									else
									{
										continue;
									}
								}
					}
					else
					{
						if(!showAllTypes && showAllComps)
						{
							if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
							{
										if(EgInstallInfo.isSuperManager)
										{
											if(!row[6].startsWith("Vmg"))
												continue;
										}
										else if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
										if(EgInstallInfo.isSuperManager)
										{
											vm = rs.getString(6);
										}
										else 
										{
											vm = rs.getString(5);
										}
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(!a_userVMs.contains(vm))
										{
											continue;
										
										}
									}
								
							}
							else
							{
								if(!userServ.contains(ctypeName))
								{
									continue;
								}
							}
						}
						else if(showAllTypes && !showAllComps)
						{
								int countVM = 0;
								for(int u =0 ; u  < userServ.size() ; u++)
								{
									String host = (String)userServ.get(u);
									String type = host.substring(0,host.indexOf(":"));
									String comp = host.substring(host.indexOf(":")+1);
									if(selectedCompName.indexOf(":") <0)
									{
										if(comp.indexOf(selectedCompName) < 0)
										{
											//it is a vm
											countVM++;
										}
									}
									else
									{
										if(comp.indexOf(selectedCompName) < 0)
										{
											continue;
										}
									}

								}
								if(countVM == userServ.size())
								{
									if(EgInstallInfo.isSuperManager)
									{
										if(!row[6].startsWith("Vmg"))
										continue;
									}
									else if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									if(EgInstallInfo.isSuperManager)
									{
										vm = rs.getString(6);
									}
									else 
									{
										vm = rs.getString(5);
									}
									vm = vm.substring(1);
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										//Count only the vm alarms with the particular descriptor
										if(vm.indexOf(":") > 0)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										if(a_userVMs.contains(vm))
										{

											
												if(!selectedCompName.equals(vm))
												{
													continue;
												}
											
										}
										else
										{
											continue;
										}
									}
								}
								else
								{
									if(ctypeName.indexOf(selectedCompName)>-1)
									{
										if (!userServ.contains(ctypeName))
										{
											continue;
										}
									}
									else
									{
										continue;
									}
								}
							}
							else if(!showAllTypes && !showAllComps)
							{
								if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
								{
									if(EgInstallInfo.isSuperManager)
									{
										if(!row[6].startsWith("Vmg"))
										continue;
									}
									else if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									if(EgInstallInfo.isSuperManager)
									{
										vm = rs.getString(6);
									}
									else 
									{
										vm = rs.getString(5);
									}
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(a_userVMs.contains(vm))
										{
											if(!selectedCompName.equals(vm))
											{
												continue;		
											}
										}
										else
										{
											continue;
										}
									}
								}
								else
								{	
										if(ctypeName.indexOf(selectedCompName)>-1)
										{
											if (!userServ.contains(ctypeName))
											{
												continue;
											}
										}
										else
										{
											continue;
										}


								}
							}
						}
				
				}
				else
				{
					if (!servers.contains(ctypeName))
					{
					continue; // not one of our servers
					}
				}
				list.add(row);
			}
			//else
			//{
				/*
				 * Just the dump the row into the list
				 */
				//list.add(rs.getString(1));
			//}
		}

		return list;
	}
	public final List getEventHistAsList(ResultSet rs, List servers,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List userCompList,String infosearch,String thisLanguage,MonitorUtility Monutil) throws SQLException
	{
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
		List list = new LinkedList();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		List userServ = userCompList;
		List a_userVMs = new LinkedList();
		String vm  = "";
		while (rs.next())
		{
			//if (count > 1)
			{
				String[] row = new String[count];
				for (int a = 0; a < count; a++)
				{
					row[a] = rs.getString(a + 1);
				}
				String ctypeName = row[3]+":"+row[2];
				String testName = row[5];
				
				if(hasVMs)
				{
					a_userVMs = user.getAlluserDesktopVms();
					//a_userVMs = user.getOnlyVMs();
					if(showAll)
					{	
								if(!userServ.contains(ctypeName))
								{
									if(!ctypeName.startsWith("Host_system"))
									{
										if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
										vm = rs.getString(5);
										vm = vm.substring(1);
										
										if(a_userVMs!=null && a_userVMs.size() > 0)
										{
											if(vm.indexOf(":") > -1)
											{
												vm = vm.substring(0,vm.indexOf(":"));
											}
											
											if(!a_userVMs.contains(vm))
											{
												
												continue;
											}
										}
									}
									else
									{
										continue;
									}
								}
					}
					else
					{
						if(!showAllTypes && showAllComps)
						{
							if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
							{
										if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
									vm = rs.getString(5);
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(!a_userVMs.contains(vm))
										{
											continue;
										
										}
									}
								
							}
							else
							{
								if(!userServ.contains(ctypeName))
								{
									continue;
								}
							}
						}
						else if(showAllTypes && !showAllComps)
						{
								int countVM = 0;
								for(int u =0 ; u  < userServ.size() ; u++)
								{
									String host = (String)userServ.get(u);
									String type = host.substring(0,host.indexOf(":"));
									String comp = host.substring(host.indexOf(":")+1);
									if(selectedCompName.indexOf(":") <0)
									{
										if(comp.indexOf(selectedCompName) < 0)
										{
											//it is a vm
											countVM++;
										}
									}
									else
									{
										if(comp.indexOf(selectedCompName) < 0)
										{
											continue;
										}
									}

								}
								if(countVM == userServ.size())
								{
									if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									vm = rs.getString(5);
									vm = vm.substring(1);
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										//Count only the vm alarms with the particular descriptor
										if(vm.indexOf(":") > 0)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										if(a_userVMs.contains(vm))
										{

											
												if(!selectedCompName.equals(vm))
												{
													continue;
												}
											
										}
										else
										{
											continue;
										}
									}
								}
								else
								{
									if(ctypeName.indexOf(selectedCompName)>-1)
									{
										if (!userServ.contains(ctypeName))
										{
											continue;
										}
									}
									else
									{
										continue;
									}
								}
							}
							else if(!showAllTypes && !showAllComps)
							{
								if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
								{
									if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									vm = rs.getString(5);
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(a_userVMs.contains(vm))
										{
											if(!selectedCompName.equals(vm))
											{
												continue;		
											}
										}
										else
										{
											continue;
										}
									}
								}
								else
								{	
										if(ctypeName.indexOf(selectedCompName)>-1)
										{
											if (!userServ.contains(ctypeName))
											{
												continue;
											}
										}
										else
										{
											continue;
										}


								}
							}
						}
				
				}
				else
				{
					if (!servers.contains(ctypeName))
					{
					continue; // not one of our servers
					}


				}
				if(row.length>0 && row.length==count)
				{
					
					String temp_compType=row[3];
					String temp_compName=row[2];
					String temp_siteName=row[1];
					String temp_testName=row[5];
					String temp_info=row[4];
					StringBuffer dec_key = new StringBuffer();
					dec_key.append(row[5]);
					dec_key.append(EgConstants.COLON);
					dec_key.append(row[6]);
					//start
					String temp_description ="";
					int len = 0;
					if(temp_compType!=null && temp_compType.endsWith("_ex"))
					{
						temp_description = tablesInfo.getMeasureAlert(dec_key.toString(),row[4],thisLanguage);
					}
					else
					{
						//temp_description = mappingInfo.getMeasureAlert(dec_key.toString());
						//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
						//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
						if(isCustomAlertMessages)
						{
							String custom_info=row[4];
							String site1=row[1];
							if(StringUtils.isNull(site1))
								site1="NONE";
							if(row[4]!=null && row[4].length()>1 && row[4].startsWith("+"))
							{
								custom_info=row[4].substring(1);
							}
							String layer=dashboardDAO.getLayerForTest(row[3],row[5],row[6]);
							temp_description = tablesInfo.getCustomMeasureAlert(dec_key.toString(), row[4],thisLanguage);
							len = temp_description.trim().length();
							if(temp_description != null && len > 0){
								temp_description =replaceMsg(temp_description,Server.getServerNameWithoutPort(row[2], false),mappingInfo.getComponentTypeDescription(row[3]),site1,row[8],mappingInfo.getLayerDescription(layer),mappingInfo.getTestDescription(row[5]),custom_info,mappingInfo.getMeasureDescription(row[5],row[6]),"");
							}
						}
						if(temp_description == null || len == 0 || temp_description.startsWith(row[6]))
						{
							Hashtable alertParams = new Hashtable();
							alertParams.put("$componentType",mappingInfo.getComponentTypeDescription(row[3]));
							alertParams.put("$componentName",Server.getServerNameWithoutPort(row[2], false));
							 //temp_description = tablesInfo.getMeasureAlert(dec_key.toString(),row[4],thisLanguage);
							/*if(infosearch!=null && infosearch.equalsIgnoreCase("+"))
							{
								temp_description = mappingInfo.getMeasureAlert(dec_key.toString());
							}
							else
							{
								temp_description = mappingInfo.getMeasureAlert(dec_key.toString()) + "{"+row[4]+"}";
							}*/
							 //temp_description = mappingInfo.getMeasureAlert(dec_key.toString());
							 if(infosearch!=null && !infosearch.equals("+") && !infosearch.equals("")){
								 if(row[4]!=null && row[4].trim().length()>1){
									if(row[4].startsWith("+"))
										alertParams.put("$info",row[4].substring(1));
									else
										alertParams.put("$info",row[4]);
								}
							 }
							 alertParams.put("hasVMs",hasVMs);
							 temp_description = mappingInfo.getMeasureAlert(dec_key.toString(),alertParams);
							 boolean infoAdded = false;
							 if(temp_description.indexOf("~!~") != -1){
								infoAdded = Boolean.parseBoolean(temp_description.substring(temp_description.indexOf("~!~")+3));
								temp_description = temp_description.substring(0,temp_description.indexOf("~!~"));
							 }
							 temp_description = temp_description+"$info$"+row[4];
							 if(temp_description != null && !infoAdded && row[4]!=null && row[4].trim().length()>1)
								 temp_description += "{"+row[4]+"}";
						}
					}
					//end
					if(infosearch!=null && infosearch.trim().length()>0 && !StringUtils.isNull(infosearch))
					{
						infosearch=infosearch.toLowerCase();
						temp_description=temp_description.toLowerCase();
						if (temp_description!=null && temp_description.indexOf(infosearch) >-1)
						{
							list.add((String[])row);
						}
					}
					String temp_measure=row[6];
					String temp_starttime=row[9];
					String temp_endtime=row[10];
					String temp_mhost=row[7];
					String temp_eventId=row[0];
					String temp_eventPriority=row[8];
					
				}
				
				//list.add(row);
			}
			//else
			//{
				/*
				 * Just the dump the row into the list
				 */
				//list.add(rs.getString(1));
			//}
		}

		return list;
	}
	//overloaded method for duration and not sortting
	public final List getEventHistAsList(ResultSet rs, List servers,long durationFilter,boolean hasVMs,MonitorUtility Monutil) throws SQLException
	{
		List list = new LinkedList();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		boolean lessThanZero =false;
		DateTimeTokenizer dt = new DateTimeTokenizer();
		if(durationFilter != 0)
		{
			lessThanZero = (durationFilter < 0);

			durationFilter = Math.abs(durationFilter);
			dt.setDateFormat(DateTimeTokenizer._YMD);
			dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
			dt.setTimeFormat(DateTimeTokenizer.HMS);
			dt.setYearAsYY(true);
		}
		while (rs.next())
		{
			if (count > 1)
			{
				String[] row = new String[count];
				for (int a = 0; a < count; a++)
				{
					row[a] = rs.getString(a + 1);
				}
				String ctypeName = row[3]+":"+row[2];
				if (!servers.contains(ctypeName))
				{
					continue; // not one of our servers
				}

				if(durationFilter != 0 && row.length>0 && row.length==count)
				{
					String start_time_value=row[9];//Start time
					String end_time_value=row[10];//End time
					
					StringBuffer value = new StringBuffer();
					if(start_time_value!=null && start_time_value.trim().length()>0)
					{
						dt.setStartDateTime((String)start_time_value);
						value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
						value.append(DateTimeTokenizer.BLANK_SPACE);
						value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
						start_time_value = value.toString();
					}
					
					value = new StringBuffer();
					
					if ((end_time_value != null) && (end_time_value.trim().length()>0) && (end_time_value.indexOf("1900") == -1))
					{
						dt.setEndDateTime(end_time_value);
						long tDiff = dt.getDateDifference();
						
						if (lessThanZero)
						{
							if(tDiff<durationFilter)
							{
								list.add(row);
							}
						}
						else
						{
							if(tDiff>durationFilter)
							{
								list.add(row);
							}
						}
					}
				}
				else
				{
					list.add(row);
				}
			}
			else
			{
				list.add(rs.getString(1));
			}
		}

		return list;
	}
	public final ArrayList getEventHistAsList(ResultSet rs,List servers,EgMappingInfo mappingInfo,boolean hasVMs,MonitorUtility Monutil) throws SQLException
	{
		List list = new LinkedList();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		ArrayList sortEvent=new ArrayList();
		while (rs.next())
		{
			if (count > 1)
			{
				
				String[] row = new String[count];
				for (int a = 0; a < count; a++)
				{
					row[a] = rs.getString(a + 1);
				}
				String ctypeName = row[3]+":"+row[2];
				if (!servers.contains(ctypeName))
				{
					continue; // not one of our servers
				}

				if(row.length>0 && row.length==count)
				{
					EgAlarmsBean eab=new EgAlarmsBean();
					
					String temp_compType=row[3];
					eab.setRealCompType(temp_compType);
					eab.setCompType(mappingInfo.getComponentTypeDescription(temp_compType));
					
					String temp_compName=row[2];
					eab.setRealCompName(temp_compName);
					eab.setCompName(temp_compName);
					
					String temp_siteName=row[1];
					eab.setRealCompSite(temp_siteName);
					eab.setCompSite(temp_siteName);
					
					String temp_testName=row[5];
					eab.setRealCompTest(temp_testName);
					eab.setCompTest(mappingInfo.getTestDescription(temp_testName));
					
					String temp_info=row[4];
					eab.setInfo(temp_info);
					
					StringBuffer dec_key = new StringBuffer();
					dec_key.append(row[5]);
					dec_key.append(EgConstants.COLON);
					dec_key.append(row[6]);
					//start
					String temp_description ="";
					int len = 0;
					if(temp_compType!=null && temp_compType.endsWith("_ex"))
					{
						temp_description = tablesInfo.getMeasureAlert(dec_key.toString(),row[4],thisLanguage);
					}
					else
					{
						//temp_description = mappingInfo.getMeasureAlert(dec_key.toString());
						//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
						//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
						if(isCustomAlertMessages)
						{
							String custom_info=row[4];
							String site1=row[1];
							if(StringUtils.isNull(site1))
								site1="NONE";
							if(row[4]!=null && row[4].length()>1 && row[4].startsWith("+"))
							{
								custom_info=row[4].substring(1);
							}
							String layer=dashboardDAO.getLayerForTest(row[3],row[5],row[6]);
							temp_description = tablesInfo.getCustomMeasureAlert(dec_key.toString(), row[4],thisLanguage);
							len = temp_description.trim().length();
							if(temp_description != null && len > 0){
								temp_description =replaceMsg(temp_description,Server.getServerNameWithoutPort(row[2], false),mappingInfo.getComponentTypeDescription(row[3]),site1,row[8],mappingInfo.getLayerDescription(layer),mappingInfo.getTestDescription(row[5]),custom_info,mappingInfo.getMeasureDescription(row[5],row[6]),"");
							}
						}
						if(temp_description == null || len == 0 || temp_description.startsWith(row[6]))
						{
							Hashtable alertParams = new Hashtable();
							alertParams.put("$componentType",mappingInfo.getComponentTypeDescription(row[3]));
							alertParams.put("$componentName",Server.getServerNameWithoutPort(row[2], false));
							if(row[4]!=null && row[4].trim().length()>1){
								if(row[4].startsWith("+"))
									alertParams.put("$info",row[4].substring(1));
								else
									alertParams.put("$info",row[4]);
							}
							alertParams.put("hasVMs",hasVMs);
							 temp_description = tablesInfo.getMeasureAlert(dec_key.toString(),row[4],thisLanguage,alertParams);
							 temp_description = (temp_description.indexOf("~!~") != -1)?temp_description.substring(0,temp_description.indexOf("~!~")):temp_description;
							 temp_description = temp_description+"$info$"+row[4]; 
						}
					}
					//end
					
					eab.setRealAlarmDesc(temp_description);
					eab.setAlarmDesc(temp_description);

					String temp_measure=row[6];
					eab.setRealMeasure(temp_measure);
					eab.setMeasure(mappingInfo.getMeasureDescription(temp_testName,temp_measure));

					String temp_starttime=row[9];
					eab.setStartTime(temp_starttime);

					String temp_endtime=row[10];
					eab.setEndTime(temp_endtime);

					String temp_mhost=row[7];
					eab.setMeasurementHost(temp_mhost);
					
					String temp_eventId=row[0];
					eab.setAlarmId(temp_eventId);
				
					String temp_eventPriority=row[8];
					eab.setAlarmPriority(temp_eventPriority);
					sortEvent.add(eab);
				}
				list.add(row);
			}
			else
			{
				
				list.add(rs.getString(1));
			}
		}

		return sortEvent;
	}
	//over loaded method for durations and sortting
	public final ArrayList getEventHistAsList(ResultSet rs,List servers,EgMappingInfo mappingInfo,long durationFilter,boolean hasVMs,MonitorUtility Monutil) throws SQLException
	{
		List list = new LinkedList();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		ArrayList sortEvent=new ArrayList();
		boolean lessThanZero =false;
		DateTimeTokenizer dt = new DateTimeTokenizer();
		if(durationFilter != 0)
		{
			lessThanZero = (durationFilter < 0);
			durationFilter = Math.abs(durationFilter);
			dt.setDateFormat(DateTimeTokenizer._YMD);
			dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
			dt.setTimeFormat(DateTimeTokenizer.HMS);
			dt.setYearAsYY(true);
		}
		while (rs.next())
		{
			if (count > 1)
			{
				String[] row = new String[count];
				for (int a = 0; a < count; a++)
				{
					row[a] = rs.getString(a + 1);
				}
				String ctypeName = row[3]+":"+row[2];
				if (!servers.contains(ctypeName))
				{
					continue; // not one of our servers
				}
				boolean isTrue=false;
				if(durationFilter != 0 && row.length>0 && row.length==count)
				{
					String start_time_value=row[9];//Start time
					String end_time_value=row[10];//End time
					
					StringBuffer value = new StringBuffer();
					if(start_time_value!=null && start_time_value.trim().length()>0)
					{
						dt.setStartDateTime((String)start_time_value);
						value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
						value.append(DateTimeTokenizer.BLANK_SPACE);
						value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
						start_time_value = value.toString();
					}
					value = new StringBuffer();
					
					if ((end_time_value != null) && (end_time_value.trim().length()>0) && (end_time_value.indexOf("1900") == -1))
					{
						dt.setEndDateTime(end_time_value);
						long tDiff = dt.getDateDifference();
						
						if (lessThanZero)
						{
							if(tDiff<durationFilter)
							{
								isTrue=true;
							}
						}
						else
						{
							if(tDiff>durationFilter)
							{
								isTrue=true;
							}
						}
					}
				}
				else
				{
					isTrue=true;
				}

				if(isTrue)
				{
					if(row.length>0 && row.length==count)
					{
						EgAlarmsBean eab=new EgAlarmsBean();
						
						String temp_compType=row[3];
						eab.setRealCompType(temp_compType);
						eab.setCompType(mappingInfo.getComponentTypeDescription(temp_compType));
						
						String temp_compName=row[2];
						eab.setRealCompName(temp_compName);
						eab.setCompName(temp_compName);
						
						String temp_siteName=row[1];
						eab.setRealCompSite(temp_siteName);
						eab.setCompSite(temp_siteName);
						
						String temp_testName=row[5];
						eab.setRealCompTest(temp_testName);
						eab.setCompTest(mappingInfo.getTestDescription(temp_testName));
						
						String temp_info=row[4];
						eab.setInfo(temp_info);
						
						StringBuffer dec_key = new StringBuffer();
						dec_key.append(row[5]);
						dec_key.append(EgConstants.COLON);
						dec_key.append(row[6]);
						//start
						int len = 0;
						String temp_description ="";
						if(temp_compType!=null && temp_compType.endsWith("_ex"))
						{
							temp_description = tablesInfo.getMeasureAlert(dec_key.toString(),row[4],thisLanguage);
						}
						else
						{
							//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
							//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
							if(isCustomAlertMessages)
							{
								String custom_info=row[4];
								String site1=row[1];
								if(StringUtils.isNull(site1))
									site1="NONE";
								if(row[4]!=null && row[4].length()>1 && row[4].startsWith("+"))
								{
									custom_info=row[4].substring(1);
								}
								String layer=dashboardDAO.getLayerForTest(row[3],row[5],row[6]);
								temp_description = mappingInfo.getCustomMeasureAlert(dec_key.toString());
								len = temp_description.trim().length();
								if(temp_description != null && len > 0){
									temp_description =replaceMsg(temp_description,Server.getServerNameWithoutPort(row[2], false),mappingInfo.getComponentTypeDescription(row[3]),site1,row[8],mappingInfo.getLayerDescription(layer),mappingInfo.getTestDescription(row[5]),custom_info,mappingInfo.getMeasureDescription(row[5],row[6]),"");
								}
							}
							if(temp_description == null || len == 0)
							{
								Hashtable alertParams = new Hashtable();
								alertParams.put("$componentType",mappingInfo.getComponentTypeDescription(row[3]));
								alertParams.put("$componentName",Server.getServerNameWithoutPort(row[2], false));
								if(row[4]!=null && row[4].trim().length()>1){
									if(row[4].startsWith("+"))
										alertParams.put("$info",row[4].substring(1));
									else
										alertParams.put("$info",row[4]);
								}
								alertParams.put("hasVMs",hasVMs);
								 temp_description =  mappingInfo.getMeasureAlert(dec_key.toString(),alertParams);
								 temp_description = (temp_description.indexOf("~!~") != -1)?temp_description.substring(0,temp_description.indexOf("~!~")):temp_description;
								 temp_description = temp_description+"$info$"+row[4];
							}
						}
						//end
						
						eab.setRealAlarmDesc(temp_description);
						eab.setAlarmDesc(temp_description);

						String temp_measure=row[6];
						eab.setRealMeasure(temp_measure);
						eab.setMeasure(mappingInfo.getMeasureDescription(temp_testName,temp_measure));

						String temp_starttime=row[9];
						eab.setStartTime(temp_starttime);

						String temp_endtime=row[10];
						eab.setEndTime(temp_endtime);

						String temp_mhost=row[7];
						eab.setMeasurementHost(temp_mhost);
						
						String temp_eventId=row[0];
						eab.setAlarmId(temp_eventId);
					
						String temp_eventPriority=row[8];
						eab.setAlarmPriority(temp_eventPriority);
						sortEvent.add(eab);
					}
					list.add(row);
				}
			}
			else
			{
				list.add(rs.getString(1));
			}
		}
		return sortEvent;
	}

	public Hashtable putAcknowledgeDetails(String eventid) throws SQLException
	{
		String user_id = "";
		String ack_time = "";
		String ack_desc = "";
		String option = "";

		ArrayList al_ackDetails = new ArrayList();
		ArrayList al_singleackDetails = new ArrayList();
		ArrayList al_multiackDetails = new ArrayList();
		
		Hashtable htable = new Hashtable();
		String status = "";
		ResultSet rs2 = null;
		EgDbAdapterUI egDb = EgDbAdapterTypeUI.getObject();
		status = egDb.setConnection();

		try
		{
			if(EgInstallInfo.isSuperManager)
			{
				int idx = eventid.indexOf("#");
				String managerId = null;
				if(idx>-1)
				{
					managerId=eventid.substring(0,idx);
					eventid=eventid.substring(idx+1);
				}
				String res = "select * from acknowledgement_history where event_id ='"+eventid+"' order by ack_time desc";
				Hashtable ht = new Hashtable();
				ht.put("OracleQuery",res);
				ht.put("SqlQuery",res);
				if(managerId != null)
				{
					ArrayList managerIds = new ArrayList();
					managerIds.add(managerId);
					ht.put("special_case_mgr_ids",managerIds);
				}
				rs2=new EgSMDBHelper().getResultSet(ht);
			}
			else
			{
				String res = "select * from acknowledgement_history where event_id ='"+eventid+"' order by ack_time desc";
				rs2 = egDb.dbselect(res);
			}
			if(rs2!=null)
			{
				while (rs2.next())
				{
					al_ackDetails=new ArrayList();
					
					user_id = rs2.getString("user_id");
					al_ackDetails.add(user_id);
					
					ack_desc = rs2.getString("ack_description");
					al_ackDetails.add(ack_desc);

					option = rs2.getString("options");
					al_ackDetails.add(option);
					
					ack_time = rs2.getString("ack_time");
					al_ackDetails.add(ack_time);
					
					if(htable.containsKey(eventid))
					{
						al_multiackDetails.add(al_ackDetails);
						htable.put(eventid, al_multiackDetails);
					}
					else
					{
						al_singleackDetails.add(al_ackDetails);
						htable.put(eventid, al_singleackDetails);
						al_multiackDetails.add(al_ackDetails);
					}
				}
			}
			if(rs2!=null)
			{
				rs2.close();
			}
			rs2=null;
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}

		catch(SQLException e)
		{
			e.printStackTrace();
			try
			{
				if (rs2!=null)
				{
					rs2.close();
				}
				rs2=null;
			}
			catch (Exception ec)
			{
				ec.printStackTrace();
			}
			finally
			{
				egDb.releaseConnection(true);
				EgDbAdapterTypeUI.releaseObject(egDb);
			}
		}
		return (htable);
	}

	public void logToTmpFile(String type, String entity,String msg)
	{
		PrintWriter logWriter;
		if (!tmpLog)
		return;
		synchronized(syncVector)
		{
			EgDateInfo dateInfo = new EgDateInfo();
			String logDateAndTime = dateInfo.egetDate(false);
			try
			{
				logWriter = new PrintWriter(new FileWriter(tmpFile, true));
			}
			catch(Exception e)
			{
				System.err.println("Cannot open tmp log file ");
				return;
			}
			String log=new String(logDateAndTime+" "+type + " "+ entity + " "+ msg);
			logWriter.println(log);
			logWriter.flush();
			logWriter.close();
		}
	}
	private List getHostSystemServers(List listServers)
	{
		List returnServer = new LinkedList();
		if(listServers!=null && listServers.size() > 0)
		{
			for(int t=0; t < listServers.size() ;t++)
			{
				String s_host = (String)listServers.get(t);
				StringTokenizer tokens = new StringTokenizer(s_host,":");

				String type = tokens.nextToken();
				String comp = tokens.nextToken();
				String host_sys =  Server.getHostSystem(s_host,true);
				returnServer.add(s_host);
				if(host_sys!=null)
					returnServer.add(host_sys);
			}
		}
		returnServer = ListUtils.removeDuplicates(returnServer);
		return returnServer;
	}

	/**
	 * This method is used to substring the given string based on Lanugage in that string and also User Language.
	 *
	 * @author Saravanan.A
	 * @created 02 Feb, 2011
	 * @param-1 the given string(String)
	 * @param-2 flage variable for find User Language (boolean)
	 * @param-3 substring length for given string is have only English char(int)
	 * @param-4 substring length for given string is have non English char (int)
	 * @return string.
	 */

	public  String egSubString(String string, boolean isUserLanguageEnglish,int englishLen, int otherLen)
	{
		String format_string="";
		try
		{
			format_string=string;

			if(format_string!=null && format_string.trim().length()>0)
			{
				boolean isEnglish = true;
				int count = 0;
				int tempEnglishLen=englishLen;
				// --- This code for find the given string char is English Language or not---
				if(!isUserLanguageEnglish)
				{
					tempEnglishLen=tempEnglishLen-3;
					for (int x=0;x<format_string.length();x++)
					{
						Character.UnicodeBlock cu = Character.UnicodeBlock.of(format_string.charAt(x));
						if (!cu.equals(Character.UnicodeBlock.BASIC_LATIN))
						{
							isEnglish = false;
							count++;
							//break;
						}
					}
				}
				//--end---

				if(isEnglish)
				{
					// All char are English Language.
					// Check the string length and extra only one char , then skip the sustring
					if (format_string!=null && format_string.trim().length()>tempEnglishLen && format_string.trim().length()>(tempEnglishLen+1))
					{
						format_string=format_string.substring(0,tempEnglishLen)+"..";
					}
				}
				else
				{
					
					if(count==format_string.length())
					{
						// When all char are Other Language text.
						// check the string length and extra only one char , then skip the sustring
						if (format_string!=null && format_string.trim().length()>otherLen && format_string.trim().length()>(otherLen+1))
						{
							format_string=format_string.substring(0,otherLen)+"..";
						}
					}
					else
					{
						// When English and other Language char mixed text.
						// check the string length and extra only 6 char , then skip the sustring
						if (format_string!=null && format_string.trim().length()>(otherLen+5) && format_string.trim().length()>(otherLen+6))
						{
							format_string=format_string.substring(0,(otherLen+5))+"..";
						}
					}
				}
			}
		}
		catch(Exception e)
		{
			System.out.println("----- Exception in egSubString method in com.egurkha.util.StringUtils.java---------------");
			e.printStackTrace();
			return format_string;
		}

		return format_string;
	}
	//This method is called only for supermanager
	public List processResults(List list, int maxWidth,EgMappingInfo mappingInfo1, boolean hasVMs,MonitorUtility Monutil) 
	{
		List results = new LinkedList();
		int length = 0;
		int oldWidth = maxWidth;
		String nullStr = EgConstants.NULL_STRING.toUpperCase();
		DateTimeTokenizer dt = new DateTimeTokenizer();
		dt.setDateFormat(DateTimeTokenizer._YMD);
		dt.setDateSeparator(DateTimeTokenizer.HYPHEN_SEPARATOR);
		dt.setTimeFormat(DateTimeTokenizer.HMS);
		dt.setYearAsYY(true);
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		for (int z=0; z<list.size(); z++)
		{
			String[] values = (String[])list.get(z);
			String[] row = new String[values.length];
			System.arraycopy(values, 0, row, 0, row.length);
			int a = 0;
			//Site name
			if (StringUtils.isNull(row[2]) || row[2].equals(nullStr))
			{
				//-->row[a] = "NONE";
			}
			else
			{
				if (row[2].length() > maxWidth)
				{
					//row[a] = split(row[a], maxWidth);
				}
			}
			//a++;	//a = 2
			//Comp Name
			if (row[2].endsWith(EgConstants.NULL_PORT))
			{
				//-->row[a] = Server.getServerNameWithoutPort(row[a], false).trim();
			}
			if (row[2].length() > maxWidth)
			{
				//row[a] = mergeSplitStr(StringUtils.split(row[a], EgConstants.COLON));
				//row[a] = split(row[a], maxWidth);
			}
			//a++;	//a = 3 
			//Comp Type
			//a++;	// a = 4
			//Info
			StringBuffer key = new StringBuffer();
			String tmp_Test=row[6];
			String tmp_CmpName=row[3];
			String tmp_cmpType=row[4];
			if(tmp_CmpName != null && tmp_CmpName.endsWith(":NULL"))
				tmp_CmpName= tmp_CmpName.substring(0,tmp_CmpName.indexOf(":NULL"));
				
			key.append(row[6]);
			key.append(EgConstants.COLON);
			key.append(row[7]);
			String description ="";
			int len = 0;
			//MonitorDAOFactory	monitorDaoFactory1 = MonitorDAOFactory.getInstance();
			//EgServerDashBoardDAO dashboardDAO1=monitorDaoFactory1.getServerDashBoardDAO();
			if(isCustomAlertMessages)
			{
				String custom_info=row[5];
				String site1=row[2];
				if(StringUtils.isNull(site1))
					site1="NONE";
				if(row[5]!=null && row[5].length()>1 && row[5].startsWith("+"))
				{
					custom_info=row[5].substring(1);
				}
				
				String layer=dashboardDAO.getLayerForTest(row[4],row[6],row[7]);
				description = tablesInfo.getCustomMeasureAlert(key.toString(), row[5],thisLanguage);
				len = description.trim().length();
				if(description != null && len > 0){
					description =replaceMsg(description,Server.getServerNameWithoutPort(row[3], false),mappingInfo1.getComponentTypeDescription(row[4]),site1,mappingInfo1.getLabelDescription(row[9]),mappingInfo1.getLayerDescription(layer),mappingInfo1.getTestDescription(row[6]),custom_info,mappingInfo1.getMeasureDescription(row[6],row[7]),"");
				}
			}
			if(description == null || len == 0 || description.startsWith(row[7]))
			{
				Hashtable alertParams = new Hashtable();
				alertParams.put("$componentType",mappingInfo1.getComponentTypeDescription(row[4]));
				alertParams.put("$componentName",Server.getServerNameWithoutPort(row[3], false));
				if(row[5]!=null && row[5].trim().length()>1){
					if(row[5].startsWith("+"))
						alertParams.put("$info",row[5].substring(1));
					else
						alertParams.put("$info",row[5]);
				}
				alertParams.put("hasVMs",hasVMs);

				description = tablesInfo.getMeasureAlert(key.toString(), row[5],thisLanguage,alertParams)+"$info$"+row[5];
			}
			row[5] = description;


			a++;
			//Test name
			if (row[a].length() > maxWidth)
			{
				//String tagTest = langinfo.getValue("TEST_NAME_MAPPING",row[a]);
				/*if(tagTest != null && !tagTest.equals(""))
				{
					row[a] = tagTest;
				}*/
				//row[a] = split(row[a], maxWidth);
			}
			a++;
			//Measure
			//Ignored because it will be taken care of while displaying meaningful messages
			a++;
			//Start time
			StringBuffer value = new StringBuffer();
			dt.setStartDateTime((String)row[10]);
			value.append(dt.getStartDateAsFormat(DateTimeTokenizer.MDY, DateTimeTokenizer.SLASH_SEPARATOR));
			value.append(DateTimeTokenizer.BLANK_SPACE);
			value.append(dt.getStartTimeAsFormat(DateTimeTokenizer.HM, DateTimeTokenizer.COLON_SEPARATOR));
			row[10] = value.toString();
			a++;
			//End time
			String temp = row[11];
			value = new StringBuffer();
			if ((row[11] != null) && (row[11].indexOf("1900") == -1))
			{
				dt.setEndDateTime(row[11]);
				long tDiff = dt.getDateDifference();
				value.append(tDiff);
			}
			else
			{
				java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				sdf.setTimeZone(EgDateInfo.getRealTimeZone());
				java.util.Date today = new java.util.Date((new EgDateInfo()).egetUTCDate());
				dt.setEndDateTime(sdf.format(today));
				value.append("-");
				value.append(dt.getDateDifference());
			}
			row[11] = value.toString();
			results.add(row);
		}
		return results;
	}
	String getMeasureAlert(String s, String info,EgMappingInfo mappingInfo)
	{
		StringBuffer alertMsg = new StringBuffer();
		alertMsg.append(s);
		if (info.startsWith("+"))
		{
			info = info.substring(1);
		}
		if (info.length() > 0)
		{
			alertMsg.append(" {");
			alertMsg.append(info);
			alertMsg.append("}");
		}
		return alertMsg.toString();
	}

	public List getAlarmHistory(
		List servers,
		String serverNames,
		String serverTypes,
		String fromTime,
		String toTime,
		String eventID,
		long durationFilter,
		String state,
		EgDbAdapterUI egDb,EgMappingInfo mappingInfo,LangInfo langinfo,String selectedArrangeOption,String infosearch,List userCompList,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List vmUserCompList,String s_event,int startIndex,int endIndex,int evtPerPage,String alertTest,MonitorUtility Monutil)
	{
		if(EgInstallInfo.isSuperManager)
		{
			SmSessionData smsData = new SmSessionData(currentSessionId);
			EgThreadLocal egtl = new EgThreadLocal();
			egtl.set(smsData);
			new SMDateTimeConverter("MM/dd/yyyy HH:mm",fromTime,toTime);
		}
		EgUserRole userRole = user.getUserRole();
		boolean isAllCompnt = userRole.hasAllComponentAccess();
		String comp_name_search="";
		if(infosearch!=null && infosearch.trim().length()>0 && infosearch.indexOf("^egsep^")>0)
		{
			ArrayList emptyColumnsList =  com.egurkha.util.StringUtils.egTokenizer(infosearch, "^egsep^",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			if(emptyColumnsList!=null && emptyColumnsList.size()>=2)
			{
				infosearch=(String)emptyColumnsList.get(0);
				if(infosearch!=null)
					infosearch=infosearch.trim();
				comp_name_search=(String)emptyColumnsList.get(1);
				if(comp_name_search!=null)
					comp_name_search=comp_name_search.trim();
			}
		}

		EgDateInfo dateInfo = new EgDateInfo();
		StringBuffer query = new StringBuffer(320);
		StringBuffer ora_query = new StringBuffer(320);
		StringBuffer sql_query = new StringBuffer(320);
		StringBuffer sb_time =new StringBuffer();
		List result = new LinkedList();
		//selectedArrangeOption = "-1";	
		boolean isArrangeOpt = false;		
		if(selectedArrangeOption.equalsIgnoreCase("-1") || selectedArrangeOption.equalsIgnoreCase("comp_name"))
			isArrangeOpt = true;	
		if(infosearch!=null && !infosearch.equalsIgnoreCase("null") && !infosearch.trim().equals("")) 
		{			
			isArrangeOpt = false;
		}
		
		if(hasVMs)
			isArrangeOpt = false;

		//TODO Check the date format for compatibility
		if (servers.isEmpty())
		{
			if(isArrangeOpt)
				query.append("SELECT * FROM(");

			query.append(
			"SELECT ALARM_ID,COMP_NAME,COMP_TYPE,LAYER_NAME,SERVICE,ZONE,SEGMENT,PROBLEM_DESC,PRIORITY,START_TIME,END_TIME");

			
			if(selectedArrangeOption.equalsIgnoreCase("comp_name"))
				query.append(",ROW_NUMBER() OVER (ORDER BY COMP_NAME,START_TIME DESC) as r");
			else if(isArrangeOpt)
				query.append(",ROW_NUMBER() OVER (ORDER BY START_TIME DESC) as r");

			query.append(" FROM alarm_hist_summary WHERE ");

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  PRIORITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  PRIORITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			sb_time.append("ALARM_ID > ' ' AND ");
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				query.append("  lower(COMP_NAME) like ('%");
				query.append(comp_name_search.toLowerCase());
				query.append("%')");
				query.append(" AND ");
				
			}
			if(alertTest != null && alertTest.trim().length() > 0 && !alertTest.equalsIgnoreCase("null")){
				query.append("PROBLEM_DESC like '%"+alertTest+"%' AND ");
			}
			ora_query.append(query);
			sql_query.append(query);
			if (EgInstallInfo.isSuperManager)
			{
				StringBuffer ora_sb_time = new StringBuffer();
				StringBuffer sql_sb_time = new StringBuffer();
				ora_sb_time.append(sb_time);
				sql_sb_time.append(sb_time);
				if(isFromInsideviewDashboard)
				{
					ora_sb_time.append(" START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					query.append(sql_sb_time);
					
				}
				else
				{
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(END_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(");
					ora_sb_time.append(" (START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME >= to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(")) OR ");
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME = to_date('");
					ora_sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					ora_sb_time.append("))) ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME >= convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME = convert(datetime,'");
					sql_sb_time.append("01/01/1900 00:00");
					sql_sb_time.append("',101)))) ");
					sql_query.append(sql_sb_time);
				}
			}
			else if (EgDbInfo.isOraAdapter)
			{
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					query.append(sb_time);
					
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append(" (START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(")) OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = to_date('");
					sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					sb_time.append("))) ");
					query.append(sb_time);
				}
			}
			else
			{
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					query.append(sb_time);
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101)) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = convert(datetime,'");
					sb_time.append("01/01/1900 00:00");
					sb_time.append("',101)))) ");
					query.append(sb_time);
				}
			}

			if(durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				if (lessThanZero)
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");

						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
			}

			if(!isArrangeOpt)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" ORDER BY START_TIME DESC");
					sql_query.append(" ORDER BY START_TIME DESC");
				}
				else
				{
					query.append(" ORDER BY START_TIME DESC");
				}
			}
			else
			{
				if(EgInstallInfo.isSuperManager)
				{
					if(startIndex==1)
					{
						ora_query.append(") where r>="+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						ora_query.append(") where r>"+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>"+startIndex+" and r<="+endIndex);
					}
				}
				else if(EgDbInfo.isOraAdapter)
				{
					if(startIndex==1)
						query.append(") where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(") where r>"+startIndex+" and r<="+endIndex);
				}
				else
				{
					if(startIndex==1)
						query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					else
						query.append(")as s where r>"+startIndex+" and r<="+endIndex);
				}
			}
			//System.out.println("getAlarmHistory-----query----->"+query);
			logToTmpFile("INFO","","Query for Alarm history is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				rs = egDb.dbselect(qry);
				ArrayList sortEvent=new ArrayList();
				if(isArrangeOpt)
					result= (List)egDb.getAlarmHistoryResultSetAsList(rs,true);
				else
					result= (List)egDb.getAlarmHistoryResultSetAsList(rs,false);

				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}

				if(!userRole.hasAllComponentAccess())
				{
					logToTmpFile("INFO","","ALARM HIST TABLE>>> showAll ... b4 calling getalarm as list " + showAll);
					List result_temp = (LinkedList)result;
					result = (List)getAlarmHistAsList(result_temp, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
				}

				
				if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
				{
					if(sortEvent!=null && sortEvent.size()>0)
					{
						int arrCnt = 11;
						if(hasVMs)
						{
							arrCnt = 12;
						}
						if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
						{
							EgAlarmComparator.compareValue=3;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}

								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							EgAlarmComparator.compareValue=2;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];
								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
					
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							if(hasVMs)
							{
								if(user.isOnlyVMAssigned() && !user.isVMAssigned())
								{
									EgAlarmComparator.compareValue=7;
									
								}
								else
								{
									//EgAlarmComparator.compareValue=8;
									EgAlarmComparator.compareValue=1;
								}
							}
							else
							{
							EgAlarmComparator.compareValue=1;
							}
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Service"))
						{
							EgAlarmComparator.compareValue=6;
							Collections.sort(sortEvent,new EgAlarmComparator());

							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Test"))
						{
							EgAlarmComparator.compareValue=5;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
					}
					//end here
				}
				if (result != null && result.size()>0)
				{
					if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
					{
						result = getDescriptionSearch(result,infosearch,hasVMs,Monutil);
						infoSearchCount.put(infoRandom,new Integer(result.size()));
					}
				}

				if(hasVMs)
				{
					infoSearchCount.put(infoRandom,new Integer(result.size()));
				}
				if(!isArrangeOpt){
					
					if(endIndex>=(result.size()-1))
						result = result.subList((startIndex),(result.size()));
					else
						result = result.subList((startIndex),(endIndex));
				}
				return result;
			}
			catch (Exception jpm)
			{
				logToTmpFile("INFO","","Error "+jpm.toString());
				jpm.printStackTrace();
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return null;
			}
		}
		else
		{
			if(isArrangeOpt)
				query.append("SELECT * FROM(");
			
			
			query.append(
			"SELECT ALARM_ID,COMP_NAME,COMP_TYPE,LAYER_NAME,SERVICE,ZONE,SEGMENT,PROBLEM_DESC,PRIORITY,START_TIME,END_TIME");

			if(selectedArrangeOption.equalsIgnoreCase("comp_name"))
				query.append(",ROW_NUMBER() OVER (ORDER BY COMP_NAME,START_TIME DESC) as r");
			else if(isArrangeOpt)
				query.append(",ROW_NUMBER() OVER (ORDER BY START_TIME DESC) as r");
			query.append(" FROM alarm_hist_summary WHERE ");

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  PRIORITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  PRIORITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			query.append("ALARM_ID > ' ' AND ");
			if(alertTest != null && alertTest.trim().length() > 0 && !alertTest.equalsIgnoreCase("null")){
				query.append("PROBLEM_DESC like '%"+alertTest+"%' AND ");
			}
			ora_query.append(query);
			sql_query.append(query);
			if (serverNames.length()==0)
			{
				// filter based on comp_type
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(" COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(")");

					sql_query.append(" COMP_TYPE IN (");
					sql_query.append(serverTypes);
					sql_query.append(")");

					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						ora_query.append("  lower(COMP_NAME) like ('%");
						ora_query.append(comp_name_search.toLowerCase());
						ora_query.append("%')");

						sql_query.append("  lower(COMP_NAME) like ('%");
						sql_query.append(comp_name_search.toLowerCase());
						sql_query.append("%')");

						ora_query.append(" AND ");
						sql_query.append(" AND ");
						
					}
					else
					{
							ora_query.append("COMP_NAME>' ' AND "); 
							sql_query.append("COMP_NAME>' ' AND ");
					}
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
					}
					else
					{
						ora_query.append("	((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append(" END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
						sql_query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and ");
					}
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						query.append("  lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%')");
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") AND ");	
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") AND "); 
							}
							else{
								query.append("COMP_NAME>' ' AND "); 
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append("	((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append(" END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and ");	
					}
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						query.append("  lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%')");
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") AND ");	
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append(" COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") AND "); 
							}
							else{
								query.append("COMP_NAME>' ' AND "); 
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
					}
					else
					{
						query.append(" ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
						query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			else 
			{
				// filter based on comp_name 
				if (EgInstallInfo.isSuperManager)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						ora_query.append(" COMP_NAME IN (");
						ora_query.append(serverNames);
						ora_query.append(") and ");
						sql_query.append(" COMP_NAME IN (");
						sql_query.append(serverNames);
						sql_query.append(") ");
					}
					ora_query.append("COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(") and ");
					sql_query.append("COMP_TYPE IN(");
					sql_query.append(serverTypes);
					sql_query.append(") ");

					if(isFromInsideviewDashboard)
					{
						ora_query.append(" and START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" and START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)");
					}
					else
					{
						ora_query.append(" and ((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" and ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append(" COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN (");
					query.append(serverTypes);
					query.append(") ");
		
					if(isFromInsideviewDashboard)
					{
						query.append(" and START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append(" and ((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append(" COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN(");
					query.append(serverTypes);
					query.append(")");
			
					if(isFromInsideviewDashboard)
					{
						query.append(" and START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)");
					}
					else
					{
						query.append(" and ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			if (durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				if (lessThanZero)
				{
					durationFilter = Math.abs(durationFilter);
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");

					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");

					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
			}
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" AND lower(COMP_NAME) like ('%");
					ora_query.append(comp_name_search.toLowerCase());
					ora_query.append("%')");

					sql_query.append(" AND lower(COMP_NAME) like ('%");
					sql_query.append(comp_name_search.toLowerCase());
					sql_query.append("%')");
				}
				else
				{
					query.append(" AND lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
			}
			if(!isArrangeOpt)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" ORDER BY START_TIME DESC");
					sql_query.append(" ORDER BY START_TIME DESC");
				}
				else
				{
					query.append(" ORDER BY START_TIME DESC");
				}
			}
			else
			{
				if(EgInstallInfo.isSuperManager)
				{
					if(startIndex==1)
					{
						ora_query.append(") where r>="+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						ora_query.append(") where r>"+startIndex+" and r<="+endIndex);
						sql_query.append(")as s where r>"+startIndex+" and r<="+endIndex);
					}
				}
				else if(EgDbInfo.isOraAdapter)
				{
					if(startIndex==1)
					{
						query.append(") where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						query.append(") where r>"+startIndex+" and r<="+endIndex);
					}
				}
				else
				{
					if(startIndex==1)
					{
						query.append(")as s where r>="+startIndex+" and r<="+endIndex);
					}
					else
					{
						query.append(")as s where r>"+startIndex+" and r<="+endIndex);
					}
				}
			}
			logToTmpFile("INFO","","Query for Alarm history2 is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(query);
					sql_query.append(query);
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				rs = egDb.dbselect(qry);
				ArrayList sortEvent=new ArrayList();
				if(isArrangeOpt)
					result = (List)egDb.getAlarmHistoryResultSetAsList(rs,true);
				else
					result = (List)egDb.getAlarmHistoryResultSetAsList(rs,false);

				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}

				if(result != null && result.size() > 0)
				{
					List result_temp = (LinkedList)result;
					result = (List)getAlarmHistAsList(result_temp, servers,showAll,hasVMs,user,selectedCompType,selectedCompName,showAllTypes,showAllComps,userCompList);
				}

				if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && !isArrangeOpt)
				{
					int arrCnt =11;
					if(hasVMs)
					{
						arrCnt = 12;
					}
					//here start thendral
					if(sortEvent!=null && sortEvent.size()>0)
					{
						if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("problem_desc"))
						{
							EgAlarmComparator.compareValue=3;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							
							EgAlarmComparator.compareValue=2;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("comp_name"))
						{
							if(hasVMs)
							{
								if(user.isOnlyVMAssigned() && !user.isVMAssigned())
								{
									EgAlarmComparator.compareValue=7;
								}
								else
								{
									//EgAlarmComparator.compareValue=8;
									EgAlarmComparator.compareValue=1;
								}
							}
							else
							{
							EgAlarmComparator.compareValue=1;
							}
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Service"))
						{
							EgAlarmComparator.compareValue=6;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
						else if(selectedArrangeOption!=null && selectedArrangeOption.trim().length()>0 && selectedArrangeOption.trim().equalsIgnoreCase("Test"))
						{
							EgAlarmComparator.compareValue=5;
							Collections.sort(sortEvent,new EgAlarmComparator());
							result.clear();
							for (int i=0;i<sortEvent.size();i++)
							{
								EgAlarmsBean obj=(EgAlarmsBean)sortEvent.get(i);
								String temp_str[]=new String[arrCnt];

								temp_str[0]=obj.getAlarmId();
								temp_str[1]=obj.getRealCompSite();
								temp_str[2]=obj.getRealCompName();
								temp_str[3]=obj.getRealCompType();
								temp_str[4]=obj.getInfo();
								temp_str[5]=obj.getRealCompTest();
								
								temp_str[6]=obj.getRealMeasure();
								temp_str[7]=obj.getMeasurementHost();
								temp_str[8]=obj.getAlarmPriority();
								temp_str[9]=obj.getStartTime();
								temp_str[10]=obj.getEndTime();
								if(hasVMs)
								{
									temp_str[11]=obj.getRealVMInfo();
								}
								result.add((String[])temp_str);
							}
						}
					}
					//here end thendral
				}
				if (result != null && result.size()>0)
				{
					if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
					{
						result = getDescriptionSearch(result,infosearch,hasVMs,Monutil);
						infoSearchCount.put(infoRandom,new Integer(result.size()));
					}
				}

				if(hasVMs)
				{
					infoSearchCount.put(infoRandom,new Integer(result.size()));
				}
			
				if(!isArrangeOpt)
				{
					if(endIndex>=(result.size()-1))
							result = result.subList((startIndex),(result.size()));
						else
							result = result.subList((startIndex),(endIndex));
				}
				return result;
			}
			catch (Exception chasegrrr)
			{
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return null;
			}
		}
	}

	public int getAlarmHistoryCount(
		List servers,
		String serverNames,
		String serverTypes,
		String fromTime,
		String toTime,
		String eventID,
		long durationFilter,
		String state,
		EgDbAdapterUI egDb,EgMappingInfo mappingInfo,LangInfo langinfo,String selectedArrangeOption,String infosearch,List userCompList,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List vmUserCompList,String s_event,int startIndex,int endIndex,String alertTest)
	{
		int recCount = 0;
		if(EgInstallInfo.isSuperManager)
		{
			SmSessionData smsData = new SmSessionData(currentSessionId);
			EgThreadLocal egtl = new EgThreadLocal();
			egtl.set(smsData);
			new SMDateTimeConverter("MM/dd/yyyy HH:mm",fromTime,toTime);
		}

		EgUserRole userRole = user.getUserRole();
		boolean isAllCompnt = userRole.hasAllComponentAccess();
		String comp_name_search="";
		if(infosearch!=null && infosearch.trim().length()>0 && infosearch.indexOf("^egsep^")>0)
		{
			ArrayList emptyColumnsList =  com.egurkha.util.StringUtils.egTokenizer(infosearch, "^egsep^",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			if(emptyColumnsList!=null && emptyColumnsList.size()>=2)
			{
				infosearch=(String)emptyColumnsList.get(0);
				if(infosearch!=null)
					infosearch=infosearch.trim();
				comp_name_search=(String)emptyColumnsList.get(1);
				if(comp_name_search!=null)
					comp_name_search=comp_name_search.trim();
			}
		}


	
		if(infosearch!=null && infosearch.trim().length()>0 && !infosearch.equals("null") && !infosearch.equals(""))
		{
		
			Integer infoCount = (Integer)infoSearchCount.get(infoRandom);	
			recCount =infoCount.intValue();
			infoSearchCount.remove(infoRandom);
			return recCount;
			//infoSearchCount.put(,new Integer(result.size()));
		}
	

		if(hasVMs)
		{		
			Integer infoCount = (Integer)infoSearchCount.get(infoRandom);	
			recCount =infoCount.intValue();
			infoSearchCount.remove(infoRandom);		
			return recCount;
		}


		EgDateInfo dateInfo = new EgDateInfo();
		StringBuffer query = new StringBuffer(320);
		StringBuffer ora_query = new StringBuffer(320);
		StringBuffer sql_query = new StringBuffer(320);
		StringBuffer sb_time =new StringBuffer();
		List result = new LinkedList();
		//TODO Check the date format for compatibility
		if (servers.isEmpty())
		{

			
			query.append("SELECT count(*) as count FROM alarm_hist_summary WHERE ");

			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  PRIORITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  PRIORITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			sb_time.append("ALARM_ID > ' ' AND ");
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				query.append("  lower(COMP_NAME) like ('%");
				query.append(comp_name_search.toLowerCase());
				query.append("%')");
				query.append(" AND ");
				
			}
			if(alertTest != null && alertTest.trim().length() > 0 && !alertTest.equalsIgnoreCase("null")){
				query.append("PROBLEM_DESC like '%"+alertTest+"%' AND ");
			}
			ora_query.append(query);
			sql_query.append(query);
			if (EgInstallInfo.isSuperManager)
			{
				StringBuffer ora_sb_time = new StringBuffer();
				StringBuffer sql_sb_time = new StringBuffer();
				ora_sb_time.append(sb_time);
				sql_sb_time.append(sb_time);
				if(isFromInsideviewDashboard)
				{
					ora_sb_time.append(" START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					query.append(sql_sb_time);
					
				}
				else
				{
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(END_TIME BETWEEN to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(") OR ");
					ora_sb_time.append("(");
					ora_sb_time.append(" (START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME >= to_date('");
					ora_sb_time.append(toTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					ora_sb_time.append(")) OR ");
					ora_sb_time.append("(");
					ora_sb_time.append("(START_TIME <= to_date('");
					ora_sb_time.append(fromTime);
					ora_sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					ora_sb_time.append(" AND ");
					ora_sb_time.append("(END_TIME = to_date('");
					ora_sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					ora_sb_time.append("))) ");
					ora_query.append(ora_sb_time);

					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("', 101) AND convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME >= convert(datetime,'");
					sql_sb_time.append(toTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(") OR ");
					sql_sb_time.append("(");
					sql_sb_time.append("(START_TIME <= convert(datetime,'");
					sql_sb_time.append(fromTime);
					sql_sb_time.append("',101)) ");
					sql_sb_time.append(" AND ");
					sql_sb_time.append("(END_TIME = convert(datetime,'");
					sql_sb_time.append("01/01/1900 00:00");
					sql_sb_time.append("',101)))) ");
					sql_query.append(sql_sb_time);
				}
			}
			else if (EgDbInfo.isOraAdapter)
			{
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					query.append(sb_time);
					
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append(" (START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= to_date('");
					sb_time.append(toTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss') ");
					sb_time.append(")) OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= to_date('");
					sb_time.append(fromTime);
					sb_time.append("','mm/dd/yyyy hh24:mi:ss')) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = to_date('");
					sb_time.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
					sb_time.append("))) ");
					query.append(sb_time);
				}
			}
			else
			{
				if(isFromInsideviewDashboard)
				{
					sb_time.append(" START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					query.append(sb_time);
				}
				else
				{
					sb_time.append("(");
					sb_time.append("(START_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(END_TIME BETWEEN convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("', 101) AND convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME >= convert(datetime,'");
					sb_time.append(toTime);
					sb_time.append("',101)) ");
					sb_time.append(") OR ");
					sb_time.append("(");
					sb_time.append("(START_TIME <= convert(datetime,'");
					sb_time.append(fromTime);
					sb_time.append("',101)) ");
					sb_time.append(" AND ");
					sb_time.append("(END_TIME = convert(datetime,'");
					sb_time.append("01/01/1900 00:00");
					sb_time.append("',101)))) ");
					query.append(sb_time);
				}
			}

			if(durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				durationFilter = Math.abs(durationFilter);
				if (lessThanZero)
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");

						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME = to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME, END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");
					}
				}
			}
		
			//System.out.println("getAlarmHistoryCount------query--------->"+query);
			logToTmpFile("INFO","","Query for Count event history is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				
				rs = egDb.dbselect(qry);


				if(rs.next())
				{
					 recCount  = rs.getInt("count");
				}
				
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				return recCount;
			}
			catch (Exception jpm)
			{
				logToTmpFile("INFO","","Error "+jpm.toString());
				jpm.printStackTrace();
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return 0;
			}
		}
		else
		{
			
			query.append("SELECT COUNT(*) as count FROM alarm_hist_summary WHERE ");
			if(state!=null && !state.equals(""))
			{
				if(state.equals("HIGHINTERMEDIATE"))
				{
					query.append("  PRIORITY in('HIGH','INTERMEDIATE')");
				}
				else
				{
					query.append("  PRIORITY='");
					query.append(state);
					query.append("'");
				}
				query.append(" AND ");
			}
			query.append("ALARM_ID > ' ' AND ");
			if(alertTest != null && alertTest.trim().length() > 0 && !alertTest.equalsIgnoreCase("null")){
				query.append("PROBLEM_DESC like '%"+alertTest+"%' AND ");
			}
			ora_query.append(query);
			sql_query.append(query);
			if (serverNames.length()==0)
			{
				// filter based on comp_type
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(" COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(") and ");
					sql_query.append(" COMP_TYPE IN (");
					sql_query.append(serverTypes);
					sql_query.append(") and ");

					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						ora_query.append("  lower(COMP_NAME) like ('%");
						ora_query.append(comp_name_search.toLowerCase());
						ora_query.append("%')");
						sql_query.append("  lower(COMP_NAME) like ('%");
						sql_query.append(comp_name_search.toLowerCase());
						sql_query.append("%')");
						ora_query.append(" AND ");
						sql_query.append(" AND ");
						
					}
					else
					{
							ora_query.append("COMP_NAME>' ' AND "); 
							sql_query.append("COMP_NAME>' ' AND");
					}
					if(isFromInsideviewDashboard)
					{
						ora_query.append(" START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
					}
					else
					{
						ora_query.append("	((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append(" END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101) ");
						sql_query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101 ) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and ");
					}
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						query.append("  lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%')");
						query.append(" AND ");
						
					}
					else
					{
							if(!isAllCompnt)
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") AND ");
							}
							else
							{
								if((s_event!=null && !s_event.equalsIgnoreCase("NULL") && s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
								{
									query.append("COMP_NAME IN(");
									query.append(tmp_srvers);
									query.append(") AND "); 
								}
								else{
									query.append("COMP_NAME>' ' AND "); 
								} 
							}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append("	((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append(" END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(serverTypes != null && !serverTypes.equals(""))		// Prem
					{
						query.append(" COMP_TYPE IN (");
						query.append(serverTypes);
						query.append(") and ");	
					}
					if(comp_name_search!=null && comp_name_search.trim().length()>0)
					{
						query.append("  lower(COMP_NAME) like ('%");
						query.append(comp_name_search.toLowerCase());
						query.append("%')");
						query.append(" AND ");
						
					}
					else
					{
						if(!isAllCompnt)
						{
							query.append("COMP_NAME IN(");
							query.append(tmp_srvers);
							query.append(") AND ");
						}
						else
						{
							if((s_event!=null && !s_event.equalsIgnoreCase("NULL")&& s_event.trim().length()>0) && (s_event.equalsIgnoreCase("Service")||s_event.equalsIgnoreCase("Segment")||s_event.equalsIgnoreCase("Zone")))
							{
								query.append("COMP_NAME IN(");
								query.append(tmp_srvers);
								query.append(") AND "); 
							}
							else{
								query.append("COMP_NAME>' ' AND "); 
							}
						}
					}
					if(isFromInsideviewDashboard)
					{
						query.append(" START_TIME BETWEEN convert(datetime,'");
					query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
					}
					else
					{
						query.append(" ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101) ");
						query.append(") OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101 ) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			else 
			{
				// filter based on comp_name 
				if (EgInstallInfo.isSuperManager)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						ora_query.append("COMP_NAME IN (");
						ora_query.append(serverNames);
						ora_query.append(") and ");
						sql_query.append("COMP_NAME IN (");
						sql_query.append(serverNames);
						sql_query.append(") and ");
					}
					ora_query.append("COMP_TYPE IN (");
					ora_query.append(serverTypes);
					ora_query.append(")");
					sql_query.append("COMP_TYPE IN(");
					sql_query.append(serverTypes);
					sql_query.append(")");

					if(isFromInsideviewDashboard)
					{
						ora_query.append(" and START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						sql_query.append(" and START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)");
					}
					else
					{
						ora_query.append(" and ((START_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR (END_TIME BETWEEN to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						ora_query.append(" OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME >= to_date('");
						ora_query.append(toTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(") OR ");
						ora_query.append("(START_TIME <= to_date('");
						ora_query.append(fromTime);
						ora_query.append("','mm/dd/yyyy hh24:mi:ss') ");
						ora_query.append(" AND ");
						ora_query.append("END_TIME = to_date('");
						ora_query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						ora_query.append(")) ");

						sql_query.append(" and ((START_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101) AND convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME >= convert(datetime,'");
						sql_query.append(toTime);
						sql_query.append("',101)) ");
						sql_query.append(") OR ");
						sql_query.append("(");
						sql_query.append("(START_TIME <= convert(datetime,'");
						sql_query.append(fromTime);
						sql_query.append("',101)) ");
						sql_query.append(" AND ");
						sql_query.append("(END_TIME = convert(datetime,'");
						sql_query.append("01/01/1900 00:00");
						sql_query.append("',101)))) ");
					}
				}
				else if (EgDbInfo.isOraAdapter)
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append(" COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN (");
					query.append(serverTypes);
					query.append(")");
		
					if(isFromInsideviewDashboard)
					{
						query.append(" and START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
					}
					else
					{
						query.append(" and ((START_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR (END_TIME BETWEEN to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') AND to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss')) ");
						query.append(" OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME >= to_date('");
						query.append(toTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(") OR ");
						query.append("(START_TIME <= to_date('");
						query.append(fromTime);
						query.append("','mm/dd/yyyy hh24:mi:ss') ");
						query.append(" AND ");
						query.append("END_TIME = to_date('");
						query.append("01/01/1900 00:00:00','mm/dd/yyyy hh24:mi:ss')");
						query.append(")) ");
					}
				}
				else
				{
					if(comp_name_search==null || comp_name_search.trim().length()==0)
					{
						query.append(" COMP_NAME IN (");
						query.append(serverNames);
						query.append(") and ");
					}
					query.append("COMP_TYPE IN(");
					query.append(serverTypes);
					query.append(") ");
				
					if(isFromInsideviewDashboard)
					{
						query.append(" and START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)");
					}
					else
					{
						query.append(" and ((START_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(" OR (END_TIME BETWEEN convert(datetime,'");
						query.append(fromTime);
						query.append("',101) AND convert(datetime,'");
						query.append(toTime);
						query.append("',101)) OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME >= convert(datetime,'");
						query.append(toTime);
						query.append("',101)) ");
						query.append(") OR ");
						query.append("(");
						query.append("(START_TIME <= convert(datetime,'");
						query.append(fromTime);
						query.append("',101)) ");
						query.append(" AND ");
						query.append("(END_TIME = convert(datetime,'");
						query.append("01/01/1900 00:00");
						query.append("',101)))) ");
					}
				}
			}
			if (durationFilter != 0)
			{
				boolean lessThanZero = (durationFilter < 0);
				if (lessThanZero)
				{
					durationFilter = Math.abs(durationFilter);
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						sql_query.append(durationFilter);
						sql_query.append(")) ");
					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)<"+durationFilter+"))");
					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))<");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
				else
				{
					if (EgInstallInfo.isSuperManager)
					{
						ora_query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						ora_query.append(" OR");
						ora_query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");
						sql_query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						sql_query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						sql_query.append(durationFilter);
						sql_query.append(")) ");

					}
					else if (EgDbInfo.isOraAdapter)
					{
						query.append(
							"AND ((END_TIME= to_date('01/01/1900 00:00','dd/mm/yyyy hh24:mi:ss'))");
						query.append(" OR");
						query.append(" (END_TIME IS NOT NULL AND ((END_TIME-START_TIME)*86400)>"+durationFilter+"))");

					}
					else
					{
						query.append("AND ((END_TIME=convert(datetime,'01/01/1900 00:00',101)");
						query.append(
							") OR (END_TIME <> convert(datetime,'01/01/1900 00:00', 101) AND (convert(bigint,datediff(ss, START_TIME,  END_TIME)))>");
						query.append(durationFilter);
						query.append(")) ");

					}
				}
			}
			if(comp_name_search!=null && comp_name_search.trim().length()>0)
			{
				if(EgInstallInfo.isSuperManager)
				{
					ora_query.append(" AND lower(COMP_NAME) like ('%");
					ora_query.append(comp_name_search.toLowerCase());
					ora_query.append("%')");

					sql_query.append(" AND lower(COMP_NAME) like ('%");
					sql_query.append(comp_name_search.toLowerCase());
					sql_query.append("%')");
				}
				else
				{
					query.append(" AND lower(COMP_NAME) like ('%");
					query.append(comp_name_search.toLowerCase());
					query.append("%')");
				}
			}
			logToTmpFile("INFO","","Query for event history2 is "+query.toString());
			ResultSet rs = null;
			try
			{
				String qry = "";
				if (EgInstallInfo.isSuperManager)
				{
					ora_query.append(query);
					sql_query.append(query);
					qry = EgSmConfigInfo.ORACLE + ora_query.toString() + EgSmConfigInfo.EG_DOLLAR + EgSmConfigInfo.SQL + sql_query.toString();
				}
				else
				{
					qry = query.toString();
				}
				rs = egDb.dbselect(qry);

				if(rs.next())
				{

				 recCount = rs.getInt("count");

				}
				
				try
				{
					rs.close();
					rs = null;
				}
				catch (Exception hh)
				{
					rs = null;
				}
				
			return recCount;
			
				
			}
			catch (Exception chasegrrr)
			{
				try
				{
					if (rs != null)
					{
						rs.close();
					}
				}
				catch (Exception grr)
				{
				}
				return 0;
			}
		}
	}

	public final List getAlarmHistAsList(List result, List servers,boolean showAll,boolean hasVMs,User user,String selectedCompType,String selectedCompName,boolean showAllTypes,boolean showAllComps,List userCompList) throws SQLException
	{
		List list = new LinkedList();
		int count = result.size();
		List userServ = userCompList;
		List a_userVMs = new LinkedList();
		String vm  = "";
		if(result != null && result.size() > 0)
		{
			for(int kk=0;kk<count;kk++)
			{
				String[] row = (String[])result.get(kk);
				if(row != null && row.length > 0)
				{
					String ctypeName = row[3]+":"+row[2];
					String testName = row[5];
					if(hasVMs)
					{
						//a_userVMs = user.getOnlyVMs();
						a_userVMs = user.getAlluserDesktopVms();
						if(showAll)
						{
							if(!userServ.contains(ctypeName))
							{
								if(!ctypeName.startsWith("Host_system"))
								{
									if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									vm = row[4];
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(!a_userVMs.contains(vm))
										{
											
											continue;
										}
									}
								}
								else
								{
									continue;
								}
							}
						}
						else
						{
							if(!showAllTypes && showAllComps)
							{
								if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
								{
									if(!row[5].startsWith("Vmg"))
									{
										continue;
									}
									vm = row[4];
									vm = vm.substring(1);
									
									if(a_userVMs!=null && a_userVMs.size() > 0)
									{
										if(vm.indexOf(":") > -1)
										{
											vm = vm.substring(0,vm.indexOf(":"));
										}
										
										if(!a_userVMs.contains(vm))
										{
											continue;
										
										}
									}
								}
								else
								{
									if(!userServ.contains(ctypeName))
									{
										continue;
									}
								}
							}
							else if(showAllTypes && !showAllComps)
							{
									int countVM = 0;
									for(int u =0 ; u  < userServ.size() ; u++)
									{
										String host = (String)userServ.get(u);
										String type = host.substring(0,host.indexOf(":"));
										String comp = host.substring(host.indexOf(":")+1);
										if(selectedCompName.indexOf(":") <0)
										{
											if(comp.indexOf(selectedCompName) < 0)
											{
												//it is a vm
												countVM++;
											}
										}
										else
										{
											if(comp.indexOf(selectedCompName) < 0)
											{
												continue;
											}
										}

									}
									if(countVM == userServ.size())
									{
										if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
										vm = row[4];
										vm = vm.substring(1);
										if(a_userVMs!=null && a_userVMs.size() > 0)
										{
											//Count only the vm alarms with the particular descriptor
											if(vm.indexOf(":") > 0)
											{
												vm = vm.substring(0,vm.indexOf(":"));
											}
											if(a_userVMs.contains(vm))
											{
												if(!selectedCompName.equals(vm))
												{
													continue;
												}
												
											}
											else
											{
												continue;
											}
										}
									}
									else
									{
										if(ctypeName.indexOf(selectedCompName)>-1)
										{
											if (!userServ.contains(ctypeName))
											{
												continue;
											}
										}
										else
										{
											continue;
										}
									}
								}
								else if(!showAllTypes && !showAllComps)
								{
									if(selectedCompType!=null && selectedCompType.equals(user.getVMType()))
									{
										if(!row[5].startsWith("Vmg"))
										{
											continue;
										}
										vm = row[4];
										vm = vm.substring(1);
										
										if(a_userVMs!=null && a_userVMs.size() > 0)
										{
											if(vm.indexOf(":") > -1)
											{
												vm = vm.substring(0,vm.indexOf(":"));
											}
											
											if(a_userVMs.contains(vm))
											{
												if(!selectedCompName.equals(vm))
												{
													continue;		
												}
											}
											else
											{
												continue;
											}
										}
									}
									else
									{	
											if(ctypeName.indexOf(selectedCompName)>-1)
											{
												if (!userServ.contains(ctypeName))
												{
													continue;
												}
											}
											else
											{
												continue;
											}
									}
								}
							}
					}
					else
					{
						if (!servers.contains(ctypeName))
						{
							continue; // not one of our servers
						}
					}
					list.add(row);
				}
			}
		}
		return list;
	}

	public JSONObject getEventDetails(String params,String thisLanguage,User user,String currentDateFormat,User selectedUser,String showUsers,Hashtable resultUserCompMap,boolean isUserLanguageEnglish,boolean isVM,MonitorUtility Monutil)
	{
		JSONObject result = new JSONObject();
		JSONArray jsonarray = new JSONArray();
		String alarm_id = "",comp_type = "", comp_name = "",row_num = "";
		EgTablesInfo tablesInfo = new EgTablesInfo(EgConstants.MANAGER);
		EgMappingInfo mappingInfo1 = new EgMappingInfo(thisLanguage);
		EgFormatInfo formatInfo = new EgFormatInfo ("manager");
		EgAgentInfo agentInfo = new EgAgentInfo(EgConstants.MANAGER);
		EgSpecsInfo specsInfo = new EgSpecsInfo(EgConstants.MANAGER);
		TestBean testBean = new TestBean();
		if(params != null && params.length() > 0)
		{
			StringTokenizer stTokens = new StringTokenizer(params, ","); 
			if(stTokens != null)
			{
				alarm_id = (String)stTokens.nextToken();
				comp_type = (String)stTokens.nextToken();
				comp_name = (String)stTokens.nextToken();
				row_num = (String)stTokens.nextToken();
			}

			Hashtable probList = (Hashtable)EgDbAdapterUI.problemList;
			ArrayList al = (ArrayList)probList.get(alarm_id+"~#~"+row_num);
			if(al != null && al.size() > 0)
			{
				String service = (String)al.get(0);
				if(service != null && service.equalsIgnoreCase("NONE"))
					service = "-";
				String layer = (String)al.get(1);
				String priority = (String)al.get(2);
				String start_time = (String)al.get(3);
				String end_time = (String)al.get(4);

				String startDateValue ="";
				startDateValue = DateUtil.changeDateFormat(start_time,"yyyy-MM-dd HH:mm:ss",currentDateFormat);
				EgTimeZoneConverter timeZoneConverter1= new EgTimeZoneConverter(startDateValue,user);
				String loginUserDateTime = (String)timeZoneConverter1.getDateTime();

				if(loginUserDateTime != null && !loginUserDateTime.trim().equals(""))
				{
					startDateValue = loginUserDateTime;
				}

				ArrayList probDescList = (ArrayList)al.get(5);
				if(probDescList != null && probDescList.size() > 0)
				{
					for(int l=1;l<probDescList.size();l++)
					{
						String site = "", info = "", test = "", measure = "",msmt_host = "", description = "";
						int len = 0;
						String problem_desc = (String)probDescList.get(l);
						if(problem_desc != null && problem_desc.trim().length() > 0)
						{
							StringTokenizer probTokens = new StringTokenizer(problem_desc,"|");
							if(probTokens.countTokens() == 5)
							{
								site = probTokens.nextToken(); // site
								info = probTokens.nextToken(); // info
								test = probTokens.nextToken(); // test
								measure = probTokens.nextToken(); // measure
								msmt_host = probTokens.nextToken(); // msmt_host
							}

							if(isCustomAlertMessages)
							{
								String custom_info=info;
								if(info!=null && info.length()>1 && info.startsWith("+"))
								{
									custom_info=info.substring(1);
								}
								description = tablesInfo.getCustomMeasureAlert(test+":"+measure,info,thisLanguage);
								len = description.trim().length();
								if(description != null && len > 0){
									description = replaceMsg(description,Server.getServerNameWithoutPort(comp_name, false),mappingInfo1.getComponentTypeDescription(comp_type),site,mappingInfo1.getLabelDescription(priority),mappingInfo1.getLayerDescription(layer),mappingInfo1.getTestDescription(test),custom_info,mappingInfo1.getMeasureDescription(test,measure),"");
								}
							}
							if(description == null || len == 0 || description.startsWith(measure))
							{
								String tmp_cmpType="";
								Hashtable alertParams = new Hashtable();
								alertParams.put("$componentType",mappingInfo1.getComponentTypeDescription(comp_type));
								alertParams.put("$componentName",Server.getServerNameWithoutPort(comp_type, false));
								if(info!=null && info.trim().length()>1){
									if(info.startsWith("+"))
										alertParams.put("$info",info.substring(1));
									else
										alertParams.put("$info",info);
								}
								alertParams.put("hasVMs",isVM);
								description = tablesInfo.getMeasureAlert(test+":"+measure,info,thisLanguage,alertParams);
								boolean infoExists = Boolean.parseBoolean(description.substring(description.indexOf("~!~")+3));
								description = description.substring(0,description.indexOf("~!~"));
								description = (!infoExists && info!=null && info.trim().length()>1)?description +" { "+(info.startsWith("+")?info.substring(1):info)+" } ":description;
							}

							String infoplus=com.egurkha.util.StringUtils.replace(info,"+","*");
							String childpopupVal = alarm_id+","+comp_type+","+comp_name+","+site+","+test+","+measure+","+infoplus+","+msmt_host+","+isVM+"&userLang="+thisLanguage;
							JSONObject jsonobject1 = new JSONObject();
							//jsonobject1.put("priority",mappingInfo1.getLabelDescription(priority));
							jsonobject1.put("popupVal",childpopupVal);
							jsonobject1.put("type", mappingInfo1.getComponentTypeDescription(comp_type));
							jsonobject1.put("name", Server.getServerNameWithoutPort(comp_name, false));
							jsonobject1.put("services", service);
							jsonobject1.put("test", mappingInfo1.getTestDescription(test));
							jsonobject1.put("description", description);

							if(hasAllComponentAccess && selectedUser==null && showUsers!=null && (showUsers.equalsIgnoreCase("true") || showUsers.equalsIgnoreCase("yes")))
							{
								Vector resultVect=new Vector();
								String displayUsers=new String();
								String displayUsersInTitle=new String();
								String strUsers = "";
								if(resultUserCompMap!=null && resultUserCompMap.size()>0)
								{
									resultVect=(Vector)resultUserCompMap.get(comp_type+":"+comp_name);
								}

								if(resultVect==null || resultVect.size()==0)
								{
									strUsers="-";
								}
								else
								{
									displayUsers=resultVect.toString();

									if(displayUsers!=null && displayUsers.trim().length()>0 && displayUsers.startsWith("["))
									{
										displayUsers=displayUsers.substring(1);
									}

									if(displayUsers!=null && displayUsers.trim().length()>0 && displayUsers.endsWith("]"))
									{
										displayUsers=displayUsers.substring(0,displayUsers.length()-1);
									}

									strUsers = displayUsers;
									ArrayList aListUsers = new ArrayList();
									StringTokenizer strTokens = new StringTokenizer(strUsers,",");
									while (strTokens.hasMoreTokens())
									{
										String strToken = strTokens.nextToken();
										strToken = strToken.trim();
										if (strToken.indexOf("/Grp/") != -1)
										{
											String grpDelimiter = "/Grp/";
											int idx = strToken.indexOf(grpDelimiter);
											String str_uname_A = strToken.substring(0,idx);
											int nextIdx = idx + grpDelimiter.length();
											String str_uname_B = strToken.substring(nextIdx);
											strToken = str_uname_A + "/" + str_uname_B + " (Group)";
										}
										aListUsers.add(strToken);
									}
									strUsers = aListUsers.toString();
									strUsers = strUsers.substring(1,strUsers.length()-1);

									displayUsersInTitle = strUsers;

									strUsers = egSubString(strUsers,isUserLanguageEnglish,15,12);
								}
								jsonobject1.put("users",strUsers);
							}

							jsonobject1.put("stdate",startDateValue);
							if(end_time.equals("1900-01-01 00:00:00.0") || end_time.equals("1900-01-01 00:00:00"))
							{
								jsonobject1.put("duration", "Current");
							}
							else
							{
								String endDateValue ="";
								endDateValue = DateUtil.changeDateFormat(end_time,"yyyy-MM-dd HH:mm:ss",currentDateFormat);
								EgTimeZoneConverter timeZoneConverter2= new EgTimeZoneConverter(endDateValue,user);
								String loginUserDateTime1 = (String)timeZoneConverter2.getDateTime();

								if(loginUserDateTime1 != null && !loginUserDateTime1.trim().equals(""))
								{
									endDateValue = loginUserDateTime1;
								}
								long diff = getDuration(start_time, end_time);
								jsonobject1.put("duration",DateTimeTokenizer.getTimeDifference(diff));
							}

							if(measure != null && measure.equalsIgnoreCase("NUM_BLOCKED_SESSIONS"))
								measure = "BLOCKED_SESSION";

							JSONObject graph = new JSONObject();
							StringBuffer sb = new StringBuffer();
							String tabSetInfo = "" , timeKey = "" ;
							String temp_measureLink = measureLink;
							StringTokenizer stringTokens = new StringTokenizer(temp_measureLink,"&");
							while(stringTokens.hasMoreTokens())
							{
								String value = stringTokens.nextToken();
								if(value!=null)
								{
									if(value.indexOf("=") > -1)
									{
										String paramName = value.substring(0,value.indexOf("="));
										String paramValue = value.substring(value.indexOf("=")+1,value.length());
										if(paramName!=null)
										{
											if(paramName.equalsIgnoreCase("site"))
											{
												paramValue = site;
											}
											else if(paramName.equalsIgnoreCase("test"))
											{
												paramValue = test;
											}
											else if(paramName.equalsIgnoreCase("info"))
											{
												if(info.startsWith("+"))
													info = com.egurkha.util.StringUtils.replace(info,"+","*");
												
												if(!paramValue.startsWith("*"))
												{
													paramValue = paramValue.substring(0,paramValue.length()-1)+info;
													tabSetInfo = paramValue;
												}
												else
												{
													tabSetInfo = info;
													paramValue = info;
												}
											}
											else if(paramName.equalsIgnoreCase("messy"))
											{
												paramValue = measure;
											}
											else if(paramName.equalsIgnoreCase("stTime"))
											{
												timeKey = paramValue;
											}
											sb.append(paramName+"="+paramValue);
											if(stringTokens.hasMoreTokens())
												sb.append("&");
										}
									}
								}
							}

							String agLink = parseUrl(aggregateLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"compfeedbacklink",agLink);

							String gLink = parseUrl(graphLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"#"+timeKey+"#"+comp_name+"compgraphlink",gLink);

							String sumLink = parseUrl(summarygraphLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"compsummarygraphlink", sumLink);

							String trLink = parseUrl(trendgraphLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"comptrendgraphlink", trLink);

							String hisLink = parseUrl(historyLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"comphistorylink", hisLink);

							String fdLink = parseUrl(feedbackLink,site,test,measure,info,true);
							linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"compfeedbacklink", fdLink);

							graph.put("url", sb.toString());
							graph.put("subParam","data");
							graph.put("popup_selection","true");
							jsonobject1.put("graphParams",graph);

							boolean showDDIcon = true;
							ArrayList excludeDDTestList = formatInfo.getHideDDTestList();
							if(excludeDDTestList != null && excludeDDTestList.size() > 0 && excludeDDTestList.contains(test))
							{
								showDDIcon = false;
							}

							if ((EgMemInfo.ddEnabled && testBean.isDdEnabled(test, measure)  && (!agentInfo.isAgentlessServer(Server.getServerNameWithoutPort(comp_name),comp_type,true) || specsInfo.isTestExternal(test))) || (EgMemInfo.ddEnabled && testBean.isDdEnabled(test, measure)))
							{
								if(showDDIcon)
								{
									String diagLink = parseUrl(compddLink,site,test,measure,info,false);
									linksMap.put(test+"#"+measure+"#"+tabSetInfo+"#"+msmt_host+"#"+timeKey+"#"+comp_name+"compddlink", diagLink);

									String ddLink1 = parseUrl(ddLink,site,test,measure,info,false);

									JSONObject ddDetails = new JSONObject();
									ddDetails.put("url",ddLink1);
									ddDetails.put("subParam","dd");
									ddDetails.put("popup_selection","true");
									jsonobject1.put("ddparams",ddDetails);
								}
							}
							jsonobject1.put("leaf",true);
							jsonarray.add(jsonobject1);
						}
					}
				}
			}
			result.put("alarmDetailJson",jsonarray);
		}
		return result;
	}

	private long getDuration(String s, String s1)
    {
        long l = 0L;
        try
        {
            SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = simpledateformat.parse(s);
            Date date1 = simpledateformat.parse(s1);
            l = (date1.getTime() - date.getTime()) / 1000L;
        }
        catch(Exception exception)
        {
            System.out.println("Exception in EgAlarmTable:getDuration()");
            exception.printStackTrace();
        }
        return l;
    }

	public String parseUrl (String url,String site, String test, String measure, String info, boolean changeCase)
	{
		StringBuffer sb = new StringBuffer();
		StringTokenizer stringTokens = new StringTokenizer(url,"&");
		while(stringTokens.hasMoreTokens())
		{
			String value = stringTokens.nextToken();
			boolean infocheck = ((value.indexOf("=")+1) == value.length());
			if(value!=null)
			{
				if(value.indexOf("=") > -1)
				{
					String paramName = value.substring(0,value.indexOf("="));
					String paramValue = (infocheck)?"":value.substring(value.indexOf("=")+1,value.length());
					if(paramName!=null)
					{
						if(paramName.equalsIgnoreCase("site"))
						{
							paramValue = site;
						}
						else if(paramName.equalsIgnoreCase("test"))
						{
							paramValue = test;
						}
						else if(!infocheck && paramName.equalsIgnoreCase("info"))
						{
							if(info.startsWith("+"))
								info = com.egurkha.util.StringUtils.replace(info,"+","*");
							
							if(!paramValue.startsWith("*"))
							{
								paramValue = paramValue.substring(0,paramValue.length()-1)+info;
							}
							else
							{
								paramValue = info;
							}
						}
						else if(paramName.equalsIgnoreCase("measure") || paramName.equalsIgnoreCase("messy"))
						{
							if(changeCase)
								paramValue = measure.toUpperCase();
							else
								paramValue = measure;
						}
						sb.append(paramName+"="+paramValue);
						if(stringTokens.hasMoreTokens())
							sb.append("&");
					}
				}
			}
		}
		return sb.toString();
	}
	public  String getMsmtTimeForLogon(String msmtSTimeforlogon,String msmtETimeforlogon,String testNameforlogon,String user_info,String mgrIdFromRow)
	{
		String msmtLogon="";
		String status = "";
		String query="";
		ResultSet rs2 = null;
		EgDbAdapterUI egDb = EgDbAdapterTypeUI.getObject();
		status = egDb.setConnection();

		try
		{
			if(EgInstallInfo.isSuperManager)
			{
				String oraQuery="select * from "+testNameforlogon+" where info='"+user_info+"' and msmt_time between to_date('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') and to_date('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc";
				String sqlQuery="select * from "+testNameforlogon+" where info='"+user_info+"' and msmt_time between convert(datetime,'"+ msmtSTimeforlogon+ "',101) and convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				Hashtable ht = new Hashtable();
				ht.put("OracleQuery",oraQuery);
				ht.put("SqlQuery",sqlQuery);
				ht.put("sourceDateFormat","MM/dd/yyyy HH:mm:ss");
				ht.put("startDate",msmtSTimeforlogon);
				ht.put("endDate",msmtETimeforlogon);
				if(mgrIdFromRow != null && mgrIdFromRow.trim().length()>0 && !mgrIdFromRow.trim().equalsIgnoreCase("null"))
				{
					ArrayList managerIds = new ArrayList();
					managerIds.add(mgrIdFromRow);
					ht.put("special_case_mgr_ids",managerIds);
				}
				rs2=new EgSMDBHelper().getResultSet(ht);
			}
			else
			{
				if (EgDbInfo.isOraAdapter)
				{
					query="select * from "+testNameforlogon+" where INFO='"+user_info+"' and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc";
				}
				else
				{
					query="select * from "+testNameforlogon+" where INFO='"+user_info+"' and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				}
				rs2 = egDb.dbselect(query);
			}
			if(rs2!=null)
			{
				if (rs2.next())
				{
					 msmtLogon = rs2.getString("msmt_time");
				}
			}
			if(rs2!=null)
			{
				rs2.close();
			}
			rs2=null;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			try
			{
				if (rs2!=null)
				{
					rs2.close();
				}
				rs2=null;
			}
			catch (Exception ec)
			{
				ec.printStackTrace();
			}
		}
		finally
		{
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}

		return msmtLogon;
	}
	public String getUserTypeForLogon(String testName,String infoName,String msmtSTimeforlogon,String msmtETimeforlogon)
	{
		String delivery_gr="";
		String compNameforLog="";
		String status = "";
		String query="";
		String query1="";
		ResultSet rs2 = null;
		ResultSet rs3 = null;
		EgDbAdapterUI egDb = EgDbAdapterTypeUI.getObject();
		status = egDb.setConnection();
		try
		{
			if(EgInstallInfo.isSuperManager)
			{
				String oraQuery="select * from (select Delivery_group from "+testName+"_DDD  where info='"+infoName+"' and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss')  order by msmt_time desc)where rownum = 1";
				String sqlQuery="select top 1 Delivery_group from "+testName+"_DDD  where info='"+infoName+"' and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				Hashtable ht = new Hashtable();
				if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
				{
					ArrayList managerIds = (ArrayList)EgManagersInfo.sessionManagerMap.get(currentSessionId);
					System.out.println("session manager ids7 " + managerIds);
					if(managerIds != null && !managerIds.isEmpty())
					{
						ht.put("special_case_mgr_ids",managerIds);
					}
				}
				ht.put("OracleQuery",oraQuery);
				ht.put("SqlQuery",sqlQuery);
				ht.put("sourceDateFormat","MM/dd/yyyy HH:mm:ss");
				ht.put("startDate",msmtETimeforlogon);
				if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
				{
					ArrayList al = (ArrayList) EgManagersInfo.sessionManagerMap.get(currentSessionId);
					if(al != null && !al.isEmpty())
					{
						ht.put("special_case_mgr_ids",al);
					}
				}
				rs2=new EgSMDBHelper().getResultSet(ht);
			}
			else if (EgDbInfo.isOraAdapter)
			{
				query="select * from (select Delivery_group from "+testName+"_DDD  where info='"+infoName+"' and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss')  order by msmt_time desc)where rownum = 1";
			}
			else
			{
				query="select top 1 Delivery_group from "+testName+"_DDD  where info='"+infoName+"' and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				rs2 = egDb.dbselect(query);
			}
			if(rs2!=null)
			{
				if (rs2.next())
				{
					 delivery_gr = rs2.getString("Delivery_group");
				}
			}
			if(rs2!=null)
			{
				rs2.close();
			}
			rs2=null;

			if(EgInstallInfo.isSuperManager)
			{
				String oraQuery=null;
				String sqlQuery=null;
				if(testName.equals("CtxCdUserTest"))
				{
					oraQuery="select * from (select info from CtxCdLogonTest where info like ('%:"+delivery_gr+"')  and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc) where rownum=1";

					sqlQuery="select top 1 info from CtxCdLogonTest where info like ('%:"+delivery_gr+"') and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				}
				else
				{
					oraQuery="select * from (select info from CtxXcXDLogonTest where info like ('%:"+delivery_gr+"')  and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc) where rownum=1";

					sqlQuery="select top 1 info from CtxXcXDLogonTest where info like ('%:"+delivery_gr+"') and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
				}
				Hashtable ht = new Hashtable();
				if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
				{
					ArrayList managerIds = (ArrayList)EgManagersInfo.sessionManagerMap.get(currentSessionId);
					System.out.println("session manager ids8 " + managerIds);
					if(managerIds != null && !managerIds.isEmpty())
					{
						ht.put("special_case_mgr_ids",managerIds);
					}
				}
				ht.put("OracleQuery",oraQuery);
				ht.put("SqlQuery",sqlQuery);
				ht.put("sourceDateFormat","MM/dd/yyyy HH:mm:ss");
				ht.put("startDate",msmtSTimeforlogon);
				ht.put("endDate",msmtETimeforlogon);
				if(EgManagersInfo.sessionManagerMap.containsKey(currentSessionId))
				{
					ArrayList al = (ArrayList) EgManagersInfo.sessionManagerMap.get(currentSessionId);
					if(al != null && !al.isEmpty())
					{
						ht.put("special_case_mgr_ids",al);
					}
				}
				rs3=new EgSMDBHelper().getResultSet(ht);
			}
			else
			{
				if(testName.equals("CtxCdUserTest"))
				{
					if (EgDbInfo.isOraAdapter)
					{
						query1="select * from (select info from CtxCdLogonTest where info like ('%:"+delivery_gr+"')  and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc) where rownum=1";
					}
					else
					{
						query1="select top 1 info from CtxCdLogonTest where info like ('%:"+delivery_gr+"') and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
					}
				}
				else
				{
					if (EgDbInfo.isOraAdapter)
					{
						query1="select * from (select info from CtxXcXDLogonTest where info like ('%:"+delivery_gr+"')  and msmt_time  BETWEEN TO_DATE('"+ msmtSTimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') AND TO_DATE('"+ msmtETimeforlogon+ "', 'mm/dd/yyyy hh24:mi:ss') order by msmt_time desc) where rownum=1";
					}
					else
					{
						query1="select top 1 info from CtxXcXDLogonTest where info like ('%:"+delivery_gr+"') and msmt_time BETWEEN convert(datetime,'"+ msmtSTimeforlogon+ "',101) AND convert(datetime,'"+ msmtETimeforlogon+ "',101) order by msmt_time desc";
					}
				}
				rs3 = egDb.dbselect(query1);
			}
			if(rs3!=null)
			{
				if (rs3.next())
				{
					 compNameforLog = rs3.getString("info");
				}
			}
			if(rs3!=null)
			{
				rs3.close();
			}
			rs3=null;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			try
			{
				if (rs2!=null)
				{
					rs2.close();
				}
				rs2=null;
				if (rs3!=null)
				{
					rs3.close();
				}
				rs3=null;
			}
			catch (Exception ec)
			{
				ec.printStackTrace();
			}
		}
		finally
		{
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		return compNameforLog;
	}
%>
