package wenrgise.hrms.helper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.workflow.bean.WflWorkListInfoBean;
import wenrgise.workflow.service.WorkFlowService;
import wenrgise.workflow.utility.Node;

public class WorkFlowSimulator implements WorkFlowService {
  public WflWorkListInfoBean getWorkListInfo(String sWorkListId) throws EnrgiseApplicationException, EnrgiseSystemException {
    WflWorkListInfoBean wflWorkListInfoBean = new WflWorkListInfoBean();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    ArrayList oParameters = new ArrayList();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sWorkListId));
    oParameters.add(new DBObject(2, 2, -10));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "WFLWORKLIST.proc_GetWorkListInfo(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      count++;
      oRow = oIt.next();
      wflWorkListInfoBean.setDocId(oRow.get("doc_id").getString());
      wflWorkListInfoBean.setDocTypeCode(oRow.get("doc_type_code").getString());
      wflWorkListInfoBean.setONode(new Node(oRow.get("lane").getString(), oRow.get("level_number").getString()));
      wflWorkListInfoBean.setCreatorempId(oRow.get("creator_emp_id").getString());
      wflWorkListInfoBean.setLastEmpId(oRow.get("last_approver_emp_id").getString());
      wflWorkListInfoBean.setSiteId(oRow.get("created_site_id").getString());
      wflWorkListInfoBean.setStatus(oRow.get("status").getString());
      wflWorkListInfoBean.setAssignedOn(oRow.get("last_assigned_date").getString());
      wflWorkListInfoBean.setRequestorEmpId(oRow.get("pending_for_emp_id").getString());
    } 
    return wflWorkListInfoBean;
  }
}
