package WEB-INF.classes.wenrgise.common.utility;

import java.rmi.RemoteException;
import java.util.HashMap;
import javax.ejb.CreateException;
import javax.servlet.http.HttpSession;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.ParamUtil;
import wenrgise.common.utility.UserInfo;
import wenrgise.ejb.common.session.UserSession;
import wenrgise.ejb.common.session.UserSessionHome;
import wenrgise.ejb.common.utility.ServiceLocator;
import wenrgise.hrms.ejb.facade.HrmFacade;
import wenrgise.hrms.ejb.facade.HrmFacadeHome;

public class DebugHelper {
  public static void createUserEjb(HttpSession session) throws EnrgiseSystemException {
    try {
      UserSession oUser = (UserSession)session.getAttribute(ParamUtil.getSessionBeanName());
      if (oUser == null) {
        UserSessionHome oUserHome = (UserSessionHome)ServiceLocator.getLocator().getService("HrmUserSession");
        oUser = oUserHome.create();
        UserInfo oUserInfo = new UserInfo();
        oUserInfo.setSiteId("1");
        oUserInfo.setModuleId("4");
        oUserInfo.setUserId("8501000");
        oUserInfo.setCurrentYear("2011");
        oUserInfo.setUserName("HANS RAJ SHARMA");
        oUser.setUserInfo(oUserInfo);
        HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
        HrmFacade oHrmFacade = oHome.create();
        HashMap oMap = new HashMap();
        oMap.put(ParamUtil.getModuleName(), oHrmFacade);
        oUser.setModuleFacade(oMap);
        session.setAttribute(ParamUtil.getSessionBeanName(), oUser);
      } 
    } catch (RemoteException oRmt) {
      throw new EnrgiseSystemException();
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException();
    } catch (Exception oExCc) {
      oExCc.printStackTrace();
      throw new EnrgiseSystemException();
    } 
  }
}
