/**
 * Copyright (c) 2009 Penril Datability (SEA) Sdn Bhd All rights reserved.
 *
 * This software is copyrighted. Under the copyright laws, this software
 * may not be copied, in whole or in part, without prior written consent
 * of Penril Datability (SEA) Sdn Bhd or its assignees. This software is
 * provided under the terms of a license between Penril Datability (SEA)
 * Sdn Bhd and the recipient, and its use is subject to the terms of that
 * license.
 */

package my.com.kfh.enterprise.services.ib104_fundtransfer.ftt;

import java.util.List;

import my.com.kfh.enterprise.services.IBUtils;
import my.com.kfh.enterprise.services.common.CommonConstants;
import my.com.kfh.enterprise.services.ib104_fundtransfer.constant.FTTConstants;
import my.com.kfh.error.exception.IBGenericException;
import my.com.kfh.error.exception.IBServiceException;
import my.com.kfh.error.handler.CommonErrorCode;
import my.com.kfh.error.handler.IBErrorHandler;
import my.com.kfh.web.utils.DataValidator;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBSessionObjects;
import my.com.kfh.web.utils.IBTimer;
import my.com.kfh.web.utils.constant.ServiceInfo;

public class IBFavFttEditConfirmServices extends IBGenericFttServices
{
	private static Class c_oClass = IBFavFttEditConfirmServices.class;

	public IBFavFttEditConfirmServices (IBSessionObjects m_oIBSessionObjects)
	{
		super (m_oIBSessionObjects);
	}

	public void executeServices () throws IBGenericException
	{
		String m_sMethodName = "executeServices";
		IBTimer m_oTimer = IBLogger.logBSFNMethodEnteringMessage (c_oClass, m_sMethodName);

		IBDynaBean m_oViewBean = null;
		IBDynaBean m_oServiceInfoBean = null;
		String m_sFttCountryIndex = null;
		List m_alFttCountryList = null;

		try
		{
			m_oViewBean = (IBDynaBean) getIBDynaBean ().get (FTTConstants.FAV_FTT_DETAILS_VIEW_BEAN);

			m_oServiceInfoBean = IBUtils.getServiceInfoBean (ServiceInfo.FUND_TRANSFER_FTT_FAV_EDIT, getIBDynaBean (), getIBSessionObjects (), true);

			m_sFttCountryIndex = (String) getIBDynaBean ().get (FTTConstants.FBEAN_FTT_COUNTRY);
			int m_iFttCountryIndex = Integer.parseInt(m_sFttCountryIndex);
			m_alFttCountryList = (List) m_oViewBean.get (FTTConstants.VBEAN_COUNTRY_LIST);
			String m_sFTTCountryName = (String) ((IBDynaBean)m_alFttCountryList.get (m_iFttCountryIndex)).get (FTTConstants.VBEAN_COUNTRY_DISP);

			getIBDynaBean ().set (FTTConstants.FBEAN_FTT_COUNTRY_NAME, m_sFTTCountryName);

			m_oViewBean.set (FTTConstants.VBEAN_FTT_COUNTRY, m_sFTTCountryName);

			m_oViewBean.set (ServiceInfo.SERVICE_INFO_BEAN, m_oServiceInfoBean);

			getIBDynaBean ().set (FTTConstants.FAV_FTT_DETAILS_VIEW_BEAN, m_oViewBean);
			
			if (((Boolean) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_TAC_REQUIRED)).booleanValue ())
			{
				IBDynaBean m_oSMSViewBean = (IBDynaBean) getIBSessionObjects().getHttpSessionAttrObject(CommonConstants.SMS_VIEW_BEAN);
				String beneName = (String) getIBDynaBean ().get (FTTConstants.FBEAN_BENEFICIARY_NAME);
				if(!DataValidator.isEmptyString(beneName)){
					beneName = beneName.length()>25?beneName.substring(0, 25):beneName;
				}
				m_oSMSViewBean.set(CommonConstants.BENE_NAME, beneName);
				getIBSessionObjects().setHttpSessionAttrObject(CommonConstants.SMS_VIEW_BEAN, m_oSMSViewBean);
			}
		}
		catch(IBGenericException e)
		{
			IBLogger.writeLog (IBErrorHandler.generateErrorMessage (e));
			if (e instanceof IBGenericException)
			{
				throw (IBGenericException) e;
			}
			throw IBErrorHandler.createServiceException(
					IBServiceException.GENERAL_SERVICE_ERROR, true,
					new String[] {CommonErrorCode.GENERIC_CODE, "", "", "", IBErrorHandler.generateErrorMessage(e)}, c_oClass);
		}

		IBLogger.logBSFNMethodLeavingMessage (c_oClass, m_sMethodName, m_oTimer);
	}

}
