 <%@ include file="ErReporterTracker.jsp"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.eg.EgReportInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgTablesInfo"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "com.eg.*"%>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "org.json.simple.JSONObject"%>
<%@ page import = "org.json.simple.JSONArray"%>
<%@ page import = "egurkha.reporter.ErInfrastructureHealthBean"%>
<jsp:useBean id="dd" scope="page" class="com.egurkha.monitor.EgDiagnosisBean" />
<%@ page import="java.io.UnsupportedEncodingException"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="java.net.URLEncoder"%>
<%!
	
	private static final String BLANK_SPACE = " ";
	private static final String COMA = ",";
	private static final String COLON = ":";
	private static final String PIE = "|";
	private static final String BSLASH = "/";
	private static final String UTF_8 = "UTF-8";
	private static final String NODATAFOUND = "NO_DATA_FOUND";
	private static final String MANAGER = "manager"; 
	private static final String INFRASTRUCTURE_HEALTH_REPORT = "INFRASTRUCTURE_HEALTH_REPORT";
	private static final String HEALTHREPORT_MEASURE_MAPPING = "HEALTHREPORT_MEASURE_MAPPING";
%>

<%
try {
	JSONObject popUpStatus=new JSONObject();
	ErInfrastructureHealthBean bean = new ErInfrastructureHealthBean();
	EgReportInfo reportInfo = new EgReportInfo(MANAGER);
	EgTablesInfo tablesInfo = new EgTablesInfo(MANAGER);
	EgDbInfo dbInfo = new EgDbInfo(MANAGER);
	ErUtils utils = new ErUtils();
	IniUI ui = IniUI.getInstance();
	String thisLanguage = ui.getDefaultLanguage();
	Map resultMap = (HashMap) session.getAttribute(INFRASTRUCTURE_HEALTH_REPORT);
	String componentType = request.getParameter("compType");
	//System.out.println("componentType&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& :"+componentType);
	String criteria = request.getParameter("criteria");
	if(criteria!=null)
	{
		criteria = utils.specialCharDecode(criteria);
	}
	String displayStr  = criteria;
	if (criteria != null && criteria.indexOf("#$#") != -1){
		displayStr = criteria.substring(criteria.indexOf("#$#")+3);
		criteria = criteria.substring(0, criteria.indexOf("#$#"));
	}
	String testMeasurestr = reportInfo.getValue(
			HEALTHREPORT_MEASURE_MAPPING, criteria);
	if(testMeasurestr == null || testMeasurestr.length()==0)
	{
		ArrayList aListLayerTest = tablesInfo.getTestsForLayer (criteria,componentType);
		for (int m=0; m<aListLayerTest.size();m++ )
		{
			if(testMeasurestr == null || testMeasurestr.length() ==0)
				testMeasurestr = (String) aListLayerTest.get(m);
			else
				testMeasurestr +=","+(String) aListLayerTest.get(m);
		}
	} 
	EgMappingInfo intlmap = new EgMappingInfo(thisuser.getLanguage());
	String er_healthSummary = request.getParameter("er_healthSummary");
	String er_component = request.getParameter("er_component");
	String startdate = request.getParameter("startdate");
	String enddate = request.getParameter("enddate");
	String starthr = request.getParameter("starthr");
	String endhr = request.getParameter("endhr");
	String startmin = request.getParameter("startmin");
	String endmin = request.getParameter("endmin");
	String inidate = request.getParameter("inidate");
	String er_timeline = request.getParameter("er_timeline");
	String er_site = request.getParameter("er_site");
	String timefrom = request.getParameter("timefrom");
	String minfrom = request.getParameter("minfrom");
	String timeto = request.getParameter("timeto");
	String minto = request.getParameter("minto");
	String er_from = request.getParameter("er_from");

	String strManagerURL = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
	// added for DD data start here
	egurkha.TestBean testBean = new egurkha.TestBean();
	com.eg.EgSpecsInfo specsInfo = new com.eg.EgSpecsInfo("manager");
	com.eg.EgAgentInfo agentInfo = new com.eg.EgAgentInfo("manager");
	boolean ddEnabled = com.eg.EgMemInfo.ddEnabled;
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile fmtUI = new IniFile(s_iniFile_dir + "eg_format.ini");
	String ddEnableForCompType = fmtUI.getValue("Default_DDEnabled", componentType);
	boolean isddEnabled = ddEnableForCompType.equalsIgnoreCase("yes") ? true : false;
	boolean isAgentlessServer = agentInfo.isAgentlessServer(er_component, componentType, true);
	
	// added for DD data ends here

	String mngrIProc = new IniFile(new EgConfigInfo("manager")
				.getDbFile()).getValue("DB_PROPERTIES", "ManagerUrl");
	
		String uiFile = "eg_ui.ini";
		com.eg.IniFile egUI = new com.eg.IniFile(s_iniFile_dir + uiFile);
		String currentDateFormat = strUserDateFormat;
		
		String startDateForHighchart = startdate  +" " + starthr + ":" + startmin;
		String endDateForHighchart   = enddate + " " + endhr + ":" + endmin;

		String chartType=ErHighchartUtils.getChartType(startDateForHighchart,endDateForHighchart,currentDateFormat+" HH:mm");
		chartType="highchart";
		popUpStatus.put("chartType",chartType);
		session.setAttribute("DRILLDOWN_PDF_URL",mngrIProc+"/final/reporter/ErInfrastructureHealthStatusPrint.jsp");

		String s_qryString = "er_component="+er_component+"&criteria="+URLEncoder.encode(criteria)+"&er_healthSummary="+er_healthSummary+"&startdate="+request.getParameter("startdate")+"&enddate="+request.getParameter("enddate")+"&timefrom="+timefrom+"&minfrom="+minfrom+"&timeto="+timeto+"&minto="+minto+"&starthr="+starthr+"&endhr="+endhr+"&er_timeline="+er_timeline+"&startmin="+startmin+"&endmin="+endmin+"&er_site="+er_site+"&compType="+componentType+"&isChartRequest=true&drillSes=yes&er_from=save";
		JSONObject urlFields=new JSONObject();
		urlFields.put("printUrl","ErInfrastructureHealthStatusPrint");
		urlFields.put("pdfUrl","../reporter/ErHtmlToSavePdf.jsp?"+s_qryString+"&pdfPrint=no"); 
		urlFields.put("drilldownPrintUrl","../reporter/ErInfrastructureHealthStatusPrint.jsp?"+s_qryString+"&pdfPrint=yes"); 
 		popUpStatus.put("urlFields",urlFields);
			
						if (er_from == null){ 	
						}
	
						popUpStatus.put("title",intlmap.getTextDescription("reporter.common.Problems affecting the health of - "+displayStr+" Category"));
						Iterator itr = resultMap.keySet().iterator();
						List DurationList = new ArrayList();
						List originalKeyList = new ArrayList();
						Map KeysMap = new HashMap();
						while(itr.hasNext())
						{
							String strTemp = (String)itr.next();
							Object obj = resultMap.get(strTemp);
							if(obj instanceof Long  && strTemp!=null && !strTemp.endsWith(criteria) && strTemp.indexOf(criteria) != -1 && er_healthSummary != null && (er_healthSummary.equalsIgnoreCase("At Tier Level") || er_healthSummary
										.equalsIgnoreCase("Component_type") || (er_healthSummary.equalsIgnoreCase("At Server Level") && strTemp.indexOf(er_component) > -1)))
							{
								List keyList = new ArrayList();
								if(er_healthSummary!=null && er_healthSummary.equalsIgnoreCase("At Tier Level") || er_healthSummary.equalsIgnoreCase("Component_type"))
								{
									if(strTemp!=null && strTemp.indexOf(componentType)==-1)
										continue;
								}
								StringTokenizer st = new StringTokenizer(strTemp,"|");
								//System.out.println("sobj  :"+obj);
								Long value = (Long)obj;
								if (st.countTokens() == 4 && value.longValue() > 0){
									DurationList.add((Long)obj);
									if (KeysMap.containsKey(value))
										keyList =(ArrayList) KeysMap.get(value);
									else 
										keyList = new ArrayList();
									keyList.add(strTemp);
									if(!originalKeyList.contains(value))
										originalKeyList.add(value);
									KeysMap.put(value,keyList);
								}
							}
						}
						JSONArray subData=new JSONArray();
						Collections.sort(originalKeyList);
						StringTokenizer st = new StringTokenizer(testMeasurestr, ",");
						//while (st.hasMoreTokens()) {
						int problemCount = 0;
						Hashtable alertParams=new Hashtable();
						for (int v=originalKeyList.size()-1; v>=0; v--){
							Long measureAlertDuration = (Long)originalKeyList.get(v);
							ArrayList KeyList = (ArrayList)KeysMap.get(measureAlertDuration);
							JSONObject labelValueObj=null;
							for(int l=0; l<KeyList.size(); l++)
							{
								labelValueObj=new JSONObject();
								String  tempStr = (String) KeyList.get(l);
								String key = tempStr;
								//System.out.println("tempStr*************************** :"+tempStr);
								//if(er_healthSummary != null && !er_healthSummary.equalsIgnoreCase("At Server Level"))
									//componentType = tempStr.substring(0,tempStr.indexOf("|"));
								//System.out.println("componentType*************************** :"+componentType);
								//component = tempStr.substring(0,tempstr.indexOf("|"));
								tempStr = tempStr.substring(tempStr.indexOf("|")+1);
								tempStr = tempStr.substring(tempStr.indexOf("|")+1);
								String test = tempStr.substring(0,tempStr.indexOf("|"));
								tempStr = tempStr.substring(tempStr.indexOf("|")+1);
								String measure = tempStr;
								// key = componentType + PIE + criteria + PIE + test ;
								//measure = tempMeasure[l];
								//Long measureAlertDuration = (Long)resultMap.get(key);
								long alertDuration = 0;
								if (measureAlertDuration != null)
									alertDuration = measureAlertDuration.longValue();
								String measureCountKey = key + "|Count";
								int measureCount = 0;
								String infosKey = key + "|INFO"; 
								String infoKey = key + "|INFOTIMES";
								List infoList = (ArrayList) resultMap.get(infoKey);
								if(infoList!=null)
									measureCount = infoList.size();
								// added for DD data start here
								boolean isTestExternal = specsInfo.isTestExternal(test.trim());
								boolean isDdEnableTestMeas = testBean.isDdEnabled(test.trim(),measure.trim());
								String ddEnable ="No";
								if (ddEnabled && isDdEnableTestMeas && (!isAgentlessServer || isTestExternal || isddEnabled))
								{
									ddEnable = "Yes";
								}
							// added for DD data ends here
									String tempInfoCount = reportInfo.getValue("INFRASTRUCTURE_HEALTH_REPORT","ChartInfoCount");
								int TotalInfoCount = 0;
								try {
									TotalInfoCount = Integer.parseInt(tempInfoCount);
								} catch(Exception e) {
									TotalInfoCount = 5;
								}
								{
									Long tempValue = (Long) resultMap.get(key);
									long value = tempValue.longValue();
									value = (value / 1000) / 60;
									long hr = value / 60;
									long days = 0;
									if (hr >= 24){
										days = hr/24;
										hr = hr % 24;
									}
									problemCount = problemCount+1;
					
											if((originalKeyList!=null && originalKeyList.size()>1) || (KeyList!=null && KeyList.size()>1))
											{	
												//out.print(problemCount+") ");
												labelValueObj.put("count",problemCount+") ");
											}
											//Commenting the below code since this is duplicated
											/*if(componentType!=null && componentType.endsWith("_ex"))
											{
												//out.println(tablesInfo.getMeasureAlert(test+":"+measure,"+",thisLanguage));
 												labelValueObj.put("header1",tablesInfo.getMeasureAlert(test+":"+measure,"+",thisLanguage));
											}
											else
											{
												//out.println(intlmap.getMeasureAlert(test+":"+measure));
												labelValueObj.put("header1",intlmap.getMeasureAlert(test+":"+measure));
											}*/

												StringBuffer tpd=new StringBuffer();
												if(measureCount >= 1){ 
												long hour = 0;
												long min = 0;
												long sec = 0;
												long day = 0;
												if (alertDuration > 0){
													alertDuration = alertDuration / 1000;
													sec = alertDuration % 60;
													alertDuration = alertDuration / 60;
													min = alertDuration % 60;
													alertDuration = alertDuration / 60;
													hour = alertDuration % 24;
													day = alertDuration / 24;
													alertDuration = alertDuration % 24;
												}
												
	
																	if (day > 0 ){ 
																			tpd.append(String.valueOf(day)); 
																			tpd.append("day "); 
																
																	}
																	if (hour > 0) {
																			tpd.append(String.valueOf(hour)); 
																			tpd.append("h ");
																
																	}
																	if (min > 0){
																			tpd.append(String.valueOf(min)); 
																			tpd.append("m ");
																
																	} 
																	if (sec > 0){
																			tpd.append(String.valueOf(sec)); 
																			tpd.append("s");
																
																	}
																 }
									
									 labelValueObj.put("label1",intlmap.getTextDescription("reporter.common.Total Problem Duration")+" : ");
									 labelValueObj.put("label1-1",tpd.toString());
									// labelValueObj.put("label2-1",intlmap.getTextDescription("reporter.common.Identified by: Test -").replaceAll("#",""));	
									 labelValueObj.put("label2-1",intlmap.getTextDescription("Test -").replaceAll("#",""));	
									 labelValueObj.put("label2-2"," "+intlmap.getTestDescription(test)+" ");
									 labelValueObj.put("label2-3",intlmap.getTextDescription("reporter.common.Measure -").replaceAll("#",""));
									 labelValueObj.put("label2-4"," "+intlmap.getMeasureDescription(test,measure));
									 //labelValueObj.put("label2",intlmap.getTextDescription("Identified by (test & measure)")+":"+intlmap.getTestDescription(test)+" - "+intlmap.getMeasureDescription(test,measure));
									 labelValueObj.put("label3",intlmap.getTextDescription("reporter.common.Affected Components").replaceAll("#",""));
									// System.out.println("labelValueObj"+labelValueObj); 
									// subData.add(labelValueObj);
									
									TreeMap tmap = new TreeMap();
									Map infoMap = new TreeMap(); 
									ArrayList aDescList = new ArrayList();
									if(infoList != null && infoList.size() > 0) {
									
										int infoSize = infoList.size();
										List dummyList = new ArrayList();
										// for getting the top 3 component with its info having alerts starts here
										Collections.sort(infoList);
										int count = 0;
										String prevInfo = "";
										List tempList = new ArrayList();
										List tempInfoList = new ArrayList();
										for(int i=0; i<infoSize; i++)
										{	  											
											String currentInfo = (String)infoList.get(i);
											currentInfo = currentInfo.substring(0,currentInfo.indexOf("|$|"));
										if (!tempInfoList.contains(currentInfo))
												tempInfoList.add(currentInfo);
											if(prevInfo.equals(""))
												prevInfo = currentInfo;
											if(prevInfo.equals(currentInfo))
												count ++;
											else {
												if(infoMap.containsKey(new Integer(count)))
														tempList = (ArrayList) infoMap.get(new Integer(count));
													else 
														tempList = new ArrayList();
														tempList.add(prevInfo);
														infoMap.put(new Integer(count),tempList);
														tmap.put(new Integer(count),prevInfo);
														prevInfo = currentInfo;
														count = 1;
											}
										}
											if(infoMap.containsKey(new Integer(count)))
													tempList = (ArrayList) infoMap.get(new Integer(count));
											tempList.add(prevInfo);
											infoMap.put(count,tempList);
										resultMap.put(test+":"+measure+":"+"InfoList",infoMap);
										Set infoSet = infoMap.keySet();
										infoList = new ArrayList();
										infoList.addAll(infoSet);
										resultMap.put(test+":"+measure+":"+"InfoCount",infoList);
										
										JSONObject colObj=new JSONObject();	 											
										colObj.put("c1",intlmap.getTextDescription("reporter.common.Component Type"));
										colObj.put("c2",intlmap.getTextDescription("reporter.common.Component"));
										colObj.put("c3",intlmap.getTextDescription("reporter.common.Test"));
										colObj.put("c4",intlmap.getTextDescription("reporter.common.Descriptor"));
										colObj.put("c5",intlmap.getTextDescription("reporter.common.Total Duration"));
										
									
														if(ddEnable!=null && !ddEnable.equals("") && ddEnable.equalsIgnoreCase("Yes") && er_from == null)
														{
															colObj.put("c6",intlmap.getTextDescription("reporter.common.Diagnosis Data"));
													
														}
													
													
										Map infoDetailsMap = new TreeMap();
										for(int i=infoList.size()-1; i>=0; i--)
										{
											Integer tempCount = (Integer) infoList.get(i);
											int occurenceCount = tempCount.intValue();
											String occurenceCountStr = "1";
											if (occurenceCount > 1)
												occurenceCountStr = String.valueOf(occurenceCount);

											List valueList = (ArrayList) infoMap.get(tempCount);
											for(int j=0; j<valueList.size(); j++)
											{
												String tempInfo = (String) valueList.get(j);
												tempInfo = tempInfo.substring(tempInfo.indexOf("|")+1);
												String infoStr = tempInfo;
												if(!dummyList.contains(infoStr)){
													dummyList.add(infoStr);
												} else 
													continue;
												String component = er_component;
												if(er_healthSummary != null && !(er_healthSummary.equalsIgnoreCase("At Server Level") )){
													component = infoStr.substring(0,infoStr.indexOf("$"));
													infoStr = infoStr.substring(infoStr.indexOf("$")+1);
												}else
												{
													if(infoStr!=null && infoStr.indexOf("$")>-1){
														component = infoStr.substring(0,infoStr.indexOf("$"));
														infoStr = infoStr.substring(infoStr.indexOf("$")+1);
													}
												}
												String infoDurationKey = key + PIE + infoStr;
												if(!infoStr.equals("+"))
													infoStr = infoStr.substring(infoStr.indexOf("+")+1);

	/*String dd_url = "/final/monitor/EgDispDD.jsp?site="+er_site+"&host="+
	com.eg.EgURLEncoder.encode(component.substring(0,component.indexOf(":")),"UTF-8")+"&port="+component.substring(component.indexOf(":")+1)
	+"&test="+test+"&info=*"+infoStr
	+"&from=0&measure="+measure+"&firsttime=true&comeFrom=Reporter&newWindow=true&flag=1&starttime="+
	startdate+"&endtime="+enddate+"&starthr="+starthr+"&endhr="+endhr+"&startmin="+startmin+"&timeline="+
	er_timeline+"&endmin="+endmin+
	"&msmt_host="+
	"&inidate="+inidate+
	"&layer="+
	"&comptype="+componentType;*/
	

	String ddInfoQusrt=infoStr;
	 if (ddInfoQusrt!=null && ddInfoQusrt.indexOf("#")>-1)
	{
		ddInfoQusrt=StringUtils.replace(ddInfoQusrt,"#","|hash|");
	}
	 if (ddInfoQusrt!=null && ddInfoQusrt.indexOf("+")>-1)
	{
		ddInfoQusrt=StringUtils.replace(ddInfoQusrt,"+","|plus|");
	}
	 if (ddInfoQusrt!=null && ddInfoQusrt.indexOf("&")>-1)
	{
		ddInfoQusrt=StringUtils.replace(ddInfoQusrt,"&","|amp|");
	}
	 if (ddInfoQusrt!=null && ddInfoQusrt.indexOf("%")>-1)
	{
		ddInfoQusrt=StringUtils.replace(ddInfoQusrt,"%","|pct|");
	}

	String mesureHost=EgURLEncoder.encode(component.substring(0,component.indexOf(":")),"UTF-8");
	if(isTestExternal)
		mesureHost="";//..

	ddInfoQusrt="*"+ddInfoQusrt;
	if(componentType!=null && componentType.equalsIgnoreCase("Oracle_server"))
		ddInfoQusrt = ddInfoQusrt;


	String dd_url = "/final/monitor/componentMeasureTabSet.jsp?type="+EgURLEncoder.encode(componentType,"UTF-8")+"&site="+er_site+"&host="+EgURLEncoder.encode(component.substring(0,component.indexOf(":")),"UTF-8")+"&port="+component.substring(component.indexOf(":")+1)+"&info="+EgURLEncoder.encode(ddInfoQusrt,"UTF-8")+"&state=&messy="+measure+"&msmt_host="+mesureHost+"&userID="+EgURLEncoder.encode(urs,"UTF-8")+"&test="+ test+"&comptype="+componentType+"&measureDisp="+measure+"&from=measurespage&dd=yes&clicked=dd&newWindow=true&fromReporterHis=true&popup=true&fromPage=eveHist&starttime="+EgURLEncoder.encode(startdate,"UTF-8")
	+"&endtime="+EgURLEncoder.encode(enddate,"UTF-8")+"&starthr="+starthr+"&endhr="+endhr+"&startmin="+startmin+"&timeline="+er_timeline+"&endmin="+endmin;

													if(infoStr.equals("+"))
														infoStr = "-";
													Long infoAlertDuration = (Long) resultMap.get(infoDurationKey);
												if (infoAlertDuration != null){
												if(component.indexOf("NULL") > -1)
													component = component.substring(0,component.indexOf("NULL")-1)+ component.substring(component.indexOf("NULL")+4);
													alertDuration = 0;
													if (infoAlertDuration != null)
														alertDuration = infoAlertDuration.longValue();
													long hour = 0;
													long min = 0;
													long sec = 0;
													long day = 0;
													if (alertDuration > 0){
														alertDuration = alertDuration / 1000;
														sec = alertDuration % 60;
														alertDuration = alertDuration / 60;
														min = alertDuration % 60;
														alertDuration = alertDuration / 60;
														hour = alertDuration % 24;
														day = alertDuration / 24;
														alertDuration = alertDuration % 24;

													}
													String time = "";
													
													if (day > 0 )
														time = day +"day ";
													if (hour > 0)
														time+=hour +"h ";
													if (min > 0)
														time+=min +"m ";
													if (sec > 0)
														time+=sec+"s";
													String detailedString = intlmap.getComponentTypeDescription(componentType) + "$$" +component +"$$"+intlmap.getTestDescription( test)+"$$"+infoStr+"$$"+time;
													if(ddEnable!=null && !ddEnable.equals("") && ddEnable.equalsIgnoreCase("Yes"))
														detailedString += "$$" + dd_url;
													List detailList;
													if (infoDetailsMap.containsKey(infoAlertDuration))
														detailList = (ArrayList)infoDetailsMap.get(infoAlertDuration);
													else
														detailList = new ArrayList();
													detailList.add(detailedString);
													infoDetailsMap.put(infoAlertDuration,detailList);
												}
											}
										}
										int infoCount = 0; 
										Set timeSet = infoDetailsMap.keySet(); 
										List timeList = new ArrayList(timeSet); 
										JSONArray tableArray=new JSONArray(); 
										ArrayList aListAdd = new ArrayList();
										boolean b_timeListFlag = false;
										for (int i=timeList.size()-1; i>=0; i--){
											Long measureDuration = (Long)timeList.get(i);
											List detailList = (ArrayList) infoDetailsMap.get(measureDuration);
											
											
											for(int j=0; j<detailList.size(); j++)
											{
												JSONArray rowArray=new JSONArray();
												String values = (String)detailList.get(j);
												aDescList.add(values);
												st = new StringTokenizer(values,"$$");
												//prakash for showing top 5 duration based on comp and descriptor
												if (infoCount >= TotalInfoCount)
												{	
													b_timeListFlag = true;
													break;
												}
												//
												int detailCount =0;
												String prevStr = "";
												while(st.hasMoreTokens())
												{	
													JSONObject rowObj=new JSONObject();	 													
													String tempStr1 = st.nextToken();
													if (st.hasMoreTokens()) {
														if (detailCount == 4){
															String query="/final/reporter/ErInfrastructureProblemDetails.jsp?test="+test+"&measure="+measure+"&er_healthSummary="+er_healthSummary+"&compType="+componentType+"&criteria="+URLEncoder.encode(criteria)+"&er_component="+er_component+"&er_info="+com.eg.EgURLEncoder.encode(prevStr,"UTF-8");
															rowObj.put("tdText",tempStr1);
															rowObj.put("tdParam",query);
														} else {
															prevStr = tempStr1;
															rowObj.put("tdText",tempStr1);
											
														}
														rowArray.add(rowObj);
													} else if (ddEnable!=null && !ddEnable.equals("") && ddEnable.equalsIgnoreCase("Yes") ){
														if ( er_from == null) {
															rowObj.put("tdText",intlmap.getTextDescription("reporter.common.View Diagnosis"));
															rowObj.put("tdParam",tempStr1);
															rowObj.put("tdImg","../reporter/images/diagnosis.gif");
															rowArray.add(rowObj);
											
														}  
													} else {
															String query="/final/reporter/ErInfrastructureProblemDetails.jsp?test="+test+"&measure="+measure+"&er_healthSummary="+er_healthSummary+"&compType="+componentType+"&criteria="+URLEncoder.encode(criteria)+"&er_component="+er_component+"&er_info="+com.eg.EgURLEncoder.encode(prevStr,"UTF-8");
															rowObj.put("tdText",tempStr1);
															rowObj.put("tdParam",query);
															rowArray.add(rowObj);											
													}
													detailCount++;
												}
												JSONObject rowAdd=new JSONObject();
												rowAdd.put("row",rowArray);
												tableArray.add(rowAdd);													
											
												infoCount++;
											}
											//prakash for showing top 5 duration based on comp and descriptor
											if(b_timeListFlag)
												break;
											//
										} 
										JSONObject tb=new JSONObject();
										tb.put("cols",colObj);
										tb.put("tableData",tableArray);
										labelValueObj.put("table",tb);
										// System.out.println("labelValueObj"+labelValueObj);
								
									
										infoList = new ArrayList();
										infoList.addAll(tempInfoList);
									} //if close
									if(resultMap.containsKey(infoKey)){
										String query="/final/reporter/ErInfrastructureProblemDetails.jsp?test="+test+"&measure="+measure+"&er_healthSummary="+er_healthSummary+"&compType="+componentType+"&criteria="+URLEncoder.encode(criteria)+"&er_component="+er_component+"&er_info="+null; 										
										labelValueObj.put("label4",intlmap.getTextDescription("reporter.common.View problem history"));
										labelValueObj.put("label4Param",query);
								}
							String servlet1 = "../../final/servlet/com.eg.ErInfrastructureHealthReportC;jsessionid=" + session.getId() + "?isChartRequest=true&er_width=900&er_height=350&er_test="+test+"&er_measure="+measure+"&er_healthSummary="+com.eg.EgURLEncoder.encode(er_healthSummary,
										UTF_8) +"&er_component="+er_component+"&er_comptype="+componentType+"&minto="+minto+"&timefrom="+timefrom+"&minfrom="+minfrom+"&timeto="+timeto+"&startdate="+com.eg.EgURLEncoder.encode(startdate,
										UTF_8)+"&enddate="+com.eg.EgURLEncoder.encode(enddate,
										UTF_8)+"&s_st_hr="+starthr+"&s_en_hr="+endhr+"&strmin="+startmin+"&enmin="+endmin+"&userID="+urs+"&criteria="+com.eg.EgURLEncoder.encode(criteria, UTF_8);
								String dbMeasure = dbInfo.getColumnForMeasure(test ,measure);
							
								
								
								String imgExpandParams = "&er_test="+test+"&&isKpiHealthReport=true&er_measure="+dbMeasure+"&er_disp_meas="+measure+"&er_gtype=intrasnap&er_healthSummary="+com.eg.EgURLEncoder.encode(er_healthSummary, UTF_8) +"&er_comptype="+componentType+"&er_comp_type="+componentType+"&minto="+minto+"&timefrom="+timefrom+"&minfrom="+minfrom+"&timeto="+timeto+"&startdate="+com.eg.EgURLEncoder.encode(startdate,UTF_8)+"&enddate="+com.eg.EgURLEncoder.encode(enddate,UTF_8)+"&starthr="+starthr+"&endhr="+endhr+"&startmin="+startmin+"&endmin="+endmin+"&userID="+urs+"&er_timeline="+com.eg.EgURLEncoder.encode(er_timeline,UTF_8)+"&drilldownenabled=yes"+"&inidate="+currentDateFormat;

									if(aDescList!=null && aDescList.size()>5) {
									infoList = new ArrayList();
									int infoCount=0;
									for(int ii=0;ii<aDescList.size();ii++) {
										String strList = (String)aDescList.get(ii);
										StringTokenizer stToken = new StringTokenizer(strList,"$$");
										if(stToken.hasMoreTokens())
										{
											stToken.nextToken();
											String compName = stToken.nextToken();
											stToken.nextToken();
											String strInfos = stToken.nextToken();
											if(infoCount >= TotalInfoCount)
												break;
											if(!strInfos.startsWith("+"))
												strInfos = "+"+strInfos;
											infoList.add(compName+"$"+strInfos);
											infoCount++;
										}
									}
								} 
								if(infoList!=null && infoList.size() > 0){
											labelValueObj.put("label5",intlmap.getTestDescription(test)+" - "+intlmap.getMeasureDescription(test,measure));
											labelValueObj.put("imageServlet",servlet1);
													
											IniUI iniui=IniUI.getInstance();
											//int maxSize = infoList.size()< TotalInfoCount ?infoList.size():TotalInfoCount;
											int maxSize = infoList.size();
											HashMap map=(HashMap)iniui.getReporterGraphParams();
											StringTokenizer stc = new StringTokenizer((String)map.get("samplecolors"),",");
											String[] colorstrArray = new String[stc.countTokens()];
											for(int k=0;k<colorstrArray.length;k++)
											{
												String strstc = stc.nextToken().trim();
												colorstrArray[k]=strstc;
											}
											int colorCount = 0;
											JSONArray boxColorImageArr=new JSONArray();
											JSONArray boxColorTextArr=new JSONArray();
											String hstName="";
											String cmpName="";
											String infsLst="";
											String description ="";
											for(int i=0; i<maxSize; i++)
											{
												String st_key = colorstrArray[colorCount];
												String infoStr = (String) infoList.get(i);
												String component = "";
												if(infoStr.indexOf("$") != -1){
													component = infoStr.substring(0,infoStr.indexOf("$"));
													infoStr = infoStr.substring(infoStr.indexOf("$")+2);
													if(component.indexOf("NULL") != -1)
														component = component.substring(0,component.indexOf("NULL")-1) ;//;+ component.substring(component.indexOf("NULL")+4);
													if(componentType!=null && componentType.endsWith("_ex"))
													{
														labelValueObj.put("header1",tablesInfo.getMeasureAlert(test+":"+measure,"+",thisLanguage));
													}
													else
													{
														alertParams=new Hashtable();
														alertParams.put("$componentName",component);
														alertParams.put("$componentType",componentType);
														String tmpInfo = infoStr;
														if(tmpInfo!=null && tmpInfo.length()>1){
															if(tmpInfo.startsWith("+")){
																tmpInfo = tmpInfo.substring(1);
																alertParams.put("$info",tmpInfo);
															}
															else
																alertParams.put("$info",tmpInfo);
														}
														alertParams.put("appendTag",new Boolean(false));
														description = tablesInfo.getMeasureAlert(test+":"+measure,infoStr,thisLanguage,alertParams);
														if(description != null && description.indexOf("~!~") != -1){
															boolean infoAdded = new Boolean(description.substring(description.indexOf("~!~")+3)).booleanValue();
															description = description.substring(0,description.indexOf("~!~"));
															if(!infoAdded && tmpInfo != null && tmpInfo.trim().length() > 1)
																description = description+" {"+tmpInfo+"} ";
														}
														labelValueObj.put("header1",description);
														labelValueObj.put("header"+(l+1),description);
													}
												if(infoStr!=null && !infoStr.equals("-") && infsLst.indexOf(infoStr) <= 0)
												{
													if(i == maxSize -1)
														infsLst+=infoStr;
													else
														infsLst+=infoStr+"|";
												}
												if(cmpName != null && cmpName.indexOf(component) < 0){
													if(i == 0)
														cmpName=component;
													else
														cmpName+="|"+component;
												}
												hstName=component;
												if (!infoStr.equals(""))
													component += " - " + infoStr;
												} else {
													component = infoStr.substring(1);
												}
												colorCount++;
												if(colorCount > colorstrArray.length-1)
													colorCount = 0;
												st_key = st_key.substring(1,st_key.length());
												boxColorImageArr.add("/final/servlet/com.eg.ErImageDrawC?req="+st_key);
												boxColorTextArr.add(component);
											}
											
											labelValueObj.put("boxImageServlet",boxColorImageArr);
											labelValueObj.put("label6",boxColorTextArr);
									
											if(cmpName != null && !cmpName.equalsIgnoreCase("")){
												if(cmpName.indexOf("|") > -1)
													imgExpandParams+="&hasMultipleHosts=true";
												imgExpandParams+="&er_hostNames="+com.eg.EgURLEncoder.encode(cmpName,UTF_8);
											}
											if(hstName != null && !hstName.equalsIgnoreCase("")){
												imgExpandParams+="&er_component="+com.eg.EgURLEncoder.encode(hstName,UTF_8);
											}
											if(infsLst != null && !infsLst.equalsIgnoreCase("")){
												imgExpandParams+="&er_info_list="+com.eg.EgURLEncoder.encode(infsLst,UTF_8);
											}
											imgExpandParams = imgExpandParams+"&forInfrastructure=true";
										String strRecommendation = utils.findMeasureInterpretation(test,measure);
										
										if(strRecommendation!=null && strRecommendation.length()>0 && !strRecommendation.trim().equalsIgnoreCase("&nbsp")&&!strRecommendation.trim().equalsIgnoreCase("&nbsp;")&&!strRecommendation.trim().equalsIgnoreCase("-")){
											labelValueObj.put("label7",intlmap.getTextDescription("reporter.common.Recommendation").replaceAll("#",""));
											labelValueObj.put("label8",strRecommendation);

											}
										if((originalKeyList!=null && originalKeyList.size()>1) || (KeyList!=null && KeyList.size()>1))
										{

										}
										labelValueObj.put("imageServletExpandUrl",imgExpandParams);
									}
									

									}
								subData.add(labelValueObj);  
							}
							//System.out.println("subData=="+subData);
						}  //for close
						st = new StringTokenizer(testMeasurestr, ",");
						boolean headerFlag = true;
						if (st.hasMoreTokens()){
						
						}
						JSONObject rowObj;
						JSONArray rowArray;
						JSONObject colObj;
						JSONArray myTableArray=new JSONArray();
						JSONObject tableObj=new JSONObject();
						String testIndex=null;
						while (st.hasMoreTokens()) {
							rowArray=new JSONArray();

							ArrayList aListTemp = new ArrayList();
							String tempStr = st.nextToken();
							String test = tempStr;//.substring(0, tempStr.indexOf(COLON));
							if(test.indexOf(COLON) > -1)
								test = test.substring(0, test.indexOf(COLON));
							String measure = null;
							if(tempStr.indexOf(COLON) > -1)
								measure = tempStr.substring(tempStr.indexOf(COLON)+1);
							if(measure != null && measure.indexOf("*") == -1)
							{
								if(measure.indexOf("#$#") != -1){
									measure = measure.substring(0,measure.indexOf("#$#"));
								}
							} else {
								measure = null;
							}
							if(test.indexOf("#$#") != -1){
								test = test.substring(test.indexOf("#$#")+3);
							}

							String key = componentType + PIE + criteria + PIE + test ;

							if(er_healthSummary != null && er_healthSummary.equalsIgnoreCase("At Server Level"))
								key = er_component + PIE + criteria + PIE + test ;
							String[] tempMeasure;
							if(measure != null){
								tempMeasure = new String[]{measure};
							} else {
								tempMeasure = dbInfo
										.getMeasurementsForTest(test);
							}
							String originalKey  =key;
							ArrayList aListMeasure = new ArrayList();
							for(int l=0; l<tempMeasure.length; l++)
							{
								measure = tempMeasure[l];
								key = originalKey + PIE + measure;
								int measureCount = 0;
								String infoKey = key + "|INFOTIMES";
								List infoList = (ArrayList) resultMap.get(infoKey);
								if(infoList!=null)
									measureCount = infoList.size();
								if (!resultMap.containsKey(key) || measureCount == 0) {
									aListMeasure.add(measure);
								}
							}
							for (int m1=0;m1<aListMeasure.size();m1++)
							{
								   rowObj=new JSONObject();
								 
								measure = (String)aListMeasure.get(m1);
									if (headerFlag){
										colObj=new JSONObject(); 
										colObj.put("c1",intlmap.getTextDescription("reporter.common.Test"));
										colObj.put("c2",intlmap.getTextDescription("reporter.common.Measure"));
										colObj.put("c3",intlmap.getTextDescription("reporter.common.Health %"));
									tableObj.put("header",displayStr+" - "+intlmap.getTextDescription("reporter.common.Associated metrics and their Health %"));
									tableObj.put("cols",colObj);		
								
									headerFlag = false;
									}

														if(aListMeasure.size()>1)
														{
															if(m1==0)
															{
																testIndex=intlmap.getTestDescription(test);

															}
														}else
														{
															testIndex=intlmap.getTestDescription(test);


														}
														rowObj.put("measure",intlmap.getMeasureDescription(test,measure));
														rowObj.put("health",100);

								rowArray.add(rowObj);
							}
							if(rowArray!=null && rowArray.size()>0)
							{
								JSONObject testObj=new JSONObject();
								testObj.put("test",testIndex);
								testObj.put("array",rowArray);
								myTableArray.add(testObj); 
							}
					}	
					 
						tableObj.put("tableData",myTableArray);
						subData.add(tableObj);
					 
 							
						if (!headerFlag){
						
						}
//For Setting the PDf File Name
HashMap paramVal = new HashMap();
paramVal.put("fileName", "infrastructure_health_report");
session.setAttribute("parameters", paramVal);

		popUpStatus.put("subData",subData);
		//System.out.println("popUpStatus----"+popUpStatus);
	out.println(popUpStatus.toString());				
} catch(Throwable e) {
	e.printStackTrace();
}
  %>