<%
/***********************************************************************************
*		Name				:	servicePerformanceConfigp.jsp
*		CreationDate		:	
*		Author				:	
*		Design				:	Jaiwin
		This jsp used to Process and return result for serviceDashboardConfig Page.
***********************************************************************************/
%>
<%@ taglib prefix = "egui" uri="../WEB-INF/eg-taglib.tld" %> 
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.egurkha.util.*" %>
<%@ page import = "com.egurkha.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "egurkha.reporter.ErInfo"%>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.egurkha.monitor.ServicesDashboardBean"%>
<%@ page import = "com.eg.EgConfigFilesSync"%>
<%@ page import="com.eg.EgTopoInfo" %>
<%@ page import = "com.eg.EgGroupInfo"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import="com.egurkha.util.EgSorter"%>
<%@ page import="com.eg.UpdateAndTransmitTrendInfo" %>
<%@ page import = "com.eg.EgAggregateInfo"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.monitor.VmDashboardHelper"%>
<%@ page import = "egurkha.reporter.ErUserData"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "com.egurkha.monitor.EgMonRemoteScriptingBean"%>
<%@ page import = "com.egurkha.monitor.VMDesktopBean"%>
<%@ page import = "com.egurkha.admin.AuditLogThread"%>
<%@ page import = "com.eg.IniFile"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="net.sf.json.*"%>

<%

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

	String sessionID = session.getId();
	UserRegistry ur = UserRegistry.getInstance();
	User user = ur.getUser(sessionID);
	EgUserRole userRole = null;
	boolean isAllCompAccess=false;
	EgMonRemoteScriptingBean bean = null;
	String userName = "admin";
	EgGroupInfo groupInfo = new EgGroupInfo();
	EgTopoInfo topoInfo = new EgTopoInfo("manager");
	String installdir = EgInstallInfo.getInstallDir();
	IniFile in = new IniFile(installdir+"/manager/config/eg_endUserDetails.ini",true);
	IniFile in_keyUser = new IniFile(installdir+"/manager/config/eg_endKeyUserDetails.ini",true);
	String Limits_to=in.getValue("END_USER_DASHBOARD_SETTINGS","Default");
	String refreshFrequency=in.getValue("END_USER_DASHBOARD_SETTINGS","Refresh frequency");
	String strEGManagerUser=in.getValue("END_USER_DASHBOARD_SETTINGS","eGManagerUser");
	strEGManagerUser=(strEGManagerUser==null || strEGManagerUser.trim().length()==0)?"false":strEGManagerUser;
	boolean isEGManagerUser = strEGManagerUser.equalsIgnoreCase("true")?true:false;
	String fromAdmin = request.getParameter("fromAdmin");
	String userType = request.getParameter("userType");

	if(user==null)
	{
		String login_user = "";
		if(isEGManagerUser)
			login_user = request.getParameter("user");

		userName=(login_user==null || login_user.trim().length()==0)?"admin":login_user;
		ErUserData userData = new ErUserData(userName,false);
		if(userData==null)
		{
			userName="admin";
			userData = new ErUserData(userName,false);
			bean = new EgMonRemoteScriptingBean(userData);
			user = userData.usr;
		}
		else if(userData!=null)
		{
			user = userData.usr;
			bean = new EgMonRemoteScriptingBean(userData);
		}

		if(user!=null)
		{
			userRole = user.getUserRole();
			isAllCompAccess = userRole.hasAllComponentAccess();
		}
	}
	else if(user!=null)
	{
		userName = user.getLoginID();
		bean = new EgMonRemoteScriptingBean(userName);

		userRole = user.getUserRole();
		isAllCompAccess = userRole.hasAllComponentAccess();
	}

	boolean isOnlyVMAssigned=false;
	boolean isVMAssigned=false;
	if(user!=null && user.isOnlyVMAssigned() && (!user.isVMAssigned()) && user.getOnlyVMs().size()>0 && userType!=null && userType.equalsIgnoreCase("VDI"))
	{
		isOnlyVMAssigned=true;
	}
	else if(user!=null && (!user.isOnlyVMAssigned()) && user.isVMAssigned() && user.getOnlyVMs().size()>0 && userType!=null && userType.equalsIgnoreCase("VDI"))
	{
		isVMAssigned=true;
	}
	else if(user!=null && user.isOnlyVMAssigned() && user.isVMAssigned() && user.getOnlyVMs().size()>0 && userType!=null && userType.equalsIgnoreCase("VDI"))
	{
		isOnlyVMAssigned=true;
		isVMAssigned=true;
	}
	/*if(user==null){
		ErUserData userData = new ErUserData(userName,false);
		bean = new EgMonRemoteScriptingBean(userData);
		user = userData.usr;
	}*/
	IniUI ui = (IniUI)com.egurkha.ini.IniUI.getInstance();
	
	String thisLanguage = ui.getDefaultLanguage();
	String user_name="";
	if (user!=null)
	{
		String userLang = user.getLanguage();
		user_name=user.getLoginID();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	//EgAggregateInfo aggInfo=new EgAggregateInfo("manager");
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	JSONObject json = new JSONObject();
	JSONObject testJson = new JSONObject();
	
	String loadTest = request.getParameter("loadTest");
	String addOrDelete = request.getParameter("addOrDelete");
	String loadMeasure = request.getParameter("loadMeasure");
	String tableType = request.getParameter("tableType");
	String loadDDColumns = request.getParameter("loadDDColumns");
	String processName = request.getParameter("processName");
	String processUnit = request.getParameter("processUnit");
	String limit = request.getParameter("limit");
	String refreshFreq = request.getParameter("refreshFreq");
	String enabledUsersStr = request.getParameter("enabledUsers");
	enabledUsersStr=(enabledUsersStr==null || enabledUsersStr.trim().length()==0)?"":enabledUsersStr;

	String saveLimit = request.getParameter("saveLimit");
	String saveLimitValue = request.getParameter("saveLimitValue");
	String hidePanel = request.getParameter("hidePanelLog");
	if(hidePanel!=null && hidePanel.trim().length()>0 && !hidePanel.equalsIgnoreCase("NULL"))
		hidePanel = com.egurkha.util.StringUtils.decodeSecurityChar(hidePanel);
	String showPanel = request.getParameter("showPanelLog");
	if(showPanel!=null && showPanel.trim().length()>0 && !showPanel.equalsIgnoreCase("NULL"))
		showPanel = com.egurkha.util.StringUtils.decodeSecurityChar(showPanel);
	String loadAssociateUsersOptions = request.getParameter("loadAssociateUsers");

	String loadFilterOptions = request.getParameter("loadFilterOptions");
	String loadRelatedInfo = request.getParameter("loadRelatedInfo");
	String loadRelatedSubInfo = request.getParameter("loadRelatedSubInfo");
	if(loadRelatedSubInfo == null || loadRelatedSubInfo.trim().length() == 0 || loadRelatedSubInfo.equals("null"))
		loadRelatedSubInfo = "All";

	String gatewayFilter = request.getParameter("gatewayFilter");
	if(gatewayFilter == null || gatewayFilter.trim().length() == 0 || gatewayFilter.equals("null"))
		gatewayFilter = "All";

	String detail = request.getParameter("detail");
	if(detail == null || detail.trim().length() == 0 || detail.equals("null"))
		detail = "componentType";
	String detailFor = request.getParameter("detailFor");
	if(detailFor != null && detailFor.trim().length() > 0 && detailFor.equalsIgnoreCase("All"))
		detailFor = "";
	boolean iscompComboPresent = false;
	ArrayList selCompList = new ArrayList();
	String compLen = request.getParameter("compLen");
	if(compLen != null && compLen.trim().length() > 0 && !compLen.equalsIgnoreCase("null"))
	{
		iscompComboPresent = true;
		int compLength = Integer.parseInt(compLen);
		for(int k=0;k<compLength;k++){
			String comp = request.getParameter("C"+k);
			if(comp!=null && comp.trim().length()>0 && !comp.equalsIgnoreCase("null"))
				selCompList.add(comp);
		}
	}


	boolean loadFilter = false;
	if(loadFilterOptions != null && loadFilterOptions.equalsIgnoreCase("true"))
		loadFilter = true;
	
	boolean loadAssociateUsers = false;
	if(loadAssociateUsersOptions != null && (loadAssociateUsersOptions.equalsIgnoreCase("true") || loadAssociateUsersOptions.equalsIgnoreCase("yes")))
		loadAssociateUsers = true;

	String test = request.getParameter("test");
	String measure = request.getParameter("measure");
	String displayName = request.getParameter("displayName");
	displayName=(displayName==null || displayName.trim().length()==0)?"":displayName.trim();
	displayName = com.egurkha.util.StringUtils.decodeSecurityChar(displayName);
	String isUpdate = request.getParameter("isUpdate");
	String isUpdateUser = request.getParameter("isUpdateUser");

	String showUserLocations = in.getValue("GEO_LOCATION_SETTINGS",userType+":ShowUserLocations");
	showUserLocations = (showUserLocations==null || showUserLocations.trim().length()==0)?"":showUserLocations;
	boolean isShowUserLocation = false;
	if(showUserLocations!=null && showUserLocations.trim().length()>0 && (showUserLocations.equalsIgnoreCase("true") || showUserLocations.equalsIgnoreCase("yes")))
	{
		isShowUserLocation = true;
	}
	ArrayList enableadList = new ArrayList();
	String enablead = in.getValue("END_USER_DASHBOARD_SETTINGS","EnableADGroup");

	if(enablead != null && enablead.trim().length() > 0){
		enableadList = com.egurkha.util.StringUtils.egTokenizer(enablead, ",", true,false,true);
	}
	boolean enableAd = false;
	if(userType != null && enableadList.contains(userType))
		enableAd = true;

	if(enableAd)
	{
		json.put("enableAdGroup",enableAd);
		try
		{
			VMDesktopBean vmDesk = new VMDesktopBean();
			Hashtable res = vmDesk.getAllAdDetails();
			if(res != null && res.containsKey("aduser")){
				Hashtable elments = (Hashtable)res.get("aduser");
				if(elments != null && elments.size() > 0){
					ArrayList keys = new ArrayList(elments.keySet());
					if(keys != null && keys.size() > 0)
					{
						JSONArray arr = new JSONArray();
						JSONObject ob = new JSONObject();
						ob.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						ob.put("valueField","All");

						arr.add(ob);
						for(int i=0;i<keys.size();i++)
						{
							String ad = (String)keys.get(i);

							ob = new JSONObject();
							ob.put("displayField",ad);
							ob.put("valueField",ad);

							arr.add(ob);
						}

						/*ob = new JSONObject();
						ob.put("displayField","Default");
						ob.put("valueField","default");
						arr.add(ob);*/
						json.put("AdGroup",arr);
					}
				}
			}
		}
		catch(Exception ee)
		{
			json.put("error",ee);
		}
	}

	boolean isFromGeo=false;
	String fromGeoStr = request.getParameter("fromGeo");
	if(fromGeoStr!=null && (fromGeoStr.equalsIgnoreCase("true") || fromGeoStr.equalsIgnoreCase("yes")))
	{
		isFromGeo=true;
	}


	if(loadFilter)
	{
		IniFile dashIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_dashboardConfig.ini",true);
		boolean isDetailsFromADOnly = false;
		String locStr = dashIni.getValue("USER_LOCATION_TEST_CONFIG",userType+":ShowLocationFromADOnly");
		if(locStr != null && locStr.trim().length() > 0 && (locStr.equalsIgnoreCase("true") || locStr.equalsIgnoreCase("yes"))){
			isDetailsFromADOnly = true;
		}
		String defaultFilter = in.getValue("END_USER_DASHBOARD_SETTINGS","defaultFilter");
		ArrayList subFilterList = null;
		String subFilter = in.getValue("END_USER_DASHBOARD_SETTINGS","subFilter");
		if(subFilter != null && subFilter.trim().length() > 0)
			subFilterList = com.egurkha.util.StringUtils.egTokenizer(subFilter, ",", true,false,true);

		

			JSONObject isEnableFilterJson = new JSONObject();
			String tmp_metrics = in.getValue("USER_DESKTOP_METRICS",userName+":"+userType);

			String tmp_metricsD = in.getValue("USER_DESKTOP_METRICS","DEFAULT_"+userType);
			String tmp_metricsT = in.getValue("USER_DESKTOP_METRICS",userType);
			if(tmp_metrics==null || tmp_metrics.trim().length()==0)
			{
				if(tmp_metricsD != null && tmp_metricsD.trim().length() > 0)
				{
					tmp_metrics = tmp_metricsD;
				}
				else
				{
					tmp_metrics = tmp_metricsT;
				}
			}

			if(isFromGeo)
			{
				tmp_metrics = tmp_metricsT;
			}

			ArrayList tmp_metricsList = new ArrayList();
			ArrayList filterList = new ArrayList();
			if(tmp_metrics != null && tmp_metrics.trim().length() > 0){
				tmp_metricsList = com.egurkha.util.StringUtils.egTokenizer(tmp_metrics, ",", true,false,true);
				if(tmp_metricsList != null && tmp_metricsList.size() > 0){
					for(int i=0;i<tmp_metricsList.size();i++){
						String met = (String)tmp_metricsList.get(i);
						if(met == null || met.trim().length() == 0)
							continue;

						ArrayList check = com.egurkha.util.StringUtils.egTokenizer(met, ":", true,false,true);
						if(check != null && check.size() ==2){
							String geoCheck = (String)check.get(0);
							String geoCheckValue = (String)check.get(1);

							if(geoCheck != null && geoCheck.trim().length()  > 0)
							{
								if(geoCheck.equalsIgnoreCase("GeoDetails") )
								{
									ArrayList valList = com.egurkha.util.StringUtils.egTokenizer(geoCheckValue, "~$~", true,false,true);
									//geoCheckValue = geoCheckValue.subtring(0,geoCheckValue.indexOf("~$~"));
									if(valList != null && valList.size() ==2){
										//ob2 = new JSONObject();
										//ob2.put("displayField",(String)valList.get(1));
										//ob2.put("valueField",(String)valList.get(0));
										filterList.add((String)valList.get(0));
									}
								}
							}
						}
					}
				}
			}
	
			
			boolean isdefaultFilter=false;
			boolean istmpSubFilter=false;
			boolean istmpnextSubFilter=false;
			if(filterList!=null && filterList.size()>0)
			{
				if(defaultFilter!=null && defaultFilter.length()>0 && filterList.contains(defaultFilter)){
					isdefaultFilter=true;
					
				}
			}
			
			isEnableFilterJson.put("isdefaultFilter",isdefaultFilter);

			if(subFilterList!=null && subFilterList.size()>0)
			{
				//for(int t=0;t<tmpSubFilList.size();t++)
				{
					String tmp_Sub_Val=(String)subFilterList.get(0);
					
					if(tmp_Sub_Val!=null && tmp_Sub_Val.length()>0 && filterList.contains(tmp_Sub_Val)){
						istmpSubFilter = true;
					}
					
					if(subFilterList.size()>1)
					{
						String tmp_Sub_Val_2=(String)subFilterList.get(1);
						if((istmpSubFilter) && tmp_Sub_Val_2!=null && tmp_Sub_Val_2.length()>0 && filterList.contains(tmp_Sub_Val_2)){
							
							istmpnextSubFilter=true;
						}
					}
				}
			}
			isEnableFilterJson.put("istmpSubFilter",istmpSubFilter);
			isEnableFilterJson.put("istmpnextSubFilter",istmpnextSubFilter);
			json.put("isEnableFilterJson",isEnableFilterJson);
		

		if(loadRelatedInfo == null || loadRelatedInfo.trim().length() == 0){
			List temp_listZone = user.getZones();
			List temp_listSegment  =  user.getSegments();
			List temp_listService  =  user.getServices();
			List temp_listComps = user.getServers(false);
			//Sorting Zones
			if (temp_listZone != null && temp_listZone.size() > 1)
			{
				EgSorter esort = new EgSorter(temp_listZone, 1);
				temp_listZone = esort.sort(1, "String", "asc");
			}
			//Sorting services
			if (temp_listService != null && temp_listService.size() > 1)
			{
				EgSorter esort = new EgSorter(temp_listService, 1);
				temp_listService = esort.sort(1, "String", "asc");
			}
			//Sorting Segments
			if (temp_listSegment != null && temp_listSegment.size() > 1)
			{
				EgSorter esort = new EgSorter(temp_listSegment, 1);
				temp_listSegment = esort.sort(1, "String", "asc");
			}
			if(isOnlyVMAssigned && isVMAssigned)
			{
				//temp_listComps.addAll(user.getOnlyVMServers());
			}
			else if(isOnlyVMAssigned)
			{
				temp_listComps = new LinkedList();
				//temp_listComps = user.getOnlyVMServers();
			}
			else if(isVMAssigned)
			{
				//temp_listComps.addAll(user.getOnlyVMServers());
			}
			
			String component = in.getValue("USER_TYPE_COMPONENTS",userType);

			String metrics = in.getValue("USER_DESKTOP_METRICS",userName+":"+userType);
			if(metrics == null || metrics.trim().length() == 0)
				metrics = in.getValue("USER_DESKTOP_METRICS",userType);

			
			JSONArray arr2 = new JSONArray();
			JSONObject ob2 = new JSONObject();
			ob2.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
			ob2.put("valueField","ALL");
			// diabled All options
			//arr2.add(ob2);

			

			if(isDetailsFromADOnly){
				ArrayList metricsList = new ArrayList();
				if(metrics != null && metrics.trim().length() > 0){
					metricsList = com.egurkha.util.StringUtils.egTokenizer(metrics, ",", true,false,true);
					if(metricsList != null && metricsList.size() > 0){
						for(int i=0;i<metricsList.size();i++){
							String met = (String)metricsList.get(i);
							if(met == null || met.trim().length() == 0)
								continue;

							ArrayList check = com.egurkha.util.StringUtils.egTokenizer(met, ":", true,false,true);
							if(check != null && check.size() ==2){
								String geoCheck = (String)check.get(0);
								String geoCheckValue = (String)check.get(1);

								if(geoCheck != null && geoCheck.trim().length()  > 0)
								{
									if(geoCheck.equalsIgnoreCase("GeoDetails") )
									{
										ArrayList valList = com.egurkha.util.StringUtils.egTokenizer(geoCheckValue, "~$~", true,false,true);
										//geoCheckValue = geoCheckValue.subtring(0,geoCheckValue.indexOf("~$~"));
										if(valList != null && valList.size() ==2){
											ob2 = new JSONObject();
											ob2.put("displayField",(String)valList.get(1));
											ob2.put("valueField",(String)valList.get(0));
											arr2.add(ob2);
										}
									}
								}

							}
						}
					}
				}
			}
			else{
				Hashtable infoSes = (Hashtable)session.getAttribute(userType+"InfoSession");
				if(infoSes != null && infoSes.size() > 0 && defaultFilter != null && infoSes.containsKey(defaultFilter)){
					Set set = (HashSet)infoSes.get(defaultFilter);
					ArrayList list = new ArrayList(set);
					if(list != null && list.size() > 0){
						ob2.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						ob2.put("valueField","All");
						arr2.add(ob2);
						Collections.sort(list);
						for(int p=0;p<list.size();p++){
							String det = (String)list.get(p);
							ob2 = new JSONObject();
							ob2.put("displayField",det);
							ob2.put("valueField",det);
							arr2.add(ob2);
						}
						json.put("Searchs_label",defaultFilter);
					}
				}

				if(subFilterList != null && subFilterList.size() > 0){
					if(subFilterList.size() == 1){
						json.put("Searchs_SubFilterlabel1",(String)subFilterList.get(0));
					}
					else if(subFilterList.size() > 1){
						json.put("Searchs_SubFilterlabel1",(String)subFilterList.get(0));
						json.put("Searchs_SubFilterlabel2",(String)subFilterList.get(1));
					}

					if(infoSes == null || infoSes.size() == 0)
						json.put("Searchs_label",defaultFilter);
				}
				else if(infoSes != null && infoSes.size() > 0 && infoSes.containsKey("Filters")){
					Set filset = (HashSet)infoSes.get("Filters");
					ArrayList list1 = new ArrayList(filset);
					list1.remove("Gateway");
					if(list1 != null && list1.size() == 2)
						json.put("Searchs_SubFilterlabel1",(String)list1.get(1));
					else if(list1 != null && list1.size() > 2){
						json.put("Searchs_SubFilterlabel1",(String)list1.get(1));
						json.put("Searchs_SubFilterlabel2",(String)list1.get(2));
					}
				}
				else{
					String groupByParam = in.getValue("LOC_USER_DESKTOP_METRICS",userType+":GroupBy");
					if(groupByParam != null && groupByParam.trim().length() > 0){
						ArrayList groupByList = com.egurkha.util.StringUtils.egTokenizer(groupByParam, ",", true,false,true);
						if(groupByList != null && groupByList.size() == 2){
							json.put("Searchs_label",(String)groupByList.get(0));
							json.put("Searchs_SubFilterlabel1",(String)groupByList.get(1));
						}
						else if(groupByList != null && groupByList.size() > 2){
							json.put("Searchs_label",(String)groupByList.get(0));
							json.put("Searchs_SubFilterlabel1",(String)groupByList.get(1));
							json.put("Searchs_SubFilterlabel2",(String)groupByList.get(2));
						}
					}
				}
			}

			ArrayList compTypeList = new ArrayList();
			if(component != null && component.trim().length() > 0){
				compTypeList = com.egurkha.util.StringUtils.egTokenizer(component, ",", true,false,true);
			}
			
			boolean isServicePresent = false;
			boolean isZonePresent = false;
			boolean isSegmentPresent = false;
			
			
			JSONArray arr = new JSONArray();
			JSONObject ob = new JSONObject();
			
			if(temp_listZone != null && temp_listZone.size() > 0){
				for(int l=0;l<temp_listZone.size();l++){
					String zone1 = (String) temp_listZone.get(l);
					List temp_zoneComps = groupInfo.getAllComponentsUnderZone(zone1,true);
					if(temp_zoneComps != null && temp_zoneComps.size() > 0){
						for(int p=0;p<temp_zoneComps.size();p++){
							String compType = (String)temp_zoneComps.get(p);
							if(compType != null && compType.indexOf(":") != -1)
								compType = compType.substring(0,compType.indexOf(":"));

							if(compTypeList != null && compTypeList.contains(compType))
							{
								isZonePresent = true;
								ob = new JSONObject();
								ob.put("displayField",zone1);
								ob.put("valueField",zone1);
								arr.add(ob);
								if(detailFor == null || detailFor.trim().length() == 0)
									detailFor = zone1;
								break;
							}
						}
					}
				}
			}
			json.put("zone",arr);

			JSONArray compt_arr = new JSONArray();
			JSONObject objt = new JSONObject();
			if(userType!=null && (userType.equalsIgnoreCase("VDI") || userType.equalsIgnoreCase("ESX") || userType.equalsIgnoreCase("VCDataStore")))
			{
				if(isOnlyVMAssigned && isVMAssigned)
				{
					objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
					objt.put("valueField","All");
					compt_arr.add(objt);
					objt = new JSONObject();
					objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
					objt.put("valueField","Virtual_Machine");
				}
				else if(isOnlyVMAssigned)
				{
					objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
					objt.put("valueField","Virtual_Machine");
				}
				else if(isVMAssigned)
				{
					objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
					objt.put("valueField","All");
					compt_arr.add(objt);
					objt = new JSONObject();
					objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
					objt.put("valueField","Virtual_Machine");
				}
				else
				{
					objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
					objt.put("valueField","All");
				}
				compt_arr.add(objt);
			}
			
			ArrayList uniqueType = new ArrayList();
			Hashtable comp_hash = new Hashtable();
			
			List sortListComps = new ArrayList();
			Hashtable compHashSort = new Hashtable();
			for(int l=0;l<temp_listComps.size();l++)
			{
				String compDetails = (String)temp_listComps.get(l);
				String compDetails_type = compDetails.substring(0,compDetails.indexOf(":"));
				String compDetails_Name = compDetails.substring(compDetails.indexOf(":")+1);
				if(compTypeList != null && compTypeList.contains(compDetails_type))
				{
					if(comp_hash.containsKey(compDetails_type))
					{
						ArrayList ele = (ArrayList)comp_hash.get(compDetails_type);
						ele.add(compDetails);
						comp_hash.put(compDetails_type,ele);
					}
					else
					{
						ArrayList ele = new ArrayList();
						ele.add(compDetails);
						comp_hash.put(compDetails_type,ele);
					}
					if(!uniqueType.contains(compDetails_type))
					{
						sortListComps.add(mappingInfo.getComponentTypeDescription(compDetails_type));
						compHashSort.put(mappingInfo.getComponentTypeDescription(compDetails_type),compDetails_type);
						uniqueType.add(compDetails_type);
						if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
							detailFor = compDetails_type;
					}
				}
			}
			//Sorting Compponents 
			if (sortListComps != null && sortListComps.size() > 1)
			{
				EgSorter esort = new EgSorter(sortListComps, 1);
				sortListComps = esort.sort(1, "String", "asc");
			}
			if(sortListComps != null && sortListComps.size()>0 && compHashSort != null && compHashSort.size()>0)
			{
				for(int c=0;c<sortListComps.size();c++)
				{
					String compDispName = (String)sortListComps.get(c);
					if(compHashSort.containsKey(compDispName))
					{
						String compType = (String)compHashSort.get(compDispName);
						objt = new JSONObject();
						objt.put("displayField",compDispName);
						objt.put("valueField",compType);
						compt_arr.add(objt);
					}
				}
			}
			json.put("componentType",compt_arr);
			
			JSONArray comp_arr = null;
			JSONObject comp_obj = null;
			Iterator it = comp_hash.entrySet().iterator();
			JSONArray compNamesArr = new JSONArray();
			JSONArray compNames = new JSONArray();
			JSONObject compNames_obj = new JSONObject();
			compNames_obj.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
			compNames_obj.put("valueField","All");
			compNames.add(compNames_obj);
			while(it.hasNext())
			{
				comp_arr = new JSONArray();
				comp_obj = new JSONObject();
				comp_obj.put("displayField",mappingInfo.getTextDescription("monitor.home..All"));
				comp_obj.put("valueField","All");
				comp_arr.add(comp_obj);
				Map.Entry en = (Map.Entry)it.next();
				String key = (String)en.getKey();
				ArrayList valueList = (ArrayList)en.getValue();
				if(valueList != null && valueList.size() > 0)
				{
					for(int l=0;l<valueList.size();l++)
					{
						String ele = (String)valueList.get(l);
						String c_comp = ele.substring(ele.indexOf(":")+1);
						if(c_comp.toLowerCase().indexOf(":null") != -1)
							c_comp = c_comp.substring(0,c_comp.indexOf(":"));

						comp_obj = new JSONObject();
						comp_obj.put("displayField",c_comp);
						comp_obj.put("valueField",ele);
						comp_arr.add(comp_obj);
						compNames_obj.put("displayField",c_comp);
						compNames_obj.put("valueField",ele);
						compNames.add(compNames_obj);
					}
					compNamesArr.add(key);
					json.put(key,comp_arr);
				}
			}
			json.put("compNamesArr",compNamesArr);
			json.put("compNames",compNames);
			if(selCompList != null && selCompList.size() > 0){
				JSONArray comp_arr1 = new JSONArray();
				JSONObject comp_obj1 = null;
				for(int l=0;l<selCompList.size();l++)
				{
					String ele = (String)selCompList.get(l);
					String c_comp = ele.substring(ele.indexOf(":")+1);
					if(c_comp.toLowerCase().indexOf(":null") != -1)
						c_comp = c_comp.substring(0,c_comp.indexOf(":"));

					comp_arr1.add(ele);
				}
				json.put("compNamesSelected",comp_arr1);
			}

			JSONArray serarr = new JSONArray();
			JSONObject serob = new JSONObject();

			if(temp_listService != null && temp_listService.size() > 0){
				for(int l=0;l<temp_listService.size();l++){
					String serv = (String) temp_listService.get(l);
					
					List temp_serviceComps = topoInfo.getComponentsForSite(serv);
					if(temp_serviceComps != null && temp_serviceComps.size() > 0){
						for(int p=0;p<temp_serviceComps.size();p++){
							String ser_comp = (String)temp_serviceComps.get(p);
							ser_comp = ser_comp.substring(ser_comp.lastIndexOf(":")+1);

							if(compTypeList != null && compTypeList.contains(ser_comp))
							{
								isServicePresent = true;
								serob = new JSONObject();
								serob.put("displayField",serv);
								serob.put("valueField",serv);
								if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
									detailFor = serv;
								serarr.add(serob);
								break;
							}
						}
					}
				}
			}
			
			json.put("service",serarr);

			JSONArray segarr = new JSONArray();
			JSONObject segob = new JSONObject();
			//segob.put("displayField","All");
			//segob.put("valueField","All");
			//segarr.add(segob);

			if(temp_listSegment != null && temp_listSegment.size() > 0){
				for(int l=0;l<temp_listSegment.size();l++){
					String serv = (String) temp_listSegment.get(l);
					
					List temp_serviceComps = topoInfo.getComponentsForSegment(serv);
					if(temp_serviceComps != null && temp_serviceComps.size() > 0){
						for(int p=0;p<temp_serviceComps.size();p++){
							String ser_comp = (String)temp_serviceComps.get(p);
							ser_comp = ser_comp.substring(ser_comp.lastIndexOf(":")+1);

							if(compTypeList != null && compTypeList.contains(ser_comp))
							{
								isSegmentPresent = true;
								segob = new JSONObject();
								segob.put("displayField",serv);
								segob.put("valueField",serv);
								segarr.add(segob);
								if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
									detailFor = serv;

								break;
							}
						}
					}
				}
			}
			
			json.put("segment",segarr);
			json.put("detailFor",detailFor);
			
			JSONArray total_arr = new JSONArray();
			JSONObject total = new JSONObject();
			
			if(userType!=null && (userType.equalsIgnoreCase("VDI")||userType.equalsIgnoreCase("ESX")))
			{
				total.put("displayField",mappingInfo.getTextDescription("monitor.common.Component Type"));
				total.put("valueField","componentType");
			}
			else
			{
				total.put("displayField",mappingInfo.getTextDescription("monitor.common.Component"));
				total.put("valueField","componentType");
			}
			
			total_arr.add(total);
			
			if(isServicePresent)
			{
				total = new JSONObject();
				total.put("displayField","Service");
				total.put("valueField","service");
				total_arr.add(total);
			}

			if(isSegmentPresent)
			{
				total = new JSONObject();
				total.put("displayField","Segment");
				total.put("valueField","segment");
				total_arr.add(total);
			}

			if(isZonePresent)
			{
				total = new JSONObject();
				total.put("displayField","Zone");
				total.put("valueField","zone");
				total_arr.add(total);
			}
			json.put("total_arr",total_arr);
			json.put("total_select",detail);
			json.put("Searchs",arr2);

			JSONArray priorityArr = new JSONArray();
			JSONObject priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
			priorityObj.put("valueField","All");
			priorityArr.add(priorityObj);
			
			priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Critical"));
			priorityObj.put("valueField","HIGH");
			priorityArr.add(priorityObj);
			
			priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Major"));
			priorityObj.put("valueField","INTERMEDIATE");
			priorityArr.add(priorityObj);

			priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Minor"));
			priorityObj.put("valueField","LOW");
			priorityArr.add(priorityObj);

			priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Unknown"));
			priorityObj.put("valueField","UNKNOWN");
			priorityArr.add(priorityObj);

			priorityObj = new JSONObject();
			priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Normal"));
			priorityObj.put("valueField","GOOD");
			priorityArr.add(priorityObj);
			if(priorityArr!=null)
				json.put("priorities",priorityArr);

			JSONArray gatewayArr = new JSONArray();
			JSONObject gatewayObj = new JSONObject();
			gatewayObj.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
			gatewayObj.put("valueField","All");
			gatewayArr.add(gatewayObj);
			
			gatewayObj = new JSONObject();
			gatewayObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Internal"));
			gatewayObj.put("valueField","Internal");
			gatewayArr.add(gatewayObj);
			
			gatewayObj = new JSONObject();
			gatewayObj.put("displayField",mappingInfo.getTextDescription("monitor.home.External"));
			gatewayObj.put("valueField","External");
			gatewayArr.add(gatewayObj);

			if(gatewayArr!=null)
				json.put("gateways",gatewayArr);
		}
		else
		{
			Hashtable infoSes = (Hashtable)session.getAttribute(userType+"InfoSession");
			Hashtable statesList = (Hashtable)session.getAttribute("statesList");
			if(session!=null)
				session.removeAttribute("statesList");
			json.put("Searchs_label",defaultFilter);
			if(subFilterList != null && subFilterList.size() > 0){
				if(subFilterList.size() == 1){
					loadRelatedInfo = (loadRelatedInfo != null && loadRelatedInfo.equalsIgnoreCase("All"))?(String)subFilterList.get(0):loadRelatedInfo.trim();
					json.put("Searchs_SubFilterlabel1",(String)subFilterList.get(0));
				}
				else if(subFilterList.size() > 1){
					loadRelatedInfo = (loadRelatedInfo != null && loadRelatedInfo.equalsIgnoreCase("All"))?(String)subFilterList.get(0):loadRelatedInfo.trim();
					loadRelatedSubInfo = (loadRelatedSubInfo != null && loadRelatedSubInfo.equalsIgnoreCase("All"))?(String)subFilterList.get(1):loadRelatedSubInfo.trim();
					json.put("Searchs_SubFilterlabel1",(String)subFilterList.get(0));
					json.put("Searchs_SubFilterlabel2",(String)subFilterList.get(1));
				}
			}
			else if(infoSes != null && infoSes.containsKey("Filters")){
				Set filset = (HashSet)infoSes.get("Filters");
				ArrayList list1 = new ArrayList(filset);
				list1.remove("Gateway");
				if(list1 != null && list1.size() == 2){
					loadRelatedInfo = (String)list1.get(1);
					json.put("Searchs_SubFilterlabel1",(String)list1.get(1));
				}
				else if(list1 != null && list1.size() > 2){
					loadRelatedInfo = (loadRelatedInfo != null && loadRelatedInfo.equalsIgnoreCase("All"))?(String)list1.get(1):loadRelatedInfo;
					loadRelatedSubInfo = (loadRelatedSubInfo != null && loadRelatedSubInfo.equalsIgnoreCase("All"))?(String)list1.get(2):loadRelatedSubInfo;
					json.put("Searchs_SubFilterlabel1",(String)list1.get(1));
					json.put("Searchs_SubFilterlabel2",(String)list1.get(2));
				}
			}
			if(infoSes != null && loadRelatedInfo != null && infoSes.containsKey(loadRelatedInfo)){
				Set set = (HashSet)infoSes.get(loadRelatedInfo);
				ArrayList list = new ArrayList(set);
				if(list != null && list.size() > 0){
					JSONArray arr = new JSONArray();
					JSONObject ob = new JSONObject();
					if(list.size() > 1){
						ob.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						ob.put("valueField","All");
						arr.add(ob);
					}
					Collections.sort(list);
					for(int p=0;p<list.size();p++){
						String det = (String)list.get(p);
						ob = new JSONObject();
						ob.put("displayField",det);
						ob.put("valueField",det);
						arr.add(ob);
					}
					json.put("otherInfos",arr);

					if(loadRelatedSubInfo == null || loadRelatedSubInfo.trim().length() == 0 || loadRelatedSubInfo.equalsIgnoreCase("undefined") || loadRelatedSubInfo.equalsIgnoreCase("null"))
						loadRelatedSubInfo = (String)list.get(0);
				}
			}

			if(infoSes != null && loadRelatedSubInfo != null && infoSes.containsKey(loadRelatedSubInfo)){
				Set set = (HashSet)infoSes.get(loadRelatedSubInfo);
				ArrayList list = new ArrayList(set);
				if(list != null && list.size() > 0){
					JSONArray arr = new JSONArray();
					JSONObject ob = new JSONObject();
					if(list.size() > 1){
						ob.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						ob.put("valueField","All");
						arr.add(ob);
					}
					Collections.sort(list);
					for(int p=0;p<list.size();p++){
						String det = (String)list.get(p);
						ob = new JSONObject();
						ob.put("displayField",det);
						ob.put("valueField",det);
						arr.add(ob);
					}
					json.put("otherSubInfos",arr);
				}
			}

			if(infoSes != null && gatewayFilter != null && infoSes.containsKey(gatewayFilter)){
				Set set = (HashSet)infoSes.get(gatewayFilter);
				ArrayList list = new ArrayList(set);
				if(list != null && list.size() > 0){
					JSONArray arr = new JSONArray();
					JSONObject ob = new JSONObject();
					if(list.size() > 1){
						ob.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						ob.put("valueField","All");
						arr.add(ob);
					}
					Collections.sort(list);
					for(int p=0;p<list.size();p++){
						String det = (String)list.get(p);
						ob = new JSONObject();
						if(det!=null && det.equalsIgnoreCase("Internal"))
						{
							ob.put("displayField",mappingInfo.getTextDescription("monitor.home.Internal"));
							ob.put("valueField","Internal");
						}
						else if(det!=null && det.equalsIgnoreCase("External"))
						{
							ob.put("displayField",mappingInfo.getTextDescription("monitor.home.External"));
							ob.put("valueField","External");
						}
						arr.add(ob);
					}

					if(arr!=null)
						json.put("gateways",arr);
				}
			}

			if(statesList!=null && statesList.size()>0)
			{
				JSONArray priorityArr = new JSONArray();
				JSONObject priorityObj = new JSONObject();
				Set stateKeys = statesList.keySet();
				ArrayList stateKeysList = new ArrayList(stateKeys);
				priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
				priorityObj.put("valueField","All");
				priorityArr.add(priorityObj);
				for(int s=0;s<stateKeysList.size();s++)
				{
					String state = (String)stateKeysList.get(s);
					if(state!=null && state.equalsIgnoreCase("HIGH"))
					{
						priorityObj = new JSONObject();
						priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Critical"));
						priorityObj.put("valueField","HIGH");
						priorityArr.add(priorityObj);
					}
					else if(state!=null && state.equalsIgnoreCase("INTERMEDIATE"))
					{
						priorityObj = new JSONObject();
						priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Major"));
						priorityObj.put("valueField","INTERMEDIATE");
						priorityArr.add(priorityObj);
					}
					else if(state!=null && state.equalsIgnoreCase("LOW"))
					{
						priorityObj = new JSONObject();
						priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Minor"));
						priorityObj.put("valueField","LOW");
						priorityArr.add(priorityObj);
					}
					else if(state!=null && state.equalsIgnoreCase("UNKNOWN"))
					{
						priorityObj = new JSONObject();
						priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Unknown"));
						priorityObj.put("valueField","UNKNOWN");
						priorityArr.add(priorityObj);
					}
					else if(state!=null && state.equalsIgnoreCase("GOOD"))
					{
						priorityObj = new JSONObject();
						priorityObj.put("displayField",mappingInfo.getTextDescription("monitor.home.Normal"));
						priorityObj.put("valueField","GOOD");
						priorityArr.add(priorityObj);
					}
				}
				if(priorityArr!=null)
					json.put("priorities",priorityArr);
			}
			if(userType!=null && (userType.equalsIgnoreCase("VDI") || userType.equalsIgnoreCase("ESX")))
			{
				List temp_listZone = user.getZones();
				List temp_listSegment = user.getSegments();
				List temp_listService = user.getServices();
				List temp_listComps = user.getServers(false);
				if(isOnlyVMAssigned && isVMAssigned)
				{
					//temp_listComps.addAll(user.getOnlyVMServers());
				}
				else if(isOnlyVMAssigned)
				{
					temp_listComps = new LinkedList();
					//temp_listComps = user.getOnlyVMServers();
				}
				else if(isVMAssigned)
				{
					//temp_listComps.addAll(user.getOnlyVMServers());
				}
				
				String component = in.getValue("USER_TYPE_COMPONENTS",userType);
				ArrayList compTypeList = new ArrayList();
				if(component != null && component.trim().length() > 0){
					compTypeList = com.egurkha.util.StringUtils.egTokenizer(component, ",", true,false,true);
				}

				boolean isServicePresent = false;
				boolean isZonePresent = false;
				boolean isSegmentPresent = false;

				JSONArray arr = new JSONArray();
				JSONObject ob = new JSONObject();

				if(temp_listZone != null && temp_listZone.size() > 0){
					for(int l=0;l<temp_listZone.size();l++){
						String zone1 = (String) temp_listZone.get(l);
						List temp_zoneComps = groupInfo.getAllComponentsUnderZone(zone1,true);
						if(temp_zoneComps != null && temp_zoneComps.size() > 0){
							for(int p=0;p<temp_zoneComps.size();p++){
								String compType = (String)temp_zoneComps.get(p);
								if(compType != null && compType.indexOf(":") != -1)
									compType = compType.substring(0,compType.indexOf(":"));

								if(compTypeList != null && compTypeList.contains(compType))
								{
									isZonePresent = true;
									ob = new JSONObject();
									ob.put("displayField",zone1);
									ob.put("valueField",zone1);
									arr.add(ob);
									if(detailFor == null || detailFor.trim().length() == 0)
										detailFor = zone1;
									break;
								}
							}
						}
					}
				}
				json.put("zone",arr);

				JSONArray compt_arr = new JSONArray();
				JSONObject objt = new JSONObject();
				if(userType!=null && (userType.equalsIgnoreCase("VDI") || userType.equalsIgnoreCase("ESX")))
				{
					//objt.put("displayField","All");
					//objt.put("valueField","All");
					if(isOnlyVMAssigned && isVMAssigned)
					{
						objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						objt.put("valueField","All");
						compt_arr.add(objt);
						objt = new JSONObject();
						objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
						objt.put("valueField","Virtual_Machine");
					}
					else if(isOnlyVMAssigned)
					{
						objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
						objt.put("valueField","Virtual_Machine");
					}
					else if(isVMAssigned)
					{
						objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						objt.put("valueField","All");
						compt_arr.add(objt);
						objt = new JSONObject();
						objt.put("displayField",mappingInfo.getComponentTypeDescription("Virtual_Machine"));
						objt.put("valueField","Virtual_Machine");
					}
					else
					{
						objt.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						objt.put("valueField","All");
					}
					compt_arr.add(objt);
				}
				
				ArrayList uniqueType = new ArrayList();
				Hashtable comp_hash = new Hashtable();

				List sortListComps = new ArrayList();
				Hashtable compHashSort = new Hashtable();
				for(int l=0;l<temp_listComps.size();l++)
				{
					String compDetails = (String)temp_listComps.get(l);
					String compDetails_type = compDetails.substring(0,compDetails.indexOf(":"));
					String compDetails_Name = compDetails.substring(compDetails.indexOf(":")+1);
					if(compTypeList != null && compTypeList.contains(compDetails_type))
					{
						if(comp_hash.containsKey(compDetails_type))
						{
							ArrayList ele = (ArrayList)comp_hash.get(compDetails_type);
							ele.add(compDetails);
							comp_hash.put(compDetails_type,ele);
						}
						else
						{
							ArrayList ele = new ArrayList();
							ele.add(compDetails);
							comp_hash.put(compDetails_type,ele);
						}
						if(!uniqueType.contains(compDetails_type))
						{
							sortListComps.add(mappingInfo.getComponentTypeDescription(compDetails_type));
							compHashSort.put(mappingInfo.getComponentTypeDescription(compDetails_type),compDetails_type);
							uniqueType.add(compDetails_type);
							if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
								detailFor = compDetails_type;
						}
					}
				}
				//Sorting Compponents 
				
				if (sortListComps != null && sortListComps.size() > 1)
				{
					EgSorter esort = new EgSorter(sortListComps, 1);
					sortListComps = esort.sort(1, "String", "asc");
				}
				if(sortListComps != null && sortListComps.size()>0 && compHashSort != null && compHashSort.size()>0)
				{
					for(int c=0;c<sortListComps.size();c++)
					{
						String compDispName = (String)sortListComps.get(c);
						if(compHashSort.containsKey(compDispName))
						{
							String compType = (String)compHashSort.get(compDispName);
							objt = new JSONObject();
							objt.put("displayField",compDispName);
							objt.put("valueField",compType);
							compt_arr.add(objt);
						}
					}
				}
				json.put("componentType",compt_arr);
				
				JSONArray comp_arr = null;
				JSONObject comp_obj = null;
				Iterator it = comp_hash.entrySet().iterator();
				JSONArray compNamesArr = new JSONArray();
				while(it.hasNext())
				{
					Map.Entry en = (Map.Entry)it.next();
					String key = (String)en.getKey();
					ArrayList valueList = (ArrayList)en.getValue();
					if(valueList != null && valueList.size() > 0)
					{
						comp_arr = new JSONArray();
						comp_obj = new JSONObject();
						comp_obj.put("displayField",mappingInfo.getTextDescription("monitor.home.All"));
						comp_obj.put("valueField","All");
						comp_arr.add(comp_obj);
						for(int l=0;l<valueList.size();l++)
						{
							String ele = (String)valueList.get(l);
							String c_comp = ele.substring(ele.indexOf(":")+1);
							if(c_comp.toLowerCase().indexOf(":null") != -1)
								c_comp = c_comp.substring(0,c_comp.indexOf(":"));

							comp_obj = new JSONObject();
							comp_obj.put("displayField",c_comp);
							comp_obj.put("valueField",ele);
							comp_arr.add(comp_obj);
						}
						compNamesArr.add(key);
						json.put(key,comp_arr);
					}
				}
				json.put("compNamesArr",compNamesArr);
				
				if(selCompList != null && selCompList.size() > 0){
					JSONArray comp_arr1 = new JSONArray();
					JSONObject comp_obj1 = null;
					for(int l=0;l<selCompList.size();l++)
					{
						String ele = (String)selCompList.get(l);
						String c_comp = ele.substring(ele.indexOf(":")+1);
						if(c_comp.toLowerCase().indexOf(":null") != -1)
							c_comp = c_comp.substring(0,c_comp.indexOf(":"));

						comp_arr1.add(ele);
					}
					json.put("compNamesSelected",comp_arr1);
				}

				JSONArray serarr = new JSONArray();
				JSONObject serob = new JSONObject();

				if(temp_listService != null && temp_listService.size() > 0){
					for(int l=0;l<temp_listService.size();l++){
						String serv = (String) temp_listService.get(l);
						
						List temp_serviceComps = topoInfo.getComponentsForSite(serv);
						if(temp_serviceComps != null && temp_serviceComps.size() > 0){
							for(int p=0;p<temp_serviceComps.size();p++){
								String ser_comp = (String)temp_serviceComps.get(p);
								ser_comp = ser_comp.substring(ser_comp.lastIndexOf(":")+1);

								if(compTypeList != null && compTypeList.contains(ser_comp))
								{
									isServicePresent = true;
									serob = new JSONObject();
									serob.put("displayField",serv);
									serob.put("valueField",serv);
									if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
										detailFor = serv;
									serarr.add(serob);
									break;
								}
							}
						}
					}
				}
				json.put("service",serarr);

				JSONArray segarr = new JSONArray();
				JSONObject segob = new JSONObject();

				if(temp_listSegment != null && temp_listSegment.size() > 0){
					for(int l=0;l<temp_listSegment.size();l++){
						String serv = (String) temp_listSegment.get(l);
						
						List temp_serviceComps = topoInfo.getComponentsForSegment(serv);
						if(temp_serviceComps != null && temp_serviceComps.size() > 0){
							for(int p=0;p<temp_serviceComps.size();p++){
								String ser_comp = (String)temp_serviceComps.get(p);
								ser_comp = ser_comp.substring(ser_comp.lastIndexOf(":")+1);

								if(compTypeList != null && compTypeList.contains(ser_comp))
								{
									isSegmentPresent = true;
									segob = new JSONObject();
									segob.put("displayField",serv);
									segob.put("valueField",serv);
									segarr.add(segob);
									if(detail != null && detail.trim().length() > 0 && detail.equalsIgnoreCase("componentType") && (detailFor == null || detailFor.trim().length() == 0))
										detailFor = serv;
									break;
								}
							}
						}
					}
				}
				
				json.put("segment",segarr);
				json.put("detailFor",detailFor);
				
				JSONArray total_arr = new JSONArray();
				JSONObject total = new JSONObject();
				
				if(userType!=null && (userType.equalsIgnoreCase("VDI") || userType.equalsIgnoreCase("ESX")))
				{
					total.put("displayField",mappingInfo.getTextDescription("monitor.common.Component Type"));
					total.put("valueField","componentType");
				}
				else
				{
					total.put("displayField",mappingInfo.getTextDescription("monitor.common.Component"));
					total.put("valueField","componentType");
				}
				total_arr.add(total);
				
				if(isServicePresent)
				{
					total = new JSONObject();
					total.put("displayField","Service");
					total.put("valueField","service");
					total_arr.add(total);
				}

				if(isSegmentPresent)
				{
					total = new JSONObject();
					total.put("displayField","Segment");
					total.put("valueField","segment");
					total_arr.add(total);
				}

				if(isZonePresent)
				{
					total = new JSONObject();
					total.put("displayField","Zone");
					total.put("valueField","zone");
					total_arr.add(total);
				}

				json.put("total_arr",total_arr);
				json.put("total_select",detail);
				
			}
		}
	}
	else if(loadTest!=null && loadTest.equalsIgnoreCase("true") && addOrDelete!=null && addOrDelete.equalsIgnoreCase("add"))
	{
		String component = in.getValue("USER_TYPE_COMPONENTS",userType);
		List userServerTypes = user.getServerTypes();
		if(component!=null && component.indexOf(",")>-1)
		{
			StringTokenizer compTypeTok = new StringTokenizer(component,",");
			while(compTypeTok.hasMoreTokens())
			{
				String compTypeTokValue = compTypeTok.nextToken();
				if(userServerTypes.contains(compTypeTokValue))
				{
					component = compTypeTokValue;
					break;
				}
			}				
		}
		/*VmDashboardHelper vmDashHelper=new VmDashboardHelper(user);
		List components = vmDashHelper.getUserTypeComponentsComboData(userType);
		if(components!=null && components.size()>0)
		{
			component = (String)components.get(0);
		}*/

		if(component!=null && component.trim().length()>0)
		{
			if(tableType!=null && tableType.equalsIgnoreCase("dd"))
				//json.put("TEST",bean.getDDTestsJsonForEndUser(component,userType));
				json.put("TEST",bean.getDDTestsJsonForEndUserNew(component,userType));
			else
				json.put("TEST",bean.getInsideViewTestsForComponentTypeJSONForEndUser(component,userType));


		}

		String HideTableType="false";
		List ddSupportedUserTypesList = new ArrayList();
		String ddSupportedUserTypes[] = in.getVariables("USER_DESKTOP_TYPES_DD_TEST_CONFIG");
		if(ddSupportedUserTypes!=null && ddSupportedUserTypes.length>0)
			ddSupportedUserTypesList=Arrays.asList(ddSupportedUserTypes);
		if(!ddSupportedUserTypesList.contains(userType))
			HideTableType="true";

		if(HideTableType!=null && HideTableType.trim().length()>0)
			json.put("HideTableType",HideTableType);
		
	}	
	else if(loadTest!=null && loadTest.equalsIgnoreCase("true") && addOrDelete!=null && addOrDelete.equalsIgnoreCase("delete"))
	{
		
		json.put("TEST",bean.getTestsForDeleteComponentTypeJSONForEndUser("USER_DESKTOP_METRICS",userType));
		
	}
	else if(loadMeasure!=null && loadMeasure.equalsIgnoreCase("true") && addOrDelete!=null && addOrDelete.equalsIgnoreCase("add") && test!=null && !test.equalsIgnoreCase("undefined") && !test.equalsIgnoreCase("-1"))
	{
		if(tableType!=null && tableType.equalsIgnoreCase("dd"))
			json.put("MEASURE",bean.getDDMeasuresJSONEndUser(test));
		else
			json.put("MEASURE",bean.getMeasuresForTestForAddJSON(test,"USER_DESKTOP_METRICS",userType));
	}
	else if(loadMeasure!=null && loadMeasure.equalsIgnoreCase("true") && addOrDelete!=null && addOrDelete.equalsIgnoreCase("delete") && test!=null && !test.equalsIgnoreCase("undefined") && !test.equalsIgnoreCase("-1"))
	{
		json.put("MEASURE",bean.getMeasuresForTestForDeleteJSON("USER_DESKTOP_METRICS", userType, test));
		
	}
	else if(loadDDColumns!=null && loadDDColumns.equalsIgnoreCase("true") && test!=null && !test.equalsIgnoreCase("undefined") && !test.equalsIgnoreCase("-1"))
	{
		//json.put("DD_COLUMNS",bean.getDDColumnsJSONEndUser(test, measure, processName));
		json.put("DD_COLUMNS",bean.getDDColumnsJSONEndUser(test, measure, processName,"USER_DESKTOP_METRICS",userType,true));
	}
	else if(isUpdate!=null && isUpdate.equalsIgnoreCase("true"))
	{
		//String limit = request.getParameter("limit");
		//String refreshFreq = request.getParameter("refreshFreq");
		if(limit!=null && limit.trim().length()>0 && !limit.equalsIgnoreCase(Limits_to)){
			in.setValue("END_USER_DASHBOARD_SETTINGS","Default",limit.trim());
			in.saveFile();
		}	
		if(refreshFreq!=null && refreshFreq.trim().length()>0 && !refreshFreq.equalsIgnoreCase(refreshFrequency)){
			in.setValue("END_USER_DASHBOARD_SETTINGS","Refresh frequency",refreshFreq.trim());
			in.saveFile();
		}
		
		boolean isSuccess = true;
		String subject = "USER_DESKTOP_METRICS";
		String variable = userType;
		String testMeasureDisp = test+":"+measure+":"+displayName.trim();
		String testMeasure = test+":"+measure;
		if(tableType!=null && tableType.equalsIgnoreCase("dd"))
		{
			testMeasureDisp=test+":"+measure+":"+processName+":"+processUnit+":"+displayName.trim();
			testMeasure=test+":"+measure+":"+processName+":"+processUnit;
		}
		if(addOrDelete!=null && addOrDelete.equalsIgnoreCase("add"))
		{
			if(test!=null && test.trim().length()>0 && !test.equalsIgnoreCase("-1")){
				String defaultValues = in.getValue(subject,variable);
				boolean flag=true;
				if(defaultValues!=null && defaultValues.trim().length()>0 && !defaultValues.equals(""))
				{
					StringTokenizer values = new StringTokenizer(defaultValues,",");

					while(values.hasMoreTokens())
					{ 
						String value = values.nextToken();
						
						if(value!=null && !value.equals(""))
						{
							String tempTestMeasure = value.substring(0,value.lastIndexOf(":"));
							if(tempTestMeasure.equalsIgnoreCase(testMeasure))
							{
								flag=false;
								break;
							}
						}
					}

					if(flag){
						in.setValue(subject,variable,defaultValues.trim()+","+testMeasureDisp.trim());
						in.saveFile();
					}
					else
					{
						isSuccess = false;
					}
					
				}
				else{
					in.setValue(subject,variable,testMeasureDisp.trim());
					in.saveFile();
				}
			}
			
		}
		
		else if(addOrDelete!=null && addOrDelete.equalsIgnoreCase("delete"))
		{
			String defaultValues = in.getValue(subject,variable);
			String temp = "";
			boolean flag=false;
			boolean commaNeeded = false;
			if(defaultValues!=null && defaultValues.trim().length()>0 && !defaultValues.equals(""))
			{
				StringTokenizer values = new StringTokenizer(defaultValues,",");
				while(values.hasMoreTokens())
				{
					String value = values.nextToken();
					if(value!=null && !value.equals(""))
					{
						String tempTestMeasure = "";
						if(value.indexOf("#")>-1)
							tempTestMeasure = value.substring(0,value.lastIndexOf("#"));
						else
							tempTestMeasure = value.substring(0,value.lastIndexOf(":"));

						String tempDisplayName = value.substring(value.lastIndexOf(":")+1);

						String tempTestMeasureDisp = tempTestMeasure+":"+tempDisplayName.trim();

						if(!tempTestMeasure.equalsIgnoreCase(testMeasure))
						{
							temp += commaNeeded?","+tempTestMeasureDisp:tempTestMeasureDisp;
							commaNeeded = true;
						}							
					}
				}

				if(temp!=null && temp.length()>0)
				{
					in.setValue(subject,variable,temp.trim());
					in.saveFile();
				}
			}
		}

		if(isSuccess){
			/* code for auditlog starts */
			boolean auditFlag = false;
			boolean configFlag = false;
			boolean measureFlag = false;

			AuditLogThread auditLogThread = new AuditLogThread();
			if(fromAdmin!=null && fromAdmin.equalsIgnoreCase("true"))
			{
				auditLogThread.setValue("Category","Admin");
				auditLogThread.setValue("Module","Monitor Settings");
				auditLogThread.setValue("Activity","User Experience Dashboard");
			}
			else
			{
				auditLogThread.setValue("Category","Monitor");
				auditLogThread.setValue("Module","End User Dashboard Details");
				auditLogThread.setValue("Activity","Configuration Settings");
			}

			auditLogThread.setValue("User_id",user.getLoginID());
			auditLogThread.setValue("Host_ip",user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());

			auditFlag = true;
			configFlag = true;
			if(limit!=null && !limit.equalsIgnoreCase("null") && limit.trim().length()>0)
				auditLogThread.setCurrentValue("01~~Limit",limit);
			if(refreshFreq!=null && !refreshFreq.equalsIgnoreCase("null") && refreshFreq.trim().length()>0)
				auditLogThread.setCurrentValue("02~~Refresh Frequence",refreshFreq);
			if(addOrDelete!=null && addOrDelete.trim().length()>0)
			{
				if(fromAdmin!=null && !fromAdmin.equalsIgnoreCase("true"))
				{
					auditLogThread.setCurrentValue("03~~Add/Delete",addOrDelete);
				}
			}
			
			if(test!=null && !test.equalsIgnoreCase("null") && test.trim().length()>0 && !test.equals("-1"))
				auditLogThread.setCurrentValue("04~~Test","$test$:"+test);
			if(measure!=null  && !measure.equalsIgnoreCase("null") && measure.trim().length()>0 && !test.equals("-1") && !measure.equals("-1"))
				auditLogThread.setCurrentValue("05~~Measure","$measure$:"+test+":"+measure);

			if(displayName!=null && displayName.trim().length()>0)
			{
				auditLogThread.setCurrentValue("06~~Display Name",displayName.trim());
			}

			if(addOrDelete!=null && !addOrDelete.equalsIgnoreCase(""))
				addOrDelete = addOrDelete.equalsIgnoreCase("add")?"added":"deleted";

			if(configFlag && measureFlag)
				auditLogThread.setValue("Description","Configuration settings have been configured successfully");
			else if(measureFlag)
				auditLogThread.setValue("Description","Measures have been "+addOrDelete+" successfully");
			else if(fromAdmin!=null && fromAdmin.equalsIgnoreCase("true"))
				auditLogThread.setValue("Description","New measure has been added to User Experience Dashboard");
			else
				auditLogThread.setValue("Description","Configuration settings have been configured successfully");

			if(auditFlag)
				auditLogThread.sendItToDB();

			json.put("UPDATE","SUCCESS");
		}
		else
		{
			json.put("UPDATE","FAILED");
		}
	}
	else if(isUpdateUser!=null && isUpdateUser.equalsIgnoreCase("true"))
	{
		if(enabledUsersStr!=null && enabledUsersStr.trim().length()>0 )
		{
			in_keyUser.setValue(userType,"Users",enabledUsersStr.trim());
			in_keyUser.saveFile();

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

			AuditLogThread auditLogThread = new AuditLogThread();
			if(fromAdmin!=null && fromAdmin.equalsIgnoreCase("true"))
			{
				auditLogThread.setValue("Category","Admin");
				auditLogThread.setValue("Module","Monitor Settings");
				auditLogThread.setValue("Activity","Key User Experience Dashboard");
			}
			else
			{
				auditLogThread.setValue("Category","Monitor");
				auditLogThread.setValue("Module","Key User Experience Dashboard");
				auditLogThread.setValue("Activity","Configuration Settings");
			}

			auditLogThread.setValue("User_id",user.getLoginID());
			auditLogThread.setValue("Host_ip",user.getUserIP(session.getId()));
			auditLogThread.setValue("Session_id",session.getId());

			boolean auditFlag = true;

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

			if(hidden_Panels != null && shown_Panels != null && hidden_Panels.size()>0 && shown_Panels.size()>0){
				auditLogThread.setCurrentValue("01~~Show/Hide","Show/Hide");
				if(hidden_Panels!=null && hidden_Panels.size()>0){
					for(int k=0;k<hidden_Panels.size();k++){
						hiddenPanels = (String)hidden_Panels.get(k);
						auditLogThread.setCurrentValue("02~~Hidden Panels",hiddenPanels);
					}
				}

				if(shown_Panels!=null && shown_Panels.size()>0){
					for(int l=0;l<shown_Panels.size();l++){
						shownPanels = (String)shown_Panels.get(l);
						auditLogThread.setCurrentValue("03~~Shown Panels",shownPanels);
					}
				}
			}else{
				if(hidden_Panels!=null && hidden_Panels.size()>0){
					auditLogThread.setCurrentValue("01~~Show/Hide","Hidden");
					for(int k=0;k<hidden_Panels.size();k++){
						hiddenPanels = (String)hidden_Panels.get(k);
						auditLogThread.setCurrentValue("02~~Hidden Panels",hiddenPanels);
					}
				}

				if(shown_Panels!=null && shown_Panels.size()>0){
					auditLogThread.setCurrentValue("01~~Show/Hide","Shown");
					for(int l=0;l<shown_Panels.size();l++){
						shownPanels = (String)shown_Panels.get(l);
						auditLogThread.setCurrentValue("02~~Shown Panels",shownPanels);
					}
				}
			}

			if(auditFlag)
			{
				auditLogThread.setValue("Description","Configuration settings have been configured successfully");
				auditLogThread.sendItToDB();
			}

			json.put("UPDATE","SUCCESS");
		}
		else
			json.put("UPDATE","FAILED");
	}

	String isFromCtx = request.getParameter("fromctx");
	String vdiType = request.getParameter("vdiType");
	String moreOptions = request.getParameter("fromMoreOptions");
	String updateMoreOptions = request.getParameter("updateMoreOptions");
	String checkedVal = request.getParameter("checkedArr");
	String fromMoreGrid = request.getParameter("fromMoreGrid");
	String updateMoreGrid = request.getParameter("updateMoreGrid");
	String checkedVal1 = request.getParameter("checkedArr1");
	if(checkedVal1!=null && checkedVal1.trim().length()>0)
	{
		checkedVal1=com.egurkha.util.StringUtils.decodeSecurityChar(checkedVal1);
		checkedVal1=com.egurkha.util.StringUtils.replace(checkedVal1,"|sinquot|","'");
	}
	if(moreOptions!=null && moreOptions.trim().length()>0 && moreOptions.equalsIgnoreCase("true"))
	{
		String subject = "USER_DESKTOP_METRICS";
		String variable = userType;
		String defaultValues = in.getValue(subject,variable);
		String userValues ="";
		if(userName!=null && userName.trim().length()>0)
		{
			userValues = in.getValue(subject,userName+":"+userType);
		}
		if(userValues==null || userValues.trim().length()==0)
		{
			userValues = in.getValue(subject,"DEFAULT_"+userType);
		}
		if(isFromCtx!=null && isFromCtx.trim().length()>0 && isFromCtx.equalsIgnoreCase("true"))
		{
			if(vdiType!=null && vdiType.trim().length()>0 && vdiType.indexOf(":")!=-1)
				vdiType = vdiType.substring(0,vdiType.indexOf(":"));
			subject = "USER_DESKTOP_METRICS_VIEW";
			userValues = in.getValue(subject,userType+":"+vdiType);
		}
		JSONArray checkBoxArr = new JSONArray();
		JSONObject checkBoxJson = new JSONObject();
		
		JSONObject defaultJson = new JSONObject();
		defaultJson.put("displayField","User/Desktops");
		defaultJson.put("valueField","User/Desktops");
		defaultJson.put("disabled","true");
		defaultJson.put("checkField","true");
		checkBoxArr.add(defaultJson);

		defaultJson = new JSONObject();
		defaultJson.put("displayField","Host");
		defaultJson.put("valueField","Host");
		defaultJson.put("disabled","true");
		defaultJson.put("checkField","true");
		checkBoxArr.add(defaultJson);

		Hashtable checkHash =new Hashtable();
		Hashtable checkBox =new Hashtable();
		
		ArrayList keyList = new ArrayList();
		ArrayList default_value = new ArrayList();
		ArrayList user_value = new ArrayList();
		
		String measVal="";
		String tempMeasure="";
		String checked="true";
		if(defaultValues!=null && defaultValues.trim().length()>0)
		{
			default_value = com.egurkha.util.StringUtils.egTokenizer(defaultValues, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
		}
		if(userValues!=null && userValues.trim().length()>0)
		{
			user_value = com.egurkha.util.StringUtils.egTokenizer(userValues, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
		}
		if(default_value!=null && default_value.size()>0)
		{
			for(int k=0;k<default_value.size();k++)
			{
				measVal = (String)default_value.get(k);				
				if(userValues!=null && userValues.trim().length()>0)
				{
					if(measVal!=null && user_value!=null && user_value.contains(measVal))
						checked="true";
					else
						checked="false";
				}
				else
				{
					checked="true";
				}
				ArrayList valTokens = new ArrayList();
				ArrayList temp=new ArrayList();
				if(measVal!=null && measVal.trim().length()>0)
				{
					valTokens = com.egurkha.util.StringUtils.egTokenizer(measVal, ":",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(valTokens!=null && valTokens.size()==2)
					{
						tempMeasure = (String)valTokens.get(1);
						if(tempMeasure!=null && tempMeasure.trim().length()>0 && tempMeasure.indexOf("~$~")>-1)
						{
							ArrayList tmpMeasureList = com.egurkha.util.StringUtils.egTokenizer(tempMeasure, "~$~",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
							if(tmpMeasureList!=null && tmpMeasureList.size()>0)
							{
								String tempDispName = (String)tmpMeasureList.get(1);
								tempMeasure = tempDispName;
							}
						}
					}
					else if(valTokens!=null && valTokens.size()==3)
						tempMeasure = (String)valTokens.get(2);
					else if(valTokens!=null && valTokens.size()==5)
						tempMeasure = (String)valTokens.get(4);

					if(checkBox.size()==0)
					{
						temp=new ArrayList();
						temp.add(measVal);
						keyList.add(tempMeasure);
					}
					else if(checkBox.size()>0)
					{
						if(checkBox.containsKey(tempMeasure))
						{
							temp=(ArrayList)checkBox.get(new String(tempMeasure));
							temp.add(measVal);
						}
						else
						{
							temp=new ArrayList();
							temp.add(measVal);
							keyList.add(tempMeasure);
						}
					}
					if(tempMeasure!=null && tempMeasure.trim().length()>0 && temp!=null && temp.size()>0)
					{
						checkBox.put(tempMeasure,(ArrayList)temp);
						checkHash.put(tempMeasure,checked);
					}
				}
			}
			
			/*ArrayList user_temp=new ArrayList();
			if(user_value!=null && user_value.size()>0)
			{
				for(int x=0;x<user_value.size();x++)
				{
					String user_Meas = (String)user_value.get(x);
					user_temp.add(user_Meas);
					ArrayList count = com.egurkha.util.StringUtils.egTokenizer(user_Meas, ":",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(user_Meas!=null && default_value!=null && !default_value.contains(user_Meas))
					{
						if(count!=null && count.size()==3)
						{
							String temp_Meas = (String)count.get(2);
							checked="true";
							keyList.add(temp_Meas);
							
							if(temp_Meas!=null && temp_Meas.trim().length()>0 && user_temp!=null && user_temp.size()>0)
							{
								checkBox.put(temp_Meas,(ArrayList)user_temp);
								checkHash.put(temp_Meas,checked);
							}
						}
					}
				}
			}
			*/
			
			for(int m=0;m<keyList.size();m++)
			{
				String key = (String)keyList.get(m);
				checkBoxJson = new JSONObject();
				checkBoxJson.put("displayField",key);
				
				ArrayList value = (ArrayList)checkBox.get(key);
				JSONArray valAr = new JSONArray();
				for(int p=0;p<value.size();p++)
				{
					valAr.add(""+value.get(p));
				}
				String checkValue = (String)checkHash.get(key);
				checkBoxJson.put("valueField",valAr);
				checkBoxJson.put("checkField",checkValue);
				checkBoxArr.add(checkBoxJson);
			}
			json.put("moreOptions",checkBoxArr);
		}
		if(updateMoreOptions!=null && updateMoreOptions.equalsIgnoreCase("true"))
		{
			String checked_Values="";
			ArrayList checkedList = new ArrayList();
			if(checkedVal!=null && checkedVal.trim().length()>0)
			{
				checkedList = com.egurkha.util.StringUtils.egTokenizer(checkedVal, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			}
			if(checkedList!=null && checkedList.size()>0)
			{
				boolean isCountryAdded=false;
				boolean isRegionAdded=false;
				boolean isCityAdded=false;

				for(int k=0;k<checkedList.size();k++)
				{
					String checkStr=(String)checkedList.get(k);
					if(checkStr!=null && checkStr.length()>0)
					{
						if(checkStr.indexOf("Country_name")>-1)
							isCountryAdded=true;
						if(checkStr.indexOf("Region")>-1)
							isRegionAdded=true;
						if(checkStr.indexOf("City")>-1)
							isCityAdded=true;

						checked_Values += checkStr;
						if(k+1 != checkedList.size())
							checked_Values = checked_Values+',';
					}
				}

				if(isCountryAdded && (checked_Values.indexOf("GeoDetails:Country~$~Country")==-1))
					checked_Values = checked_Values +",GeoDetails:Country~$~Country";

				if(isRegionAdded && (checked_Values.indexOf("GeoDetails:Region~$~Region")==-1))
					checked_Values = checked_Values +",GeoDetails:Region~$~Region";

				if(isCityAdded && (checked_Values.indexOf("GeoDetails:City~$~City")==-1))
					checked_Values = checked_Values +",GeoDetails:City~$~City";
			}

			if(userName!=null && userType!=null && checked_Values!=null)
			{
				in.setValue(subject,userName+":"+userType,checked_Values);
				in.saveFile();
			}
		}
	}
	else if(saveLimit!=null && (saveLimit.equalsIgnoreCase("true") || saveLimit.equalsIgnoreCase("yes")) && saveLimitValue!=null && saveLimitValue.trim().length()>0)
	{
		String subject = "USER_DESKTOP_METRICS";
		//in.setValue("User_Default_Limits",userName+":"+userType,saveLimitValue);
		in.setValue("User_Default_Limits",userName,saveLimitValue.trim());
		in.saveFile();

		json.put("UPDATE","SUCCESS");

	}
	
	if(loadAssociateUsers)
	{
		List SelectedUserList = (List)session.getAttribute("SelectedUserList");
		//List AllUserList = (List)session.getAttribute("AllUserList");
		VMDesktopBean desktopObj = new VMDesktopBean();
		List AllUserList = (List)desktopObj.getTestsForHighProfileUsers(userType);
		if(AllUserList==null || AllUserList.size()==0)
			AllUserList = (List)session.getAttribute("AllUserList");


		JSONArray allUserJsonArr = new JSONArray();
		if(AllUserList!=null)
		{
			int aul=AllUserList.size();
			Collections.sort(AllUserList);
			for(int kk=0;kk<aul;kk++)
			{
				String user_name_str=(String)AllUserList.get(kk);
				if(user_name_str!=null && user_name_str.trim().length()>0)
				{
					JSONObject allUserJson = new JSONObject();
					allUserJson.put("displayField",user_name_str);
					allUserJson.put("valueField",user_name_str.toLowerCase());
					allUserJsonArr.add(allUserJson);
				}
			}
		}
		json.put("allUserList",allUserJsonArr);

		if(SelectedUserList!=null)
		{
			JSONArray selectedUserJsonArr = new JSONArray();
			int sul=SelectedUserList.size();
			Collections.sort(SelectedUserList);
			for(int kk=0;kk<sul;kk++)
			{
				String sel_user_name_str=(String)SelectedUserList.get(kk);
				if(sel_user_name_str!=null)
				{
					//JSONObject selUserJson = new JSONObject();
					//selUserJson.put("text",sel_user_name_str);
					//selUserJson.put("value",sel_user_name_str);
					//selUserJson.put(sel_user_name_str);
					selectedUserJsonArr.add(sel_user_name_str.toLowerCase());
				}
			}
			json.put("selectedUserList",selectedUserJsonArr);
		}
	}

	if (fromMoreGrid!=null && fromMoreGrid.trim().length()>0 && fromMoreGrid.equalsIgnoreCase("true"))
	{
		String subject = "USER_DESKTOP_METRICS";
		String variable = userType;
		String defaultValues = in.getValue(subject,"DEFAULT_"+variable);
		String userTypeValues= "";
		String userValues ="";
		if(userName!=null && userName.trim().length()>0)
		{
			userValues = in.getValue(subject,userName+":"+userType);
		}
		if(isFromCtx!=null && isFromCtx.trim().length()>0 && isFromCtx.equalsIgnoreCase("true"))
		{
			if(vdiType!=null && vdiType.trim().length()>0 && vdiType.indexOf(":")!=-1)
				vdiType = vdiType.substring(0,vdiType.indexOf(":"));
			subject = "USER_DESKTOP_METRICS_VIEW";
			userValues = in.getValue(subject,userType+":"+vdiType);
			defaultValues = in.getValue(subject,userType+":"+vdiType+"_DEFAULT");
		}
		else
		{
			userTypeValues= in.getValue(subject,variable);
		}
		JSONArray checkBoxArr1 = new JSONArray();
		JSONObject checkBoxJson1 = new JSONObject();
		JSONObject defaultJson1 = new JSONObject();
		defaultJson1.put("measName","User/Desktops");
		defaultJson1.put("orgName","User/Desktops");
		defaultJson1.put("disableVal","true");
		defaultJson1.put("checkVal",true);
		//defaultJson1.put("checkVal","<div><input type='checkbox' id='chk'  name='chk' checked disabled></div>");
		checkBoxArr1.add(defaultJson1);

		defaultJson1 = new JSONObject();
		defaultJson1.put("measName","Host");
		defaultJson1.put("orgName","Host");
		defaultJson1.put("disableVal","true");
		defaultJson1.put("checkVal",true);
		//defaultJson1.put("checkVal","<div><input type='checkbox' id='chk'  name='chk' checked disabled></div>");
		checkBoxArr1.add(defaultJson1);

		Hashtable checkHash =new Hashtable();
		Hashtable checkBox =new Hashtable();
		
		ArrayList keyList = new ArrayList();
		ArrayList default_value = new ArrayList();
		ArrayList user_value = new ArrayList();
		ArrayList user_Type_value = new ArrayList();
		
		String measVal="";
		String tempMeasure="";
		String checked="true";
		if (userValues!=null && userValues.trim().length()>0)
		{
			defaultValues = userValues+","+defaultValues;
		}

		if(defaultValues!=null && defaultValues.trim().length()>0)
		{
			default_value = com.egurkha.util.StringUtils.egTokenizer(defaultValues, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			
			ArrayList tempList = new ArrayList();
			if(default_value!=null && default_value.size()>0)
			{
				for(int k=0;k<default_value.size();k++)
				{
					String temp_measVal = (String)default_value.get(k);
					if(!tempList.contains(temp_measVal))
						tempList.add(temp_measVal);
				}
				default_value = new ArrayList(tempList);
			}
		}
		if(userValues!=null && userValues.trim().length()>0)
		{
			user_value = com.egurkha.util.StringUtils.egTokenizer(userValues, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
		}
		if(userTypeValues!=null && userTypeValues.trim().length()>0)
		{
			user_Type_value = com.egurkha.util.StringUtils.egTokenizer(userTypeValues, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
		}
		if(default_value!=null && default_value.size()>0)
		{
			for(int k=0;k<default_value.size();k++)
			{
				measVal = (String)default_value.get(k);
				if(userValues!=null && userValues.trim().length()>0)
				{
					if(measVal!=null && user_value!=null && user_value.contains(measVal))
						checked="true";
					else
						checked="false";
				}
				else
				{
					checked="true";
				}
				ArrayList valTokens = new ArrayList();
				ArrayList temp=new ArrayList();
				if(measVal!=null && measVal.trim().length()>0)
				{
					valTokens = com.egurkha.util.StringUtils.egTokenizer(measVal, ":",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(valTokens!=null && valTokens.size()==2)
					{
						tempMeasure = (String)valTokens.get(1);
						if(tempMeasure!=null && tempMeasure.trim().length()>0 && tempMeasure.indexOf("~$~")>-1)
						{
							ArrayList tmpMeasureList = com.egurkha.util.StringUtils.egTokenizer(tempMeasure, "~$~",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
							if(tmpMeasureList!=null && tmpMeasureList.size()>0)
							{
								String tempDispName = (String)tmpMeasureList.get(1);
								tempMeasure = tempDispName;
							}
						}
					}
					else if(valTokens!=null && valTokens.size()==3)
						tempMeasure = (String)valTokens.get(2);
					else if(valTokens!=null && valTokens.size()==5)
						tempMeasure = (String)valTokens.get(4);

					if(checkBox.containsKey(tempMeasure))
					{
						temp=(ArrayList)checkBox.get(new String(tempMeasure));
						temp.add(measVal);
					}
					else
					{
						temp=new ArrayList();
						temp.add(measVal);
						keyList.add(tempMeasure);
					}
					if(tempMeasure!=null && tempMeasure.trim().length()>0 && temp!=null && temp.size()>0)
					{
						if(checkHash.containsKey(tempMeasure))
						{
							String tmp_checked= (String)checkHash.get(tempMeasure);
							if(tmp_checked.equalsIgnoreCase("false") && checked.equalsIgnoreCase("true"))
								checkHash.put(tempMeasure,checked);
						}
						else
							checkHash.put(tempMeasure,checked);

						checkBox.put(tempMeasure,(ArrayList)temp);
					}
				}
			}

			ArrayList user_temp=new ArrayList();
			if(user_value!=null && user_value.size()>0)
			{
				for(int x=0;x<user_value.size();x++)
				{
					String user_Meas = (String)user_value.get(x);
					user_temp.add(user_Meas);
					ArrayList count = com.egurkha.util.StringUtils.egTokenizer(user_Meas, ":",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(user_Meas!=null && default_value!=null && !default_value.contains(user_Meas))
					{
						if(count!=null && count.size()==3)
						{
							String temp_Meas = (String)count.get(2);
							checked="true";
							keyList.add(temp_Meas);
							
							if(temp_Meas!=null && temp_Meas.trim().length()>0 && user_temp!=null && user_temp.size()>0)
							{
								checkBox.put(temp_Meas,(ArrayList)user_temp);
								checkHash.put(temp_Meas,checked);
							}
						}
					}
				}
			}
			if(user_Type_value!=null && user_Type_value.size()>0)
			{
				for(int x=0;x<user_Type_value.size();x++)
				{
					ArrayList user_Type_temp=new ArrayList();
					String user_Type_Meas = (String)user_Type_value.get(x);
					user_Type_temp.add(user_Type_Meas);
					ArrayList count = com.egurkha.util.StringUtils.egTokenizer(user_Type_Meas, ":",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
					if(user_Type_Meas!=null && default_value!=null && !default_value.contains(user_Type_Meas))
					{
						String temp_Meas="";
						checked="false";
						if(count!=null && count.size()==3)
						{
							temp_Meas = (String)count.get(2);
							//keyList.add(temp_Meas);
						}
						else if(count!=null && count.size()==5)
						{
							temp_Meas = (String)count.get(4);
							//keyList.add(temp_Meas);
						}
						if(checkBox.containsKey(temp_Meas))
						{
							user_Type_temp=(ArrayList)checkBox.get(new String(temp_Meas));
							user_Type_temp.add(user_Type_Meas);
						}
						else
						{
							user_Type_temp=new ArrayList();
							user_Type_temp.add(user_Type_Meas);
							keyList.add(temp_Meas);
						}
						if(temp_Meas!=null && temp_Meas.trim().length()>0 && user_Type_temp!=null && user_Type_temp.size()>0)
						{
							checkBox.put(temp_Meas,(ArrayList)user_Type_temp);
							checkHash.put(temp_Meas,checked);
						}
					}
				}
			}
			
		
			for(int m=0;m<keyList.size();m++)
			{
				String key1 = (String)keyList.get(m);
				checkBoxJson1 = new JSONObject();
				checkBoxJson1.put("measName",key1);
				
				ArrayList value1 = (ArrayList)checkBox.get(key1);
				if(value1!=null && value1.size()>0)
				{
					JSONArray valAr1 = new JSONArray();
					for(int q=0;q<value1.size();q++)
					{
						valAr1.add(""+value1.get(q));
					}

					String checkValue1 = (String)checkHash.get(key1);
					checkBoxJson1.put("orgName",valAr1);
				
					if (checkValue1 != null && checkValue1.equalsIgnoreCase("true"))
					{
						checkBoxJson1.put("checkVal",new Boolean(checkValue1));
						
						//checkBoxJson1.put("checkVal","<div ><input type='checkbox' id='chk' name='chk' checked></div>");
						
					}
					else
					{
						checkBoxJson1.put("checkVal",new Boolean(checkValue1));
						//checkBoxJson1.put("checkVal","<div><input type='checkbox' id='chk'  name='chk'></div>");
						
					}
					checkBoxArr1.add(checkBoxJson1);
				}
			}
			json.put("moreGrid",checkBoxArr1);
		}
		
		if(updateMoreGrid!=null && updateMoreGrid.equalsIgnoreCase("true"))
		{
			String checked_Values="";
			ArrayList checkedList = new ArrayList();
			if(checkedVal1!=null && checkedVal1.trim().length()>0)
			{
				checkedList = com.egurkha.util.StringUtils.egTokenizer(checkedVal1, ",",false,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
			}
			if(checkedList!=null && checkedList.size()>0)
			{
				boolean isCountryAdded=false;
				boolean isRegionAdded=false;
				boolean isCityAdded=false;
				for(int k=0;k<checkedList.size();k++)
				{
					String checkStr=(String)checkedList.get(k);
					if(checkStr!=null && checkStr.length()>0)
					{
						if(checkStr.indexOf("Country_name")>-1)
							isCountryAdded=true;
						if(checkStr.indexOf("Region")>-1)
							isRegionAdded=true;
						if(checkStr.indexOf("City")>-1)
							isCityAdded=true;

						checked_Values += checkStr;
						if(k+1 != checkedList.size())
							checked_Values = checked_Values+',';
					}
				}

				if(isCountryAdded && (checked_Values.indexOf("GeoDetails:Country~$~Country")==-1))
					checked_Values = checked_Values +",GeoDetails:Country~$~Country";

				if(isRegionAdded && (checked_Values.indexOf("GeoDetails:Region~$~Region")==-1))
					checked_Values = checked_Values +",GeoDetails:Region~$~Region";

				if(isCityAdded && (checked_Values.indexOf("GeoDetails:City~$~City")==-1))
					checked_Values = checked_Values +",GeoDetails:City~$~City";
			}
			userValues = in.getValue(subject,userType+":"+vdiType);
			if(isFromCtx!=null && isFromCtx.trim().length()>0 && isFromCtx.equalsIgnoreCase("true"))
			{
				if(vdiType!=null && vdiType.trim().length()>0 && vdiType.indexOf(":")!=-1)
					vdiType = vdiType.substring(0,vdiType.indexOf(":"));
				subject = "USER_DESKTOP_METRICS_VIEW";
				in.setValue(subject,userType+":"+vdiType,checked_Values);
				in.saveFile();
			}
			else if(userName!=null && userType!=null && checked_Values!=null)
			{
				in.setValue(subject,userName+":"+userType,checked_Values);
				in.saveFile();
			}
		}
	}
	response.getWriter().write(json.toString());
%>
