Commit 72414180 authored by vlagad's avatar vlagad

Changed Related to migrating pb comp to Java Comp for Obj Name workshift rotate screen

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@206807 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1339828a
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.w3c.dom.Document;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
public class WorkShiftRotateIc extends ValidatorEJB
{
E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = "";
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
BaseLogger.log("3",null,null,"ErrString :" + errString);
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception :AdChangeIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
BaseLogger.log("2",null,null,"Returning from EmpITDeclarationIC wfValData");
return errString;
}
public String itemChanged(String xmlString, String xmlStringHdr, String xmlStringAll, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null, domHdr = null, domAll = null;
String valueXmlString = "";
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlStringHdr != null && xmlStringHdr.trim().length() > 0)
{
domHdr = genericUtility.parseString(xmlStringHdr);
}
if (xmlStringAll != null && xmlStringAll.trim().length() > 0)
{
domAll = genericUtility.parseString(xmlStringAll);
}
valueXmlString = itemChanged(dom, domHdr, domAll, objContext, currentColumn, editFlag, xtraParams);
}
catch (Exception e)
{
BaseLogger.log("0",null,null,"Exception [" + this.getClass().getSimpleName() + "] : [itemChanged(S)] " + e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
BaseLogger.log("2",null,null,"InSide itemChanges in WorkShiftRotate.................");
String sql = "",empFname = "", empLname = "",loginSiteCode="",descr="",empMname="";
String empCodeFrom ="",empCodeTo ="", userId = "",userLevel ="",mval="";
int currentFormNo = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer valueXmlString = new StringBuffer();
try
{
conn = getConnection();
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
BaseLogger.log("3",null,null,"LoginSiteCode ["+loginSiteCode+"] userId ["+userId+"] ");
sql = "select usr_lev from users where code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userId);
rs = pstmt.executeQuery();
if (rs.next())
{
userLevel = checkNull(rs.getString("usr_lev"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
BaseLogger.log("3",null,null,"[" + this.getClass().getSimpleName() + "] [itemChanged(D)]:currentFormNo:" + currentFormNo);
BaseLogger.log("3",null,null,"currentColumn:::::" + currentColumn);
valueXmlString = new StringBuffer("<?xml version=\"1.0\" encoding=''?>\r\n<Root>\r\n<header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</header>\r\n");
switch (currentFormNo)
{
case 1:
{
valueXmlString.append("<Detail1>\r\n");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
sql = "select descr from site where site_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
BaseLogger.log("3",null,null,"descr is == "+descr);
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<site_code__fr><![CDATA[" +loginSiteCode+ "]]></site_code__fr>\r\n");
valueXmlString.append("<site_code__to><![CDATA[" +loginSiteCode+ "]]></site_code__to>\r\n");
valueXmlString.append("<site_code_fr_descr><![CDATA[" +descr+ "]]></site_code_fr_descr>\r\n");
valueXmlString.append("<site_code_to_descr><![CDATA[" +descr+ "]]></site_code_to_descr>\r\n");
valueXmlString.append("<dept_code__fr><![CDATA[00]]></dept_code__fr>\r\n");
valueXmlString.append("<dept_code__to><![CDATA[ZZ]]></dept_code__to>\r\n");
empCodeFrom = checkNull(genericUtility.getColumnValue("emp_code__fr", dom));
if( "".equalsIgnoreCase(empCodeFrom) && empCodeFrom.length() == 0 )
{
valueXmlString.append("<emp_code__fr><![CDATA[00]]></emp_code__fr>\r\n");
valueXmlString.append("<fr_emp_name><![CDATA[]]></fr_emp_name>\r\n");
}
else
{
sql = "select emp_fname,emp_mname, emp_lname from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCodeFrom);
rs = pstmt.executeQuery();
if (rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empMname = checkNull(rs.getString("emp_mname"));
empLname = checkNull(rs.getString("emp_lname"));
}
valueXmlString.append("<fr_emp_name protect=\"1\"><![CDATA["+empFname+" "+empMname+" "+empLname+"]]></fr_emp_name>\r\n");
}
empCodeTo = checkNull(genericUtility.getColumnValue("emp_code__to", dom));
if( "".equalsIgnoreCase(empCodeTo) && empCodeTo.length() == 0 )
{
valueXmlString.append("<emp_code__to><![CDATA[ZZ]]></emp_code__to>\r\n");
valueXmlString.append("<to_emp_name><![CDATA[]]></to_emp_name>\r\n");
}
else
{
sql = "select emp_fname,emp_mname, emp_lname from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCodeTo);
rs = pstmt.executeQuery();
if (rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empMname = checkNull(rs.getString("emp_mname"));
empLname = checkNull(rs.getString("emp_lname"));
}
valueXmlString.append("<to_emp_name protect=\"1\"><![CDATA["+empFname+" "+empMname+" "+empLname+"]]></to_emp_name>\r\n");
}
valueXmlString.append("<shift_pattern protect=\"1\"><![CDATA[N]]></shift_pattern>\r\n");
if(Integer.parseInt(userLevel) > 1)
{
valueXmlString.append("<site_code__fr protect=\"1\"><![CDATA[" +loginSiteCode+ "]]></site_code__fr>\r\n");
valueXmlString.append("<site_code__to protect=\"1\"><![CDATA[" +loginSiteCode+ "]]></site_code__to>\r\n");
}
}
else if("shift_pattern".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("shift_pattern", dom));
if(mval.equalsIgnoreCase("Y"))
{
valueXmlString.append("<shift_pattern ><![CDATA[N]]></shift_pattern>\r\n");
}
else
{
valueXmlString.append("<shift_pattern protect=\"1\"><![CDATA[N]]></shift_pattern>\r\n");
}
}
else if("emp_code__fr".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("emp_code__fr", dom));
sql = "select emp_fname,emp_mname, emp_lname from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empMname = checkNull(rs.getString("emp_mname"));
empLname = checkNull(rs.getString("emp_lname"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<fr_emp_name protect=\"1\"><![CDATA["+empFname+" "+empMname+" "+empLname+"]]></fr_emp_name>\r\n");
}
else if("emp_code__to".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("emp_code__to", dom));
sql = "select emp_fname,emp_mname, emp_lname from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empMname = checkNull(rs.getString("emp_mname"));
empLname = checkNull(rs.getString("emp_lname"));
}
rs=null;pstmt=null;
valueXmlString.append("<to_emp_name protect=\"1\"><![CDATA["+empFname+" "+empMname+" "+empLname+"]]></to_emp_name>\r\n");
}
else if("dept_code__fr".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("dept_code__fr", dom));
sql = "select descr from department where dept_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
rs=null;pstmt=null;
valueXmlString.append("<dept_code_fr_descr protect=\"1\"><![CDATA["+descr+"]]></dept_code_fr_descr>\r\n");
}
else if("dept_code__to".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("dept_code__to", dom));
sql = "select descr from department where dept_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
rs=null;pstmt=null;
valueXmlString.append("<dept_code_to_descr protect=\"1\"><![CDATA["+descr+"]]></dept_code_to_descr>\r\n");
}
else if("site_code__fr".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("site_code__fr", dom));
sql = "select descr from site where site_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
rs=null;pstmt=null;
valueXmlString.append("<site_code_fr_descr protect=\"1\"><![CDATA["+descr+"]]></site_code_fr_descr>\r\n");
}
else if("site_code__to".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("site_code__to", dom));
sql = "select descr from site where site_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
rs=null;pstmt=null;
valueXmlString.append("<site_code_to_descr protect=\"1\"><![CDATA["+descr+"]]></site_code_to_descr>\r\n");
}
else if("shift_to".equalsIgnoreCase(currentColumn))
{
mval = checkNull(genericUtility.getColumnValue("shift_to", dom));
sql = "select descr from workshft where shift = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mval);
rs = pstmt.executeQuery();
if (rs.next())
{
descr = checkNull(rs.getString("descr"));
}
rs=null;pstmt=null;
valueXmlString.append("<shift_to_descr protect=\"1\"><![CDATA["+descr+"]]></shift_to_descr>\r\n");
}
valueXmlString.append("</Detail1>\r\n");
}
break;
}
valueXmlString.append("</Root>\r\n");
}
catch (Exception e)
{
BaseLogger.log("0",null,null,"Exception in EJB["+this.getClass().getSimpleName()+"]:[" + e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
BaseLogger.log("3",null,null,"Closed all Database Resource...!");
}
catch (Exception e)
{
BaseLogger.log("0",null,null,"Exception in EJB["+this.getClass().getSimpleName()+"]::itemChanged::[" + e.getMessage()+"]");
throw new ITMException(e);
}
}
BaseLogger.log("2",null,null,"Itemchange ::==== ["+valueXmlString.toString()+"]");
return valueXmlString.toString();
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
}
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.BaseLogger;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.bean.adm.LogWriterDatabase;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
public class WorkShiftRotatePrc extends ProcessEJB
{
E12GenericUtility genericUtility = new E12GenericUtility();
public String process(String xmlString,String xmlString1,String objContext,String xtraParams) throws RemoteException,ITMException
{
BaseLogger.log("2",null,null,"InSide WorkShiftRotateProcess.................");
Document detailDom = null;
Document headerDom = null;
String retStr = "";
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
BaseLogger.log("0",null,null,"headerDom" + xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString1);
BaseLogger.log("0",null,null,"detailDom" + xmlString1);
}
retStr = process(headerDom, detailDom, objContext, xtraParams);
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception In WorkShiftRotateProcess 1 "+e.getMessage());
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String objContext, String xtraParams)throws RemoteException, ITMException
{
String retStr="";
Connection con=null;
try
{
if(con==null)
{
con=getConnection();
con.setAutoCommit(false);
}
retStr=process(headerDom, detailDom, objContext, xtraParams, con);
}
catch(Exception e)
{
BaseLogger.log("0",null,null," Exception WorkShiftRotateProcess 2"+e.getMessage());
}
finally
{
try
{
con.close();
con=null;
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception In WorkShiftRotateProcess 3"+e.getMessage());
}
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams, Connection conn) throws RemoteException,ITMException
{
String errorString = "";
LogWriterDatabase logWriter = new LogWriterDatabase();
Connection logConn = null;
try
{
logConn = getConnection();
logWriter.setTotalRows(0);
logWriter.setRowsProcessed(0);
logWriter.setRowsIgnored(0);
logWriter.setRowsRejected(0);
errorString = processData(headerDom, detailDom, xtraParams,logWriter, conn, logConn);
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception In WorkShiftRotateProcess P5"+e.getMessage());
try
{
conn.rollback();
}
catch(Exception e1){}
throw new ITMException(e);
}
finally
{
try
{
if(logConn != null)
{
logConn.close();
logConn = null;
}
BaseLogger.log("0",null,null,"Finally Executed In WorkShiftRotateProcess P5");
}
catch(Exception se){
}
}
return errorString;
}
public String processData(Document headerDom , Document detailDom,String xtraParams ,LogWriterDatabase logWriter ,Connection conn, Connection logConn )
{
BaseLogger.log("2",null,null,"Inside ProcessData.......................");
String errorString = "",empCodeFr="",empCodeTo,siteCodeFr="",siteCodeTo="",deptCodeFr="",deptCodeTo="",fromDateStr="",toDateStr="";
String shiftPattern ="",toShift="", logStr ="",objName="",chgTerm="",loginSite="",sql="",errCode="";
String empCode ="",empFname="",empLname="",workShift="",shiftRot="",holTblNo="",relieveDatestr="", realShift ="";;
String userId ="",ldToDateStr = "";;
PreparedStatement pStmt = null;
int count =0,cntr = 0;
ResultSet rs = null,rs1=null;;
StringBuilder sqlQuery = new StringBuilder();
AdmCommon admCommon = new AdmCommon();
Timestamp currDate = null,relieveDate= null,fromDate = null,toDate = null,tempFromDate=null,tempToDate = null,lastDate =null;
Timestamp ldToDate= null,toDateFilter=null, procDate= null,tempDate=null;
Timestamp ldFromDate = null,holDate= null;
HashMap<String, String> gbflogWriterMap = null;
java.util.ArrayList<Timestamp> sortedDateList=new java.util.ArrayList<Timestamp>();
TreeMap<Timestamp,HashMap<String, Object>> sortedDateMap = new TreeMap<>();
boolean isError = false ;
try
{
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
chgTerm = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));
loginSite = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
logConn = getConnection();//Connection for LogWriter
objName = getObjNameFromDom(headerDom, "objName");
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(CommonConstants.APPL_DATE_FORMAT);
String currentDatestr = formatter.format(now.getTime());
if(currentDatestr != null && currentDatestr.trim().length() > 0)
{
currDate = getTimeStampValue(currentDatestr);
}
BaseLogger.log("3",null,null,"currDate "+currDate);
siteCodeFr = checkNull(genericUtility.getColumnValue("site_code__fr", headerDom));
siteCodeTo = checkNull(genericUtility.getColumnValue("site_code__to", headerDom));
empCodeTo = checkNull(genericUtility.getColumnValue("emp_code__to", headerDom));
empCodeFr = checkNull(genericUtility.getColumnValue("emp_code__fr", headerDom));
deptCodeFr = checkNull(genericUtility.getColumnValue("dept_code__fr", headerDom));
deptCodeTo = checkNull(genericUtility.getColumnValue("dept_code__to", headerDom));
fromDateStr = checkNull(genericUtility.getColumnValue("date__fr", headerDom));
toDateStr = checkNull(genericUtility.getColumnValue("date__to", headerDom));
if(fromDateStr.length() > 0)
{
fromDate = getTimeStampValue(fromDateStr);
}
if(toDateStr.length() > 0)
{
toDate = getTimeStampValue(toDateStr);
}
if( empCodeFr.length() == 0)
empCodeFr ="00";
if( empCodeTo.length() == 0)
empCodeTo ="ZZZZZ";
if( siteCodeFr.length() == 0)
siteCodeFr ="00";
if( siteCodeTo.length() == 0)
siteCodeTo ="ZZZZZ";
if( deptCodeFr.length() == 0)
deptCodeFr ="00";
if( deptCodeTo.length() == 0)
deptCodeTo ="ZZZZZ";
BaseLogger.log("0",null,null,"empCodeFr ["+empCodeFr+"] empCodeTo["+empCodeTo+"] siteCodeFr["+siteCodeFr+"] siteCodeTo["+siteCodeTo+"] ");
BaseLogger.log("0",null,null,"deptCodeFr ["+deptCodeFr+"] deptCodeTo["+deptCodeTo+"] fromDate["+fromDateStr+"] toDate["+toDateStr+"]");
logWriter.setCurrentProcess("WorkShiftRotate");
logWriter.setActivity("WorkShiftRotate");
logWriter.setProcessId("WorkShiftRotate");
logWriter.setFileNameStartWith("WORKSHIFT");
gbflogWriterMap = new HashMap<String, String>();
gbflogWriterMap.put("objName", objName);
gbflogWriterMap.put("currentProcess", logWriter.getCurrentProcess());
gbflogWriterMap.put("activity", logWriter.getActivity());
gbflogWriterMap.put("processId", logWriter.getProcessId());
gbflogWriterMap.put("userId", userId);
gbflogWriterMap.put("loginSite", loginSite);
gbflogWriterMap.put("xtraParams", xtraParams);
gbflogWriterMap.put("fileNameStartName", logWriter.getFileNameStartWith());
shiftPattern = checkNull(genericUtility.getColumnValue("shift_pattern", headerDom));
if(("Y").equalsIgnoreCase(shiftPattern))
{
toShift = checkNull(genericUtility.getColumnValue("shift_to", headerDom));
for(int i=0; i < (5-toShift.length());i++)
{
toShift = toShift + " ";
}
}
logWriter = (LogWriterDatabase) admCommon.initializeLogWriter(gbflogWriterMap,headerDom, logConn);
int i = logWriter.getlogWriterFlag();
if(i < 0)
{
admCommon.gfLogWriter(logWriter,logConn);
//return is_errxml;
}
if(siteCodeFr.equalsIgnoreCase(siteCodeTo))
{
logStr = "Processing Started for Site: " + siteCodeFr;
}
else
{
logStr = "Processing Started for Sites between: " + siteCodeFr + " To: " + siteCodeTo;
}
admCommon.gbfErrWrite("", empCode, "", "", "I", logWriter, logConn);
// Modified by Piyush on 23/10/2012 [To avoid generating shift after relieve date CCF No.: COR10/C252 - AD01SUN037 and ADM6/0136 - AD78SUN020 ].Start
toDateFilter = toDate ;
// Modified by Piyush on 23/10/2012 [To avoid generating shift after relieve date CCF No.: COR10/C252 - AD01SUN037 and ADM6/0136 - AD78SUN020 ].End
if( siteCodeFr.length() > 0 )
{
sqlQuery.append(" select emp_code,emp_fname,emp_lname,work_shift,shift_rot,hol_tblno,relieve_date from employee ");
sqlQuery.append(" where ( employee.emp_code >= ?) and ");
sqlQuery.append(" (employee.emp_code <= ?) and ");
sqlQuery.append(" (employee.dept_code <= ?) and ");
sqlQuery.append(" (employee.dept_code <= ?) and ");
sqlQuery.append(" (employee.work_site >= ?) and ");
sqlQuery.append(" (employee.work_site <= ?) and ");
sqlQuery.append(" (employee.shift_rot = ?) and ");
sqlQuery.append(" (nvl(employee.status,' ') <> ?) ");
pStmt = conn.prepareStatement(sqlQuery.toString());
pStmt.setString(1, empCodeFr);
pStmt.setString(2, empCodeTo);
pStmt.setString(3, deptCodeFr);
pStmt.setString(4, deptCodeTo);
pStmt.setString(5, siteCodeFr);
pStmt.setString(6, siteCodeTo);
pStmt.setString(7, "Y");
pStmt.setString(8, "S");
rs = pStmt.executeQuery();
while(rs.next())
{
empCode = checkNull(rs.getString("emp_code"));
empFname = checkNull(rs.getString("emp_fname"));
empLname = checkNull(rs.getString("emp_lname"));
workShift = checkNull(rs.getString("work_shift"));
shiftRot = checkNull(rs.getString("shift_rot"));
holTblNo = checkNull(rs.getString("hol_tblno"));
relieveDatestr = checkNull(rs.getString("relieve_date"));
BaseLogger.log("3",null,null,"empCode ["+empCode+"] empFname["+empFname+"] empLname["+empLname+"] workShift["+workShift+"] shitRot["+shiftRot+"] holTblNo["+holTblNo+"] relieveDatestr["+relieveDatestr+"]");
toDate = toDateFilter; // As toDate may get changed due to relieve date hence reset is required
if(relieveDatestr != null && relieveDatestr.trim().length() > 0)
{
relieveDate = Timestamp.valueOf(relieveDatestr);
}
if( relieveDate != null && relieveDate.compareTo(toDate) <= 0)
{
sql = "delete from work_shift where emp_code = ? and from_dt > ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, relieveDate);
count = pStmt.executeUpdate();
BaseLogger.log("3",null,null,"Delete Count for work_shift :: "+count);
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
sql = "select count(emp_code) as count from work_shift where emp_code = ? and ? >= from_dt and ? <= to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, relieveDate);
pStmt.setTimestamp(3, relieveDate);
rs1 = pStmt.executeQuery();
if(rs1.next())
{
cntr = rs1.getInt("count");
}
BaseLogger.log("3",null,null,"Employee Count From work_shift :: "+cntr);
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
if( cntr > 0 )
{
count =0;
sql = "update work_shift set to_dt = ? where emp_code = ? and ? >= from_dt and ? <= to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1, relieveDate);
pStmt.setString(2, empCode);
pStmt.setTimestamp(3, relieveDate);
pStmt.setTimestamp(4, relieveDate);
count = pStmt.executeUpdate();
BaseLogger.log("3",null,null,"WorkShift to_dt Update Count :: "+count);
if(cntr != count)
{
admCommon.gbfErrWrite("", empCode, "", "DS000NR", "E", 2, logWriter, logConn);
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
}
cntr = 0;
BaseLogger.log("3",null,null,"relieveDate.compareTo(fromDate).................."+relieveDate.compareTo(fromDate));
if ( relieveDate.compareTo(fromDate) < 0)
continue ;
toDate = relieveDate;
}
procDate = fromDate;
sql= "select count(emp_code) as count from work_shift where emp_code = ? and ? > from_dt and ? <= to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, fromDate);
pStmt.setTimestamp(3, fromDate);
rs1 = pStmt.executeQuery();
if(rs1.next())
{
cntr = rs1.getInt("count");
}
BaseLogger.log("3",null,null,"cntrs.............. "+cntr);
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
String tempFromDatestr = admCommon.getRelativeDate(fromDateStr, -1);
if(tempFromDatestr != null && tempFromDatestr.trim().length() > 0)
{
tempFromDate = getTimeStampValue(tempFromDatestr);
}
if( cntr > 0 )
{
sql ="update work_shift set to_dt = ? where emp_code = ? and ? > from_dt and ? <= to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1, tempFromDate);
pStmt.setString(2, empCode);
pStmt.setTimestamp(3, fromDate);
pStmt.setTimestamp(4, fromDate);
int executeUpdate = pStmt.executeUpdate();
BaseLogger.log("3",null,null,"Update Count for WorkShift to_dt :: "+executeUpdate);
if(cntr != executeUpdate)
{
admCommon.gbfErrWrite("", empCode, "", "DS000NR", "E", 2, logWriter, logConn);
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
}
cntr = 0;
sql="select count(emp_code) as count from work_shift where emp_code = ? and ? >= from_dt and ? < to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, toDate);
pStmt.setTimestamp(3, toDate);
rs1 = pStmt.executeQuery();
if(rs1.next())
{
cntr = rs1.getInt("count");
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
String tempTODateStr = admCommon.getRelativeDate(toDateStr, 1);
if(tempTODateStr != null && tempTODateStr.trim().length() > 0)
{
tempToDate = getTimeStampValue(tempTODateStr);
}
if( cntr > 0 )
{
sql="update work_shift set from_dt = ? where emp_code = ? and ? >= from_dt and ? < to_dt ";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1, tempToDate);
pStmt.setString(2, empCode);
pStmt.setTimestamp(3, toDate);
pStmt.setTimestamp(4, toDate);
int executeUpdate = pStmt.executeUpdate();
if(cntr != executeUpdate)
{
admCommon.gbfErrWrite("", empCode, "", "DS000NR", "E", 2, logWriter, logConn);
}
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
}
sql="delete from work_shift where emp_code = ? and from_dt between ? and ? and to_dt between ? and ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, fromDate);
pStmt.setTimestamp(3, toDate);
pStmt.setTimestamp(4, fromDate);
pStmt.setTimestamp(5, toDate);
int updateQuery = pStmt.executeUpdate();
BaseLogger.log("0",null,null,"<><><><><><>< Delete WorkShift ><><><><><><> "+updateQuery);
sql ="select count(emp_code) as count, max(to_dt) as last_date from work_shift where from_dt < ? and emp_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1, procDate);
pStmt.setString(2, empCode);
rs1=pStmt.executeQuery();
while(rs1.next())
{
count = rs1.getInt("count");
lastDate =rs1.getTimestamp("last_date");
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
BaseLogger.log("3",null,null,"<><><>< Count["+count+"] <><><><>< Last Date ["+lastDate+"]");
String tempDatestr = admCommon.relativeDate(procDate, -1);
if( tempDatestr != null)
{
tempDate = getTimeStampValue(tempDatestr);
}
if( lastDate != null )
{
sql="select real_shift from work_shift where to_dt = ? and emp_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1,lastDate );
pStmt.setString(2, empCode);
rs1 = pStmt.executeQuery();
while(rs1.next())
{
workShift = rs1.getString("real_shift");
BaseLogger.log("0",null,null,"<><><><>< RealShift ><><><><> "+workShift);
}
if (rs1 != null)
{
rs1.close();
rs1 = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
if( tempDate.compareTo(lastDate) >= 0 )
{
errCode = gbfProjectShift(empCode, holTblNo,lastDate,tempDate, conn);
BaseLogger.log("3",null,null,"Return From gbf_project_shift..................."+errCode);
if( errCode.length() > 0)
{
admCommon.gbfErrWrite("", empCode, "", errCode, "E", 2, logWriter, logConn);
}
}
}
else
{
sql="select work_shift from employee where emp_code = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1,empCode);
rs1=pStmt.executeQuery();
while(rs1.next())
{
workShift = rs1.getString("work_shift");
}
}
HashMap holiData=admCommon.gfGetHols(empCode, fromDate, toDate, holTblNo, logConn);
BaseLogger.log("3",null,null,"holiData........................"+holiData);
errCode = (String) holiData.get("errorcode");
HashMap holyAllData = (HashMap) holiData.get("holiday");
if(errCode.length() > 0)
{
admCommon.gbfErrWrite("", empCode, "", errCode, "E", 2, logWriter, logConn);
}
count =holyAllData.size();
if(shiftPattern.equalsIgnoreCase("Y"))
{
workShift = toShift;
}
procDate = fromDate;
cntr=1;
ldFromDate = fromDate;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//Make hashmap data sorted by holiday date
Iterator<Entry<String, HashMap<String, Object>>> itr = holyAllData.entrySet().iterator();
while(itr.hasNext())
{
Entry<String, HashMap<String, Object>> entry = itr.next();
String key = entry.getKey();
BaseLogger.log("0",null,null,key+" #Key............."+key.substring(0, key.length() - 2));
java.util.Date date1= sdf.parse(key.substring(0, key.length() - 2));
sortedDateMap.put(new Timestamp(date1.getTime()), (HashMap<String, Object>) holyAllData.get(key));
}
//Make hashmap data sorted by holiday date
Set<Entry<Timestamp, HashMap<String, Object>>> set = sortedDateMap.entrySet();
Iterator it1 = set.iterator();
while(it1.hasNext())
{
Map.Entry nextEntry = (Entry)it1.next();
Timestamp sortedDate = (Timestamp) nextEntry.getKey();
sortedDateList.add(sortedDate);
}
BaseLogger.log("3",null,null,"sortedDateList................."+sortedDateList);
int counter = -1;
while( procDate.compareTo(toDate) <=0)
{
for(int k =0;k < sortedDateList.size() ;k++ )
{
if(sortedDateList.get(k).compareTo(procDate) >=0)
{
counter = k;
break;
}
}
BaseLogger.log("3",null,null,"counter......... " + counter);
if( counter >= 0)
{
ldToDate = sortedDateList.get(counter);
ldToDateStr = admCommon.relativeDate(ldToDate, 1);
if(ldToDateStr != null && ldToDateStr.length() > 0)
{
procDate = getTimeStampValue(ldToDateStr);
}
for(int j= counter+1; j<sortedDateList.size();j++)
{
if(procDate.compareTo(sortedDateList.get(j)) == 0)
{
ldToDate = sortedDateList.get(j);
ldToDateStr = admCommon.relativeDate(ldToDate, 1);
if(ldToDateStr != null && ldToDateStr.length() > 0)
{
procDate = getTimeStampValue(ldToDateStr);
}
}
else
{
BaseLogger.log("3",null,null,"\n Break :: ");
}
if(ldToDate.compareTo(toDate) > 0)
{
ldToDate = toDate;
}
}
}
else
{
ldToDate = toDate;
}
if(relieveDate != null)
{
BaseLogger.log("3",null,null,"relieveDate.compareTo(ldToDate)......................"+relieveDate.compareTo(ldToDate));
if( relieveDate.compareTo(ldToDate) <= 0)
{
ldToDate = relieveDate;
}
}
BaseLogger.log("3",null,null,"procDate ["+procDate+"] ldToDate["+ldToDate+"]");
if( ldFromDate.compareTo(ldToDate) > 0)
{
ldToDate = toDate;
}
sql="insert into work_shift (emp_code,from_dt,to_dt,shift,chg_user,chg_term,chg_date,real_shift) values (?,?,?,?,?,?,?,?) ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, empCode);
pStmt.setTimestamp(2, ldFromDate);
pStmt.setTimestamp(3, ldToDate);
pStmt.setString(4, workShift);
pStmt.setString(5, userId);
pStmt.setString(6, chgTerm);
pStmt.setTimestamp(7, currDate);
pStmt.setString(8, workShift);
count = pStmt.executeUpdate();
BaseLogger.log("3",null,null,"Insert Count "+count);
if(pStmt != null)
{
pStmt.close();
pStmt = null;
}
ldToDateStr = admCommon.relativeDate(ldToDate, 1);
if(ldToDateStr != null && ldToDateStr.trim().length() > 0)
{
procDate = getTimeStampValue(ldToDateStr);
}
ldFromDate = procDate;
String tempShift = workShift;
sql="select next_shift from workshft where shift = ? and day_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, tempShift);
pStmt.setString(2, "1");
rs1=pStmt.executeQuery();
while(rs1.next())
{
realShift = rs1.getString("next_shift");
}
if("".equals(realShift))
{
errorString = genericUtility.getErrorString("", "VTNTXSHFT", userId);
admCommon.gbfErrWrite("", empCode, "", errCode, "E", 2, logWriter, logConn);
}
}
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
}
else
{
errorString = genericUtility.getErrorString("", "VMSITECD1", userId);
}
if(errorString.trim().length()>0)
{
return errorString;
}
else
{
errorString = genericUtility.getErrorString("", "VPSUCC1", userId);
}
}
catch(Exception e)
{
isError = true;
BaseLogger.log("0",null,null,"Excption in processData:"+e);
try
{
admCommon.gbfErrWrite("", empCode, "", errCode, "E", 2, logWriter, logConn);
}
catch (ITMException e1)
{
e1.printStackTrace();
}
}
finally
{
try
{
if( !isError )
{
conn.commit();
logConn.commit();
}
if(logConn != null)
{
logConn.close();
logConn = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}
if(pStmt!=null)
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Finally Excption in processData:"+e);
}
}
return errorString;
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
private String getObjNameFromDom(Document dom, String attribute) throws RemoteException, ITMException
{
String objName = "";
try
{
NodeList detailList = null;
Node currDetail = null;
int detailListLength = 0;
detailList = dom.getElementsByTagName("Detail1");
detailListLength = detailList.getLength();
for (int ctr = 0; ctr < detailListLength; ctr++)
{
currDetail = detailList.item(ctr);
objName = currDetail.getAttributes().getNamedItem(attribute).getNodeValue();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return objName;
}
private String gbfProjectShift (String empCode,String hol, Timestamp lastDate, Timestamp toDate, Connection conn)
{
BaseLogger.log("2",null,null,"Inside gbfProjectShift................... ");
String errCode ="",sql="",realShift="",lsShift="",holDateStr="",ldtoDateStr,procDateStr = "";
String nextShift = "";
AdmCommon admCommon = new AdmCommon();
Timestamp nextStart = null,procDate=null,currDate = null,ldtoDate = null;
ResultSet rs = null;
PreparedStatement pStmt = null;
try
{
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(CommonConstants.APPL_DATE_FORMAT);
String currentDatestr = formatter.format(calendar.getTime());
BaseLogger.log("0",null,null,"currentDateStr = " + currentDatestr);
if(currentDatestr != null && currentDatestr.trim().length() > 0)
{
currDate = getTimeStampValue(currentDatestr);
}
sql = "select real_shift from work_shift where to_dt = ? and emp_code = ?";
pStmt = conn.prepareStatement(sql);
pStmt.setTimestamp(1, lastDate);
pStmt.setString(2, empCode);
rs = pStmt.executeQuery();
while(rs.next())
{
realShift = checkNull(rs.getString("real_shift"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pStmt != null)
{
pStmt.close();
pStmt = null;
}
calendar.setTime(lastDate);
int dayNum = calendar.get(Calendar.DAY_OF_WEEK);
String nextStartStr = admCommon.relativeDate(toDate, 1);
if(nextStartStr != null && currentDatestr.trim().length() > 0)
{
nextStart = getTimeStampValue(nextStartStr);
}
BaseLogger.log("3",null,null,"NexrStart................"+nextStart);
HashMap<String,String> holyData = new HashMap();
HashMap<Integer,HashMap<String,String>> holyAllData = new HashMap<>();
int cnt =0;
sql=" SELECT HOL_DATE ,HOL_TYPE, NO_DAYS,HOL_TBLNO FROM HOLIDAY WHERE (( holiday.hol_tblno = ? ) AND "
+ "( holiday.hol_date between ? and ?) AND (holiday.hol_type = 'W')) ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, hol);
pStmt.setTimestamp(2,lastDate);
pStmt.setTimestamp(3, nextStart);
ResultSet rs1 = pStmt.executeQuery();
while(rs1.next())
{
holyData = new HashMap();
holyData.put("hol_date", checkNull(rs1.getString(("hol_date"))));
holyData.put("hol_type", checkNull(rs1.getString("hol_type")));
holyData.put("no_days", checkNull(rs1.getString("no_days")));
holyData.put("hol_tblno", checkNull(rs1.getString("hol_tblno")));
holyAllData.put(cnt, holyData);
cnt++;
}
BaseLogger.log("0",null,null,"ResultSet Count "+cnt);
if(cnt == 0)
return "";
procDate = lastDate;
lsShift = realShift;
while(procDate.compareTo(toDate) <= 0)
{
try
{
Iterator<Entry<Integer, HashMap<String, String>>> itr = holyAllData.entrySet().iterator();
while(itr.hasNext())
{
Entry<Integer, HashMap<String, String>> entry = itr.next();
int key = entry.getKey();
HashMap<String, String> innerMap = entry.getValue();
BaseLogger.log("3",null,null,"Key ["+key+"] Value["+innerMap+"]");
String values1 = innerMap.get("hol_date");
java.sql.Timestamp holDate = java.sql.Timestamp.valueOf( values1 ) ;
BaseLogger.log("3",null,null,"holDate ["+holDate+"] procDate["+procDate+"]"+" "+holDate.compareTo(procDate));
if(holDate.compareTo(procDate) >= 0 && innerMap.get("hol_type").equalsIgnoreCase("W"))
{
BaseLogger.log("3",null,null,key);
ldtoDate = holDate;
procDateStr = admCommon.relativeDate(ldtoDate, 1);
if(procDateStr != null && procDateStr.trim().length() > 0)
{
procDate = getTimeStampValue(procDateStr);
}
BaseLogger.log("3",null,null,"procdate................."+procDate);
BaseLogger.log("3",null,null,"Next Date "+holyAllData.get(key+1).get("hol_date"));
for(int i = key+1; i <= holyAllData.size(); i++ )
{
BaseLogger.log("3",null,null,"Loop......................"+i);
holDate = Timestamp.valueOf(holyAllData.get(i).get("hol_date"));
if(procDate.compareTo(holDate) == 0)
{
ldtoDate = holDate;
procDateStr = admCommon.relativeDate(ldtoDate, 1);
if(procDateStr != null && procDateStr.trim().length() > 0)
{
procDate = getTimeStampValue(procDateStr);
}
}
else
{
break;
}
}
if(ldtoDate.compareTo(toDate) > 0)
{
BaseLogger.log("3",null,null,"Exit::");
break;
}
sql ="select next_shift from workshft where shift = ? and day_no = ? ";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, realShift);
pStmt.setString(2, "1");
rs=pStmt.executeQuery();
while(rs.next())
{
nextShift = checkNull(rs.getString("next_shift"));
}
ldtoDateStr = admCommon.relativeDate(ldtoDate,1);
if(ldtoDateStr != null && ldtoDateStr.trim().length() > 0)
{
procDate = getTimeStampValue(ldtoDateStr);
}
if(procDate.compareTo(toDate) > 0)
break;
}
else
{
break;
}
}
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception in do while..............."+e.getMessage());
}
}
}
catch(Exception e)
{
errCode="DS000";
BaseLogger.log("0",null,null,"Exception ing gbf_project_shift.............................");
}
return errCode;
}
public Timestamp getTimeStampValue(String dateStr)
{
Timestamp timeStampValue = null;
try
{
timeStampValue = Timestamp.valueOf(genericUtility.getValidDateTimeString(dateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()));
}
catch(Exception e)
{
BaseLogger.log("0",null,null,"Exception "+e);
return null;
}
return timeStampValue;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment