<%
/*******************************************************************************
*	File name	:	EgSaveStatus.jsp
*	Purpose		:	Intimate the Downloading status.
*	Author      :   Vadivel.M
*   Creation	:	23/11/2012
*******************************************************************************/
%>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import="net.sf.json.*"%>										
<%// Prem
	JSONObject json =  new JSONObject();
	String downloadFile = request.getParameter("downloadFile");

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

	if (!StringUtils.isNull(hitFrom) && hitFrom.equals("monitor"))
	{
		String strCompType = request.getParameter("componentType");
		String strCompName = request.getParameter("componentName");
		String strTestType = request.getParameter("testType");
		String strTestName = request.getParameter("testName");
		String strDescName = request.getParameter("monDescName");
		String monTestState = request.getParameter("monTestState");
		String layerName = request.getParameter("layerName");
		String monSource = request.getParameter("monSource");


		if (!StringUtils.isNull(monSource))
		{
			String qryString = "";

			String qryTestVal = null;
			if(!StringUtils.isNull(strDescName) && !strDescName.equals("NONE"))
			{
				qryTestVal = strTestName+"- "+strDescName;
			}
			else
			{
				qryTestVal = strTestName+"- ";
			}


			if(monSource.equals("measure"))
			{
				String State = request.getParameter("State");

				qryString = "/final/servlet/com.eg.EgMonitorController?monCmd=measures&from=MainDashboard&action="+monSource+"&compName="+EgURLEncoder.encode(strCompName+":"+strCompType,"UTF-8")+"&State="+State;

				session.setAttribute("monitorURL",qryString);
				json.put("monitorURL",qryString);
			}
			else if(monSource.equals("insideview"))
			{
				String State = request.getParameter("State");
				
				if(strDescName != null && strDescName.trim().length()>0 && strDescName.indexOf(":")>-1 )
				{
					strDescName = strDescName.substring(0,strDescName.indexOf(":"));
				}

				qryString = "/final/monitor/egInsideviewDashboard.jsp?getFor=measure&comp="+EgURLEncoder.encode(strCompName,"UTF-8")+"&comptype="+strCompType+"&Layer="+layerName+"&info="+EgURLEncoder.encode(strDescName,"UTF-8")+"&compName="+EgURLEncoder.encode(strCompType+":"+strCompName,"UTF-8");

				session.setAttribute("monitorURL",qryString);
				json.put("monitorURL",qryString);
			}
			else 
			{
				//qryString = "/final/servlet/com.eg.EgDashboardController?from=list&comptype="+strCompType+"&host="+strCompName+"&tab=LayerModel&comesFrom=LayerModel&site=NULL&qctr=0&fromPage=componentList&newWindow=false&comptype="+strCompType+"&host="+strCompName+"&isFromMenu=true&layer="+layerName+"&test="+EgURLEncoder.encode(qryTestVal,"UTF-8")+"&tstate="+EgURLEncoder.encode(monTestState,"UTF-8");
				qryString = "/final/monitor/EgSiteInfraView.jsp?qctr=2&fromalarm=&comptype="+strCompType+"&host="+EgURLEncoder.encode(strCompName,"UTF-8")+"&site=NULL&msmt_host=&newWindow=false&prevPage=MainDashBoard&layer="+layerName+"&test="+EgURLEncoder.encode(qryTestVal,"UTF-8")+"&tstate="+EgURLEncoder.encode(monTestState,"UTF-8");

				session.setAttribute("monitorURL",qryString);
				json.put("monitorURL",qryString);
			}
		}
	}
	else if(downloadFile!=null && downloadFile.trim().length()>0)
	{
		int cnt=0;
		while(true)
		{
			String saveStatus =(String) session.getAttribute("pdf");
			if (saveStatus!=null)
			{
				session.removeAttribute("pdf");
				json.put("downloadStatus","done");
				break;
			}

			try
			{
				Thread.sleep(1000);
			}
			catch (Exception er)
			{
			}
			
			cnt++;
			if(cnt >= 900)
			{
				json.put("downloadStatus","done");
				break;
			}
		}
	}
	else
		json.put("downloadStatus","done");

	response.getWriter().write(json.toString());
	// Prem
%>










