/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：番号ポータビリティ可否確認
*   ソースファイル名：FUW00951SFLogic.java
*   作成者          ：富士通
*   日付            ：2013年04月06日
*＜機能概要＞
*   番号ポータビリティ可否確認の画面制御を行います。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   5.00        2013/04/08   FJ)大塚     新規作成
*   v12.00      2014/11/05   FJ）谷本    【ANK-2309-03-00】＜案件内仕変＞店頭販売支援へのメニュー画面追加
**********************************************************************/

package eo.web.webview.FUW00951SF;

import static com.fujitsu.futurity.web.x31.X31SWebLog.DEBUG_LOG;

import java.util.HashMap;

import com.fujitsu.futurity.web.x00.JCCBusinessException;
import com.fujitsu.futurity.web.x00.JCCWebServiceException;
import com.fujitsu.futurity.web.x31.X31CMessageResult;
import com.fujitsu.futurity.web.x31.X31CWebConst;
import com.fujitsu.futurity.web.x31.X31SDataBeanAccess;

import eo.common.constant.JFUStrConst;
import eo.common.constant.JPCModelConstant;
import eo.web.webview.JCCWebBusinessLogic;
import eo.web.webview.CommonInfoCF.CommonInfoCFConst;
import eo.web.webview.FUW00951SF.FUW00951SFConst;
import eo.web.webview.common.JFUScreenConst;
import eo.web.webview.common.JFUWebCommon;
import eo.web.webview.mapping.FUSV0197_FUSV0197OPDBMapper;

/**
 * 番号ポータビリティ可否画面のVIEWロジックです。
 * <br>
 * @author 富士通
 */
@SuppressWarnings("serial")
public class FUW00951SFLogic extends JCCWebBusinessLogic
{
	//----------------------------------------------------
	// 定数群
	//----------------------------------------------------
	/** 定数参照ID チェック結果(記号) NG */
	private final static String RESULT_MARK_FALSE = "RESULT_MARK_FALSE";
	/** 定数参照ID チェック結果(記号) OK */
	private final static String RESULT_MARK_TRUE = "RESULT_MARK_TRUE";
	/** 定数参照ID チェック結果(文言) NG  */
	private final static String RESULT_TEXT_FALSE = "RESULT_TEXT_FALSE";
	/** 定数参照ID チェック結果(文言) OK  */
	private final static String RESULT_TEXT_TRUE = "RESULT_TEXT_TRUE";
	/** チェック結果 TRUE */
	private final static Boolean RESULT_TRUE = true;
	/** チェック結果 FALSE */
	private final static Boolean RESULT_FALSE = false;
	/** ユースケースID */
	private final static String USECASE_ID = "FUSV0197";
	/** Mapキー：検索エラーフラグ */
	private static final String MAP_KEY_ERR_UM = "err_um";
	/** エラーコード：1 */
	private static final String ERR_CODE_1 = "1";

	/**
	 * 初期表示処理
	 * 
	 * <br>
	 * @return true
	 * @throws Exception
	 */
	public boolean init() throws Exception
	{
		return true;
	}

	/**
	 * 確認ボタン押下処理
	 * 
	 * <br>
	 * @return ロジック正常終了時、true
	 * @throws Exception 
	 */
	@SuppressWarnings("unchecked")
	public boolean kakunin() throws Exception
	{
		// サービスフォームBean取得
		X31SDataBeanAccess serviceFormBean = super.getServiceFormBean();

		// ユースケースID格納用マップを生成します。
		HashMap paramMap = new HashMap();
		paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, USECASE_ID);

		// マッパー引数用Bean配列
		X31SDataBeanAccess[] beans = { super.getServiceFormBean() };

		// マッパー作成・上りマッピング開始
		HashMap inputMap = new HashMap();
		FUSV0197_FUSV0197OPDBMapper mapper = new FUSV0197_FUSV0197OPDBMapper();
		mapper.setFUSV019701CC(beans, inputMap, JPCModelConstant.FUNC_CD_1);

		// 結果格納用マップを生成します。
		HashMap outputMap = new HashMap();

		// サービスの実行
		try
		{
			@SuppressWarnings("unused")
			X31CMessageResult result = invokeService(paramMap, inputMap, outputMap);

			// -------------------------------------------------
			// 番ポ可否チェック
			// -------------------------------------------------

			// 番ポ電話番号登録可否チェックCC
			HashMap<String, Object> parentMap = (HashMap)outputMap.get(USECASE_ID + "01CC");

			if (null != parentMap)
			{
				// 検索エラーフラグチェック
				if (parentMap.size() > 0 && parentMap.containsKey(MAP_KEY_ERR_UM))
				{
					String errUm = (String)parentMap.get(MAP_KEY_ERR_UM);

					// 検索エラーが発生している場合
					if (ERR_CODE_1.equals(errUm))
					{
						serviceFormBean.sendMessageString(FUW00951SFConst.RESULT_MARK, X31CWebConst.DATABEAN_SET_VALUE,
								getDefinition(RESULT_MARK_FALSE));
						serviceFormBean.sendMessageString(FUW00951SFConst.RESULT_TEXT, X31CWebConst.DATABEAN_SET_VALUE,
								getDefinition(RESULT_TEXT_FALSE));
						serviceFormBean.sendMessageBoolean(FUW00951SFConst.RESULT, X31CWebConst.DATABEAN_SET_VALUE, RESULT_FALSE);
						return true;
					}
				}
			}

			serviceFormBean.sendMessageString(FUW00951SFConst.RESULT_MARK, X31CWebConst.DATABEAN_SET_VALUE, getDefinition(RESULT_MARK_TRUE));
			serviceFormBean.sendMessageString(FUW00951SFConst.RESULT_TEXT, X31CWebConst.DATABEAN_SET_VALUE, getDefinition(RESULT_TEXT_TRUE));
			serviceFormBean.sendMessageBoolean(FUW00951SFConst.RESULT, X31CWebConst.DATABEAN_SET_VALUE, RESULT_TRUE);
		}
		catch (JCCWebServiceException e)
		{
			throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002);
		}
		return true;
	}

	/**
	 * 戻るボタン押下処理
	 * 
	 * <br>
	 * 
	 * @return true
	 * @throws Exception
	 */
	public boolean back() throws Exception
	{
		// デバッグ用ログ出力
		DEBUG_LOG.info("----- init_Start -----");

		X31SDataBeanAccess commonInfoBean = getCommonInfoBean();
		// 遷移先画面ID
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_ID, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_ID_FUW00954);
		// 遷移先画面名
		commonInfoBean.sendMessageString(CommonInfoCFConst.NEXT_SCREEN_NAME, X31CWebConst.DATABEAN_SET_VALUE, JFUScreenConst.SCREEN_NAME_FUW00954);

		DEBUG_LOG.info("----- init_End  -----");

		return true;
	}

	/**
	 * 設定ファイルから自画面IDの値を取得
	 * 
	 * @param id 取得する値のID
	 * @throws Exception 
	 */
	private String getDefinition(String id) throws Exception
	{
		return JFUWebCommon.getDispText(JFUScreenConst.SCREEN_ID_FUW00951, id);
	}
}
