
package my.com.kfh.enterprise.services.ib115_gold.gold_thirdparty;

import my.com.kfh.enterprise.services.IBEnterpriseServicesWorkspace;
import my.com.kfh.enterprise.services.common.CommonConstants;
import my.com.kfh.error.exception.IBBusinessExceptionExtension;
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.IBDynaBeanManager;
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;


/**
 * Verify the selected account and sets necessary display information for the desired account details into IBDynaBean.
 */
public class IBGold3rdPartyMaintEditConfirmServices extends IBEnterpriseServicesWorkspace
{
	private static Class c_oClass = IBGold3rdPartyMaintEditConfirmServices.class;

	private static String MAINTAINANCE_VIEWBEAN = ThirdPartyGoldTransferTags.THIRDPARTY_GOLD_MAINTENANCE_VIEW;

	/**
	 * Class constructor specifying session object.
	 *
	 * @param m_oIBSessionObjects session object containing all information stored in HTTP session
	 */
	public IBGold3rdPartyMaintEditConfirmServices (IBSessionObjects m_oIBSessionObjects)
	{
		super (m_oIBSessionObjects);
	}

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

		IBDynaBean m_oViewBean = null;
		String m_sAcctHolderName = "";
		String m_sAccountNo = "";

		try
		{
			m_oViewBean = (IBDynaBean) getIBDynaBean ().get (MAINTAINANCE_VIEWBEAN) == null
				? IBDynaBeanManager.createIBDynaBean(MAINTAINANCE_VIEWBEAN, getIBDynaBean ().getActionMapping ())
						: (IBDynaBean) getIBDynaBean ().get (MAINTAINANCE_VIEWBEAN);

			m_sAccountNo = (String) getIBDynaBean ().get (ThirdPartyGoldTransferTags.ACCOUNT_NUMBER);

			m_sAcctHolderName = getESBServices ().getAccountHolderName (m_sAccountNo);
			
			if (DataValidator.isEmptyString (m_sAcctHolderName))
			{
				throw IBErrorHandler.createBusinessException (
						IBBusinessExceptionExtension.GOLDTRANSFER_3RDPARTY_KEY, ThirdPartyGoldTransferTags.VA_ERR_INVALID_ACCOUNT);
			}
			
			m_oViewBean.set (ThirdPartyGoldTransferTags.ACCOUNT_NUMBER_DIS, m_sAccountNo);
			m_oViewBean.set (ThirdPartyGoldTransferTags.NICKNAME_DIS, (String) getIBDynaBean ().get (ThirdPartyGoldTransferTags.NICKNAME));
			m_oViewBean.set (ThirdPartyGoldTransferTags.ACCOUNT_HOLDER_NAME, m_sAcctHolderName);
			m_oViewBean.set (ThirdPartyGoldTransferTags.EMAIL_DIS, (String) getIBDynaBean ().get (ThirdPartyGoldTransferTags.EMAIL));

			getIBDynaBean ().set (MAINTAINANCE_VIEWBEAN, m_oViewBean);
			IBDynaBean m_oServiceInfoBean = (IBDynaBean) m_oViewBean.get (ServiceInfo.SERVICE_INFO_BEAN);
			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 (ThirdPartyGoldTransferTags.NICKNAME);
				if(!DataValidator.isEmptyString(beneName)){
					m_oSMSViewBean.set(CommonConstants.BENE_NAME, beneName.length()>25?beneName.substring(0, 25):beneName);
				}
				getIBSessionObjects().setHttpSessionAttrObject(CommonConstants.SMS_VIEW_BEAN, m_oSMSViewBean);
			}
			
		}
		catch (Exception 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);
	}
}
