Commit e7db48a3 authored by sanashaikh's avatar sanashaikh

Sana S:modified on 22/08/2019

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@206256 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b699aad4
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
//import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
//@Stateless
//Created by Sana Shaikh on 19/08/2019 for holiday Change of employee [START]
public class HolChangeIC extends ValidatorEJB implements HolChangeICRemote, HolChangeICLocal
{
public String itemChanged() throws RemoteException, ITMException
{
return "";
}
public String itemChanged(String xmlString, String xmlString1,
String xmlString2, String objContext, String currentColumn,
String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom1 = null;
Document dom = null;
Document dom2 = null;
String valueXmlString = "";
E12GenericUtility genericUtility = new E12GenericUtility();
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);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext,currentColumn, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :HolChangeIC :itemChanged(String,String):"+ e.getMessage() + ":");
valueXmlString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from HolChangeIC itemChanged");
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,
String objContext, String currentColumn, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
Connection connectionObject = null;
int currentFormNo = 0;
StringBuffer valueXmlString = null;
ResultSet resultSet = null;
PreparedStatement pstmt = null;
String sql = " ";
String empCode="";
String holDateTo="";
String empFname="";
String empLname="";
String status="",work_site="";
String holDateFor="";
String hol="";
String dayFrom="",dayTo="",dayFromDt="",dayToDt="";
Timestamp dateFor = null,dateTo = null,dayFrom1=null,dayTo1=null;
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
System.out.println("currentFormNo...." + currentFormNo);
connectionObject = getConnection();
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</Header>\r\n");
System.out.println("current form no: " + currentFormNo);
switch (currentFormNo)
{
case 1:
System.out.println("Case1");
valueXmlString.append("<Detail1>\r\n");
if (currentColumn.trim().equals("itm_default"))
{
holDateFor = checkNull(genericUtility.getColumnValue("hol_date_for", dom));
System.out.print("Holiday Date For:"+holDateFor);
if(holDateFor == null || holDateFor.trim().length() == 0)
{
valueXmlString.append("<hol_date_for><![CDATA[").append(holDateFor).append("]]></hol_date_for>");
}
else
{
dateFor = Timestamp.valueOf(genericUtility.getValidDateString(holDateFor, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
valueXmlString.append("<hol_date_for><![CDATA[").append(dateFor).append("]]></hol_date_for>");
}
System.out.print("Converted Holiday Date For:"+dateFor);
holDateTo = checkNull(genericUtility.getColumnValue("hol_date_to", dom));
if(holDateTo == null || holDateTo.trim().length()==0)
{
valueXmlString.append("<hol_date_to><![CDATA[").append(holDateTo).append("]]></hol_date_to>");
}
else
{
dateTo = Timestamp.valueOf(genericUtility.getValidDateString(holDateTo, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
valueXmlString.append("<hol_date_to><![CDATA[").append(dateTo).append("]]></hol_date_to>");
}
valueXmlString.append("<day_from><![CDATA[").append(dayFrom).append("]]></day_from>");
valueXmlString.append("<day_to><![CDATA[").append(dayTo).append("]]></day_to>");
/*dayFrom = checkNull(genericUtility.getColumnValue("day_from", dom));
if(dayFrom==null || dayFrom.trim().length()==0)
{
valueXmlString.append("<day_from><![CDATA[").append(dayFrom).append("]]></day_from>");
}
else
{
valueXmlString.append("<day_from><![CDATA[").append(dayFrom).append("]]></day_from>");
}
dayTo = checkNull(genericUtility.getColumnValue("day_to", dom));
if(dayTo==null || dayTo.trim().length()==0)
{
valueXmlString.append("<day_to><![CDATA[").append(dayTo).append("]]></day_to>");
}
else
{
valueXmlString.append("<day_to><![CDATA[").append(dayTo).append("]]></day_to>");
}*/
valueXmlString.append("<hol_type><![CDATA[").append("W").append("]]></hol_type>");
valueXmlString.append("<confirmed><![CDATA[").append("N").append("]]></confirmed>");
}
else if (currentColumn.trim().equals("itm_defaultedit"))
{
status =checkNull(genericUtility.getColumnValue("confirmed", dom));
System.out.print("Status =:"+status);
if(status != "Y" && status != "C" || status.trim().length() == 0)
{
}
else
{
if(status.equals("Y"))
{
}
else if (status.equals("C"))
{
}
}
}
else if (currentColumn.trim().equals("emp_code"))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
System.out.print("EMP CODE:"+empCode);
//sql = "select emp_fname,emp_lname,work_site as fname,lname,work_site from employee where emp_code = ?";
sql = "select emp_fname as fname,emp_lname as lname,work_site as work_site from employee where emp_code = ? "; //Modified by sana on 20/08/2019
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
resultSet = pstmt.executeQuery();
if (resultSet.next())
{
empFname = checkNull(resultSet.getString("fname"));
empLname = checkNull(resultSet.getString("lname"));
work_site = checkNull(resultSet.getString("work_site"));
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<emp_fname><![CDATA[").append(empFname).append("]]></emp_fname>");
valueXmlString.append("<emp_lname><![CDATA[").append(empLname).append("]]></emp_lname>");
valueXmlString.append("<work_site><![CDATA[").append(work_site).append("]]></work_site>");
}
else if (currentColumn.trim().equals("hol_date_for"))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
holDateFor = checkNull(genericUtility.getColumnValue("hol_date_for", dom));
dateFor = Timestamp.valueOf(genericUtility.getValidDateString(holDateFor, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
dayFromDt=sdf.format(dateFor);
valueXmlString.append("<day_from><![CDATA[").append(dayFromDt).append("]]></day_from>");
System.out.print("EMP CODE:"+"["+empCode+"]\t Holiday Date For Value:["+holDateFor+"]");
System.out.println("dayFromDt = "+dayFromDt);
sql = "select fn_get_holtblno(?,?) as hol from dual";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setTimestamp(2, dateFor);
resultSet = pstmt.executeQuery();
if (resultSet.next())
{
hol = checkNull(resultSet.getString("hol"));
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<hol_tblno><![CDATA[").append(hol).append("]]></hol_tblno>");
}
else if (currentColumn.trim().equals("hol_date_to"))
{
holDateTo = checkNull(genericUtility.getColumnValue("hol_date_to", dom));
dateTo = Timestamp.valueOf(genericUtility.getValidDateString(holDateTo, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
dayToDt=sdf.format(dateTo);
valueXmlString.append("<day_to><![CDATA[").append(dayToDt).append("]]></day_to>");
System.out.print("dayToDt"+dayToDt);
}
valueXmlString.append("</Detail1>\r\n");
break;
}
valueXmlString.append("</Root>\r\n");
} catch (Exception e) {
System.out.println("Exception :HolidayChangeIC :itemChanged(Document,String):"+ e.getMessage() + ":");
valueXmlString.delete(0, valueXmlString.length());
valueXmlString = valueXmlString.append(genericUtility.createErrorString(e));
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (connectionObject != null)
{
connectionObject.close();
connectionObject = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
System.out.println("\n****ValueXmlString :" + valueXmlString + ":********");
return valueXmlString.toString();
}
public String wfValData() throws RemoteException, ITMException {
return "";
}
public String wfValData(String xmlString, String xmlString1,
String xmlString2, String objContext, String editFlag,
String xtraParams) throws RemoteException,
ITMException
{
System.out.println(xmlString);
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
if (xmlString != null && xmlString.trim().length() != 0)
{
dom = genericUtility.parseString(xmlString);
System.out.println("Print dom>>>> "+dom);
}
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);
System.out.println("ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :DeptIC :wfValData(String xmlString):"+ e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from DeptIC wfvaldata");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
String userId = "";
String sql = "";
String errString = "";
Connection connectionObject = null;
ResultSet resultSet = null;
PreparedStatement pstmt = null;
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
int counter;
int noOfChilds = 0;
int currentFormNo = 0;
int cnt = 0;
String empCode = "",errCode="",errorType = "";
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
String holDateFor="";
String holType="";
String hol="";
String holDateFTo="";
String mLevel = "", loginSite = "";
Timestamp dateFor = null,dateTo = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
connectionObject = getConnection();
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode"));
System.out.println("Line no--468");
if(objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
parentNode = parentList.item(0);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
if(mLevel == null)
{
sql = "select usr_lev from users where code = ?";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, userId);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
mLevel = checkNull(resultSet.getString("usr_lev"));
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
System.out.println("noOfChilds--->>>"+noOfChilds);
for (counter = 0; counter < noOfChilds; counter++)
{
childNode = childList.item(counter);
childNodeName = childNode.getNodeName();
System.out.println("childNodeName>>>>>"+childNodeName);
System.out.println("childNode>>>>>>"+childNode);
System.out.println("counter>>>"+counter);
switch (currentFormNo)
{
case 1:
{
if(childNodeName.equals("emp_code"))
{
empCode =checkNull(genericUtility.getColumnValue("emp_code", dom));
sql = "select count(*) as cnt from employee where emp_code = ? and "
+ "work_site = (case when ? > 1 then ? else work_site end)";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setString(2, mLevel);
pstmt.setString(3, loginSite);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
cnt = resultSet.getInt("cnt");
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(empCode == null || empCode.trim().length() == 0)
{
errCode = "VMEMP1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if(cnt == 0)
{
errCode = "VMEMPCD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if(childNodeName.equalsIgnoreCase("hol_date_for"))
{
System.out.println("line --509");
empCode =checkNull(genericUtility.getColumnValue("emp_code", dom));
holDateFor = checkNull(genericUtility.getColumnValue("hol_date_for", dom));
dateFor = Timestamp.valueOf(genericUtility.getValidDateString(holDateFor, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
sql = "select fn_get_holtblno(?,?) as ls_hol from dual";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setTimestamp(2, dateFor);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
hol = resultSet.getString("ls_hol");
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
sql = "select count(1) as cnt from holiday where hol_date = ? and hol_tblno = ? ";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setTimestamp(1, dateFor);
pstmt.setString(2, hol);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
cnt = resultSet.getInt("cnt");
}
if(cnt<1)
{
errCode = "VMHOLF1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
//////////////
empCode =checkNull(genericUtility.getColumnValue("emp_code", dom));
holDateFor = checkNull(genericUtility.getColumnValue("hol_date_for", dom));
dateFor = Timestamp.valueOf(genericUtility.getValidDateString(holDateFor, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
holDateFTo=checkNull(genericUtility.getColumnValue("hol_date_to", dom));
dateTo = Timestamp.valueOf(genericUtility.getValidDateString(holDateFTo, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
sql = "select fn_get_holtblno(?,?) as ls_hol from dual";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setTimestamp(2, dateFor);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
hol = resultSet.getString("ls_hol");
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
sql = "select count(*) as cnt from holiday where hol_date = ? and hol_tblno = ?";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setTimestamp(1, dateTo);
pstmt.setString(2, hol);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
cnt = resultSet.getInt("cnt");
}
if(cnt>0)
{
sql = "select count(*) as cnt from change_holiday where emp_code = ? and hol_tblno = ? and hol_date_for = ? and confirmed = ?";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setString(2, hol);
pstmt.setTimestamp(3, dateFor);
pstmt.setString(4, "Y");
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
cnt = resultSet.getInt("cnt");
}
if(cnt == 0)
{
errCode = "VMHOL1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
else if(childNodeName.equalsIgnoreCase("hol_type"))
{
holType =checkNull(genericUtility.getColumnValue("hol_type", dom));
sql = "select hol_type as ls_hol_type from holiday where hol_date = ? and hol_tblno = ? and hol_type = ?";
pstmt = connectionObject.prepareStatement(sql);
pstmt.setTimestamp(1, dateFor);
pstmt.setString(2, hol);
pstmt.setString(3, holType);
resultSet = pstmt.executeQuery();
if(resultSet.next())
{
holType = resultSet.getString("ls_hol_type");
}
if(holType.equals("H"))
{
errCode = "VTHOLCHG";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if(holType.trim() == "")
{
errCode = "VTHOLNOT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
}
}
}
int errListSize = errList.size();
System.out.print("errList:"+errList);
System.out.print("errListSize:"+errListSize);
cnt = 0;
String errFldName = null;
if(errList != null && errListSize > 0)
{
for(cnt = 0; cnt < errListSize; cnt ++)
{
errCode = errList.get(cnt);
errFldName = errFields.get(cnt);
System.out.println("errCode .........." + errCode);
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(connectionObject , errCode);
if(errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8, errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
if(errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer("");
}
}catch (Exception e)
{
System.out.println("Exception :DeptIC :wfValData(Document,String):"+ e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (resultSet != null)
{
resultSet.close();
resultSet = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (connectionObject != null)
{
connectionObject.close();
connectionObject = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
////////////////////
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if (rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return msgType;
}
/////////////
private String checkNull(String input)
{
if(input==null)
{
input="";
}
return input;
}
}
//Created by Sana Shaikh on 19/08/2019 for holiday Change of employee [End]
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