/*******************************************************************************
*	 All Rights reserved,Copyright (c) K-Opticom 
********************************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JSYejbKK1401ETDA
*	ソースファイル名：JSYejbKK1401ETDA.java
*	作成者			：EKek0003
*	日付			：2011年10月24日
*＜機能概要＞
*	データ抽出項目設定対象契約 ETMsgDBアクセス部品
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	ｖ1.00.00
*
********************************************************************************/

package eo.ejb.cbm.entity;

import com.fujitsu.futurity.model.base.CAANMsg;
import com.fujitsu.futurity.model.base.CAANException;
import com.fujitsu.futurity.model.base.CAANCreateException;
import com.fujitsu.futurity.model.base.CAANRuntimeException;
import com.fujitsu.futurity.model.ejb.common.StatusCodes;
import com.fujitsu.futurity.model.ejb.common.JSYejbLog;
import com.fujitsu.futurity.model.ejb.common.fw.AgentDispatchContext;
import com.fujitsu.futurity.model.ejb.common.fw.ETMsgDBAccessHandler;
import eo.ejb.common.EventIDList;

/**
 * データ抽出項目設定対象契約ETMsgDBアクセス部品です。
 * ＜メソッド一覧＞
 * invoke
 * execIKK1401D001
 * execIKK1401D002
 * 
 */
public class JSYejbKK1401ETDA implements ETMsgDBAccessHandler {

	/**
	 * コンストラクタ
	 */
	public JSYejbKK1401ETDA() {
	}

	/**
	 * データ抽出項目設定対象契約ETMsgDBアクセス部品のメイン処理です。
	 * ETMsgの振舞IDに従い、項目値設定後、LogicalEntityを呼出します。
	 * @param  inETMsg 処理を行うETMsg
	 * @exception CAANRuntimeException 例外発生時にthrowします。
	 */
	public void invoke(CAANMsg inETMsg, AgentDispatchContext inContext) {

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "call:JSYejbKK1401ETDA.invoke");

		// ETMsgチェック
		// 処理対象のETMsgでなければ処理をぬけます。
		if (inETMsg.equalsSchemaClass(KK1401ETMsg.class) == false) {
			return;
		}

		// 振舞ID
		String eventID;

		// 振舞ID取り出し
		eventID = inETMsg.getString(KK1401ETMsg.EVENTID);

		// イベントの振り分け
		if(eventID.equals(EventIDList.IKK1401D001)){
			// データ抽出項目設定対象契約登録振舞内部
			execIKK1401D001(inETMsg);
		}
		else if(eventID.equals(EventIDList.IKK1401D002)){
			// データ抽出項目設定対象契約変更振舞内部
			execIKK1401D002(inETMsg);
		}

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "end:JSYejbKK1401ETDA.invoke");

	}

	/**
	 * データ抽出項目設定対象契約登録振舞内部<IKK1401D001>です。
	 * @param inETMsg 処理を行うETMsg
	 */
	private void execIKK1401D001(CAANMsg inETMsg) {

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "call:JSYejbKK1401ETDA.IKK1401D001");

		// 項目値設定
		// 現在日時
		String nowTimestamp = inETMsg.getString(KK1401ETMsg.OPERATEDATETIME);

		// 登録日時
		inETMsg.set(KK1401ETMsg.ADD_DTM, nowTimestamp);

		// 更新日時
		inETMsg.set(KK1401ETMsg.UPD_DTM, nowTimestamp);

		// LogicalEntity呼び出し
		KK1401LE le = new KK1401LE();

		try{
			le.create(inETMsg);

		}catch(CAANCreateException cce){
			inETMsg.set(KK1401ETMsg.STATUS, StatusCodes.CREATE_DB_ERR);
			throw new CAANRuntimeException(cce);
		}catch(CAANException ce){
			inETMsg.set(KK1401ETMsg.STATUS, StatusCodes.FATAL_ERR);
			throw new CAANRuntimeException(ce);
		}

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "end:JSYejbKK1401ETDA.IKK1401D001");

	}
	/**
	 * データ抽出項目設定対象契約変更振舞内部<IKK1401D002>です。
	 * @param inETMsg 処理を行うETMsg
	 */
	private void execIKK1401D002(CAANMsg inETMsg) {

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "call:JSYejbKK1401ETDA.IKK1401D002");

		// 項目値設定
		// 現在日時
		String nowTimestamp = inETMsg.getString(KK1401ETMsg.OPERATEDATETIME);

		// 登録日時
		inETMsg.set(KK1401ETMsg.ADD_DTM, nowTimestamp);

		// 更新日時
		inETMsg.set(KK1401ETMsg.UPD_DTM, nowTimestamp);

		// LogicalEntity呼び出し
		KK1401LE le = new KK1401LE();

		try{
			le.create(inETMsg);

		}catch(CAANCreateException cce){
			inETMsg.set(KK1401ETMsg.STATUS, StatusCodes.CREATE_DB_ERR);
			throw new CAANRuntimeException(cce);
		}catch(CAANException ce){
			inETMsg.set(KK1401ETMsg.STATUS, StatusCodes.FATAL_ERR);
			throw new CAANRuntimeException(ce);
		}

		// ログ出力
		JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "end:JSYejbKK1401ETDA.IKK1401D002");

	}

}
