<%
/********************************************************************************************************
*	Name			:	servicesBusinessDashboard.jsp
*	Purpose			:	This page used to Display the Performance of Services
*	Version			:	6.0
*	CreationDate	:	Oct 21 2013
*	Author			:	Saravanan.A
*******************************************************************************************************/
%>

<%//@ include file = "EgLoginTracker.jsp" %>
<%@ include file = "EgServerDashboardTracker.jsp" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "com.egurkha.monitor.*" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.math.*" %>
<%@ page import = "com.egurkha.ini.*" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgTopoInfo"%>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgAggregateInfo"%>
<%@ page import="com.egurkha.util.*"%>
<%@ page import = "com.egurkha.monitor.ServicesDashboardBean"%>
<%@ page import="com.egurkha.util.EgSorter"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.eg.EgExternalInfo"%>
<%@ page import="com.eg.EgDiscInfo"%>
<%@ page import="com.eg.EgSpecsInfo"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.EgConstants" %>
<%@ page import = "egurkha.EgCrawler" %>
<%@ page import = "com.egurkha.EgMeasureGraphExt" %>
<%@ page import = "com.egurkha.monitor.MonitorUtility" %>
<%@ page import = "com.eg.supermanager.*" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="net.sf.json.*"%>

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

<%
	JSONObject json = new JSONObject();
try
{
	if(com.eg.EgInstallInfo.isSuperManager)
	{
		SmSessionData smsData = new SmSessionData(session.getId());
		EgThreadLocal egtl = new EgThreadLocal();
		egtl.set(smsData);
	}
	session.removeAttribute("layer");
	session.removeAttribute("test");

	ServiceListData d = (ServiceListData) request.getAttribute("data");
	ServiceListResult r = (ServiceListResult) request.getAttribute("result");
	if(session.getAttribute("ServiceListData")!=null && session.getAttribute("ServiceListResult")!=null )
	{
		d=(ServiceListData)session.getAttribute("ServiceListData");
		r=(ServiceListResult)session.getAttribute("ServiceListResult");
	}

	int abnormalServicesCount=0;
	if(r!=null && r.serviceList!=null)
		abnormalServicesCount=r.serviceList.size();
	int totServices = 0;
	if(r!=null && r.serviceList!=null)
		totServices = r.serviceList.size();

	boolean ifshowImage=r.showImage;
	String treeFlag=request.getParameter("treeFlag");
	IniUI iniUI = IniUI.getInstance();
	UserRegistry userReg = UserRegistry.getInstance();
	User user = userReg.getUser(session.getId());
	String thisLanguage = iniUI.getDefaultLanguage();
	String user_name="";
	if (user!=null)
	{
		String userLang = user.getLanguage();
		user_name=user.getLoginID();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	
	EgMeasureGraphExt measureGraphInfo = new EgMeasureGraphExt();
	EgUserRole userRole = user.getUserRole();
	boolean hasAllComponentAccess=userRole.hasAllComponentAccess();
	List components_typelist=new LinkedList();
	components_typelist.addAll(user.getServerTypes());
	List userCompList=new LinkedList();
	userCompList.addAll(user.getServers(false));
	boolean isUserLanguageEnglish=true;
	if(thisLanguage!=null && !thisLanguage.equals("en_US"))
	{
		isUserLanguageEnglish=false;
	}
	ServicesDashboardBean servicesBean = new ServicesDashboardBean();
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	EgTopoInfo topoInfo=new EgTopoInfo("manager");
	EgAggregateInfo aggInfo=new EgAggregateInfo("manager");
	EgTablesInfo tablesInfo=new EgTablesInfo("manager");
	EgDiscInfo discInfo=new EgDiscInfo("manager");
	EgDbInfo dbInfo=new EgDbInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	EgExternalInfo egExternalInfo=new EgExternalInfo("manager");
	MonitorUtility monUtil = new MonitorUtility();
	IniFile serviceDashIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_serviceperfdash.ini");
	String showTopNTier=(String)serviceDashIni.getValue("Services_Overview_Common","Show_TopTier");
	int showTopN=0;
	if(showTopNTier!=null && showTopNTier.trim().length()>0 && !showTopNTier.equalsIgnoreCase("All"))
	{
		try
		{
			showTopN = Integer.parseInt(showTopNTier.trim());
		}
		catch(Exception e)
		{
			showTopN = 5;
		}
	}

	String isServiceBusiDash = request.getParameter("isServiceBusiDash");

	String showTopNInfoStr=(String)serviceDashIni.getValue("Services_Overview_Common","Show_TopDescriptors");
	int showTopNInfos=0;
	if(showTopNInfoStr!=null && showTopNInfoStr.trim().length()>0 && !showTopNInfoStr.equalsIgnoreCase("All"))
	{
		try
		{
			showTopNInfos = Integer.parseInt(showTopNInfoStr.trim());
		}
		catch(Exception e)
		{
			showTopNInfos = 5;
		}
	}

	String showMaxDemandMeas=(String)serviceDashIni.getValue("Services_Overview_Common","Show_Max_Demand_Measures");
	int showMaxDemand=3;
	if(showMaxDemandMeas!=null && showMaxDemandMeas.trim().length()>0)
	{
		try
		{
			showMaxDemand = Integer.parseInt(showMaxDemandMeas.trim());
		}
		catch(Exception e)
		{
			showMaxDemand = 3;
		}
	}
	String showMaxConsumptionMeas=(String)serviceDashIni.getValue("Services_Overview_Common","Show_Max_Consumption_Measures");
	int showMaxConsumption=3;
	if(showMaxConsumptionMeas!=null && showMaxConsumptionMeas.trim().length()>0)
	{
		try
		{
			showMaxConsumption = Integer.parseInt(showMaxConsumptionMeas.trim());
		}
		catch(Exception e)
		{
			showMaxConsumption = 3;
		}
	}
	String showMaxQualityMeas=(String)serviceDashIni.getValue("Services_Overview_Common","Show_Max_Quality_Measures");
	int showMaxQuality=3;
	if(showMaxQualityMeas!=null && showMaxQualityMeas.trim().length()>0)
	{
		try
		{
			showMaxQuality = Integer.parseInt(showMaxQualityMeas.trim());
		}
		catch(Exception e)
		{
			showMaxQuality = 3;
		}
	}

	String showGraphMAM=(String)serviceDashIni.getValue("Services_Overview_Common","Show_graph_MAM");
	boolean isShowGraphMAM=false;
	if(showGraphMAM!=null && showGraphMAM.trim().length()>0 && showGraphMAM.equalsIgnoreCase("true"))
	{
		isShowGraphMAM=true;
	}
	String enableServiceSkipReorder =
	(String)serviceDashIni.getValue("Services_User_Config",user_name+":enableServiceSkipReorder");
	enableServiceSkipReorder = (enableServiceSkipReorder==null || enableServiceSkipReorder.trim().length()==0)?"false":enableServiceSkipReorder;
	boolean isEnableServiceSkipReorder = false;
	if(enableServiceSkipReorder!=null && enableServiceSkipReorder.equalsIgnoreCase("true")|| enableServiceSkipReorder.equalsIgnoreCase("yes"))
		isEnableServiceSkipReorder=true;
		
	ArrayList ServicesToSkipList = new ArrayList();
	ArrayList servicesReorderList = null;
	
	if(isEnableServiceSkipReorder)
	{
		String ServicesToSkip = (String)serviceDashIni.getValue("Services_User_Config",user_name+":ServicesToSkip");

		if(ServicesToSkip!=null && ServicesToSkip.trim().length()>0)
		{
			ServicesToSkipList =  com.egurkha.util.StringUtils.egTokenizer(ServicesToSkip, ",",false,false,true);
		}
		String servicesReordered = (String)serviceDashIni.getValue("Services_User_Config",user_name+":ServicesReorder");
		if(servicesReordered!=null && servicesReordered.trim().length()>0)
		{
			servicesReorderList =  com.egurkha.util.StringUtils.egTokenizer(servicesReordered, ",",false,false,true);
		}
	}
	
	String show_graph = (String)serviceDashIni.getValue("Services_Overview_Common","show_graph");
	show_graph = (show_graph==null || show_graph.trim().length()==0)?"true":show_graph;
	boolean show_graph_flag = true;
	if(show_graph!=null && show_graph.trim().length()>0 && (show_graph.equalsIgnoreCase("false")||show_graph.equalsIgnoreCase("no")))
		show_graph_flag = false; 
	
	String show_state_color = (String)serviceDashIni.getValue("Services_Overview_Common","show_state_color");
	show_state_color = (show_state_color==null || show_state_color.trim().length()==0)?"true":show_state_color;
	boolean isShowStateColor = true;
	if(show_state_color!=null && show_state_color.trim().length()>0 && (show_state_color.equalsIgnoreCase("false")||show_state_color.equalsIgnoreCase("no")))
		isShowStateColor = false; 

	String [] test_array=serviceDashIni.getVariables("Show_Descriptors");
	ArrayList showDescriptorsList = new ArrayList();
	if(test_array!=null && test_array.length>0)
		showDescriptorsList = new ArrayList(Arrays.asList(test_array));

	int compNameLength = 13;
	int compHeadLength = 16;
	String iniIdentity = "monitor.transaction.";

	IniFile egUI = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");
	String chartOption = egUI.getValue("CHART_TYPE","ChartOption");
	String chartTimeline = egUI.getValue("CHART_TYPE","Timeline");
	chartTimeline = (chartTimeline != null && !chartTimeline.equals(""))?chartTimeline:"1 hour";

	IniFile topoIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_topology.ini");
	Object [] anchorVar=aggInfo.getVariables("ANCHOR_COMPONENT");
	Hashtable anchorHash=new Hashtable();
	Hashtable anchorTypeHash=new Hashtable();
	if(anchorVar!=null)
	{
		for(int k=0;k<anchorVar.length;k++)
		{
			String anchorValue = (String)anchorVar[k];
			if(anchorValue!=null && anchorValue.trim().length()>0 )
			{
				anchorValue = anchorValue.trim();
				String anchorKey=aggInfo.getValue("ANCHOR_COMPONENT",anchorValue);
				if(anchorKey!=null && anchorKey.trim().length()>0)
				{
					anchorKey=anchorKey.trim();
					String anchorCompValue=anchorValue.substring(0,anchorValue.indexOf("#"));
					String anchorCompTypeValue=anchorCompValue.substring(0,anchorCompValue.indexOf(":"));
					if(hasAllComponentAccess || (userCompList!=null && userCompList.contains(anchorCompValue)))
					{
						if(anchorHash.containsKey(anchorKey))
						{
							ArrayList alist=(ArrayList)anchorHash.get(anchorKey);
							alist.add(anchorCompValue);
							anchorHash.put(anchorKey,(ArrayList)alist);

							ArrayList aCtlist=(ArrayList)anchorTypeHash.get(anchorKey);
							if(aCtlist!=null && !aCtlist.contains(anchorCompTypeValue))
								aCtlist.add(anchorCompTypeValue);

							anchorTypeHash.put(anchorKey,(ArrayList)aCtlist);
							
						}
						else
						{
							ArrayList alist=new ArrayList();
							alist.add(anchorCompValue);
							anchorHash.put(anchorKey,(ArrayList)alist);

							ArrayList aCtlist=new ArrayList();
							aCtlist.add(anchorCompTypeValue);
							anchorTypeHash.put(anchorKey,(ArrayList)aCtlist);
							
						}
					}
				}
			}
		}
	}

	Object [] aggCompAssVar=aggInfo.getVariables("COMPONENT_ASSOCIATION");
	Hashtable aggCompAssHash=new Hashtable();
	Hashtable aggCompAssTypeHash=new Hashtable();
	if(aggCompAssVar!=null)
	{
		for(int k=0;k<aggCompAssVar.length;k++)
		{
			String aggCompAssVarValue = (String)aggCompAssVar[k];
			if(aggCompAssVarValue!=null && aggCompAssVarValue.trim().length()>0 )
			{
				aggCompAssVarValue = aggCompAssVarValue.trim();
				String aggCompAssKey=aggInfo.getValue("COMPONENT_ASSOCIATION",aggCompAssVarValue);
				if(aggCompAssKey!=null && aggCompAssKey.trim().length()>0)
				{
					aggCompAssKey=aggCompAssKey.trim();
					String aggAssCompValue=aggCompAssVarValue.substring(0,aggCompAssVarValue.indexOf("#"));
					String aggAssCompTypeValue=aggCompAssVarValue.substring(0,aggCompAssVarValue.indexOf(":"));
					if(hasAllComponentAccess || (userCompList!=null && userCompList.contains(aggAssCompValue)))
					{
						if(aggCompAssHash.containsKey(aggCompAssKey))
						{
							ArrayList alist=(ArrayList)aggCompAssHash.get(aggCompAssKey);
							alist.add(aggAssCompValue);
							aggCompAssHash.put(aggCompAssKey,(ArrayList)alist);

							ArrayList aCtlist=(ArrayList)aggCompAssTypeHash.get(aggCompAssKey);
							if(aCtlist!=null && !aCtlist.contains(aggAssCompTypeValue))
								aCtlist.add(aggAssCompTypeValue);
							
							aggCompAssTypeHash.put(aggCompAssKey,(ArrayList)aCtlist);
							
						}
						else
						{
							ArrayList alist=new ArrayList();
							alist.add(aggAssCompValue);
							aggCompAssHash.put(aggCompAssKey,(ArrayList)alist);
						
							ArrayList aCtlist=new ArrayList();
							aCtlist.add(aggAssCompTypeValue);
							aggCompAssTypeHash.put(aggCompAssKey,(ArrayList)aCtlist);
						}
					}
				}
			}
		}
	}

	//AGG_SITE_MAP
	Object [] aggSiteMapVar=topoIni.getVariables("AGG_SITE_MAP");
	Hashtable aggSiteMapHash=new Hashtable();
	List site_services_list = new LinkedList();
	site_services_list.addAll(user.getSites());
	site_services_list.addAll(user.getServices());
	if(aggSiteMapVar!=null)
	{
		for(int k=0;k<aggSiteMapVar.length;k++)
		{
			String aggSiteMapVarValue = (String)aggSiteMapVar[k];
			if(aggSiteMapVarValue!=null && aggSiteMapVarValue.trim().length()>0 )
			{
				aggSiteMapVarValue = aggSiteMapVarValue.trim();
				String aggSiteMapKey=topoIni.getValue("AGG_SITE_MAP",aggSiteMapVarValue);
				if(aggSiteMapKey!=null && aggSiteMapKey.trim().length()>0)
				{
					aggSiteMapKey=aggSiteMapKey.trim();
					if(hasAllComponentAccess || (site_services_list!=null && site_services_list.contains(aggSiteMapVarValue)))
					{
						if(aggSiteMapHash.containsKey(aggSiteMapKey))
						{
							ArrayList alist=(ArrayList)aggSiteMapHash.get(aggSiteMapKey);
							alist.add(aggSiteMapVarValue);
							aggSiteMapHash.put(aggSiteMapKey,(ArrayList)alist);
							
						}
						else
						{
							ArrayList alist=new ArrayList();
							alist.add(aggSiteMapVarValue);
							aggSiteMapHash.put(aggSiteMapKey,(ArrayList)alist);
							
						}
					}
				}
			}
		}
	}

	String screenWidthVal = request.getParameter("screenWidth");
	long graphWidth=210;
	if(screenWidthVal!=null && screenWidthVal.trim().length()>0)
	{
		int winWidth = Integer.parseInt(screenWidthVal);
		try
		{
			Long temp_measure_value=new Long(Math.round((double)((winWidth-20)*(0.2))));
			graphWidth=temp_measure_value.longValue();
		}
		catch(Exception e)
		{
			graphWidth=210;
		}
	}
	
	Hashtable stateMeasure = monUtil.getComponentState(null,null,null,null,null,null,null,null);

	if((totServices!=0) || (d.searchString!=null&&totServices==0))
	{
		if (totServices==0)
		{
			json.put("errMsg",mappingInfo.getTextDescription("monitor.serviceDashboard.No services found for the current search"));
		}

		if(abnormalServicesCount!=0)
		{
			if(totServices==0)
			{
				json.put("needHeader","false");
			}
			else
			{
				json.put("needHeader","true");
			}

			JSONArray jsonArr = new JSONArray();

			int i = 0;
			int j = 0;
			int cnt = 0;
			EgService service = null;
			EgList tmpServList=new EgList();
			ArrayList defaultSerList=new ArrayList();
			IniFile iniSerReordSkip = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_serviceperfdash.ini",true);
			for(int dfs=0;dfs<r.serviceList.size();dfs++)
			{
				service = (EgService) r.serviceList.get(dfs);
				String service_name=(String)service.getName();
				if( service_name!=null && defaultSerList!=null && !defaultSerList.contains(service_name))
					defaultSerList.add(service_name);
			}
			if((isEnableServiceSkipReorder) && (servicesReorderList!=null && servicesReorderList.size()>0)) 
			{
					boolean isReoderUpdate = false;
					boolean isSkipUpdate = false;
					for(int k=0;k<servicesReorderList.size();k++)
					{
						String tmpServ = (String)servicesReorderList.get(k);
						if(defaultSerList!=null && !defaultSerList.contains(tmpServ))
						{
							servicesReorderList.remove(tmpServ);
							isReoderUpdate = true;
						}
					}
					if(ServicesToSkipList!=null && ServicesToSkipList.size()>0)
					{
						for(int k=0;k<ServicesToSkipList.size();k++)
						{
							String tmpServ = (String)ServicesToSkipList.get(k);
							if(defaultSerList!=null && !defaultSerList.contains(tmpServ))
							{
								ServicesToSkipList.remove(tmpServ);
								isSkipUpdate = true;
							}
						}
					}

					for(int k=0;k<defaultSerList.size();k++)
					{
						String tmpServ = (String)defaultSerList.get(k);
						if(ServicesToSkipList!=null && tmpServ!=null && !ServicesToSkipList.contains(tmpServ) && !servicesReorderList.contains(tmpServ))
						{
							servicesReorderList.add(tmpServ);
							isReoderUpdate = true;
						}
					}
					if(iniSerReordSkip!=null)
					{
						if(isReoderUpdate)
						{
							StringBuffer tmpReordList = new StringBuffer();
							for(int k=0;k<servicesReorderList.size();k++)
							{
								String tmpServ = (String)servicesReorderList.get(k);
								tmpReordList.append(tmpServ);
								tmpReordList.append(",");
							}
							String tmpSrvReord = tmpReordList.toString();
							if(tmpSrvReord!=null && tmpSrvReord.lastIndexOf(",")>-1)
								tmpSrvReord = tmpSrvReord.substring(0,tmpSrvReord.lastIndexOf(","));
							
							iniSerReordSkip.setValue("Services_User_Config",user_name+":ServicesReorder",tmpSrvReord);
							iniSerReordSkip.saveFile();
						}
						else if(isSkipUpdate)
						{
							StringBuffer tmpReordList = new StringBuffer();
							for(int k=0;k<ServicesToSkipList.size();k++)
							{
								String tmpServ = (String)ServicesToSkipList.get(k);
								tmpReordList.append(tmpServ);
								tmpReordList.append(",");
							}
							
							String tmpSrvReord = tmpReordList.toString();
							if(tmpSrvReord!=null && tmpSrvReord.lastIndexOf(",")>-1)
								tmpSrvReord = tmpSrvReord.substring(0,tmpSrvReord.lastIndexOf(","));
							
							iniSerReordSkip.setValue("Services_User_Config",user_name+":ServicesToSkip",tmpSrvReord);
							iniSerReordSkip.saveFile();
						}
					} 
				
				for(int sr=0;sr <servicesReorderList.size();sr++)
				{
					String service_reoroder = (String)servicesReorderList.get(sr);
					for(int ik = 0; ik < r.serviceList.size() ; ik++)
					{
						service = (EgService) r.serviceList.get(ik);
						String service_name=(String)service.getName();
						if(service_reoroder!=null && service_name!=null && service_reoroder.equals(service_name))
						{
							tmpServList.add(service);
							break;
						}
					}
				}
			}
			else
			{
				tmpServList = r.serviceList;
			}
			for(i = 0; i < tmpServList.size(); i++)//service loop start here
			{
				JSONObject serviceDataJson = new JSONObject();

				boolean isSite=false;
				boolean isAggSite=false;

				//service = (EgService) r.serviceList.get(i);
				service = (EgService) tmpServList.get(i);
				String site_name="NULL";
				String service_name=(String)service.getName();
				if((isEnableServiceSkipReorder) && service_name!=null && (ServicesToSkipList!=null && ServicesToSkipList.contains(service_name)))
				{
					cnt++;
					continue;
				}
				String siteText="";
				if(service.isSite())
				{
					isSite = true;
					site_name = service_name;
					isAggSite = aggInfo.isAggregateSite(site_name);
					
					siteText="(Site)";
				}

				String spc_domain_value=topoIni.getValue("SERVICE_DOMAIN",service_name);
				ArrayList commonNCtsList = new ArrayList();
				ArrayList commonACtsList = new ArrayList();
				if(spc_domain_value!=null && spc_domain_value.trim().length()>0)
				{
					String tmp_common_ncts=(String)serviceDashIni.getValue("Service_Types",spc_domain_value);
					if(tmp_common_ncts!=null && tmp_common_ncts.trim().length()>0)
					{
						commonNCtsList = StringUtils.egTokenizer(tmp_common_ncts, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
					}

					String tmp_common_acts=(String)serviceDashIni.getValue("Aggregate:Service_Types",spc_domain_value);
					if(tmp_common_acts!=null && tmp_common_acts.trim().length()>0)
					{
						commonACtsList = StringUtils.egTokenizer(tmp_common_acts, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
					}
				}

				ArrayList finalCompTypeList = new ArrayList();
				ArrayList finalNCompTypeList = new ArrayList();
				Hashtable compHash = new Hashtable();

				boolean isDemandAggSiteService=false;
				boolean isConsAggSiteService=false;
				boolean isQualityAggSiteService=false;
				boolean isAggSiteService=false;
				boolean isDemandAgg=false;
				boolean isConsAgg=false;
				boolean isQualityAgg=false;

				ArrayList aggCompAssList=new ArrayList();
				ArrayList aggCompTypeAssList=new ArrayList();
				if(aggCompAssHash!=null && aggCompAssHash.size()>0)
				{
					String agg_site_map=service_name;
					if(isAggSite)
					{
						agg_site_map=topoIni.getValue("AGG_SITE_MAP",service_name);
					}
					aggCompAssList=(ArrayList)aggCompAssHash.get("service#"+agg_site_map);
					aggCompTypeAssList=(ArrayList)aggCompAssTypeHash.get("service#"+agg_site_map);
				}
				
				if(aggCompAssList!=null && aggCompAssList.size()>0)
				{
					if(commonACtsList!=null && commonACtsList.size()>0)
					{
						for(int x=0;x<commonACtsList.size();x++)
						{
							String tmp_ct_str=(String)commonACtsList.get(x);
							if(tmp_ct_str!=null && tmp_ct_str.trim().length()>0 && aggCompTypeAssList!=null && aggCompTypeAssList.contains(tmp_ct_str))
							{
								isDemandAggSiteService = true;
								isConsAggSiteService = true;
								isQualityAggSiteService = true;
								isAggSiteService = true;

								/*if(aggCompTypeAssList!=null && aggCompTypeAssList.size()>0)
								{
									finalCompTypeList.addAll(aggCompTypeAssList);
								}*/
								finalCompTypeList.add(tmp_ct_str);
								break;
							}
						}
					}
				}

				EgComponentList componentList = null;
				EgList egList = null;

				if(r.displayCompType)
				{
					egList = servicesBean.getComponentsForSelection("services",service_name,"");
				}
				else
				{
					componentList = service.getComponentList();
				}

				List info_HIGH_list=new LinkedList();
				List info_INTER_list=new LinkedList();
				List info_LOW_list=new LinkedList();
				List info_UNKNOWN_list=new LinkedList();
				List info_GOOD_list=new LinkedList();
				Vector aList_info=new Vector();

				if(componentList != null || egList!=null)
				{
					int comp_count = 0;
					if(r.displayCompType)
					{
						comp_count = egList.size();
					}
					else
					{
						comp_count =  componentList.size();
					}

					for(j = 0; j < comp_count; j++)
					{
						EgComponent component = null;
						if(r.displayCompType)
						{
							component = (EgComponent) egList.get(j);
						}
						else
						{
							component = (EgComponent) componentList.get(j);
						}
						if(component!=null)
						{
							String serverName = component.getName();
							String serverType = component.getType();
							
							//if(aggCompAssList==null || aggCompAssList.size()==0)
							{
								if(serverType!=null && (!serverType.startsWith("Agg_")))
								{
									if(finalNCompTypeList!=null && serverType!=null && !finalNCompTypeList.contains(serverType))
									{
										// && commonNCtsList!=null && commonNCtsList.contains(serverType)
										finalNCompTypeList.add(serverType);
									}

									if(serverType!=null && (aggCompAssList==null || aggCompAssList.size()==0) && commonNCtsList!=null && commonNCtsList.contains(serverType))
									{
										if(finalCompTypeList!=null && serverType!=null && !finalCompTypeList.contains(serverType))
										{
											finalCompTypeList.add(serverType);
										}
									}

									if(compHash.size()==0)
									{
										ArrayList temp=new ArrayList();
										temp.add(serverType+":"+serverName);
										compHash.put(serverType,(ArrayList)temp);
									}
									else if(compHash.size()>0)
									{
										if(compHash.containsKey(serverType))
										{
											ArrayList temp=(ArrayList)compHash.get(new String(serverType));
											temp.add(serverType+":"+serverName);
											compHash.put(serverType,(ArrayList)temp);
										}
										else
										{
											ArrayList temp=new ArrayList();
											temp.add(serverType+":"+serverName);
											compHash.put(serverType,(ArrayList)temp);
										}
									}
								}
							}

							String state_value = (String)component.getState().getName();
							String serverDispType= mappingInfo.getComponentTypeDescription(serverType);
							if(state_value!=null && state_value.equalsIgnoreCase("HIGH") && !info_HIGH_list.contains(serverDispType))
							{
								info_HIGH_list.add(serverDispType);
								info_HIGH_list.add(serverDispType+"^HIGH");
								info_HIGH_list.add(serverType);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("INTERMEDIATE") && !info_INTER_list.contains(serverDispType))
							{
								info_INTER_list.add(serverDispType);
								info_INTER_list.add(serverDispType+"^INTERMEDIATE");
								info_INTER_list.add(serverType);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("LOW") && !info_LOW_list.contains(serverDispType))
							{
								info_LOW_list.add(serverDispType);
								info_LOW_list.add(serverDispType+"^LOW");
								info_LOW_list.add(serverType);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("UNKNOWN") && !info_UNKNOWN_list.contains(serverDispType))
							{
								info_UNKNOWN_list.add(serverDispType);
								info_UNKNOWN_list.add(serverDispType+"^UNKNOWN");
								info_UNKNOWN_list.add(serverType);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("GOOD") && !info_GOOD_list.contains(serverDispType))
							{
								info_GOOD_list.add(serverDispType);
								info_GOOD_list.add(serverDispType+"^GOOD");
								info_GOOD_list.add(serverType);
							}
						}
					}

					if(info_HIGH_list!=null && info_HIGH_list.size()>0)
					{
						EgSorter esort=new EgSorter(info_HIGH_list,3);
						info_HIGH_list=esort.sort(1,"String","asc");
						aList_info.addAll(info_HIGH_list);
					}
					if(info_INTER_list!=null && info_INTER_list.size()>0)
					{
						EgSorter esort=new EgSorter(info_INTER_list,3);
						info_INTER_list=esort.sort(1,"String","asc");
						aList_info.addAll(info_INTER_list);
					}
					if(info_LOW_list!=null && info_LOW_list.size()>0)
					{
						EgSorter esort=new EgSorter(info_LOW_list,3);
						info_LOW_list=esort.sort(1,"String","asc");
						aList_info.addAll(info_LOW_list);
					}
					if(info_UNKNOWN_list!=null && info_UNKNOWN_list.size()>0)
					{
						EgSorter esort=new EgSorter(info_UNKNOWN_list,3);
						info_UNKNOWN_list=esort.sort(1,"String","asc");
						aList_info.addAll(info_UNKNOWN_list);
					}
					if(info_GOOD_list!=null && info_GOOD_list.size()>0)
					{
						EgSorter esort=new EgSorter(info_GOOD_list,3);
						info_GOOD_list=esort.sort(1,"String","asc");
						aList_info.addAll(info_GOOD_list);
					}
				}

				ArrayList demandctypeList = new ArrayList();
				ArrayList consumptionCtypeList = new ArrayList();
				ArrayList qualityCtypeList = new ArrayList();

				ArrayList demandTestMeaList = new ArrayList();
				ArrayList consumptionTestMeaList = new ArrayList();
				ArrayList qualityTestMeaList = new ArrayList();

				ArrayList demandTestList = new ArrayList();
				ArrayList consumptionTestList = new ArrayList();
				ArrayList qualityTestList = new ArrayList();

				ArrayList demandTestWithMeaList = new ArrayList();
				ArrayList consumptionTestWithMeaList = new ArrayList();
				ArrayList qualityTestWithMeaList = new ArrayList();

				Hashtable selectedDemandCompHash=new Hashtable();
				Hashtable selectedConsumptionCompHash=new Hashtable();
				Hashtable selectedQualityCompHash=new Hashtable();
				String demand_sub="";
				String consumption_sub="";
				String quality_sub="";

				String demand_spc_values=serviceDashIni.getValue("Demand_Specific",user_name+":"+service_name);
				String consum_spc_values=serviceDashIni.getValue("Consumption_Specific",user_name+":"+service_name);
				String quality_spc_values=serviceDashIni.getValue("Quality_Specific",user_name+":"+service_name);

				if(demand_spc_values!=null && demand_spc_values.trim().length()>0)
				{
					if(finalNCompTypeList!=null && finalNCompTypeList.size()>0)
						finalCompTypeList.addAll(finalNCompTypeList);

					ArrayList res_list=(ArrayList)splitSpecificSubject(showMaxDemand,finalCompTypeList,demand_spc_values,specsInfo,demandctypeList,demandTestList,demandTestMeaList,demandTestWithMeaList);

					if(res_list!=null && res_list.size()>0)
					{
						demandctypeList=(ArrayList)res_list.get(0);
						demandTestList=(ArrayList)res_list.get(1);
						demandTestMeaList=(ArrayList)res_list.get(2);
						demandTestWithMeaList=(ArrayList)res_list.get(3);

						if(isAggSiteService && demandctypeList!=null && demandctypeList.size()>0)
						{
							int countAgg=0;
							for(int q = 0; q < demandctypeList.size(); q++)
							{
								String cl=(String)demandctypeList.get(q);
								if(cl!=null && cl.startsWith("Agg_"))
									countAgg++;
							}

							if(countAgg==0)
								isDemandAgg=false;
							else if(countAgg>0)
								isDemandAgg=true;
						}
					}
				}
				else
				{
					//if((demandTestWithMeaList.size() < showMaxDemand))
					{
						demand_sub="Demand";
						ArrayList res_list=(ArrayList)splitCommonSubject(isAggSiteService,showMaxDemand,finalCompTypeList,demand_sub,serviceDashIni,specsInfo,demandctypeList,demandTestList,demandTestMeaList,demandTestWithMeaList,spc_domain_value);

						if(res_list!=null && res_list.size()>0)
						{
							demandctypeList=(ArrayList)res_list.get(0);
							demandTestList=(ArrayList)res_list.get(1);
							demandTestMeaList=(ArrayList)res_list.get(2);
							demandTestWithMeaList=(ArrayList)res_list.get(3);
							
						}
						isDemandAgg=true;
					}
				}

				if(consum_spc_values!=null && consum_spc_values.trim().length()>0)
				{
					if(finalNCompTypeList!=null && finalNCompTypeList.size()>0)
						finalCompTypeList.addAll(finalNCompTypeList);

					ArrayList res_list=(ArrayList)splitSpecificSubject(showMaxConsumption,finalCompTypeList,consum_spc_values,specsInfo,consumptionCtypeList,consumptionTestList,consumptionTestMeaList,consumptionTestWithMeaList);

					if(res_list!=null && res_list.size()>0)
					{
						consumptionCtypeList=(ArrayList)res_list.get(0);
						consumptionTestList=(ArrayList)res_list.get(1);
						consumptionTestMeaList=(ArrayList)res_list.get(2);
						consumptionTestWithMeaList=(ArrayList)res_list.get(3);

						if(isAggSiteService && consumptionCtypeList!=null && consumptionCtypeList.size()>0)
						{
							int countAgg=0;
							for(int q = 0; q < consumptionCtypeList.size(); q++)
							{
								String cl=(String)consumptionCtypeList.get(q);
								if(cl!=null && cl.startsWith("Agg_"))
									countAgg++;
							}

							if(countAgg==0)
								isConsAgg=false;
							else if(countAgg>0)
								isConsAgg=true;
						}
					}
				}
				else
				{
					//if(consumptionTestWithMeaList.size() < showMaxConsumption)
					{
						consumption_sub="Consumption";
						ArrayList res_list=(ArrayList)splitCommonSubject(isAggSiteService,showMaxConsumption,finalCompTypeList,consumption_sub,serviceDashIni,specsInfo,consumptionCtypeList,consumptionTestList,consumptionTestMeaList,consumptionTestWithMeaList,spc_domain_value);
						if(res_list!=null && res_list.size()>0)
						{
							consumptionCtypeList=(ArrayList)res_list.get(0);
							consumptionTestList=(ArrayList)res_list.get(1);
							consumptionTestMeaList=(ArrayList)res_list.get(2);
							consumptionTestWithMeaList=(ArrayList)res_list.get(3);
						}
						isConsAgg=true;
					}
				}

				if(quality_spc_values!=null && quality_spc_values.trim().length()>0)
				{
					if(finalNCompTypeList!=null && finalNCompTypeList.size()>0)
						finalCompTypeList.addAll(finalNCompTypeList);

					ArrayList res_list=(ArrayList)splitSpecificSubject(showMaxQuality,finalCompTypeList,quality_spc_values,specsInfo,qualityCtypeList,qualityTestList,qualityTestMeaList,qualityTestWithMeaList);
					if(res_list!=null && res_list.size()>0)
					{
						qualityCtypeList=(ArrayList)res_list.get(0);
						qualityTestList=(ArrayList)res_list.get(1);
						qualityTestMeaList=(ArrayList)res_list.get(2);
						qualityTestWithMeaList=(ArrayList)res_list.get(3);

						if(isAggSiteService && qualityCtypeList!=null && qualityCtypeList.size()>0)
						{
							int countAgg=0;
							for(int q = 0; q < qualityCtypeList.size(); q++)
							{
								String cl=(String)qualityCtypeList.get(q);
								if(cl!=null && cl.startsWith("Agg_"))
									countAgg++;
							}

							if(countAgg==0)
								isQualityAgg=false;
							else if(countAgg>0)
								isQualityAgg=true;
						}
					}
				}
				else
				{
					//if(qualityTestWithMeaList.size() < showMaxQuality)
					{
						quality_sub="Quality";
						ArrayList res_list=(ArrayList)splitCommonSubject(isAggSiteService,showMaxQuality,finalCompTypeList,quality_sub,serviceDashIni,specsInfo,qualityCtypeList,qualityTestList,qualityTestMeaList,qualityTestWithMeaList,spc_domain_value);
						if(res_list!=null && res_list.size()>0)
						{
							qualityCtypeList=(ArrayList)res_list.get(0);
							qualityTestList=(ArrayList)res_list.get(1);
							qualityTestMeaList=(ArrayList)res_list.get(2);
							qualityTestWithMeaList=(ArrayList)res_list.get(3);
						}
						isQualityAgg=true;
					}
				}

				String agg_site_map="";
				if(isAggSiteService && (isDemandAgg || isConsAgg || isQualityAgg))
				{
					ArrayList anchorCompList=new ArrayList();
					if(anchorHash!=null && anchorHash.size()>0)
					{
						agg_site_map=service_name;
						if(isAggSite)
						{
							agg_site_map=topoIni.getValue("AGG_SITE_MAP",service_name);
						}
						else if(isSite)
						{
							ArrayList siteMapList=(ArrayList)aggSiteMapHash.get(agg_site_map);
							if(siteMapList!=null && siteMapList.size()>0)
							{
								site_name=(String)siteMapList.get(0);
							}
						}
						anchorCompList=(ArrayList)anchorHash.get("service#"+agg_site_map);
					}

					if(anchorCompList!=null && anchorCompList.size()>0)
					{
						Hashtable res_hash=new Hashtable();
						
						res_hash=(Hashtable)getComponentHash((ArrayList)anchorCompList,demandctypeList);
						if(res_hash!=null && res_hash.size()>0)
						{
							selectedDemandCompHash.putAll(res_hash);
						}

						res_hash=new Hashtable();
						res_hash=(Hashtable)getComponentHash((ArrayList)anchorCompList,consumptionCtypeList);
						if(res_hash!=null && res_hash.size()>0)
						{
							selectedConsumptionCompHash.putAll(res_hash);
						}

						res_hash=new Hashtable();
						
						res_hash=(Hashtable)getComponentHash((ArrayList)anchorCompList,qualityCtypeList);
						if(res_hash!=null && res_hash.size()>0)
						{
							selectedQualityCompHash.putAll(res_hash);
						}
					}
				}
				else
				{
					Object inList=null;
					if(r.displayCompType)
					{
						inList=(EgList)egList;
					}
					else
					{
						inList=(EgComponentList)componentList;
					}

					Hashtable res_hash=new Hashtable();
					res_hash=(Hashtable)getComponentHash(inList,demandctypeList);
					if(res_hash!=null && res_hash.size()>0)
					{
						selectedDemandCompHash.putAll(res_hash);
					}
					res_hash=new Hashtable();
					res_hash=(Hashtable)getComponentHash(inList,consumptionCtypeList);
					if(res_hash!=null && res_hash.size()>0)
					{
						selectedConsumptionCompHash.putAll(res_hash);
					}

					res_hash=new Hashtable();
					res_hash=(Hashtable)getComponentHash(inList,qualityCtypeList);
					if(res_hash!=null && res_hash.size()>0)
					{
						selectedQualityCompHash.putAll(res_hash);
					}
				}

				Vector compVec = topoInfo.getAssociatesForSite(service_name);
				boolean isEmulTrans = false;
				for(int k=0; k<compVec.size(); k++)
				{
					String comp =(String) compVec.get(k);
					if(comp!=null && comp.indexOf("Emulated")>-1)
					{
						isEmulTrans = true;
						break;
					}
				}
				String bg_style="";
				if(i%2==0)
					bg_style="businessRowBg";
				else
					bg_style="businessRowBgAlter";

				//String service_url="/final/monitor/servicePerformanceDetailsMain.jsp?treeFlag="+treeFlag+"&outsideService=true&titleText=Services&selectNode=Service^"+EgURLEncoder.encode(service_name,"UTF-8") +siteText+"&serviceFromZone="+EgURLEncoder.encode(service_name,"UTF-8")+"&isEmulTrans="+isEmulTrans+"&serviceName="+EgURLEncoder.encode(service_name,"UTF-8")+"&serviceState="+service.getState().getName();
				String en_service_name = com.egurkha.util.StringUtils.encodeSecurityChar(service_name);
				String service_url="/final/monitor/serviceBusinessDetailsMain.jsp?treeFlag="+treeFlag+"&outsideService=true&titleText=Services&selectNode="+EgURLEncoder.encode("Service^"+en_service_name,"UTF-8") +siteText+"&serviceFromZone="+EgURLEncoder.encode(en_service_name,"UTF-8")+"&isEmulTrans="+isEmulTrans+"&serviceName="+EgURLEncoder.encode(en_service_name,"UTF-8")+"&serviceState="+service.getState().getName()+"&isServiceBusiDash="+isServiceBusiDash;

				serviceDataJson.put("service_name",service_name);
				serviceDataJson.put("service_state",service.getState().getName());
				if(ifshowImage)
				{
					serviceDataJson.put("showImage","true");

					String service_image=(String)topoInfo.getValue("SERVICE_DISPLAY_IMAGE",service_name);

					if(service_image!=null && service_image.endsWith("Small"))
					{
						service_image=service_image.substring(0,service_image.lastIndexOf("S"));
					}

					serviceDataJson.put("service_image",service_image+"48");
				}

				serviceDataJson.put("service_url",service_url);

				String service_dash_url="";

				service_dash_url="/final/monitor/serviceDashboard.jsp?treeFlag="+treeFlag+"&outsideService=true&titleText=Services&selectNode=Service^"+EgURLEncoder.encode(en_service_name,"UTF-8") +siteText+"&serviceFromZone="+EgURLEncoder.encode(en_service_name,"UTF-8")+"&isEmulTrans="+isEmulTrans+"&currentTab=performance&selectedParam="+EgURLEncoder.encode(service_name,"UTF-8");

				serviceDataJson.put("service_disp_name",service_name);
				serviceDataJson.put("service_dash_url",service_dash_url);

				String service_disp_site="";
				if(isSite)
				{
					service_disp_site="("+mappingInfo.getTextDescription("monitor.services.Site")+")";
				}
				serviceDataJson.put("service_disp_site",service_disp_site);

/*-------------------Demand-----------------------------------------------*/
				String nick_name ="";
				String test_measure ="";
				String test_name="";
				String measure_name="";
				String db_measure="";
				String s_dispName="";
				String temp_unit="";
				String temp_Or="";
				String tokens[] = null;
				String unitForMeasure="";

				JSONArray serviceDemandDataArr = new JSONArray();

				if(selectedDemandCompHash!=null && selectedDemandCompHash.size()>0 && demandctypeList!=null && demandctypeList.size()>0)
				{
					JSONObject serviceDemandDataJson = new JSONObject();

					int loopTotND=demandTestMeaList.size();
					Hashtable resultHash=new Hashtable();
					resultHash=(Hashtable)servicesBean.getServicePerformanceDashData(demandctypeList,selectedDemandCompHash,demandTestMeaList,site_name,false);
					List slist=new LinkedList();
					if(resultHash!=null && resultHash.size()>0)
					{
						slist=(List)getSortedList(resultHash,"desc");
						//loopTotND=slist.size();
					}
					ArrayList key_unit_list=new ArrayList();
					ArrayList only_key_unit_list=new ArrayList();
					ArrayList only_key_list=new ArrayList();
					ArrayList key_info_list=new ArrayList();
					ArrayList key_testmea_list=new ArrayList();
					boolean infoFlage=false;
					boolean isDescriptor=false;
					boolean sameKeyFlage=false;
					String infoTest="";
					if(slist!=null && slist.size()>0)
					{
						for(int zz=0;zz<slist.size();zz++)
						{
							String str_key=(String)slist.get(zz);
							if(str_key!=null && str_key.endsWith("_Value"))
								continue;
							String key_unit=str_key.substring(str_key.lastIndexOf(":")+1);
							String only_key=str_key.substring(0,str_key.lastIndexOf(":"));
							String key_info=null;
							if(str_key!=null && str_key.indexOf("~")>-1)
							{
								key_info=str_key.substring(str_key.indexOf("~")+1);
							}
							if(key_info!=null && key_info.trim().length()>0)
							{
								String only_key_info="";
								String only_key_unit="";
								if(key_info.indexOf(":")>-1)
								{
									only_key_info=key_info.substring(0,key_info.lastIndexOf(":"));
									only_key_unit=key_info.substring(key_info.lastIndexOf(":")+1);
									
									infoTest=str_key.substring(0,str_key.indexOf(":"));
									String test_mea=str_key.substring(0,str_key.indexOf("~"));
									if(test_mea!=null && test_mea.trim().length()>0 && !key_testmea_list.contains(test_mea))
									{
										key_testmea_list.add(test_mea);
									}

									if(showDescriptorsList!=null && infoTest!=null && showDescriptorsList.contains(infoTest))
									{
										infoFlage=true;
										String Caption=(String)serviceDashIni.getValue("Show_Descriptors",infoTest);
										if(Caption!=null && Caption.equalsIgnoreCase("Descriptors"))
											isDescriptor=true;
									}
								}

								if(!key_unit_list.contains(key_info))
									key_unit_list.add(key_info);

								if(!only_key_unit_list.contains(only_key_unit))
									only_key_unit_list.add(only_key_unit);

								if(only_key_info!=null && only_key_info.trim().length()>0 && !key_info_list.contains(only_key_info))
									key_info_list.add(only_key_info);
							}
							else if(key_unit!=null)
							{
								if(!key_unit_list.contains(key_unit))
									key_unit_list.add(key_unit);

								if(!only_key_unit_list.contains(key_unit))
									only_key_unit_list.add(key_unit);
							}

							if(only_key_list!=null && !only_key_list.contains(only_key))
							{
								only_key_list.add(only_key);
							}
							else if(only_key_list!=null && only_key_list.contains(only_key))
							{
								sameKeyFlage = true;
							}
						}
					}

					if(key_unit_list==null)
					{
						key_unit_list = new ArrayList();
					}

					if(infoFlage)
					{
						JSONObject minMaxTable = new JSONObject();
						JSONArray minMaxTableHeadersArray = new JSONArray();
						if(!(key_unit_list.size()==1 && key_testmea_list.size()==1))
						{
							String displyText=(String)serviceDashIni.getValue("Show_Descriptors",infoTest);
							displyText=(displyText==null || displyText.trim().length()==0)?"Descriptors":displyText;

							JSONObject descHeader = new JSONObject();
							descHeader.put("name",mappingInfo.getTextDescription("monitor.VirtualDashboard."+displyText));
							descHeader.put("width","15");
							descHeader.put("textType","string");
							minMaxTableHeadersArray.add(descHeader);

							for(int zz=0;zz<key_testmea_list.size();zz++)
							{
								//String str_test_mea=(String)key_testmea_list.get(zz);
								String str_test_mea=(String)demandTestWithMeaList.get(zz);
								if(str_test_mea!=null && str_test_mea.trim().length()>0)
								{
									String str_test_name=(String)str_test_mea.substring(0,str_test_mea.indexOf(":"));
									//String str_dbmea_name=str_test_mea.substring(str_test_mea.indexOf(":")+1);
									String normal_measure=str_test_mea.substring(str_test_mea.indexOf(":")+1);
									String display_text="";
									if(normal_measure!=null && normal_measure.indexOf(":")>-1)
									{
										display_text=normal_measure.substring(normal_measure.indexOf(":")+1);
										normal_measure=normal_measure.substring(0,normal_measure.indexOf(":"));
									}
									//String normal_measure = dbInfo.getMeasureForColumn(str_test_name,str_dbmea_name);
									String mappingString=str_test_name+":"+normal_measure;
									String un=tablesInfo.getUnitForMeasure(str_test_name,normal_measure);

									JSONObject measHeader = new JSONObject();

									if(display_text==null || display_text.trim().length()==0)
									{
										measHeader.put("name",mappingInfo.getMeasureDescription(str_test_name,normal_measure));
										measHeader.put("width","15");
										measHeader.put("textType","asFloat");
									}
									else
									{
										measHeader.put("name",display_text);
										measHeader.put("width","15");
										measHeader.put("textType","asFloat");
									}

									minMaxTableHeadersArray.add(measHeader);
								}
							}

							minMaxTable.put("minMaxTableHeadersArray",minMaxTableHeadersArray);
						}
						String descri_info="+";
						if(resultHash!=null && resultHash.size()>0 && loopTotND>0 && key_unit_list!=null && key_unit_list.size()>0)
						{
							int count_else_loop=0;
							ArrayList temp_dummy_list=new ArrayList();
							String sep="~";
							if(key_unit_list.size()>1)
							{
								ArrayList temp_key_unit_list=(ArrayList)getStateSortedList(key_unit_list,demandTestMeaList,selectedDemandCompHash,stateMeasure);
								if(temp_key_unit_list!=null && temp_key_unit_list.size()>0)
								{
									key_unit_list = new ArrayList();
									key_unit_list.addAll(temp_key_unit_list);
								}
							}
							JSONArray minMaxTableDataArray = new JSONArray();
							
							//for(int kk=0;kk<key_unit_list.size() && kk < showTopNInfos;kk++)
							for(int kk=0;kk<key_unit_list.size();kk++)
							{
								String str_unit=(String)key_unit_list.get(kk);
								String url_descri_info="";
								if(sep!=null && sep.equals("~"))
								{
									if(str_unit!=null && !str_unit.equals("") && str_unit.indexOf(":") > -1 )
										descri_info=(String)str_unit.substring(0,str_unit.indexOf(":"));
									else
												descri_info=str_unit;
									if(descri_info!=null && descri_info.trim().length()>0 && descri_info.startsWith("+"))
									{
										url_descri_info=descri_info.substring(1);
									}
								}
								boolean flage_tr=true;
								for(int zz=0;zz<loopTotND;zz++)
								{
									String selected_dem_tier="";
									String demand_test_measure="";
									String selected_dem_tier_with_all=(String)demandTestMeaList.get(zz);
									if(selected_dem_tier_with_all!=null && selected_dem_tier_with_all.length()>0)
									{
										selected_dem_tier=selected_dem_tier_with_all.substring(0,selected_dem_tier_with_all.indexOf(":"));

										if(selected_dem_tier!=null && selected_dem_tier.startsWith("CT^"))
										{
											selected_dem_tier=selected_dem_tier.substring(selected_dem_tier.indexOf("^")+1);
										}

										demand_test_measure=selected_dem_tier_with_all.substring(selected_dem_tier_with_all.indexOf(":")+1);
									}

									if(demand_test_measure!=null && demand_test_measure.trim().length()>0)
									{
										test_measure = demand_test_measure;
										test_name="";
										measure_name="";
										db_measure="";
										s_dispName="";
										temp_unit="";
										temp_Or="";
										unitForMeasure="";
										String unit_k="";
										tokens = StringUtils.getTokens(test_measure,":");
										if(tokens!=null && tokens.length>1)
										{
											int inx=0;
											if(tokens.length==5)
											{
												nick_name=tokens[inx++];
												if(nick_name!=null && nick_name.startsWith("CN^"))
												{
													nick_name=nick_name.substring(nick_name.indexOf("^")+1);
												}
											}
											test_name = tokens[inx++];
											measure_name = tokens[inx++];
											db_measure = dbInfo.getColumnForMeasure(test_name,measure_name);
											if(db_measure==null || db_measure.trim().length()==0)
												db_measure=measure_name;
											if(tokens.length > 2)
											{
												s_dispName = tokens[inx++];
											}
											if(tokens.length > 3)
											{
												//temp_unit=tokens[inx++];
												temp_Or=tokens[inx++];
												ArrayList orAlist = StringUtils.egTokenizer(temp_Or,"~",false,true,true);
												if(orAlist!=null && orAlist.size()==2)
												{
													temp_Or=(String)orAlist.get(1);
												}
											}
										}
										if(test_name!=null && measure_name!=null && measure_name.trim().length()>0 && test_name.trim().length()>0)
										{
											if(s_dispName==null || s_dispName.trim().length()==0)
												s_dispName = mappingInfo.getMeasureDescription(test_name,measure_name);

											if(temp_unit==null || temp_unit.trim().length()==0)
											{
												String un=tablesInfo.getUnitForMeasure(test_name,measure_name);
												unit_k=un;
												if(un!=null && un.equals("MB"))
													un="GB";
												if(un.equals("Number"))
													un="No.";
												unitForMeasure="("+un+")";
												
											}
											else if(temp_unit!=null && temp_unit.trim().length()>0)
											{
												unit_k=temp_unit;
												unitForMeasure="("+temp_unit+")";
											}
										}
										String key_comp1=test_name+":"+db_measure;

										if(slist!=null)
										{
											boolean flage_continue=true;
											
											for(int kk2=0;kk2<key_unit_list.size();kk2++)
											{
												String str_unit2=(String)key_unit_list.get(kk2);
												if(slist.contains(key_comp1+sep+str_unit2))
												{
													flage_continue=false;
													temp_dummy_list.add(key_comp1+sep+str_unit2);
												}
											}
											if(flage_continue)
												continue;
										}
										else if(temp_dummy_list!=null && temp_dummy_list.contains(key_comp1+sep+str_unit))
										{
											continue;
										}
										
										//temp_dummy_list.add(key_comp1);
										String measure_value=(String)resultHash.get(key_comp1+sep+str_unit);
										if(measure_value==null || measure_value.trim().length()==0)
											measure_value=(String)resultHash.get(key_comp1);

										String url_for_graph="";
										String comp="";
										String host_type="";
										String host_name="";
										String port="";
										String sid="";
										String msmtHost="";
										String comp_name="";
										String state_value="GRAY";
										String layerName="";
										String url_for_layermodel="";
										String class_mouse="mouse";
										String state_display="";
										ArrayList selectedDemandCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier);

										ArrayList selectedDemandOrgCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier+"_real");

										//if(isDemandAggSiteService || (selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()==1))
										if(isDemandAggSiteService || (selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()>0))
										{
											Hashtable temp_state_hash=new Hashtable();
											for(int f=0;f<selectedDemandOrgCompList.size();f++)
											{
												comp = (String)selectedDemandOrgCompList.get(f);

												String comp_tokens[] = StringUtils.getTokens(comp,":");
												
												if(comp_tokens!=null && comp_tokens.length>1)
												{
													host_type = comp_tokens[0];
													host_name = comp_tokens[1];
													comp_name=host_name;
													if(comp_tokens.length > 2)
													{
														port = comp_tokens[2];
														if(specsInfo.isPortRelevantForTest(test_name))
														{
															comp_name=comp_name+":"+port;
														}
														else
														{
															comp_name=comp_name+":NULL";
														}
													}
													if(comp_tokens.length > 3)
													{
														sid=comp_tokens[3];
														comp_name=comp_name+":"+sid;
													}
												}
												ArrayList layersOfComp = new ArrayList();
												layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_dem_tier);
												String Layer_name_str=tablesInfo.getLayerForTest(test_name);
												layerName="HOST";
												if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
												{
													StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
													if(tokenLayer!=null)
													{
														while(tokenLayer.hasMoreTokens())
														{
															String l_name=(String)tokenLayer.nextToken();
															if(l_name!=null)
															{
																if(layersOfComp != null && layersOfComp.contains(l_name))
																{
																	if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
																	{
																		layerName=l_name;
																		break;
																	}
																}
																else
																	continue;
															}
														}
													}
												}
												List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
												if(agents!=null && agents.size()>0)
													msmtHost=(String)agents.get(0);
												else
													msmtHost=host_name;
												
												//state_value=(String)servicesBean.getStateForMeasure(selected_dem_tier,comp_name,layerName,test_name,measure_name,descri_info,msmtHost);
												try
												{
													if(stateMeasure != null)
													{
														String temp_info=descri_info;
														if(!temp_info.startsWith("+"))
															temp_info="+"+temp_info;
														String state_key = "NULL^eg^"+selected_dem_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^"+temp_info+"^eg^"+measure_name;
														state_value = (String)stateMeasure.get(state_key);
													}
												}
												catch (Exception er)
												{
												}

												if(state_value==null || state_value.trim().length()==0)
													state_value="GOOD";

												if (EgConfigInfo.isBad(state_value))
												{
													state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_dem_tier,layerName,descri_info,test_name,msmtHost,measure_name,"");
												}

												String url_site="NULL";
												if(layerName.equals("WEB_SITE") || layerName.equals("WEB_TRANSACTIONS") || test_name.equals("WebSiteTest") || test_name.equals("WebSiteTransactionTest"))
												{
													url_site=site_name;
												}

												url_for_graph="gtype=yes&showRange=Range&mode=2D&info=*&monitorSkin="+monitor_Skin+"&gformat=graph&measure="+db_measure+"&test="+test_name+"&port="+port+"&site="+url_site+"&comptype="+host_type+"&host="+host_name+"&layer="+layerName+"&msmt_host="+msmtHost+"&width="+graphWidth+"&timeLine=1 hour&height=100&from_page=serviceOverview&threshold=no&from=cview&bgStyle="+bg_style+"&starttime=&endtime=&starthr=&endhr=";

												String display_c_name=comp_name;

												if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
												{
													display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
												}

												String displayComponentType = mappingInfo.getComponentTypeDescription(selected_dem_tier);
												
												String temp_compName = null;
												if(comp_name != null && port != null)
												{
													if(comp_name.indexOf(":") > -1)
														comp_name = comp_name.substring(0,comp_name.indexOf(":"));
													temp_compName = comp_name+":"+port;
												}

												url_for_layermodel="/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(temp_compName,"UTF-8")+"&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-"+EgURLEncoder.encode(url_descri_info,"UTF-8")+"&comptype="+EgURLEncoder.encode(selected_dem_tier,"UTF-8")+"&tstate="+EgURLEncoder.encode(state_value,"UTF-8")+"&newWindow=false&prevPage=MainDashBoard&isServiceBusiDash="+isServiceBusiDash;

												if(descri_info!=null && descri_info.equals("+"))
													url_for_layermodel=url_for_layermodel+"&findInfo=true";
											
												state_display=mappingInfo.getLabelDescription(state_value);

												if(state_value!=null && state_value.equalsIgnoreCase("HIGH"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("INTERMEDIATE"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("LOW"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("UNKNOWN"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("GOOD"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
											}

											if(temp_state_hash!=null && temp_state_hash.size()>0)
											{
												Enumeration keys=temp_state_hash.keys();
												ArrayList temp_state_ArrayList=new ArrayList();
												while(keys.hasMoreElements())
												{
													String hash_state = (String)keys.nextElement();
													temp_state_ArrayList.add(hash_state);
												}

												Object[] arrayInfoStateTemp=(Object[])temp_state_ArrayList.toArray();
												state_value  = (String)com.eg.EgAlarmTable.getHighestPriority(arrayInfoStateTemp);
												if(state_value!=null)
												{
													ArrayList temp_ArrayList=(ArrayList)temp_state_hash.get(state_value);
													state_display=(String)temp_ArrayList.get(1);
													url_for_layermodel=(String)temp_ArrayList.get(2);
													url_for_graph=(String)temp_ArrayList.get(3);
													msmtHost=(String)temp_ArrayList.get(4);
												}
											}
										}
										else
										{
											class_mouse="mouse";
											String actipnreq = request.getParameter("action");
											if(actipnreq.equalsIgnoreCase("service"))
												actipnreq = "services";
											url_for_layermodel="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&fromAcessPage=bussinessDashboard&from=bussinessDashboard&action=component&searchIndComps=checked&isFromMenu=false&view=metric&viewId=components&viewPageTitle=Components&viewTreeTitle=Component&filterBy="+actipnreq+"&subFilter="+service_name+"&componentType="+selected_dem_tier+"&isServiceBusiDash=true";
										}

										if(key_unit_list.size()==1 && key_testmea_list.size()==1 && descri_info.equals("+") && show_graph_flag)
										{
											Hashtable avgMinMaxData =new Hashtable();
											if(isShowGraphMAM)
											{
												avgMinMaxData =measureGraphInfo.getAvgMaxMinData(db_measure,test_name,host_name,port,site_name,descri_info,msmtHost,host_type,"1 hour",user);
											}
											String avg_str="-";
											String max_str="-";
											String min_str="-";
											String td_width="185";
											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												ArrayList meaList=(ArrayList)avgMinMaxData.get(measure_name+" ("+unit_k+")");
												if(meaList!=null && meaList.size()>0)
													avg_str=(String)meaList.get(0);
												if(meaList!=null && meaList.size()>1)
													max_str=(String)meaList.get(1);
												if(meaList!=null && meaList.size()>2)
													min_str=(String)meaList.get(2);
												td_width="100%";
											}
											minMaxTable.put("ChartId","dhigh_"+service_name+"_"+zz);

											minMaxTable.put("ChartName",s_dispName+unitForMeasure);
											minMaxTable.put("ChartURL",url_for_graph);
											minMaxTable.put("ChartTdWidth",td_width);
											minMaxTable.put("ChartURLForLM",url_for_layermodel);
											minMaxTable.put("ChartClass",class_mouse);

											minMaxTable.put("chartOption",chartOption);
											minMaxTable.put("chartTimeline",chartTimeline);

											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												minMaxTable.put("ChartState",mappingInfo.getTextDescription("monitor.measure.State"));
												minMaxTable.put("ChartAvg",mappingInfo.getTextDescription("monitor.measure.Avg"));
												minMaxTable.put("ChartMax",mappingInfo.getTextDescription("monitor.measure.Max"));
												minMaxTable.put("ChartMin",mappingInfo.getTextDescription("monitor.measure.Min"));

												minMaxTable.put("ChartStateVal",state_value);
												minMaxTable.put("ChartStateDisp",state_display);

												minMaxTable.put("ChartAvgVal",formatDbValue(avg_str));

												minMaxTable.put("ChartMaxVal",formatDbValue(max_str));
												minMaxTable.put("ChartMinVal",formatDbValue(min_str));
											}
										}
										else
										{
											JSONObject minMaxTableDataObject = new JSONObject();

											String disp_info="";
											if(infoFlage && str_unit!=null && str_unit.indexOf(":")>-1)
											{
												disp_info=str_unit.substring(0,str_unit.lastIndexOf(":"));
												if(disp_info.startsWith("+"))
													disp_info=disp_info.substring(1);
											}

											if(flage_tr)
											{
												flage_tr=false;
												String uri_site_name=service_name;
												if(isAggSiteService && isDemandAgg)
												{
													if(isAggSite && agg_site_map!=null && agg_site_map.trim().length()>0)
													{
														uri_site_name = agg_site_map;
													}
												}
												String trsn_img=(String)servicesBean.getDispTransImg(uri_site_name,disp_info);
												String disp_trans_img=trsn_img;
												if(disp_trans_img!=null && disp_trans_img.equals("image1"))
												{
													disp_trans_img="images";
												}

												minMaxTableDataObject.put("value0","trans_"+disp_trans_img+"_small");

												minMaxTableDataObject.put("value0_tip",mappingInfo.getTextDescription(iniIdentity+trsn_img));
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(disp_info));
												minMaxTableDataObject.put("value0_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_mouse",class_mouse);
											}
											if(!isShowStateColor)
												state_value = "GRAY";
											if(measure_value!=null && measure_value.length()>0)
											{
												minMaxTableDataObject.put("value1",formatDbValue(measure_value));
												minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
												minMaxTableDataObject.put("value1_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_state",state_value);
												minMaxTableDataObject.put("value1_mouse",class_mouse);

											}
											else
											{
												minMaxTableDataObject.put("value1","-");
												minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
											}
											if(loopTotND==(zz+1))
											{
												//-- ends tr
												minMaxTableDataObject.put("value1_endTR","true");
											}

											minMaxTableDataArray.add(minMaxTableDataObject);
										}
									}
									else
									{
										count_else_loop++;
									}
								}
							}
							
							if(count_else_loop==key_unit_list.size())
							{
								serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
							}
							else
							{
								if(minMaxTableDataArray!=null && minMaxTableDataArray.size()>0)
									minMaxTable.put("minMaxTableDataArray",minMaxTableDataArray);

								serviceDemandDataJson.put("minMaxTable",minMaxTable);
							}
						}
						else
						{
							serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
						}

						if(!(key_unit_list.size()==1 && key_testmea_list.size()==1 && descri_info.equals("+")))
						{
							//--old html table ends
							serviceDemandDataJson.put("endTable","true");
						}
					}
					else if(slist!=null && slist.size()>0)
					{
						boolean more_then_one=false;
						if(!(isDemandAggSiteService && ((demandTestWithMeaList!=null && demandTestWithMeaList.size()==1) || (slist.size()==1)) && demandctypeList!=null && demandctypeList.size()==1))
						{
							more_then_one=true;
							serviceDemandDataJson.put("more_then_one","true");
						}
						if(resultHash!=null && resultHash.size()>0 && loopTotND>0)
						{
							JSONObject minMaxTable = new JSONObject();
							JSONArray minMaxTableDataArray = new JSONArray();

							int count_else_loop=0;
							ArrayList temp_dummy_list=new ArrayList();
							for(int zz=0;zz<loopTotND;zz++)
							{
								String selected_dem_tier="";
								String demand_test_measure="";
								String selected_dem_tier_with_all=(String)demandTestMeaList.get(zz);
								if(selected_dem_tier_with_all!=null && selected_dem_tier_with_all.length()>0)
								{
									selected_dem_tier=selected_dem_tier_with_all.substring(0,selected_dem_tier_with_all.indexOf(":"));

									if(selected_dem_tier!=null && selected_dem_tier.startsWith("CT^"))
									{
										selected_dem_tier=selected_dem_tier.substring(selected_dem_tier.indexOf("^")+1);
									}

									demand_test_measure=selected_dem_tier_with_all.substring(selected_dem_tier_with_all.indexOf(":")+1);
								}
								if(demand_test_measure!=null && demand_test_measure.trim().length()>0)
								{
									test_measure = demand_test_measure;
									test_name="";
									measure_name="";
									db_measure="";
									s_dispName="";
									temp_unit="";
									temp_Or="";
									unitForMeasure="";
									String unit_k="";
									tokens = StringUtils.getTokens(test_measure,":");
									if(tokens!=null && tokens.length>1)
									{
										int inx=0;
										if(tokens.length==5)
										{
											nick_name=tokens[inx++];
											if(nick_name!=null && nick_name.startsWith("CN^"))
											{
												nick_name=nick_name.substring(nick_name.indexOf("^")+1);
											}
										}
										test_name = tokens[inx++];
										measure_name = tokens[inx++];
										db_measure = dbInfo.getColumnForMeasure(test_name,measure_name);
										if(db_measure==null || db_measure.trim().length()==0)
											db_measure=measure_name;
										if(tokens.length > 2)
										{
											s_dispName = tokens[inx++];
										}
										if(tokens.length > 3)
										{
											//temp_unit=tokens[inx++];
											temp_Or=tokens[inx++];
											ArrayList orAlist = StringUtils.egTokenizer(temp_Or,"~",false,true,true);
											if(orAlist!=null && orAlist.size()==2)
											{
												temp_Or=(String)orAlist.get(1);
											}
										}
									}
									if(test_name!=null && measure_name!=null && measure_name.trim().length()>0 && test_name.trim().length()>0)
									{
										if(s_dispName==null || s_dispName.trim().length()==0)
											s_dispName = mappingInfo.getMeasureDescription(test_name,measure_name);

										if(temp_unit==null || temp_unit.trim().length()==0)
										{
											String un=tablesInfo.getUnitForMeasure(test_name,measure_name);
											unit_k=un;
											if(un!=null && un.equals("MB"))
												un="GB";
											if(un.equals("Number"))
												un="No.";
											unitForMeasure="("+un+")";
										}
										else if(temp_unit!=null && temp_unit.trim().length()>0)
										{
											unit_k=temp_unit;
											unitForMeasure="("+temp_unit+")";
										}
									}
									String key_comp1=test_name+":"+db_measure;
									String sep=":";
									if(temp_dummy_list!=null && temp_dummy_list.contains(key_comp1))
									{
										continue;
									}
									else if(slist!=null && temp_Or!=null && temp_Or.equalsIgnoreCase("or"))
									{
										boolean flage_continue=true;
										if(infoFlage)
											sep="~";
										for(int kk=0;kk<key_unit_list.size();kk++)
										{
											String str_unit=(String)key_unit_list.get(kk);
											if(slist.contains(key_comp1+sep+str_unit))
											{
												flage_continue=false;
											}
										}
										if(flage_continue)
											continue;
									}
									else if(slist!=null && (temp_Or==null || !temp_Or.equalsIgnoreCase("or")))
										infoFlage=false;
									temp_dummy_list.add(key_comp1);
									boolean flageFirst=true;
									//for(int kk=0;kk<key_unit_list.size() && kk < showTopN;kk++)
									for(int kk=0;kk<key_unit_list.size();kk++)
									{
										String str_unit=(String)key_unit_list.get(kk);
										String measure_value=(String)resultHash.get(key_comp1+sep+str_unit);
										if(measure_value==null || measure_value.trim().length()==0)
											measure_value=(String)resultHash.get(key_comp1);

										String descri_info="+";
										String url_descri_info="";
										if(sep!=null && sep.equals("~"))
										{
											if(str_unit!=null && !str_unit.equals("") && str_unit.indexOf(":") > -1 )
												descri_info=(String)str_unit.substring(0,str_unit.indexOf(":"));
											else
												descri_info=str_unit;
											if(descri_info!=null && descri_info.trim().length()>0 && descri_info.startsWith("+"))
											{
												url_descri_info=descri_info.substring(1);
											}
										}

										String url_for_graph="";
										String comp="";
										String host_type="";
										String host_name="";
										String port="";
										String sid="";
										String msmtHost="";
										String comp_name="";
										String state_value="GRAY";
										String layerName="";
										String url_for_layermodel="";
										String class_mouse="mouse";
										String state_display="";
										ArrayList selectedDemandCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier);

										ArrayList selectedDemandOrgCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier+"_real");

										if(isDemandAggSiteService || (selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()==1))
										{
											if(selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()>0 )
												comp = (String)selectedDemandOrgCompList.get(0);
											else if(selectedDemandCompList!=null && selectedDemandCompList.size()>0 )
												comp = (String)selectedDemandCompList.get(0);

											String comp_tokens[] = StringUtils.getTokens(comp,":");
											
											if(comp_tokens!=null && comp_tokens.length>1)
											{
												host_type = comp_tokens[0];
												host_name = comp_tokens[1];
												comp_name=host_name;
												if(comp_tokens.length > 2)
												{
													port = comp_tokens[2];
													if(specsInfo.isPortRelevantForTest(test_name))
													{
														comp_name=comp_name+":"+port;
													}
													else
													{
														comp_name=comp_name+":NULL";
													}
												}
												if(comp_tokens.length > 3)
												{
													sid=comp_tokens[3];
													comp_name=comp_name+":"+sid;
												}
											}
											ArrayList layersOfComp = new ArrayList();
											layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_dem_tier);
											String Layer_name_str=tablesInfo.getLayerForTest(test_name);
											layerName="HOST";
											if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
											{
												StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
												if(tokenLayer!=null)
												{
													while(tokenLayer.hasMoreTokens())
													{
														String l_name=(String)tokenLayer.nextToken();
														if(l_name!=null)
														{
															if(layersOfComp != null && layersOfComp.contains(l_name))
															{
																if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
																{
																	layerName=l_name;
																	break;
																}
															}
															else
																continue;
														}
													}
												}
											}
											List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
											if(agents!=null && agents.size()>0)
												msmtHost=(String)agents.get(0);
											else
												msmtHost=host_name;
											//state_value=(String)servicesBean.getStateForMeasure(selected_dem_tier,comp_name,layerName,test_name,measure_name,descri_info,msmtHost);
											try
											{
												if(stateMeasure != null)
												{
													String temp_info=descri_info;
													if(!temp_info.startsWith("+"))
														temp_info="+"+temp_info;
													String state_key = "NULL^eg^"+selected_dem_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^"+temp_info+"^eg^"+measure_name;
													state_value = (String)stateMeasure.get(state_key);
												}
											}
											catch (Exception er)
											{
											}
											if(state_value==null || state_value.trim().length()==0)
												state_value="GOOD";

											if (EgConfigInfo.isBad(state_value))
											{
												state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_dem_tier,layerName,descri_info,test_name,msmtHost,measure_name,"");
											}

											String url_site="NULL";
											if(layerName.equals("WEB_SITE") || layerName.equals("WEB_TRANSACTIONS") || test_name.equals("WebSiteTest") || test_name.equals("WebSiteTransactionTest"))
											{
												url_site=site_name;
											}

											url_for_graph="gtype=yes&showRange=Range&mode=2D&info=*&monitorSkin="+monitor_Skin+"&gformat=graph&measure="+db_measure+"&test="+test_name+"&port="+port+"&site="+url_site+"&comptype="+host_type+"&host="+host_name+"&layer="+layerName+"&msmt_host="+msmtHost+"&width="+graphWidth+"&timeLine=1 hour&height=100&from_page=serviceOverview&threshold=no&from=cview&bgStyle="+bg_style+"&starttime=&endtime=&starthr=&endhr=";

											String display_c_name=comp_name;

											if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
											{
												display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
											}

											String displayComponentType = mappingInfo.getComponentTypeDescription(selected_dem_tier);
											
											String temp_compName = null;
											if(comp_name != null && port != null)
											{
												if(comp_name.indexOf(":") > -1)
													comp_name = comp_name.substring(0,comp_name.indexOf(":"));
												temp_compName = comp_name+":"+port;
											}
										
											url_for_layermodel="/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(temp_compName,"UTF-8")+"&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-"+EgURLEncoder.encode(url_descri_info,"UTF-8")+"&comptype="+EgURLEncoder.encode(selected_dem_tier,"UTF-8")+"&tstate="+EgURLEncoder.encode(state_value,"UTF-8")+"&newWindow=false&prevPage=MainDashBoard&isServiceBusiDash="+isServiceBusiDash;
											if(descri_info!=null && descri_info.equals("+"))
												url_for_layermodel=url_for_layermodel+"&findInfo=true";
										
											state_display=mappingInfo.getLabelDescription(state_value);
										}
										else
										{
											class_mouse="mouse";
											String actipnreq = request.getParameter("action");
											if(actipnreq.equalsIgnoreCase("service"))
												actipnreq = "services";
											url_for_layermodel="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&fromAcessPage=bussinessDashboard&from=bussinessDashboard&action=component&searchIndComps=checked&isFromMenu=false&view=metric&viewId=components&viewPageTitle=Components&viewTreeTitle=Component&filterBy="+actipnreq+"&subFilter="+service_name+"&componentType="+selected_dem_tier+"&isServiceBusiDash=true";
											class_mouse="mouse";
										}

										if((isDemandAggSiteService || (selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()==1)) && url_for_graph!=null && url_for_graph.trim().length()>0 && ((demandTestWithMeaList!=null && demandTestWithMeaList.size()==1) && (slist.size()==1)) && demandctypeList!=null && demandctypeList.size()==1 && show_graph_flag)
										{
											Hashtable avgMinMaxData =new Hashtable();
											if(isShowGraphMAM)
											{
												avgMinMaxData =measureGraphInfo.getAvgMaxMinData(db_measure,test_name,host_name,port,site_name,descri_info,msmtHost,host_type,"1 hour",user);
											}
											String avg_str="-";
											String max_str="-";
											String min_str="-";
											String td_width="185";
											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												ArrayList meaList=(ArrayList)avgMinMaxData.get(measure_name+" ("+unit_k+")");

												if(meaList!=null && meaList.size()>0)
													avg_str=(String)meaList.get(0);
												if(meaList!=null && meaList.size()>1)
													max_str=(String)meaList.get(1);
												if(meaList!=null && meaList.size()>2)
													min_str=(String)meaList.get(2);

												td_width="100%";
											}

											minMaxTable.put("ChartId","dhigh_"+service_name+"_"+zz);

											minMaxTable.put("ChartName",s_dispName+unitForMeasure);
											minMaxTable.put("ChartURL",url_for_graph);
											minMaxTable.put("ChartTdWidth",td_width);
											minMaxTable.put("ChartURLForLM",url_for_layermodel);
											minMaxTable.put("ChartClass",class_mouse);

											minMaxTable.put("chartOption",chartOption);
											minMaxTable.put("chartTimeline",chartTimeline);

											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												minMaxTable.put("ChartState",mappingInfo.getTextDescription("monitor.measure.State"));
												minMaxTable.put("ChartAvg",mappingInfo.getTextDescription("monitor.measure.Avg"));
												minMaxTable.put("ChartMax",mappingInfo.getTextDescription("monitor.measure.Max"));
												minMaxTable.put("ChartMin",mappingInfo.getTextDescription("monitor.measure.Min"));

												minMaxTable.put("ChartStateVal",state_value);
												minMaxTable.put("ChartStateDisp",state_display);

												minMaxTable.put("ChartAvgVal",formatDbValue(avg_str));

												minMaxTable.put("ChartMaxVal",formatDbValue(max_str));
												minMaxTable.put("ChartMinVal",formatDbValue(min_str));
											}
										}
										else
										{
											JSONObject minMaxTableDataObject = new JSONObject();

											String disp_info="";
											if(infoFlage && str_unit!=null && str_unit.indexOf(":")>-1)
											{
												disp_info=str_unit.substring(0,str_unit.lastIndexOf(":"));
												if(disp_info.startsWith("+"))
													disp_info=disp_info.substring(1);
											}
											if(!isShowStateColor)
												state_value = "GRAY";
											if(infoFlage)
											{
												minMaxTableDataObject.put("value0_info","true");
												minMaxTableDataObject.put("value0",state_value);

												minMaxTableDataObject.put("value0_tip",state_display);
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(disp_info));
												
												minMaxTableDataObject.put("value0_url",url_for_layermodel);

												minMaxTableDataObject.put("value0_mouse",class_mouse);
											}
											else if(more_then_one && (!infoFlage) && flageFirst)
											{
												flageFirst=false;

												String tier_tmp=selected_dem_tier;
												if(selected_dem_tier!=null && selected_dem_tier.startsWith("Agg_"))
												{
													tier_tmp=selected_dem_tier.substring(selected_dem_tier.indexOf("_")+1);
												}

												String icon_txt="serviceIcon_"+tier_tmp;
												String measure_icontxt=(String)serviceDashIni.getValue("Measure_icons",measure_name);

												//unit_k
												if(measure_icontxt==null || measure_icontxt.trim().length()==0)
												{
													measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons",unit_k);

													if(measure_icontxt==null || measure_icontxt.trim().length()==0)
													{
														measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons","Common");

														if(measure_icontxt==null || measure_icontxt.trim().length()==0)
															measure_icontxt="measureCommon";
													}
												}

												minMaxTableDataObject.put("value0",measure_icontxt);

												minMaxTableDataObject.put("value0_tip",mappingInfo.getComponentTypeDescription(selected_dem_tier));
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(s_dispName));
												minMaxTableDataObject.put("value0_d_tip",s_dispName+unitForMeasure);
												minMaxTableDataObject.put("value0_url",url_for_layermodel);

												minMaxTableDataObject.put("value0_mouse",class_mouse);
											}

											if(measure_value!=null && measure_value.length()>0)
											{
												minMaxTableDataObject.put("value1",formatDbValue(measure_value));
												minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
												minMaxTableDataObject.put("value1_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_state",state_value);
												minMaxTableDataObject.put("value1_mouse",class_mouse);
											}
											else
											{
												if(sameKeyFlage)
												{
													minMaxTableDataObject.put("value1","-");
													minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
													minMaxTableDataObject.put("value1_state",state_value);
												}
											}

											if(infoFlage)
											{
												// --- html tr ends--
												minMaxTableDataObject.put("value1_endTR","true");
											}
											minMaxTableDataArray.add(minMaxTableDataObject);
										}
									}
									if(more_then_one && (!infoFlage))
									{
										//-- tr tables ends--
										JSONObject minMaxTableDataObject = new JSONObject();
										minMaxTableDataObject.put("more_then_one_End","true");
										minMaxTableDataArray.add(minMaxTableDataObject);
									}
								}
								else
								{
									count_else_loop++;
								}
							}

							if(count_else_loop==loopTotND)
							{
								serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
							}
							else
							{
								if(minMaxTableDataArray!=null && minMaxTableDataArray.size()>0)
									minMaxTable.put("minMaxTableDataArray",minMaxTableDataArray);

								serviceDemandDataJson.put("minMaxTable",minMaxTable);
							}
						}
						else
						{
							serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
						}
						if(!(isDemandAggSiteService && ((demandTestWithMeaList!=null && demandTestWithMeaList.size()==1) && (slist.size()==1)) && demandctypeList!=null && demandctypeList.size()==1))
						{
							// --- html table ends--
							serviceDemandDataJson.put("endTable","true");
						}
					}
					else
					{
						serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
					}
					serviceDemandDataArr.add(serviceDemandDataJson);
				}
				else
				{
					JSONObject serviceDemandDataJson = new JSONObject();
					serviceDemandDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
					serviceDemandDataArr.add(serviceDemandDataJson);
				}

				serviceDataJson.put("serviceDemandData",serviceDemandDataArr);

 //------------------Consumption--------------------------------------------------------------->

				JSONArray serviceConsumptionDataArr = new JSONArray();

				if(selectedConsumptionCompHash!=null && selectedConsumptionCompHash.size()>0 && consumptionCtypeList!=null && consumptionCtypeList.size()>0)
				{
					JSONObject serviceConsumptionDataJson = new JSONObject();

					int loopTotCon=consumptionTestMeaList.size();
					Hashtable resultHash=new Hashtable();
					resultHash=(Hashtable)servicesBean.getServicePerformanceDashData(consumptionCtypeList,selectedConsumptionCompHash,consumptionTestMeaList,site_name,true);
					List slist=new LinkedList();
					if(resultHash!=null && resultHash.size()>0)
					{
						slist=(List)getSortedList(resultHash,"desc");
						//loopTotCon=slist.size();
					}

					if(resultHash!=null && resultHash.size()>0 && loopTotCon>0)
					{
						int count_else_loop=0;
						ArrayList temp_dummy_list=new ArrayList();
						JSONArray serviceConsumptionInnerDataArr = new JSONArray();
						//for(int zz=0;zz<loopTotCon && zz<showMaxConsumption;zz++)
						for(int zz=0;zz<loopTotCon;zz++)
						{
							String selected_con_tier="";
							String consum_test_measure="";
							String selected_con_tier_with_all=(String)consumptionTestMeaList.get(zz);
							if(selected_con_tier_with_all!=null && selected_con_tier_with_all.length()>0)
							{
								selected_con_tier=selected_con_tier_with_all.substring(0,selected_con_tier_with_all.indexOf(":"));

								if(selected_con_tier!=null && selected_con_tier.startsWith("CT^"))
								{
									selected_con_tier=selected_con_tier.substring(selected_con_tier.indexOf("^")+1);
								}

								consum_test_measure=selected_con_tier_with_all.substring(selected_con_tier_with_all.indexOf(":")+1);
							}

							if(consum_test_measure!=null && consum_test_measure.trim().length()>0)
							{
								test_measure = consum_test_measure;
								test_name="";
								measure_name="";
								db_measure="";
								s_dispName="";
								temp_unit="";
								temp_Or="";
								unitForMeasure="";
								tokens = StringUtils.getTokens(test_measure,":");
								if(tokens!=null && tokens.length>1)
								{
									int inx=0;
									if(tokens.length==5)
									{
										nick_name=tokens[inx++];
										if(nick_name!=null && nick_name.startsWith("CN^"))
										{
											nick_name=nick_name.substring(nick_name.indexOf("^")+1);
										}
									}

									test_name = tokens[inx++];
									measure_name = tokens[inx++];
									db_measure = dbInfo.getColumnForMeasure(test_name,measure_name);
									if(db_measure==null || db_measure.trim().length()==0)
										db_measure=measure_name;
									if(tokens.length > 2)
									{
										s_dispName = tokens[inx++];
									}
									if(tokens.length > 3)
									{
										//temp_unit=tokens[inx++];
										temp_Or=tokens[inx++];
										ArrayList orAlist = StringUtils.egTokenizer(temp_Or,"~",false,true,true);
										if(orAlist!=null && orAlist.size()==1)
											temp_unit=(String)orAlist.get(0);
										else if(orAlist!=null && orAlist.size()==2)
										{
											temp_unit=(String)orAlist.get(0);
											temp_Or=(String)orAlist.get(1);
										}
									}
								}
								if(test_name!=null && measure_name!=null && measure_name.trim().length()>0 && test_name.trim().length()>0)
								{
									if(s_dispName==null || s_dispName.trim().length()==0)
										s_dispName = mappingInfo.getMeasureDescription(test_name,measure_name);

									//if(temp_unit==null || temp_unit.trim().length()==0)
									{
										String un=tablesInfo.getUnitForMeasure(test_name,measure_name);
										if(un!=null && un.equals("MB"))
											un="GB";
										if(un.equals("Number"))
											un="No.";
										//unitForMeasure="("+un+")";
										unitForMeasure=un;
									}
									/*else if(temp_unit!=null && temp_unit.trim().length()>0)
									{
										unitForMeasure="("+temp_unit+")";
									}*/
								}
								String key_comp1=test_name+":"+db_measure;
								if(temp_dummy_list!=null && temp_dummy_list.contains(key_comp1))
								{
									continue;
								}
								temp_dummy_list.add(key_comp1);
								String measure_value=(String)resultHash.get(key_comp1+":"+temp_unit);

								if(measure_value==null || measure_value.trim().length()==0)
									measure_value=(String)resultHash.get(key_comp1);

								try
								{
									if(measure_value!=null && !measure_value.equals("-"))
									{
										double tmp_mea_val=Double.parseDouble(measure_value);
									}
								}
								catch(Exception e)
								{
									measure_value=(String)resultHash.get(key_comp1+":"+temp_unit+"_Value");

									if(measure_value==null || measure_value.trim().length()==0)
										measure_value=(String)resultHash.get(key_comp1+"_Value");
								}

								ArrayList selectedConsumptionCompList=(ArrayList)selectedConsumptionCompHash.get(selected_con_tier);

								ArrayList selectedConsumptionOrgCompList=(ArrayList)selectedConsumptionCompHash.get(selected_con_tier+"_real");

								String url_for_graph="";
								String comp="";
								String host_type="";
								String host_name="";
								String port="";
								String sid="";
								String msmtHost="";
								if(selectedConsumptionCompList!=null && selectedConsumptionCompList.size()>0)
									comp = (String)selectedConsumptionCompList.get(0);

								String comp_tokens[] = StringUtils.getTokens(comp,":");
								String comp_name="";
								if(comp_tokens!=null && comp_tokens.length>1)
								{
									host_type = comp_tokens[0];
									host_name = comp_tokens[1];
									comp_name=host_name;
									if(comp_tokens.length > 2)
									{
										port = comp_tokens[2];
										comp_name=comp_name+":"+port;
									}
									if(comp_tokens.length > 3)
									{
										sid=comp_tokens[3];
										comp_name=comp_name+":"+sid;
									}
								}

								String display_c_name=comp_name;

								if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
								{
									display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
								}

								//String display_c_name=comp_name.substring(0,comp_name.indexOf("^"));
								String c_name=display_c_name;
								String strCompName = c_name;
								if(c_name!=null && c_name.indexOf(":")<0)
								{
									String port_value=(String)discInfo.getPortForHost(c_name,selected_con_tier);
									port_value=(port_value==null || port_value.trim().length()==0)?"NULL":port_value;
									c_name=c_name+":"+port_value;
									display_c_name=c_name;
								}

								if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
								{
									display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
								}
								if(strCompName!=null && strCompName.indexOf(":") > -1)
								{
									strCompName = strCompName.substring(0,c_name.indexOf(":"));
								}

								ArrayList layersOfComp = new ArrayList();
								layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_con_tier);
								String Layer_name_str=tablesInfo.getLayerForTest(test_name);
								String layerName="HOST";
								if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
								{
									StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
									if(tokenLayer!=null)
									{
										while(tokenLayer.hasMoreTokens())
										{
											String l_name=(String)tokenLayer.nextToken();
											if(l_name!=null)
											{
												if(layersOfComp != null && layersOfComp.contains(l_name))
												{
													if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
													{
														layerName=l_name;
														break;
													}
												}
												else
													continue;
											}
										}
									}
								}
								List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
								if(agents!=null && agents.size()>0)
									msmtHost=(String)agents.get(0);
								else
									msmtHost=host_name;
								//String state_value=(String)servicesBean.getStateForMeasure(selected_con_tier,comp_name,layerName,test_name,measure_name,"",msmtHost);
								String state_value="GOOD";
								try
								{
									if(stateMeasure != null)
									{
										String state_key = "NULL^eg^"+selected_con_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^+^eg^"+measure_name;
										state_value = (String)stateMeasure.get(state_key);
									}
								}
								catch (Exception er)
								{
								}

								if(state_value==null || state_value.trim().length()==0)
									state_value="GOOD";

								if (EgConfigInfo.isBad(state_value))
								{
									state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_con_tier,layerName,"",test_name,msmtHost,measure_name,"");
								}

								String url_site="NULL";
								if(layerName.equals("WEB_SITE") || layerName.equals("WEB_TRANSACTIONS") || test_name.equals("WebSiteTest") || test_name.equals("WebSiteTransactionTest"))
								{
									url_site=site_name;
								}

								url_for_graph="gtype=yes&showRange=Range&mode=2D&info=*&monitorSkin="+monitor_Skin+"&gformat=graph&measure="+db_measure+"&test="+test_name+"&port="+port+"&site="+url_site+"&comptype="+host_type+"&host="+host_name+"&layer="+layerName+"&msmt_host="+msmtHost+"&width="+graphWidth+"&height=100&from_page=serviceOverview&threshold=no&bgStyle="+bg_style+"&starttime=&endtime=&starthr=&endhr=";

								String displayComponentType = mappingInfo.getComponentTypeDescription(selected_con_tier);
								
								String temp_compName = null;
								if(comp_name != null && port != null)
								{
									if(comp_name.indexOf(":") > -1)
										comp_name = comp_name.substring(0,comp_name.indexOf(":"));
									temp_compName = comp_name+":"+port;
								}

								String url_for_layermodel="/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(temp_compName,"UTF-8")+"&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-&comptype="+EgURLEncoder.encode(selected_con_tier,"UTF-8")+"&tstate="+EgURLEncoder.encode(state_value,"UTF-8")+"&newWindow=false&prevPage=MainDashBoard&findInfo=true&isServiceBusiDash="+isServiceBusiDash;

								// Fix by Aysha - c_name, site_name and msmtHost are encoded twice since it is decoded when fusion chart is loaded. 

								String url_for="EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(c_name,"UTF-8")+"&layer="+layerName+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-&comptype="+selected_con_tier+"&tstate="+state_value+"&newWindow=false&prevPage=MainDashBoard&findInfo=true";
								
								String temp_url = "/final/monitor/";
								String encoded_url=EgURLEncoder.encode(url_for,"UTF-8");
								temp_url=temp_url+encoded_url;

								String class_mouse="mouse";
								String state_value_chart=state_value;
								if(!isConsAggSiteService)
								{
									//consumptionTestMeaList
									if(selectedConsumptionOrgCompList!=null && selectedConsumptionOrgCompList.size()>1 && selected_con_tier_with_all!=null && selected_con_tier_with_all.indexOf("CN^")<0)
									{
										state_value="DARKGRAY";
										state_value_chart="";
										url_for_layermodel="";
										String actipnreq = request.getParameter("action");
										if(actipnreq.equalsIgnoreCase("service"))
											actipnreq = "services";
										url_for_layermodel="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&fromAcessPage=bussinessDashboard&from=bussinessDashboard&action=component&searchIndComps=checked&isFromMenu=false&view=metric&viewId=components&viewPageTitle=Components&viewTreeTitle=Component&filterBy="+actipnreq+"&subFilter="+service_name+"&componentType="+selected_con_tier+"&isServiceBusiDash=true";
										class_mouse="mouse";
										display_c_name="";
										temp_url="";
									}
								}
								if(!isShowStateColor)
									state_value = "DARKGRAY";
								//state_value="UNKNOWN";
								String chart_str="cpu_GRAY";
								String chart_state_str="cpu_"+state_value;
								String chart_MainStr="cpu_Main";
								String chart_MainHeight="width:45px;height:54px;";
								String chart_spacing="8 0 0 -1px;";
								//String chart_spacing="0";
								//measure_value="90";

								if(s_dispName.indexOf("Memory")>-1 || s_dispName.indexOf("memory")>-1)
								{
									//state_value="INTERMEDIATE";
									//state_value="GOOD";
									chart_str="mem_GRAY";
									chart_state_str="mem_"+state_value;
									chart_MainStr="mem_Main";
									chart_MainHeight="width:47px;height:46px;";
									chart_spacing="9 9 9 9";
									//chart_spacing="0";
									//measure_value="95";
								}

								JSONObject serviceConsumptionInnerDataJson = new JSONObject();

								if(measure_value!=null && !measure_value.equals("-"))
								{
									double mea_val=Double.parseDouble(measure_value);

									if(unitForMeasure!=null && unitForMeasure.trim().length()>0 && (unitForMeasure.equalsIgnoreCase("%") || unitForMeasure.equalsIgnoreCase("Percent") || unitForMeasure.equalsIgnoreCase("Percentage")))
									{
										//if(mea_val>10.0 && (s_dispName.indexOf("Disk")>-1 || (((zz+1)%3)==0)))
										//if(s_dispName.indexOf("Disk")>-1)
										if(mea_val>0.0 && (s_dispName.indexOf("Disk")>-1 || s_dispName.indexOf("disk")>-1))
										{
											Hashtable temp_hash=new Hashtable();
											temp_hash.put(state_value,new Double(measure_value));
											double val=100.00-Double.parseDouble(measure_value);
											temp_hash.put("GRAY",new Double(val));

											String measValue=dbInfo.formatValue(measure_value);

											String xmlData=(String)getXMLForPieOverview(temp_hash,thisLanguage,iniUI,null,temp_url,monitor_Skin);
											JSONObject highChartJsonData=(JSONObject)this.getJsonForPieOverview(temp_hash,thisLanguage,iniUI,null,url_for_layermodel,monitor_Skin,mappingInfo);
											
											if(xmlData!=null && xmlData.trim().length()>0)
											{
												serviceConsumptionInnerDataJson.put("divId","spd_chartContainer_"+service_name+"_"+zz);
												serviceConsumptionInnerDataJson.put("fcId","myChartId_"+service_name+"_"+zz);
												serviceConsumptionInnerDataJson.put("dataXML",xmlData);
												serviceConsumptionInnerDataJson.put("graphWidth","99%");
												serviceConsumptionInnerDataJson.put("graphHeight","64");
												serviceConsumptionInnerDataJson.put("movie","/final/FusionCharts/swf/Doughnut2D.swf");

												serviceConsumptionInnerDataJson.put("layerModelUrl",url_for_layermodel);
												serviceConsumptionInnerDataJson.put("toolTip",display_c_name);
												serviceConsumptionInnerDataJson.put("class_mouse",class_mouse);

												serviceConsumptionInnerDataJson.put("consumptionDisplayValue",formatDbValue(measValue)+" "+unitForMeasure);
												serviceConsumptionInnerDataJson.put("consumptionDisplayTip",s_dispName+"("+unitForMeasure+")");
												if(highChartJsonData!=null)
												{
													serviceConsumptionInnerDataJson.put("highChartData",highChartJsonData);
												}
											}
											else
											{
												serviceConsumptionInnerDataJson.put("consumptionDisplayValue",formatDbValue(measValue)+" "+unitForMeasure);
												serviceConsumptionInnerDataJson.put("consumptionDisplayTip",s_dispName+"("+unitForMeasure+")");
											}
										}
										else
										{
											int columnWidth = 100;
											Long temp_measure_value=new Long(Math.round(Double.parseDouble(measure_value)));
											String measValue=dbInfo.formatValue(measure_value);
											long fillColorValue=temp_measure_value.longValue();
											
											long value2 = (fillColorValue*100)/columnWidth;
											if(fillColorValue>-1)
											{
												if(value2>=100)
													value2=100;
												long val=100-value2;

												serviceConsumptionInnerDataJson.put("layerModelUrl",url_for_layermodel);
												serviceConsumptionInnerDataJson.put("toolTip",display_c_name);

												serviceConsumptionInnerDataJson.put("chartStateOuter",chart_state_str);
												serviceConsumptionInnerDataJson.put("chartStateInner",chart_str);
												serviceConsumptionInnerDataJson.put("chartMain",chart_MainStr);
												serviceConsumptionInnerDataJson.put("chartMainHeight",chart_MainHeight);
												serviceConsumptionInnerDataJson.put("chartSpacing",chart_spacing);

												serviceConsumptionInnerDataJson.put("chartValue",val);

												serviceConsumptionInnerDataJson.put("consumptionDisplayValue",formatDbValue(measValue)+" "+unitForMeasure);
												serviceConsumptionInnerDataJson.put("consumptionDisplayTip",s_dispName+"("+unitForMeasure+")");
											}
										}
									}
									else
									{
										String measValue=dbInfo.formatValue(measure_value);
										serviceConsumptionInnerDataJson.put("consumptionWithoutIcon","true");
										serviceConsumptionInnerDataJson.put("layerModelUrl",url_for_layermodel);
										serviceConsumptionInnerDataJson.put("toolTip",display_c_name);
										serviceConsumptionInnerDataJson.put("consumptionBigDisplayValue",formatDbValue(measValue));
										serviceConsumptionInnerDataJson.put("consumptionDisplayValue",formatDbValue(measValue)+" "+unitForMeasure);
										serviceConsumptionInnerDataJson.put("consumptionDisplayUnit",unitForMeasure);
										serviceConsumptionInnerDataJson.put("consumptionDisplayTip",s_dispName+"("+unitForMeasure+")");
									}
								}
								else
								{
									serviceConsumptionInnerDataJson.put("consumptionInnerErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No data"));
								}

								serviceConsumptionInnerDataJson.put("consumptionInnerDisplay",mappingInfo.getTextDescription("monitor.VirtualDashboard."+s_dispName));
								serviceConsumptionInnerDataJson.put("consumptionInnerTip",s_dispName+"("+unitForMeasure+")");

								serviceConsumptionInnerDataArr.add(serviceConsumptionInnerDataJson);
							}
							else
							{
								count_else_loop++;
							}
						}

						if(count_else_loop==loopTotCon)
						{
							serviceConsumptionDataJson.put("consumptionErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
						}
						else
						{
							serviceConsumptionDataJson.put("consumptionInnerDataArr",serviceConsumptionInnerDataArr);
						}
					}
					serviceConsumptionDataArr.add(serviceConsumptionDataJson);
				}
				else
				{
					JSONObject serviceConsumptionDataJson = new JSONObject();
					serviceConsumptionDataJson.put("consumptionErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
					serviceConsumptionDataArr.add(serviceConsumptionDataJson);
				}

				serviceDataJson.put("serviceConsumptionData",serviceConsumptionDataArr);

//-----------------Quality------------------------------------------------------------------

				JSONArray serviceQualityDataArr = new JSONArray();

				if(selectedQualityCompHash!=null && selectedQualityCompHash.size()>0 && qualityCtypeList!=null && qualityCtypeList.size()>0)
				{
					JSONObject serviceQualityDataJson = new JSONObject();

					int loopTotNQ=qualityTestMeaList.size();
					Hashtable resultHash=new Hashtable();
					resultHash=(Hashtable)servicesBean.getServicePerformanceDashData(qualityCtypeList,selectedQualityCompHash,qualityTestMeaList,site_name,false);
					List slist=new LinkedList();
					if(resultHash!=null && resultHash.size()>0)
					{
						slist=(List)getSortedList(resultHash,"desc");
						//loopTotNQ=slist.size();
					}
					ArrayList key_unit_list=new ArrayList();
					ArrayList only_key_unit_list=new ArrayList();
					ArrayList only_key_list=new ArrayList();
					ArrayList key_info_list=new ArrayList();
					ArrayList key_testmea_list=new ArrayList();
					boolean infoFlage=false;
					boolean isDescriptor=false;
					boolean sameKeyFlage=false;
					String infoTest="";
					if(slist!=null && slist.size()>0)
					{
						for(int zz=0;zz<slist.size();zz++)
						{
							String str_key=(String)slist.get(zz);
							if(str_key!=null && str_key.endsWith("_Value"))
								continue;
							String key_unit=str_key.substring(str_key.lastIndexOf(":")+1);
							String only_key=str_key.substring(0,str_key.lastIndexOf(":"));
							String key_info=null;
							if(str_key!=null && str_key.indexOf("~")>-1)
							{
								key_info=str_key.substring(str_key.indexOf("~")+1);
							}
							if(key_info!=null && key_info.trim().length()>0)
							{
								String only_key_info="";
								String only_key_unit="";
								if(key_info.indexOf(":")>-1)
								{
									only_key_info=key_info.substring(0,key_info.lastIndexOf(":"));
									only_key_unit=key_info.substring(key_info.lastIndexOf(":")+1);
									
									infoTest=str_key.substring(0,str_key.indexOf(":"));
									String test_mea=str_key.substring(0,str_key.indexOf("~"));
									if(test_mea!=null && test_mea.trim().length()>0 && !key_testmea_list.contains(test_mea))
									{
										key_testmea_list.add(test_mea);
									}

									if(showDescriptorsList!=null && infoTest!=null && showDescriptorsList.contains(infoTest))
									{
										infoFlage=true;
										String Caption=(String)serviceDashIni.getValue("Show_Descriptors",infoTest);
										if(Caption!=null && Caption.equalsIgnoreCase("Descriptors"))
											isDescriptor=true;
									}
								}

								if(!key_unit_list.contains(key_info))
									key_unit_list.add(key_info);

								if(!only_key_unit_list.contains(only_key_unit))
									only_key_unit_list.add(only_key_unit);

								if(only_key_info!=null && only_key_info.trim().length()>0 && !key_info_list.contains(only_key_info))
									key_info_list.add(only_key_info);
							}
							else if(key_unit!=null)
							{
								if(!key_unit_list.contains(key_unit))
									key_unit_list.add(key_unit);

								if(!only_key_unit_list.contains(key_unit))
									only_key_unit_list.add(key_unit);
							}

							if(only_key_list!=null && !only_key_list.contains(only_key))
							{
								only_key_list.add(only_key);
							}
							else if(only_key_list!=null && only_key_list.contains(only_key))
							{
								sameKeyFlage = true;
							}
						}
					}

					if(key_unit_list==null)
					{
						key_unit_list = new ArrayList();
					}

					if(infoFlage)
					{
						JSONObject minMaxTable = new JSONObject();
						JSONArray minMaxTableHeadersArray = new JSONArray();

						if(!(key_unit_list.size()==1 && key_testmea_list.size()==1))
						{
							String displyText=(String)serviceDashIni.getValue("Show_Descriptors",infoTest);
							displyText=(displyText==null || displyText.trim().length()==0)?"Descriptors":displyText;

							JSONObject descHeader = new JSONObject();
							descHeader.put("name",mappingInfo.getTextDescription("monitor.VirtualDashboard."+displyText));
							descHeader.put("width","15");
							descHeader.put("textType","string");
							minMaxTableHeadersArray.add(descHeader);

							for(int zz=0;zz<key_testmea_list.size();zz++)
							{
								//String str_test_mea=(String)key_testmea_list.get(zz);
								String str_test_mea=(String)qualityTestWithMeaList.get(zz);
								if(str_test_mea!=null && str_test_mea.trim().length()>0)
								{
									String str_test_name=(String)str_test_mea.substring(0,str_test_mea.indexOf(":"));
									//String str_dbmea_name=str_test_mea.substring(str_test_mea.indexOf(":")+1);
									String normal_measure=str_test_mea.substring(str_test_mea.indexOf(":")+1);
									String display_text="";
									if(normal_measure!=null && normal_measure.indexOf(":")>-1)
									{
										display_text=normal_measure.substring(normal_measure.indexOf(":")+1);
										normal_measure=normal_measure.substring(0,normal_measure.indexOf(":"));
									}
									//String normal_measure = dbInfo.getMeasureForColumn(str_test_name,str_dbmea_name);
									String mappingString=str_test_name+":"+normal_measure;
									String un=tablesInfo.getUnitForMeasure(str_test_name,normal_measure);

									JSONObject measHeader = new JSONObject();

									if(display_text==null || display_text.trim().length()==0)
									{
										measHeader.put("name",mappingInfo.getMeasureDescription(str_test_name,normal_measure));
										measHeader.put("width","15");
										measHeader.put("textType","asFloat");
									}
									else
									{
										measHeader.put("name",display_text);
										measHeader.put("width","15");
										measHeader.put("textType","asFloat");
									}
									minMaxTableHeadersArray.add(measHeader);
								}
							}
							minMaxTable.put("minMaxTableHeadersArray",minMaxTableHeadersArray);
						}

						String descri_info="+";
						if(resultHash!=null && resultHash.size()>0 && loopTotNQ>0 && key_unit_list!=null && key_unit_list.size()>0)
						{
							int count_else_loop=0;
							ArrayList temp_dummy_list=new ArrayList();
							String sep="~";

							if(key_unit_list.size()>1)
							{
								ArrayList temp_key_unit_list=(ArrayList)getStateSortedList(key_unit_list,qualityTestMeaList,selectedQualityCompHash,stateMeasure);
								if(temp_key_unit_list!=null && temp_key_unit_list.size()>0)
								{
									key_unit_list = new ArrayList();
									key_unit_list.addAll(temp_key_unit_list);
								}
							}
							JSONArray minMaxTableDataArray = new JSONArray();
							//for(int kk=0;kk<key_unit_list.size() && kk < showTopNInfos;kk++)
							for(int kk=0;kk<key_unit_list.size();kk++)
							{
								String str_unit=(String)key_unit_list.get(kk);
								String url_descri_info="";
								if(sep!=null && sep.equals("~"))
								{
									if(str_unit!=null && !str_unit.equals("") && str_unit.indexOf(":") > -1 )
										descri_info=(String)str_unit.substring(0,str_unit.indexOf(":"));
									else
												descri_info=str_unit;
									if(descri_info!=null && descri_info.trim().length()>0 && descri_info.startsWith("+"))
									{
										url_descri_info=descri_info.substring(1);
									}
								}
								boolean flage_tr=true;

								for(int zz=0;zz<loopTotNQ;zz++)
								{
									String selected_qua_tier="";
									String quality_test_measure="";
									String selected_qua_tier_with_all=(String)qualityTestMeaList.get(zz);
									if(selected_qua_tier_with_all!=null && selected_qua_tier_with_all.length()>0)
									{
										selected_qua_tier=selected_qua_tier_with_all.substring(0,selected_qua_tier_with_all.indexOf(":"));

										if(selected_qua_tier!=null && selected_qua_tier.startsWith("CT^"))
										{
											selected_qua_tier=selected_qua_tier.substring(selected_qua_tier.indexOf("^")+1);
										}

										quality_test_measure=selected_qua_tier_with_all.substring(selected_qua_tier_with_all.indexOf(":")+1);
									}
									if(quality_test_measure!=null && quality_test_measure.trim().length()>0)
									{
										test_measure = quality_test_measure;
										test_name="";
										measure_name="";
										db_measure="";
										s_dispName="";
										temp_unit="";
										temp_Or="";
										unitForMeasure="";
										String unit_k="";
										tokens = StringUtils.getTokens(test_measure,":");
										if(tokens!=null && tokens.length>1)
										{
											int inx=0;
											if(tokens.length==5)
											{
												nick_name=tokens[inx++];
												if(nick_name!=null && nick_name.startsWith("CN^"))
												{
													nick_name=nick_name.substring(nick_name.indexOf("^")+1);
												}
											}

											test_name = tokens[inx++];
											measure_name = tokens[inx++];
											db_measure = dbInfo.getColumnForMeasure(test_name,measure_name);
											if(db_measure==null || db_measure.trim().length()==0)
												db_measure=measure_name;
											if(tokens.length > 2)
											{
												s_dispName = tokens[inx++];
											}
											if(tokens.length > 3)
											{
												//temp_unit=tokens[inx++];
												temp_Or=tokens[inx++];
												ArrayList orAlist = StringUtils.egTokenizer(temp_Or,"~",false,true,true);
												if(orAlist!=null && orAlist.size()==1)
												{
													//temp_unit=(String)orAlist.get(0);
												}
												else if(orAlist!=null && orAlist.size()==2)
												{
													//temp_unit=(String)orAlist.get(0);
													temp_Or=(String)orAlist.get(1);
												}
											}
										}
										if(test_name!=null && measure_name!=null && measure_name.trim().length()>0 && test_name.trim().length()>0)
										{
											if(s_dispName==null || s_dispName.trim().length()==0)
												s_dispName = mappingInfo.getMeasureDescription(test_name,measure_name);

											if(temp_unit==null || temp_unit.trim().length()==0)
											{
												String un=tablesInfo.getUnitForMeasure(test_name,measure_name);
												unit_k=un;
												if(un!=null && un.equals("MB"))
													un="GB";
												if(un.equals("Number"))
													un="No.";
												unitForMeasure="("+un+")";
											}
											else if(temp_unit!=null && temp_unit.trim().length()>0)
											{
												unit_k=temp_unit;
												unitForMeasure="("+temp_unit+")";
											}
										}
										String key_comp1=test_name+":"+db_measure;
										String new_unit="";
										if(slist!=null)
										{
											boolean flage_continue=true;
											
											for(int kk2=0;kk2<key_unit_list.size();kk2++)
											{
												String str_unit2=(String)key_unit_list.get(kk2);
												if(slist.contains(key_comp1+sep+str_unit2))
												{
													flage_continue=false;
													new_unit = str_unit2;
													temp_dummy_list.add(key_comp1+sep+str_unit2);
												}
											}
											if(flage_continue)
												continue;
										}
										else if(temp_dummy_list!=null && temp_dummy_list.contains(key_comp1+sep+str_unit))
										{
											continue;
										}
										String measure_value=(String)resultHash.get(key_comp1+sep+str_unit);
										if(measure_value==null || measure_value.trim().length()==0)
											measure_value=(String)resultHash.get(key_comp1+sep+new_unit);
										if(measure_value==null || measure_value.trim().length()==0)
											measure_value=(String)resultHash.get(key_comp1);

										String url_for_graph="";
										String comp="";
										String host_type="";
										String host_name="";
										String port="";
										String sid="";
										String msmtHost="";
										String state_value="GRAY";
										String comp_name="";
										String layerName="";
										String url_for_layermodel="";
										String state_display="";
										String class_mouse="mouse";
										ArrayList selectedQualityCompList=(ArrayList)selectedQualityCompHash.get(selected_qua_tier);

										ArrayList selectedQualityOrgCompList=(ArrayList)selectedQualityCompHash.get(selected_qua_tier+"_real");

										//if(isQualityAggSiteService || (selectedQualityOrgCompList!=null && selectedQualityOrgCompList.size()==1))
										if(isQualityAggSiteService || (selectedQualityOrgCompList!=null && selectedQualityOrgCompList.size()>0))
										{
											Hashtable temp_state_hash=new Hashtable();
											for(int f=0;f<selectedQualityOrgCompList.size();f++)
											{
												comp = (String)selectedQualityOrgCompList.get(f);

												String comp_tokens[] = StringUtils.getTokens(comp,":");
												
												if(comp_tokens!=null && comp_tokens.length>1)
												{
													host_type = comp_tokens[0];
													host_name = comp_tokens[1];
													comp_name=host_name;
													if(comp_tokens.length > 2)
													{
														port = comp_tokens[2];
														if(specsInfo.isPortRelevantForTest(test_name))
														{
															comp_name=comp_name+":"+port;
														}
														else
														{
															comp_name=comp_name+":NULL";
														}
													}
													if(comp_tokens.length > 3)
													{
														sid=comp_tokens[3];
														comp_name=comp_name+":"+sid;
													}
												}
												ArrayList layersOfComp = new ArrayList();
												layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_qua_tier);
												String Layer_name_str=tablesInfo.getLayerForTest(test_name);
												layerName="HOST";
												if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
												{
													StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
													if(tokenLayer!=null)
													{
														while(tokenLayer.hasMoreTokens())
														{
															String l_name=(String)tokenLayer.nextToken();
															if(l_name!=null)
															{
																if(layersOfComp != null && layersOfComp.contains(l_name))
																{
																	if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
																	{
																		layerName=l_name;
																		break;
																	}
																}
																else
																	continue;
															}
														}
													}
												}
												List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
												if(agents!=null && agents.size()>0)
													msmtHost=(String)agents.get(0);
												else
													msmtHost=host_name;

												//state_value=(String)servicesBean.getStateForMeasure(selected_qua_tier,comp_name,layerName,test_name,measure_name,descri_info,msmtHost);
												try
												{
													if(stateMeasure != null)
													{
														String temp_info=descri_info;
														if(!temp_info.startsWith("+"))
															temp_info="+"+temp_info;
														String state_key = "NULL^eg^"+selected_qua_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^"+temp_info+"^eg^"+measure_name;
														state_value = (String)stateMeasure.get(state_key);
													}
												}
												catch (Exception er)
												{
												}

												if(state_value==null || state_value.trim().length()==0)
													state_value="GOOD";

												if (EgConfigInfo.isBad(state_value))
												{
													state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_qua_tier,layerName,descri_info,test_name,msmtHost,measure_name,"");
												}

												String url_site="NULL";
												if(layerName.equals("WEB_SITE") || layerName.equals("WEB_TRANSACTIONS") || test_name.equals("WebSiteTest") || test_name.equals("WebSiteTransactionTest"))
												{
													url_site=site_name;
												}

												url_for_graph="gtype=yes&showRange=Range&mode=2D&info=*&monitorSkin="+monitor_Skin+"&gformat=graph&measure="+db_measure+"&test="+test_name+"&port="+port+"&site="+url_site+"&comptype="+host_type+"&host="+host_name+"&layer="+layerName+"&msmt_host="+msmtHost+"&width="+graphWidth+"&timeLine=1 hour&height=100&from_page=serviceOverview&threshold=no&from=cview&bgStyle="+bg_style+"&starttime=&endtime=&starthr=&endhr=";

												String display_c_name=comp_name;

												if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
												{
													display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
												}

												String displayComponentType = mappingInfo.getComponentTypeDescription(selected_qua_tier);
												
												String temp_compName = null;
												if(comp_name != null && port != null)
												{
													if(comp_name.indexOf(":") > -1)
														comp_name = comp_name.substring(0,comp_name.indexOf(":"));
													temp_compName = comp_name+":"+port;
												}

												url_for_layermodel="/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(temp_compName,"UTF-8")+"&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-"+EgURLEncoder.encode(url_descri_info,"UTF-8")+"&comptype="+EgURLEncoder.encode(selected_qua_tier,"UTF-8")+"&tstate="+EgURLEncoder.encode(state_value,"UTF-8")+"&newWindow=false&prevPage=MainDashBoard&isServiceBusiDash="+isServiceBusiDash;

												if(descri_info!=null && descri_info.equals("+"))
													url_for_layermodel=url_for_layermodel+"&findInfo=true";
											
												state_display=mappingInfo.getLabelDescription(state_value);

												if(state_value!=null && state_value.equalsIgnoreCase("HIGH"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("INTERMEDIATE"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("LOW"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("UNKNOWN"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
												else if(state_value!=null && state_value.equalsIgnoreCase("GOOD"))
												{
													ArrayList temp_ArrayList=new ArrayList();
													temp_ArrayList.add(comp);
													temp_ArrayList.add(state_display);
													temp_ArrayList.add(url_for_layermodel);
													temp_ArrayList.add(url_for_graph);
													temp_ArrayList.add(msmtHost);

													temp_state_hash.put(state_value,(ArrayList)temp_ArrayList);
												}
											}

											if(temp_state_hash!=null && temp_state_hash.size()>0)
											{
												Enumeration keys=temp_state_hash.keys();
												ArrayList temp_state_ArrayList=new ArrayList();
												while(keys.hasMoreElements())
												{
													String hash_state = (String)keys.nextElement();
													temp_state_ArrayList.add(hash_state);
												}

												Object[] arrayInfoStateTemp=(Object[])temp_state_ArrayList.toArray();
												state_value  = (String)com.eg.EgAlarmTable.getHighestPriority(arrayInfoStateTemp);
												if(state_value!=null)
												{
													ArrayList temp_ArrayList=(ArrayList)temp_state_hash.get(state_value);
													state_display=(String)temp_ArrayList.get(1);
													url_for_layermodel=(String)temp_ArrayList.get(2);
													url_for_graph=(String)temp_ArrayList.get(3);
													msmtHost=(String)temp_ArrayList.get(4);
												}
											}
										}
										else
										{
											class_mouse="mouse";
											String actipnreq = request.getParameter("action");
											if(actipnreq.equalsIgnoreCase("service"))
												actipnreq = "services";
											url_for_layermodel="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&fromAcessPage=bussinessDashboard&from=bussinessDashboard&action=component&searchIndComps=checked&isFromMenu=false&view=metric&viewId=components&viewPageTitle=Components&viewTreeTitle=Component&filterBy="+actipnreq+"&subFilter="+service_name+"&componentType="+selected_qua_tier+"&isServiceBusiDash=true";
											class_mouse="mouse";
										}

										if(key_unit_list.size()==1 && key_testmea_list.size()==1 && descri_info.equals("+") && show_graph_flag)
										{
											Hashtable avgMinMaxData =new Hashtable();
											if(isShowGraphMAM)
											{
												avgMinMaxData =measureGraphInfo.getAvgMaxMinData(db_measure,test_name,host_name,port,site_name,descri_info,msmtHost,host_type,"1 hour",user);
											}
											String avg_str="-";
											String max_str="-";
											String min_str="-";
											String td_width="185";
											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												ArrayList meaList=(ArrayList)avgMinMaxData.get(measure_name+" ("+unit_k+")");

												if(meaList!=null && meaList.size()>0)
													avg_str=(String)meaList.get(0);
												if(meaList!=null && meaList.size()>1)
													max_str=(String)meaList.get(1);
												if(meaList!=null && meaList.size()>2)
													min_str=(String)meaList.get(2);
												td_width="100%";
											}

											minMaxTable.put("ChartId","qhigh_"+service_name+"_"+zz);

											minMaxTable.put("ChartName",s_dispName+unitForMeasure);
											minMaxTable.put("ChartTdWidth",td_width);
											minMaxTable.put("ChartURL",url_for_graph);
											minMaxTable.put("ChartURLForLM",url_for_layermodel);
											minMaxTable.put("ChartClass",class_mouse);

											minMaxTable.put("chartOption",chartOption);
											minMaxTable.put("chartTimeline",chartTimeline);

											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												minMaxTable.put("ChartState",mappingInfo.getTextDescription("monitor.measure.State"));
												minMaxTable.put("ChartAvg",mappingInfo.getTextDescription("monitor.measure.Avg"));
												minMaxTable.put("ChartMax",mappingInfo.getTextDescription("monitor.measure.Max"));
												minMaxTable.put("ChartMin",mappingInfo.getTextDescription("monitor.measure.Min"));

												minMaxTable.put("ChartStateVal",state_value);
												minMaxTable.put("ChartStateDisp",state_display);

												minMaxTable.put("ChartAvgVal",formatDbValue(avg_str));

												minMaxTable.put("ChartMaxVal",formatDbValue(max_str));
												minMaxTable.put("ChartMinVal",formatDbValue(min_str));
											}
										}
										else
										{
											JSONObject minMaxTableDataObject = new JSONObject();

											String disp_info="";
											if(infoFlage && str_unit!=null && str_unit.indexOf(":")>-1)
											{
												disp_info=str_unit.substring(0,str_unit.lastIndexOf(":"));
												if(disp_info.startsWith("+"))
													disp_info=disp_info.substring(1);
											}

											if(flage_tr)
											{
												flage_tr=false;

												String uri_site_name=service_name;
												if(isAggSiteService || isQualityAgg)
												{
													if(isAggSite && agg_site_map!=null && agg_site_map.trim().length()>0)
													{
														uri_site_name = agg_site_map;
													}
												}
												//layerName
												String trsn_img="";
												if(!isDescriptor)
												{
													trsn_img =(String)servicesBean.getDispTransImg(uri_site_name,disp_info);
												}
												else
												{
													String tier_tmp=selected_qua_tier;
													if(selected_qua_tier!=null && selected_qua_tier.startsWith("Agg_"))
													{
														tier_tmp=selected_qua_tier.substring(selected_qua_tier.indexOf("_")+1);
													}

													trsn_img="serviceIcon_"+tier_tmp;
													String measure_icontxt=(String)serviceDashIni.getValue("Measure_icons",measure_name);

													if(measure_icontxt==null || measure_icontxt.trim().length()==0)
													{
														measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons",unit_k);

														if(measure_icontxt==null || measure_icontxt.trim().length()==0)
														{
															measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons","Common");

															if(measure_icontxt==null || measure_icontxt.trim().length()==0)
																measure_icontxt="measureCommon";
														}
													}
												}

												if(!isDescriptor)
												{
													String disp_trans_img=trsn_img;
													if(disp_trans_img!=null && disp_trans_img.equals("image1"))
													{
														disp_trans_img="images";
													}

													minMaxTableDataObject.put("value0","trans_"+disp_trans_img+"_small");
													//minMaxTableDataObject.put("value0_tip",iniIdentity+trsn_img);
													minMaxTableDataObject.put("value0_tip",mappingInfo.getTextDescription(iniIdentity+trsn_img));
												}
												else
												{
													minMaxTableDataObject.put("value0",trsn_img);
													minMaxTableDataObject.put("value0_tip",mappingInfo.getComponentTypeDescription(selected_qua_tier));
												}
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(s_dispName));
												minMaxTableDataObject.put("value0_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_mouse",class_mouse);
											}
											if(!isShowStateColor)
												state_value = "GRAY";
											if(measure_value!=null && measure_value.length()>0)
											{
												minMaxTableDataObject.put("value1",formatDbValue(measure_value));
												minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
												minMaxTableDataObject.put("value1_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_state",state_value);
												minMaxTableDataObject.put("value1_mouse",class_mouse);
											}
											else
											{
												minMaxTableDataObject.put("value1","-");
												minMaxTableDataObject.put("value1_tip",s_dispName+unitForMeasure+"("+host_name+")");
												minMaxTableDataObject.put("value1_state",state_value);
											}
											if(loopTotNQ==(zz+1))
											{
												//--- html tr ends
												minMaxTableDataObject.put("value1_endTR","true");
											}

											minMaxTableDataArray.add(minMaxTableDataObject);
										}
									}
									else
									{
										count_else_loop++;
									}
								}
							}

							if(count_else_loop==key_unit_list.size())
							{
								serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
							}
							else
							{
								if(minMaxTableDataArray!=null && minMaxTableDataArray.size()>0)
									minMaxTable.put("minMaxTableDataArray",minMaxTableDataArray);

								serviceQualityDataJson.put("minMaxTable",minMaxTable);
							}
						}
						else
						{
							serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
						}

						if(!(key_unit_list.size()==1 && key_testmea_list.size()==1 && descri_info.equals("+")))
						{
							//--html table td ends--
							serviceQualityDataJson.put("endTable","true");
						}
					}
					else if(slist!=null && slist.size()>0)
					{
						boolean more_then_one=false;

						if(!(isQualityAggSiteService && ((qualityTestWithMeaList!=null && qualityTestWithMeaList.size()==1) || (slist.size()==1)) && qualityCtypeList!=null && qualityCtypeList.size()==1))
						{
							more_then_one=true;
							serviceQualityDataJson.put("more_then_one","true");
						}
						if(resultHash!=null && resultHash.size()>0 && loopTotNQ>0)
						{
							JSONObject minMaxTable = new JSONObject();
							JSONArray minMaxTableDataArray = new JSONArray();

							int count_else_loop=0;
							ArrayList temp_dummy_list=new ArrayList();
							for(int zz=0;zz<loopTotNQ;zz++)
							{
								String selected_qua_tier="";
								String quality_test_measure="";
								String selected_qua_tier_with_all=(String)qualityTestMeaList.get(zz);
								if(selected_qua_tier_with_all!=null && selected_qua_tier_with_all.length()>0)
								{
									selected_qua_tier=selected_qua_tier_with_all.substring(0,selected_qua_tier_with_all.indexOf(":"));

									if(selected_qua_tier!=null && selected_qua_tier.startsWith("CT^"))
									{
										selected_qua_tier=selected_qua_tier.substring(selected_qua_tier.indexOf("^")+1);
									}

									quality_test_measure=selected_qua_tier_with_all.substring(selected_qua_tier_with_all.indexOf(":")+1);
								}
								if(quality_test_measure!=null && quality_test_measure.trim().length()>0)
								{
									test_measure = quality_test_measure;
									test_name="";
									measure_name="";
									db_measure="";
									s_dispName="";
									temp_unit="";
									temp_Or="";
									unitForMeasure="";
									String unit_k="";
									tokens = StringUtils.getTokens(test_measure,":");
									if(tokens!=null && tokens.length>1)
									{
										int inx=0;
										if(tokens.length==5)
										{
											nick_name=tokens[inx++];
											if(nick_name!=null && nick_name.startsWith("CN^"))
											{
												nick_name=nick_name.substring(nick_name.indexOf("^")+1);
											}
										}

										test_name = tokens[inx++];
										measure_name = tokens[inx++];
										db_measure = dbInfo.getColumnForMeasure(test_name,measure_name);
										if(db_measure==null || db_measure.trim().length()==0)
											db_measure=measure_name;
										if(tokens.length > 2)
										{
											s_dispName = tokens[inx++];
										}
										if(tokens.length > 3)
										{
											//temp_unit=tokens[inx++];
											temp_Or=tokens[inx++];
											ArrayList orAlist = StringUtils.egTokenizer(temp_Or,"~",false,true,true);
											if(orAlist!=null && orAlist.size()==1)
											{
												//temp_unit=(String)orAlist.get(0);
											}
											else if(orAlist!=null && orAlist.size()==2)
											{
												//temp_unit=(String)orAlist.get(0);
												temp_Or=(String)orAlist.get(1);
											}
										}
									}
									if(test_name!=null && measure_name!=null && measure_name.trim().length()>0 && test_name.trim().length()>0)
									{
										if(s_dispName==null || s_dispName.trim().length()==0)
											s_dispName = mappingInfo.getMeasureDescription(test_name,measure_name);

										if(temp_unit==null || temp_unit.trim().length()==0)
										{
											String un=tablesInfo.getUnitForMeasure(test_name,measure_name);
											unit_k=un;
											if(un!=null && un.equals("MB"))
												un="GB";
											if(un.equals("Number"))
												un="No.";
											unitForMeasure="("+un+")";
										}
										else if(temp_unit!=null && temp_unit.trim().length()>0)
										{
											unit_k=temp_unit;
											unitForMeasure="("+temp_unit+")";
										}
									}
									String key_comp1=test_name+":"+db_measure;
									String sep=":";
									if(temp_dummy_list!=null && temp_dummy_list.contains(key_comp1))
									{
										continue;
									}
									else if(slist!=null && temp_Or!=null && temp_Or.equalsIgnoreCase("or"))
									{
										boolean flage_continue=true;
										if(infoFlage)
											sep="~";
										for(int kk=0;kk<key_unit_list.size();kk++)
										{
											String str_unit=(String)key_unit_list.get(kk);
											if(slist.contains(key_comp1+sep+str_unit))
											{
												flage_continue=false;
												break;
											}
										}
										if(flage_continue)
											continue;
									}
									else infoFlage=false;
									temp_dummy_list.add(key_comp1);
									boolean flageFirst=true;
									//for(int kk=0;kk<key_unit_list.size() && kk < showTopN;kk++)
									for(int kk=0;kk<key_unit_list.size();kk++)
									{
										String str_unit=(String)key_unit_list.get(kk);
										String measure_value=(String)resultHash.get(key_comp1+sep+str_unit);
										if(measure_value==null || measure_value.trim().length()==0)
											measure_value=(String)resultHash.get(key_comp1);

										String descri_info="+";
										String url_descri_info="";
										if(sep!=null && sep.equals("~"))
										{
											if(str_unit!=null && !str_unit.equals("") && str_unit.indexOf(":") > -1 )
												descri_info=(String)str_unit.substring(0,str_unit.indexOf(":"));
											else
												descri_info=str_unit;
											if(descri_info!=null && descri_info.trim().length()>0 && descri_info.startsWith("+"))
											{
												url_descri_info=descri_info.substring(1);
											}
										}

										String url_for_graph="";
										String comp="";
										String host_type="";
										String host_name="";
										String port="";
										String sid="";
										String msmtHost="";
										String state_value="GRAY";
										String comp_name="";
										String layerName="";
										String url_for_layermodel="";
										String state_display="GRAY";
										String class_mouse="mouse";
										ArrayList selectedQualityCompList=(ArrayList)selectedQualityCompHash.get(selected_qua_tier);

										ArrayList selectedQualityOrgCompList=(ArrayList)selectedQualityCompHash.get(selected_qua_tier+"_real");

										if(isQualityAggSiteService || (selectedQualityOrgCompList!=null && selectedQualityOrgCompList.size()==1))
										{
											if(selectedQualityOrgCompList!=null && selectedQualityOrgCompList.size()>0)
												comp = (String)selectedQualityOrgCompList.get(0);
											else if(selectedQualityCompList!=null && selectedQualityCompList.size()>0)
												comp = (String)selectedQualityCompList.get(0);

											String comp_tokens[] = StringUtils.getTokens(comp,":");
											
											if(comp_tokens!=null && comp_tokens.length>1)
											{
												host_type = comp_tokens[0];
												host_name = comp_tokens[1];
												comp_name=host_name;
												if(comp_tokens.length > 2)
												{
													port = comp_tokens[2];
													if(specsInfo.isPortRelevantForTest(test_name))
													{
														comp_name=comp_name+":"+port;
													}
													else
													{
														comp_name=comp_name+":NULL";
													}
												}
												if(comp_tokens.length > 3)
												{
													sid=comp_tokens[3];
													comp_name=comp_name+":"+sid;
												}
											}
											ArrayList layersOfComp = new ArrayList();
											layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_qua_tier);

											String Layer_name_str=tablesInfo.getLayerForTest(test_name);
											layerName="HOST";
											if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
											{
												StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
												if(tokenLayer!=null)
												{
													while(tokenLayer.hasMoreTokens())
													{
														String l_name=(String)tokenLayer.nextToken();
														if(l_name!=null)
														{
															if(layersOfComp != null && layersOfComp.contains(l_name))
															{
																if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
																{
																	layerName=l_name;
																	break;
																}
															}
															else
																continue;
														}
													}
												}
											}
											List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
											if(agents!=null && agents.size()>0)
												msmtHost=(String)agents.get(0);
											else
												msmtHost=host_name;

											//state_value=(String)servicesBean.getStateForMeasure(selected_qua_tier,comp_name,layerName,test_name,measure_name,descri_info,msmtHost);
											try
											{
												if(stateMeasure != null)
												{
													String temp_info=descri_info;
													if(!temp_info.startsWith("+"))
														temp_info="+"+temp_info;
													String state_key = "NULL^eg^"+selected_qua_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^"+temp_info+"^eg^"+measure_name;
													state_value = (String)stateMeasure.get(state_key);
												}
											}
											catch (Exception er)
											{
											}

											if(state_value==null || state_value.trim().length()==0)
												state_value="GOOD";

											if (EgConfigInfo.isBad(state_value))
											{
												state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_qua_tier,layerName,descri_info,test_name,msmtHost,measure_name,"");
											}

											String url_site="NULL";
											if(layerName.equals("WEB_SITE") || layerName.equals("WEB_TRANSACTIONS") || test_name.equals("WebSiteTest") || test_name.equals("WebSiteTransactionTest"))
											{
												url_site=site_name;
											}

											url_for_graph="gtype=yes&showRange=Range&mode=2D&info=*&monitorSkin="+monitor_Skin+"&gformat=graph&measure="+db_measure+"&test="+test_name+"&port="+port+"&site="+url_site+"&comptype="+host_type+"&host="+host_name+"&layer="+layerName+"&msmt_host="+msmtHost+"&width="+graphWidth+"&timeLine=1 hour&height=100&from_page=serviceOverview&threshold=no&from=cview&bgStyle="+bg_style+"&starttime=&endtime=&starthr=&endhr=";

											String display_c_name=comp_name;

											if (display_c_name.endsWith(EgConstants.NULL_PORT) && (display_c_name.indexOf(EgConstants.NULL_PORT) > -1))
											{
												display_c_name = Server.getServerNameWithoutPort(display_c_name, false);
											}

											String displayComponentType = mappingInfo.getComponentTypeDescription(selected_qua_tier);
											String temp_compName = null;
											if(comp_name != null && port != null)
											{
												if(comp_name.indexOf(":") > -1)
													comp_name = comp_name.substring(0,comp_name.indexOf(":"));
												temp_compName = comp_name+":"+port;
											}
											url_for_layermodel="/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&host="+EgURLEncoder.encode(temp_compName,"UTF-8")+"&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&site="+EgURLEncoder.encode(url_site,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&test="+test_name+"-"+EgURLEncoder.encode(url_descri_info,"UTF-8")+"&comptype="+EgURLEncoder.encode(selected_qua_tier,"UTF-8")+"&tstate="+EgURLEncoder.encode(state_value,"UTF-8")+"&newWindow=false&prevPage=MainDashBoard&isServiceBusiDash="+isServiceBusiDash;

											if(descri_info!=null && descri_info.equals("+"))
												url_for_layermodel=url_for_layermodel+"&findInfo=true";
										
											state_display=mappingInfo.getLabelDescription(state_value);
										}
										else 
										{
											class_mouse="mouse";
											String actipnreq = request.getParameter("action");
											if(actipnreq.equalsIgnoreCase("service"))
												actipnreq = "services";
											url_for_layermodel="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&fromAcessPage=bussinessDashboard&from=bussinessDashboard&action=component&searchIndComps=checked&isFromMenu=false&view=metric&viewId=components&viewPageTitle=Components&viewTreeTitle=Component&filterBy="+actipnreq+"&subFilter="+service_name+"&componentType="+selected_qua_tier+"&isServiceBusiDash=true";
										}										

										if((isQualityAggSiteService || (selectedQualityOrgCompList!=null && selectedQualityOrgCompList.size()==1)) && ((qualityTestWithMeaList!=null && qualityTestWithMeaList.size()==1) && (slist.size()==1)) && qualityCtypeList!=null && qualityCtypeList.size()==1 && show_graph_flag)
										{
											Hashtable avgMinMaxData =new Hashtable();
											if(isShowGraphMAM)
											{
												avgMinMaxData =measureGraphInfo.getAvgMaxMinData(db_measure,test_name,host_name,port,site_name,descri_info,msmtHost,host_type,"1 hour",user);
											}
											String avg_str="-";
											String max_str="-";
											String min_str="-";
											String td_width="185";
											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												ArrayList meaList=(ArrayList)avgMinMaxData.get(measure_name+" ("+unit_k+")");
												if(meaList!=null && meaList.size()>0)
													avg_str=(String)meaList.get(0);
												if(meaList!=null && meaList.size()>1)
													max_str=(String)meaList.get(1);
												if(meaList!=null && meaList.size()>2)
													min_str=(String)meaList.get(2);
												td_width="100%";
											}

											minMaxTable.put("ChartId","qhigh_"+service_name+"_"+zz);

											minMaxTable.put("ChartName",s_dispName+unitForMeasure);
											minMaxTable.put("ChartTdWidth",td_width);
											minMaxTable.put("ChartURL",url_for_graph);
											minMaxTable.put("ChartURLForLM",url_for_layermodel);
											minMaxTable.put("ChartClass",class_mouse);

											minMaxTable.put("chartOption",chartOption);
											minMaxTable.put("chartTimeline",chartTimeline);

											if(isShowGraphMAM && avgMinMaxData!=null && avgMinMaxData.size()>0)
											{
												minMaxTable.put("ChartState",mappingInfo.getTextDescription("monitor.measure.State"));
												minMaxTable.put("ChartAvg",mappingInfo.getTextDescription("monitor.measure.Avg"));
												minMaxTable.put("ChartMax",mappingInfo.getTextDescription("monitor.measure.Max"));
												minMaxTable.put("ChartMin",mappingInfo.getTextDescription("monitor.measure.Min"));

												minMaxTable.put("ChartStateVal",state_value);
												minMaxTable.put("ChartStateDisp",state_display);

												minMaxTable.put("ChartAvgVal",formatDbValue(avg_str));
												minMaxTable.put("ChartMaxVal",formatDbValue(max_str));
												minMaxTable.put("ChartMinVal",formatDbValue(min_str));
											}
										}
										else
										{
											JSONObject minMaxTableDataObject = new JSONObject();

											String disp_info="";
											if(infoFlage && str_unit!=null && str_unit.indexOf(":")>-1)
											{
												disp_info=str_unit.substring(0,str_unit.lastIndexOf(":"));
												if(disp_info.startsWith("+"))
													disp_info=disp_info.substring(1);
											}
											if(!isShowStateColor)
												state_value="GRAY";	
											if(infoFlage)
											{
												minMaxTableDataObject.put("value0_info","true");
												minMaxTableDataObject.put("value0",state_value);

												minMaxTableDataObject.put("value0_tip",state_display);
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(s_dispName));
												
												minMaxTableDataObject.put("value0_url",url_for_layermodel);

												minMaxTableDataObject.put("value0_mouse",class_mouse);
											}
											else if(more_then_one && !infoFlage && flageFirst)
											{
												flageFirst=false;
												String tier_tmp=selected_qua_tier;
												if(selected_qua_tier!=null && selected_qua_tier.startsWith("Agg_"))
												{
													tier_tmp=selected_qua_tier.substring(selected_qua_tier.indexOf("_")+1);
												}

												String icon_txt="serviceIcon_"+tier_tmp;
												String measure_icontxt=(String)serviceDashIni.getValue("Measure_icons",measure_name);
												if(measure_icontxt==null || measure_icontxt.trim().length()==0)
												{
													measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons",unit_k);

													if(measure_icontxt==null || measure_icontxt.trim().length()==0)
													{
														measure_icontxt=(String)serviceDashIni.getValue("Measure_Unit_icons","Common");

														if(measure_icontxt==null || measure_icontxt.trim().length()==0)
															measure_icontxt="measureCommon";
													}
												}

												minMaxTableDataObject.put("value0",measure_icontxt);

												minMaxTableDataObject.put("value0_tip",mappingInfo.getComponentTypeDescription(selected_qua_tier));
												minMaxTableDataObject.put("value0_disp",mappingInfo.getComponentTypeDescription(s_dispName));
												minMaxTableDataObject.put("value0_d_tip",s_dispName+unitForMeasure);
												minMaxTableDataObject.put("value0_url",url_for_layermodel);

												minMaxTableDataObject.put("value0_mouse",class_mouse);
											}

											if(measure_value!=null && measure_value.length()>0)
											{
												minMaxTableDataObject.put("value1",formatDbValue(measure_value));
												minMaxTableDataObject.put("value1_url",url_for_layermodel);
												minMaxTableDataObject.put("value1_state",state_value);
												minMaxTableDataObject.put("value1_mouse",class_mouse);
											}
											else
											{
												if(sameKeyFlage)
												{
													minMaxTableDataObject.put("value1","-");
													minMaxTableDataObject.put("value1_state",state_value);
												}
											}
											if(infoFlage)
											{
												//--- html tr ends--
												minMaxTableDataObject.put("value1_endTR","true");
											}
											minMaxTableDataArray.add(minMaxTableDataObject);
										}
									}
									if(more_then_one && !infoFlage)
									{
										// -- html tr ends
										JSONObject minMaxTableDataObject = new JSONObject();
										minMaxTableDataObject.put("more_then_one_End","true");
										minMaxTableDataArray.add(minMaxTableDataObject);
									}
								}
								else
								{
									count_else_loop++;
								}
							}

							if(count_else_loop==loopTotNQ)
							{
								serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
							}
							else
							{
								if(minMaxTableDataArray!=null && minMaxTableDataArray.size()>0)
									minMaxTable.put("minMaxTableDataArray",minMaxTableDataArray);

								serviceQualityDataJson.put("minMaxTable",minMaxTable);
							}
						}
						else
						{
							serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
						}
						if(!(isQualityAggSiteService && ((qualityTestWithMeaList!=null && qualityTestWithMeaList.size()==1) && (slist.size()==1)) && qualityCtypeList!=null && qualityCtypeList.size()==1))
						{
							//-- html table td ends
							serviceQualityDataJson.put("endTable","true");
						}
					}
					else
					{
						serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
					}
					serviceQualityDataArr.add(serviceQualityDataJson);
				}
				else
				{
					JSONObject serviceQualityDataJson = new JSONObject();
					serviceQualityDataJson.put("ErrMsg",mappingInfo.getTextDescription("monitor.VirtualDashboard.No Data found"));
					serviceQualityDataArr.add(serviceQualityDataJson);
				}

				serviceDataJson.put("serviceQualityData",serviceQualityDataArr);

//------------------Tier Health------------------------------------------------------------------->

				JSONArray serviceTierHealthDataArr = new JSONArray();

				if(aList_info!=null && aList_info.size()>0)
				{
					String Show_TopTier=(String)serviceDashIni.getValue("Services_Overview_Common","Show_TopTier");
					int show_top=0;
					String spec_state=null;
					if(Show_TopTier!=null)
					{
						try
						{
							show_top=Integer.parseInt(Show_TopTier);
						}
						catch(Throwable th)
						{
							if(aList_info!=null && aList_info.size()>0)
							{
								show_top = (aList_info.size()/3);
							}
							spec_state = Show_TopTier;
						}
					}
					ArrayList add_ct=new ArrayList();
					for(int k = 0; k < aList_info.size(); k=k+3)
					{
						if((show_top*3) < (k+1))
							break;
						String ct = (String) aList_info.get(k);
						String ct_state = (String) aList_info.get(k+1);
						String ct_org = (String) aList_info.get(k+2);
						
						if(add_ct!=null && add_ct.contains(ct_org))
							continue;
						String tokens_st[] = StringUtils.getTokens(ct_state,"^");

						if(spec_state!=null && spec_state.equalsIgnoreCase("Abnormal") && tokens_st[1]!=null && tokens_st[1].equalsIgnoreCase("GOOD"))
							continue;
						else if(spec_state!=null && !spec_state.equalsIgnoreCase("All") && !spec_state.equalsIgnoreCase("Abnormal") && tokens_st[1]!=null && !tokens_st[1].equalsIgnoreCase(spec_state))
							continue;

						if(ct!=null && ct.trim().length()>0)
						{
							JSONObject serviceTierHealthDataJson = new JSONObject();

							String compUrl="";

							if(ct_org!=null && ct_org.startsWith("Agg_"))
							{
								compUrl="../servlet/com.eg.EgMonitorController?monCmd=componentList&isServiceBusiDash="+isServiceBusiDash+"&from=MainDashboard&searchStateString=All States&action=componentType&searchIndComps=checked&componentType="+EgURLEncoder.encode(ct_org,"UTF-8")+"&menuName=agg&who=fromServerTypes&serviceName="+EgURLEncoder.encode(service_name,"UTF-8");

								if(isSite)
								{
									compUrl="../servlet/com.eg.EgMonitorController?monCmd=componentList&isServiceBusiDash="+isServiceBusiDash+"&from=MainDashboard&searchStateString=All States&action=componentType&searchIndComps=checked&componentType="+EgURLEncoder.encode(ct_org,"UTF-8")+"&menuName=agg&who=fromServerTypes&serviceName="+EgURLEncoder.encode(service_name,"UTF-8");
								}
							}
							else
							{
								compUrl="../servlet/com.eg.EgMonitorController?service= "+EgURLEncoder.encode(service_name,"UTF-8")+"&monCmd=componentList&from=MainDashboard&action=componentType&componentType="+EgURLEncoder.encode(ct_org,"UTF-8")+"&searchIndComps=true&serviceName="+EgURLEncoder.encode(service_name,"UTF-8")+"&selectNode_SBD="+EgURLEncoder.encode("Service$cap$"+service_name,"UTF-8")+"&isServiceBusiDetails=true";
								

								if(isSite)
								{
									compUrl="../servlet/com.eg.EgMonitorController?site="+EgURLEncoder.encode(service_name,"UTF-8")+"&monCmd=componentList&isServiceBusiDash="+isServiceBusiDash+"&from=MainDashboard&action=componentType&componentType="+EgURLEncoder.encode(ct_org,"UTF-8")+"&searchIndComps=true";
								}
							}

							serviceTierHealthDataJson.put("tierStyle","state_"+tokens_st[1]);
							serviceTierHealthDataJson.put("tierTip",ct);
							serviceTierHealthDataJson.put("tierDisplay",ct);
							serviceTierHealthDataJson.put("tierClickURL",compUrl);

							add_ct.add(ct_org);

							serviceTierHealthDataArr.add(serviceTierHealthDataJson);
						}
					}
				}

				serviceDataJson.put("serviceTierHealthData",serviceTierHealthDataArr);

				jsonArr.add(serviceDataJson);
			}
			if(ServicesToSkipList!=null && cnt==ServicesToSkipList.size() && cnt==totServices)
			{
				json.put("errMsg",mappingInfo.getTextDescription("monitor.services.No services to display "));
			}
			else if(jsonArr!=null && jsonArr.size()>0)
			{
				json.put("servicesBusinessData",jsonArr);
			}
			else
			{
				json.put("errMsg",mappingInfo.getTextDescription("monitor.services.No services to display "));
			}
		}
		else
		{
			json.put("errMsg",mappingInfo.getTextDescription("monitor.services.No services found"));
			json.put("errImg","/final/monitor/eg_images/"+monitor_Skin+"/icon_exclamation.png");
		}
	}
	else
	{
		json.put("errMsg",mappingInfo.getTextDescription("monitor.services.No services found"));
	}

	if(request.getQueryString()!=null)
	{
		session.setAttribute("monitorLastSession","/final/monitor/servicesBusinessDashMain.jsp?"+request.getQueryString()+"&isServiceBusiDash=true");
	}
	else
	{
		session.setAttribute("monitorLastSession","/final/monitor/servicesBusinessDashMain.jsp");
	}
	String showLegStr = request.getParameter("showLegend");
	/*if(showLegStr == null || showLegStr.equals(""))
	{
		showLegStr = uiIni.getValue("CHART_TYPE","showLegendsInCharts");
	}*/
	showLegStr = (showLegStr==null || showLegStr.equals(""))?"false":showLegStr;
	json.put("showLegend",showLegStr);

	response.getWriter().write(json.toString());
}
catch(Throwable e)
{
	System.out.println("Exception is servicesBusinessDashMain page--->"+e);
	e.printStackTrace();
}
%>

<%!
	private IniFile iniObj=new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_serverdashboard.ini",true);
	public final String CRITICAL=iniObj.getValue("State_Colors","CRITICAL");
	public final String MAJOR=iniObj.getValue("State_Colors","MAJOR");
	public final String MINOR=iniObj.getValue("State_Colors","MINOR");
	public final String GOOD=iniObj.getValue("State_Colors","GOOD");
	public final String UNKNOWN=iniObj.getValue("State_Colors","UNKNOWN");
	public final String GRAY=iniObj.getValue("State_Colors","GRAY");
	public final String DARKGRAY=iniObj.getValue("State_Colors","DARKGRAY");

	private static DecimalFormat df = (DecimalFormat)NumberFormat.getNumberInstance();
	static{
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setDecimalSeparator('.');

        df.applyPattern("#.##");
        df.setDecimalFormatSymbols(dfs);
        df.setGroupingSize(0);
	}

	private static DecimalFormat df2 = (DecimalFormat)NumberFormat.getNumberInstance();
	static{
        DecimalFormatSymbols dfs2 = new DecimalFormatSymbols();
        dfs2.setDecimalSeparator('.');

        df2.applyPattern("#.####");
        df2.setDecimalFormatSymbols(dfs2);
        df2.setGroupingSize(0);
	}

	private static DecimalFormat df3 = (DecimalFormat)NumberFormat.getNumberInstance();
	static{
        DecimalFormatSymbols dfs3 = new DecimalFormatSymbols();
        dfs3.setDecimalSeparator('.');

        df3.applyPattern("#");
        df3.setDecimalFormatSymbols(dfs3);
        df3.setGroupingSize(0);
	}

	public static String formatDbValue(String measure)
	{
		String value="";
		try
		{
			/*
				* Check the indexOf "e", For avoid Exponent or Scientific Notation in a String, 
				Because of Address and other String field changed like double data type value
				when we use Double.parseDouble, Its wrong, So put this fix.

				* The real double value not affected because of this change. its shown as per db..

				* changed by Saravanan.A on 31-1-2012.
			*/

			/*
				* Double parsing have problem when double value range exceed, So used BigDecimal instead of Double parsing.

				* changed by Saravanan.A on 15-2-2012.
			*/

			String measure_lower=null;
			if(measure!=null && measure.length()>0)
				measure_lower=measure.toLowerCase().trim();
			
			if(measure_lower!=null && measure_lower.indexOf("e")>-1)
			{
				value=measure;
			}
			else
			{
				//double val=Double.parseDouble(measure);
				//value = df.format(val);

				BigDecimal bigDecRef = new BigDecimal(measure);
				value = df.format(bigDecRef);
				double xxx=bigDecRef.doubleValue();
				if(xxx>=100.0)
				{
					value = df3.format(bigDecRef);
				}
				else if(xxx>=1 && xxx<100)
				{
					value = df.format(bigDecRef);
				}

			}
		}catch(Exception e)
		{
			value=measure;
		}
		return value;
	}

	public String getStateForSegment(String serviceName, String segmentName)
	{
		ServiceDAO dao = MonitorDAOFactory.getInstance().getServiceDAO();
		return dao.getStateForSegment(serviceName, segmentName);
	}

	public String getXMLForPieOverview(Hashtable stateCountHash,String thisLanguage,IniUI iniUI,String radius,String url_for_layermodel,String monitor_Skin)
	{
		StringBuffer xmlData=new StringBuffer("");

		try
		{
			String font="verdana";
			boolean isNonEnglishLanguage=((EgDbInfo.doubleByteEnabled && !thisLanguage.equals("en_US")) || !thisLanguage.equals("en_US"));

			if(isNonEnglishLanguage)
				font=iniUI.getFontName();
			else
				font="verdana";

			Double criticalPct=null;
			Double majorPct=null;
			Double minorPct=null;
			Double unknownPct=null;
			Double goodPct=null;
			Double grayPct=null;
			Double nonAggGrayPct=null;

			if(stateCountHash!=null)
			{
				criticalPct=(Double)stateCountHash.get("HIGH");
				majorPct=(Double)stateCountHash.get("INTERMEDIATE");
				minorPct=(Double)stateCountHash.get("LOW");
				unknownPct=(Double)stateCountHash.get("UNKNOWN");
				goodPct=(Double)stateCountHash.get("GOOD");
				grayPct=(Double)stateCountHash.get("GRAY");
				nonAggGrayPct=(Double)stateCountHash.get("DARKGRAY");
			}

			int count_sli=0;
			if(criticalPct!=null && criticalPct.doubleValue()>0)
				count_sli++;
			if(majorPct!=null && majorPct.doubleValue()>0)
				count_sli++;
			if(minorPct!=null && minorPct.doubleValue()>0)
				count_sli++;
			if(unknownPct!=null && unknownPct.doubleValue()>0)
				count_sli++;
			if(goodPct!=null && goodPct.doubleValue()>0)
				count_sli++;
			if(grayPct!=null && grayPct.doubleValue()>0)
				count_sli++;
			if(nonAggGrayPct!=null && nonAggGrayPct.doubleValue()>0)
				count_sli++;

			Vector pieChartAttributes=new Vector();

			pieChartAttributes.add("palette='2'");
			pieChartAttributes.add("paletteColors='99CCFF,FFFFFF'");
			pieChartAttributes.add("decimals='2'");
			pieChartAttributes.add("showPercentValues='0'");
			pieChartAttributes.add("showLabels='0'");
			pieChartAttributes.add("showValues='0'");
			pieChartAttributes.add("showToolTip='0'");
			pieChartAttributes.add("enableRotation='0'");
			pieChartAttributes.add("bgColor='99CCFF,FFFFFF'");
			pieChartAttributes.add("bgAlpha='0,0'");// for transparent 0,0
			pieChartAttributes.add("bgRatio='0,100'");
			pieChartAttributes.add("bgAngle='180'");
			pieChartAttributes.add("showBorder='0'");
			pieChartAttributes.add("startingAngle='240'");
			//pieChartAttributes.add("pieInnerFaceAlpha='60'");
			//pieChartAttributes.add("pieOuterFaceAlpha='20'");
			if(count_sli==1)
			{
				pieChartAttributes.add(" baseFontColor='FFFFFF'");
				pieChartAttributes.add(" toolTipBgColor='000000'");
			}
			else
			{
				pieChartAttributes.add(" baseFontColor='545454'");
			}
			//pieChartAttributes.add("exportEnabled='1'");
			//pieChartAttributes.add("exportAction='download'");
			//pieChartAttributes.add("exportAtClient='0'");
			//pieChartAttributes.add("exportHandler='/final/FusionCharts/jsp/FCExporter.jsp'");
			pieChartAttributes.add("chartLeftMargin='0'");
			pieChartAttributes.add("chartTopMargin='0'");
			pieChartAttributes.add("chartBottomMargin='0'");
			pieChartAttributes.add("chartRightMargin='0'");
			pieChartAttributes.add("showToolTipShadow='0'");
			pieChartAttributes.add("showPercentageValues='0'");
			pieChartAttributes.add("showPercentInToolTip='0'");
			pieChartAttributes.add("pieSliceDepth='10'");
			pieChartAttributes.add("pieOuterFaceAlpha='100'");
			pieChartAttributes.add("pieYScale='27'"); //--pie
			//pieChartAttributes.add("pieYScale='95'");
			pieChartAttributes.add("smartLineColor='000000'");
			pieChartAttributes.add("captionPadding='0'");
			//---resize-- no need this pieRadius, becasuse fusion charts 
			if(radius!=null && radius.trim().length()>0)
			{
				pieChartAttributes.add("pieRadius='"+radius+"'");
			}
			else
			{
				//pieChartAttributes.add("pieRadius='47'"); // pie
				pieChartAttributes.add("pieRadius='32'"); 
				pieChartAttributes.add("doughnutRadius='5'"); 
			}
			//---end--
			pieChartAttributes.add("bgSWFAlpha='0'");
			pieChartAttributes.add("slicingDistance='0'");
			pieChartAttributes.add("enableSmartLabels='0'");
			pieChartAttributes.add("showShadow='0'");
			pieChartAttributes.add("use3DLighting='1'");
			pieChartAttributes.add("manageLabelOverflow='1'");
			pieChartAttributes.add("useEllipsesWhenOverflow='1'");
			pieChartAttributes.add("showAboutMenuItem='1' aboutMenuItemLabel='About eG Innovations' aboutMenuItemLink='n-://www.eginnovations.com'");

			xmlData.append("<chart");
			if(pieChartAttributes!=null && pieChartAttributes.size()>0)
			{
				Iterator itr=pieChartAttributes.iterator();
				while(itr.hasNext())
				{
					xmlData.append(" ");
					xmlData.append((String)itr.next());
				}
			}
			xmlData.append(" baseFont  ='"+font+"'");
			xmlData.append(">");


			boolean isCurrentStatus=true;
			if(count_sli==0)
			{
				isCurrentStatus=false;
			}

			if(isCurrentStatus)
			{
				String Pie_GRAY="";
				String Pie_DARKGRAY="";
				if(monitor_Skin!=null && monitor_Skin.equalsIgnoreCase("DARK"))
				{
					Pie_GRAY="#595959";
					Pie_DARKGRAY="#5e5e5e";
				}
				else
				{
					Pie_GRAY="#dbdbdb";
					Pie_DARKGRAY="#a2a2a2";
				}

				if(criticalPct!=null && criticalPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+criticalPct+"' link='"+url_for_layermodel+"' color='"+CRITICAL+"'/>");
				}
				if(majorPct!=null && majorPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+majorPct+"' link='"+url_for_layermodel+"' color='"+MAJOR+"'/>");
				}
				if(minorPct!=null && minorPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+minorPct+"' link='"+url_for_layermodel+"' color='"+MINOR+"'/>");
				}
				if(unknownPct!=null && unknownPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+unknownPct+"' link='"+url_for_layermodel+"' color='"+UNKNOWN+"'/>");
				}
				if(goodPct!=null && goodPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+goodPct+"' link='"+url_for_layermodel+"' color='"+GOOD+"'/>");
				}

				if(grayPct!=null && grayPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+grayPct+"' link='"+url_for_layermodel+"' color='"+Pie_GRAY+"'/>");
				}

				if(nonAggGrayPct!=null && nonAggGrayPct.doubleValue()>0)
				{
					xmlData.append("<set value='"+nonAggGrayPct+"' link='"+url_for_layermodel+"' color='"+Pie_DARKGRAY+"'/>");
				}
				xmlData.append("</chart>");
			}
		}
		catch(Throwable th)
		{
			th.printStackTrace();
			return "";
		}

		return xmlData.toString();
	}

	public JSONObject getJsonForPieOverview (Hashtable stateCountHash,String thisLanguage,IniUI iniUI,String radius,String url_for_layermodel,String monitor_Skin,EgMappingInfo mappingInfo)
	{
		Double criticalPct=null;
		Double majorPct=null;
		Double minorPct=null;
		Double unknownPct=null;
		Double goodPct=null;
		Double grayPct=null;
		Double nonAggGrayPct=null;
		if(stateCountHash!=null)
		{
			criticalPct=(Double)stateCountHash.get("HIGH");
			majorPct=(Double)stateCountHash.get("INTERMEDIATE");
			minorPct=(Double)stateCountHash.get("LOW");
			unknownPct=(Double)stateCountHash.get("UNKNOWN");
			goodPct=(Double)stateCountHash.get("GOOD");
			grayPct=(Double)stateCountHash.get("GRAY");
			nonAggGrayPct=(Double)stateCountHash.get("DARKGRAY");
		}
		int count_sli=0;
		if(criticalPct!=null && criticalPct.doubleValue()>0)
			count_sli++;
		if(majorPct!=null && majorPct.doubleValue()>0)
			count_sli++;
		if(minorPct!=null && minorPct.doubleValue()>0)
			count_sli++;
		if(unknownPct!=null && unknownPct.doubleValue()>0)
			count_sli++;
		if(goodPct!=null && goodPct.doubleValue()>0)
			count_sli++;
		if(grayPct!=null && grayPct.doubleValue()>0)
			count_sli++;
		if(nonAggGrayPct!=null && nonAggGrayPct.doubleValue()>0)
			count_sli++;
		JSONObject finalJsonObj  = new JSONObject();
		JSONObject dataJsonObj  = new JSONObject();
		JSONArray  doNutJsonArr = new JSONArray();
		JSONObject doNutObj = new JSONObject();
		boolean isCurrentStatus=true;
		if(count_sli==0)
		{
			isCurrentStatus=false;
		}
		if(isCurrentStatus)
		{
			String Pie_GRAY="";
			String Pie_DARKGRAY="";
			if(monitor_Skin!=null && monitor_Skin.equalsIgnoreCase("DARK"))
			{
				Pie_GRAY="#595959";
				Pie_DARKGRAY="#5e5e5e";
			}
			else
			{
				Pie_GRAY="#dbdbdb";
				Pie_DARKGRAY="#a2a2a2";
			}
			doNutObj = new JSONObject();
			if(criticalPct!=null && criticalPct.doubleValue()>0)
			{
				doNutObj.put("name",mappingInfo.getLabelDescription("HIGH"));
				doNutObj.put("y",criticalPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color","#"+CRITICAL);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(majorPct!=null && majorPct.doubleValue()>0)
			{
				doNutObj.put("name",mappingInfo.getLabelDescription("INTERMEDIATE"));
				doNutObj.put("y",majorPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color","#"+MAJOR);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(minorPct!=null && minorPct.doubleValue()>0)
			{
				doNutObj.put("name",mappingInfo.getLabelDescription("LOW"));
				doNutObj.put("y",minorPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color","#"+MINOR);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(unknownPct!=null && unknownPct.doubleValue()>0)
			{
				doNutObj.put("name",mappingInfo.getLabelDescription("UNKNOWN"));
				doNutObj.put("y",unknownPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color","#"+UNKNOWN);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(goodPct!=null && goodPct.doubleValue()>0)
			{
				doNutObj.put("name",mappingInfo.getLabelDescription("GOOD"));
				doNutObj.put("y",goodPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color","#"+GOOD);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(grayPct!=null && grayPct.doubleValue()>0)
			{
				//doNutObj.put("name","GRAY");
				doNutObj.put("y",grayPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color",Pie_GRAY);
				doNutJsonArr.add(doNutObj);
			}
			doNutObj = new JSONObject();
			if(nonAggGrayPct!=null && nonAggGrayPct.doubleValue()>0)
			{
				//doNutObj.put("name","DARKGRAY");
				doNutObj.put("y",nonAggGrayPct);
				doNutObj.put("url",url_for_layermodel);
				doNutObj.put("color",Pie_DARKGRAY);
				doNutJsonArr.add(doNutObj);
			}
		}
		if(doNutJsonArr!=null && doNutJsonArr.size()>0)
		{
			JSONArray jsonDataSetArr = new JSONArray();
			dataJsonObj.put("data",(JSONArray)doNutJsonArr);
			jsonDataSetArr.add(dataJsonObj);
			finalJsonObj.put("DataSet",(JSONArray)jsonDataSetArr);
		}
		return finalJsonObj;
	}
	public ArrayList getStateSortedList(ArrayList key_unit_list,ArrayList demandTestMeaList,Hashtable selectedDemandCompHash,Hashtable stateMeasure)
	{
		List temp_info_HIGH_list=new LinkedList();
		List temp_info_INTER_list=new LinkedList();
		List temp_info_LOW_list=new LinkedList();
		List temp_info_UNKNOWN_list=new LinkedList();
		List temp_info_GOOD_list=new LinkedList();
		List temp_info_all_list=new LinkedList();
		Vector temp_aList_info=new Vector();
		
		EgExternalInfo egExternalInfo=new EgExternalInfo("manager");
		EgTablesInfo tablesInfo=new EgTablesInfo("manager");
		ServicesDashboardBean servicesBean = new ServicesDashboardBean();

		for(int kk=0;kk<key_unit_list.size();kk++)
		{
			String str_unit=(String)key_unit_list.get(kk);
			String url_descri_info="";
			String descri_info="";
			String sep="~";
			if(sep!=null && sep.equals("~"))
			{
				if(str_unit!=null && !str_unit.equals("") && str_unit.indexOf(":") > -1 )
					descri_info=(String)str_unit.substring(0,str_unit.indexOf(":"));
				else
					descri_info=str_unit;
				
			}
			if(demandTestMeaList!=null)
			{
				for(int zz=0;zz<demandTestMeaList.size();zz++)
				{
					String selected_dem_tier="";
					String demand_test_measure="";
					String selected_dem_tier_with_all=(String)demandTestMeaList.get(zz);
					if(selected_dem_tier_with_all!=null && selected_dem_tier_with_all.length()>0)
					{
						selected_dem_tier=selected_dem_tier_with_all.substring(0,selected_dem_tier_with_all.indexOf(":"));

						if(selected_dem_tier!=null && selected_dem_tier.startsWith("CT^"))
						{
							selected_dem_tier=selected_dem_tier.substring(selected_dem_tier.indexOf("^")+1);
						}

						demand_test_measure=selected_dem_tier_with_all.substring(selected_dem_tier_with_all.indexOf(":")+1);
					}
					if(demand_test_measure!=null && demand_test_measure.trim().length()>0)
					{
						String test_measure = demand_test_measure;
						String test_name="";
						String measure_name="";
						String nick_name="";
						String tokens[] = StringUtils.getTokens(test_measure,":");
						if(tokens!=null && tokens.length>1)
						{
							int inx=0;
							if(tokens.length==5)
							{
								nick_name=tokens[inx++];
								if(nick_name!=null && nick_name.startsWith("CN^"))
								{
									nick_name=nick_name.substring(nick_name.indexOf("^")+1);
								}
							}
							test_name = tokens[inx++];
							measure_name = tokens[inx++];
						}

						String comp="";
						String host_type="";
						String host_name="";
						String port="";
						String sid="";
						String msmtHost="";
						String comp_name="";
						String state_value="GRAY";
						String layerName="";
						ArrayList selectedDemandCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier);

						ArrayList selectedDemandOrgCompList=(ArrayList)selectedDemandCompHash.get(selected_dem_tier+"_real");

						if((selectedDemandOrgCompList!=null && selectedDemandOrgCompList.size()==1))
						{
							if(selectedDemandCompList!=null && selectedDemandCompList.size()>0)
								comp = (String)selectedDemandCompList.get(0);

							String comp_tokens[] = StringUtils.getTokens(comp,":");
							
							if(comp_tokens!=null && comp_tokens.length>1)
							{
								host_type = comp_tokens[0];
								host_name = comp_tokens[1];
								comp_name=host_name;
								if(comp_tokens.length > 2)
								{
									port = comp_tokens[2];
									comp_name=comp_name+":"+port;
								}
								if(comp_tokens.length > 3)
								{
									sid=comp_tokens[3];
									comp_name=comp_name+":"+sid;
								}
							}
							ArrayList layersOfComp = new ArrayList();
							layersOfComp=(ArrayList)tablesInfo.getLayersForComponent(selected_dem_tier);
							String Layer_name_str=tablesInfo.getLayerForTest(test_name);
							layerName="HOST";
							if(Layer_name_str!=null && Layer_name_str.trim().length()>0)
							{
								StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
								if(tokenLayer!=null)
								{
									while(tokenLayer.hasMoreTokens())
									{
										String l_name=(String)tokenLayer.nextToken();
										if(l_name!=null)
										{
											if(layersOfComp != null && layersOfComp.contains(l_name))
											{
												if(tablesInfo.isMeasureInLayer(test_name,measure_name,l_name))
												{
													layerName=l_name;
													break;
												}
											}
											else
												continue;
										}
									}
								}
							}
							List agents=egExternalInfo.getAgentsFor(test_name,host_type,host_name);
							if(agents!=null && agents.size()>0)
								msmtHost=(String)agents.get(0);
							else
								msmtHost=host_name;
							//state_value=(String)servicesBean.getStateForMeasure(selected_dem_tier,comp_name,layerName,test_name,measure_name,descri_info,msmtHost);
							try
							{
								if(stateMeasure != null)
								{
									String temp_info=descri_info;
									if(!temp_info.startsWith("+"))
										temp_info="+"+temp_info;
									String state_key = "NULL^eg^"+selected_dem_tier+"^eg^"+comp_name+"^eg^"+layerName+"^eg^"+test_name+"^eg^"+msmtHost+"^eg^"+temp_info+"^eg^"+measure_name;
									state_value = (String)stateMeasure.get(state_key);
								}
							}
							catch (Exception er)
							{
							}

							if(state_value==null || state_value.trim().length()==0)
								state_value="GOOD";

							if (EgConfigInfo.isBad(state_value))
							{
								state_value = com.eg.EgAlarmTable.getTestPriority(comp_name,selected_dem_tier,layerName,descri_info,test_name,msmtHost,measure_name,"");
								
							}

							if(state_value!=null && state_value.equalsIgnoreCase("HIGH") && !temp_info_HIGH_list.contains(str_unit) && !temp_info_all_list.contains(str_unit))
							{
								temp_info_HIGH_list.add(str_unit);
								temp_info_all_list.add(str_unit);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("INTERMEDIATE") && !temp_info_INTER_list.contains(str_unit) && !temp_info_all_list.contains(str_unit))
							{
								temp_info_INTER_list.add(str_unit);
								temp_info_all_list.add(str_unit);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("LOW") && !temp_info_LOW_list.contains(str_unit) && !temp_info_all_list.contains(str_unit))
							{
								temp_info_LOW_list.add(str_unit);
								temp_info_all_list.add(str_unit);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("UNKNOWN") && !temp_info_UNKNOWN_list.contains(str_unit) && !temp_info_all_list.contains(str_unit))
							{
								temp_info_UNKNOWN_list.add(str_unit);
								temp_info_all_list.add(str_unit);
							}
							else if(state_value!=null && state_value.equalsIgnoreCase("GOOD") && !temp_info_GOOD_list.contains(str_unit) && !temp_info_all_list.contains(str_unit))
							{
								temp_info_GOOD_list.add(str_unit);
								temp_info_all_list.add(str_unit);
							}
						}
					}
				}
			}
		}

		if(temp_info_HIGH_list!=null && temp_info_HIGH_list.size()>0)
		{
			EgSorter esort=new EgSorter(temp_info_HIGH_list,1);
			temp_info_HIGH_list=esort.sort(1,"String","asc");
			temp_aList_info.addAll(temp_info_HIGH_list);
		}
		if(temp_info_INTER_list!=null && temp_info_INTER_list.size()>0)
		{
			EgSorter esort=new EgSorter(temp_info_INTER_list,1);
			temp_info_INTER_list=esort.sort(1,"String","asc");
			temp_aList_info.addAll(temp_info_INTER_list);
		}
		if(temp_info_LOW_list!=null && temp_info_LOW_list.size()>0)
		{
			EgSorter esort=new EgSorter(temp_info_LOW_list,1);
			temp_info_LOW_list=esort.sort(1,"String","asc");
			temp_aList_info.addAll(temp_info_LOW_list);
		}
		if(temp_info_UNKNOWN_list!=null && temp_info_UNKNOWN_list.size()>0)
		{
			EgSorter esort=new EgSorter(temp_info_UNKNOWN_list,1);
			temp_info_UNKNOWN_list=esort.sort(1,"String","asc");
			temp_aList_info.addAll(temp_info_UNKNOWN_list);
		}
		if(temp_info_GOOD_list!=null && temp_info_GOOD_list.size()>0)
		{
			EgSorter esort=new EgSorter(temp_info_GOOD_list,1);
			temp_info_GOOD_list=esort.sort(1,"String","asc");
			temp_aList_info.addAll(temp_info_GOOD_list);
		}
		
		return (new ArrayList(temp_aList_info));
	}

	//for Sort the List by values of the Measure
	public List getSortedList(Hashtable result_hash,String orderBy)
	{
		List result_eg_list=new LinkedList();

		if(result_hash!=null && result_hash.size()>0)
		{
			TreeMap treeMap = new TreeMap();
			ArrayList list_of_pro=new ArrayList();
			Enumeration mes_keys=result_hash.keys();
			while(mes_keys.hasMoreElements())
			{
				String key_as_mes = (String)mes_keys.nextElement();
				if(key_as_mes!=null && key_as_mes.trim().length()>0)
				{
					StringTokenizer key_token=new StringTokenizer(key_as_mes,"^");
					if(key_token.countTokens()>=1)
					{
						String value_mea=(String)result_hash.get(new String(key_as_mes));
						//if(value_mea!=null && value_mea.trim().length()>0 && !value_mea.equalsIgnoreCase("-"))
						if(value_mea!=null && value_mea.trim().length()>0)
						{
							String value_value=value_mea;// like 25.80 or -
							
							if(value_value!=null && value_value.equalsIgnoreCase("-"))
							{
								value_value="0.0";
								list_of_pro.add(key_as_mes);
							}
							else
							{
								try
								{
									Float temp_data = new Float(Float.parseFloat(value_value));
								}
								catch(Exception e)
								{
									if(value_value!=null && value_value.trim().length()>0)
									{
										value_value="0.0";
										list_of_pro.add(key_as_mes);
									}
								}
							}

							Float temp_data = new Float(Float.parseFloat(value_value));
							if(treeMap.size() > 0)
							{
								if(treeMap.containsKey((Float)temp_data))
								{
									String val=(String)treeMap.get(temp_data);
									val=val+"#"+key_as_mes;
									treeMap.put(temp_data,(String)val);
								}
								else
								{
									treeMap.put(temp_data,(String)key_as_mes);
								}
							}
							else
							{
								treeMap.put(temp_data,(String)key_as_mes);
							}
						}
					}
				}
			}
			if(orderBy!=null && orderBy.equals("desc"))
			{
				if(treeMap.size() > 0)
				{
					Set set = treeMap.keySet();
					ArrayList al = new ArrayList(set);
					for(int j=treeMap.size()-1; j >= 0; j--)
					{
						Float key = (Float)al.get(j);
						String values = (String)treeMap.get(key);
						StringTokenizer st = new StringTokenizer(values,"#");
						while(st.hasMoreTokens())
						{
							String val = (String)st.nextToken();
							if(list_of_pro!=null && list_of_pro.size()>0 && list_of_pro.contains(val))
								continue;
							
							result_eg_list.add(val);
						}
					}
					
					if(list_of_pro!=null && list_of_pro.size()>0)
					{
						for(int j=0; j<list_of_pro.size(); j++)
						{
							String val = (String)list_of_pro.get(j);
							result_eg_list.add(val);
						}
					}
				}
				else
				{
					//result_eg_list=copy_egList;
				}
			}
			else
			{
				if(treeMap.size() > 0)
				{
					Iterator ite = treeMap.keySet().iterator();
					while(ite.hasNext())
					{
						Float key = (Float)ite.next();
						String values = (String)treeMap.get(key);
						StringTokenizer st = new StringTokenizer(values,"#");
						while(st.hasMoreTokens())
						{
							String val = (String)st.nextToken();
							if(list_of_pro!=null && list_of_pro.size()>0 && list_of_pro.contains(val))
								continue;
							result_eg_list.add(val);
						}
					}
					
					if(list_of_pro!=null && list_of_pro.size()>0)
					{
						for(int j=0; j<list_of_pro.size(); j++)
						{
							String val = (String)list_of_pro.get(j);
							result_eg_list.add(val);
						}
					}
				}
				else
				{
					//result_eg_list=copy_egList;
				}
			}
		}
		return result_eg_list;
	}

	public Hashtable getComponentHash(Object inputList,ArrayList componentTypeLists)
	{
		Hashtable resultCompHash=new Hashtable();
		try
		{
			if(inputList!=null)
			{
				int comp_count = 0;
				ArrayList aa=null;
				EgComponentList ecl=null;
				EgList el=null;
				
				if(inputList instanceof EgList)
				{
					el = (EgList) inputList;
					if(el!=null)
					{
						comp_count = el.size();
					}
				}
				else if(inputList instanceof EgComponentList)
				{
					ecl = (EgComponentList) inputList;
					if(ecl!=null)
					{
						comp_count = ecl.size();
					}
				}
				else if(inputList instanceof ArrayList)
				{
					aa = (ArrayList)inputList;
					if(aa!=null)
					{
						comp_count = aa.size();
					}
				}
				
				for(int j = 0; j < comp_count; j++)
				{
					EgComponent component = null;
					String component_str = null;

					if(inputList instanceof EgList)
					{
						component = (EgComponent) el.get(j);
					}
					else if(inputList instanceof EgComponentList)
					{
						component = (EgComponent) ecl.get(j);
					}
					else if(inputList instanceof ArrayList)
					{
						component_str = (String)aa.get(j);
					}

					String serverName = "";
					String serverType = "";
					if(component!=null)
					{
						serverName = component.getName();
						serverType = component.getType();
					}
					else if(component_str!=null && component_str.trim().length()>0)
					{
						serverName = component_str.substring(component_str.indexOf(":")+1);
						serverType = component_str.substring(0,component_str.indexOf(":"));
					}

					if(serverType!=null && componentTypeLists!=null && componentTypeLists.contains(serverType))
					{
						int portIndex = 0;
						String temp_servername="";
						String temp_serverport="";
						if(resultCompHash.size()==0)
						{
							ArrayList tempList=new ArrayList();
							tempList.add(serverType+":"+serverName);

							ArrayList tempOrgList=new ArrayList();
							tempOrgList.add(serverType+":"+serverName);

							if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
							{
								portIndex = serverName.indexOf(":");
							}
							else
							{
								portIndex = serverName.lastIndexOf(":");
							}

							if(serverName != null && portIndex > 0)
							{
								temp_servername = serverName.substring(0,portIndex);
								String tt_sn=temp_servername;
								temp_servername = temp_servername+":NULL";
								if(!tempList.contains(serverType+":"+temp_servername))
									tempList.add(serverType+":"+temp_servername);

								if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
								{
									temp_serverport = serverName.substring(portIndex+1);
									if(temp_serverport!=null && temp_serverport.indexOf(":")>-1)
									{
										tt_sn=tt_sn+":"+temp_serverport.substring(0,temp_serverport.indexOf(":"));
										if(!tempList.contains(serverType+":"+tt_sn))
											tempList.add(serverType+":"+tt_sn);
									}
								}
							}

							resultCompHash.put(serverType,(ArrayList)tempList);
							resultCompHash.put(serverType+"_real",(ArrayList)tempOrgList);
						}
						else
						{
							if(resultCompHash!=null && resultCompHash.containsKey(serverType))
							{
								ArrayList tempList=(ArrayList)resultCompHash.get(serverType);
								tempList.add(serverType+":"+serverName);

								ArrayList tempOrgList=(ArrayList)resultCompHash.get(serverType+"_real");
								tempOrgList.add(serverType+":"+serverName);

								if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
								{
									portIndex = serverName.indexOf(":");
								}
								else
								{
									portIndex = serverName.lastIndexOf(":");
								}

								if(serverName != null && portIndex > 0)
								{
									temp_servername = serverName.substring(0,portIndex);
									String tt_sn=temp_servername;
									temp_servername = temp_servername+":NULL";
									if(!tempList.contains(serverType+":"+temp_servername))
										tempList.add(serverType+":"+temp_servername);

									if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
									{
										temp_serverport = serverName.substring(portIndex+1);
										if(temp_serverport!=null && temp_serverport.indexOf(":")>-1)
										{
											tt_sn=tt_sn+":"+temp_serverport.substring(0,temp_serverport.indexOf(":"));
											if(!tempList.contains(serverType+":"+tt_sn))
												tempList.add(serverType+":"+tt_sn);
										}
									}
								}

								resultCompHash.put(serverType,(ArrayList)tempList);
								resultCompHash.put(serverType+"_real",(ArrayList)tempOrgList);
							}
							else
							{
								ArrayList tempList=new ArrayList();
								tempList.add(serverType+":"+serverName);

								ArrayList tempOrgList=new ArrayList();
								tempOrgList.add(serverType+":"+serverName);

								if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
								{
									portIndex = serverName.indexOf(":");
								}
								else
								{
									portIndex = serverName.lastIndexOf(":");
								}

								if(serverName != null && portIndex > 0)
								{
									temp_servername = serverName.substring(0,portIndex);
									String tt_sn=temp_servername;
									temp_servername = temp_servername+":NULL";
									if(!tempList.contains(serverType+":"+temp_servername))
										tempList.add(serverType+":"+temp_servername);

									if(serverType!=null && (serverType.equals("Oracle_server") || serverType.equals("Agg_Oracle_server")))
									{
										temp_serverport = serverName.substring(portIndex+1);
										if(temp_serverport!=null && temp_serverport.indexOf(":")>-1)
										{
											tt_sn=tt_sn+":"+temp_serverport.substring(0,temp_serverport.indexOf(":"));
											if(!tempList.contains(serverType+":"+tt_sn))
												tempList.add(serverType+":"+tt_sn);
										}
									}
								}

								resultCompHash.put(serverType,(ArrayList)tempList);
								resultCompHash.put(serverType+"_real",(ArrayList)tempOrgList);
							}
						}
					}
				}
			}
		}
		catch(Throwable th)
		{
			th.printStackTrace();
		}
		return resultCompHash;
	}

	public ArrayList splitSpecificSubject(int showMax,ArrayList finalCompTypeList,String spe_sub_values,EgSpecsInfo specsInfo,ArrayList ctypeList,ArrayList testList,ArrayList testMeaList,ArrayList testWithMeaList)
	{
		ArrayList result_al=new ArrayList();
		ArrayList tempctypeList=new ArrayList();
		ArrayList tempTestList=new ArrayList();
		ArrayList tempTestMeaList=new ArrayList();
		ArrayList tempTestWithMeaList=new ArrayList();

		if(ctypeList!=null && ctypeList.size()>0)
		{
			tempctypeList.addAll(ctypeList);
		}

		if(testList!=null && testList.size()>0)
		{
			tempTestList.addAll(testList);
		}

		if(testMeaList!=null && testMeaList.size()>0)
		{
			tempTestMeaList.addAll(testMeaList);
		}

		if(testWithMeaList!=null && testWithMeaList.size()>0)
		{
			tempTestWithMeaList.addAll(testWithMeaList);
		}

		if(spe_sub_values!=null && spe_sub_values.trim().length()>0)
		{
			ArrayList speList = StringUtils.egTokenizer(spe_sub_values, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
			for(int z=0;z<speList.size();z++)
			{
				String tmp_str=(String)speList.get(z);
				if(tmp_str!=null && tmp_str.trim().length()>0)
				{
					String tokens_measures[] = StringUtils.getTokens(tmp_str,":");
					if(tokens_measures!=null && tokens_measures.length>0)
					{
						String ct="";
						String cn="";
						String test_name="";
						String measure_name="";
						String disp_measure_name="";
						String measure_unit="";
						if(tokens_measures.length==6)
						{
							ct=tokens_measures[0];
							if(ct!=null && ct.startsWith("CT^"))
								ct=ct.substring(ct.indexOf("^")+1);

							cn=tokens_measures[1];
							if(cn!=null && cn.startsWith("CN^"))
								cn=cn.substring(cn.indexOf("^")+1);

							test_name=tokens_measures[2];
							measure_name=tokens_measures[3];
							disp_measure_name=tokens_measures[4];
							measure_unit=tokens_measures[5];
						}
						else if(tokens_measures.length==5)
						{
							String tem_val=tokens_measures[0];
							if(tem_val!=null && tem_val.startsWith("CT^"))
							{
								ct=tem_val.substring(tem_val.indexOf("^")+1);
							}
							else if(tem_val!=null && tem_val.startsWith("CN^"))
							{
								cn=tem_val.substring(tem_val.indexOf("^")+1);
							}

							test_name=tokens_measures[1];
							measure_name=tokens_measures[2];
							disp_measure_name=tokens_measures[3];
							measure_unit=tokens_measures[4];
						}
						else if(tokens_measures.length==4)
						{
							test_name=tokens_measures[0];
							measure_name=tokens_measures[1];
							disp_measure_name=tokens_measures[2];
							measure_unit=tokens_measures[3];
						}

						if(ct!=null && ct.trim().length()>0 && finalCompTypeList!=null && finalCompTypeList.contains(ct))
						{
							boolean isTestRelevantForServer = false;
							isTestRelevantForServer = specsInfo.isTestRelevantForServer(ct,test_name);
							if(isTestRelevantForServer)
							{
								//if(!tempTestMeaList.contains(tmp_str) && showMax>=tempTestWithMeaList.size())
								if(!tempTestMeaList.contains(tmp_str))
								{
									if(!tempctypeList.contains(ct))
										tempctypeList.add(ct);
									if(!tempTestList.contains(test_name))
										tempTestList.add(test_name);
									if(!tempTestWithMeaList.contains(test_name+":"+measure_name+":"+disp_measure_name))
										tempTestWithMeaList.add(test_name+":"+measure_name+":"+disp_measure_name);

									tempTestMeaList.add(tmp_str);
								}
							}
						}
						else if((ct==null || ct.trim().length()==0) && (finalCompTypeList!=null  && finalCompTypeList.size()>0))
						{
							for(int x=0;x<finalCompTypeList.size();x++)
							{
								//if(tempTestWithMeaList.size() >= showMax)
								//	break;
								String temp_ctype=(String)finalCompTypeList.get(x);
								boolean isTestRelevantForServer = false;
								isTestRelevantForServer = specsInfo.isTestRelevantForServer(temp_ctype,test_name);
								if(isTestRelevantForServer)
								{
									//if(!tempTestMeaList.contains(temp_ctype+":"+tmp_str) && showMax>=tempTestWithMeaList.size())
									if(!tempTestMeaList.contains(temp_ctype+":"+tmp_str))
									{
										if(!tempctypeList.contains(temp_ctype))
											tempctypeList.add(temp_ctype);
										if(!tempTestList.contains(test_name))
											tempTestList.add(test_name);
										if(!tempTestWithMeaList.contains(test_name+":"+measure_name+":"+disp_measure_name))
											tempTestWithMeaList.add(test_name+":"+measure_name+":"+disp_measure_name);
										tempTestMeaList.add(temp_ctype+":"+tmp_str);
									}
								}
							}
						}
					}
				}
			}
		}

		if(tempctypeList!=null && tempTestList!=null && tempTestMeaList!=null && tempTestWithMeaList!=null)
		{
			result_al.add((ArrayList)tempctypeList);
			result_al.add((ArrayList)tempTestList);
			result_al.add((ArrayList)tempTestMeaList);
			result_al.add((ArrayList)tempTestWithMeaList);
		}

		return result_al;
	}

	public ArrayList splitCommonSubject(boolean isAggSiteService,int showMax,ArrayList finalCompTypeList,String subject,IniFile serviceDashIni,EgSpecsInfo specsInfo,ArrayList ctypeList,ArrayList testList,ArrayList testMeaList,ArrayList testWithMeaList,String spc_domain_value)
	{
		ArrayList result_al=new ArrayList();
		ArrayList tempctypeList=new ArrayList();
		ArrayList tempTestList=new ArrayList();
		ArrayList tempTestMeaList=new ArrayList();
		ArrayList tempTestWithMeaList=new ArrayList();

		if(ctypeList!=null && ctypeList.size()>0)
		{
			tempctypeList.addAll(ctypeList);
		}

		if(testList!=null && testList.size()>0)
		{
			tempTestList.addAll(testList);
		}

		if(testMeaList!=null && testMeaList.size()>0)
		{
			tempTestMeaList.addAll(testMeaList);
		}

		if(testWithMeaList!=null && testWithMeaList.size()>0)
		{
			tempTestWithMeaList.addAll(testWithMeaList);
		}

		String servic_type_sub="Service_Types";
		String test_measure_sub=subject;
		if(isAggSiteService)
		{
			servic_type_sub="Aggregate:Service_Types";
			test_measure_sub="Aggregate:"+subject;
		}

		String [] st_variables=serviceDashIni.getVariables(servic_type_sub);
		if(st_variables!=null && st_variables.length>0)
		{
			ArrayList tmp_varList = new ArrayList();
			if(spc_domain_value!=null && spc_domain_value.trim().length()>0)
			{
				tmp_varList.add(spc_domain_value);
			}
			else
			{
				tmp_varList = new ArrayList(Arrays.asList(st_variables));
			}

			if(tmp_varList!=null && tmp_varList.size()>0)
			{
				for(int c=0;c<tmp_varList.size();c++)
				{
					//if(tempTestWithMeaList.size() >= showMax)
					//	break;
					String tmp_common_var=(String)tmp_varList.get(c);
					if(tmp_common_var!=null && tmp_common_var.trim().length()>0)
					{
						String tmp_common_cts=(String)serviceDashIni.getValue(servic_type_sub,tmp_common_var);
						if(tmp_common_cts!=null && tmp_common_cts.trim().length()>0)
						{
							ArrayList commonCtsList = StringUtils.egTokenizer(tmp_common_cts, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
							if(commonCtsList!=null && commonCtsList.size()>0)
							{
								for(int x=0;x<commonCtsList.size();x++)
								{
									//if(tempTestWithMeaList.size() >= showMax)
									//	break;
									String tmp_ct_str=(String)commonCtsList.get(x);
									if(tmp_ct_str!=null && tmp_ct_str.trim().length()>0 && finalCompTypeList!=null && finalCompTypeList.contains(tmp_ct_str))
									{
										String tmp_test_mea_values=(String)serviceDashIni.getValue(test_measure_sub,tmp_common_var);
										String tmp_test_mea_func=(String)serviceDashIni.getValue(test_measure_sub,tmp_common_var+":Metric");

										if(tmp_test_mea_values!=null && tmp_test_mea_values.trim().length()>0)
										{
											ArrayList test_meaList = StringUtils.egTokenizer(tmp_test_mea_values, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
											for(int z=0;z<test_meaList.size();z++)
											{
												//if(tempTestWithMeaList.size() >= showMax)
												//	break;
												String tmp_test_mea_str=(String)test_meaList.get(z);
												if(tmp_test_mea_str!=null && tmp_test_mea_str.trim().length()>0)
												{
													String tokens_measures[] = StringUtils.getTokens(tmp_test_mea_str,":");
													if(tokens_measures!=null && tokens_measures.length>0)
													{
														String comp_type_new="";
														String test_name="";
														String measure_name="";
														String disp_measure_name="";
														String measure_unit="";
														if(tokens_measures.length>0)
														{
															if(tokens_measures.length>4)
															{
																comp_type_new=tokens_measures[0];
																test_name=tokens_measures[1];
																measure_name=tokens_measures[2];
																disp_measure_name=tokens_measures[3];
																measure_unit=tokens_measures[4];
															}
															else
															{
																test_name=tokens_measures[0];
																measure_name=tokens_measures[1];
																disp_measure_name=tokens_measures[2];
																measure_unit=tokens_measures[3];
															}

															boolean isTestRelevantForServer = false;
															isTestRelevantForServer = specsInfo.isTestRelevantForServer(tmp_ct_str,test_name);
															if(isTestRelevantForServer)
															{
																if(tmp_test_mea_func!=null && tmp_test_mea_func.trim().length()>0)
																{
																	//if(!tempTestMeaList.contains(tmp_ct_str+":"+tmp_test_mea_str+"~"+tmp_test_mea_func) && showMax>=tempTestWithMeaList.size())
																	if(!tempTestMeaList.contains(tmp_ct_str+":"+tmp_test_mea_str+"~"+tmp_test_mea_func))
																	{
																		if(!tempctypeList.contains(tmp_ct_str))
																			tempctypeList.add(tmp_ct_str);
																		if(!tempTestList.contains(test_name))
																			tempTestList.add(test_name);
																		
																		tempTestMeaList.add(tmp_ct_str+":"+tmp_test_mea_str+"~"+tmp_test_mea_func);

																		if(!tempTestWithMeaList.contains(test_name+":"+measure_name+":"+disp_measure_name))
																			tempTestWithMeaList.add(test_name+":"+measure_name+":"+disp_measure_name);
																	}
																}
																else
																{
																	//if(!tempTestMeaList.contains(tmp_ct_str+":"+tmp_test_mea_str) && showMax>=tempTestWithMeaList.size())
																	if(!tempTestMeaList.contains(tmp_ct_str+":"+tmp_test_mea_str))
																	{
																		if(!tempctypeList.contains(tmp_ct_str))
																			tempctypeList.add(tmp_ct_str);
																		if(!tempTestList.contains(test_name))
																			tempTestList.add(test_name);
																		
																		tempTestMeaList.add(tmp_ct_str+":"+tmp_test_mea_str);

																		if(!tempTestWithMeaList.contains(test_name+":"+measure_name+":"+disp_measure_name))
																			tempTestWithMeaList.add(test_name+":"+measure_name+":"+disp_measure_name);
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		if(tempctypeList!=null && tempTestList!=null && tempTestMeaList!=null && tempTestWithMeaList!=null)
		{
			if((!subject.equalsIgnoreCase("Consumption")) || (subject.equalsIgnoreCase("Consumption") && tempctypeList.size()>0 && tempTestWithMeaList.size()>0))
			{
				result_al.add((ArrayList)tempctypeList);
				result_al.add((ArrayList)tempTestList);
				result_al.add((ArrayList)tempTestMeaList);
				result_al.add((ArrayList)tempTestWithMeaList);
			}
			else if(subject!=null && subject.equalsIgnoreCase("Consumption"))
			{
				result_al=(ArrayList)getDefaultSubjectValue(showMax,finalCompTypeList,test_measure_sub,serviceDashIni,specsInfo,ctypeList,testList,testMeaList,testWithMeaList);
			}
		}

		return result_al;
	}

	public ArrayList getDefaultSubjectValue(int showMax,ArrayList finalCompTypeList,String subject,IniFile serviceDashIni,EgSpecsInfo specsInfo,ArrayList ctypeList,ArrayList testList,ArrayList testMeaList,ArrayList testWithMeaList)
	{
		ArrayList result_al=new ArrayList();
		ArrayList tempctypeList=new ArrayList();
		ArrayList tempTestList=new ArrayList();
		ArrayList tempTestMeaList=new ArrayList();
		ArrayList tempTestWithMeaList=new ArrayList();

		if(ctypeList!=null && ctypeList.size()>0)
		{
			tempctypeList.addAll(ctypeList);
		}

		if(testList!=null && testList.size()>0)
		{
			tempTestList.addAll(testList);
		}

		if(testMeaList!=null && testMeaList.size()>0)
		{
			tempTestMeaList.addAll(testMeaList);
		}

		if(testWithMeaList!=null && testWithMeaList.size()>0)
		{
			tempTestWithMeaList.addAll(testWithMeaList);
		}

		String tmp_test_mea_values=(String)serviceDashIni.getValue(subject,"Default");
		if(tmp_test_mea_values!=null && tmp_test_mea_values.trim().length()>0)
		{
			ArrayList test_meaList = StringUtils.egTokenizer(tmp_test_mea_values, ",",false,true,true);//params 3-->includeEmpty,4-->unique,5-->trim
			for(int z=0;z<test_meaList.size();z++)
			{
				String tmp_test_mea_str=(String)test_meaList.get(z);
				if(tmp_test_mea_str!=null && tmp_test_mea_str.trim().length()>0)
				{
					String tokens_measures[] = StringUtils.getTokens(tmp_test_mea_str,":");
					if(tokens_measures!=null && tokens_measures.length>0)
					{
						String ct_new="";
						String test_name="";
						String measure_name="";
						String disp_measure_name="";
						String measure_unit="";
						if(tokens_measures.length>0)
						{
							if(tokens_measures.length>4)
							{
								ct_new=tokens_measures[0];
								test_name=tokens_measures[1];
								measure_name=tokens_measures[2];
								disp_measure_name=tokens_measures[3];
								measure_unit=tokens_measures[4];
							}
							else
							{
								test_name=tokens_measures[0];
								measure_name=tokens_measures[1];
								disp_measure_name=tokens_measures[2];
								measure_unit=tokens_measures[3];
							}

							for(int x=0;x<finalCompTypeList.size();x++)
							{
								//if(tempTestWithMeaList.size() >= showMax)
								//	break;
								String temp_ctype=(String)finalCompTypeList.get(x);

								boolean isTestRelevantForServer = false;
								isTestRelevantForServer = specsInfo.isTestRelevantForServer(temp_ctype,test_name);

								if(isTestRelevantForServer)
								{
									//if(!tempTestMeaList.contains(temp_ctype+":"+tmp_test_mea_str) && showMax>=tempTestWithMeaList.size())
									if(!tempTestMeaList.contains(temp_ctype+":"+tmp_test_mea_str))
									{
										if(!tempctypeList.contains(temp_ctype))
											tempctypeList.add(temp_ctype);
										if(!tempTestList.contains(test_name))
											tempTestList.add(test_name);

										tempTestMeaList.add(temp_ctype+":"+tmp_test_mea_str);

										if(!tempTestWithMeaList.contains(test_name+":"+measure_name))
											tempTestWithMeaList.add(test_name+":"+measure_name);
									}
								}
							}
						}
					}
				}
			}
		}

		if(tempctypeList!=null && tempTestList!=null && tempTestMeaList!=null && tempTestWithMeaList!=null)
		{
			result_al.add((ArrayList)tempctypeList);
			result_al.add((ArrayList)tempTestList);
			result_al.add((ArrayList)tempTestMeaList);
			result_al.add((ArrayList)tempTestWithMeaList);
		}

		return result_al;
	}

	public ArrayList splitData(String [] tmp_variables,int showMax,ArrayList finalCompTypeList,String subject,IniFile serviceDashIni,EgSpecsInfo specsInfo,ArrayList ctypeList,ArrayList testList,ArrayList testMeaList,ArrayList testWithMeaList)
	{
		ArrayList result_al=new ArrayList();
		ArrayList tempctypeList=new ArrayList();
		ArrayList tempTestList=new ArrayList();
		ArrayList tempTestMeaList=new ArrayList();
		ArrayList tempTestWithMeaList=new ArrayList();

		if(ctypeList!=null && ctypeList.size()>0)
		{
			tempctypeList.addAll(ctypeList);
		}

		if(testList!=null && testList.size()>0)
		{
			tempTestList.addAll(testList);
		}

		if(testMeaList!=null && testMeaList.size()>0)
		{
			tempTestMeaList.addAll(testMeaList);
		}

		if(testWithMeaList!=null && testWithMeaList.size()>0)
		{
			tempTestWithMeaList.addAll(testWithMeaList);
		}

		if(tmp_variables!=null && tmp_variables.length>0)
		{
			ArrayList tmp_varList = new ArrayList(Arrays.asList(tmp_variables));
			if(tmp_varList!=null && tmp_varList.size()>0)
			{
				for(int c=0;c<tmp_varList.size();c++)
				{
					//if(tempTestWithMeaList.size() >= showMax)
					//	break;
					String tmp_str=(String)tmp_varList.get(c);
					if(tmp_str!=null && tmp_str.trim().length()>0)
					{
						String tokens_measures[] = StringUtils.getTokens(tmp_str,":");
						if(tokens_measures!=null && tokens_measures.length>0)
						{
							String ct="";
							String test_name="";
							String measure_name="";
							if(tokens_measures.length>2)
							{
								ct=tokens_measures[0];
								test_name=tokens_measures[1];
								measure_name=tokens_measures[2];
							}
							else if(tokens_measures.length>1)
							{
								test_name=tokens_measures[0];
								measure_name=tokens_measures[1];
							}

							if(ct!=null && ct.trim().length()>0 && finalCompTypeList!=null && finalCompTypeList.contains(ct))
							{
								boolean isTestRelevantForServer = false;
								isTestRelevantForServer = specsInfo.isTestRelevantForServer(ct,test_name);
								if(isTestRelevantForServer)
								{
									String tmp_test_measure=(String)serviceDashIni.getValue(subject,tmp_str);
									//if(!tempTestMeaList.contains(tmp_str+":"+tmp_test_measure) && showMax>=tempTestWithMeaList.size())
									if(!tempTestMeaList.contains(tmp_str+":"+tmp_test_measure))
									{
										if(!tempctypeList.contains(ct))
											tempctypeList.add(ct);
										if(!tempTestList.contains(test_name))
											tempTestList.add(test_name);
										if(!tempTestWithMeaList.contains(test_name+":"+measure_name))
											tempTestWithMeaList.add(test_name+":"+measure_name);
										tempTestMeaList.add(tmp_str+":"+tmp_test_measure);
									}
								}
							}
							else if(ct==null || ct.trim().length()==0 && (finalCompTypeList!=null  && finalCompTypeList.size()>0))
							{
								for(int x=0;x<finalCompTypeList.size();x++)
								{
									//if(tempTestWithMeaList.size() > showMax)
									//	break;
									String temp_ctype=(String)finalCompTypeList.get(x);
									boolean isTestRelevantForServer = false;
									isTestRelevantForServer = specsInfo.isTestRelevantForServer(temp_ctype,test_name);
									if(isTestRelevantForServer)
									{
										String tmp_test_measure=(String)serviceDashIni.getValue(subject,tmp_str);
										//if(!tempTestMeaList.contains(temp_ctype+":"+test_name+":"+measure_name+":"+tmp_test_measure) && showMax>=tempTestWithMeaList.size())
										if(!tempTestMeaList.contains(temp_ctype+":"+test_name+":"+measure_name+":"+tmp_test_measure))
										{
											if(!tempctypeList.contains(temp_ctype))
												tempctypeList.add(temp_ctype);
											if(!tempTestList.contains(test_name))
												tempTestList.add(test_name);
											if(!tempTestWithMeaList.contains(test_name+":"+measure_name))
												tempTestWithMeaList.add(test_name+":"+measure_name);
											tempTestMeaList.add(temp_ctype+":"+test_name+":"+measure_name+":"+tmp_test_measure);
										}
									}
								}
							}
						}
					}
				}
			}
		}

		if(tempctypeList!=null && tempTestList!=null && tempTestMeaList!=null && tempTestWithMeaList!=null)
		{
			result_al.add((ArrayList)tempctypeList);
			result_al.add((ArrayList)tempTestList);
			result_al.add((ArrayList)tempTestMeaList);
			result_al.add((ArrayList)tempTestWithMeaList);
		}
		return result_al;
	}
%>
