/*********************************************************************
*	All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JKKejbMapPkgCall
*	ソースファイル名：JKKejbMapPkgCall.java
*	作成者			：富士通
*	日付			：2011年8月11日
*＜機能概要＞
*	地図パッケージ呼出部品のクラス
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	v1.00.00	2011/08/11	富士通		新規作成
*
**********************************************************************/

package eo.ejb.common;

import java.util.HashMap;

import com.fujitsu.futurity.model.base.CAANRuntimeException;
import com.fujitsu.futurity.model.common.JCMAPLConstMgr;

import eo.common.util.JKKURLconnection;
import eo.common.util.JKKXmlParser;

/**
 * <p>
 * 地図パッケージ呼出部品のクラスです。
 * </p>
 * @author 富士通
 */
public class JKKejbMapPkgCall
{
	/** エリアチェック結果(eo光ネット) */
	private static final String KEY_AREAEONET = "AreaEoNet";
	/** エリアチェック結果(eo光電話) */
	private static final String KEY_AREAEOTEL = "AreaEoTel";
	/** エリアチェック結果(eo光テレビ) */
	private static final String KEY_AREAEOTV = "AreaEoTv";
	/** エリアチェック結果(ビジネス光) */
	private static final String KEY_AREAEOBIZ = "AreaEoBiz";
	/** エリアチェック結果(eo光ネット)詳細 */
	private static final String KEY_AREAEONETDTL = "AreaEoNetDtl";
	/** エリアチェック結果(eo光テレビ)詳細 */
	private static final String KEY_AREAEOTVDTL = "AreaEoTvDtl";
	/** 文字コード */
	private static final String ENCORDING = "UTF-8";
	/** 審査（エリアチェック）アドレス取得キー */
	private static final String KK_JDG_AREACHK_AD = "KK_JDG_AREACHK_AD";

	/**
	 * コンストラクタです。
	 */
	public JKKejbMapPkgCall()
	{
	}

	/**
	 * <p>
	 * 自動照査する中心位置（お客様位置）をもとに、エリアチェック結果を返却します。
	 * </p>
	 * 
	 * @param srvId   利用業務ID
	 * @param lgtd    お客様位置(経度)
	 * @param lttd    お客様位置(緯度)
	 * @return        エリアチェック結果(HashMap)
	 * @throws Exception
	 */
	public HashMap<String, String> areaCheck(String srvId, String lgtd, String lttd)
	{
		try {
			HashMap<String, String> hmResult = new HashMap<String, String>();

			//XMLに変換する項目をMapに設定します
			HashMap<String, Object> xml = new HashMap<String, Object>();
			HashMap<String, Object> envlope = new HashMap<String, Object>();
			HashMap<String, Object> body = new HashMap<String, Object>();
			HashMap<String, Object> getPoint = new HashMap<String, Object>();
			HashMap<String, String> kmkMap = new HashMap<String, String>();

			//XML宣言をマップに設定
			xml.put("?xml version=\"1.0\" encoding=\"utf-8\"?", envlope);
			//SOAPをマップに設定
			envlope.put("soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
					"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
					" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"", body);
			//属性の設定
			body.put("soap:Body", getPoint);
			//Link
			getPoint.put("getPoints xmlns=\"http://tempuri.org/\"", kmkMap);
			//利用業務IDをマップに設定
			kmkMap.put("SrvId", srvId);
			//経度を経度情報マップに設定
			kmkMap.put("CnsmrLng", lgtd);
			//緯度を緯度マップに設定
			kmkMap.put("CnsmrLat", lttd);
			//XML文に変換します
			String xmlParam = JKKXmlParser.convertXml(envlope);
			//プロパティファイルから外部インタフェースに接続するURLを取得します
			String apiUrl = JCMAPLConstMgr.getString(KK_JDG_AREACHK_AD);
			//XML宣言をマップに設定
			xmlParam = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xmlParam;
			//外部インタフェース(共通(地図))に接続します。
			//XML文字列をMapに変換します。
			HashMap<String, Object> areaChkRslt = (HashMap<String, Object>)JKKXmlParser.parseXml(JKKURLconnection.setUrlConnection(xmlParam, apiUrl, ENCORDING));
			//返却されたMapから情報を取得します
			envlope = (HashMap<String, Object>)areaChkRslt.get("soap:Envelope");
			body = (HashMap<String, Object>)envlope.get("soap:Body");
			getPoint = (HashMap<String, Object>)body.get("getPointsResponse");
			kmkMap = (HashMap<String, String>)getPoint.get("getPointsResult");

			//エリアチェック結果(eo光ネット)
			hmResult.put(KEY_AREAEONET, kmkMap.get(KEY_AREAEONET));
			//エリアチェック結果(eo光電話)
			hmResult.put(KEY_AREAEOTEL, kmkMap.get(KEY_AREAEOTEL));
			//エリアチェック結果(eo光テレビ)
			hmResult.put(KEY_AREAEOTV, kmkMap.get(KEY_AREAEOTV));
			//エリアチェック結果(ビジネス光))
			hmResult.put(KEY_AREAEOBIZ, kmkMap.get(KEY_AREAEOBIZ));
			//エリアチェック結果(eo光ネット)詳細
			hmResult.put(KEY_AREAEONETDTL, kmkMap.get(KEY_AREAEONETDTL));
			//エリアチェック結果eo光テレビ)詳細
			hmResult.put(KEY_AREAEOTVDTL, kmkMap.get(KEY_AREAEOTVDTL));

			return hmResult;
			
		} catch (Exception e) {
			throw new CAANRuntimeException();
		}

	}
}
