package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.DateUtility;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.MessageKey;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.vo.BaseDetailVO;
import wenrgise.common.vo.BaseHeaderVO;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
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.hrms.bean.HrmOrgCntryMstDtlBean;
import wenrgise.hrms.bean.HrmOrgCntryMstHdrBean;
import wenrgise.hrms.vo.HrmOrgCntryMstQVO;

public class HrmOrgCntryMstBO extends HrmBaseBO {
  public HrmOrgCntryMstBO() {}
  
  public HrmOrgCntryMstBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmCountryHdrMetaInfo(HrmOrgCntryMstQVO oHrmOrgCntryMstQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmOrgCntryMstQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmOrgCntryMstQVO.getCountryCode()));
    arylstParameters.add(new DBObject(3, 2, -5));
    arylstParameters.add(new DBObject(4, 2, 93));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_HrCountryHdrCount(?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmCountryHeaderInfo(HrmOrgCntryMstQVO oHrmOrgCntryMstQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList arylstHeaderList = null;
    if (oHrmOrgCntryMstQVO == null)
      oHrmOrgCntryMstQVO = new HrmOrgCntryMstQVO(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmOrgCntryMstQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmOrgCntryMstQVO.getCountryCode()));
    arylstParameters.add(new DBObject(5, 2, -10));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_HrCountryHdrInfo(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmOrgCntryMstHdrBean oCountryHeader = new HrmOrgCntryMstHdrBean();
      oCountryHeader.setCountryCode(oRow.get("COUNTRY_CODE").getString());
      oCountryHeader.setHeaderPrimaryKey(oRow.get("COUNTRY_ID").getString());
      oCountryHeader.setCountryName(oRow.get("NAME").getString());
      arylstHeaderList.add(oCountryHeader);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmCountryDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_HrCountryDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmCountryDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmCountryDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_HrCountryDtlInfo(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmCountryDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmOrgCntryMstDtlBean oCountryDetailBean = new HrmOrgCntryMstDtlBean();
      oCountryDetailBean.setDetailId(oRow.get("CITY_ID").getString());
      oCountryDetailBean.setTxtCityCode(oRow.get("CITY_CODE").getString());
      oCountryDetailBean.setTxtCityName(oRow.get("NAME").getString());
      arylstHrmCountryDetail.add(oCountryDetailBean);
    } 
    return arylstHrmCountryDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "GEN_COUNTRY_MST";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmOrgCntryMstHdrBean oHrmCountryHdrBean = (HrmOrgCntryMstHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "i"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmCountryHdrBean.getCountryCode()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmCountryHdrBean.getCountryName()));
      arylstParameters.add(new DBObject(4, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(6, 1, 12, null));
      arylstParameters.add(new DBObject(7, 2, 12));
      arylstParameters.add(new DBObject(8, 2, 12));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_UpsertHrCountryHdr(?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "u"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmCountryHdrBean.getCountryCode()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmCountryHdrBean.getCountryName()));
      arylstParameters.add(new DBObject(4, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(6, 1, 12, oHrmCountryHdrBean.getHeaderPrimaryKey()));
      arylstParameters.add(new DBObject(7, 2, 12));
      arylstParameters.add(new DBObject(8, 2, 12));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGCOUNTRYMST.proc_UpsertHrCountryHdr(?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } 
    return returnString;
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmOrgCntryMst"))
      saveHrmCountryDetail(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  private void saveHrmCountryDetail(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmOrgCntryMstDtlBean oHrmCountryDtlBean = itrBean.next();
      if (oHrmCountryDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMORGCOUNTRYMST.proc_UpsertHrCountryMst(?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "I"));
        arylstParameters.add(new DBObject(2, 1, 12, null));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmCountryDtlBean.getTxtCityCode()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmCountryDtlBean.getTxtCityName()));
        arylstParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmCountryDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMORGCOUNTRYMST.proc_UpsertHrCountryMst(?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmCountryDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmCountryDtlBean.getTxtCityCode()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmCountryDtlBean.getTxtCityName()));
        arylstParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmCountryDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMORGCOUNTRYMST.proc_DeleteHrCountryMst(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmCountryDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public LovVO getHrmCountryCodeLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("Code ID");
    arylstHeaderList.add("hrm.HrmCountryMaster.countryCode");
    arylstHeaderList.add("hrm.HrmCountryMaster.countryName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMORGSETUPLOV.proc_GetCountryCodeLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("COUNTRY_ID").getString());
      oLOVBean.setDetailField2(oRow.get("COUNTRY_CODE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmOrgCntryMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmOrgCntryMst")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmOrgCntryMstDtlBean oHrmOrgCntryMstDtlBean = itrBean1.next();
          if (!oHrmOrgCntryMstDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatory(oHrmOrgCntryMstDtlBean, iCount, arylstErrorList); 
          iCount++;
        } 
      }  
    reportError(arylstErrorList);
  }
  
  private void checkMandatory(HrmOrgCntryMstDtlBean oHrmOrgCntryMstDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmOrgCntryMstDtlBean.getTxtCityCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmCountryMaster.txtCityCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmOrgCntryMstDtlBean.getTxtCityName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmCountryMaster.txtCityName");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(arylstErrorList);
  }
  
  private void checkMandatoryHeader(HrmOrgCntryMstHdrBean oHrmOrgCntryMstHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmOrgCntryMstHdrBean.getCountryCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmCountryMaster.countryCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmOrgCntryMstHdrBean.getCountryName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmCountryMaster.countryName");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    HrmOrgCntryMstHdrBean oHrmOrgCntryMstHdrBean = (HrmOrgCntryMstHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkUniqueHeader((HrmOrgCntryMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmOrgCntryMst")) {
          EnrgiseUtil.checkDuplicate(arylstDetailBeanArray, "txtCityCode", "hrm.HrmCountryMaster.txtCityCode", arylstErrorList, true);
          EnrgiseUtil.checkDuplicate(arylstDetailBeanArray, "txtCityName", "hrm.HrmCountryMaster.txtCityName", arylstErrorList, true);
          checkUniqueDtl(oBaseHeaderBean.getHeaderPrimaryKey(), arylstDetailBeanArray);
        }   
    reportError(arylstErrorList);
  }
  
  private void checkUniqueDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParams = new ArrayList();
    ArrayList oErrorList = new ArrayList();
    int count = 0;
    Iterator oIt1 = oDetailBeanArray.iterator();
    while (oIt1.hasNext()) {
      HrmOrgCntryMstDtlBean oHrmOrgCntryMstDtlBean = oIt1.next();
      String sQuery = String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(" Select CITY_ID as ID from GEN_CITY_MST where CITY_CODE='").concat(String.valueOf(oHrmOrgCntryMstDtlBean.getTxtCityCode()))).concat(String.valueOf("'"))).concat(String.valueOf(" and CNTRY_ID='"))).concat(String.valueOf(sHeaderPrimaryKey))).concat(String.valueOf("'"));
      System.out.println(sQuery);
      DBUtilitiesBean oBean = new DBUtilitiesBean();
      ArrayList oList = oBean.executeQuery(sQuery);
      Iterator oIt = oList.iterator();
      if (oIt.hasNext()) {
        QueryRow oRow = oIt.next();
        if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmOrgCntryMstDtlBean.getDetailId())) {
          MessageKey oMessageKey = new MessageKey("hrm.HrmCountryMaster.txtCityCode");
          oParams = new ArrayList();
          oParams.add(oMessageKey);
          oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.uniqueConstraintViolated", oParams, "E"));
        } 
      } 
    } 
    reportError(oErrorList);
  }
  
  public void checkRefferenceKey(String sSkillHeaderId) throws EnrgiseApplicationException, EnrgiseSystemException {
    System.out.println("To be added");
  }
  
  private void checkUniqueHeader(HrmOrgCntryMstHdrBean oHrmOrgCntryMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(String.valueOf(" Select COUNTRY_ID as ID from GEN_COUNTRY_MST where COUNTRY_CODE='").concat(String.valueOf(oHrmOrgCntryMstHdrBean.getCountryCode()))).concat(String.valueOf("'"));
    System.out.println(sQuery);
    ArrayList arylstList1 = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstList = oBean.executeQuery(sQuery);
    Iterator itrBean = arylstList.iterator();
    if (itrBean.hasNext()) {
      QueryRow oRow = itrBean.next();
      if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmOrgCntryMstHdrBean.getHeaderPrimaryKey())) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstList1.add(new EnrgiseMessageKeyException("wenrgise.common.uniqueConstraintViolated", arylstParam));
      } 
    } 
    reportError(arylstList1);
  }
}
