/*************************************************************************************************
 * 프로그램명 : HttpReportTrans.java 프로그램설명 : 보고문서 이관 파라미터 작성자 : 작성일 : 변경일 :
 **************************************************************************************************/

package kr.co.kihyun.beans.totsys.repoper;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import kr.co.kihyun.beans.entity.util.*;
import kr.co.kihyun.beans.user.HttpSSOLogin;
import kr.co.kihyun.lang.Encoder;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.text.html.ServletUtil;
@WebServlet("/servlet/kr.co.kihyun.beans.totsys.repoper.HttpReportTrans")
public class HttpReportTrans extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		res.setContentType("text/html;charset=UTF-8");
		PrintWriter out = res.getWriter();

		/*********** User HttpLogin check ***********/
		if (!HttpSSOLogin.isLogin(req)) {
			String connURL = "location='/totsys/login/login.jsp';";
			out.println(ServletUtil.getJavaScript(connURL));
			return;
		}

		/********** parameter value **********/
		String reportID = Encoder.toJava(req.getParameter("reportID"));

		PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
		try {
			TotReport totReport = pm.getObjectById(TotReport.class, reportID);
			totReport.setProcess(TotReportProcess.READ);
			pm.makePersistent(totReport);

			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_report") + MoumiConfig.getMessageBundle().getString("moumi.message.popup.transControlSuccess")));
			out.println(ServletUtil.getJavaScript("document.location='/totsys/repoper/readbox/report_list.jsp';"));
		} catch (Exception ex) {
			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_report") + MoumiConfig.getMessageBundle().getString("moumi.message.popup.transControlFail")));
			out.println(ServletUtil
					.getJavaScript("document.location='/totsys/repoper/mydocbox/endbox/report_list.jsp';"));
			ex.printStackTrace();
		} finally {
			pm.close();
		}
	}
}
