Commit 8f6dce6e authored by vdhoble's avatar vdhoble

for S15CSUN001


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98059 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6f654be3
package ibase.webitm.ejb.sys;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless;
@Stateless
public class EntityContact extends ValidatorEJB implements EntityContactLocal,EntityContactRemote{
E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String xmlString, String xmlString1, String xmlString2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("------------ wfvalData method called-----------------");
System.out.println("xmlString --->>> [["+xmlString+" ]]");
System.out.println("xmlString1 --->>> [["+xmlString1+" ]]");
System.out.println("xmlString2 --->>> [["+xmlString2+" ]]");
System.out.println("editFlag --->>> [["+editFlag+" ]]");
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : EntityContact.java : wfValData(String xmlString) : ==>\n"+e.getMessage());
throw new ITMException(e);
}
return errString;
} //end of wfValData
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr=0;
double quantity = 0.0,rate = 0.0 ;
String childNodeName = null;
String entityType = "",entityCode = "",contact_pers="",siteCode="",itemCode="",userId = "",sql="";
String empCode="",stanCode="",errCode="";
String errString="",errorType="",countCode="",stateCode="",keyFlag="";
Connection conn = null;
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs=null,rs1=null;
int cnt1=0,cnt=0,cnt2=0;
int currentFormNo=0;
int childNodeListLength;
int stateCnt = 0;
java.util.Date tranDateL = null;
ConnDriver connDriver = new ConnDriver();
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
try
{
SimpleDateFormat simpleDateFormatObj = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = connDriver.getConnectDB("DriverITM");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("user ID form XtraParam : "+userId +"Edit Flag -->>: "+editFlag);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
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();
System.out.println("Child name --->> "+childNodeName);
if(childNodeName.equalsIgnoreCase("entity_code")) //TRAN DATE
{
entityCode = checkNull(genericUtility.getColumnValue("entity_code",dom));
entityType = checkNull(genericUtility.getColumnValue("entity_type",dom));
System.out.println("entityType--->["+entityType+"]");
if(("S").equalsIgnoreCase(entityType)){
sql = "SELECT COUNT(*) FROM supplier WHERE SUPP_CODE = ?";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,entityCode);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
cnt = rs1.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(cnt == 0)
{
errCode = "VTENTSCODE"; //entity code should exist in supplier master
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
else if(("C").equalsIgnoreCase(entityType))
{
sql = "SELECT count(*) FROM customer WHERE cust_code = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,entityCode);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
cnt1 = rs1.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(cnt1 == 0)
{
errCode = "VTENTCCODE"; //entity code should exist in customer master
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
else if(("T").equalsIgnoreCase(entityType))
{
sql = "SELECT count(*) FROM transporter WHERE tran_code = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,entityCode);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
cnt2 = rs1.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
if(cnt2 == 0)
{
errCode = "VTTRANCD1"; //entity code should exist in transporter master
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
}
if (childNodeName.equalsIgnoreCase("contact_pers")) //SITE CODE
{
contact_pers = checkNull(genericUtility.getColumnValue("contact_pers",dom));
System.out.println("state_code---->["+contact_pers+"]");
if (contact_pers.length()==0)
{
errCode = "VTCONTPER"; //No value for Contact person
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
} //end for loop
break;
}
int errListSize = errList.size();
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( 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 ( 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
{
System.out.println("------------------ itemChanged called------------------");
System.out.println("xmlString DOM-->>["+xmlString+"]");
System.out.println("xmlString DOM1-->>["+xmlString1+"]");
System.out.println("xmlString DOM2-->>["+xmlString2+"]");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [EntityContact ][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
{
System.out.println("@@@@@@@ itemChanged called");
StringBuffer valueXmlString = new StringBuffer();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
double pickRate = 0.0,quantity = 0.0,netAmt = 0.0,rate = 0.0;
E12GenericUtility genericUtility = new E12GenericUtility();
ConnDriver connDriver = new ConnDriver();
String entityType="",sql = "";
int currentFormNo =0;
String entityCode="",descr="",Descr = "",tablename = "",entitycode = "";
PreparedStatement pstmt1 = null;
ResultSet rs1=null;
String columnValue = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
try
{
SimpleDateFormat simpleDateFormatObj = new SimpleDateFormat(genericUtility.getApplDateFormat());
Calendar currentDate = Calendar.getInstance();
String tranDate = simpleDateFormatObj.format(currentDate.getTime());
String contactPer = "";
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver=null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext.trim());
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("-------- currentFormNo : "+currentFormNo);
switch(currentFormNo)
{
case 1 :
valueXmlString.append("<Detail1>");
System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
System.out.println("editFlag =>" +editFlag);
if( currentColumn.trim().equalsIgnoreCase( "itm_defaultedit" ) )
{
contactPer = checkNull(genericUtility.getColumnValue("contact_pers",dom));
entityType = checkNull(genericUtility.getColumnValue("entity_type",dom));
entityCode = checkNull(genericUtility.getColumnValue("entity_code",dom));
System.out.println("entity_code ----->>["+entityCode+"]");
if(("S").equalsIgnoreCase(entityType))
{
Descr = "sh_name";
tablename = "supplier";
entitycode = "supp_code";
}
else if(("C").equalsIgnoreCase(entityType))
{
Descr = "CUST_NAME";
tablename = "customer";
entitycode = "cust_code";
}
else if(("T").equalsIgnoreCase(entityType))
{
Descr = "tran_name";
tablename = "transporter";
entitycode = "tran_code";
}
sql = "select "+Descr+" from "+tablename+" where "+entitycode+" = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,entityCode);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
descr = rs1.getString(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
valueXmlString.append("<ent_descr>").append("<![CDATA[" + descr + "]]>").append("</ent_descr>");
valueXmlString.append( "<entity_type protect ='1'>" ).append("<![CDATA[" + entityType + "]]>").append( "</entity_type>\r\n" );
valueXmlString.append( "<contact_pers protect ='1'>" ).append("<![CDATA[" + contactPer + "]]>").append( "</contact_pers>\r\n" );
}
else if (currentColumn.trim().equals("entity_code"))//FOR SITE CODE
{
entityType = checkNull(genericUtility.getColumnValue("entity_type",dom));
entityCode = checkNull(genericUtility.getColumnValue("entity_code",dom));
System.out.println("entity_code ----->>["+entityCode+"]");
if(("S").equalsIgnoreCase(entityType))
{
Descr = "sh_name";
tablename = "supplier";
entitycode = "supp_code";
}
else if(("C").equalsIgnoreCase(entityType))
{
Descr = "CUST_NAME";
tablename = "customer";
entitycode = "cust_code";
}
else if(("T").equalsIgnoreCase(entityType))
{
Descr = "tran_name";
tablename = "transporter";
entitycode = "tran_code";
}
sql = "select "+Descr+" from "+tablename+" where "+entitycode+" = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,entityCode);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
descr = rs1.getString(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
valueXmlString.append("<ent_descr>").append("<![CDATA[" + descr + "]]>").append("</ent_descr>");
}
valueXmlString.append("</Detail1>");
break;
}// end switch
valueXmlString.append("</Root>");
} //end try-------------------------------------------------------------
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(conn!=null)
{
conn.close();
conn = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
return valueXmlString.toString();
}
protected int getDBRowCount(Connection conn, String table_name, String whrCondCol, String whrCondVal)
{
int count=-1;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="select count(1) from "+table_name+" where "+whrCondCol+" = ?";
System.out.println("SQL in getDBRowCount method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception In getDBRowCount method of SalesBudgetCustIC Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getDBRowCount method of SalesBudgetCustIC Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("Connection passed to SalesBudgetCustIC.getDBRowCount() method ");
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}
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, checkNull(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;
}
public String checkNull(String input)
{
if (input == null)
{
input="";
}
return input.trim();
}
public String getColumnDescr(Connection conn, String columnName ,String tableName, String columnName2, String value)
{
PreparedStatement pstmt = null ;
ResultSet rs = null ;
String sql = "";
String findValue = "";
try
{
sql = "SELECT " + columnName + " from " + tableName + " where " + columnName2 +"= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,value);
rs = pstmt.executeQuery();
if(rs.next())
{
findValue = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
System.out.println("Exception in getColumnDescr ");
e.printStackTrace();
}
System.out.println("returning String from getColumnDescr " + findValue);
return findValue;
}
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.w3c.dom.Document;
import javax.ejb.Stateless;
@Local
public interface EntityContactLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
@Remote
public interface EntityContactRemote extends ValidatorLocal{
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, 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