/*
̃t@C̒ǵANTT I[v\[XCZX@o[W 1.0iu{
_vƂj̓Kp󂯂܂B
{_炵ȂÃt@CgpĂ͂Ȃ܂B
{_̃Rs[́Âtqkł܂B
yzzTCgURLz http://www.oss.ecl.ntt.co.jp/lms/

{_ɊÂЕz\tgEFÁÂ܂܁Âَ͖
ނ̕ۏ؂ȂŁAЕz܂B{_ɊÂyѐ𗥂
̕ɂẮA{_QƂĂB

uIWiR[hv́A NTT Cyber Space Laboratories Code łB 
uIWiR[hv́uJҁv́A{dMdbЂłB  
{dMdbЂɂn삳ꂽ́ACopyright (C) 2004 
{dMdb łB
SĂ̌ۂ܂B 
uRgr[^vF_____________________________________ 


The contents of this file are subject to the NTT Opensource License
Version 1.0 (the License); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
yzzTCgURLz http://www.oss.ecl.ntt.co.jp/lms/

Software distributed under the License is distributed on an AS IS
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is NTT Cyber Space Laboratories Code .

The Initial Developer of the Original Code is NIPPON TELEGRAPH AND 
TELEPHONE CORPORATION.
Portions created by the NIPPON TELEGRAPH AND TELEPHONE CORPORATION 
are Copyright (C) 2004 NIPPON TELEGRAPH AND TELEPHONE CORPORATION. 
All Rights Reserved.

Contributor(s) ______________________________________.
*/

//
// [Uo^@͉ʕ\rWlXAction
// 
//
//	ύX
//	2004.01.08 VK쐬 M.Seko 
//

package jp.co.ntt.lms.xms.people;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import jp.co.ntt.lms.xmo.Mail.MailConst;
import jp.co.ntt.lms.xms.framework.XmsBusinessAction;
import jp.co.ntt.lms.xms.framework.XmsException;
import jp.co.ntt.lms.xms.framework.XmsRequest;
import jp.co.ntt.lms.xms.framework.XmsResponse;
import jp.co.ntt.lms.xms.framework.XmsSystemException;
import jp.co.ntt.lms.xms.common.mail.InputFrameErrorBean;
import jp.co.ntt.lms.xms.common.mail.MailTemplateConstant;
import jp.co.ntt.lms.xms.common.util.CommonUtil;

/**
 * [Uo^@͉ʕ\rWlXActionB<br>
 * j[烆[Uo^IۂɁA
 * ʕ\s߂ɎgpB
 * 
 *  @author M.Seko
 */
public class PeopleInsertInputFramesetDisplayBusinessAction extends XmsBusinessAction {

	/**
	 * @see jp.co.ntt.lms.xms.framework.XmsBusinessAction#initProcessRequest(XmsRequest)
	 */
	protected void initProcessRequest(XmsRequest xmsRequest) throws XmsException {
		//ZbVL[ǗNX̃CX^XɃZbVɑ݂Ă΁A
		//ZbV̏폜B

		// HTTPZbV擾p
		HttpServletRequest request = null;
		// HTTPZbV
		HttpSession session = null;
		//ZbVL[ێNX̃ZbV̎擾sp
		SKeyKeep skeyKeep = null;

		request = xmsRequest.getRequest();
		session = request.getSession(false);
		if (session == null) {
			//sessionłꍇAsłȂ̂ŗOf
			throw new XmsSystemException("This session is invalid.");
		}

		skeyKeep = (SKeyKeep) session.getAttribute(PeopleConst.SKeyKeepSessionKey);

		if (skeyKeep != null) {
			//ZbVL[ێNXɃZbVɑ݂ĂB
			//āAZbVL[ێNXێĂZbVL[ɌтĂf[^폜
			CommonUtil.removeSessionData(xmsRequest, skeyKeep.getSkeyStringArray());
		}

		//̉ʂւ̕AɕKvȏZbVɊi[B
		PeopleInsertComeBackInfoBean peopleInsertComebackInfoBean =
			new PeopleInsertComeBackInfoBean();
		peopleInsertComebackInfoBean.setReturnURL(request.getParameter("returnURL"));
		session.setAttribute(PeopleConst.ComebackInfoSessionKey, peopleInsertComebackInfoBean);

	}

	/**
	 * [̎gp\Es\ɉďU蕪B<br>
	 * ܂Aform͂郆[U̓ei[ꂽZbVNAɂB<br>
	 * @see jp.co.ntt.lms.xms.framework.XmsBusinessAction#processRequest(XmsRequest, XmsResponse)
	 */
	protected void processRequest(XmsRequest xmsRequest, XmsResponse xmsResponse)
		throws XmsException {
		// HTTPZbV擾p
		HttpServletRequest request = null;
		// HTTPZbV
		HttpSession session = null;

		request = xmsRequest.getRequest();
		session = request.getSession(false);
		if (session == null) {
			//sessionłꍇAsłȂ̂ŗOf
			throw new XmsSystemException("This session is invalid.");
		}

		//[Uj[烆[Uo^ʂ\ۂɁAÔߓo^tH[ޔ폜B
		//{Ȃ΁AinitProcessRequest\bhō폜͂łB
		session.removeAttribute(PeopleConst.PeopleFormInfoSessionKey);

		//o^tH[ޔi[pBean𐶐
		//[Uo^@\ĂяoƂGETp[^ňꏏɊi[Kv̂̂̂
		PeopleFormInfoBean peopleFormInfoBean = new PeopleFormInfoBean();

		//eO[vID擾
		String parentID = null;
		parentID = request.getParameter("parentID");
		if ((parentID != null) && (parentID.equals("") == false)) {
			//eO[vID΁ABeanɒlo^
			peopleFormInfoBean.setParentID(parentID);
		} else {
			//eO[vID΁AG[ʂ֑Jڂ
			InputFrameErrorBean inputFrameErrorBean = new InputFrameErrorBean();
			inputFrameErrorBean.setErrorMessage(PeopleConst.M032001);
			inputFrameErrorBean.setActionId("PeopleInsert.reDisplay");
			inputFrameErrorBean.setButtonType(InputFrameErrorBean.BUTTON_TYPE_RETURN);

			//G[ZbVɒǉ
			session.setAttribute(MailTemplateConstant.KEY_ERROR_INFO, inputFrameErrorBean);

			//G[ʂ֑Jڂ邽߂̏Ԃݒ肵A\bhIB
			xmsResponse.setBusinessStatus("error");
			return;
		}

		if (CommonUtil.checkMailAuthority(xmsRequest) == true) {
			//OC[ÚA[gp\ł
			//[ev[gt̉ʂ\Xe[^XZbg
			xmsResponse.setBusinessStatus("mailAuthorityOK");

			//[Uo^JSP̂߂ɁA[ev[ggp\\lZbg
			peopleFormInfoBean.setIsUsableMailTemplate(true);

			//[ʏZbVɓo^
			session.setAttribute("XMM_MT_MailType", MailConst.TYPE_REGIST);

		} else {
			//OC[ÚA[gps\łB
			//[ev[g̉ʂ\Xe[^XZbg
			xmsResponse.setBusinessStatus("mailAuthorityNG");

			//[Uo^JSP̂߂ɁA[ev[ggps\\lZbg
			peopleFormInfoBean.setIsUsableMailTemplate(false);

		}

		//[ev[ggp\^s\y
		//ZbVɓo^tH[ޔǉ
		session.setAttribute(PeopleConst.PeopleFormInfoSessionKey, peopleFormInfoBean);

		//ZbVL[ێNX̃ZbV̎擾syсAZbVւ̓o^p
		SKeyKeep skeyKeep = null;

		skeyKeep = (SKeyKeep) session.getAttribute(PeopleConst.SKeyKeepSessionKey);
		if (skeyKeep == null) {
			//܂AZbVL[ێNX̃CX^XZbVɑ݂ĂȂ
			//Vɐ
			skeyKeep = new SKeyKeep();
		}
		skeyKeep.addSKey(PeopleConst.PeopleFormInfoSessionKey); //tH[ޔ̃L[ǉ
		//ZbVL[ێNX̃CX^XZbVɓo^
		session.setAttribute(PeopleConst.SKeyKeepSessionKey, skeyKeep);

	}
}
