/*********************************************************************
* All Rights reserved, Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム共通（共通マスタ）
*   モジュール名    ：ZMW01401SFLogic
*   ソースファイル名：ZMW01401SFLogic.java
*   作成者          ：富士通
*   日付            ：2012年05月15日
*＜機能概要＞
*   権限情報削除のビューロジックです。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v3.00       2012/05/15   FJ）垣内    新規作成
*	v3.00		2012/05/15   FJ) 垣内	【SGY-2012-000006】統合認証対応
*
**********************************************************************/

package eo.web.webview.ZMW01401SF;

import java.util.ArrayList;
import java.util.HashMap;

import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccess;

import eo.common.constant.JPCModelConstant;
import eo.common.constant.JPCOnlineMessageConstant;
import eo.web.webview.JCCWebBusinessLogic;
import eo.web.webview.CommonInfoCF.CommonInfoCFConst;
import eo.web.webview.common.JZMScreenConst;
import eo.web.webview.common.JZMWebCommon;
import eo.web.webview.common.JZMWebConst;
import eo.web.webview.mapping.ZMSV0117_ZMSV0117OPDBMapper;
import eo.web.webview.mapping.ZMSV0118_ZMSV0118OPDBMapper;

/** * 
 *  権限情報削除のビューロジックです。
 * @author 910079
 *
 */
@SuppressWarnings("serial")
public class ZMW01401SFLogic extends JCCWebBusinessLogic
{
	/** メッセージ置き換え文字 */
	private static final String[] ERROR_MESSAGE = {"権限", "情報"};
	
	/** 機能コード１  */
	private static final String FUNC_CD_1 = JPCModelConstant.FUNC_CD_1;

	/** 機能コード２  */
	private static final String FUNC_CD_2 = JPCModelConstant.FUNC_CD_2;

	/** メッセージID EKB0370--I  */
	private static final 	String MESSAGE_ID_370 = JPCOnlineMessageConstant.EKB0370__I;

	/** メッセージID EKB0380--I  */
	private static final 	String MESSAGE_ID_380 = JPCOnlineMessageConstant.EKB0380__I;

	/**	メッセージ置換文字 */
	private static final 	String[] MESSAGE_VALUE = {"権限情報削除"};

	/**	メッセージ置換文字 */
	private static final 	String MESSAGE_KGCD = "権限コード";

	/**	メッセージ置換文字 */
	private static final 	String MESSAGE_ROLE_KG = "ロール_権限";

	/**	メッセージ置換文字 */
	private static final 	String MESSAGE_ROLE_CD = "ロールコード：";

	/**	エラーリスト */
	private static final 	String ERR_LIST = "err_list";

	/**
	 * 権限削除の初期表示処理を行います。
	 * <br>
	 * @return boolean
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public boolean init() throws Exception
	{
		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commonBean = getCommonInfoBean();
		
		if(JZMWebCommon.getScreenInfo(this) == null)
		{
			setBackScreenId(commonBean, true);
			return true;
		}

		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();
		
		// サービスフォームBeanのデータBeanアクセスクラスを取得。
		X31SDataBeanAccess[] paramBean = {bean};

		// ユースケースID格納用マップ
		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		// マッピング用Map
		HashMap<String, Object> dataMap = new HashMap<String, Object>();

		// サービス実行結果データ用Map
		HashMap<String, Object> outputMap = new HashMap<String, Object>();
		
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, JZMWebConst.SV117);
		
		// マッピングクラスのインスタンスを生成
		ZMSV0117_ZMSV0117OPDBMapper mapper = new ZMSV0117_ZMSV0117OPDBMapper();
		mapper.setZMSV011701CC(paramBean, dataMap, FUNC_CD_2);
		mapper.setZMSV011702SC(paramBean, dataMap, FUNC_CD_1);
		
		// サービスの呼び出し
		invokeService(paramMap, dataMap, outputMap);
		
		// マッピングクラスの呼び出し
		mapper.getZMSV011702SC(paramBean, outputMap);

		// 検索エラーフラグの取得
		String searchErrFlg = JZMWebCommon.getSearchErrFlg(JZMWebConst.SC11702, outputMap);
		
		if(JPCModelConstant.SEARCH_ERR_FLG_NODATA.equals(searchErrFlg))
		{
			JZMWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0300_KW, ERROR_MESSAGE);
			setBackScreenId(commonBean, true);
			return true;
		}
		
		if(outputMap.containsKey(JZMWebConst.CC11701))
		{
			HashMap<String, Object> ccMap = (HashMap<String, Object>)outputMap.get(JZMWebConst.CC11701);
			
			if(ccMap.containsKey(JZMWebConst.EZM0021B010CBSMSG1LIST))
			{
				ArrayList<?> msgList = (ArrayList<?>)ccMap.get(JZMWebConst.EZM0021B010CBSMSG1LIST);
				// ロール＿権限一覧照会に値が存在する場合
				if(msgList.size() != 0)
				{
					// 取得したロール＿権限の明細行分、エラーメッセージ追加処理を行う
					for(int i = 0; i < msgList.size(); i++)
					{
						HashMap tmpMap = (HashMap)msgList.get(i);
						if(tmpMap.containsKey(JZMWebConst.EZM0021B010_ROLE_CD))
						{
							String[] items = new String[]{MESSAGE_KGCD, MESSAGE_ROLE_KG, MESSAGE_ROLE_CD + (String)tmpMap.get(JZMWebConst.EZM0021B010_ROLE_CD)};
							
							// 権限コードがロール＿権限マスタに存在している場合エラー
							JZMWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB9960_KW, items);
						}
					}
					setBackScreenId(commonBean, true);
					return true;
				}
			}
			else if(ccMap.containsKey(ERR_LIST))
			{
				ArrayList<?> errList = (ArrayList<?>)ccMap.get(ERR_LIST);
				if(errList.size() != 0)
				{
					HashMap errMap = (HashMap)errList.get(0);
					if(errMap.containsValue("WA"))
					{
						String[] errItems = new String[]{MESSAGE_KGCD, MESSAGE_ROLE_KG};
						JZMWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB1270__Q, errItems);
						JZMWebCommon.setMessageAreaBackColor(this, JZMWebConst.ONE);
						
						// 遷移先画面ID、名称の設定
						commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID,
								X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst.SCREEN_ID_ZMW01401);
						commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME,
								X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst.SCREEN_NAME_ZMW01401);
						
						return true;
					}
				}
			}
		}

		// メッセージの設定
		JZMWebCommon.setMessageInfo(this, MESSAGE_ID_370, MESSAGE_VALUE);
		JZMWebCommon.setMessageAreaBackColor(this, JZMWebConst.ONE);
						
		// 遷移先画面ID、名称の設定
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID,
				X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst.SCREEN_ID_ZMW01401);
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME,
				X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst.SCREEN_NAME_ZMW01401);
		
		return true;
	}
	
	/**
	 * 確定処理を行います
	 * @return boolean　処理結果
	 * @throws Exception　予期せぬ例外
	 */
	@SuppressWarnings("unchecked")
	public boolean fix() throws Exception
	{
		// サービスフォームBeanの内容の取得
		X31SDataBeanAccess bean = getServiceFormBean();

		// 共通フォームBeanの内容を取得
		X31SDataBeanAccess commoninfoBean = getCommonInfoBean();

		// ユースケースID格納用マップ
		HashMap<String, Object> paramMap = new HashMap<String, Object>();

		// マッピング用Map
		HashMap<String, Object> dataMap = new HashMap<String, Object>();

		// サービス実行結果データ用Map
		HashMap<String, Object> outputMap = new HashMap<String, Object>();

		// (3)サービス呼出処理
		// マッピングクラスを使用する為、配列化
		X31SDataBeanAccess[] paramBean = {bean};

		// ユースケースID格納
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, JZMWebConst.SV118);

		// マッピングクラス
		ZMSV0118_ZMSV0118OPDBMapper mapper = new ZMSV0118_ZMSV0118OPDBMapper();

		// マッピング処理（上り）
		mapper.setZMSV011801CC(paramBean, dataMap, FUNC_CD_1);

		// サービス実行
		invokeService(paramMap, dataMap, outputMap);
		
		if(outputMap.containsKey(JZMWebConst.CC11801))
		{
			HashMap<String, Object> ccMap = (HashMap<String, Object>)outputMap.get(JZMWebConst.CC11801);
			
			if(ccMap.containsKey(JZMWebConst.EZM0021B010CBSMSG1LIST))
			{
				ArrayList<?> msgList = (ArrayList<?>)ccMap.get(JZMWebConst.EZM0021B010CBSMSG1LIST);
				// ロール＿権限一覧照会に値が存在する場合
				if(msgList.size() != 0)
				{
					// 取得したロール＿権限の明細行分、エラーメッセージ追加処理を行う
					for(int i = 0; i < msgList.size(); i++)
					{
						HashMap tmpMap = (HashMap)msgList.get(i);
						if(tmpMap.containsKey(JZMWebConst.EZM0021B010_ROLE_CD))
						{
							String[] items = new String[]{MESSAGE_KGCD, MESSAGE_ROLE_KG, MESSAGE_ROLE_CD + (String)tmpMap.get(JZMWebConst.EZM0021B010_ROLE_CD)};
							
							// 権限コードがロール＿権限マスタに存在している場合エラー
							JZMWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB9960_KW, items);
						}
					}
					return true;
				}
			}
		}

		// メッセージの設定
		JZMWebCommon.setMessageInfo(this, MESSAGE_ID_380, MESSAGE_VALUE);
		
		// 画面遷移
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst.SCREEN_ID_ZMW01402);
		commoninfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JZMScreenConst. SCREEN_NAME_ZMW01402);
		
		return true;
	}

	/**
	 * 戻るボタンの処理を行います。
	 * <br>
	 * @return boolean　処理結果
	 * @throws Exception　予期せぬエラー
	 */
	public boolean back() throws Exception
	{
		// 共有フォームBean
		X31SDataBeanAccess commonBean = getCommonInfoBean();
		
		// 画面遷移
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JZMWebCommon.getScreenId(this));
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JZMWebConst.BLANK);
		
		return true;
	}
	
	/**
	 * 
	 * @return boolean
	 * @throws Exception
	 */
	public boolean fin() throws Exception
	{
		// 共有フォームBean
		X31SDataBeanAccess commonBean = getCommonInfoBean();
		
		// HashMapを設定する
		JZMWebCommon.setScreenInfo(this, this.getGamenId(), new HashMap<String, Object>());
		
		setBackScreenId(commonBean, false);
				
		return true;
	}

	/**
	 * セッションから遷移先画面を取得し共通ビーンに設定します。
	 * @param commonBean 共通ビーン
	 * @param transfer setTransferPageId()を呼び出すかどうかを設定します。
	 */
	private void setBackScreenId(X31SDataBeanAccess commonBean, boolean transfer)
	{
		String screenId = JZMWebCommon.getScreenId(this);

		// 遷移先画面ID、名称の設定
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID,
				X31CWebConst.DATABEAN_SET_VALUE, screenId);
		commonBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME,
				X31CWebConst.DATABEAN_SET_VALUE, JZMWebConst.BLANK);

		if(transfer)
		{
			setTransferPageId(screenId + JZMWebConst.PJP);
		}
	}
}
