
<%
/********************************************************************************************************
*	Name			:	zones.jsp
*	Purpose			:	This jsp is used to display All the Zones and its associated components in 	Zone Dashboard
*	Version			:	5.6
*	CreationDate	:	Feb 20, 2012
*	Author			:	S.Saravanan
*******************************************************************************************************/
%>
<%@ include file = "EgMonitorTracker.jsp" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "com.eg.*" %>
<%@ page import = "com.egurkha.monitor.*" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "java.util.*" %>
<%@ page import = "com.egurkha.ini.*" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgTopoInfo"%>
<%@ page import = "com.eg.EgStateZone"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgTopoInfo"%>
<%@ page import="com.eg.EgAggregateInfo" %>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "com.eg.EgMaintenanceInfo"%>
<%@ page import="com.egurkha.util.*"%>
<%@ page import="com.egurkha.admin.EgMaintenanceUtility"%>
<%@ page import="net.sf.json.*"%>
<%@ page import="java.sql.*"%>
<%@ page import = "egurkha.*" %>
<%@ page import = "com.eg.EgAggregateInfo"%>

<%@ page import="com.fasterxml.jackson.databind.ObjectMapper"%>
<%@ page import="com.fasterxml.jackson.databind.node.ArrayNode"%>
<%@ page import="com.fasterxml.jackson.databind.node.ObjectNode"%>
<%@ page import="com.fasterxml.jackson.databind.JsonNode"%>
<%
try
{
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);
	response.setContentType("application/json");
	session.removeAttribute("layer");
	session.removeAttribute("test");
	CompositeComparator compobj = new CompositeComparator();
	compobj.add(new StateComparatorDes());
	compobj.add(new NameComparatorAsc());
	ZoneListData d = (ZoneListData) request.getAttribute("data");
	ZoneListResult r = (ZoneListResult) request.getAttribute("result");
	EgAggregateInfo aggregateInfo = new EgAggregateInfo("manager");
	if(session.getAttribute("ZoneListData")!=null && session.getAttribute("ZoneListResult")!=null)
	{
		d=(ZoneListData)session.getAttribute("ZoneListData");
		r=(ZoneListResult)session.getAttribute("ZoneListResult");
	}
	int normalZoneCount=0;
	int abnormalZoneCount=(r==null?0:r.zoneList.size());
	int totalZones = (r==null?0:r.zoneList.size());
	boolean ifshowImage=(r==null?false:r.showImage);
	String treeFlag=request.getParameter("treeFlag");
	String zone_image = "";
	IniUI iniUI = IniUI.getInstance();
	UserRegistry userReg = UserRegistry.getInstance();
	User user = userReg.getUser(session.getId());
	String thisLanguage = iniUI.getDefaultLanguage();
	if (user!=null)
	{
		String userLang = user.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	boolean isUserLanguageEnglish=true;
	if(thisLanguage!=null && !thisLanguage.equals("en_US"))
	{
		isUserLanguageEnglish=false;
	}
	//EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	EgDateInfo dateInfo=new EgDateInfo();
	EgMaintenanceInfo egM=new EgMaintenanceInfo("manager");
	EgMaintenanceUtility maintenanceUtil=new EgMaintenanceUtility();
	EgTopoInfo topoInfo=new EgTopoInfo("manager");
	IniFile uiIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_group.ini");
	String fromHomepage = request.getParameter("fromHomepage");
	fromHomepage = (fromHomepage!=null && !fromHomepage.equalsIgnoreCase("") && !fromHomepage.equalsIgnoreCase("null") && !fromHomepage.equalsIgnoreCase("undefined"))?fromHomepage:"";

	int compNameLength = 18;
	int compHeadLength = 16;
	if(!isUserLanguageEnglish)
	{
		compNameLength = 14;
		compHeadLength = 14;
	}

	DashboardModel dashModel = new DashboardModel();
	com.eg.IniFile commonDashSaveIni = new com.eg.IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_citrixdashboard.ini", true);

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode json  = mapper.createObjectNode();
	ArrayNode  zonesJsonArray = mapper.createArrayNode();
	ObjectNode labelJson = mapper.createObjectNode();
	
	labelJson.put("ListTitle",mappingInfo.getTextDescription("monitor.common.ZONES"));
	labelJson.put("backButtonText",mappingInfo.getTextDescription("monitor.common.Back"));
	labelJson.put("searchResultText",mappingInfo.getTextDescription("monitor.global.Search Results For "));
	
	if(d!=null)
	{
		if(d.searchString != null)
			d.searchString = egurkha.EgUIUtils.decodeSecurityChar(d.searchString);
	}

	if((totalZones!=0)||(d!=null&&d.searchString!=null&&totalZones==0))
	{
		if(totalZones!=0)
		{
			labelJson.put("ListName",mappingInfo.getTextDescription("monitor.zones.Zone Name"));
			labelJson.put("AssociatedElements",mappingInfo.getTextDescription("monitor.zones.Associated Elements"));
		}
		boolean showAssociations = false;
		if(r.showAssociations&&totalZones!=0)
		{
			showAssociations = true;
			labelJson.put("Associations",mappingInfo.getTextDescription("monitor.common.Associations"));
		}
		json.put("showAssociations",String.valueOf(showAssociations));
		if(r.showSearch)
		{
			labelJson.put("searchText",d.searchString);
			labelJson.put("searchDefaultText", mappingInfo.getTextDescription("monitor.common.Search"));
		}

		if (totalZones==0)
		{
			json.put("SearchNoListFound","true");
			json.put("SearchNoListFoundText",mappingInfo.getTextDescription("monitor.zoneDashboard.No zones found for the current search"));
		}
		if(abnormalZoneCount!=0)
		{

			if(d.action.equalsIgnoreCase("zoneState"))
			{
				json.put("listStateHiddenField",d.state.toString());
				
				labelJson.put("ZonesIn",mappingInfo.getTextDescription("monitor.zones.Zones in"));
				json.put("ListIn_value",mappingInfo.getTextDescription("monitor.zones."+d.state.getDisplayName()));
				labelJson.put("State",mappingInfo.getTextDescription("monitor.common.State"));
				if(d.from.equalsIgnoreCase("ZoneDashboard"))
				{
					json.put("ForTheList",mappingInfo.getTextDescription("monitor.zones.for the Zone"));
					json.put("ForTheList_value", d.zoneName);
				}
				if(d.userName!=null)
				{
					json.put("ForTheList",mappingInfo.getTextDescription("monitor.common.For the User"));
					json.put("ForTheList_value", d.userName);
				}
			}
			else
			{
				if(d.userName!=null)
				{
					json.put("ListForTheUser",mappingInfo.getTextDescription("monitor.servers.zones for the User "));
					json.put("ListForTheUser_value", d.userName);
				}
				if(d.from!=null && d.from.equals("ZoneDashboard") && d.action.equals("zone"))
				{
					json.put("ListForTheUser",mappingInfo.getTextDescription("monitor.servers.Zones For the Zone "));
					json.put("ListForTheUser_value", d.zoneName);
				}
			}

			int i = 0;
			int j = 0;
			EgZone zone = null;
			boolean toSave = false;
			json.put("AbnormalListCountHiddenField",String.valueOf(r.zoneList.size()));

			EgDbAdapterUI egDb=EgDbAdapterTypeUI.getObject();
			String s_conn = null;
			Hashtable transactionHash= new Hashtable();				
			try
			{
				s_conn = egDb.setConnection();
				transactionHash= egDb.SelectAllEgTrans();
			}
			catch(Exception e)
			{
				System.out.println("Exception while adding TransactionList to EgService object in Zones.jsp : "+e);
			}
			finally
			{
				egDb.releaseConnection(false);
				EgDbAdapterTypeUI.releaseObject(egDb);
			}

			for(i = 0; i < r.zoneList.size(); i++)//zone loop start here
			{
				zone = (EgZone) r.zoneList.get(i);
				
				ObjectNode zone_json_object = mapper.createObjectNode();

				//request.setAttribute("jsonObject",zone_json_object);
				//request.setAttribute("category","zone");
				//request.setAttribute("itemName",zone.getName());

				ArrayList aggregateArrayZone = aggregateInfo.getAggregateComponentsOfElement("zone",zone.getName());
				if(aggregateArrayZone != null && aggregateArrayZone.size() > 0)
				{
					zone_json_object.put("aggregateTab","true");
				}
				else
				{
					zone_json_object.put("aggregateTab","false");
				}

				%>
					<%//@ include file="aggregateTabHandler.jsp" %>
				<%

				if(ifshowImage)
				{
					zone_image=(String)uiIni.getValue("ZONE_DISPLAY_IMAGE",zone.getName());
					if(zone_image.indexOf("Small")!=-1)
					{
						zone_image=zone_image.replace("Small","48");
						if(zone_image.equals("serviceOthers48"))
						{
							zone_image="zone_GRAY";
						}
						zone_json_object.put("ZoneImage",zone_image);
						zone_json_object.put("StateName", zone.getState().getName());
					}
				}

				zone_json_object.put("NameText", zone.getName());
				zone_json_object.put("URL", "/final/monitor/zoneDash.jsp?treeFlag="+treeFlag+"&outsideZone=true&titleText=zone&selectNode=Zone$cap$"+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&selectedParam="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&zoneName="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&zoneFromZone="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&fromHomepage="+fromHomepage+"&fromZoneMenu=true");
				zone_json_object.put("Tooltip", zone.getName());
				ArrayNode inner_items_json = mapper.createArrayNode();

				EgList zoneList = zone.getZoneList();
				int normalZones=0;
				int abnormalZones=zoneList.size();//sarav subZone start here 
				if(zoneList != null&&zoneList.size()>0&&abnormalZones>0)
				{
					ObjectNode inner_zone_json_object = mapper.createObjectNode();
					inner_zone_json_object.put("NameText",mappingInfo.getTextDescription("monitor.common.Zones"));
					if(zoneList!=null)
					{
						int count = zoneList.size();
						int compSize = count;
						int goodCount = zoneList.getCount(State.getState("Good"));
						
						ArrayNode innerZonesJsonArray = mapper.createArrayNode();
						
						for(j = 0; (j < compSize && j < r.dispCompCount); j++)
						{
							
							ObjectNode innerZoneJsonObject = mapper.createObjectNode();
							
							EgZone zones = null;
							if (j <compSize)
							{
								zones = (EgZone) zoneList.get(j);
								
								aggregateArrayZone = aggregateInfo.getAggregateComponentsOfElement("zone",zones.getName());

								boolean aggregateTab =false;
								if(aggregateArrayZone != null && aggregateArrayZone.size() > 0)
									aggregateTab = true;
								
								innerZoneJsonObject.put("StateName","state_"+zones.getState().getName());
								String href = "/final/monitor/zoneDash.jsp?from=ZoneDashboard&selectNode=Zone$cap$"+EgURLEncoder.encode(zones.getName(),"UTF-8")+"&selectedParam="+EgURLEncoder.encode(zones.getName(),"UTF-8")+"&currentTab=details&monCmd=zoneDashboard&zoneName="+EgURLEncoder.encode(zones.getName(),"UTF-8")+"&treeOpen=false&fromHomepage="+fromHomepage+"&aggregateTab="+aggregateTab+"&parentZone="+zone.getName()+"&fromZoneMenu=true";
								
								innerZoneJsonObject.put("URL",href);

								innerZoneJsonObject.put("Tooltip",zones.getName());
								innerZoneJsonObject.put("NameText",zones.getName());
							}
							innerZonesJsonArray.add(innerZoneJsonObject);
						}
						inner_zone_json_object.put("InnerItems",innerZonesJsonArray);
						
						inner_items_json.add(inner_zone_json_object);
					}
				}
				EgList serviceList = zone.getServiceList();
				int normalServices=0;
				int abnormalServices=serviceList.size();
				if(serviceList != null && serviceList.size()>0 && abnormalServices>0)
				{
					ObjectNode inner_service_json_object = mapper.createObjectNode();
					
					inner_service_json_object.put("NameText",mappingInfo.getTextDescription("monitor.common.Services"));
					int count = serviceList.size();
					int goodCount = serviceList.getCount(State.getState("Good"));
					//count = count - goodCount;
					int compSize = count;
					
					ArrayNode innerServiceJsonArray = mapper.createArrayNode();
					com.eg.IniFile dashConfigIni = new com.eg.IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_dashboardConfig.ini", false);
					String serviceDashboardType = dashConfigIni.getValue("SERVICE_DASHBOARD_TYPE","Citrix_dashboard_view");
					ArrayList simulationTypes = new ArrayList();
					String[] s_types = dashConfigIni.getVariables("SIMULATION_SUPPORT");
					if(s_types != null && s_types.length > 0){
						for(int k=0;k<s_types.length;k++){
							String type = s_types[k];
							if(type != null && type.length() > 0)
								simulationTypes.add(type);
						}
					}
					EgAggregateInfo aggregate1 = new EgAggregateInfo("manager");
					LinkedList siteServers = (LinkedList)d.user.getSites();
					ArrayList dashComps = com.egurkha.util.StringUtils.egTokenizer((dashConfigIni.getValue("InfraDashboard_service_redirectURL","componenetTypes")),",",false,true,true);
					Vector compVec = new Vector();

					for(j = 0; (j < compSize) && j < count; j++)
					{
						ObjectNode innerServiceJsonObject = mapper.createObjectNode();
						EgService service = null;
						if ( j <compSize)
						{
							service = (EgService) serviceList.get(j);
							innerServiceJsonObject.put("StateName","state_"+service.getState().getName());
							//EgTopoInfo topoInfo=new EgTopoInfo("manager");

							// <! Starts  end here -------Kaliraj--------- !>
							compVec = topoInfo.getAssociatesForSite(service.getName());
							String hrefForSite=service.getName();
							boolean isSite=false;
							boolean isEmulTrans = false;
							boolean isLogon = false;
							boolean isRum = false;
							boolean isCitrix = false;
							String comp_type_rum = "";
							String comp_type_rum_first ="";
							List rumcomp_arr = new ArrayList();
							
							for(int p = 0;p<siteServers.size();p++)
							{
								if(service.getName().equals(siteServers.get(p))){
									isSite = true;
									break;
								}
							}
							for(int k=0; k<compVec.size(); k++)
							{
								String comp =(String) compVec.get(k);
								if(comp!=null && comp.indexOf("Emulated")>-1)
								{
									isEmulTrans = true;
								}
								if(simulationTypes != null && simulationTypes.size() > 0 && comp != null && comp.indexOf(":") > 0 && simulationTypes.contains(comp.substring(0,comp.indexOf(":"))))
								{
									isLogon = true;
								}
								if(comp.indexOf("Real_user_monitor") > -1){
									isRum = true;
									comp_type_rum = comp.substring(comp.indexOf(":")+1);
									rumcomp_arr.add(comp_type_rum);
								}
								String comp_type_alone = comp.substring(0,comp.indexOf(":"));
								comp_type_alone = comp_type_alone.trim();
								if(dashComps != null && dashComps.contains(comp_type_alone)){
										isCitrix = true;
								}
							}
							ArrayList aggregateArray1 = aggregate1.getAggregateComponentsOfElement("service",hrefForSite);

							boolean aggregateTab =false;
							if(aggregateArray1 != null && aggregateArray1.size() > 0)
								aggregateTab = true;

							/*EgList transactionList = new EgList();
							if(isSite)
							{
								EgDbAdapterUI egDb;
								egDb=EgDbAdapterTypeUI.getObject();
								String s_conn = null;
								ResultSet rs=null;
							
								try
								{
									s_conn = egDb.setConnection();
									rs = egDb.SelectEgAddMonTrans(hrefForSite.trim());

									while(rs.next())
									{
										transactionList.add(rs.getString("trans_name") +"~~#~~"+ rs.getString("user_id"));
									}

									rs.close();
								}
								catch(Exception e)
								{
									System.out.println("Exception while adding TransactionList to EgService object : "+e);
								}
								finally
								{
									if(rs!=null)
									{
										rs.close();
										rs=null;
									}
									egDb.releaseConnection(false);
									EgDbAdapterTypeUI.releaseObject(egDb);
								}
							}*/

							boolean hasTransactions = false;
							boolean hasEmulatedTransactions = false;

							//if(transactionList != null && transactionList.size() > 0)
							if(transactionHash != null && transactionHash.containsKey(hrefForSite))
							{
								hasTransactions = true;
							}
							
							String currentTab = "";
							if(isSite && hasTransactions)
								currentTab = "transactions";
							else
								currentTab = "topology";

							//String href =	"/final/monitor/serviceDashboard.jsp?action=service&treeFlag=treeFlag&treeTitle=services&outsideService=true&selectNode=Service^&selectedParam="+hrefForSite+"&topoSegment="+hrefForSite+"&currentTab="+currentTab+"&isSite="+isSite+"&aggregateTab="+aggregateTab+"&hasTransactions="+hasTransactions+"&hasEmulatedTransactions="+isEmulTrans+"&treeOpen=false&openNode=Services&fromPage=serviceTree&fromHomepage=true";
										
							//innerServiceJsonObject.put("URL", "/final/monitor/serviceDashboard.jsp?outsideService=true&titleText=Services&selectNode=Service^"+EgURLEncoder.encode(service.getName(),"UTF-8") + ((isSite)?"(Site)":"") +"&serviceFromZone="+EgURLEncoder.encode(service.getName(),"UTF-8")+"&isEmulTrans="+isEmulTrans);
							String url="/final/monitor/serviceDashboard.jsp?action=service&treeFlag=treeFlag&treeTitle=services&outsideService=true&selectNode=Service$cap$&selectedParam="+EgURLEncoder.encode(hrefForSite,"UTF-8")+"&topoSegment="+EgURLEncoder.encode(hrefForSite,"UTF-8")+"&currentTab="+currentTab+"&isSite="+isSite+"&aggregateTab="+aggregateTab+"&hasTransactions="+hasTransactions+"&isEmulTrans="+isEmulTrans+"&treeOpen=false&openNode=Services&fromPage=serviceTree&isFromZone=true";
							if(!fromHomepage.equalsIgnoreCase("") && fromHomepage!=null && !fromHomepage.equalsIgnoreCase("null") && !fromHomepage.equalsIgnoreCase("undefined"))
								url = url + "&fromHomepage="+fromHomepage;

							// <! Changes end here -------Kaliraj--------- !>
							String temp_user = d.user.getLoginID();
							temp_user = (temp_user == null || temp_user.trim().length() == 0)?"admin":temp_user;
						
							com.eg.IniFile ctx_ini = new com.eg.IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_citrixdashboard.ini", false);
									
							String userBased = ctx_ini.getValue("DASHBOARD_SETTINGS","User_Based");
							userBased = (userBased == null || userBased.trim().length() == 0)?"true":userBased;
							ArrayList dashboardNames = null;
							if(userBased != null && userBased.equalsIgnoreCase("true"))
								dashboardNames = com.egurkha.util.StringUtils.egTokenizer((ctx_ini.getValue("User_Dashboard_List",temp_user+":Dashboard_Names")),",",false,true,true);
							if(dashboardNames == null || dashboardNames.size() == 0)
								dashboardNames = com.egurkha.util.StringUtils.egTokenizer((ctx_ini.getValue("Dashboard_List","Dashboard_Names")),",",false,true,true);

							String dashboard_name = ctx_ini.getValue("Dashboard_List",temp_user+":Service"+":"+service.getName()+":DefaultDashboard");
							if(dashboard_name == null || dashboard_name.trim().length() == 0){
								dashboard_name = dashModel.getDashboardName("Service",service.getName(),ctx_ini,d.user,dashboardNames);
								commonDashSaveIni.setValue("Dashboard_List",temp_user+":Service"+":"+service.getName()+":DefaultDashboard",dashboard_name);
								toSave = true;
							}
							String temp_dashboard_name = null;
							String getDashboards[] = ctx_ini.getVariables(temp_user+":"+dashboard_name+":Mapping");
							String activeView=ctx_ini.getValue(dashboard_name,"Dashboard_Default_view");

							if(getDashboards != null && getDashboards.length > 0)
							{
								for(int l=0;l<getDashboards.length;l++)
								{
									String dash_keys = getDashboards[l];
									if(dash_keys == null || dash_keys.trim().length() ==0)
										continue;

									
									if(dash_keys.equalsIgnoreCase("DefaultView"))
										continue;
									
									String dash_value = ctx_ini.getValue(temp_user+":"+dashboard_name+":Mapping",dash_keys);

									if(!dash_value.toLowerCase().startsWith("service:"))
										continue;
									
									if(dash_value.indexOf(":") > -1 && dash_value.indexOf("#~#") > -1)
										dash_value = dash_value.substring(dash_value.indexOf(":")+1,dash_value.indexOf("#~#"));
									
									
									if(dash_value!= null && dash_value.trim().length() > 0 && dash_value.equalsIgnoreCase(service.getName()))
									{
										temp_dashboard_name = dash_keys;
										break;
									}
								}
							}
							if(serviceDashboardType != null && serviceDashboardType.trim().length()>0 && (serviceDashboardType.equalsIgnoreCase("yes") || serviceDashboardType.equalsIgnoreCase("true")))
							{
								if(isRum)
								{	
									StringBuffer  rum_url = new StringBuffer();
									rum_url.append("/final/monitor/rumAppFlow.jsp?");
									rum_url.append("iniName=eg_rumdashboard&action=loadViewData&user_name=");
									rum_url.append(temp_user);
									rum_url.append("&userBased="+userBased+"&fromMenu=true&showConfig=true&");
									
									if(temp_dashboard_name == null || temp_dashboard_name.trim().length() == 0)
										rum_url.append("filter=Service&filterBy="+service.getName());
									else
									{
										rum_url.append("dashboard_mapping="+temp_dashboard_name);
										rum_url.append("&filter=Service&filterBy="+service.getName());
									}
									
									rum_url.append("&dashboard_name=RUM_Dashboard");
									rum_url.append("&hasCitrix="+isCitrix);
									rum_url.append("&hasTransactions="+isSite);
									rum_url.append("&hasEmulatedTransactions="+isEmulTrans);
									rum_url.append("&hasLogonSimulations="+isLogon);
									rum_url.append("&hasRUM="+isRum);
									for(int p=0;p<rumcomp_arr.size();p++){
										comp_type_rum_first = (String)rumcomp_arr.get(0);
									}
									rum_url.append("&appliesTo="+comp_type_rum_first);
									rum_url.append("&isBackFromRUM=false");									
									rum_url.append("&isFromZone=true");
									rum_url.append("&isFromZoneMain=true");
									rum_url.append("&aggregateTab="+aggregateTab);
																	
									url = rum_url.toString();
								}
								else
								{
									StringBuffer  citrix_url = new StringBuffer();
									citrix_url.append("/final/monitor/citrixDashboard.jsp?");
									citrix_url.append("iniName=eg_citrixdashboard&action=loadViewData&user_name=");
									citrix_url.append(temp_user);
									citrix_url.append("&userBased="+userBased+"&fromMenu=true&showConfig=true&fromUED=false&");
									
									if(temp_dashboard_name == null || temp_dashboard_name.trim().length() == 0)
										citrix_url.append("filter=Service&filterBy="+service.getName());
									else
									{
										citrix_url.append("dashboard_mapping="+temp_dashboard_name);
										citrix_url.append("&filter=Service&filterBy="+service.getName());
									}

									citrix_url.append("&dashboard_name="+dashboard_name);
									//citrix_url.append("&view_name="+activeView);
									//citrix_url.append("&active_view="+activeView);
									citrix_url.append("&filterName=");
									citrix_url.append("&filterViewName=");
									citrix_url.append("&hasCitrix="+isCitrix);
									citrix_url.append("&hasTransactions="+isSite);
									citrix_url.append("&hasEmulatedTransactions="+isEmulTrans);
									citrix_url.append("&hasLogonSimulations="+isLogon);
									citrix_url.append("&fromServiceHomePage=true");
									citrix_url.append("&fromSerComboChange=true");
									citrix_url.append("&appliesTo=Service:"+service.getName());
									citrix_url.append("&isFromZone=true");
									citrix_url.append("&isFromZoneMain=true");
									citrix_url.append("&aggregateTab="+aggregateTab);

									
									url = citrix_url.toString();
								}
							}

							innerServiceJsonObject.put("URL",url);							
							innerServiceJsonObject.put("Tooltip",(isSite?service.getName()+"(Site)":service.getName()));
							innerServiceJsonObject.put("NameText",(isSite?service.getName()+"(Site)":service.getName()));
						}
						innerServiceJsonArray.add(innerServiceJsonObject);
					}
					inner_service_json_object.put("InnerItems",innerServiceJsonArray);
					
					inner_items_json.add(inner_service_json_object);
				}
				EgList segmentList = zone.getSegmentList();
				int normalSegments=0;
				int abnormalSegments=segmentList.size();
				if(segmentList != null&&segmentList.size()>0&&abnormalSegments>0)
				{
					ObjectNode inner_segment_json_object = mapper.createObjectNode();
					
					inner_segment_json_object.put("NameText",mappingInfo.getTextDescription("monitor.common.Segments"));
					int count = segmentList.size();
					int goodCount = segmentList.getCount(State.getState("Good"));
					//count = count - goodCount;
					int compSize = count;
					
					ArrayNode innerSegmentJsonArray = mapper.createArrayNode();
					
					for(j = 0; (j < compSize) && j < count; j++)
					{
						ObjectNode innerSegmentJsonObject = mapper.createObjectNode();
						
						EgSegment segment = null;
						if ( j <compSize)
						{
							segment = (EgSegment) segmentList.get(j);
							innerSegmentJsonObject.put("StateName","state_"+segment.getState().getName());
							innerSegmentJsonObject.put("URL", "/final/monitor/segmentDashboard.jsp?outsideSegment=true&titleText=segment&selectNode=Segment$cap$"+EgURLEncoder.encode(segment.getName(),"UTF-8")+"&selectedParam="+EgURLEncoder.encode(segment.getName(),"UTF-8")+"&segment="+EgURLEncoder.encode(segment.getName(),"UTF-8")+"&currentTab=topology&segmentFromZone="+EgURLEncoder.encode(segment.getName(),"UTF-8")+"&isFromZone=true&fromHomepage="+fromHomepage);
							innerSegmentJsonObject.put("Tooltip", segment.getName());
							if (segment.getName().length() > compNameLength)
							{
								innerSegmentJsonObject.put("NameText",segment.getName());
							}
							else
							{
								innerSegmentJsonObject.put("NameText",segment.getName());
							}
						}
						innerSegmentJsonArray.add(innerSegmentJsonObject);
					}
					inner_segment_json_object.put("InnerItems",innerSegmentJsonArray);
					
					inner_items_json.add(inner_segment_json_object);
				}

				EgComponentList aggregateList=zone.getAggregateList();
				int normalAggregates=0;
				int abnormalAggregates=aggregateList.size();
				if(aggregateList != null&& aggregateList.size()>0&&abnormalAggregates>0)
				{
					ObjectNode inner_aggregate_json_object = mapper.createObjectNode();
					
					inner_aggregate_json_object.put("NameText",mappingInfo.getTextDescription("monitor.common.Aggregates"));
					int count = aggregateList.size();
					int compSize = count;
					EgComponent component = null;
					int goodCount = aggregateList.getCount(State.getState("Good"));
					boolean isLayerModel=true;
					if(aggregateInfo.getView().equalsIgnoreCase("dashboard") && EgInstallInfo.isAggregationSupported())
					{
						isLayerModel=false;
					}
					
					ArrayNode innerAggregateJsonArray = mapper.createArrayNode();
					String currdate = dateInfo.egetDate(false);
					for(int k = 0; (k < compSize && k < r.dispCompCount) && k < count; k++)
					{
						ObjectNode innerAggregateJsonObject = mapper.createObjectNode();
						if(k < compSize)
						{
							component = (EgComponent) aggregateList.get(k);
						}

						if ( k <compSize)
						{
						//this block for maintanence image
							String serverName = component.getName();
							
							String sid = "";
							String sname = "";
							String portno = "";
							if ( serverName != null && !serverName.equals(""))
							{
								StringTokenizer  tok=new StringTokenizer(serverName,":");    
								int tokens = tok.countTokens();
								sname = tok.nextToken();
								portno = tok.nextToken();
								if ( tokens == 3 )
									sid = tok.nextToken();
							}
							
							//boolean  isHostMaintenance=egM.isItMaintenanceTime(currdate,sname,"","",true);
							//boolean  isComponentMaintenance=egM.isItMaintenanceTime(currdate,sname,portno,sid,true);

							boolean  isHostMaintenance=false;
							boolean  isComponentMaintenance=false;

							Hashtable resHostHash=(Hashtable)egM.getMaintenanceTimePeriod(currdate,sname,"","",true);
							Hashtable resCompHash=(Hashtable)egM.getMaintenanceTimePeriod(currdate,sname,portno,sid,true);

							if(resHostHash!=null)
							{
								isHostMaintenance = ((Boolean)resHostHash.get("isUnderMaintenance")).booleanValue();
							}

							if(resCompHash!=null)
							{
								isComponentMaintenance = ((Boolean)resCompHash.get("isUnderMaintenance")).booleanValue();
							}

							List  maintenaceTimePeriod=new ArrayList();
							List temp=null;
							if(isHostMaintenance)
							{
								/*temp=egM.getMaintenancePeriods(sname,"","",true);
								if(temp!=null && temp.size()>0)
									maintenaceTimePeriod.addAll(temp);
								temp=egM.getUnplannedMaintenancePeriods(sname,"","",true);
								if(temp!=null && temp.size()>0)
									maintenaceTimePeriod.addAll(temp);*/

								temp=(List)resHostHash.get("MaintenancePeriods");
								if(temp!=null && temp.size()>0)
									maintenaceTimePeriod.addAll(temp);
							}
							if(isComponentMaintenance)
							{
								/*temp=egM.getMaintenancePeriods(sname,portno,sid,true);
								if(temp!=null && temp.size()>0)
								{
									maintenaceTimePeriod.addAll(temp);
								}
								temp=egM.getUnplannedMaintenancePeriods(sname,portno,sid,true);
								if(temp!=null && temp.size()>0)
									maintenaceTimePeriod.addAll(temp);*/

								temp=(List)resCompHash.get("MaintenancePeriods");
								if(temp!=null && temp.size()>0)
									maintenaceTimePeriod.addAll(temp);
							}
							int noOfLines=maintenaceTimePeriod.size();

							String maintenaceTimePeriodStr="";
							if(isHostMaintenance || isComponentMaintenance)
							{
								maintenaceTimePeriodStr=maintenanceUtil.convertMaintenacevectorToString(maintenaceTimePeriod,user);
							}
						//maintanence block end here
							if(r.displayCompType)
							{
								innerAggregateJsonObject.put("StateName","state_"+component.getState().getName());
								String displayComponentType = mappingInfo.getComponentTypeDescription(component.getType());
								innerAggregateJsonObject.put("URL", "/final/servlet/com.eg.EgMonitorController?monCmd=componentList&from=TreeMenu&menuName=agg&searchIndComps=true&action=componentType&componentType="+EgURLEncoder.encode(component.getType(),"UTF-8"));
								innerAggregateJsonObject.put("Tooltip", displayComponentType);
								innerAggregateJsonObject.put("NameText",displayComponentType);
							}
							else
							{
								String site="Null";
								
								innerAggregateJsonObject.put("StateName","state_"+component.getState().getName());
								
								if(!isLayerModel)
								{		
									innerAggregateJsonObject.put("URL","../servlet/com.eg.EgDashboardController?from=list&site="+EgURLEncoder.encode(site,"UTF-8")+"&qctr=0&comptype="+EgURLEncoder.encode(component.getType(),"UTF-8")+"&host="+EgURLEncoder.encode(component.getName(),"UTF-8")+"&tab=LayerModel&toDashBoardLayer=true&treeFlag="+treeFlag+"&action=zone");
									innerAggregateJsonObject.put("NameText",component.getDisplayName());
									innerAggregateJsonObject.put("Tooltip",component.getDisplayName());
									if(isHostMaintenance || isComponentMaintenance)
									{
										innerAggregateJsonObject.put("AlertMaintenanceTime",maintenaceTimePeriodStr);
										innerAggregateJsonObject.put("AlertNoOfLines",String.valueOf(noOfLines));
									}
								}
								else
								{
									innerAggregateJsonObject.put("URL","/final/servlet/com.eg.EgDashboardController?from=list&site=NULL&qctr=0&comptype="+EgURLEncoder.encode(component.getType(),"UTF-8")+"&host="+EgURLEncoder.encode(component.getName(),"UTF-8")+"&showDashBoardLink=true&action=zone");
									innerAggregateJsonObject.put("NameText",component.getDisplayName());
									innerAggregateJsonObject.put("Tooltip",component.getDisplayName());
									if(isHostMaintenance || isComponentMaintenance)
									{
										innerAggregateJsonObject.put("AlertMaintenanceTime",maintenaceTimePeriodStr);
										innerAggregateJsonObject.put("AlertNoOfLines",String.valueOf(noOfLines));
									}
								}
							}
						}
						innerAggregateJsonArray.add(innerAggregateJsonObject);
					}
					inner_aggregate_json_object.put("InnerItems",innerAggregateJsonArray);
					
					inner_items_json.add(inner_aggregate_json_object);
				}

					EgComponentList componentList = zone.getComponentList();
					EgComponent component = null;
					int count = componentList.size();
					if(componentList != null && count>0)
					{
						int goodCount = componentList.getCount(State.getState("Good"));
						//count = count - goodCount;
						int compSize = count;
						
						ObjectNode inner_component_json_object = mapper.createObjectNode();
						inner_component_json_object.put("NameText",mappingInfo.getTextDescription("monitor.common.Components"));
						String currdate = dateInfo.egetDate(false);
						if(componentList != null)
						{
							ArrayNode innerComponentJsonArray = mapper.createArrayNode();
							
							for(j = 0; (j < compSize && j < r.dispCompCount); j++)
							{
								ObjectNode innerComponentJsonObject = mapper.createObjectNode();
								
								EgZone seg = null;
								if ( j <compSize)
								{
									component = (EgComponent) componentList.get(j);
									String site = "NULL";
									//boolean isSite = false;
									//this block for maintanence image
										String serverName = component.getName();
										
										String sid = "";
										String sname = "";
										String portno = "";
										if ( serverName != null && !serverName.equals(""))
										{
											StringTokenizer  tok=new StringTokenizer(serverName,":");    
											int tokens = tok.countTokens();
											sname = tok.nextToken();
											portno = tok.nextToken();
											if ( tokens == 3 )
												sid = tok.nextToken();
										}
										
										//boolean  isHostMaintenance=egM.isItMaintenanceTime(currdate,sname,"","",true);
										//boolean  isComponentMaintenance=egM.isItMaintenanceTime(currdate,sname,portno,sid,true);

										boolean  isHostMaintenance=false;
										boolean  isComponentMaintenance=false;
										
										Hashtable resHostHash=(Hashtable)egM.getMaintenanceTimePeriod(currdate,sname,"","",true);
										Hashtable resCompHash=(Hashtable)egM.getMaintenanceTimePeriod(currdate,sname,portno,sid,true);

										if(resHostHash!=null)
										{
											isHostMaintenance = ((Boolean)resHostHash.get("isUnderMaintenance")).booleanValue();
										}

										if(resCompHash!=null)
										{
											isComponentMaintenance = ((Boolean)resCompHash.get("isUnderMaintenance")).booleanValue();
										}

										List  maintenaceTimePeriod=new ArrayList();
										List temp=null;
										if(isHostMaintenance)
										{
											/*temp=egM.getMaintenancePeriods(sname,"","",true);
											if(temp!=null && temp.size()>0)
												maintenaceTimePeriod.addAll(temp);
											temp=egM.getUnplannedMaintenancePeriods(sname,"","",true);
											if(temp!=null && temp.size()>0)
												maintenaceTimePeriod.addAll(temp);*/

											temp=(List)resHostHash.get("MaintenancePeriods");
											if(temp!=null && temp.size()>0)
												maintenaceTimePeriod.addAll(temp);
										}
										if(isComponentMaintenance)
										{
											/*temp=egM.getMaintenancePeriods(sname,portno,sid,true);
											if(temp!=null && temp.size()>0)
											{
												maintenaceTimePeriod.addAll(temp);
											}
											temp=egM.getUnplannedMaintenancePeriods(sname,portno,sid,true);
											if(temp!=null && temp.size()>0)
												maintenaceTimePeriod.addAll(temp);*/

											temp=(List)resCompHash.get("MaintenancePeriods");
											if(temp!=null && temp.size()>0)
												maintenaceTimePeriod.addAll(temp);
										}
										int noOfLines=maintenaceTimePeriod.size();
										String maintenaceTimePeriodStr="";
										if(isHostMaintenance || isComponentMaintenance)
										{
											maintenaceTimePeriodStr=maintenanceUtil.convertMaintenacevectorToString(maintenaceTimePeriod,user);
										}
									//maintanence block end here
									if(r.displayCompType)
									{
										innerComponentJsonObject.put("StateName","state_"+component.getState().getName());
										String displayComponentType = mappingInfo.getComponentTypeDescription(component.getType());
										innerComponentJsonObject.put("URL","../servlet/com.eg.EgMonitorController?site="+EgURLEncoder.encode(site,"UTF-8")+"&monCmd=componentList&from=ZoneDashboard&action=componentType&componentType="+EgURLEncoder.encode(component.getType(),"UTF-8")+"&searchIndComps=true&zoneName="+EgURLEncoder.encode(zone.getName(),"UTF-8"));
										innerComponentJsonObject.put("Tooltip",displayComponentType);
										innerComponentJsonObject.put("NameText",displayComponentType);
									}
									else
									{
										innerComponentJsonObject.put("StateName","state_"+component.getState().getName());
										innerComponentJsonObject.put("URL","../servlet/com.eg.EgDashboardController?from=list&site="+EgURLEncoder.encode(site,"UTF-8")+"&qctr=0&comptype="+EgURLEncoder.encode(component.getType(),"UTF-8")+"&host="+EgURLEncoder.encode(component.getName(),"UTF-8")+"&tab=LayerModel&toDashBoardLayer=true&treeFlag="+treeFlag+"&action=zone");
										innerComponentJsonObject.put("Tooltip",component.getDisplayName());
										//innerComponentJsonObject.put("NameText",StringUtils.egSubString(component.getDisplayName(),isUserLanguageEnglish,compNameLength,13));
										innerComponentJsonObject.put("NameText",component.getDisplayName());
										if(isHostMaintenance || isComponentMaintenance)
										{
											innerComponentJsonObject.put("MaintenanceTime",maintenaceTimePeriodStr);
											innerComponentJsonObject.put("NoOfLines",String.valueOf(noOfLines));
										}
									}
								}
								innerComponentJsonArray.add(innerComponentJsonObject);
							}
							inner_component_json_object.put("InnerItems",innerComponentJsonArray);
							
							inner_items_json.add(inner_component_json_object);
						}
					}
					zone_json_object.put("InnerItems", inner_items_json);
						
				zonesJsonArray.add(zone_json_object);
			}
			if(toSave)
				commonDashSaveIni.saveFile();
			json.put("RootItem",zonesJsonArray);
		}
		if(normalZoneCount!=0)
		{
			ArrayNode zonesNormalJsonArray = mapper.createArrayNode();
			
			if(!(d.action.equalsIgnoreCase("zoneState") && !d.state.equals(State.GOOD)))
			{
				json.put("NormalZones",mappingInfo.getTextDescription("monitor.zones.Normal Zones"));
				if (normalZoneCount!=0)
				{
					r.zoneList = r.zoneList.search(State.GOOD);
					int count = r.zoneList.size();

					if (count <= 9)
					{
						count = 9;
					}
					else  if(count % 3 > 0)
					{
						count = count + 3 - count % 3;
					}
					json.put("ShowServiceGood","true");
					int i = 0;
					EgZone zone = null;
					
					for(i = 0; i < r.zoneList.size() || i < count; i++)
					{
						ObjectNode zoneNormalJsonObject = mapper.createObjectNode();
						
						boolean isSite = false;
						if(i < r.zoneList.size())
						{
							zone = (EgZone) r.zoneList.get(i);
						}
						if ( i <r.zoneList.size())
						{
							if (zone.getName().length() > compNameLength)
							{
								//Onclick handling is to be done on client side 
								zoneNormalJsonObject.put("zoneURL","/final/monitor/EgSiteInfraView.jsp?site="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&isSite="+isSite+"&service="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&target=main&fromHomepage="+fromHomepage);
								zoneNormalJsonObject.put("zoneTooltip",zone.getName());
								zoneNormalJsonObject.put("zoneNameText",zone.getName());
							}
							else
							{
								//Onclick handling is to be done on client side
								zoneNormalJsonObject.put("zoneURL","/final/monitor/EgSiteInfraView.jsp?site="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&service="+EgURLEncoder.encode(zone.getName(),"UTF-8")+"&target=main&fromHomepage="+fromHomepage);
								zoneNormalJsonObject.put("zoneTooltip",zone.getName());
								zoneNormalJsonObject.put("zoneNameText",zone.getName());
							}
						}
						zonesNormalJsonArray.add(zoneNormalJsonObject);
					}
				}
			}
			json.put("normalZonesArray",zonesNormalJsonArray);
		}
	}
	//}
	else
	{
		json.put("NoListFound","true");
		json.put("NoListFoundText",mappingInfo.getTextDescription("monitor.zones.No zones found"));
	}
	json.put("screenLabels",labelJson);
	if ((d!=null) && (!d.equals("")))
	{
	if( d.action!=null && d.action.equalsIgnoreCase("globalsearch") || d.action.equalsIgnoreCase("globalsearchallzone"))
	{
      /*if(request.getQueryString()!=null)
	   {
		  session.setAttribute("globalSearchLastSessionURL","/final/monitor/zoneDash.jsp?"+request.getQueryString());
	   }
	   else
	   {
		 session.setAttribute("globalSearchLastSessionURL","/final/monitor/zoneDash.jsp");
	   }*/
	   if(d.searchString!=null && d.searchString.length()>0)
		{
			session.setAttribute("monitorLastSession","/final/servlet/com.eg.EgMonitorController?monCmd=zoneList&from=zoneList&action=globalsearch&searchString="+d.searchString+"&treeOpen=false&isFromMenu=false&refresh=true");
			
		}
		else
		{
			session.setAttribute("globalSearchLastSessionURL","/final/monitor/zoneDash.jsp?");
		}

	}
        else
	{
          if(request.getQueryString()!=null)
	  {
		session.setAttribute("monitorLastSession","/final/monitor/zoneDash.jsp?"+request.getQueryString());
	  }
	  else
	  {
		session.setAttribute("monitorLastSession","/final/monitor/zoneDash.jsp?");
	  }
	}
	}
	response.getWriter().write(json.toString());
}
catch(Throwable e)
{
	System.out.println("Exception is ZoneDashboard page "+e);
	e.printStackTrace();
}

%>
