/*******************************************************************************
*	All Rights reserved,Copyright (c) K-Opticom
********************************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JCCejbConvertCharacter
*	ソースファイル名：JCCejbConvertCharacter.java
*	作成者			：EK909308
*	日付			：2011年05月31日
*＜機能概要＞
*	クライアント表示向け文字変換
*	外部システム向け文字変換
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	ｖ1.00.00
*				2023/09/01	FJ)広田		ANK-4463-00-00_【eo定期】サービスサーバリプレース対応_ＳＴ工程まで
********************************************************************************/
package eo.ejb.common;

import java.util.HashMap;

import com.fujitsu.futurity.common.JCMConvertCharacter;

import eo.common.util.JCCFrameworkException;
import eo.ejb.common.JCCejbMojiChgReferenceCache;
import eo.ejb.common.JCCejbMojiChgRuleCache;

/**
 * クライアント表示向け、または外部システム向けの文字変換部品です。
 * 
 * @author 富士通
 */
public class JCCejbConvertCharacter  extends JCMConvertCharacter
{
	
	/**
	 * 外部システム向け文字変換部品です
	 * @param interfaceID 外部システムのインターフェースID
	 * @param inMap	 呼び出し元の情報を格納したHashMap。キーにはAPIの項目名、値には項目名に紐づく文字列をセット。
	 * @throws JCCFrameworkException
	 */
// ANK-4463-00-00 MOD START
	//public static void convertCharacter(String interfaceID, HashMap<String, String> inMap) throws JCCFrameworkException
	public static void convertCharacter2(String interfaceID, HashMap<String, String> inMap) throws JCCFrameworkException
// ANK-4463-00-00 MOD END
	{
		// 文字変換モードが設定されていない場合は何もせずに復帰
		if("1".equals(JCCModelCommon.getApplicationConst("CONV_CHAR_FOR_OUT")) == false)
		{
			return;
		}
		try
		{
			// インターフェースIDのチェック
			if(chkObject(interfaceID))
			{
				throw new JCCFrameworkException("外部インターフェースIDが指定されていません。");
			}
			if(interfaceID.length() != 8)
			{
				throw new JCCFrameworkException("外部インターフェースIDが8桁で指定されていません。");
			}
			// 入力されたマップデータのnullチェック
			if(null == inMap)
			{
				throw new JCCFrameworkException("入力された変換元のマップデータがnullです。");
			}
		}
		catch(JCCFrameworkException jcce)
		{
			throw jcce;
		}
		
		// 文字変換処理
		try
		{
			// アプリケーションプロパティファイルのパスを設定
			JCCejbMojiChgReferenceCache.setPath();
			JCCejbMojiChgRuleCache.setPath();
			
			// 文字変換リファレンス定義から外部インターフェースIDに紐づくAPI項目名のリストを取得
			String strReference = JCCejbMojiChgReferenceCache.getValue(interfaceID);
			// 該当するIDがリファレンスに存在しない場合はここで復帰
			if(chkObject(strReference))
			{
				return;
			}
			
			// リファレンス文字列をタブ文字（または空白）によって分解
			String[] localReference = strReference.split("\t| ");
			
			// 取得したキーリストのフォーマットチェック
			if(chkObject(localReference))
			{
				throw new JCCFrameworkException("文字変換リファレンス定義ファイルのフォーマット誤り。システムIDが未設定。");
			}
			else if(localReference.length < 2)
			{
				throw new JCCFrameworkException("文字変換リファレンス定義ファイルのフォーマット誤り。項目名が未設定。");
			}
						
			// システムIDの取得
			String ruleSystemKey = localReference[0];
			
			// 文字変換ルール定義から変換のキーと値を格納したHashMapを取得
			HashMap<String, Object> ruleMap = JCCejbMojiChgRuleCache.getMap(ruleSystemKey);
			
			// 入力されたHashMap内に存在するキーとリファレンスで指定されたAPI項目名が一致する場合は変換を行う
			for(int i = 1; i < localReference.length; i++)
			{
				String localKey = localReference[i];
				if(inMap.containsKey(localKey) == true)
				{
					inMap.put(localKey, convertCharacter(inMap.get(localKey), ruleMap));
				}
			}
		}
		catch(Exception e)
		{
			String str = e.getMessage();
			throw new JCCFrameworkException(str);
		}
		return;
	}
}