Commit 6f158e1c authored by ssalve's avatar ssalve

Sarita:Source code of EmpITConfPrc on 25 SEPT 2018

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@191155 ce508802-f39f-4f6c-b175-0d175dae99d5
parent bc80eccc
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
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.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class EmpITConfPrc extends ProcessEJB implements EmpITConfPrcLocal,EmpITConfPrcRemote //SessionBean
{
ibase.utility.E12GenericUtility genericUtility= new ibase.utility.E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
public String getData(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException
{
String rtrStr = "";
Document headerDom = null;
Document detailDom = null;
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
}
if(xmlString2 != null && xmlString2.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString2);
}
rtrStr = getData(headerDom, detailDom, xtraParams);
System.out.println("Inside getDate returnString is :::"+rtrStr);
}
catch (Exception e)
{
System.out.println("Exception :EmpITConfPrc :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return rtrStr;
}//END OF GETDATA(1)
public String getData(Document headerDom, Document detailDom, String xtraParams) throws RemoteException,ITMException
{
String resultString = "", errString= "";
String lsFrEmp = "",lsToEmp = "",lsFrSite = "",lsToSite = "",lsProcfr = "",lsProcto = "",
lsAdTtax = "",lsAdTpaid = "",lsPrd = "",userId = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
boolean isError = false;
AdmCommon objAdmCommon = new AdmCommon();
Connection conn = null;
String sql = "";
try
{
System.out.println("Inside getData method ");
conn = getConnection();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
lsPrd = checkNullAndTrim(genericUtility.getColumnValue("acct_prd",headerDom));
lsFrEmp = checkNullAndTrim(genericUtility.getColumnValue("emp_code__fr",headerDom));
lsToEmp = checkNullAndTrim(genericUtility.getColumnValue("emp_code__to",headerDom));
lsFrSite = checkNullAndTrim(genericUtility.getColumnValue("site_code__fr",headerDom));
lsToSite = checkNullAndTrim(genericUtility.getColumnValue("site_code__to",headerDom));
lsProcfr = checkNullAndTrim(genericUtility.getColumnValue("proc_group__from",headerDom));
lsProcto = checkNullAndTrim(genericUtility.getColumnValue("proc_group__to",headerDom));
if(lsFrEmp == null || lsFrEmp.trim().length() == 0)
{
lsFrEmp = "0";
}
if(lsToEmp == null || lsToEmp.trim().length() == 0)
{
lsToEmp = "z";
}
if(lsFrSite == null || lsFrSite.trim().length() == 0)
{
lsFrSite = "0";
}
if(lsToSite == null || lsToSite.trim().length() == 0)
{
lsToSite = " ";
}
if(lsProcfr == null || lsProcfr.trim().length() == 0)
{
lsProcfr = "0";
}
if(lsProcto == null || lsProcto.trim().length() == 0)
{
lsProcto = "ZZZZZ";
}
lsAdTtax = objAdmCommon.getEnv("999999","IYEAR",conn);
lsAdTpaid = objAdmCommon.getEnv("999999","IPAYABLE",conn);
System.out.println("Value of lsAdTtax ["+lsAdTtax+"] \t Value of lsAdTpaid ["+lsAdTpaid+"]");
if((lsAdTtax != null && lsAdTtax.trim().length() > 0) && (lsAdTtax.equalsIgnoreCase("NULLFOUND")))
{
errString = itmDBAccessEJB.getErrorString("","VSENVAR1","",userId,conn);
isError = true;
return errString;
}
if(lsAdTpaid != null && lsAdTpaid.trim().length() > 0 && (lsAdTpaid.equalsIgnoreCase("NULLFOUND")))
{
errString = itmDBAccessEJB.getErrorString("","VSENVAR1","",userId,conn);
isError = true;
return errString;
}
StringBuffer retTabSepStrBuff = new StringBuffer("<?xml version = \"1.0\"?>");
retTabSepStrBuff.append("<DocumentRoot>");
retTabSepStrBuff.append("<description>").append("Datawindow Root").append("</description>");
retTabSepStrBuff.append("<group0>");
retTabSepStrBuff.append("<description>").append("Group0 description").append("</description>");
retTabSepStrBuff.append("<Header0>");
sql = "select itcalhdr.acct_prd , " +
"employee.emp_code , " +
"employee.emp_fname || ' ' || employee.emp_mname || ' ' || employee.emp_lname as emp_name, " +
"employee.pay_site as site_code, " +
"employee.proc_group as proc_group, " +
"case when itcaldet1.amount is null then 0 else itcaldet1.amount end as itax, " +
"case when itcaldet2.amount is null then 0 else itcaldet2.amount end as taxpaid, " +
"(case when itcaldet1.amount is null then 0 else itcaldet1.amount end - case when itcaldet2.amount is null then 0 else itcaldet2.amount end) as itpayable " +
"from IT_CALCHDR itcalhdr, EMPLOYEE employee , IT_CALCDET itcaldet1 , IT_CALCDET itcaldet2 " +
"where (itcalhdr.emp_code = employee.emp_code) " +
"and itcalhdr.acct_prd = ? " +
"and case when itcalhdr.confirmed is null then 'N' else itcalhdr.confirmed end <> 'Y' " +
"and employee.emp_code between ? and ? " +
"and employee.pay_site between ? and ? " +
"and employee.proc_group between ? and ? " +
"and itcaldet1.emp_code = employee.emp_code " +
"and itcaldet1.acct_prd = ? " +
"and itcaldet1.ad_code = ? " +
"and itcaldet2.emp_code = employee.emp_code " +
"and itcaldet2.acct_prd = ? " +
"and itcaldet2.ad_code = ?";
System.out.println("sql..."+ sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,lsPrd );
pstmt.setString(2,lsFrEmp);
pstmt.setString(3,lsToEmp);
pstmt.setString(4,lsFrSite);
pstmt.setString(5,lsToSite);
pstmt.setString(6,lsProcfr );
pstmt.setString(7,lsProcto);
pstmt.setString(8,lsPrd);
pstmt.setString(9,lsAdTtax);
pstmt.setString(10,lsPrd);
pstmt.setString(11,lsAdTpaid);
rs = pstmt.executeQuery();
while(rs.next())
{
retTabSepStrBuff.append("<Detail2>");
retTabSepStrBuff.append("<acct_prd>").append("<![CDATA[" + rs.getString("acct_prd") + "]]>").append("</acct_prd>\r\n");
retTabSepStrBuff.append("<emp_code>").append("<![CDATA[" + rs.getString("emp_code") + "]]>").append("</emp_code>\r\n");
retTabSepStrBuff.append("<emp_name>").append("<![CDATA[" + rs.getString("emp_name") + "]]>").append("</emp_name >\r\n");
retTabSepStrBuff.append("<site_code>").append("<![CDATA[" + rs.getString("site_code") + "]]>").append("</site_code>\r\n");
retTabSepStrBuff.append("<proc_group>").append("<![CDATA[" + rs.getString("proc_group") + "]]>").append("</proc_group>\r\n");
retTabSepStrBuff.append("<itax>").append("<![CDATA[" + rs.getString("itax") + "]]>").append("</itax>\r\n");
retTabSepStrBuff.append("<taxpaid>").append("<![CDATA[" + rs.getString("taxpaid") + "]]>").append("</taxpaid>\r\n");
retTabSepStrBuff.append("<itpayable>").append("<![CDATA[" + rs.getString("itpayable") + "]]>").append("</itpayable>\r\n");
retTabSepStrBuff.append("</Detail2>");
}
retTabSepStrBuff.append("</Header0>\r\n");
retTabSepStrBuff.append("</group0>\r\n");
retTabSepStrBuff.append("</DocumentRoot>\r\n");
if(rs != null)
{
rs.close();
rs=null;
}
if(pstmt != null)
{
pstmt.close();
pstmt=null;
}
resultString = retTabSepStrBuff.toString();
System.out.println("ResultString....." + resultString);
}
catch (Exception e)
{
System.out.println("Exception :EmpITConfPrc :getData(Document headerDom, Document detailDom, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception d) {throw new ITMException(d);}
}
finally
{
try
{
if(isError)
{
conn.rollback();
}
else
{
conn.commit();
conn.close();
conn = null;
}
if(rs != null)
{
rs.close();
rs=null;
}
if(pstmt != null)
{
pstmt.close();
pstmt=null;
}
}
catch(Exception e)
{
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
}
return resultString;
}//END OF GETDATA(2)
public String process(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null;
Document headerDom = null;
String retStr = "";
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
headerDom = genericUtility.parseString(xmlString);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
detailDom = genericUtility.parseString(xmlString2);
}
retStr = process(headerDom, detailDom, xtraParams);
System.out.println("Process forEmpITConfPrc ::"+retStr);
}
catch (Exception e)
{
System.out.println("Exception :DistIssPrcEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return retStr;
}//END OF PROCESS (1)
public String process(Document headerDom, Document detailDom, String xtraParams) throws RemoteException,ITMException
{
String errString="",childNodeName="",employeeCode = "",accountPrd = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int parentNodeListLength = 0 , childNodeListLength = 0,cnt1 = 0;
Connection conn = null;
boolean isError = false;
String succstring = "";
String succLine = "Successfully processed IT confirmation for below employee's :";
try
{
System.out.println("Inside process method [DETAIL DOM]"+genericUtility.serializeDom(detailDom)+"]");
conn = getConnection();
parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
cnt1 = getNumOfNonDelDetail(detailDom,2);
System.out.println("parentNodeListLength::["+parentNodeListLength+"] \n cnt1 is ["+cnt1+"]");
if(cnt1 == 0)
{
errString = itmDBAccessEJB.getErrorString("","VTBLNKDTL","","",conn);
return errString;
}
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
System.out.println("childNodeListLength-->>["+childNodeListLength+"] \n childNodeName---->>["+childNodeName+"] ");
if("emp_code".equalsIgnoreCase(childNodeName))
{
employeeCode = childNode.getFirstChild().getNodeValue();
}
if("acct_prd".equalsIgnoreCase(childNodeName))
{
accountPrd = childNode.getFirstChild().getNodeValue();
}
System.out.println("employeeCode is ["+employeeCode+"] \t accountPrd is ["+accountPrd+"]");
}
errString = gbfConfIt(accountPrd,employeeCode,xtraParams,conn);
System.out.println("errString is "+errString);
if((errString !=null && errString.trim().length() > 0 ) && (!(errString.contains("VTSUCC1"))))
{
isError = false;
succstring = succstring + employeeCode + "</br>";
}//end of if
else
{
isError = true;
return errString;
}
}
succLine = succLine + succstring;
errString = getErrorXml(succLine);
System.out.println("errString--["+errString+"]");
}//try end
catch(Exception e)
{
System.out.println("Exception :EmpItConf :process(String xmlString2, String xmlString2, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception d)
{
throw new ITMException(d);
}
}
finally
{
try
{
if(isError)
{
conn.rollback();
}
else
{
conn.commit();
conn.close();
conn = null;
}
}
catch(Exception e)
{
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
}
System.out.println("Error Message=>"+errString.toString());
return errString;
}//END OF PROCESS(2)
public String checkNullAndTrim( String inputVal )
{
if ( inputVal == null )
{
inputVal = "";
}
else
{
inputVal = inputVal.trim();
}
return inputVal;
}
public String gbfConfIt(String acctPrd , String empCode,String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String sql = "",loginEmpCode="";
PreparedStatement pstmt = null;
SimpleDateFormat sdf1 = null;
java.sql.Timestamp currentDate = null,today = null;
try
{
today = new java.sql.Timestamp(System.currentTimeMillis()) ;
sdf1 = new SimpleDateFormat(genericUtility.getDBDateFormat());
currentDate = java.sql.Timestamp.valueOf(sdf1.format(today) + " 00:00:00.000");
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
System.out.println("loginEmpCode is ==="+loginEmpCode);
sql = "update it_calchdr set confirmed = ? , emp_code__aprv = ?, conf_date = ? "
+ "where acct_prd = ? and emp_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,"Y");
pstmt.setString(2,loginEmpCode);
pstmt.setTimestamp(3,currentDate);
pstmt.setString(4,acctPrd);
pstmt.setString(5,empCode);
int updateCnt = pstmt.executeUpdate();
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("["+updateCnt+"] data updated in it_calchdr table");
if(updateCnt > 0)
{
retString = itmDBAccessEJB.getErrorString("","VPSUCC1","","",conn);
}
else
{
retString = itmDBAccessEJB.getErrorString("","DS000","","",conn);
}
}
catch(Exception e)
{
System.out.println("Inside Method gbfConfIt ["+e+"]");
e.printStackTrace();
try
{
conn.rollback();
}
catch(Exception d) {
throw new ITMException(e);
}
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return retString.toString();
}
public int getNumOfNonDelDetail(Document dom2,int detailNo)
{
Node childNode = null;
NodeList updateList;
String childNodeName = "";
String updateFlag="";
int cntr=0;
System.out.println("Inside getXmlDocument method!!!!!!!!!!!!!!");
try
{
System.out.println("detailString value is =="+genericUtility.serializeDom(dom2));
NodeList detailNoteList = dom2.getElementsByTagName("Detail"+detailNo);
for(int cnt = 0;cnt<detailNoteList.getLength();cnt++)
{
Node pNode=detailNoteList.item(cnt);
/*NodeList cNodeList=pNode.getChildNodes();
childNodeListLength = cNodeList.getLength();*/
childNodeName = pNode.getNodeName();
//System.out.println("pNode::["+pNode+"]"+"cNodeList::["+cNodeList+"]");
updateFlag = getAttributeVal(pNode,"updateFlag");
System.out.println("updateFlag [" + updateFlag + "]");
if(!updateFlag.equalsIgnoreCase("D"))
{
cntr++;
}
System.out.println("Counter is ==="+cntr);
}
}
catch(Exception e)
{
System.out.println("Exception : : getNumOfNonDelDetail :"+e);
e.printStackTrace();
}
return cntr;
}
public String getAttributeVal(Node dom, String attribName )throws ITMException
{
String AttribValue = null;
try
{
NodeList detailList = dom.getChildNodes();
int detListLength = detailList.getLength();
for(int ctr = 0; ctr < detListLength; ctr++)
{
Node curDetail = detailList.item(ctr);
if(curDetail.getNodeName().equals("attribute"))
{
AttribValue = curDetail.getAttributes().getNamedItem(attribName).getNodeValue();
break;
}
else
{
continue;
}
}
}
catch (Exception e)
{
System.out.println("Exception : : searchNode :"+e);
throw new ITMException(e);
}
return AttribValue;
}
public String getErrorXML(String message,String messageValue,String errorId, String traceInfo ,String type) throws RemoteException,ITMException
{
System.out.println("getErrorXML..........");
String errString = "";
try
{
errString = "";
StringBuffer valueXmlErrorString = new StringBuffer( "<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<Errors>\r\n" );
valueXmlErrorString.append("<error id=\"").append(errorId).append("\" type=\""+type+"\"").append(" column_name=\"description\"").append(">");
//valueXmlErrorString.append("<message><![CDATA[").append(message).append("]]></message>\r\n");
valueXmlErrorString.append("<message><![CDATA[").append(message).append("]]></message>\r\n");
valueXmlErrorString.append("<description><![CDATA[").append(messageValue).append("]]></description>\r\n");
valueXmlErrorString.append("<type>"+type+"</type>\r\n");
valueXmlErrorString.append("<option></option>\r\n");
valueXmlErrorString.append("<time></time>\r\n");
valueXmlErrorString.append("<alarm></alarm>\r\n");
valueXmlErrorString.append("<source></source>\r\n");
valueXmlErrorString.append("<trace>Error : "+traceInfo+" </trace>\r\n");
valueXmlErrorString.append("<redirect>1</redirect>\r\n");
valueXmlErrorString.append("</error>\r\n");
valueXmlErrorString.append("</Errors>\r\n");
valueXmlErrorString.append("</Header>\r\n");
valueXmlErrorString.append( "</Root>\r\n" );
System.out.println( "\n****valueXmlErrorString :" + valueXmlErrorString.toString() + ":********" );
errString =valueXmlErrorString.toString();
System.out.println("Modified error string"+errString);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return errString;
}
private String getErrorXml(String retXml)
{
System.out.println("retXml------["+ retXml + "]");
E12GenericUtility genericUtility = null;
NodeList parentNodeList = null;
Node parentNode = null;
NodeList childNodeList = null;
Node childNode = null;
String childNodeName = "";
String message = "";
String description = "";
String errId = "";
String msgType = "";
int childNodeLength = 0;
int ctr=0;
try
{
if(retXml.indexOf("<root>") != -1 || retXml.indexOf("<Root>") != -1 )
{
System.out.println("Inside root condition......");
genericUtility = new E12GenericUtility();
Document errDom = genericUtility.parseString(retXml);
parentNodeList = errDom.getElementsByTagName("root");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if("error".equalsIgnoreCase(childNodeName))
{
errId = childNode.getAttributes().getNamedItem("id").getNodeValue();
System.out.println("Error code -----["+ errId +"]");
msgType = childNode.getAttributes().getNamedItem("type").getNodeValue();
System.out.println("msgType--["+msgType+"]");
}
else if("message".equalsIgnoreCase(childNodeName))
{
message = genericUtility.getColumnValue("message", errDom);
System.out.println("message--["+message+"]");
}
else if("description".equalsIgnoreCase(childNodeName))
{
description = genericUtility.getColumnValue("description", errDom);
System.out.println("description--["+description+"]");
}
}
retXml = getErrorXML(message, description, errId, "",msgType);
System.out.println("retXml----[" + retXml + "]");
}
else
{
retXml = getErrorXML("Message", retXml, "VTCONFTRAN", "","P");
}
}
catch(Exception e)
{
System.out.println("Exception from getErrorXml---["+ e.getMessage() +"]");
e.printStackTrace();
return retXml;
}
return retXml;
}
}
/*
Title : DistIssPrcRemote
Date : 07/03/11
Developer: Chandni Shah
*/
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ProcessLocal;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface EmpITConfPrcLocal extends ibase.webitm.ejb.ProcessLocal//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException;
}
\ No newline at end of file
/*
Title : DistIssPrcRemote
Date : 07/03/11
Developer: Chandni Shah
*/
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ProcessLocal;
import javax.ejb.Remote; // added for ejb3
@Remote // added for ejb3
public interface EmpITConfPrcRemote extends ibase.webitm.ejb.ProcessRemote//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String xtraParams) throws RemoteException,ITMException;
}
\ 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