<%
/*****************************************************************************************************
 *	Name			:	EgVmwareLiveGraphDisplay.jsp
 *	Version			:	eG 4.0
 *	Purpose			:	To View the comaprison graph for Vmware_esx_server and Vmware_vdi_server
 *	Creation Date	:	10-5-2007.
 *  Modifyed		:	Support for RHEV component type By Saravanan.A
 *****************************************************************************************************/
%>
<%@ include file="EgTracker.jsp" %>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import="com.egurkha.util.EgSorter"%>
<%@ page import="com.egurkha.monitor.EgVmwareGraph"%>
<%@ page import="com.egurkha.*"%>
<%@ page import="egurkha.reporter.*"%>
<%@ page import="java.util.StringTokenizer"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import ="com.egurkha.ini.IniUI"%>
<%@ page import ="com.eg.EgExternalInfo"%>
<%@ page import ="com.eg.EgURLEncoder"%>
<%@ page import ="com.eg.EgDiscInfo"%>
<%@ page import ="com.eg.EgSpecsInfo"%>
<%@ page import="com.egurkha.monitor.*"%>
<%@ page import="com.eg.EgExternalInfo"%>
<%@ page import="java.io.*"%>
<%@ page import="java.awt.Color"%>
<%@ page import = "com.egurkha.monitor.alarms.AlarmPriorities" %>
<%@ taglib prefix="egui" uri="../../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="trans_services_ini" scope="page" class="egurkha.TransactionBean" />
<%@ 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
{
	ArrayList result_info_List=new ArrayList();

	String s_iniFile_dir3=EgInstallInfo.getInstallDir()+"/manager/config/";
	IniFile uiIniObj=new IniFile(s_iniFile_dir3+"eg_ui.ini");

	IniFile externalIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_external.ini");
	String supportedUserTypeEntry[]=externalIni.getVariables("Virtual_Servers");
	List supportedUserTypeList = null;
	if(supportedUserTypeEntry!=null && supportedUserTypeEntry.length>0)
		supportedUserTypeList = Arrays.asList(supportedUserTypeEntry);

	String mode= request.getParameter("mode");
	mode=(mode==null || mode.trim().length()==0)?"3D":mode;
	String s_view= request.getParameter("er_view");
	s_view=(s_view==null || s_view.trim().length()==0)?"Live Data":s_view;
	//s_view=(s_view==null || s_view.trim().length()==0)?"TopN/LastN":s_view;
	boolean showLegendChk = true;
	String selLiveData="";
	String selTopNOrLast="";
	if(s_view!=null && s_view.equals("Live Data"))
	{
		selLiveData = "checked";
	}
	else if(s_view!=null && s_view.equals("TopN/LastN"))
	{
		selTopNOrLast = "checked";
	}
	
	String twoDModeSelected="";
	String threeDModeSelected="";
	String useRoundEdges="1";
	String zoomoutChart ="/final/FusionCharts/swf/Bar2D.swf";
	
	if(mode!=null && mode.equalsIgnoreCase("2D"))
	{
		zoomoutChart ="/final/FusionCharts/swf/Bar2D.swf";
		twoDModeSelected="selected";
		useRoundEdges="1";// if want 2D view we need to give 0.
	}
	else
	{
		zoomoutChart ="/final/FusionCharts/swf/Bar2D.swf";
		threeDModeSelected="selected";
		useRoundEdges="1";
	}
	IniUI iniui = IniUI.getInstance();
	EgTablesInfo tablesInfo=new EgTablesInfo("manager");
	EgExternalInfo egExternalInfo=new EgExternalInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	MonitorDAOFactory monitorDaoFactory = MonitorDAOFactory.getInstance();	
	EgDashBoardDAO dashboardDAO=monitorDaoFactory.getDashBoardDAO();
	MeasuresDAO MeasuresDao = monitorDaoFactory.getMeasuresDAO();
	EgDashBoardModel dashboardModel=new EgDashBoardModel();
	EgDashboardMGraphModel measureGraph=new EgDashboardMGraphModel();
	IniUI iniUi=IniUI.getInstance();
	EgExternalInfo externalInfo=new EgExternalInfo("manager");
	EgDiscInfo discInfo=new EgDiscInfo("manager");
	EgSpecsInfo specs=new EgSpecsInfo("manager");
	AlarmPriorities ap = AlarmPriorities.getInstance();
	int noCol=3;
	int scroll=4;
	Vector v_comp=new Vector();
	String sessionID = session.getId();
	String info=null;
	String port="NULL";
	Vector tests=null;
	long ref_rate=0;
	String ua = request.getHeader( "User-Agent" );
	boolean  isChrome = ( ua != null && ua.indexOf( "Chrome/" ) != -1 );
	boolean isFirefox = ( ua != null && ua.indexOf( "Firefox/" ) != -1 );

	User this_user = UserRegistry.getInstance().getUser(sessionID);	
	ErUserData UBean = this_user.getReporterData();
	
	UserRegistry registry = UserRegistry.getInstance();
	User user = registry.getUser(session.getId());
	IniUI ui = IniUI.getInstance();

	String thisLanguage =ui.getDefaultLanguage();
	if (user!=null)
	{
		String userLang = user.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}

	EgMappingInfo mappingInfo=new EgMappingInfo(thisLanguage);

	List typeList=iniUi.getAllComponetType();
	Collections.sort(typeList,String.CASE_INSENSITIVE_ORDER);
	List userServerTypes=new LinkedList();
	if(this_user!=null)
	{
		userServerTypes.addAll(this_user.getServerTypes());
	}
	List compTypes=new ArrayList();

	String s_comptype=null;

	if(request.getParameter("comptype")!=null)
	{
		s_comptype=request.getParameter("comptype");
		if(s_comptype.equals("null") || s_comptype.equals(""))
			s_comptype=null;
	}
	EgDbInfo dbInfo=new EgDbInfo("manager");
	IniFile egUI = null;
	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	egUI = new IniFile(s_iniFile_dir + uiFile);
	String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	if(s_comptype!=null && !s_comptype.equals("-1"))
		compTypes.add(s_comptype);
	String s_comp=request.getParameter("er_component");
	s_comp=(s_comp==null || s_comp.trim().length()==0)?"-1":s_comp;

	if(s_comp!=null && !s_comp.equals("-1") && s_comp.indexOf(":") < 0)
	{
		s_comp=s_comp+":NULL";
	}

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

	String refreshTime = u_ser.getRefreshFrequency();

	String refreshurl="/final/monitor/livegraph/EgVmwareLiveGraphDisplay.jsp?comptype="+EgURLEncoder.encode(s_comptype,"UTF-8")+"&er_component="+EgURLEncoder.encode(s_comp,"UTF-8")+"&mode="+mode+"&er_view="+s_view;
	
	if(compTypes!=null && compTypes.size()>0)
	{
		json.put("view",s_view);
		ArrayList component= new ArrayList();
		if(supportedUserTypeList.contains(s_comptype))
			component=discInfo.getAllHostsOfTypes(compTypes);
		Vector vmmanagedcomp=discInfo.getAllManagedComponents();
		Vector usercomp=UBean.getAllUserComponents(3);
		// To find the port based component type, by Saravanan.A on 10-1-2012
		IniFile servicesIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_services.ini");
		boolean isPortRelevantType=false;
		String portRelavantType=servicesIni.getValue("NOPORT_SERVERS",s_comptype);
		if(portRelavantType==null || portRelavantType.trim().length()==0)
			isPortRelevantType=true;
		//---end---
		
		for(int i=0;i<component.size();i++)
		{
			String compName=(String)component.get(i);
			// To get the port based on component type, by Saravanan.A on 10-1-2012
			if(isPortRelevantType && port!=null && s_comptype!=null && port.equals("NULL"))
			{
				port=(String)discInfo.getPortForHost(compName,s_comptype);
			}
			//---end---
			String tmpComp=compName+":"+port;
			/*if(usercomp.contains(tmpComp+":VmEsx_i_server") || usercomp.contains(tmpComp+":Vmware_vdi_server")||
			usercomp.contains(tmpComp+":VmVdi_i_server")||
			usercomp.contains(tmpComp+":Solaris_virtual_server")||
			usercomp.contains(tmpComp+":Xen_virtual_server")||
			usercomp.contains(tmpComp+":Xen_desktop_server")||
			usercomp.contains(tmpComp+":Virtual_server")||
			usercomp.contains(tmpComp+":Ldoms_server")||
			usercomp.contains(tmpComp+":HyperV_VDI_server")||
			usercomp.contains(tmpComp+":Hyperv_server")||
			usercomp.contains(tmpComp+":Vmware_esx_server") || usercomp.contains(tmpComp+":Xen_pool_server") || usercomp.contains(tmpComp+":Xen_pool_vdi_server") || usercomp.contains(tmpComp+":pSeries_server") || usercomp.contains(tmpComp+":Redhat_linux_hpv") || usercomp.contains(tmpComp+":Redhat_linux_vdi") || usercomp.contains(tmpComp+":VMWare_VDI_Box") || usercomp.contains(tmpComp+":Xen_VDI_Box") || usercomp.contains(tmpComp+":HyperV_VDI_Box") || usercomp.contains(tmpComp+":KVM_vdi_server") || usercomp.contains(tmpComp+":KVM_server") || usercomp.contains(tmpComp+":Nutanix_Acropolis"))*/
			if(usercomp.contains(tmpComp+":"+s_comptype))
			{
				if (port==null || port.equals("") || port.equals("NULL"))
					v_comp.add(compName);//+":"+port);
				else
					v_comp.add(compName+":"+port);
			}
		}
		ref_rate = iniUi.getRefreshRate();
		noCol=iniUi.getCols();
		scroll=iniUi.getScrollbeyond();

		if(scroll<=0)
			scroll=4;

		if(noCol<=0)
			noCol=3;
	
		if(s_comp!=null && !s_comp.equals("-1") && !s_comp.equals("null"))
			tests=iniUi.getTests(s_comptype);

		JSONObject jsonData = new JSONObject();
		jsonData.put("ComponentType",mappingInfo.getTextDescription("monitor.livegraph.Component Type"));
		jsonData.put("selectedCompType",s_comptype);

		JSONArray ctArrList = new JSONArray();
		if(typeList!=null && typeList.size()>0)
		{
			for(int c=0;c<typeList.size();c++)
			{
				JSONObject jsonCTData = new JSONObject();
				String comptype=(String)typeList.get(c);
				if(userServerTypes!=null && userServerTypes.contains(comptype))
				{
					if(comptype != null && !comptype.equals(""))//modified on 19/12/07 to remove empty in list box
					{
						if(comptype.equals(s_comptype))
						{
							jsonCTData.put("displayField",mappingInfo.getComponentTypeDescription(comptype));
							jsonCTData.put("valueField",comptype);
						}
						else
						{
							jsonCTData.put("displayField",mappingInfo.getComponentTypeDescription(comptype));
							jsonCTData.put("valueField",comptype);
						}
						ctArrList.add(jsonCTData);
					}
				}
			}
		}
		else
		{
			JSONObject jsonCTData = new JSONObject();
			jsonCTData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.Not Applicable"));
			jsonCTData.put("valueField","-1");
			ctArrList.add(jsonCTData);
		}
		jsonData.put("ComponentTypeData",ctArrList);

		jsonData.put("ComponentName",mappingInfo.getTextDescription("monitor.livegraph.Component Name"));

		String strTempComp = "";
		if(s_comp!=null && !s_comp.equals("-1"))
		{
			strTempComp = s_comp+":"+port;
			if (port==null || port.equals("") || port.equals("NULL"))
				strTempComp = s_comp;
		}
		else if(s_comp==null || s_comp.equals("-1"))
		{
			strTempComp="-1";
		}

		jsonData.put("selectedCompName",strTempComp);
		
		if(strTempComp!=null && strTempComp.length()>0 && !strTempComp.equals("-1"))
		{
			String state_of_comp="";
			if(strTempComp!=null && strTempComp.length()>0 && strTempComp.indexOf(":")>-1)
				state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+strTempComp), s_comptype,"NULL");
			else
				state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+strTempComp+":NULL"), s_comptype,"NULL");
			
			jsonData.put("selectedCompState",state_of_comp);
		}

		JSONArray cmArrList = new JSONArray();
		if (v_comp==null || v_comp.size()==0)
		{
			JSONObject jsonCNData = new JSONObject();
			jsonCNData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.Not Applicable"));
			jsonCNData.put("valueField","-1");
			cmArrList.add(jsonCNData);
		}
		else
		{
			JSONObject jsonCNData = new JSONObject();
			jsonCNData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.Please select a component"));
			jsonCNData.put("valueField","-1");
			cmArrList.add(jsonCNData);
			
			result_info_List= (ArrayList)getStateSortedList(v_comp,s_comptype,ap);
			for(int c=0;c<result_info_List.size();c++)
			{
				JSONObject jsonCNRData = new JSONObject();
				String comp=(String)result_info_List.get(c);
				String state_of_comp="GOOD";
				if(comp!=null && comp.length()>0 && comp.indexOf(":")>-1)
				{
					state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+comp), s_comptype,"NULL");
				}
				else
				{
					state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+comp+":NULL"), s_comptype,"NULL");
				}
				
				if(comp.equals(strTempComp))
				{
					jsonCNRData.put("displayField",comp);
					jsonCNRData.put("valueField",comp);
					jsonCNRData.put("state", state_of_comp);
				}
				else
				{
					jsonCNRData.put("displayField",comp);
					jsonCNRData.put("valueField",comp);
					jsonCNRData.put("state", state_of_comp);
				}
				cmArrList.add(jsonCNRData);
			}
		}
		jsonData.put("ComponentNameData",cmArrList);

		if(s_view!=null && s_view.equalsIgnoreCase("Live Data"))
		{
			JSONArray mArrList = new JSONArray();
			showLegendChk = false;
			jsonData.put("Mode",mappingInfo.getTextDescription("monitor.livegraph.Mode"));
			jsonData.put("selectedMode",mode);

			JSONObject jsonMData = new JSONObject();

			jsonMData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.3D"));
			jsonMData.put("valueField","3D");
			mArrList.add(jsonMData);

			jsonMData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.2D"));
			jsonMData.put("valueField","2D");

			mArrList.add(jsonMData);

			jsonData.put("ModeData",mArrList);
		}

		jsonData.put("GraphType",mappingInfo.getTextDescription("monitor.livegraph.Graphs"));
		jsonData.put("selectedGraphType",s_view);

		JSONArray gtArrList = new JSONArray();
		JSONObject jsonGTData = new JSONObject();

		jsonGTData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.Live Data"));
		jsonGTData.put("valueField","Live Data");
		gtArrList.add(jsonGTData);

		jsonGTData = new JSONObject();

		jsonGTData.put("displayField",mappingInfo.getTextDescription("monitor.livegraph.TopN/LastN"));
		jsonGTData.put("valueField","TopN/LastN");
		gtArrList.add(jsonGTData);

		jsonData.put("GraphTypeData",gtArrList);

		if(s_view!=null && s_view.equals("TopN/LastN"))
		{
			JSONArray chList = new JSONArray();

			trans_services_ini.createFile("eg_services.ini");
			
			Hashtable analysis_Single_Data=new Hashtable();
			String appLiveGraph=egUI.getValue("APPLICATION_LIVE_GRAPH_TOPLAST",s_comptype);
			String top_last=egUI.getValue("APPLICATION_LIVE_GRAPH_TOPLAST","TopN/LastN");

			int topLastValue=Integer.parseInt(top_last);
			if(appLiveGraph!=null && appLiveGraph.trim().length()>0 && s_comp!=null && !s_comp.equals("-1") && !s_comp.equals("null"))
			{
				StringTokenizer tokens=new StringTokenizer(appLiveGraph,",");
				int totalTokens=tokens.countTokens();
				String msmtHost="";

				String mainTag="";
				int c=-1;
				String s_iniFile_dir2=EgInstallInfo.getInstallDir()+"/manager/config/";
				IniFile iniObj=new IniFile(s_iniFile_dir2+"eg_dashboard.ini");
				Vector times=(Vector)dashboardModel.getStartEndDateTimeForMeasure();
				String startTime="";
				String endTime="";
				String startHour="";
				String endHour="";
				if(times!=null && times.size()>=4)
				{
					startTime=(String)times.get(0);
					endTime=(String)times.get(1);
					startHour=(String)times.get(2);
					endHour=(String)times.get(3);
				}
				Hashtable measureLastTimeForAllTest=new Hashtable();
				measureLastTimeForAllTest=measureGraph.getMeasureLastRunTimeForAllTest("'"+s_comp+"'");
				boolean is_convert_MB_to_GB=false;
				String str_convert_MB_to_GB=iniObj.getValue("Display_Analysis","convert_MB_to_GB");
				if(str_convert_MB_to_GB!=null && str_convert_MB_to_GB.equalsIgnoreCase("yes"))
				{
					is_convert_MB_to_GB=true;
				}

				while(tokens.hasMoreTokens())
				{
					JSONObject jsonChData = new JSONObject();
					c=c+1;
					StringBuffer key_value=new StringBuffer();
					String token=(String)tokens.nextToken();
					String test=token.substring(0,token.indexOf(":"));
					String measure=token.substring(token.indexOf(":")+1,token.lastIndexOf(":"));
					String priority=token.substring(token.lastIndexOf(":")+1);
					String measureForDB=dbInfo.getColumnForMeasure(test,measure);
					String unit=tablesInfo.getUnitForMeasure(test,measure);
					String display_name=mappingInfo.getMeasureDescription(test,measure);
					List agents=egExternalInfo.getAgentsFor(test,s_comptype,s_comp);
					if(agents!=null && agents.size()>0)
					{
						msmtHost=(String)agents.get(0);
					}
					else
						msmtHost=s_comp;

					boolean portReleventForTest = false;
					boolean isTestRelevantForServer = false;
					if(test!=null)
					{
						portReleventForTest = specsInfo.isPortRelevantForTest(test);
						isTestRelevantForServer = specsInfo.isTestRelevantForServer(s_comptype,test);
					}

					String Layer_name_str=tablesInfo.getLayerForTest(test);
					StringTokenizer tokenLayer=new StringTokenizer(Layer_name_str,",");
					String layerName="HOST";
					if(tokenLayer!=null)
					{
						while(tokenLayer.hasMoreTokens())
						{
							String l_name=(String)tokenLayer.nextToken();
							if(l_name!=null)
							{
								if(tablesInfo.isMeasureInLayer(test,measure,l_name))
								{
									layerName=l_name;
									break;
								}
							}
						}
					}
					String lastRuntime=null;
					if(measureLastTimeForAllTest!=null && measureLastTimeForAllTest.size()>0)
						lastRuntime=(String)measureLastTimeForAllTest.get(test+"^"+s_comp);
					boolean isTimeout=false;
					//Added by Chandrasekhar toget Cut of Factor value from eg_services.ini...
					String cut_off_factor_value = null;
					if(test!=null)
						cut_off_factor_value = trans_services_ini.getStrValue("CUT_OFF_FACTOR", test);
					
					if(cut_off_factor_value==null || cut_off_factor_value.trim().length()==0)
					{
						cut_off_factor_value = trans_services_ini.getStrValue("CUT_OFF_FACTOR", "Default");
					}
					//ended here...
					if(cut_off_factor_value!=null && !cut_off_factor_value.trim().equals("-1") && lastRuntime!=null && lastRuntime.trim().length()>0 && cut_off_factor_value.trim().length()>0)
					{
						String compName_for_timeout=comp_name;
						if(!portReleventForTest)
						{
							if (comp_name!=null && comp_name.indexOf(":")>-1)
							{
								compName_for_timeout=comp_name.substring(0,comp_name.indexOf(":"));
							}
						}
						isTimeout=MeasuresDao.isTimeOut(lastRuntime,test+"#"+msmtHost,compName_for_timeout,s_comptype);
					}

					if(isTestRelevantForServer && !isTimeout)
					{
						isTimeout=false;
					}
					else
					{
						isTimeout=true;
					}

					if(!isTimeout)
					{
						analysis_Single_Data=dashboardDAO.getCurrentAnalysisStatus(comp_name,s_comptype,port,null,test,measureForDB,msmtHost,null,null,null,null,null,null,null,true,null,priority,topLastValue);
					}

					if(analysis_Single_Data!=null && analysis_Single_Data.size()==1)
					{
						mainTag="<chart majorTMNumber='6'  plotSpacePercent='100' showLabels='1' majorTMHeight='10' majorTMColor='ffffff' minorTMColor='D5D5D5' minorTMHeight='5' minorTMNumber='5' majorTMThickness='2' palette='2' showValues='1' showYAxisValues='0'  showXAxisValues='0' decimals='2' formatNumberScale='0' useRoundEdges='"+useRoundEdges+"' exportEnabled='0' showExportDialog='1' exportAction='save' exportTargetWindow='1' showShadow='1' showToolTipShadow='1' chartLeftMargin='8' chartRightMargin='20' chartTopMargin='3' chartBottomMargin='8' bgColor='99CCFF,FFFFFF' bgAlpha='0,0' outCnvBaseFontColor='000000' canvasLeftMargin='17' canvasRightMargin='7' canvasTopMargin='5' canvasBottomMargin='7' showBorder='0' clickURL='javascript:showFullview("+c+",this.event,1)'> " ;
					}
					else if(analysis_Single_Data!=null && analysis_Single_Data.size()==2)
					{
						mainTag="<chart majorTMNumber='6' plotSpacePercent='80'    showLabels='1' majorTMHeight='10' majorTMColor='ffffff' minorTMColor='D5D5D5' minorTMHeight='5' minorTMNumber='5' majorTMThickness='2' palette='2' showValues='1' showYAxisValues='0'  showXAxisValues='1' decimals='2' formatNumberScale='0' useRoundEdges='"+useRoundEdges+"' exportEnabled='0' showExportDialog='1' exportAction='save' exportTargetWindow='1' showShadow='1' showToolTipShadow='1' chartLeftMargin='8' chartRightMargin='20' chartTopMargin='3' chartBottomMargin='8' bgColor='99CCFF,FFFFFF' bgAlpha='0,0' outCnvBaseFontColor='000000' canvasLeftMargin='17' canvasRightMargin='7' canvasTopMargin='5' canvasBottomMargin='7' showBorder='0' clickURL='javascript:showFullview("+c+",this.event,1)'> " ;
					}
					else
					{
						mainTag="<chart majorTMNumber='6'  plotSpacePercent='60' showLabels='1' majorTMHeight='10' majorTMColor='ffffff' minorTMColor='D5D5D5' minorTMHeight='5' minorTMNumber='5' majorTMThickness='2' palette='2' showValues='1' showYAxisValues='0'  showXAxisValues='1' decimals='2' formatNumberScale='0' useRoundEdges='"+useRoundEdges+"' exportEnabled='0' showExportDialog='1' exportAction='save' exportTargetWindow='1' showShadow='1' showToolTipShadow='1' chartLeftMargin='8' chartRightMargin='20' chartTopMargin='3' chartBottomMargin='8' bgColor='99CCFF,FFFFFF' bgAlpha='0,0' outCnvBaseFontColor='000000' canvasLeftMargin='17' canvasRightMargin='7' canvasTopMargin='5' canvasBottomMargin='7' showBorder='0' clickURL='javascript:showFullview("+c+",this.event,1)'> " ;
					}
					Vector ddKeys=new Vector();
					Vector ddValues=new Vector();
					Vector reverseddKeys = new Vector();
					Vector reverseddValues= new Vector();
					if(analysis_Single_Data!=null && analysis_Single_Data.size()>0)
					{
						Vector sortedkeys=dashboardModel.getSortedKeys(analysis_Single_Data);
						dashboardModel.displayTopNMeasures(sortedkeys,analysis_Single_Data,"ALL",false);
						
						ddKeys=dashboardModel.ddKeys;
						ddValues=dashboardModel.ddValues;

						if(priority!=null && priority.equalsIgnoreCase("LAST"))
						{
							if(ddValues!=null  && ddValues.size()>0)
							{
								for(int j=ddValues.size()-1; j >= 0; j--)
								{
									reverseddKeys.add((String)ddKeys.get(j));
									reverseddValues.add((String)ddValues.get(j));
								}
							}
							ddKeys=new Vector();
							ddValues=new Vector();
							ddKeys=reverseddKeys;
							ddValues=reverseddValues;
						}
					}

					key_value.append(mainTag);

					int i=0;

					String color_palet[]={"B35806","F1A340","67A9CF","E7298A","EF8A62","7570B3","008E8F","999999","9D594","570B3","008E8F", "FF9900","FFCCBB","FFD700","AA00114","21B6AB"};
					int count_color=(analysis_Single_Data!=null)?analysis_Single_Data.size():0;
					Color[] chart_colors=new Color[count_color];
					Vector chart_colors2=new Vector();
					//String vars=iniObj.getValue("Dashboard_Graph_colors","BarGraph");
					String vars = uiIniObj.getValue("CHART_COLORS","BAR_CHART");
					
					int cnt=0;
					do
					{
						StringTokenizer ctr=new StringTokenizer(vars,",");
						while(ctr.hasMoreTokens())
						{
							if((chart_colors.length-1)<cnt)
								break;
							String tmpColor=(String)ctr.nextToken();
							chart_colors[cnt]=Color.decode(tmpColor);
							chart_colors2.add(tmpColor);
							cnt++;
						}
					}while(chart_colors.length!=cnt);

					if(ddValues!=null  && ddValues.size()>0)
					{
						for(int  h=0;h<ddValues.size();h=h+1)
						{
							String ddvalue=(String)ddValues.get(h);
							if(ddvalue!=null && !ddvalue.equals("") && !ddvalue.equalsIgnoreCase("null"))
							{
								if(unit!=null && unit.equals("MB") && is_convert_MB_to_GB)
								{
									try
									{
										double fillColorValue=Double.parseDouble(ddvalue);
										fillColorValue=fillColorValue/1024.0;
										ddvalue=String.valueOf(fillColorValue);
									}
									catch(Exception e)
									{
										ddvalue=ddvalue;
										unit="MB";
									}
								}
								try
								{
									ddvalue=String.valueOf(com.egurkha.util.MathUtils.round(Double.parseDouble(ddvalue),2));
								}
								catch(Exception e)
								{
									ddvalue=ddvalue;
								}

								String str=(String)ddKeys.get(h);
								String valueStr="";
								String toolTextStr="";
								if(str.length()>=20)
								{
									String tmpStr=str.substring(0,20)+"..";
									valueStr=tmpStr;
									toolTextStr=str.substring(0,20);
									String tempToolTextStr=str.substring(20);
									while(tempToolTextStr.trim().length()>20)
									{
										toolTextStr=toolTextStr+"\\n"+tempToolTextStr.substring(0,20);
										tempToolTextStr=tempToolTextStr.substring(20);
									}
									toolTextStr=toolTextStr+"\\n"+tempToolTextStr;
								}
								else
								{
									valueStr=str;
									toolTextStr=str;
								}

								toolTextStr=com.egurkha.util.StringUtils.replace(toolTextStr,"&","-");
								str=com.egurkha.util.StringUtils.replace(str,"&","-");

								String display_toolText="";
								if(toolTextStr!=null && toolTextStr.trim().length()>0)
									display_toolText=display_toolText+toolTextStr+" , ";

								display_toolText=display_toolText+dbInfo.formatValue(Double.parseDouble(ddvalue));

								key_value.append("<set label=\'");
								key_value.append(valueStr);
								key_value.append("\' ");
								key_value.append(" toolText=\'");
								key_value.append(display_toolText);
								key_value.append("\'");
								key_value.append(" value=\'");
								key_value.append(ddvalue);
								key_value.append("\'");
								key_value.append(" displayValue=\'");
								key_value.append(ddvalue);
								key_value.append("\'");
								key_value.append(" color=\'");
								try
								{
									key_value.append(chart_colors2.get(h));
								}
								catch(Exception e){e.printStackTrace();}
								key_value.append("\'");
								key_value.append("/>");
							}
						}
					}

					if(unit!=null && unit.equals("MB") && is_convert_MB_to_GB)
					{
						unit="GB";
					}

					key_value.append("</chart>");

					String tdWidth="";
					
					if(totalTokens==1)
					{
						tdWidth="100%";
					}
					else if(totalTokens==2)
					{
						tdWidth="50%";
					}
					else
					{
						tdWidth="33.33%";
					}

					jsonChData.put("measureTitle",mappingInfo.getMeasureDescription(test,measure)+"("+unit+")");

					
				
					Vector barColors=HighChartTimeline.getBarPieChartColor(true,"bar");
					boolean isFusionChart=HighChartTimeline.isFusion();

					if(analysis_Single_Data!=null && analysis_Single_Data.size() > 0)
					{

						String urlForMaximize="";
						urlForMaximize="/final/servlet/com.egurkha.monitor.DDTopview?host="+EgURLEncoder.encode(comp_name,"UTF-8")+"&compType="+EgURLEncoder.encode(s_comptype,"UTF-8")+"&test="+EgURLEncoder.encode(test,"UTF-8")+"&measure="+measureForDB+"&real_measure="+measure+"&module=System&width=880&height=320&from=fullview&mode=3D&graphdisplay=defaultView&fullview=true&monitorSkin="+monitor_Skin+"&msmt_host="+EgURLEncoder.encode(msmtHost,"UTF-8")+"&port="+port+"&isFromAnalysis=true&layer="+EgURLEncoder.encode(layerName,"UTF-8")+"&starttime="+startTime+"&starthr="+startHour+"&endtime="+endTime+"&endhr="+endHour+"&time_line=1+hour&displayName="+EgURLEncoder.encode(display_name,"UTF-8")+"&isTimeout="+isTimeout+"&priority=ALL&display=false&applyFusion=true&actualPriority="+priority+"&noOfInfos="+top_last;
						if(isFusionChart)
						{
							jsonChData.put("chartCId","vLGFC"+c);
							jsonChData.put("divId","chartContainer"+c);
							jsonChData.put("fcId","myChartId"+c);
							jsonChData.put("movie",zoomoutChart);
							jsonChData.put("dataXML",key_value.toString());
							jsonChData.put("fullViewURL",urlForMaximize);
						}
						


						JSONObject dataSetObject = new JSONObject();
						JSONObject dataObject = new JSONObject();
						JSONArray dataArrayObj = new JSONArray();
						JSONArray labelArray=new JSONArray();

					
						JSONArray arrayObj=new JSONArray();	
						if(ddValues!=null  && ddValues.size()>0)
						{
							Vector barColorValue=HighChartTimeline.getBarPieChartColor(true,"bar");
							for(int  h=0;h<ddValues.size();h=h+1)
							{
								String ddvalue=(String)ddValues.get(h);
								String str=(String)ddKeys.get(h);
								JSONObject objData = new JSONObject();
								String valueStr="";
								String toolTextStr="";
								str=com.egurkha.util.StringUtils.replace(str,"&","-");
								objData.put("name",str); 
								labelArray.add(str);
								if(str.length()>=20)
								{
									String tmpStr=str.substring(0,20)+"..";
									valueStr=tmpStr;
									toolTextStr=str.substring(0,20);
									String tempToolTextStr=str.substring(20);
									while(tempToolTextStr.trim().length()>20)
									{
										toolTextStr=toolTextStr+"\\n"+tempToolTextStr.substring(0,20);
										tempToolTextStr=tempToolTextStr.substring(20);
									}
									toolTextStr=toolTextStr+"\\n"+tempToolTextStr;
								}
								else
								{
									valueStr=str;
									toolTextStr=str;
								}
								toolTextStr=com.egurkha.util.StringUtils.replace(toolTextStr,"&","-");
								str=com.egurkha.util.StringUtils.replace(str,"&","-");
								String colorValue  = (String)barColorValue.get(h);
								if(ddvalue.indexOf("-")>-1)
									objData.put("y",0);
								else
									objData.put("y",new Double(ddvalue));
								objData.put("color",colorValue);
								arrayObj.add(objData);
							}
						}
						int barChartHeight = 230;
						barChartHeight = ( labelArray.size() <= 5)?barChartHeight:(100+(labelArray.size()*22));
						if(!isFusionChart)
						{
							dataSetObject.put("chartHeight",new Integer(barChartHeight));
							dataSetObject.put("xAxisLabel",labelArray);
							dataSetObject.put("fullViewURL",urlForMaximize);
							dataObject.put("data",arrayObj);
							dataObject.put("showInLegend",new Boolean(false)); 
							dataArrayObj.add(dataObject);
							JSONObject styles=new JSONObject();
							styles.put("title",HighChartTimeline.getBarProperty("bar","caption"));
							//styles.put("title",mappingInfo.getMeasureDescription(test,measure)+"("+unit+")");
							styles.put("legendStyle",HighChartTimeline.getBarProperty("bar","legend"));
							styles.put("datalabel",HighChartTimeline.getBarProperty("bar","datalabel"));
							//styles.put("color",HighChartTimeline.getBarPieChartColor(true,"bar"));
							dataSetObject.put("DataSet",dataArrayObj);
							dataSetObject.put("name","");
							dataSetObject.put("chartType","bar");
							dataSetObject.put("title",mappingInfo.getMeasureDescription(test,measure)+"("+unit+")");
							dataSetObject.put("chartCId","vLGFC"+c);
							dataSetObject.put("divId","chartContainer"+c);
							dataSetObject.put("fcId","myChartId"+c);
							dataSetObject.put("fullViewId",c+",this.event,1,analysisBargraph");
							dataSetObject.put("maxChartType","analysisBargraph");
							dataSetObject.put("styles",styles);
							chList.add(dataSetObject);
						}
					}
					else 
					{
						boolean isAdded = false;
						if(isFusionChart)
						{
							jsonChData.put("measureErrData",mappingInfo.getTextDescription("monitor.VirtualDashboard.No measures available"));
							
						}
						else
						{
							jsonChData.put("measureErrData",mappingInfo.getTextDescription("monitor.VirtualDashboard.No measures available"));
							if(!isFusionChart)
							{
								chList.add(jsonChData);
								isAdded = true;
							}
						}
						if(s_comp!=null && s_comp.trim().length()>0 && !s_comp.equals("-1"))
						{
							jsonChData.put("measureErrData",mappingInfo.getTextDescription("monitor.VirtualDashboard.No measures available"));
							if(!isFusionChart && !isAdded)
								chList.add(jsonChData);
						}
					}
					if(isFusionChart)
					{
						chList.add(jsonChData);
					}
				}
			}
			else
			{
				JSONObject jsonChData = new JSONObject();
				jsonChData.put("errData",mappingInfo.getTextDescription("monitor.measure.No data found for this selection"));

				chList.add(jsonChData);
			}

			jsonData.put("TopNData",chList);
		}
		else if(s_view!=null && s_view.equals("Live Data"))
		{
			JSONArray lgList = new JSONArray();

			if(tests!=null && tests.size()>0)
			{
				JSONObject jsonVGData = new JSONObject();

				jsonVGData.put("lgHeader",mappingInfo.getTextDescription("monitor.livegraph.Time is displayed in the X-Axis in")+"\""+mappingInfo.getTextDescription("monitor.livegraph.HH")+":"+mappingInfo.getTextDescription("monitor.livegraph.mm")+"\""+mappingInfo.getTextDescription("monitor.livegraph.format"));

				jsonVGData.put("cols",noCol);
				jsonVGData.put("rows",iniUi.getRows());
				jsonVGData.put("scroll",scroll);
				jsonVGData.put("chCount",tests.size());

				lgList.add(jsonVGData);
				int count=0;

				for(int i=0; i<tests.size(); i++)
				{
					jsonVGData = new JSONObject();
					String test=((String)tests.get(i)).trim();
					String strTestOnly = test;
					if(test.indexOf(":")>-1)
						strTestOnly  = test.substring(0,test.indexOf(":"));
					String tmpport=port;
					if (!specs.isPortRelevantForTest(strTestOnly))
						tmpport="NULL";
								
					if((i%noCol)==0)
					{
						count=0;
					}
					jsonVGData.put("code","com.objectplanet.chart.ChartApplet");
					jsonVGData.put("archive","/final/monitor/chart.ext.jar");
					jsonVGData.put("gmode",mode);

					String gdurl="/final/monitor/livegraph/EgVmwareLiveGraphParam.jsp?test="+test+"&er_component="+EgURLEncoder.encode(s_comp,"UTF-8")+":"+tmpport+"&comptype="+request.getParameter("comptype")+"&tableId="+i+"&mode="+mode;

					jsonVGData.put("chId","liveGraphId"+(i+1));
					jsonVGData.put("gDataUrl",gdurl);

					count++;
					if(count ==noCol)
					{
						//---no data--
					}
					lgList.add(jsonVGData);
				}
			}
			else
			{
				JSONObject jsonVGData = new JSONObject();
				jsonVGData.put("errData",mappingInfo.getTextDescription("monitor.measure.No data found for this selection"));

				lgList.add(jsonVGData);
			}
			jsonData.put("LiveData",lgList);
		}
		else
		{
			jsonData.put("noData",mappingInfo.getTextDescription("monitor.measure.No data found"));
		}
		json.put("jsonData",jsonData);
	}
	else
	{
		json.put("noData",mappingInfo.getTextDescription("monitor.measure.No data found"));
	}
	String showLegStr = request.getParameter("showLegend");
	if(showLegStr == null || showLegStr.equals(""))
		showLegStr = egUI.getValue("CHART_TYPE","showLegendsInCharts");

	json.put("LegendInChart",showLegStr);
	json.put("showLegendChk",showLegendChk);
	response.getWriter().write(json.toString());
}
catch(Throwable e)
{
	e.printStackTrace();
}
%>
<%!
public ArrayList getStateSortedList(Vector v_comp,String s_comptype, AlarmPriorities ap)
{
	Vector temp_aList_info=new Vector();
	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();
	for(int c=0;c<v_comp.size();c++)
	{
		String comp=(String)v_comp.get(c);
		String state_of_comp="GOOD";
		if(comp!=null && comp.length()>0 && comp.indexOf(":")>-1)
		{
			state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+comp), s_comptype,"NULL");
		}
		else
		{
			state_of_comp= ap.getAlarmPriority(Server.getServerName(s_comptype+":"+comp+":NULL"), s_comptype,"NULL");
		}

		if(state_of_comp!=null && state_of_comp.equalsIgnoreCase("HIGH"))
		{
			temp_info_HIGH_list.add(comp);
		}
		else if(state_of_comp!=null && state_of_comp.equalsIgnoreCase("INTERMEDIATE"))
		{
			temp_info_INTER_list.add(comp);
		}
		else if(state_of_comp!=null && state_of_comp.equalsIgnoreCase("LOW"))
		{
			temp_info_LOW_list.add(comp);
		}
		else if(state_of_comp!=null && state_of_comp.equalsIgnoreCase("UNKNOWN"))
		{
			temp_info_UNKNOWN_list.add(comp);
		}
		else if(state_of_comp!=null && state_of_comp.equalsIgnoreCase("GOOD"))
		{
			temp_info_GOOD_list.add(comp);
		}
		
	}
	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));
}
%>