Commit f5c81398 authored by sanashaikh's avatar sanashaikh

Sana S : Added on 07/11/19

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@211501 ce508802-f39f-4f6c-b175-0d175dae99d5
parent dc9dfc84
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
//Created by Sana S on 01/10/2019 [start]
public class LeaveConvertIC extends ValidatorEJB implements LeaveConvertICLocal,LeaveConvertICRemote
{
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 = null;
try
{
genericUtility = new E12GenericUtility();
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 :LeaveConvertIC :itemChanged(String,String):" + e.getMessage() + ":");
valueXmlString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from LeaveConvertIC itemChanged");
return valueXmlString;
}
public String itemChanged(Document dom , Document dom1, Document dom2, String objContext, String currentColumn,
String editFlag, String xtraParams) throws RemoteException, ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
StringBuffer valueXmlString = null;
int currentFormNo = 0;
E12GenericUtility genericUtility = null;
String sql = "";
String userId="";
String loginSite="";
int mLevel = 0;
String lsDescr = "";
String empCodeFr="";
String empFname="";
String empLname="";
String modStr="";
String empCodeTo="";
String deptCodeFr="";
String deptCodeTo="";
String siteCodeFr="";
String siteCodeTo="";
String lveTypeFr="";
String procGroupFr="";
String procGroupTo="";
try
{
genericUtility = new E12GenericUtility();
System.out.println("currentFormNo...." + currentFormNo);
conn = 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);
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSite=genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
sql="select usr_lev from users where code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userId);
rs = pstmt.executeQuery();
if (rs.next())
{
mLevel = rs.getInt("usr_lev");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
switch (currentFormNo)
{
case 1:
{
valueXmlString.append("<Detail1>\r\n");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside itm_default:::::::::::::::");
valueXmlString.append("<emp_name__fr><![CDATA[").append("").append("]]></emp_name__fr>\r\n");
valueXmlString.append("<emp_name__to><![CDATA[").append("").append("]]></emp_name__to>\r\n");
valueXmlString.append("<fr_site_descr><![CDATA[").append("").append("]]></fr_site_descr>\r\n");
valueXmlString.append("<to_site_descr><![CDATA[").append("").append("]]></to_site_descr>\r\n");
valueXmlString.append("<lve_desc_of><![CDATA[").append("").append("]]></lve_desc_of>\r\n");
if(loginSite != null && loginSite.trim().length() > 0)
{
valueXmlString.append("<site_code__fr><![CDATA[").append(loginSite).append("]]></site_code__fr>\r\n");
valueXmlString.append("<site_code__to><![CDATA[").append(loginSite).append("]]></site_code__to>\r\n");
sql="select descr from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSite);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<fr_site_descr><![CDATA[").append(lsDescr).append("]]></fr_site_descr>\r\n");
valueXmlString.append("<to_site_descr><![CDATA[").append(lsDescr).append("]]></to_site_descr>\r\n");
if(mLevel > 1)
{
valueXmlString.append("<site_code__fr protect=\"1\"><![CDATA[").append(loginSite).append("]]></site_code__fr>\r\n");
valueXmlString.append("<site_code__to protect=\"1\"><![CDATA[").append(loginSite).append("]]></site_code__to>\r\n");
}
valueXmlString.append("<resign_emp><![CDATA[").append("N").append("]]></resign_emp>\r\n");
valueXmlString.append("<noof_confirmed><![CDATA[").append("0").append("]]></noof_confirmed>\r\n");
valueXmlString.append("<noof_rejected><![CDATA[").append("0").append("]]></noof_rejected>\r\n");
}
}
if ("emp_code__fr".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside emp_code__fr:::::::::::::::");
empCodeFr=checkNull(genericUtility.getColumnValue("emp_code__fr", dom));
sql="select emp_fname, emp_lname from employee where emp_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCodeFr);
rs = pstmt.executeQuery();
if (rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empLname = checkNull(rs.getString("emp_lname"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
modStr = empFname+" "+empLname;
valueXmlString.append("<emp_name__fr><![CDATA[").append(modStr).append("]]></emp_name__fr>\r\n");
}
if ("emp_code__to".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside emp_code__to:::::::::::::::");
empCodeTo=checkNull(genericUtility.getColumnValue("emp_code__to", dom));
sql="select emp_fname, 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"));
empLname = checkNull(rs.getString("emp_lname"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
modStr = empFname+" "+empLname;
valueXmlString.append("<emp_name__to><![CDATA[").append(modStr).append("]]></emp_name__to>\r\n");
}
if ("dept_code__fr".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside dept_code__fr:::::::::::::::");
deptCodeFr=checkNull(genericUtility.getColumnValue("dept_code__fr", dom));
sql="select descr from department where dept_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, deptCodeFr);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<dept_descr__fr><![CDATA[").append(lsDescr).append("]]></dept_descr__fr>\r\n");
}
if ("dept_code__to".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside dept_code__to:::::::::::::::");
deptCodeTo=checkNull(genericUtility.getColumnValue("dept_code__to", dom));
sql="select descr from department where dept_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, deptCodeTo);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<dept_descr__to><![CDATA[").append(lsDescr).append("]]></dept_descr__to>\r\n");
}
if ("site_code__fr".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside site_code__fr:::::::::::::::");
siteCodeFr=checkNull(genericUtility.getColumnValue("site_code__fr", dom));
sql="select descr from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCodeFr);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<fr_site_descr><![CDATA[").append(lsDescr).append("]]></fr_site_descr>\r\n");
}
if ("site_code__to".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside site_code__to:::::::::::::::");
siteCodeTo=checkNull(genericUtility.getColumnValue("site_code__to", dom));
sql="select descr from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCodeTo);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<to_site_descr><![CDATA[").append(lsDescr).append("]]></to_site_descr>\r\n");
}
if ("lve_code_of".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside lve_code__of:::::::::::::::");
lveTypeFr=checkNull(genericUtility.getColumnValue("leave_type__fr", dom));
sql="select descr from leaves where lve_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lveTypeFr);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<lve_desc_of><![CDATA[").append(lsDescr).append("]]></lve_desc_of>\r\n");
}
if ("proc_group__fr".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside proc_group__fr:::::::::::::::");
procGroupFr=checkNull(genericUtility.getColumnValue("proc_group__fr", dom));
sql="select descr from gencodes where fld_name = ? and fld_value = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "PROC_GROUP");
pstmt.setString(2, procGroupFr);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<fr_proc_desc><![CDATA[").append(lsDescr).append("]]></fr_proc_desc>\r\n");
}
if ("proc_group__to".equalsIgnoreCase(currentColumn))
{
System.out.println(":::::::::::Inside proc_group__to:::::::::::::::");
procGroupTo=checkNull(genericUtility.getColumnValue("proc_group__to", dom));
sql="select descr from gencodes where fld_name = ? and fld_value = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "PROC_GROUP");
pstmt.setString(2, procGroupTo);
rs = pstmt.executeQuery();
if (rs.next())
{
lsDescr = checkNull(rs.getString("descr"));
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
valueXmlString.append("<to_proc_desc><![CDATA[").append(lsDescr).append("]]></to_proc_desc>\r\n");
}
}
valueXmlString.append("</Detail1>");
break;
}
valueXmlString.append("</Root>");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception :LeaveConvertIC [itemChanged(String xmlString)] : ==>\n" + e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
conn = null;
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
throw new ITMException(e);
}
}
return valueXmlString.toString();
}
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
System.out.println("xmlString::::::::::::"+xmlString);
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = "";
E12GenericUtility genericUtility = null;
try
{
genericUtility = new E12GenericUtility();
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("[wfValData] ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :LeaveConvertIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning from LeaveConvertIC wfvaldata");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String childNodeName = null;
StringBuffer errStringXml = null;
ITMDBAccessEJB itmDbAcess = null;
Connection conn = null;
int currentFormNo = 0;
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
int noOfChilds = 0;
String errString = "";
String userId="";
String procDate="",errCode="";
String msgType = null;
ArrayList<String> errList = new ArrayList<String>();//0
ArrayList<String> errFields = new ArrayList<String>();
//errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
E12GenericUtility genericUtility = null;
try
{
errStringXml = new StringBuffer();
genericUtility = new E12GenericUtility();
itmDbAcess = new ITMDBAccessEJB();
conn = getConnection();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
System.out.println("parentList--->>>" + parentList);
parentNode = parentList.item(0);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
System.out.println("noOfChilds--->>>" + noOfChilds);
switch (currentFormNo)
{
case 1:
NodeList parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
NodeList childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
System.out.println("child Node List Length::::::" + childNodeListLength);
for (int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
System.out.println("childNode" + childNode);
if (childNode.getNodeType() != Node.ELEMENT_NODE)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("childNodeName.editFlag." + childNodeName + " " + editFlag);
System.out.println("@V@ Edit flag :- [" + editFlag + "");
if("proc_date".equalsIgnoreCase(childNodeName))
{
procDate = genericUtility.getColumnValue("proc_date", dom);
System.out.println("procDate::["+procDate+"]");
if(procDate == null)
{
errCode="VEDAT2";
if(errCode.length() > 0)
{
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
//msgType = errorType(conn, errCode);
}
}
}
}
if (errList != null && errList.size() > 0)
{
//errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
errStringXml.append("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
System.out.println("errList==[" + errList + "]");
int errListSize = errList.size();
System.out.println("errListSize:::::::[" + errListSize + "]");
System.out.println("in error::::::::::");
for (int i = 0; i < errListSize; i++)
{
System.out.println("in error For:::::::::::::::");
errCode = (String) errList.get(i);
String errFldName = (String) errFields.get(i);
System.out.println("errCode .........." + errCode);
errString = itmDbAcess.getErrorString(errFldName, errCode, userId, "", conn);
System.out.println("errString is : ::::>>>> " + errString);
//String msgType = errorType(conn, errCode);
msgType = errorType(conn, 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);
System.out.println("--->>errStringXml=[" + errStringXml+"]");
errString = "";
}
if (msgType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errFields.clear();
errStringXml.append("</Errors></Root>\r\n");
}
else
{
//errStringXml = new StringBuffer("");
errStringXml.append("");
}
//errStringXml.append("</Errors></Root>\r\n");
System.out.println("final errorString in string=["+errStringXml.toString()+"]");
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
throw new ITMException(e);
}
}
System.out.println("sana errStringXml["+errStringXml+"]");
errString = errStringXml.toString();
return errString;
}
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
if (conn == null)
{
System.out.println("Connection is null");
} else
{
System.out.println("Connection is not null");
}
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 S on 03/10/2019 [end]
\ No newline at end of file
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