package wenrgise.workflow.ejb.facade;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Logger;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.UserInfo;
import wenrgise.workflow.bean.WflDtlsHdrBean;
import wenrgise.workflow.core.WflDocumentInfo;
import wenrgise.workflow.core.WflService;
import wenrgise.workflow.core.WflStatus;
import wenrgise.workflow.ejb.business.DocHistoryDtlBO;
import wenrgise.workflow.ejb.business.WorkFlowCommonBO;
import wenrgise.workflow.utility.WorkFlowServiceFactory;

public class WflCommFacadeBean implements SessionBean {
  public static Logger log = Logger.getLogger("wenrgise.workflow.ejb.facade.WflCommFacadeBean");
  
  public void ejbCreate() {}
  
  public void ejbActivate() {}
  
  public void ejbPassivate() {}
  
  public void ejbRemove() {}
  
  public void setSessionContext(SessionContext ctx) {}
  
  public UserInfo getLoginUserInfo(String sEmpId, String sSiteId) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO oBo = new WorkFlowCommonBO();
    return oBo.getLoginUserInfo(sEmpId, sSiteId);
  }
  
  public String getDocumentTypeId(String documentType) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO oBo = new WorkFlowCommonBO();
    return oBo.getDocumentTypeId(documentType);
  }
  
  public String getActivityId(String activity) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO oBo = new WorkFlowCommonBO();
    return oBo.getActivityId(activity);
  }
  
  public String getActivityCode(String activityId) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO oBo = new WorkFlowCommonBO();
    return oBo.getActivityCode(activityId);
  }
  
  public String getRouteDtlId(WflDocumentInfo docInfo) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO oBo = new WorkFlowCommonBO();
    return oBo.getRouteDtlId(docInfo);
  }
  
  public boolean canDo(WflDocumentInfo docInfo) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (docInfo == null)
      throw new EnrgiseApplicationException(); 
    if (docInfo.getCreator() == null)
      throw new EnrgiseApplicationException(); 
    if (docInfo.getCreator().getLoginSite() == null)
      throw new EnrgiseApplicationException(); 
    WflService wflService = WorkFlowServiceFactory.getInstance().getWorkFlowService();
    return wflService.canDo(docInfo);
  }
  
  public WflStatus process(WflDocumentInfo docInfo) throws EnrgiseApplicationException, EnrgiseSystemException {
    log.severe("step1");
    if (docInfo == null)
      throw new EnrgiseApplicationException(); 
    log.severe("step2");
    if (docInfo.getCreator() == null)
      throw new EnrgiseApplicationException(); 
    log.severe("step3");
    if (docInfo.getCreator().getLoginSite() == null)
      throw new EnrgiseApplicationException(); 
    log.severe("step4");
    WflService wflService = WorkFlowServiceFactory.getInstance().getWorkFlowService();
    log.severe("step5");
    return wflService.process(docInfo);
  }
  
  public ArrayList getWorkListInfo(String sEmpId) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO wflCommBO = new WorkFlowCommonBO();
    return wflCommBO.getWorkListInfo(sEmpId);
  }
  
  public WflDtlsHdrBean getWorkFlowDtlsInfo(String sWorkListId) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO wflCommBO = new WorkFlowCommonBO();
    return wflCommBO.getWorkFlowDtlsInfo(sWorkListId);
  }
  
  public ArrayList getDocHistDtl(String sDocID, String sDocType, String sModuleID) throws EnrgiseApplicationException, EnrgiseSystemException {
    DocHistoryDtlBO oBo = new DocHistoryDtlBO();
    return oBo.getDocHistDtl(sDocID, sDocType, sModuleID);
  }
  
  public String closeWorkList(WflDtlsHdrBean oWflDtlsHdrBean, Timestamp oWhenPicked, ArrayList oDetailBeanArray, Timestamp oDetailPicked, UserInfo oUserInfo) throws EnrgiseApplicationException, EnrgiseSystemException {
    WorkFlowCommonBO wflCommBO = new WorkFlowCommonBO();
    return wflCommBO.closeNotification(oWflDtlsHdrBean);
  }
}
