Commit c169786c authored by manohar's avatar manohar

New ejb for contact master imported from migration folder


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@99913 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 20b09039
/********************************************************
Title : StationIC
Date : 16/11/11
Developer: Kunal Mandhre
********************************************************/
package ibase.webitm.ejb.sys;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.util.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless;
@Stateless
public class ContactIC extends ValidatorEJB implements ContactICLocal, ContactICRemote
{
GenericUtility genericUtility = GenericUtility.getInstance();
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String errString = "";
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
if (xmlString != null && xmlString.trim().length() > 0 )
{
dom = parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length() > 0 )
{
dom1 = parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0 )
{
dom2 = parseString(xmlString2);
}
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
}
catch(Exception e)
{
throw new ITMException(e);
}
return(errString);
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String stateCode = "";
String bankCode = "";
String desc = "";
String countCode = "";
String childNodeName = null;
String errString = "";
String errCode = "";
String userId = "";
String sql = "";
String errorType = "";
int count = 0;
int ctr=0;
int childNodeListLength;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null;
ConnDriver connDriver = new ConnDriver();
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
System.out.println("Station Val Start");
try
{
conn = connDriver.getConnectDB("DriverITM");
userId = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equalsIgnoreCase("state_code"))
{
stateCode = checkNull(genericUtility.getColumnValue("state_code", dom));
System.out.println("State code="+stateCode);
if(stateCode == null || stateCode.trim().length() == 0)
{
errCode = "VMSTATCD2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if(stateCode != null && stateCode.trim().length() > 0)
{
sql = "select count(*) from state where state_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,stateCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
if(count == 0)
{
errCode = "VMSTATCD2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
}
else if(childNodeName.equalsIgnoreCase("count_code"))
{
countCode = checkNull(genericUtility.getColumnValue("count_code", dom));
System.out.println("countCode"+countCode);
sql = " select count(*) from country where count_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
System.out.println("COUNT = "+count);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(count == 0)
{
errCode = "VTCONTCD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = " select count(*) from state where count_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
System.out.println("COUNT = "+count);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(count == 0)
{
errCode = "VTCONTCD2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
}
int errListSize = errList.size();
count = 0;
String errFldName = null;
if(errList != null && errListSize > 0)
{
for(count = 0; count < errListSize; count ++)
{
errCode = errList.get(count);
errFldName = errFields.get(count);
System.out.println("errCode .........." + errCode);
errString = getErrorString(errFldName, errCode, userId);
errorType = 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);
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)
{
e.printStackTrace();
errString = 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 d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
errString = errStringXml.toString();
return errString;
}
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = parseString(xmlString2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [Station][itemChanged( String, String )] :==>\n" + e.getMessage());
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String stateCode = "", countCode = "", city = "", siteCode = "";
String bankCode = "";
String descr = "";
String childNodeName = null;
String sql = "";
StringBuffer valueXmlString = new StringBuffer();
int ctr = 0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null ;
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
try
{
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
valueXmlString = new StringBuffer("<?xml version = \"1.0\"?> <Root> <header> <editFlag>");
valueXmlString.append(editFlag).append("</editFlag> </header>");
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
int childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr ++;
}while(ctr < childNodeListLength && ! childNodeName.equals(currentColumn));
if(currentColumn.trim().equalsIgnoreCase("state_code"))
{
stateCode = checkNull(genericUtility.getColumnValue("state_code", dom));
System.out.println("436 StateCode"+stateCode);
sql = " Select descr, count_code from state where state_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,stateCode);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString(1);
countCode = rs.getString(2);
}
valueXmlString.append("<state_descr>").append("<![CDATA[" + descr +"]]>").append("</state_descr>");
valueXmlString.append("<count_code>").append("<![CDATA[" + countCode +"]]>").append("</count_code>");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else if(currentColumn.trim().equalsIgnoreCase("city"))
{
city = checkNull(genericUtility.getColumnValue("city", dom));
System.out.println("436 StateCode"+stateCode);
sql = " select state_code from station where rtrim(descr) = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,city);
rs = pstmt.executeQuery();
if(rs.next())
{
stateCode = rs.getString(1);
}
valueXmlString.append("<state_code>").append("<![CDATA[" + stateCode +"]]>").append("</state_code>");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " Select descr, count_code from state where state_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,stateCode);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString(1);
countCode = rs.getString(2);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<state_descr>").append("<![CDATA[" + descr +"]]>").append("</state_descr>");
valueXmlString.append("<count_code>").append("<![CDATA[" + countCode +"]]>").append("</count_code>");
}
else if(currentColumn.trim().equalsIgnoreCase("site_code"))
{
siteCode = checkNull(genericUtility.getColumnValue("site_code", dom));
System.out.println("436 StateCode"+stateCode);
sql = " Select descr from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<site_descr>").append("<![CDATA[" + descr +"]]>").append("</site_descr>");
}
valueXmlString.append("</Detail1>");
valueXmlString.append("</Root>");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+ e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
if(pstmt != null)
pstmt.close();
if(rs != null)
rs.close();
rs = null;
pstmt = null;
conn.close();
conn = null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
return valueXmlString.toString();
}
private String checkNull(String input)
{
if(input == null)
{
input = "";
}
return input;
}
private String errorType(Connection conn , String errorCode)
{
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();
while(rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
return msgType;
}
}
/********************************************************
Title : ContactICLocal
Date : 16/11/11
Developer: Kunal Mandhre
********************************************************/
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
@Local
public interface ContactICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
/********************************************************
Title : ContactICRemote
Date : 16/11/11
Developer: Kunal Mandhre
********************************************************/
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
@Remote
public interface ContactICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
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