Commit 5f706692 authored by sanashaikh's avatar sanashaikh

Sana S: added on 10/01/2020

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@214918 ce508802-f39f-4f6c-b175-0d175dae99d5
parent a17d6821
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
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;
import java.util.*;
import javax.ejb.Stateless;
@Stateless
//Created By Sana S on 10/01/2020 [start]
public class ArrearsLoadIC extends ValidatorEJB implements ArrearsLoadICLocal,ArrearsLoadICRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
AdmCommon admCommon = new AdmCommon();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
//validation start//
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 = "";
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("ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :ArrearsLoadIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning ArrearsLoadIC Load wfvaldata");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag,
String xtraParams) throws RemoteException, ITMException
{
StringBuffer errStringXml = null;
PreparedStatement pstmt = null;
ITMDBAccessEJB itmDbAcess = null;
ResultSet rs = null;
Connection conn = null;
NodeList parentList = null,childList = null,parentNodeList=null,childNodeList=null;
Node parentNode = null,childNode = null;
String childNodeName = null;
String userId = "",mVal= "",sql = "";
String errString = "",errCode= "";
int currentFormNo = 0,noOfChilds = 0,counter,cnt = 0,childNodeListLength=0;
E12GenericUtility genericUtility = null;
errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
try
{
genericUtility = new E12GenericUtility();
itmDbAcess = new ITMDBAccessEJB();
conn = getConnection();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("User ID:"+userId);
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();
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:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
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 ("emp_code".equalsIgnoreCase(childNodeName))
{
mVal = checkNull(genericUtility.getColumnValue("emp_code", dom));
if("A".equals(editFlag) || "E".equals(editFlag))
{
if(mVal.length() == 0 || mVal == null)
{
errCode="VEEMP2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
sql=" select count(1) as cnt from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mVal);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt==0)
{
errCode="VMEMP1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
else if ("fin_entity".equalsIgnoreCase(childNodeName))
{
mVal = checkNull(genericUtility.getColumnValue("fin_entity",dom));
if("A".equals(editFlag) || "E".equals(editFlag))
{
if(mVal.length() == 0 || mVal == null)
{
errCode="VEFENTY2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else
{
sql="select count(1) as cnt from finent where fin_entity = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mVal);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt==0)
{
errCode="VMFENTY1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
break;
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
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 ("ad_code".equalsIgnoreCase(childNodeName))
{
mVal = checkNull(genericUtility.getColumnValue("ad_code", dom));
if("A".equals(editFlag) || "E".equals(editFlag))
{
if(mVal.length() == 0 || mVal == null)
{
errCode="VTIADC1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
sql=" select count(1) as cnt from allwdedn where ad_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mVal);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt==0)
{
errCode="VTIADC2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
}
break;
}
}
System.out.println("errStringXml.toString()---1= "+errStringXml.toString());
if (errList != null && errList.size() > 0)
{
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:::::::::::::::");
String errCode1 = (String) errList.get(i);
String errFldName = (String) errFields.get(i);
System.out.println("errCode .........." + errCode1);
errString = itmDbAcess.getErrorString(errFldName, errCode1, userId, "", conn);
System.out.println("errString is : ::::>>>> " + errString);
String 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");
System.out.println("errStringXml.toString()---2= "+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);
}
}
errString = errStringXml.toString();
return errString;
}
/////validation end////
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("Came Inside 1 itemChanged:::");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errFields = null;
genericUtility = new E12GenericUtility();
try
{
System.out.println("xmlString [" + xmlString + "]");
System.out.println("xmlString1 [" + xmlString1 + "]");
System.out.println("xmlString2 [" + xmlString2 + "]");
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);
}
errFields = itemChanged(dom, dom1, dom2, objContext, currentColumn,editFlag, xtraParams);
System.out.println("errFields :" + errFields);
}
catch (Exception e)
{
System.out.println("Exception :PayrollLoad :" + e.getMessage()+ ":");
errFields = genericUtility.createErrorString(e);
throw new ITMException(e);
}
return errFields;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException
{
System.out.println("Item Changes Call..................");
Connection conn = null;
PreparedStatement pstmt=null,pstmt1=null;
ResultSet rs = null,rs1 = null;
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0;
String empCode = "",prdCode="",sql=null,sql1=null,empFname="",empMname="",empLname="",designation="",
deptCode="",cadre="",grade="",paySite="",empSite="",workSite="",empName="",deptDescription="",prdCodeAcc="";
try
{
conn = getConnection();
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("Form No:::"+currentFormNo);
switch (currentFormNo)
{
case 1:
{
valueXmlString.append("<Detail1>");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom));
valueXmlString.append("<prd_code protect=\"1\"><![CDATA[").append(prdCode).append("]]></prd_code>");
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
valueXmlString.append("<emp_code><![CDATA[").append(empCode).append("]]></emp_code>");
prdCodeAcc = checkNull(genericUtility.getColumnValue("prd_code__acc", dom));
valueXmlString.append("<prd_code__acc><![CDATA[").append(prdCodeAcc).append("]]></prd_code__acc>");
}
else if ("emp_code".equalsIgnoreCase(currentColumn))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
sql="select emp_fname,emp_mname,emp_lname,designation,dept_code,grade,cadre,pay_site,emp_site, work_site from employee where emp_code = ?";
pstmt=conn.prepareStatement(sql);
sql1="select descr from department where dept_code = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt.setString(1, empCode);
rs=pstmt.executeQuery();
while(rs.next())
{
empFname=rs.getString("emp_fname");
empMname=rs.getString("emp_mname");
empLname=rs.getString("emp_lname");
designation=rs.getString("designation");
grade=rs.getString("grade");
cadre=rs.getString("cadre");
paySite=rs.getString("pay_site");
empSite=rs.getString("emp_site");
workSite=rs.getString("work_site");
empFname=empFname+" "+empMname+" "+empLname;
pstmt1.setString(1, deptCode);
rs1=pstmt1.executeQuery();
while(rs1.next())
{
deptDescription=rs1.getString("descr");
valueXmlString.append("<emp_name><![CDATA[").append(empFname).append("]]></emp_name>");
valueXmlString.append("<designation><![CDATA[").append(designation).append("]]></designation>");
valueXmlString.append("<dept_code><![CDATA[").append(deptCode).append("]]></dept_code>");
valueXmlString.append("<department_descr><![CDATA[").append(deptDescription).append("]]></department_descr>");
valueXmlString.append("<grade><![CDATA[").append(grade).append("]]></grade>");
valueXmlString.append("<cadre><![CDATA[").append(cadre).append("]]></cadre>");
valueXmlString.append("<site_code__pay><![CDATA[").append(paySite).append("]]></site_code__pay>");
valueXmlString.append("<site_code__emp><![CDATA[").append(empSite).append("]]></site_code__emp>");
valueXmlString.append("<site_code__work><![CDATA[").append(workSite).append("]]></site_code__work>");
}
}
if(rs!=null)
{
rs.close();
rs=null;
}
if(rs1!=null)
{
rs1.close();
rs1=null;
}
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(pstmt1!=null)
{
pstmt1.close();
pstmt1=null;
}
}
valueXmlString.append("</Detail1>");
break;
}
}//END OF SWITCH
valueXmlString.append("</Root>");
System.out.println("valueXmlString[sepclose]"+valueXmlString);
}//END OF TRY
catch(Exception e)
{
System.out.println("Exception ::"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
if(rs != null)
{
rs.close();
rs = null;
}
if(rs1 != null)
{
rs1.close();
rs1 = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
throw new ITMException(e);
}
}
return valueXmlString.toString();
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
} else
{
input = input.trim();
}
return input;
}
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;
}
}
//Created By Sana S on 10/01/2020 [start]
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