package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.ejb.HalolMFGReleaseRemote;
import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
public class QCBatchExportPDFServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
	{
		 doPost( request, response );
	}
    

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
	{
		 String rptTitle        ="";
		 String remark          ="";
		 String userID          ="";
		 String imgName         = "";
		 String resultString    ="";
	     HalolMFGReleaseRemote halolMFGReleaseRemote = null;
		 InitialContext context = null;
		 AppConnectParm appConnectParm = new AppConnectParm();
		System.out.println(" ENTER - QCBatchExportPDFServlet  ***********************");
		try
		{
			
			response.setContentType("application/xml");
			userID           = request.getParameter("userID");
		    rptTitle         = request.getParameter("rptTitle");
		    remark           = request.getParameter("remark");
		    imgName          = request.getParameter("imgNameList");
		    System.out.println("userID inside QCBatchExportPDFServlet====="+ userID +"---rptTitle----->"+rptTitle + "---remark--->"+remark); 		     
		    // call EJB method for PDF creation******************* 
		    context = new InitialContext(appConnectParm.getProperty());
			halolMFGReleaseRemote  = (HalolMFGReleaseRemote) context.lookup("ibase/HalolMFGRelease/remote");
		     resultString          =  halolMFGReleaseRemote.getPDFByScheduler(rptTitle,remark,userID,imgName);
			 response.setContentType("text/html");
			 if(resultString.equals("false"))
			 {
				 response.getWriter().write("false");
			 }
			 else
			 {
				 response.getWriter().write("true");
			 }
		}
		catch (Exception e)
		{
			System.out.println("Exception :QCBatchExportPDFServlet : QCBatchExportPDFServlet) :"+e.getMessage()); //$NON-NLS-1$
			try 
			{
				throw new ITMException(e);
			}
			catch (ITMException e1) 
			{
				e1.printStackTrace();
			}
		}
		finally
		{
			userID="";
			rptTitle="";
		}
	}

		
	
	
}