Commit 57e0d77c authored by manohar's avatar manohar

This commit was generated by cvs2svn to compensate for changes in r11, which

included commits to RCS files with non-trunk default branches.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@91076 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 64e53f4e
package ibase.webitm.ejb.sys;
public class CbBean
{
private String fldName= "";
private String compName= "";
private String methName= "";
private String formNo ="";
public void setFldName(String fldNm)
{
this.fldName = fldNm;
}
public String getFldName()
{
return fldName;
}
public void setCompName(String compNm)
{
this.compName = compNm;
}
public String getCompName()
{
return compName;
}
public void setMethName(String methNm)
{
this.methName = methNm;
}
public String getMethName()
{
return methName;
}
public String getFormNo()
{
return formNo;
}
public void setFormNo(String formNo)
{
this.formNo = formNo;
}
}
\ No newline at end of file
/*
Window Name : W_file_to_batch_load
*/
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.dis.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
import ibase.ejb.*;
import ibase.system.config.*;
import java.util.*;
import java.lang.*;
import javax.annotation.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class CreateBatchPrc extends ProcessEJB implements CreateBatchPrcLocal , CreateBatchPrcRemote // SessionBean
{
Connection conn = null;
ITMDBAccessEJB itmDBAccessEJB = null;
CommonConstants commonConstants;
GenericUtility genericUtility = GenericUtility.getInstance();
String userId = "";
String logInSite = "";
int tran_sl = 0;
String win_name= "";
String batch_id = "";
String xtraParam = "";
@PostConstruct
public void createCall() throws RemoteException //, CreateException
{
try
{
itmDBAccessEJB = new ITMDBAccessEJB();
ConnDriver conndriver = new ConnDriver();
conn = conndriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
commonConstants = new CommonConstants();
System.out.println("CreateBatchPrcEJB ejbCreate called.........");
}
catch (Exception e)
{
System.out.println("Exception :CreateBatchPrcEJB :ejbCreate :==>"+e);
e.printStackTrace();
//throw new CreateException();
}
}
/*public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String process() throws RemoteException,ITMException
{
return "";
}
//process()
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
xtraParam = xtraParams;
String retStr = "";
Document detailDom = null;
Document headerDom = null;
GenericUtility genericUtility = GenericUtility.getInstance();
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, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :CreateBatchPrcEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
String childNodeName = "";
String errCode = null;
String errString = null;
int parentNodeListLength = 0;
int childNodeListLength = 0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
java.io.File file = null;
Node parentNode = null;
Node childNode = null;
String filePath = "";
String winName = "";
xtraParam = xtraParams;
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
logInSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
try
{
parentNodeList = headerDom.getElementsByTagName("Detail1");
parentNodeListLength = parentNodeList.getLength();
System.out.println("ParentNodeListLength:::::::::::::::::::::::"+parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("ChildNodeListLength:::::::::::::: "+ childNodeListLength);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
System.out.println("Inside for loop...........");
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
if (childNodeName.equals("window_name"))
{
winName = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("winName::::::::::: "+ winName);
}
if (childNodeName.equals("file_path"))
{
filePath = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("file_path:::::::: "+ filePath);
}
}
}
win_name = winName;
file = new java.io.File(filePath.trim());
if(file.exists())
{
System.out.println("FILE FOUND");
errString = gfCreateBatch(file,winName);
System.out.println("errString"+errString);
}
else
{
System.out.println("File Not Found");
errCode = "VBFILEOPEN";
errString = itmDBAccessEJB.getErrorString("",errCode,"");
System.out.println("errString"+errString);
}
}//try end
catch(Exception e)
{
System.out.println("Exception :process(String xmlString2, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
return errString;
}
//FUNCTION GFCREATEBATCH
public String gfCreateBatch(java.io.File filePath,String winName)throws RemoteException,ITMException
{
int fildNos = 0;
int fildNod = 0;
int objSld = 0;
int lisubPos = 0;
int colWidth =0;
int store = 0;
int lineNo = 0;
int pos = 0;
int pos1 = 0;
int pos2 = 0;
int pos4 =0;
int liObjs = 0;
int row = 0;
int row1 = 0;
int liObj [] = new int[1000];
int liRecWidth [] = new int[1000];
int brow = 0;
long fpos = 0;
int hdr = 1;
long flen = 0;
String constantVal = "";
String dateFormat ="";
String suffix = " ";
String prefix = "";
String alignment = "";
String version = "";
String identifier = "";
String fldData= "";
String totFunc="";
String func = "";
String retCode= "";
String entity = "";
String entitySource ="";
String entitySourceRef = "";
String winNameLoad = "";
String SubjectSstr = "";
String entityAddnl= "";
String transer = "";
String xfrtax = "";
String statOption = "";
String edimedium = " ";
String columnSep = "";
String nullInter = "";
String query = " ";
String sql = " ";
String errCode = "";
String batchNo = "";
String errString = "";
String sqlbins = "";
String lsHeader[] = new String[1000];
PreparedStatement spstmt = null;
PreparedStatement pstmt = null;
PreparedStatement pstBatchDet = null;
ResultSet rs = null;
Statement stmt1 = null;
ResultSet rs1 = null;
long start = System.currentTimeMillis();
System.out.println("Going To Insert in BatchLoad ...................");
// GETS THE MAXIMUM DATAWINDOW CONTROL PRESENT AND DEFINED IN EDI FOR THE SPECIFIED WINDOW
query ="SELECT MAX(EDI_CONTROL_DET.OBJ_SL__SOURCE) + 1 FROM EDI_CONTROL_DET,EDI_CONTROL "
+" WHERE ( EDI_CONTROL_DET.WIN_NAME = ? ) AND "
+"( EDI_CONTROL.WIN_NAME = EDI_CONTROL_DET.WIN_NAME ) AND "
+"( EDI_CONTROL.LINE_NO = EDI_CONTROL_DET.LINE_NO ) AND "
+"( EDI_CONTROL.EDI_MEDIUM = 2 )";
try
{
spstmt = conn.prepareStatement(query);
spstmt.setString(1,winName.trim());
rs = spstmt.executeQuery();
if(rs.next())
{
liObjs = rs.getInt(1);
}
rs.close();
spstmt.close();
}
catch(SQLException ex)
{
try{conn.rollback();}catch(Exception ee1){}
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed1]" + query + ex.getMessage());
}
catch(Exception ex1)
{
try{conn.rollback();}catch(Exception ee2){}
System.out.println("Exception ::"+query +ex1.getMessage());
ex1.printStackTrace();
}
query="SELECT LINE_NO, ENTITY, ENTITY_SOURCE, ENTITY_SOURCE_REF, "
+"WIN_NAME__LOAD, SUBJECT_STR, ENTITY_ADDNL, REF_SER, XFR_TAX, STAT_OPTION, "
+"EDI_MEDIUM,COLUMN_SEPRATOR,INTERPRET_NULL"
+" FROM EDI_CONTROL WHERE WIN_NAME = ? AND EDI_MEDIUM = 2 ";
try
{
spstmt = conn.prepareStatement(query);
spstmt.setString(1,winName);
rs = spstmt.executeQuery();
while (rs.next())
{
batchNo = generateBatchNo();
batch_id = batchNo;
String ins = "";
//INSERTING A RECORD IN BATCHLOAD
lineNo = rs.getInt(1);
entity = rs.getString(2);
entitySource = rs.getString(3);
entitySourceRef = rs.getString(4);
winNameLoad = rs.getString(5);
SubjectSstr = rs.getString(6);
entityAddnl = rs.getString(7);
transer = rs.getString(8);
xfrtax = rs.getString(9);
statOption = rs.getString(10);
edimedium = rs.getString(11);
columnSep = rs.getString(12);
nullInter = rs.getString(13);
/*System.out.println("lineNo"+lineNo);
System.out.println("entity"+entity);
System.out.println("entitySource"+entitySource);
System.out.println("entitySourceRef"+entitySourceRef);
System.out.println("winNameLoad"+winNameLoad);
System.out.println("SubjectSstr"+SubjectSstr);
System.out.println("entityAddnl"+entityAddnl);
System.out.println("transer"+transer);
System.out.println("statOption"+xfrtax);
System.out.println("edimedium"+edimedium);
System.out.println("columnSep"+columnSep);
System.out.println("nullInter"+nullInter);*/
//INSERT A ROW IN BATCHLOAD TABLE FOR TRAN_SL = 1
ins = "INSERT INTO BATCHLOAD ( BATCH_ID,TRAN_SL,WIN_NAME, LOAD_STAT, EDI_ADDR, CHG_DATE, CHG_USER, CHG_TERM, LOAD_MODE ) "
+" VALUES(?, ?,?,?, ?,?, ?,?, ?)";
java.sql.Timestamp ts=new java.sql.Timestamp(System.currentTimeMillis());
SimpleDateFormat sdt=new SimpleDateFormat(genericUtility.getDBDateFormat());
try
{
pstmt = conn.prepareStatement(ins);
pstmt.setString(1,batchNo);
pstmt.setInt(2,1);
pstmt.setString(3,winName);
pstmt.setString(4,"N");
pstmt.setString(5,"");
pstmt.setDate(6,java.sql.Date.valueOf(sdt.format(ts)));
pstmt.setString(7,userId);
pstmt.setString(8,userId);
pstmt.setString(9,"0");
pstmt.executeUpdate();
pstmt.close();
System.out.println("Insert Batchload For Header :::::::::::::::::::::::::::::::::::::::::1");
}
catch(SQLException se2)
{
try{conn.rollback();}catch(Exception ee3){}
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed2]" + ins + se2.getMessage());
}
catch(Exception ex2)
{
try{conn.rollback();}catch(Exception ee6){}
System.out.println("Exception ::"+ex2.getMessage());
ex2.printStackTrace();
}//INSERTING END
// FOR LOOP DEFINED TO GET THE LENGTH OF EACH RECORD IN SPECIFIED DATAWINDOW CONTROL
for (row = 1 ;row<= liObjs ; row++)
{
try
{
//stmt = conn.createStatement();
int temp = row - 1 ;
sql = "SELECT EDI_CONTROL_DET.OBJ_SL__SOURCE,SUM(EDI_CONTROL_DET.COL_WIDTH) "
+"FROM EDI_CONTROL_DET,EDI_CONTROL "
+" WHERE EDI_CONTROL_DET.WIN_NAME = ? AND "
+" ( EDI_CONTROL.WIN_NAME = EDI_CONTROL_DET.WIN_NAME ) AND "
+" ( EDI_CONTROL.LINE_NO = EDI_CONTROL_DET.LINE_NO ) AND "
+" ( EDI_CONTROL.EDI_MEDIUM = 2 ) AND OBJ_SL__SOURCE = ?"
+" GROUP BY OBJ_SL__SOURCE ";
spstmt = conn.prepareStatement(sql);
spstmt.setString(1,winName);
spstmt.setInt(2,temp);
rs1 = spstmt.executeQuery();
while(rs1.next())
{
liObj [row] = rs1.getInt(1);
liRecWidth [row] = rs1.getInt(2);
}
rs1.close();
}
catch(SQLException se4)
{
try{conn.rollback();}catch(Exception ee4){}
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed3]" + sql + se4.getMessage());
}
catch(Exception ex4)
{
try{conn.rollback();}catch(Exception ee7){}
System.out.println("Exception ::"+ex4.getMessage());
ex4.printStackTrace();
}
}//END OF FOR
// FOR LOOP DEFINED TO HOLD THE IDENTIFIERS OF EACH RECORD OF SPECIFIED DATAWINDOW CONTROL IN AN ARRAY
for (row = 1; row <= liObjs;row++)
{
try
{
int temp = row - 1;
sql = " SELECT CONSTANT_VAL FROM EDI_CONTROL_DET WHERE"
+ " WIN_NAME = ? AND FLD_NO__DEST = 0 AND OBJ_SL__SOURCE =? AND ROWNUM = 1 "
+" ORDER BY OBJ_SL__SOURCE,FLD_NO__DEST";
spstmt = conn.prepareStatement(sql);
spstmt.setString(1,winName);
spstmt.setInt(2,temp);
rs1 = spstmt.executeQuery();
while(rs1.next())
{
lsHeader [row] = rs1.getString(1);
if (lsHeader[row].length() == 0)
{
lsHeader[row] = "@@";
}
}
rs1.close();
}
catch(SQLException se5)
{
try{conn.rollback();}catch(Exception ee8){}
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed4]" + sql + se5.getMessage());
}
catch(Exception ex5)
{
conn.rollback();
System.out.println("Exception ::"+ex5.getMessage());
ex5.printStackTrace();
}
}//END FOR
//DO LOOP DEFINED TO CONTINUE TILL THE ENTIRE FILE IS READ
RandomAccessFile rf= null;
rf = new RandomAccessFile(filePath,"r");
flen = rf.length();
sql ="";
fpos = 0;
objSld = 0;
//PREPARING STSTEMENT FOR
sqlbins = "INSERT INTO BATCHLOADDET (BATCH_ID,TRAN_SL,OBJ_SL,OBJ_SSL,FLD_NO,FLD_DATA) "
+" VALUES(?, ?,?,?, ?,?)";
pstBatchDet = conn.prepareStatement(sqlbins);
while(fpos < flen)
{
for (row = 1 ;row <= liObjs;row++)
{
// NOTE THAT CONDITION CAN BE CHECKED WITH ONLY THE HEADER (row = 1)
if (row ==1)
{
while(true)
{
boolean booln = gfCheckcon(winName,lineNo,fldData = read(fpos,liRecWidth[row],rf));
if (!(booln ) )
{
fpos = fpos + liRecWidth[row];
System.out.println("calculate done for hdr...........");
}
else
{
System.out.println("enter else");
break;
}
}
}
int temp = row - 1;
sql = "SELECT A.FLD_NO__SOURCE, A.CONSTANT_VAL, A.OBJ_SL__DEST, A.FLD_NO__DEST, A.SUBJECT_POS, "
+"A.COL_WIDTH, A.DATE_FORMAT, A.SUFFIX, A.PREFIX, A.ALIGNMENT, A.VERSION, A.TRAN_IDENTIFIER "
+" FROM EDI_CONTROL_DET A, EDI_CONTROL B WHERE A.WIN_NAME = B.WIN_NAME AND A.LINE_NO = B.LINE_NO "
+" AND B.WIN_NAME = ? AND A.OBJ_SL__SOURCE = ?"
+" AND B.EDI_MEDIUM = 2 ORDER BY A.OBJ_SL__SOURCE,A.FLD_NO__DEST";
try
{
spstmt = conn.prepareStatement(sql);
spstmt.setString(1,winName);
spstmt.setInt(2,temp);
rs1 = spstmt.executeQuery();
while(rs1.next())
{
fildNos = rs1.getInt(1);
constantVal = rs1.getString(2);
objSld = rs1.getInt(3);
fildNod = rs1.getInt(4);
lisubPos = rs1.getInt(5);
colWidth = rs1.getInt(6);
dateFormat = rs1.getString(7);
suffix = rs1.getString(8);
prefix = rs1.getString(9);
alignment = rs1.getString(10);
version = rs1.getString(11);
identifier = rs1.getString(12);
fldData = read(fpos,colWidth,rf);
fpos = fpos + colWidth;
/*System.out.println("version:"+version);
System.out.println("fildNos:"+fildNos);
System.out.println("constantVal:"+constantVal);
System.out.println("objSld:"+objSld);
System.out.println("fildNod:"+fildNod);
System.out.println("lisubPos:"+lisubPos);
System.out.println("colWidth:"+colWidth);
System.out.println("dateFormat:"+dateFormat);
System.out.println("suffix:"+suffix);
System.out.println("prefix:"+prefix);
System.out.println("alignment:"+alignment);
System.out.println("version:"+version);
System.out.println("identifier:"+identifier);
System.out.println("fldData:"+fldData);
System.out.println("fpos:"+fpos);
version = "abc";*/
if(version != null)
{
System.out.println("VersionCheck:::");
if (!(version.trim().equals(fldData.trim())))
{
System.out.println("Version::::"+version);
System.out.println("fldData::::"+fldData);
errCode = "VTEDIVER";
errString = itmDBAccessEJB.getErrorString("",errCode,"");
return errString;
}
}
else if (identifier != null)
{
if (colWidth ==0 || (fldData.trim().length()==0))
{
fldData = constantVal.trim();
}
if (!(identifier.trim().equals(fldData.trim())))
{
System.out.println("identifier::::"+identifier);
System.out.println("fldData::::"+fldData);
errCode = "VTEDIIDT";
errString = itmDBAccessEJB.getErrorString("",errCode,"");
return errString;
}
}
if ((suffix != null) && (suffix.length() > 0))
{
fldData = fldData.substring(0,colWidth - suffix.length());
}
else if(prefix != null && (prefix.length() > 0))
{
fldData = fldData.substring(prefix.length(),prefix.length()+colWidth);
}
else if (fldData.trim().equals(""))
{
fldData = "<NULL>";
}
else if (dateFormat != null && (dateFormat.length() > 0))
{
fldData = fldData.substring(0,0+4)+"-"+fldData.substring(4,4+2)+"-"+fldData.substring(6,6+2);
}
// INSERT INTO BATCHLOADDET ONLY IF THE SOURCE COLUMN IS NOT ZERO
if (fildNos!= 0 )
{
//System.out.println("INSERTING INTO ITEM SQL :: "+sqlbins);
try
{
/*System.out.println("BatchNo:"+batchNo);
System.out.println("TRAN_SL:"+hdr);
System.out.println("OBJ_SL:"+objSld);
System.out.println("OBJ_SSL:"+brow);
System.out.println("FLD_NO:"+fildNos);
System.out.println("FLD_DATA:"+fldData);*/
pstBatchDet.setString(1,batchNo);
pstBatchDet.setInt(2,hdr);
pstBatchDet.setInt(3,objSld);
pstBatchDet.setInt(4,brow);
pstBatchDet.setInt(5,fildNos);
pstBatchDet.setString(6,fldData);
pstBatchDet.addBatch();
//pstBatchDet.executeUpdate();
System.out.println("SuccessEntryBLD Header("+hdr+")ObjSsl("+brow+")ObjSL("+objSld+")FP("+fpos+")Len("+flen+")");
store = objSld;
}
catch(SQLException se6)
{
conn.rollback();
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed5]" + sqlbins + se6.getMessage());
}
catch(Exception ex6)
{
conn.rollback();
System.out.println("Exception1 ::"+ex6.getMessage());
ex6.printStackTrace();
}
}
}//END OF WHILE INNER LOOP
rs1.close();
spstmt.close();
}
catch(SQLException se25)
{
conn.rollback();
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed27]"+sql );
se25.printStackTrace();
}
catch(Exception ex25)
{
conn.rollback();
System.out.println("Exception23::"+ex25.getMessage());
ex25.printStackTrace();
}
// FOR LOOP DEFINED TO CONTINUE READ THE NEXT STRING AND TO CHECK IF IT MATCHES WITH ANY SPECIFIED IDENTIFIERS
for (row1 = 1 ; row1 <=liObjs;row1++)
{
int temp11 = row1 - 1;
String selsql = " SELECT COL_WIDTH,OBJ_SL__DEST FROM EDI_CONTROL_DET "
+" WHERE WIN_NAME = ? AND OBJ_SL__SOURCE = ?"
+" AND FLD_NO__DEST = 0 AND ROWNUM = 1 ORDER BY OBJ_SL__SOURCE,FLD_NO__DEST";
try
{
spstmt = conn.prepareStatement(selsql);
spstmt.setString(1,winName);
spstmt.setInt(2,temp11);
rs1= spstmt.executeQuery();
if(rs1.next())
{
colWidth = rs1.getInt(1);
objSld = rs1.getInt(2);
}
rs1.close();
spstmt.close();
}//end try
catch(SQLException se15)
{
conn.rollback();
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed7]"+selsql );
se15.printStackTrace();
}
catch(Exception ex15)
{
conn.rollback();
System.out.println("Exception3::"+ex15.getMessage());
ex15.printStackTrace();
}
fldData = read(fpos,colWidth,rf);
//System.out.println("lsHeader[row1]:"+lsHeader[row1]);
//System.out.println("fldData:"+fldData.trim());
if(fldData.trim().equals(lsHeader[row1].trim()))
{
row = row1 - 1;
//INSERT ANOTHER RECORD FOR NEXT HEADER IN BATCHLOAD
if (row1 ==1)
{
hdr = hdr + 1;
brow = 1;
String sqlins = " ";
sqlins = "INSERT INTO BATCHLOAD ( BATCH_ID,TRAN_SL,WIN_NAME, LOAD_STAT, EDI_ADDR, CHG_DATE, CHG_USER, CHG_TERM, LOAD_MODE )"
+" VALUES ( ?,?,?,?,?,?,?, ?,?)";
try
{
pstmt = conn.prepareStatement(sqlins);
pstmt.setString(1,batchNo);
pstmt.setInt(2,hdr);
pstmt.setString(3,winName );
pstmt.setString(4,"N");
pstmt.setString(5," ");
pstmt.setTimestamp(6,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.setString(7,userId);
pstmt.setString(8,userId);
pstmt.setString(9,"0");
pstmt.executeUpdate();
pstmt.close();
System.out.println("Insert Batchload For Header ::::::::::::::::::::::::::::::::::::::::"+hdr);
}
catch(SQLException se22)
{
conn.rollback();
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed6]" + sqlins + se22.getMessage());
}
catch(Exception ex22)
{
conn.rollback();
System.out.println("Exception2 ::"+ex22.getMessage());
ex22.printStackTrace();
}//INSERTING END
}
else
{
// IF THE STRING MATCHES WITH THE EXISTING DATAWINDOW CONTROL THEN INCREMENT THE
// RECORD READ OF THAT CONTROL ELSE REINITIALISE THE RECORD READ OF THAT CONTROL TO 1.
if (objSld == store)
{
brow = brow + 1;
}
else
{
brow = 1;
}
}
}
}//end for
}//endfor
}//END OF FILE READ
}//OUTER END OF WHILE
rs.close();
pstBatchDet.executeBatch();
udateBatchLoadNOR(batchNo, winName);
}//END OF OUTER TRY
catch(SQLException se12)
{ try{conn.rollback();}catch(Exception ee11){}
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed9]" + sql + se12.getMessage());
}
catch(Exception ex12)
{
try{conn.rollback();}catch(Exception ee9){}
System.out.println("Exception5::"+ex12.getMessage());
ex12.printStackTrace();
}
finally
{
try
{
System.out.println("Closing Connection......");
conn.commit();
spstmt.close();
}catch(SQLException se){}
}
System.out.println("Successfully data load in to batchload!!!!!!!!!!!!!!!!!!!!!!!!!");
try
{
//String batchNo = "CP114-000000008";
InitialContext ctx1 = null;
AppConnectParm appConnect = new AppConnectParm();
ctx1 = new InitialContext(appConnect.getProperty());
MasterApplyHome maObjHome = (MasterApplyHome)ctx1.lookup("MasterApply");
MasterApply maObj = maObjHome.create();
System.out.println("batchNo::::::::::::::"+ batchNo);
maObj.applyMasterTable(batchNo,xtraParam);
}
catch(Exception exc){ System.out.println(exc.getMessage());}
long end = System.currentTimeMillis();
System.out.println(" [Loading Details] ");
System.out.println("__________________________________________________");
System.out.println("Load in ["+ (end-start) +"+]MilliSecond");
System.out.println("WinDow name:::"+win_name);
System.out.println("BatchId name:::"+batch_id);
System.out.println("Total TranSl(Header):::"+tran_sl);
System.out.println("___________________________________________________");
return errString;
}//END OF FUNCTION GFCREATEBATCH
// FUNCTION GF_CHECK_CONDITION
boolean gfCheckcon(String winName,int lineNo,String data)
{
int colNo = 0;
int count = 0;
int pos = 0;
int fldNod = 0;
int colWidth = 0;
String compValue = "";
String oper = "";
String ediMethod = "";
String totFunc = "";
String retCode = "";
String mcoltype = "";
String constantVal ="";
String chkValue = "";
boolean flag;
flag = true;
ResultSet lrs = null;
PreparedStatement pst = null;
PreparedStatement pst1 = null;
ResultSet lrs1 = null;
String sql1 = "";
String sql ="select col_no, comp_operator, comp_value, edi_method from edi_control_values a, edi_control b "
+"where a.win_name = b.win_name and a.line_no = b.line_no and b.win_name = ? "
+"and b.line_no =? "
+"and b.edi_medium = 2 ";
try
{
pst = conn.prepareStatement(sql);
pst.setString(1,winName);
pst.setInt(2,lineNo);
lrs = pst.executeQuery();
while(lrs.next())
{
colNo = lrs.getInt(1);
oper = lrs.getString(2);
compValue =lrs.getString(3);
ediMethod = lrs.getString(4);
oper = oper.trim();
compValue = compValue.trim();
if (compValue.trim().length()== 0 )
{
try
{
compValue = "";
sql1 = "SELECT CONSTANT_VAL, FLD_NO__DEST, COL_WIDTH FROM EDI_CONTROL_DET "
+"WHERE WIN_NAME = ? "
+" AND OBJ_SL__SOURCE =0 AND OBJ_SL__DEST = 0 "
+"ORDER BY OBJ_SL__SOURCE,FLD_NO__DEST";
pos = 1;
pst1 = conn.prepareStatement(sql1);
pst1.setString(1,winName);
lrs1 = pst1.executeQuery();
while(lrs1.next())
{
constantVal = lrs1.getString(1);
fldNod = lrs1.getInt(2);
colWidth = lrs1.getInt(3);
chkValue = data.substring(pos,pos+colWidth);
pos = pos + colWidth;
chkValue = chkValue;
}
pst1.close();
//System.out.println("Query Successfully execute...............");
}
catch(SQLException se1)
{
conn.rollback();
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed10]" + sql + se1.getMessage());
}
catch(Exception ex1)
{
conn.rollback();
System.out.println("Exception6 ::"+ex1.getMessage());
ex1.printStackTrace();
}
if (ediMethod != null && (ediMethod.trim().length()) > 0 )
{
if (retCode.equals("N"))
{
flag = false;
}
else
{
chkValue = retCode;
}
}
if (oper.equals("=" ))
{
if (compValue.equals(chkValue))
{
flag = true;
}
else
{
flag = false;
}
}
else if (oper.equals(">" ))
{
if (compValue.compareTo(chkValue)<0)
{
flag = true;
}
else
{
flag = false;
}
}
else if (oper.equals("<" ))
{
if (compValue.compareTo(chkValue)>0)
{
flag = true;
}
else
{
flag = false;
}
}
else if (oper.toLowerCase().equals("in"))
{
if (compValue.indexOf(chkValue) > 0 )
{
flag = true;
}
else
{
flag = false;
}
}
else if (oper.toLowerCase().equals("not in"))
{
if (compValue.indexOf(chkValue) == 0 )
{
flag = true;
}
else
{
flag = false;
}
}
else if (oper.equals("<>"))
{
if (compValue != chkValue)
{
flag = true;
}
else
{
flag = false;
}
}
}
}//end while
pst.close();
}
catch(SQLException se)
{
System.out.println("SQLException :[CreateBatchEJB][Excuting Query Failed11]" + sql + se.getMessage());
}
catch(Exception ex)
{
System.out.println("Exception7::"+ex.getMessage());
ex.printStackTrace();
}
return flag;
}
//READ SPECIFIC NO OF CHARACTER FORM FILE
String read(long l,int len,RandomAccessFile refRf)
{
String str = "";
try
{
refRf.seek(l);
for(int i=1;i<= len;i++)
{
char c =(char)refRf.readByte();
str = str + c;
}
}
catch(Exception e){System.out.println("Exception in reading File"+e.getMessage());}
return str;
}
//GENERATING BATCHID
public String generateBatchNo()
{
System.out.println("Generating in batchload!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Connection conn1 = null;
Statement lstmt = null;
ResultSet lrs = null;
String keyStringQuery = null;
String tranId = null;
try
{
ConnDriver conndriver = new ConnDriver();
conn1 = conndriver.getConnectDB("DriverITM");
keyStringQuery = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW) = 'I-BL'";
System.out.println("keyStringQuery::"+keyStringQuery);
lstmt = conn1.createStatement();
lrs = lstmt.executeQuery(keyStringQuery);
String tranSer = "";
String keyString = "";
String keyCol = "";
if (lrs.next())
{
keyString = lrs.getString(1);
keyCol = lrs.getString(2);
tranSer = lrs.getString(3);
}
else
{
lstmt.close();
keyStringQuery = "SELECT KEY_STRING, TRAN_ID_COL, REF_SER FROM TRANSETUP WHERE UPPER(TRAN_WINDOW) = 'GENERAL'";
System.out.println("keyStringQuery::"+keyStringQuery);
lstmt = conn1.createStatement();
lrs = lstmt.executeQuery(keyStringQuery);
if (lrs.next())
{
keyString = lrs.getString(1);
keyCol = lrs.getString(2);
tranSer = lrs.getString(3);
}
}
System.out.println("keyString :"+keyString);
System.out.println("keyCol :"+keyCol);
System.out.println("tranSer :"+tranSer);
String xmlValues = "";
xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues +"</Detail1></Root>";
System.out.println("xmlValues :["+xmlValues+"]");
TransIDGenerator tg = new TransIDGenerator(xmlValues, "SUN", commonConstants.DB_NAME);
tranId = tg.generateTranSeqID(tranSer, keyCol, keyString, conn1);
System.out.println("tranId ::"+tranId);
}
catch(SQLException se)
{
System.out.println("SQLException :Generating id[failed] : " + "\n" +se.getMessage());
}
catch(Exception ex)
{
System.out.println("Exception8:Generating id [failed]:" + "\n" +ex.getMessage());
}
finally
{
if (lstmt != null)
{
lstmt = null;
}
}
return tranId;
}
private void udateBatchLoadNOR(String batchNo,String winName )
{
PreparedStatement pstmt = null;
ResultSet rs = null;
PreparedStatement psUpdateBl = null;
String sqlTotTranSl = "SELECT COUNT(*) FROM BATCHLOAD WHERE BATCH_ID = ? AND WIN_NAME = ?";
String sqlCountTotDetRec = "SELECT COUNT(*) FROM BATCHLOADDET WHERE BATCH_ID = ? AND TRAN_SL = ?";
String update = "UPDATE BATCHLOAD SET NO_OF_RECORDS = ? WHERE BATCH_ID =? AND TRAN_SL=? ";
int totTranSl = 0;
int totalDetRec = 0;
try
{
pstmt = conn.prepareStatement(sqlTotTranSl);
pstmt.setString(1,batchNo.trim());
pstmt.setString(2,winName.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
totTranSl = rs.getInt(1);
}
rs.close();
pstmt.close();
}
catch(SQLException se)
{
System.out.println("SQLException :[CreateBatchPrcEJB][udateBatchLoad()][Excuting Query Failed(count tot transl from batchload)]" + sqlTotTranSl + se.getMessage());
}
catch(Exception ex)
{
System.out.println("Exception3[CreateBatchPrcEJB][udateBatchLoad()][Excuting Query Failed(count tot transl from batchload)] ::"+sqlTotTranSl +ex.getMessage());
ex.printStackTrace();
}
System.out.println("TOTALHEADER IN BATCHLOAD ::::"+totTranSl);
for(int transl =1 ;transl<=totTranSl;transl++)
{
try
{
totalDetRec = 0;
pstmt = conn.prepareStatement(sqlCountTotDetRec);
pstmt.setString(1,batchNo.trim());
pstmt.setInt(2,transl);
rs = pstmt.executeQuery();
if(rs.next())
{
totalDetRec = rs.getInt(1);
}
rs.close();
pstmt.close();
}
catch(SQLException se1)
{
System.out.println("SQLException :[CreateBatchPrcEJB][udateBatchLoad()][Excuting Query Failed(count det rec)]" + sqlCountTotDetRec + se1.getMessage());
}
catch(Exception ex1)
{
System.out.println("Exception3[CreateBatchPrcEJB][udateBatchLoad()] ::"+sqlCountTotDetRec +ex1.getMessage());
ex1.printStackTrace();
}
try
{
psUpdateBl = conn.prepareStatement(update);
psUpdateBl.setInt(1,totalDetRec);
psUpdateBl.setString(2,batchNo.trim());
psUpdateBl.setInt(3,transl);
psUpdateBl.executeUpdate();
psUpdateBl.close();
}
catch(SQLException seUpdate)
{
System.out.println("SQLException(Update Batchload) :[domCreation][Excuting Query Failed ]" + update + seUpdate.getMessage());
}
catch(Exception exUpdate)
{
System.out.println("Exception3(Update Batchload) ::"+update +exUpdate.getMessage());
exUpdate.printStackTrace();
}
}
}
}//END OF EJB
\ No newline at end of file
package ibase.webitm.ejb.sys;
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 CreateBatchPrcLocal extends ibase.webitm.ejb.ProcessLocal//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ProcessRemote;
public interface CreateBatchPrcRemote extends ibase.webitm.ejb.ProcessRemote//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.*;
import ibase.webitm.ejb.*;
import ibase.webitm.bean.*;
import ibase.utility.CommonConstants;
import ibase.system.config.*;
import ibase.utility.UserInfoBean;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.*;
import java.rmi.*;
import javax.ejb.*;
import javax.rmi.*;
import java.io.File;
import java.io.FileWriter;
import java.io.*;
import java.lang.String;
import org.apache.log4j.*;
import org.w3c.dom.*;
public class DownloadCSVBatchBean implements Schedule
{
protected ibase.utility.UserInfoBean userInfo = null;
public void downloadTransaction( String objName, String downloadLoc, String entityCode, String entityType, String siteCodeDnld, String custCodeDnld ) throws RemoteException, ITMException
{
//String entityType = null;
//String entityCode = null;
String templUpld = null;
String templTypeUpld = null;
String templDnld = null;
String templTypeDnld = null;
String objEximpFmt = null;
TranXmlData client = null;
String dnldFileName = null;
String xmlToCsvStr = null;
HashMap tranFileMip = new HashMap();
String tranId = null;
String custCode = null;
String uniformCode = null;
String dt = null;
String prvCustCode = null;
String previousDay = null;
int recCounter = 0;
String fileName = null;
boolean isTemplateExist = false;
siteCodeDnld = ( siteCodeDnld != null && siteCodeDnld.equalsIgnoreCase( "null" ) ) ? "" : siteCodeDnld.trim();
custCodeDnld = ( custCodeDnld != null && custCodeDnld.equalsIgnoreCase( "null" ) ) ? "" : custCodeDnld.trim();
//entityCode = userInfo.getEntityCode();
//entityType = userInfo.getUserType();
//entityType = "E";
//entityCode = "E03498";
String sql = null;
//objName = "invoice";
//downloadLoc = "G:\\rcp\\JBoss-2.4.4\\DOWNLOAD\\daily";
sql = " select OBJ_NAME, TEMPL_UPLD, TEMPL_TYPE_UPLD, TEMPL_DNLD, TEMPL_TYPE_DNLD"
+" from OBJECT_EXIM_FMT "
+" where OBJ_NAME = '" + objName + "'"
+" and OBJ_CONTEXT = '" + entityType.trim() + "-" + entityCode.trim() + "'";
//System.out.println( "SQL :: " + sql );
java.sql.Connection conn = null;
java.sql.PreparedStatement pstmt = null;
java.sql.ResultSet rs = null;
ConnDriver connDriver = new ConnDriver();
try
{
conn = connDriver.getConnectDB( "DriverITM" );
conn.setAutoCommit( false );
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
objName = rs.getString( "OBJ_NAME" );
templUpld = rs.getString( "TEMPL_UPLD" );
templTypeUpld = rs.getString( "TEMPL_TYPE_UPLD" );
templDnld = rs.getString( "TEMPL_DNLD" );
templTypeDnld = rs.getString( "TEMPL_TYPE_DNLD" );
isTemplateExist = true;
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}catch( Exception ex )
{
ex.printStackTrace();
}
if( isTemplateExist )
{
GenericUtility genericUtility = GenericUtility.getInstance();
String xlsFileName = null;
String csvData = null;
String templFileName = null;
templFileName = CommonConstants.JBOSSHOME;
fileName = CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD" + File.separator + objName;
//ibase.webitm.utility.XML2XLSCustomXfm xlsConverter = new ibase.webitm.utility.XML2XLSCustomXfm();
//System.out.println( " templDnld :: " + CommonConstants.JBOSSHOME + File.separator + "DWNLOAD" + File.separator + "template" + File.separator + templDnld );
//System.out.println( " fileName :: " + fileName );
try
{
if( templTypeDnld.equalsIgnoreCase( "C" ) )
{
ibase.webitm.utility.XML2CSVCustomConverter csvConverter = null;
csvConverter = new ibase.webitm.utility.XML2CSVCustomConverter();
if( objName.equalsIgnoreCase( "INVOICE" ) )
{
String str = null;
client = new TranXmlData();
//start - select all the undownloaded invoice, if found, then download for each.
sql = "SELECT iv.INVOICE_ID TRAN_ID, iv.CUST_CODE, cu.UNIFORM_CODE, "
+" to_char( iv.tran_date, 'ddmmyyyy' ) dt "
+" FROM INVOICE iv, CUSTOMER cu, site_customer sc "
+" WHERE iv.cust_code = cu.cust_code( + ) "
+" and iv.site_code = sc.site_code "
+" and iv.cust_code = sc.cust_code "
+" and sc.download_YN = 'Y' "
+" and ( iv.download_flag is null or iv.download_flag = 'N' ) ";
if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0 && custCodeDnld != null && custCodeDnld.trim().length() > 0 )
{
sql = sql + " and iv.site_code = '" + siteCodeDnld + "' and iv.cust_code = '" + custCodeDnld + "' ";
}
sql = sql + " order by iv.cust_code ";
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
prvCustCode = null;
recCounter = 0;
while( rs.next() )
{
tranId = rs.getString( "TRAN_ID" );
custCode = rs.getString( "CUST_CODE" );
uniformCode = rs.getString( "UNIFORM_CODE" );
dt = rs.getString( "dt" );
if( custCode.equalsIgnoreCase( prvCustCode ) && dt.equalsIgnoreCase( previousDay ) )
{
recCounter++;
}
else
{
recCounter = 1;
}
dnldFileName = ( uniformCode == null ? "" : uniformCode.trim() ) + "_" + dt + "_" + ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
tranFileMip.put( tranId, dnldFileName );
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//end - select all the undownloaded invoice, if found, then download for each.
pstmt = conn.prepareStatement( "update invoice set download_flag = 'Y' where invoice_id = ?" );
Iterator tranItr = tranFileMip.keySet().iterator();
while( tranItr.hasNext() )
{
tranId = ( String ) tranItr.next();
dnldFileName = ( String )tranFileMip.get( tranId );
xmlToCsvStr = client.getTranXml( "invoice",
java.sql.Timestamp.valueOf( "2008-11-01 00:00:00" ),
java.sql.Timestamp.valueOf( "2008-11-01 00:00:00" ),
tranId, tranId, conn );
csvData = csvConverter.convert( xmlToCsvStr,
CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD"
+ File.separator + "template"
+ File.separator + templDnld + ".xml",
null
);
FileWriter fw = new FileWriter( downloadLoc + File.separator + dnldFileName + ".csv" );
fw.write( csvData );
fw.close();
fw = null;
pstmt.setString( 1, tranId );
pstmt.addBatch();
}
pstmt.executeBatch();
pstmt.close();
pstmt = null;
try{
conn.commit();
}catch( Exception ex ){}
}
else
{
/*
csvData = csvConverter.convert( xmlDataDnld,
CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD"
+ File.separator + "template"
+ File.separator + templDnld + ".xml",
null
);
*/
}
}
}
catch( Exception pte )
{
try{
conn.rollback();
}catch( Exception ex ){}
pte.printStackTrace();
}
}
}
public String schedule( HashMap map )throws RemoteException, ITMException
{
return "";
}
public String schedule( String scheduleParamXML )throws RemoteException, ITMException
{
String userInfoList = null;
String isIntractive = null;
String objName = null;
String downloadLoc = null;
ArrayList paramListArr = new ArrayList();
try
{
//APPLICATION_CONTEXT = CommonConstants.UPLOAD_LOC + File.separator + "webapps" + File.separator + "ibase" + File.separator ;
//System.out.println(" scheduleParamXML [" + scheduleParamXML + "]");
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML );
NodeList paramList = userInfoDom.getElementsByTagName( "ACTUALPARAMETER" );
//
int noOfParam = paramList.getLength();
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ )
{
paramListArr.add( ( String )( paramList.item( paramCnt ).getFirstChild().getNodeValue() ) );
}
//for( int i = 0 ; i < paramListArr.size(); i++ )
//{
// System.out.println( "My param :: " + (String)paramListArr.get( i ) );
//}
//
/*
System.out.println(" RootNode [ " + rootNode+ " ] ");
NodeList propNodeList = rootNode.getChildNodes();
System.out.println(" propNodeList [ " + propNodeList+ " ] ");
int noOfProps = propNodeList.getLength();
for( int propCtr = 0; propCtr < noOfProps; propCtr++ )
{
Node propNode = propNodeList.item( propCtr );
System.out.println(" propNode [" +propNode+"]");
if( propNode != null && propNode.getFirstChild() != null )
{
String propName = propNode.getNodeName();
System.out.println(" propName [" +propName+"]");
if ( "UserInfoStr".equalsIgnoreCase( propName ) )
{
userInfoList = propNode.getFirstChild().getNodeValue();
System.out.println(" userInfoList [" + userInfoList + "]");
}
else if ( "downloadLoc".equalsIgnoreCase( propName ) )
{
downloadLoc = propNode.getFirstChild().getNodeValue();
System.out.println(" isIntractive [" + isIntractive + "]");
}
else if ( "objName".equalsIgnoreCase( propName ) )
{
objName = propNode.getFirstChild().getNodeValue();
System.out.println(" objName [" + objName + "]");
}
else if ( "entityCode".equalsIgnoreCase( propName ) )
{
entityCode = propNode.getFirstChild().getNodeValue();
System.out.println(" entityCode [" + entityCode + "]");
}
else if ( "entityType".equalsIgnoreCase( propName ) )
{
entityType = propNode.getFirstChild().getNodeValue();
System.out.println(" entityType [" + entityType + "]");
}
}
}
*/
//downloadTransaction( objName, downloadLoc, entityCode, entityType, null );
/*
List and order of arguments :
1. location,
2. Entity Code
3. Entity Type
4. Stite Code
5. Cust code
*/
downloadTransaction( (String)paramListArr.get( 0 ), (String)paramListArr.get( 1 ), (String)paramListArr.get( 2 ), (String)paramListArr.get( 3 ), (String)paramListArr.get( 4 ), (String)paramListArr.get( 5 ) );
}
catch(Exception e)
{
//System.out.println("DownloadCSVBatchEJB :==>Schedule");
e.printStackTrace();
}
return "";
}
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.TransIDGenerator;//TID
import ibase.utility.CommonConstants;//TID
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class FileFlt extends ValidatorEJB implements FileFltLocal , FileFltRemote // SessionBean
{
/*public void ejbCreate() throws RemoteException, CreateException
{
System.out.println("Enter in to the the FileFltEJB........................");
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String wfValData() throws RemoteException,ITMException
{
return "";
}
public String itemChanged() throws RemoteException,ITMException
{
return "";
}
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
{
dom = parseString(xmlString); //returns the DOM Object for the passed XML Stirng
System.out.println("xmlString" + xmlString);
dom1 = parseString(xmlString1); //returns the DOM Object for the passed XML Stirng
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [FileFltEJB][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
{
int ctr =0;
int currentFormNo = 0;
String errCode = "";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String errString = "";
StringBuffer valueXmlString = new StringBuffer();
String sql = "";
String columnValue = "";
String format = "";
NodeList parentNodeList = null;
Node parentNode = null;
Node childNode = null;
NodeList childNodeList = null;
String childNodeName = "";
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
GenericUtility genericUtility = GenericUtility.getInstance();
StringBuffer retString = new StringBuffer();
String winName = "";
String filePath ="";
try
{
conn = getConnection(); //THIS FUNCTION IS TO CONNECT WITH ORACLE....
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
System.out.println("[FileFltEJB] [itemChanged] :currentFormNo ....." +currentFormNo);
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
valueXmlString.append("<Detail>");
System.out.println("FORM NO-------------"+currentFormNo);
switch (currentFormNo)
{
case 1:
/* SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START*/
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
int childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equals(currentColumn))
{
if (childNode.getFirstChild() != null)
{
columnValue=childNode.getFirstChild().getNodeValue().trim();
}
}
ctr++;
}while(ctr < childNodeListLength && !childNodeName.equals(currentColumn));
if (currentColumn.trim().equals("tran_id"))
{
if (columnValue != null)
{
System.out.println("columnValue.................."+columnValue);
try
{
sql =" SELECT EDI_CONTROL_DET.WIN_NAME,EDI_CONTROL_FILE.FILE_PATH,EDI_CONTROL_FILE.FILE_NAME "
+" FROM EDI_CONTROL_DET,EDI_CONTROL_FILE "
+" WHERE ( EDI_CONTROL_DET.WIN_NAME = EDI_CONTROL_FILE.WIN_NAME ) AND "
+" ( EDI_CONTROL_DET.TRAN_IDENTIFIER = '"+ columnValue +"' )";
st = conn.createStatement();
rs = st.executeQuery(sql);
while(rs.next())
{
winName = rs.getString(1);
filePath = rs.getString(2)+ rs.getString(3);
}
System.out.println("File Name.................."+filePath);
System.out.println("Window Name................."+winName);
}
catch(Exception e)
{
System.out.println("Exception :[FileFltEJB[itemChanged::case 1] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}
System.out.println("");
valueXmlString.append("<file_path>").append(filePath).append("</file_path>");
valueXmlString.append("<window_name>").append(winName).append("</window_name>");
}
valueXmlString.append("</Detail>");
break;
}//END OF SWITCH
valueXmlString.append("</Root>");
}//END OF TRY
catch(Exception e)
{
System.out.println("Exception ::"+e.getMessage());
}
finally
{
try
{
conn.close();
conn = null;
}catch(Exception s){}
}
return valueXmlString.toString();
}//END OF ITEMCHNGE
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface FileFltLocal extends ValidatorLocal//, EJBObject
{
public String wfValData() throws RemoteException,ITMException;
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() 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;
}
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
public interface FileFltRemote extends ValidatorRemote//, EJBObject
{
public String wfValData() throws RemoteException,ITMException;
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() 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;
}
package ibase.webitm.ejb.sys;
import java.util.*;
import java.text.SimpleDateFormat;
import java.sql.*;
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.utility.CommonConstants;
import ibase.system.config.*;
public class GenVal
{
Connection conn = null;
GenericUtility genericUtility = GenericUtility.getInstance();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
CommonConstants commonConstants = new CommonConstants();
boolean flag =false;
boolean xFlag = true;
//changed by msalam on 26/09/07 start
//field added to store focused Row of the form
int formCtxFocusedRow = 0;
//changed by msalam on 26/09/07 end
//added by msalam on 22/11/07 for appending log in jboss log
File filePtr ;
File logDir ;
String logDirName = "";
//end added by msalam on 22/11/07 for appending log in jboss log
public String genVal(String modName ,String objContext,Document data ,Connection conn)
{
//System.out.println("Generalized Validation Is In Process.************************************.......");
Statement stmt = null;
ResultSet rs = null;
String fldName ="",valType = "",fldMin = "",sqlInput = "",fldMax = "",errCD = "",blankOpt = "",fldData ="",fldType="";
String errCode ="";
String sql = " SELECT FLD_NAME,VAL_TYPE,FLD_MIN,SQL_INPUT,FLD_MAX,ERROR_CD,BLANK_OPT ,FLD_TYPE FROM GENMST WHERE MOD_NAME= '"+modName.toUpperCase()+"'";
//System.out.println("SQL :: "+sql);
String errMsg =" ";
try
{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
flag =false;
fldName = rs.getString(1).trim();
valType = rs.getString(2);
fldMin = rs.getString(3);
sqlInput = rs.getString(4);
fldMax = rs.getString(5);
errCD = rs.getString(6);
blankOpt = rs.getString(7);
fldType = rs.getString(8);
fldData = getValueFromDom(data,fldName,objContext);
//System.out.println("Fld Name :["+fldName+"] Value : "+fldData+"] Present["+flag+"]");
//System.out.println("validation Type********************["+valType+"]");
if( flag == true )
{
if ( checkBlank( fldName, fldData, blankOpt) && valType.trim().equalsIgnoreCase( "M" ) )
{
errMsg = errCD;//user enter blank but blank option is Y
}
else
{
//next 2 line commented by msalam on 22/11/07 as validation is required on fldData blank also
// 06/10/08 manoharan uncommented and added condition that valtype "M"
//System.out.println("fldData********************["+fldData+"]");
if ( ( fldData != null && fldData.trim().length() > 0 && "M".equalsIgnoreCase(valType.trim())) || !"M".equalsIgnoreCase(valType.trim()) )
{
//end commented by msalam on 22/11/07 as validation is required on fldData blank also
if( valType == null ) valType= " ";
//cross query validation
if (valType.equalsIgnoreCase("Q"))
{
errMsg = genVal( fldName, modName, data, objContext, fldMin, sqlInput, fldMax, errCD, conn );
}
//slab validation
else if( valType.equalsIgnoreCase( "S" ) )
{
//if field type is N
try
{
double fldValue = 0,fldMinValue = 0,fldMaxValue = 0;
fldValue = Double.parseDouble(fldData);
fldMinValue = Double.parseDouble(fldMin);
fldMaxValue = Double.parseDouble(fldMax);
if (fldValue < fldMinValue || fldValue > fldMaxValue)
{
errMsg = errCD;
}
}
catch(NumberFormatException noFormat)
{
errMsg = errCD;
}
}
//cruss slab validation
else if(valType.equalsIgnoreCase("X"))
{
double fldValue = 0,fldMinValue = 0,fldMaxValue = 0;
try
{
fldMinValue = Double.parseDouble(fldMin);
}
catch(NumberFormatException noFormat)
{
String fldMinValueStr= getValueFromDom(data,fldMin,objContext);
if(fldMinValueStr!=null || fldMinValueStr.trim().length()!=0)
fldMinValue = Double.parseDouble(fldMinValueStr);
}
try
{
fldMaxValue = Double.parseDouble(fldMax);
}
catch(NumberFormatException noFormat)
{
String fldMaxValueStr = getValueFromDom(data,fldMax,objContext);
if(fldMaxValueStr!=null || fldMaxValueStr.trim().length()!=0)
fldMaxValue = Double.parseDouble(fldMaxValueStr);
}
double dfldData = 0;
if(fldData!=null | fldData.trim().length()!=0)
{
dfldData = Double.parseDouble(fldData);
}
if (dfldData < fldMinValue || dfldData > fldMaxValue)
{
errMsg = errCD;
}
}
//master Validation
else if( valType.trim().equalsIgnoreCase("M") )
{
//System.out.println("Calling masterVal for module * * * * * [" + modName.trim() + "]");
errMsg = masterVal( fldName, modName, fldData, errCD, conn );
}
//next line commented by msalam on 22/11/07 as validation is required on fldData blank also
}//end of blank opt N
//end commented by msalam on 22/11/07 as validation is required on fldData blank also
}
}
if(errMsg.trim().length()>0)
{
break;
}
}
if(errMsg.trim().length()==0 && xFlag == true)
{
xFlag = false;
//System.out.println("Calling genVal for module * * * * * [X]");
errMsg = genVal("X",objContext,data ,conn);
xFlag = true;
}
} // end of try
catch (SQLException sx)
{
//System.out.println("SQLException ()::" +sql+ sx.getMessage() + ":");
sx.printStackTrace();
}
catch (Exception e)
{
//System.out.println("Exception () ::" + e.getMessage());
e.printStackTrace();
}
finally
{
try
{
if(stmt!=null)
{
stmt=null;
}
if(rs !=null)
{
rs=null;
}
if (conn != null)
{
conn.close();
conn = null;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
//return stkOpt;
}
return errMsg;
}
//changed by msalam on 26/09/07 start
//to overload the function
//public String genVal(String modName ,String objContext,Document data ,Connection conn)
public String genVal(String modName ,String objContext,Document data, String focusedRow, Connection conn)
{
String errMsg =" ";
//changed by msalam on 26/09/07 start
if( focusedRow != null )
{
this.formCtxFocusedRow = Integer.parseInt( focusedRow );
}
//changed by msalam on 26/09/07 end
//changed by msalam on 22/11/07 for appending log
if(CommonConstants.J2EE_VERSION.equals("1"))
{
logDirName = CommonConstants.JBOSSHOME + File.separator + "log" ;
}
else if(CommonConstants.J2EE_VERSION.equals("2"))
{
logDirName = CommonConstants.JBOSSHOME + File.separator + "server"+ File.separator +"default"+ File.separator +"log" ;
}
logDir = new File(logDirName);
filePtr = new File(logDirName+ File.separator + "genval.log");
//System.out.println("--------------------------------------->GenVal called");
writeLog( filePtr, "GenVal called", true );
//end changed by msalam on 22/11/07 for appending log
errMsg = genVal( modName, objContext, data, conn);
return errMsg;
}
//changed by msalam on 26/09/07 end
/* The method is to check wheather the blank validation is check or not.
If blank opt is Y and user left field blank it return true*/
private boolean checkBlank(String colName, String colValue, String blankOpt)
{
boolean result = false;
try
{
writeLog( filePtr, "Blank Option " + blankOpt, true );
//System.out.println("Blank Option "+blankOpt);
// 08-10-2007 manoharan default value assigned for blankopt also
// blankopt is N and empty data then indicate error
if (blankOpt == null)
{
blankOpt = "N";
}
//if (blankOpt != null && blankOpt.equalsIgnoreCase("Y"))
if (blankOpt != null && blankOpt.equalsIgnoreCase("N"))
// end 08-10-2007 manoharan
{
if (colValue == null || colValue.trim().length() == 0)
{
result = true;
}
}
}catch(Exception e)
{
//System.out.println("Exception "+e);
e.printStackTrace();
}
return result;
}
//master validation
private String masterVal( String fldName, String modName, String fldData, String errCD, Connection conn )
{
String err = " ";
Statement mst = null;
ResultSet mrs = null;
int count=0;
String sql ="";
writeLog( filePtr, "fldData:::::::::"+fldData, true );
//System.out.println("fldData:::::::::"+fldData);
//next 2 lines commented by msalam on 23/11/07 as validation is required on fldData blank also
//if( fldData != null && fldData.trim().length()!=0 )
//{
//end commented by msalam on 23/11/07 as validation is required on fldData blank also
if(modName.equalsIgnoreCase("X"))
{
sql="SELECT COUNT(*) FROM GENCODES WHERE FLD_NAME = '"+fldName+"'AND MOD_NAME = 'X' AND RTRIM(FLD_VALUE) = RTRIM('"+fldData+"') AND ACTIVE = 'Y'";
}
else
{
sql ="SELECT COUNT(*) FROM GENCODES WHERE FLD_NAME = '"+fldName+"' AND MOD_NAME = '"+modName.toUpperCase()+"' AND RTRIM(FLD_VALUE) = RTRIM('"+fldData+"') AND ACTIVE = 'Y'";
}
writeLog( filePtr, "Excecuting Query(valtype=M);:::::::::::::::"+sql, true );
//System.out.println("Excecuting Query(valtype=M);:::::::::::::::"+sql);
try
{
mst=conn.createStatement();
mrs = mst.executeQuery( sql );
if(mrs.next())
{
count = mrs.getInt(1);
}
if(count==0)
{
err = errCD;
writeLog( filePtr, "Master validation record Not Found", true );
}
}
catch(Exception e){e.printStackTrace();}
//next line commented by msalam on 22/11/07 as validation is required on fldData blank also
//}//end of blank opt N
//end commented by msalam on 22/11/07 as validation is required on fldData blank also
return err;
}
private String genVal( String fldName, String modName, Document dom, String objContext, String queryFrDB, String sqlInput, String resultStr, String errcd, Connection conn )
{
//System.out.println( "Result Should come as " + resultStr );
writeLog( filePtr, "Result Should come as " + resultStr, true );
//System.out.println("Incomming dom:::" + GenericUtility getInstance().serializeDom(dom));
PreparedStatement pstmt1= null;
ResultSet rs1 = null;
java.util.Vector resultStrVec = new java.util.Vector();
java.util.Vector sqlInputVec = new java.util.Vector();
java.util.Vector dataVec = new java.util.Vector();
StringTokenizer st = null;
String data="";
String errCode =" ";
String colType ="";
try
{
writeLog( filePtr, "Mod Name :::" + modName, true );
writeLog( filePtr, "Field Name :::" + fldName, true );
writeLog( filePtr, "Database queries :::" + queryFrDB, true );
writeLog( filePtr, "Input to query :::" + sqlInput, true );
writeLog( filePtr, "Value after execute :::" + resultStr, true );
//***enumerate the sqlinput and store individual parameter in an vector(check for null)
if( sqlInput != null )
{
st = new StringTokenizer( sqlInput, ":" );
while ( st.hasMoreTokens() )
{
sqlInputVec.add( st.nextToken() );
}
}
//***Enumerate the resultStr and store individual parameter in an vector
st = new StringTokenizer( resultStr, "," );
while ( st.hasMoreTokens() )
{
resultStrVec.add( st.nextToken() );
}
}
catch ( Exception e )
{
writeLog( filePtr, "Excetion in seperating sql input ::", true );
e.printStackTrace();
}
try
{
//**********Executing The Query
StringBuffer QueryBuf= new StringBuffer( queryFrDB );
if( sqlInputVec.size() != 0 )
{
for(int ctr=0; ctr < sqlInputVec.size(); ctr++)
{
String colName = (String)sqlInputVec.get( ctr );
//added on 310107
int objContextInt = Integer.parseInt( colName.substring( 0, colName.indexOf( "." ) ) );
objContextInt++;
String objContext1 = new Integer( objContextInt ).toString();
String colName1 = colName.substring( colName.indexOf( "." ) + 1 );
// 21-09-2007 manoharan
colName1 = colName1.replaceAll( ",", " " );
colName1 = colName1.trim();
// end 21-09-2007
colType = getType(modName, objContext1, colName1);
//*****find the value of given field
//changed by msalam on 24/09/07
//for getting value of last row
String colValue = getValueFromDom( dom, colName1, objContext1 );
writeLog( filePtr, "colValue form dom===[" + colValue + "]" + " Col Type [" + colType + "]", true );
//changed by msalam on 24/09/07 end
//changed by msalam on 03/10/07 for colType = "DATETIME"
if( colType.toUpperCase().indexOf( "DATETIME") != -1 )
{
String dataBase = null;
dataBase = CommonConstants.DB_NAME;
String replaceDateColValue = null;
String dateColValue = null;
dateColValue = colValue;
if( dateColValue == null )
{
dateColValue = "";
}
if( dataBase.equalsIgnoreCase( "ORACLE") )
{
replaceDateColValue = "TO_DATE( '" + getDateInAppFormat( dateColValue.trim(), "yyyy-mm-dd" ) + "', 'yyyy/MM/dd' )";
}
else if( dataBase.equalsIgnoreCase( "DB2") )
{
if( dateColValue == null || dateColValue.trim().length() == 0 )
{
replaceDateColValue = "cast(null as timestamp)";
}
else
{
replaceDateColValue = "timestamp( '" + getDateInAppFormat( dateColValue.trim() ) + "' )";
}
}
else if( dataBase.equalsIgnoreCase( "MSSQL") )
{
if( dateColValue == null || dateColValue.trim().length() == 0 )
{
replaceDateColValue = "cast(null as datetime)";
}
else
{
replaceDateColValue = "convert( '" + getDateInAppFormat( dateColValue.trim() ) + "'as DATETIME )";
}
}
int index = QueryBuf.toString().indexOf( '?' );
QueryBuf.replace( index, index + 1, replaceDateColValue );
}
//changed by msalam on 03/10/07 for colType = "DATETIME" end
//Changed by msalam on 22/10/07 for colType = "DATETIME" start
//if( ( colType.toUpperCase().indexOf( "STRING" ) != -1 ) || ( colType.toUpperCase().indexOf( "CHAR" ) != -1) || ( colType.toUpperCase().indexOf( "VARCHAR" ) != -1 ) )
//changed line below
else if( ( colType.toUpperCase().indexOf( "STRING" ) != -1 ) ||
( colType.toUpperCase().indexOf( "CHAR" ) != -1) ||
( colType.toUpperCase().indexOf( "VARCHAR" ) != -1 ) )
{
int index = QueryBuf.toString().indexOf( '?' );
//next line changed and modified line added by msalam to replace null by blank on 23/11/07
//QueryBuf.replace( index, index + 1, "'" + colValue.trim() + "'" );
if( colValue != null )
{
QueryBuf.replace( index, index + 1, "'" + colValue.trim() + "'" );
}
else
{
QueryBuf.replace( index, index + 1, "''" );
}
//end changed by msalam on 23/11/07
}
else if((colType.toUpperCase().indexOf("DECIMAL") != -1) || (colType.toUpperCase().indexOf("DOUBLE") != -1) || (colType.toUpperCase().indexOf("NUMBER") != -1) || (colType.toUpperCase().indexOf("LONG") != -1))
{
int index = QueryBuf.toString().indexOf( '?' );
//next line changed and modified line added by msalam to replace null by blank on 23/11/07
//QueryBuf.replace( index, index + 1, colValue);
if( colValue != null )
{
QueryBuf.replace( index, index + 1, colValue);
}
else
{
QueryBuf.replace( index, index + 1, "0.0" );
}
//end changed by msalam on 23/11/07
}
//Changed by msalam on 22/10/07 for colType = "DATETIME" end
}
}
writeLog( filePtr, "After replace parameter Final Query[*********]:::" + QueryBuf.toString(), true );
pstmt1= conn.prepareStatement( QueryBuf.toString() );
rs1 = pstmt1.executeQuery();
ResultSetMetaData rsmd = rs1.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
if( numberOfColumns != resultStrVec.size() )
{
errCode = "CONFIGERR";
}
else
{
while (rs1.next())
{
for(int ctr = 1; ctr <= numberOfColumns; ctr++)
{
int metaType = rsmd.getColumnType(ctr);
writeLog( filePtr, "metaType----------------------------------"+metaType, true );
if (metaType == Types.VARCHAR)
{
data = rs1.getString(ctr);
}
else if (metaType == Types.CHAR)
{
data = rs1.getString(ctr);
}
else if(metaType == Types.NUMERIC)
{
data = new Integer(rs1.getInt(ctr)).toString();
}
else if(metaType == Types.DECIMAL)
{
data = new Double(rs1.getDouble(ctr)).toString();
}
else if( metaType == Types.TIMESTAMP )
{
data =rs1.getTimestamp( ctr ).toString();
}
else if(metaType == 4)
{
data = new Integer( rs1.getInt( ctr ) ).toString();
}
}
writeLog( filePtr, "Query RESULT ====>>>" + data, true );
dataVec.add( data );
}
}
for( int counter = 0; counter < resultStrVec.size(); counter++ )
{
String result = (String)resultStrVec.get( counter );
String valueFrDatabase = (String)dataVec.get( counter );
writeLog( filePtr, "valueFrDatabase=" + valueFrDatabase, true );
writeLog( filePtr, "QRY Result" + result, true );
if( !result.trim().equalsIgnoreCase( valueFrDatabase.trim() ) )
{
errCode = errcd ;
break;
}
}
}
catch (SQLException sx)
{
writeLog( filePtr, "Exception in executing ", true );
sx.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return errCode;
}
//******** Get the type of the field
private String getType(String winName,String objContext,String fldName)
{
Document dom = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int parentNodeListLength = 0;
int childNodeListLength = 0;
String tagName = null;
String tagValue = null;
String colName = "";
String colType = "";
String childNodeName = "";
String fldType="";
try
{
String ObjName =winName.substring(2,winName.length())+"2"+objContext;
// 01/10/08 manoharan not working in linux
//String filename = CommonConstants.JBOSSHOME + File.separator + "bin\\metadata\\"+ ObjName.trim() + ".xml";
String filename = CommonConstants.JBOSSHOME + File.separator + "bin" + File.separator + "metadata" + File.separator + ObjName.trim() + ".xml";
// end 01/10/08 manoharan not working in linux
File file = new File(filename);
DocumentBuilder parser1 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
dom = parser1.parse(file);
NodeList columnsNodeList = dom.getElementsByTagName("table_column");
int tableColLength = columnsNodeList.getLength();
for(int i= 0 ;i < tableColLength;i++ )
{
NodeList columnNodeList = columnsNodeList.item(i).getChildNodes();
int tableColChildLength = columnNodeList.getLength();
for(int j= 0 ;j < tableColChildLength;j++)
{
Node colNode = columnNodeList.item(j) ;
tagName = colNode.getNodeName() ;
if (tagName.equals("type") )
{
colType = colNode.getFirstChild().getNodeValue();
}
if (tagName.equals("name"))
{
colName = colNode.getFirstChild().getNodeValue();
}
}
if(fldName.equalsIgnoreCase(colName))
{
fldType = colType;
break;
}
}
}
catch(FileNotFoundException fileNotFound)
{
fileNotFound.printStackTrace();
}
catch(Exception e )
{
e.printStackTrace();
}
return fldType;
}
//*****Get the parameter field value
//function changed by msalam on 26/09/07
//for getting value of last row in place of first row only
private String getValueFromDom(Document dom, String fldName, String objContext)
{
String value = "";
int currentFormNo= 0;
NodeList parentNodeList = null;
Node parentNode = null;
NodeList childNodeList = null;
int childNodeListLength = 0;
Node childNode = null;
String childNodeName ="";
try
{
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
String tag = "Detail"+currentFormNo;
parentNodeList = dom.getElementsByTagName(tag);
//changed by msalam on 26/09/07 start
//for getting value of focused Row rather than first row only
//commented next line and added lines
//parentNode = parentNodeList.item(0);
//added lines in place of previous line
parentNode = parentNodeList.item( currentFormNo == 1 ? 0 : (this.formCtxFocusedRow - 1) );
//changed by msalam on 26/09/07 end
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
// 21-09-2007 manoharan
fldName = fldName.replaceAll(","," ");
fldName = fldName.trim();
// end 21-09-2007 manoharan
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase(fldName))
{
flag = true;
if (childNode.getFirstChild() != null)
{
value = childNode.getFirstChild().getNodeValue();
break;
}
}
}
}//end try
catch(Exception e)
{
e.printStackTrace();
}
return value;
}
//added by msalam on 22-10-2007 to get date in application format
private String getDateInAppFormat( String dateColValue )
{
String appDate = null;
Object date = null;
SimpleDateFormat DBDate=null;
try
{
DBDate= new SimpleDateFormat( genericUtility.getApplDateFormat() ); //"yyyy-mm-dd");
date = DBDate.parse( java.sql.Timestamp.valueOf( genericUtility.getValidDateTimeString( dateColValue, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat() ) ).toString() );
appDate = DBDate.format( date ).toString() + " 00:00:00" ;
}
catch(Exception e)
{
e.printStackTrace();
}
return ( appDate );
}
//
//FUNCTION ADDED BY MSALAM ON 22/11/07 TO GET DATE IN GIVEN FORMAT
private String getDateInAppFormat( String dateColValue, String dateFormat )
{
String appDate = null;
Object date = null;
SimpleDateFormat DBDate=null;
if ( dateColValue == null || dateColValue.trim().length() == 0 )
{
return "";
}
try
{
DBDate= new SimpleDateFormat( dateFormat );
date = DBDate.parse( java.sql.Timestamp.valueOf( genericUtility.getValidDateTimeString( dateColValue, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat() ) ).toString() );
appDate = DBDate.format( date ).toString() ;
writeLog( filePtr, appDate, true );
}
catch(Exception e)
{
writeLog( filePtr, "Exception in getDateInFormat", true );
}
return ( appDate );
}
//END FUNCTION ADDED BY MSALAM ON 22/11/07 TO GET DATE IN GIVEN FORMAT
//functions added by msalam on 22/11/07 for appending log in jboss logg
static void writeLog(File f,String Msg,boolean flag)
{
try{
PrintWriter pw = new PrintWriter((new FileOutputStream(f,flag)),flag);
pw.println("PosSave ::"+Msg);
pw.close();
}
catch(Exception exWm){exWm.printStackTrace();}
}
//end functions added by msalam on 22/11/07 for appending log in jboss logg
}//END OF EJB
package ibase.webitm.ejb.sys;
import java.sql.*;
import java.util.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
//import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.ejb.*;
public class GenValBean
{
//GenericUtility genericUtility = GenericUtility.getInstance();
public void CheckCredential() throws Exception
{
System.out.println("Check status [" + status + "]");
if ((status != null && "Y".equalsIgnoreCase(status)) || e_days > 360 )
{
setStatus();
conn.close();
conn = null;
throw new Exception("340 Invalid system, cannot proceed");
}
}
private static String encodeString (String stringVal)
{
StringBuffer buf = new StringBuffer();
if (stringVal != null) {
byte[] bytes = (stringVal).getBytes();
int b;
for (int n = 0; n < bytes.length; n++) {
b = bytes[n] ^ (ENCODE_XORMASK + n);
buf.append((char)(ENCODE_CHAR_OFFSET1 + (b & 0x0F)));
buf.append((char)(ENCODE_CHAR_OFFSET2 + ((b >> 4) & 0x0F)));
}
}
return buf.toString();
}
private static String decodeString( String stringVal ) {
// check that the string value isn't null or zero-length
if( stringVal == null || stringVal.length() <= 0 ) {
return null;
}
// unrafel the string value
char[] chars = stringVal.toCharArray();
byte[] bytes = new byte[chars.length / 2];
int b;
for (int n = 0, m = 0; n < bytes.length; n++) {
b = chars[m++] - ENCODE_CHAR_OFFSET1;
b |= (chars[m++] - ENCODE_CHAR_OFFSET2) << 4;
bytes[n] = (byte)(b ^ (ENCODE_XORMASK + n));
}
stringVal = new String(bytes);
return stringVal;
}
private void setStd() throws Exception
{
std = sdf.parse(decodeString(CHK_STRING1));
setCrd();
}
private void setCrd() throws Exception
{
crd = new java.util.Date();
crd.setTime(System.currentTimeMillis());
crd = sdf.parse(sdf.format(crd));
setDays();
}
private void setDays() throws Exception
{
Statement stmt = null;
ResultSet rs = null;
e_days = um.DaysAfter(java.sql.Timestamp.valueOf(sdf.format(std) + " 00:00:00.000"), java.sql.Timestamp.valueOf(sdf.format(crd) + " 00:00:00.000") );
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT STATUS FROM PURCCTRL");
if (rs.next())
{
status = rs.getString("STATUS");
}
else
{
status = null;
}
rs.close();
rs = null;
stmt.close();
stmt = null;
}
private void setStatus() throws Exception
{
Statement stmt = null;
stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM PURCCTRL");
stmt.executeUpdate("INSERT INTO PURCCTRL() VALUES ()" );
stmt.close();
stmt = null;
conn.commit();
}
public GenValBean() throws Exception
{
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
ConnDriver conndriver = new ConnDriver();
conn = conndriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
itmDBAccessEJB = null;
conndriver = null;
setStd();
}
private UtilMethods um = UtilMethods.getInstance();
private final static int ENCODE_XORMASK = 0x5A;
private final static char ENCODE_DELIMETER = '\002';
private final static char ENCODE_CHAR_OFFSET1 = 'A';
private final static char ENCODE_CHAR_OFFSET2 = 'h';
private final static String CHK_STRING1 = "InMnBoAmAmLlGmAm";
private final static String CHK_STRING2 = "JnKnOn";
private final int maxNum = (int) Integer.parseInt(decodeString(CHK_STRING2));
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private long e_days = 0;
private java.util.Date std = null;
private java.util.Date crd = null;
private String status = null;
private Connection conn = null;
}//class
\ No newline at end of file
/*
* Created on Feb 5, 2007
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ibase.webitm.ejb.sys;
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 javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import org.w3c.dom.Document;
/**
* @author ashah
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class GenValidate extends ValidatorEJB implements GenValidateLocal , GenValidateRemote // SessionBean{
{
Connection conn = null;
String sql = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
GenVal genVal = new GenVal();
/* public void ejbCreate() throws RemoteException, CreateException
{
//System.out.println("GenValidateEJB Created...");
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public void setSessionContext(SessionContext arg0)
{
}
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String winName, String xtraParams) throws RemoteException
{
String finalStr = "";
Document dom = null;
String userId="", errCode = "",resultString = "";
// finalStr = mergeXml(xmlString, xmlString1, xmlString2);
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
//System.out.println("xmlString2 : " + xmlString2);
dom = parseString(xmlString2);
userId = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
//changed by msalam on 27/09/07 start
//for passing current focused Row from xtraParams
String focusedRow = null;
focusedRow = getValueFromXTRA_PARAMS(xtraParams, "focusRow");
//System.out.println( "focusedRow :: " + focusedRow );
//errCode = genVal.genVal(winName,objContext,dom,conn);
errCode = genVal.genVal(winName,objContext,dom, focusedRow, conn);
//changed by msalam on 27/09/07 end
if (errCode != null && errCode.trim().length() > 0)
{
resultString = getErrorString("", errCode, userId);
}
}
catch (RemoteException e1) {
e1.printStackTrace();
}
catch (ITMException e1) {
e1.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (conn != null)
{ conn.close();
conn = null;
}
}
catch(Exception ex)
{ex.printStackTrace();}
}
return resultString;
}
private String mergeXml(String xmlString, String xmlString1, String xmlString2)
{
StringBuffer data = new StringBuffer();
StringBuffer compData = new StringBuffer();
String temp = "";
// System.out.println("xmlString : " + xmlString);
// System.out.println("xmlString1 : " + xmlString1);
// System.out.println("xmlString2 : " + xmlString2);
try{
compData.append("<DocumentRoot><description>Datawindow Root</description>");
compData.append("<group0><description>Group0 description</description>");
compData.append("<Header0><description>Header0 members</description>");
compData.append(xmlString);
data.append(xmlString1);
// if (data.indexOf("<Detail2") > 0)
// {
temp = data.substring(data.indexOf("<Detail"),data.indexOf("</Header0>"));
compData.append(temp);
// }
data.replace(0,data.length(),xmlString2);
// if (data.indexOf("<Detail3") > 0)
// {
temp = data.substring(data.indexOf("<Detail"),data.indexOf("</Header0>"));
compData.append(temp);
// }
compData.append("</Header0></group0></DocumentRoot>");
}
catch(Exception e)
{
//System.out.println("In mergeXml ::: " + e.getMessage());
e.printStackTrace();
}
//System.out.println("compData ::::" + compData.toString());
return compData.toString();
}
}
/*
* Created on Feb 5, 2007
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
//import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
* @author ashah
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
//RemoteException is Added in throw list - Gulzar - 01/09/08 Req ID - FI89PHE013
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface GenValidateLocal extends ValidatorLocal //extends EJBObject
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String winName, String xtraParams) throws RemoteException;
}
/*
* Created on Feb 5, 2007
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package ibase.webitm.ejb.sys;
//import javax.ejb.EJBObject;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
/**
* @author ashah
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
//RemoteException is Added in throw list - Gulzar - 01/09/08 Req ID - FI89PHE013
import javax.ejb.Remote; // added for ejb3
@Remote // added for ejb3
public interface GenValidateRemote extends ValidatorRemote //extends EJBObject {
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String winName, String xtraParams) throws RemoteException;
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import java.io.*;
import java.text.*;
// Rajesh on 9/20/2005 to use BaseLogger functions
import ibase.utility.BaseLogger;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ItmMenu extends ValidatorEJB implements ItmMenuLocal , ItmMenuRemote // SessionBean
{
/*public void ejbCreate() throws RemoteException, CreateException
{
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String wfValData() throws RemoteException, ITMException
{
return "";
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;//Ratikant 30/Mar/2005
String errString = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
// dom2 = parseString(xmlString2);//Ratikant 30/Mar/2005
errString = wfValData(dom,dom1,null,objContext,editFlag,xtraParams);//Ratikant 30/Mar/2005
}
catch(Exception e)
{
BaseLogger.error(e);
}
return (errString);
}
public String wfValData(Document dom,Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
String columnName = "";
String columnValue = "";
String userId = "";
String sql = "";
String errString = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int currentFormNo=0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
String appln = "";
String level1 = "";
String level2 = "";
String level3 = "";
String level4 = "";
String level5 = "";
int ctr;
try
{
conn = getConnection(); //This function is to connect with oracle....
userId = GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"userId");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
stmt = conn.createStatement();
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
BaseLogger.debug("Child Node::"+childNodeName);
if(childNodeName.equals("application"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Application Is Null");
errString = getErrorString("application","NULLAPPLCD",userId,errString);
break;
}
else
{
appln = childNode.getFirstChild().getNodeValue();
}
}
else if(childNodeName.equals("level_1"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Level1 Is Null");
errString = getErrorString("level_1","NULLLEV1",userId,errString);
break;
}
else
{
level1 = childNode.getFirstChild().getNodeValue();
}
}
else if(childNodeName.equals("level_2"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Level2 Is Null");
errString = getErrorString("level_2","NULLLEV2",userId,errString);
break;
}
else
{
level2 = childNode.getFirstChild().getNodeValue();
}
}
else if(childNodeName.equals("level_3"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Level3 Is Null");
errString = getErrorString("level_3","NULLLEV3",userId,errString);
break;
}
else
{
level3 = childNode.getFirstChild().getNodeValue();
}
}
else if(childNodeName.equals("level_4"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Level4 Is Null");
errString = getErrorString("level_4","NULLLEV4",userId,errString);
break;
}
else
{
level4 = childNode.getFirstChild().getNodeValue();
}
}
else if(childNodeName.equals("level_5"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Level5 Is Null");
errString = getErrorString("level_5","NULLLEV5",userId,errString);
break;
}
else
{
level5 = childNode.getFirstChild().getNodeValue();
BaseLogger.debug("Level 5 is " +level5);//17/Mar/2005
if (editFlag.equalsIgnoreCase("A"))
{
BaseLogger.debug("The Edit Flag Is Ratikant....."+editFlag);//17/Mar/2005
sql = " SELECT COUNT(*) FROM ITM2MENU WHERE application = '"+appln+ "' AND level_1 = '"+level1+"' AND level_2 = '"+level2+"' AND level_3 ='"+level3+ "' AND level_4 = '"+level4+ "' AND level_5 = '"+level5+"'";
BaseLogger.debug("SQL is " +sql);//17/Mar/2005
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next())
{
if(rs.getInt(1) > 0)
{
BaseLogger.debug("Tried to enter Duplicate key combination");
errString = getErrorString("user_id","DUPLITM2CD ",userId,errString);
break;
}
}
}
}
}
}
break;
}
}
catch (Exception e)
{
BaseLogger.error(e);
}
return errString;
}
public String itemChanged() throws RemoteException,ITMException
{
return "";
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;//Ratikant 30/Mar/2005
String valueXmlString = "";
try
{
dom = parseString(xmlString); //returns the DOM Object for the passed XML Stirng
dom1 = parseString(xmlString1); //returns the DOM Object for the passed XML Stirng
// dom2 = parseString(xmlString2);//Ratikant 29/Mar/2005
valueXmlString = itemChanged(dom,dom1,null,objContext,currentColumn,editFlag,xtraParams);//Ratikant 30/Mar/2005
}
catch(Exception e)
{
BaseLogger.error(e);
}
BaseLogger.debug("currentColumn ....." +currentColumn);
return (valueXmlString); //calls itemChanged(Document dom,String currentColumn) method and returns string
}
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
ResultSet rs = null;
int n;
int currentFormNo = 0;
Connection conn = null;
Statement stmt;
StringBuffer valueXmlString = new StringBuffer();
String sql = "";
String columnValue = "";
String returnValue = "";
String application = "";
String level1 = "";
String level2 = "";
String level3 = "";
String level4 = "";
String level5 = "";
StringBuffer menuPath = new StringBuffer();//19/Mar/2005
try
{
conn = getConnection(); //This function is to connect with oracle....
stmt = conn.createStatement();
columnValue = getColumnValue(currentColumn,dom);
BaseLogger.debug("columnValue ....." +columnValue);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
BaseLogger.debug("currentFormNo ....." +currentFormNo);
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");
valueXmlString.append("<Detail>\r\n");
switch (currentFormNo)
{
case 1:
{
if (columnValue != null)
{
if (currentColumn.trim().equals("level_5"))
{
application = getColumnValue("application", dom);
level1 = getColumnValue("level_1", dom);
level2 = getColumnValue("level_2", dom);
level3 = getColumnValue("level_3", dom);
level4 = getColumnValue("level_4", dom);
level5 = getColumnValue("level_5", dom);
menuPath.append(application);
menuPath.append(".");
menuPath.append(level1);
menuPath.append(".");
menuPath.append(level2);
menuPath.append(".");
menuPath.append(level3);
menuPath.append(".");
menuPath.append(level4);
menuPath.append(".");
menuPath.append(level5);
valueXmlString.append("<menu_path>").append(menuPath.toString()).append("</menu_path>");
}
}
valueXmlString.append("</Detail>\r\n");
break;
}
}
}
catch (Exception e)
{
BaseLogger.error(e);
}
valueXmlString.append("</Root>\r\n");
return valueXmlString.toString();
}
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface ItmMenuLocal extends ValidatorLocal//, EJBObject
{
public String wfValData() throws RemoteException, ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
public interface ItmMenuRemote extends ValidatorRemote//, EJBObject
{
public String wfValData() throws RemoteException, ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
/*
Window Name : W_file_to_batch_load
*/
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.dis.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
import ibase.ejb.*;
import ibase.system.config.*;
import java.util.*;
import java.lang.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class MasterApply implements MasterApplyLocal , MasterApplyRemote // SessionBean
{
Connection conn = null;
ITMDBAccessEJB itmDBAccessEJB = null;
CommonConstants commonConstants;
SessionContext cSessionContext;
GenericUtility genericUtility = GenericUtility.getInstance();
String userId = "";
String logInSite = "";
int tran_sl = 0;
String win_name= "";
String batch_id = "";
public void ejbCreate() throws RemoteException, CreateException
{
try
{
itmDBAccessEJB = new ITMDBAccessEJB();
ConnDriver conndriver = new ConnDriver();
conn = conndriver.getConnectDB("DriverITM");
commonConstants = new CommonConstants();
System.out.println("MasterApplyEJB ejbCreate called.........");
}
catch (Exception e)
{
System.out.println("Exception :CreateBatchPrcEJB :ejbCreate :==>"+e);
throw new CreateException();
}
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void setSessionContext(SessionContext mSessionContext)
{
this.cSessionContext = mSessionContext;
}
//CREATING XMLSTRING BY TAKING DATA AND FIELD NAME FROM BATCHLOADET AND INSERTING IN TO CHARGEBACK
public void applyMasterTable(String batchid,String xtraParam)
{
String winName = "";
StringBuffer logBuff =new StringBuffer();
System.out.println("Enter In to Dom Creation and master apply in Corresponding Master....");
System.out.println("Transation for Batch id::::::"+batchid);
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet dateRs = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
PreparedStatement psUpdateBl = null;
PreparedStatement datepstmt = null;
StringBuffer xmlBuff = null;
String sql = "";
String sql1 = "";
String BachId = "";
String fldData = "";
String fldName = "";
String xmlStrPass = "";
int objSsl = 0;
int totObjSl = 0;
int tranSl = 1;
int fldNo = 0;
Document dom = null;
Connection conect = null;
int maxTranSl =0;
String update = "";
String xmlStr = "";
String tableName = "";
String dateStr = "";
String tableNameDet1 = " ";
String tableNameDet2 = " ";
String tableNameDet3 = " ";
String collectWin = "";
ArrayList headerDateFilelds = new ArrayList();
ArrayList detati1DateFilelds = new ArrayList();
ArrayList detati2DateFilelds = new ArrayList();
ArrayList detati3DateFilelds = new ArrayList();
ArrayList collectFldList = new ArrayList();
String collectField = "";
ArrayList pointerList = null;
try
{
ConnDriver conndriver = new ConnDriver();
conect = conndriver.getConnectDB("DriverITM");
}
catch(Exception g){}
java.io.File objFile = new java.io.File (CommonConstants.JBOSSHOME+File.separator+"LOG");
java.io.File objFile1 = new java.io.File (CommonConstants.JBOSSHOME+File.separator+"XMLCB");
if(!(objFile.exists()))
{
objFile.mkdir();
}
if(!(objFile1.exists()))
{
objFile1.mkdir();
}
//COLLECTING WINDOW NAME FROM BATCHID AND BATCHLOAD
try
{
collectWin = "SELECT WIN_NAME FROM BATCHLOAD WHERE BATCH_ID=? AND TRAN_SL = (SELECT MIN(TRAN_SL) FROM BATCHLOAD WHERE BATCH_ID = ?)";
System.out.println(collectWin);
pstmt = conn.prepareStatement(collectWin);
pstmt.setString(1,batchid.trim());
pstmt.setString(2,batchid.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
winName = rs.getString(1);
System.out.println("win_name"+win_name);
}
rs.close();
}
catch(SQLException sexwin)
{
System.out.println("SQLException :[MasterApplyEJB(1)][Excuting Query Failed1]" +collectWin+sexwin.getMessage());
}
catch(Exception exwin)
{
System.out.println("Exception1(MasterApplyEJB(1)) ::"+collectWin+exwin.getMessage());
exwin.printStackTrace();
}
System.out.println("win_name:::::::::::"+winName);
System.out.println("BatchId:::::::::::"+batchid);
try
{
collectField = "SELECT A.obj_sl__source,A.FLD_NAME__DEST,A.comp_name ,A.method_name FROM EDI_CONTROL_DET A, EDI_CONTROL B WHERE A.WIN_NAME = B.WIN_NAME AND A.LINE_NO = B.LINE_NO "
+"AND B.WIN_NAME = ? AND B.EDI_MEDIUM = 2 and A.FLD_NO__SOURCE <>0 and comp_name is not null and method_name is not null ORDER BY A.OBJ_SL__SOURCE,A.FLD_NO__DEST ";
pstmt = conect.prepareStatement(collectField);
pstmt.setString(1,winName.trim());
rs = pstmt.executeQuery();
while(rs.next())
{
int form = 0;
CbBean collectFiels = new CbBean();
form = rs.getInt(1);
form++;
collectFiels.setFormNo(new Integer(form).toString());
collectFiels.setFldName(rs.getString(2));
collectFiels.setCompName(rs.getString(3));
collectFiels.setMethName(rs.getString(4));
collectFldList.add(collectFiels);
}
pstmt.close();
}
catch(SQLException extc111)
{
System.out.println("SQLException :[CreateBatchEJB(TableCreation)][Excuting Query Failed1]" + collectField + extc111.getMessage());
}
catch(Exception extc111)
{
System.out.println("Exception1(TableCreation) ::"+collectField +extc111.getMessage());
extc111.printStackTrace();
}
//COLLECTIING TABLE NAME FROM A GIVEN WINDOW
try
{
dateStr = "SELECT TABLE_NAME ,TABLE_NAME_DET1 , TABLE_NAME_DET2 ,TABLE_NAME_DET3 FROM TRANSETUP WHERE TRAN_WINDOW = ?";
datepstmt = conect.prepareStatement(dateStr);
datepstmt.setString(1,winName.trim());
dateRs = datepstmt.executeQuery();
if(dateRs.next())
{
tableName = dateRs.getString(1);
tableNameDet1 = dateRs.getString(2);
tableNameDet2 = dateRs.getString(3);
tableNameDet3 = dateRs.getString(4);
}
datepstmt.close();
}
catch(SQLException extc)
{
System.out.println("SQLException :[MasterApplyEJB(2)][Excuting Query Failed1]" + dateStr + extc.getMessage());
}
catch(Exception extc)
{
System.out.println("Exception1(MasterApplyEJB(2)) ::"+dateStr +extc.getMessage());
extc.printStackTrace();
}
System.out.println("HeaderTable Name::::"+tableName);
System.out.println("Detail Table1:1:::::"+tableNameDet1);
System.out.println("Detail Table1:2:::::"+tableNameDet2);
System.out.println("Detail Table1:3::::::"+tableNameDet3);
//COLLECTING THE DATE FIELD LIST FROM HEADER
if(tableName != null)
{
try
{
dateStr = "SELECT * from "+tableName.trim();
datepstmt = conn.prepareStatement(dateStr);
dateRs = datepstmt.executeQuery();
ResultSetMetaData rsmd = dateRs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int colCount =1;colCount<=numberOfColumns;colCount++)
{
if((rsmd.getColumnType(colCount) == java.sql.Types.DATE )|| (rsmd.getColumnType(colCount)==java.sql.Types.TIMESTAMP))//HARD CODE FOR DATE 91
{
System.out.println("Date field collect...");
String dateFlds = rsmd.getColumnName(colCount);
headerDateFilelds.add(dateFlds);
}
}
datepstmt.close();
System.out.println("total date fld in ="+headerDateFilelds);
}
catch(SQLException extc1)
{
System.out.println("SQLException :[MasterApplyEJB(3)][Excuting Query Failed1]" +dateStr+extc1.getMessage());
}
catch(Exception extc1)
{
System.out.println("Exception1(MasterApplyEJB(3)) ::"+dateStr+extc1.getMessage());
extc1.printStackTrace();
}
}
//COLLECTING THE DATE FIELD LIST FROM (DETAIL-1)
if(tableNameDet1 != null)
{
try
{
dateStr = "SELECT * from "+tableNameDet1.trim();
datepstmt = conn.prepareStatement(dateStr);
dateRs = datepstmt.executeQuery();
ResultSetMetaData rsmd = dateRs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int colCount =1;colCount<=numberOfColumns;colCount++)
{
if((rsmd.getColumnType(colCount) == java.sql.Types.DATE) || (rsmd.getColumnType(colCount)==java.sql.Types.TIMESTAMP))//HARD CODE FOR DATE 91
{
System.out.println("Date field colect...");
String dateFlds = rsmd.getColumnName(colCount);
detati1DateFilelds.add(dateFlds);
}
}
datepstmt.close();
System.out.println("Total Date fld in ="+detati1DateFilelds);
}
catch(SQLException extc1)
{
System.out.println("SQLException :[MasterApplyEJB(4)][Excuting Query Failed1]" +dateStr+extc1.getMessage());
}
catch(Exception extc1)
{
System.out.println("Exception1(MasterApplyEJB(4)) ::"+dateStr+extc1.getMessage());
extc1.printStackTrace();
}
}
//COLLECTING THE DATE FIELD LIST FROM (DETAIL-2)
if(tableNameDet2 != null)
{
try
{
dateStr = "SELECT * from "+tableNameDet1.trim();
datepstmt = conn.prepareStatement(dateStr);
dateRs = datepstmt.executeQuery();
ResultSetMetaData rsmd = dateRs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int colCount =1;colCount<=numberOfColumns;colCount++)
{
if((rsmd.getColumnType(colCount) == java.sql.Types.DATE )||(rsmd.getColumnType(colCount)== java.sql.Types.TIMESTAMP))//HARD CODE FOR DATE 91
{
System.out.println("Date field collect...");
String dateFlds = rsmd.getColumnName(colCount);
detati2DateFilelds.add(dateFlds);
}
}
datepstmt.close();
System.out.println("total date fld in ="+detati2DateFilelds);
}
catch(SQLException extc1)
{
System.out.println("SQLException :[CreateBatchEJB(MasterApplyEJB(5))][Excuting Query Failed1]" +dateStr+extc1.getMessage());
}
catch(Exception extc1)
{
System.out.println("Exception1(MasterApplyEJB(5)) ::"+dateStr+extc1.getMessage());
extc1.printStackTrace();
}
}
//COLLECTING THE DATE FIELD LIST FROM (DETAIL-3)
if(tableNameDet3 != null)
{
try
{
dateStr = "SELECT * from "+tableNameDet1.trim();
datepstmt = conn.prepareStatement(dateStr);
dateRs = datepstmt.executeQuery();
ResultSetMetaData rsmd = dateRs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
for(int colCount =1;colCount<=numberOfColumns;colCount++)
{
if((rsmd.getColumnType(colCount) == java.sql.Types.DATE )|| (rsmd.getColumnType(colCount)==java.sql.Types.TIMESTAMP))//HARD CODE FOR DATE 91
{
System.out.println("Date field collect...");
String dateFlds = rsmd.getColumnName(colCount);
detati3DateFilelds.add(dateFlds);
}
}
datepstmt.close();
System.out.println("total date fld in ="+detati3DateFilelds);
}
catch(SQLException extc1)
{
System.out.println("SQLException :[MasterApplyEJB(6)][Excuting Query Failed1]" +dateStr+extc1.getMessage());
}
catch(Exception extc1)
{
System.out.println("Exception1(MasterApplyEJB(6)) ::"+dateStr+extc1.getMessage());
extc1.printStackTrace();
}
}
//GET MAX OBJSL (OBJSL=0 HEADER OTHERWISE DTL )FOR A WINDOW
sql="SELECT MAX(EDI_CONTROL_DET.OBJ_SL__SOURCE) + 1 FROM EDI_CONTROL_DET,EDI_CONTROL "
+" WHERE ( EDI_CONTROL_DET.WIN_NAME = ? ) AND "
+"( EDI_CONTROL.WIN_NAME = EDI_CONTROL_DET.WIN_NAME ) AND "
+"( EDI_CONTROL.LINE_NO = EDI_CONTROL_DET.LINE_NO ) AND "
+"( EDI_CONTROL.EDI_MEDIUM = 2 )";
try
{
pstmt = conect.prepareStatement(sql);
pstmt.setString(1,winName.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
totObjSl = rs.getInt(1);
}
rs.close();
pstmt.close();
}
catch(SQLException se)
{
System.out.println("SQLException :[MasterApplyEJB(7)][Excuting Query Failed1]" + sql + se.getMessage());
}
catch(Exception ex)
{
System.out.println("Exception1 ::(MasterApplyEJB(7))"+sql +ex.getMessage());
ex.printStackTrace();
}
System.out.println("MAX OF DATAWINDOW (totObjSl):"+totObjSl);
sql = "";
//GETTING MAX HEADER FOR A PARTICULAR WINDOW
String sqlmax="SELECT MAX(TRAN_SL) FROM BATCHLOAD WHERE WIN_NAME= ? AND BATCH_ID= ? ";
try
{
pstmt = conect.prepareStatement(sqlmax);
pstmt.setString(1,winName.trim());
pstmt.setString(2,batchid.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxTranSl = rs.getInt(1);
}
rs.close();
pstmt.close();
}
catch(SQLException se33)
{
System.out.println("SQLException :[MasterApplyEJB(8)][Excuting Query Failed1]" + sql + se33.getMessage());
}
catch(Exception ex33)
{
System.out.println("Exception1 (MasterApplyEJB(8))::"+sql +ex33.getMessage());
ex33.printStackTrace();
}
System.out.println("MAX OF HEADER (maxTranSl):"+maxTranSl);
tran_sl = maxTranSl;
logBuff.append( "<?xml version='1.0' encoding='UTF-8'?>\n").append("<Root>\n");
logBuff.append("<Header>");
logBuff.append("<win_name>").append(winName).append("</win_name>");
logBuff.append("<batch_id>").append(batchid).append("</batch_id>");
for(int transl = 1 ; transl<=maxTranSl;transl++)//maxTranSl
{ String TranID = "";
int totalDetRec = 0;
String errMsg= "";
String loadStatus = "";
String tranTag = "<TranSl domID=\""+transl+"\" >";
logBuff.append(tranTag);
xmlBuff =new StringBuffer();
System.out.println("total no of objsl="+totObjSl);
xmlBuff.append( "<?xml version='1.0' encoding='UTF-8'?>\n").append("<Root>\n");
xmlBuff.append("<DocumentRoot>");
xmlBuff.append("<description>").append("Datawindow Root").append("</description>");
xmlBuff.append("<group0>");
xmlBuff.append("<description>").append("Group0 description").append("</description>");
xmlBuff.append("<Header0>");
xmlBuff.append("<objName><![CDATA[").append("charge_back").append("]]></objName>");
xmlBuff.append("<pageContext><![CDATA[").append("1").append("]]></pageContext>");
xmlBuff.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
xmlBuff.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
xmlBuff.append("<focusedColumn><![CDATA[").append("").append("]]></focusedColumn>");
xmlBuff.append("<action><![CDATA[").append("SAVE").append("]]></action>");
xmlBuff.append("<elementName><![CDATA[").append("").append("]]></elementName>");
xmlBuff.append("<keyValue><![CDATA[").append("1").append("]]></keyValue>");
xmlBuff.append("<taxKeyValue><![CDATA[").append("").append("]]></taxKeyValue>");
xmlBuff.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
xmlBuff.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
xmlBuff.append("<taxInFocus><![CDATA[").append(false).append("]]></taxInFocus>");
xmlBuff.append("<description>").append("Header0 members").append("</description>");
objSsl = 0;
//GET MAX OBJ_SSL FOR A HEADER(THAT HOW MANY DETAIL RECORD FOR A PARTICULAR HEADER RECORD)
sql = "SELECT MAX(BATCHLOADDET.OBJ_SSL) FROM BATCHLOADDET,BATCHLOAD WHERE BATCHLOAD.BATCH_ID=BATCHLOADDET.BATCH_ID AND BATCHLOAD.TRAN_SL=BATCHLOADDET.TRAN_SL AND BATCHLOAD.WIN_NAME=? "
+ " AND BATCHLOAD.TRAN_SL=? AND BATCHLOAD.BATCH_ID= ?";
try
{
pstmt = conect.prepareStatement(sql);
pstmt.setString(1,winName.trim());
pstmt.setInt(2,tranSl);
pstmt.setString(3,batchid.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
objSsl = rs.getInt(1);
}
System.out.println("TOTAL DETAIL OF HEADER =("+transl+")IS("+objSsl+")");
rs.close();
pstmt.close();
}
catch(SQLException se11)
{
try{conect.rollback();}catch(Exception see){}
System.out.println("SQLException :[MasterApplyEJB(9)][Excuting Query Failed1]" + sql + se11.getMessage());
}
catch(Exception ex11)
{
try{conect.rollback();}catch(Exception exe){}
System.out.println("Exception1 (MasterApplyEJB(9))::"+sql +ex11.getMessage());
ex11.printStackTrace();
}
//LOOP FOR NO OF TOTAL DATAWINDOW(HEADER + DETAIL)
for(int ctr = 0 ; ctr<totObjSl;ctr++)
{
int temp = ctr+1;
//CONDITION FOR HEADER OBJSL=0
if(temp == 1)
{
System.out.println("HEADER OF TRANSL :"+transl);
String tag = "<Detail1 dbID=\"\" domID=\""+transl+"\" objName=\"charge_back\" objContext=\"1\" >";
xmlBuff.append(tag);
String tag1 = "<attribute pkNames=\"\" status=\"N\" updateFlag=\"A\" selected=\"N\" />";
xmlBuff.append(tag1);
xmlBuff.append("<tran_id/>");
try
{
//GETTING FIELD VALUE FOR ALL THE FIELD FOR A PARTICULAR TRANSL ,OBJSSL(1,0.1.2...MAX)
sql = "SELECT BATCHLOAD.BATCH_ID,BATCHLOADDET.FLD_NO,BATCHLOADDET.FLD_DATA FROM BATCHLOAD,BATCHLOADDET"
+" WHERE BATCHLOAD.BATCH_ID=BATCHLOADDET.BATCH_ID AND BATCHLOAD.TRAN_SL=BATCHLOADDET.TRAN_SL AND BATCHLOAD.WIN_NAME = ? "
+ "AND BATCHLOADDET.OBJ_SL= ? AND BATCHLOAD.TRAN_SL=? and BATCHLOAD.BATCH_ID= ? ";
pstmt = conect.prepareStatement(sql);
pstmt.setString(1,winName);
pstmt.setInt(2,ctr);
pstmt.setInt(3,transl);
pstmt.setString(4,batchid.trim());
rs = pstmt.executeQuery();
while(rs.next())
{
BachId = rs.getString(1);
fldNo = rs.getInt(2);
fldData = rs.getString(3);
try
{
//GETTING THE FILED NAME FOR A PARTICULAR FILED
sql1 = "SELECT FLD_NAME__DEST FROM EDI_CONTROL_DET A, EDI_CONTROL B WHERE A.WIN_NAME = B.WIN_NAME AND A.LINE_NO = B.LINE_NO"
+" AND B.WIN_NAME = ? AND A.OBJ_SL__SOURCE =? "
+" AND B.EDI_MEDIUM = 2 and A.FLD_NO__SOURCE <>0 and A.FLD_NO__SOURCE = ? ORDER BY A.OBJ_SL__SOURCE,A.FLD_NO__DEST ";
pstmt1 = conect.prepareStatement(sql1);
pstmt1.setString(1,winName);
pstmt1.setInt(2,ctr);
pstmt1.setInt(3,fldNo);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
fldName = rs1.getString(1);
}
fldName = fldName.toLowerCase();
//IF FILED IS DATE THEN CONVERT IN TO APPDATE FORMAT
for(int dateFldCount = 0;dateFldCount<headerDateFilelds.size();dateFldCount++)
{
String dateFld = (String)headerDateFilelds.get(dateFldCount);
if(fldName.trim().equalsIgnoreCase(dateFld.trim()))
{
System.out.println("find........");
Object date = null;
System.out.println("Field data="+fldData);
System.out.println("Db date format="+fldData);
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = sdf.parse(fldData);
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility.getApplDateFormat());
fldData=sdf1.format(date).toString();
System.out.println("application date format="+fldData);
}
}
xmlBuff.append("<").append(fldName).append(">").append("<![CDATA[").append(fldData.trim()).append("]]>").append("<").append("/").append(fldName).append(">");
rs1.close();
pstmt1.close();
}
catch(SQLException se3)
{
System.out.println("SQLException :[MasterApplyEJB(10)][Excuting Query Failed2]" + sql1 + se3.getMessage());
}
catch(Exception ex3)
{
System.out.println("Exception2(MasterApplyEJB(10)) ::"+sql1+ex3.getMessage());
ex3.printStackTrace();
}
}
String end = "</Detail1>";
xmlBuff.append(end);
rs.close();
pstmt.close();
}
catch(SQLException se1)
{
System.out.println("SQLException :[MasterApplyEJB(11)][Excuting Query Failed3]" + sql + se1.getMessage());
}
catch(Exception ex1)
{
System.out.println("Exception3 (MasterApplyEJB(11))::"+sql +ex1.getMessage());
ex1.printStackTrace();
}
}
else
{
//FOR DETAIL LOOP FOR NO OF RECORD IN DETAIL
for(int j=1;j<=objSsl;j++) //objSsl
{
pointerList = new ArrayList();
if(j==1)
{
pointerList = detati1DateFilelds;
}
if(j==2)
{
pointerList = detati2DateFilelds;
}
if(j==3)
{
pointerList = detati3DateFilelds;
}
System.out.println("detail(" +j+")of" +"HEADER :"+transl);
String tag = "<Detail"+temp;
tag = tag +" dbID=\"\" domID=\""+j+"\" objName=\"charge_back\" objContext=\"2\""+">";
xmlBuff.append(tag);
xmlBuff.append("<attribute pkNames=\"tran_id:line_no:\" status=\"N\" updateFlag=\"A\" selected=\"N\"/>");
xmlBuff.append("<tran_id><![CDATA[").append("").append("]]></tran_id>");
xmlBuff.append("<line_no><![CDATA[").append(j).append("]]></line_no>");
try
{ //GETTING FIELD VALUE FOR ALL THE FIELD FOR A PARTICULAR TRANSL
sql = "SELECT BATCHLOAD.BATCH_ID,BATCHLOADDET.FLD_NO,BATCHLOADDET.FLD_DATA FROM BATCHLOAD,BATCHLOADDET"
+" WHERE BATCHLOAD.BATCH_ID=BATCHLOADDET.BATCH_ID AND BATCHLOAD.TRAN_SL=BATCHLOADDET.TRAN_SL AND BATCHLOAD.WIN_NAME = ? "
+ "AND BATCHLOADDET.OBJ_SL= ? AND BATCHLOAD.TRAN_SL=? and BATCHLOADDET.OBJ_SSL=? AND BATCHLOAD.BATCH_ID= ? ";
pstmt = conect.prepareStatement(sql);
pstmt.setString(1,winName);
pstmt.setInt(2,ctr);
pstmt.setInt(3,transl);
pstmt.setInt(4,j);
pstmt.setString(5,batchid.trim());
rs = pstmt.executeQuery();
while(rs.next())
{
BachId = rs.getString(1);
fldNo = rs.getInt(2);
fldData = rs.getString(3);
try
{
sql1 = "SELECT FLD_NAME__DEST FROM EDI_CONTROL_DET A, EDI_CONTROL B WHERE A.WIN_NAME = B.WIN_NAME AND A.LINE_NO = B.LINE_NO"
+" AND B.WIN_NAME = ? AND A.OBJ_SL__SOURCE =? "
+" AND B.EDI_MEDIUM = 2 and A.FLD_NO__SOURCE <>0 and A.FLD_NO__SOURCE = ? ORDER BY A.OBJ_SL__SOURCE,A.FLD_NO__DEST ";
pstmt1 = conect.prepareStatement(sql1);
pstmt1.setString(1,winName);
pstmt1.setInt(2,ctr);
pstmt1.setInt(3,fldNo);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
fldName = rs1.getString(1);
}
fldName = fldName.toLowerCase();
//IF FILED IS DATE THEN CONVERT IN TO APPDATE FORMAT
for(int dateFldCount = 0;dateFldCount<pointerList.size();dateFldCount++)
{
String dateFld = (String)pointerList.get(dateFldCount);
if(fldName.trim().equalsIgnoreCase(dateFld.trim()))
{
System.out.println("find........");
Object date = null;
System.out.println("Field data="+fldData);
System.out.println("Db date format="+fldData);
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = sdf.parse(fldData);
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility.getApplDateFormat());
fldData=sdf1.format(date).toString();
System.out.println("application date format="+fldData);
}
}
xmlBuff.append("<").append(fldName).append(">").append("<![CDATA[").append(fldData.trim()).append("]]>").append("<").append("/").append(fldName).append(">");
pstmt1.close();
}
catch(SQLException se3)
{
System.out.println("SQLException :[MasterApplyEJB(12)][Excuting Query Failed2]" + sql1 + se3.getMessage());
}
catch(Exception ex3)
{
System.out.println("Exception2(MasterApplyEJB(12)) ::"+sql1+ex3.getMessage());
ex3.printStackTrace();
}
}
String end = "</Detail"+temp+">";
xmlBuff.append(end);
rs.close();
pstmt.close();
}
catch(SQLException se1)
{
System.out.println("SQLException :[MasterApplyEJB(13)][Excuting Query Failed3]" + sql + se1.getMessage());
}
catch(Exception ex1)
{
System.out.println("Exception3 (MasterApplyEJB(13))::"+sql +ex1.getMessage());
ex1.printStackTrace();
}
}
}
}//end of for
xmlBuff.append("</Header0>");
xmlBuff.append("</group0>");
xmlBuff.append("</DocumentRoot>");
xmlBuff.append("</Root>\r\n");
try
{
//System.out.println("Before modifying:::::::::::::"+xmlBuff.toString());
xmlStrPass = xmlBuff.toString();
System.out.println("passing xmlString is::::::::"+xmlStrPass);
System.out.println("Size:::"+collectFldList.size());
for(int count = 0;count<collectFldList.size();count++)
{
System.out.println("call the ejb "+ count +"times");
CbBean collectFiels = (CbBean)collectFldList.get(count);
// String methodStr = "replaceVal";
//String classStr = "ibase.webitm.ejb.dis.ChargeBackEJB";
System.out.println("[component:"+collectFiels.getCompName().trim()+"]");
System.out.println("[Field:"+collectFiels.getFldName().trim()+"]");
System.out.println("[Method:"+collectFiels.getMethName().trim()+"]");
System.out.println("[Form:"+collectFiels.getFormNo().trim()+"]");
Class cobj = Class.forName( collectFiels.getCompName().trim());
Class stringClass= Class.forName("java.lang.String");
Class[] paramSpec = new Class[4];
paramSpec[0] = stringClass;
paramSpec[1] = stringClass;
paramSpec[2] = stringClass;
paramSpec[3] = stringClass;
String params[] = new String[4];
params[0] = xmlStrPass;
params[1] = collectFiels.getFldName().trim();;
params[2] = collectFiels.getFormNo().trim();
params[3] = xtraParam;
java.lang.reflect.Method metObj = cobj.getMethod(collectFiels.getMethName().trim(),paramSpec);
metObj.setAccessible(true);
xmlStr = (String)metObj.invoke(cobj.newInstance(), params);
xmlStrPass = xmlStr;
}
System.out.println("xmlStr::::::::::::::::::"+xmlStrPass);
FileOutputStream fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"XMLCB"+File.separator+"CB"+transl+batchid+".xml");
byte convertStringToByte1[] = xmlStrPass.getBytes();
fos1.write(convertStringToByte1);
fos1.close();
}
catch(Exception e)
{
System.out.println("Exception : [MasterApplyEJB(14)][getErrorString] \n:==>"+e.getMessage());
e.printStackTrace();
}
// System.out.println("Before Update:::::::"+xmlBuff);
String errMessage = null;
try
{
String errStr = saveData(xmlStrPass);
System.out.println("After update:::::::"+errStr);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
OutputStreamWriter errorWriter = new OutputStreamWriter(System.err, "UTF-8");//writes the thing with the specific format hardcoded
ByteArrayInputStream baos = new ByteArrayInputStream(errStr.getBytes());
dom = db.parse(baos);
Node parentNode = dom.getElementsByTagName("Error").item(0);
if(parentNode != null)
{
NodeList childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
Node childNode = childNodeList.item(childRow);
String childNodeName = childNode.getNodeName();
if (childNodeName.equals("message"))
{
errMessage = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("Message::::: "+ errMessage);
}
}
System.out.println("message::::::::::"+ errMessage);
}
}
catch(Exception g)
{
System.out.println(g.getMessage());
}
if(errMessage != null)
{
update = "";
loadStatus = "N";
errMsg = errMessage;
//<Root><Detail>Success</Detail><TranID>0000001405</TranID></Root>
try
{
update = "UPDATE BATCHLOAD SET ERROR_MSG = ? WHERE BATCH_ID =? AND TRAN_SL= ? ";
psUpdateBl = conect.prepareStatement(update);
psUpdateBl.setString(1,errMessage);
psUpdateBl.setString(2,batchid.trim());
psUpdateBl.setInt(3,transl);
psUpdateBl.executeUpdate();
psUpdateBl.close();
}
catch(SQLException seUpdate)
{
System.out.println("SQLException(Update Batchload) :[domCreation][Excuting Query Failed ]" + update + seUpdate.getMessage());
}
catch(Exception exUpdate)
{
System.out.println("Exception3(Update Batchload) ::"+update +exUpdate.getMessage());
exUpdate.printStackTrace();
}
}
else
{
loadStatus = "Y";
try
{
TranID = "";
//String xmlStr="<Root><Detail>Success</Detail><TranID>0000001405</TranID></Root>";
NodeList parentNodeList = dom.getElementsByTagName("Root");
Node parentNode = parentNodeList.item(0);
NodeList childNodeList = parentNode.getChildNodes();
int ctr = 0;
int childNodeListLength = childNodeList.getLength();
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
Node childNode = childNodeList.item(childRow);
String childNodeName = childNode.getNodeName();
if (childNodeName.equals("TranID"))
{
TranID = (childNode.getFirstChild().getNodeValue()).trim();
}
}
System.out.println("tran_id="+TranID);
}
catch(Exception e){System.out.println(e.getMessage());}
try
{
update = "";
update = "UPDATE BATCHLOAD SET LOAD_STAT = 'Y' , LOAD_DATE = ? WHERE BATCH_ID =? AND TRAN_SL=? ";
java.sql.Timestamp ts=new java.sql.Timestamp(System.currentTimeMillis());
SimpleDateFormat sdt=new SimpleDateFormat(genericUtility.getDBDateFormat());
psUpdateBl = conect.prepareStatement(update);
psUpdateBl.clearParameters();
psUpdateBl.setDate(1,java.sql.Date.valueOf(sdt.format(ts)));
psUpdateBl.setString(2,batchid.trim());
psUpdateBl.setInt(3,transl);
int rec = psUpdateBl.executeUpdate();
psUpdateBl.close();
System.out.println("No of record Update = "+rec);
}
catch(SQLException seUpdate)
{
System.out.println("SQLException(Update Batchload) :[domCreation][Excuting Query Failed ]" + update + seUpdate.getMessage());
}
catch(Exception exUpdate)
{
System.out.println("Exception3(Update Batchload) ::"+update +exUpdate.getMessage());
exUpdate.printStackTrace();
}
}
logBuff.append("<tran_id>").append(TranID).append("</tran_id>");
logBuff.append("<total_det>").append(totalDetRec).append("</total_det>");
logBuff.append("<load_status>").append(loadStatus).append("</load_status>");
logBuff.append("<err_msg>").append(errMsg).append("</err_msg>");
logBuff.append("</TranSl>");
}//end of transl
logBuff.append("</Header>");
logBuff.append("</Root>");
try
{
//WRITING IN THE XMLSTRING(LOG) IN A FILE
FileOutputStream fos11 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"LOG"+File.separator+ "LOG"+batchid+".xml");
byte convertStringToByte11[] = logBuff.toString().getBytes();
fos11.write(convertStringToByte11);
fos11.close();
}
catch(Exception e)
{
System.out.println("Exception : [CreateEJB][getErrorString] \n:==>"+e.getMessage());
e.printStackTrace();
}
System.out.println("END OF MASTER APPLY......");
}//end of dom creation
private String saveData(String xmlString)throws ITMException
{
System.out.println("saving data...........");
InitialContext ctx = null;
String retString = null;
MasterStatefulLocal masterStateful = null ; // for ejb3
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
// MasterStateful masterStateful = masterStatefulHome.create();
String [] authencate = new String[2];
authencate[0] = userId;
authencate[1] = userId;
retString = masterStateful.processRequest(authencate, logInSite, true, xmlString);
}
catch(ITMException itme)
{
System.out.println("ITMException :FeedBackServlet :saveData :==>");
throw itme;
}
catch(Exception e)
{
System.out.println("Exception :FeedBackServlet :saveData :==>");
throw new ITMException(e);
}
return retString;
}
}//END OF EJB
\ No newline at end of file
package ibase.webitm.ejb.sys;
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 MasterApplyLocal //extends EJBObject
{
public void applyMasterTable(String batchid,String xtraParams)throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ProcessRemote;
public interface MasterApplyRemote //extends EJBObject
{
public void applyMasterTable(String batchid,String xtraParams)throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
// Rajesh on 9/20/2005 to use BaseLogger functions
import ibase.utility.BaseLogger;
import java.io.File;
/* This EJB will Validate the Data entered in the Object Actions Master */
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ObjLinks extends ValidatorEJB implements ObjLinksLocal , ObjLinksRemote // SessionBean//Ratikant 30/Mar/2005
{
/*public void ejbCreate() throws RemoteException, CreateException
{
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String wfValData() throws RemoteException,ITMException
{
return "";
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;//Ratikant 30/Mar/2005
String errString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
// dom2 = parseString(xmlString2);//Ratikant 30/Mar/2005
errString = wfValData(dom,dom1,null,objContext,editFlag,xtraParams);//Ratikant 30/Mar/2005
}
catch(Exception e)
{
BaseLogger.error(e);
}
return (errString);
}
public String wfValData(Document dom,Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
String columnName = "";
String columnValue = "";
String userId = "";
String errString = "";
String errCode = "";
String evtCode = "";
String objName = "";
String lineNo = "";
String sql = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int cnt = 0;
int currentFormNo = 0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
int ctr;
try
{
conn = getConnection(); //This function is to connect with oracle....
userId = GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"userId");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
stmt = conn.createStatement();
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
BaseLogger.debug("Child Node::"+childNodeName);
if(childNodeName.equals("obj_name"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Obj Name Is Null");
errString = getErrorString("obj_name","NULLOBJNM",userId,errString);
break;
}
else
{
objName=childNode.getFirstChild().getNodeValue();
}
}
else if (childNodeName.equals("line_no"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Line Number is null");
errString = getErrorString("line_no","NULLLNNO",userId,errString);
break;
}
else
{
lineNo = childNode.getFirstChild().getNodeValue();
if (editFlag.equalsIgnoreCase("A"))
{
sql = " SELECT COUNT(*) FROM OBJ_ACTIONS WHERE obj_name = '"+objName+"'" +" AND line_no = '"+lineNo+ "'";
BaseLogger.debug("SQL is -->" +sql);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next())
{
if(rs.getInt(1) > 0)
{
BaseLogger.debug("Tried to enter Duplicate key combination");
errString = getErrorString("event_code","DUPLOBJACD ",userId,errString);
break;
}
}
}
}
}
else if(childNodeName.equals("title"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Obj Name Is Null");
errString = getErrorString("title","NULLTITLCD",userId,errString);
break;
}
}
}
break;
}
}
catch(Exception e)
{
BaseLogger.error(e);
e.printStackTrace();
throw new ITMException(e);
}
return errString;
}//wfValData(Document dom) method ends here
}//class ends
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface ObjLinksLocal extends ValidatorLocal//, EJBObject//Ratikant 30/Mar/2005
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
public interface ObjLinksRemote extends ValidatorRemote//, EJBObject//Ratikant 30/Mar/2005
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
// Rajesh on 9/20/2005 to use BaseLogger functions
import ibase.utility.BaseLogger;
import java.io.File;
/* This EJB will Validate the Data entered in the Object Actions Master */
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class ObjectActions extends ValidatorEJB implements ObjectActionsLocal , ObjectActionsRemote // SessionBean//Ratikant 30/Mar/2005
{
/*public void ejbCreate() throws RemoteException, CreateException
{
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
*/
public String wfValData() throws RemoteException,ITMException
{
return "";
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;//Ratikant 30/Mar/2005
String errString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
// dom2 = parseString(xmlString2);//Ratikant 30/Mar/2005
errString = wfValData(dom,dom1,null,objContext,editFlag,xtraParams);//Ratikant 30/Mar/2005
}
catch(Exception e)
{
BaseLogger.error(e);
}
return (errString);
}
public String wfValData(Document dom,Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException//Ratikant 30/Mar/2005
{
String columnName = "";
String columnValue = "";
String userId = "";
String errString = "";
String errCode = "";
String evtCode = "";
String objName = "";
String lineNo = "";
String sql = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int cnt = 0;
int currentFormNo = 0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
int ctr;
try
{
conn = getConnection(); //This function is to connect with oracle....
userId = GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"userId");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
stmt = conn.createStatement();
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
BaseLogger.debug("Child Node::"+childNodeName);
if(childNodeName.equals("obj_name"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Obj Name Is Null");
errString = getErrorString("obj_name","NULLOBJNM",userId,errString);
break;
}
else
{
objName=childNode.getFirstChild().getNodeValue();
}
}
else if (childNodeName.equals("line_no"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Line Number is null");
errString = getErrorString("line_no","NULLLNNO",userId,errString);
break;
}
else
{
lineNo = childNode.getFirstChild().getNodeValue();
if (editFlag.equalsIgnoreCase("A"))
{
sql = " SELECT COUNT(*) FROM OBJ_ACTIONS WHERE obj_name = '"+objName+"'" +" AND line_no = '"+lineNo+ "'";
BaseLogger.debug("SQL is -->" +sql);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next())
{
if(rs.getInt(1) > 0)
{
BaseLogger.debug("Tried to enter Duplicate key combination");
errString = getErrorString("event_code","DUPLOBJACD ",userId,errString);
break;
}
}
}
}
}
else if(childNodeName.equals("title"))
{
if(childNode.getFirstChild() == null)
{
BaseLogger.debug("Obj Name Is Null");
errString = getErrorString("title","NULLTITLCD",userId,errString);
break;
}
}
}
break;
}
}
catch(Exception e)
{
BaseLogger.error(e);
e.printStackTrace();
throw new ITMException(e);
}
return errString;
}//wfValData(Document dom) method ends here
}//class ends
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface ObjectActionsLocal extends ValidatorLocal //, EJBObject//Ratikant 30/Mar/2005
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
public interface ObjectActionsRemote extends ValidatorRemote//, EJBObject//Ratikant 30/Mar/2005
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;//Ratikant 30/Mar/2005
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import java.text.*;
class PassWordGenerator
{
public String password(String userName)
{
String subStr ="",passWord ="";
int dateLength,timeLength,charIntVal =0,pos =0;
long totalLen =0;
StringBuffer strbuf =new StringBuffer();
java.sql.Timestamp currDate =new java.sql.Timestamp(System.currentTimeMillis()) ;
String leftStr="",suffixStr ="";
int userNameLength;
char prefixChar ='q' ,midChar ='M';
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
System.out.println(currDate);
String dateStr = sdf.format(currDate);
sdf = new SimpleDateFormat("HH:mm:ss");
String timeStr = sdf.format(currDate);
dateLength =dateStr.length();
timeLength =timeStr.length();
for(int ctr =0;ctr < timeLength;ctr++)
{
char charval = dateStr.charAt(ctr) ;
int ascii =(int)charval;
strbuf.append(ascii);
charIntVal =0;
if(Character.getNumericValue(charval) != -1)
{
charIntVal = Character.getNumericValue(charval);
}
totalLen = totalLen + charIntVal + timeLength;
}
totalLen = Long.parseLong(strbuf.toString()) / totalLen;
subStr = dateStr.substring(dateStr.length()-2,dateStr.length());
if(totalLen == 0)
{
passWord = strbuf.substring(strbuf.length()-10,strbuf.length());
}
else
{
totalLen = totalLen * Integer.parseInt(subStr);
passWord = totalLen+"";
}
pos = (int)((passWord.length())/2);
//userName ="RAJENDRA";
userName = userName.trim();
leftStr = passWord.substring(0,pos);
suffixStr = passWord.substring(pos);
userNameLength =userName.length();
for(int count = userNameLength;count >=2;count--)
{
String prefixStr =userName.substring(count-2,count-1);
prefixChar =prefixStr.charAt(0);
if((Character.isDigit(prefixChar)) || (int)(Character.toLowerCase(prefixChar)) > 116 )continue;
if((int)(Character.toLowerCase(prefixChar)) <= 116)
{
prefixChar = Character.toLowerCase(prefixChar);
break;
}
else
{
prefixChar = 'q';
}
}
for(int ctr =0;ctr < userName.length()-1;ctr++)
{
String midStr = userName.substring(ctr,ctr+1);
midChar =midStr.charAt(0);
if(Character.isDigit(midChar)) continue;
if(((int)(Character.toUpperCase(midChar)) >= 65) && ((int)(Character.toUpperCase(midChar)) <= 90) )
break;
else
{
midChar ='M';
}
}
passWord = prefixChar+leftStr+midChar+suffixStr;
return passWord;
}
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class SQLChange extends ValidatorEJB implements SQLChangeLocal , SQLChangeRemote // SessionBean
{
GenericUtility genericUtility = GenericUtility.getInstance();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
/*public void ejbCreate() throws RemoteException, CreateException
{
System.out.println("Entering into SQLChangeEJB.............");
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String wfValData() throws RemoteException,ITMException
{
return "";
}
public String itemChanged() throws RemoteException,ITMException
{
return "";
}
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
{
dom = parseString(xmlString); //returns the DOM Object for the passed XML Stirng
System.out.println("xmlString :" + xmlString);
dom1 = parseString(xmlString1); //returns the DOM Object for the passed XML Stirng
System.out.println("xmlString1 :" + xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [SQLChangeEJB][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
{
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSet rs1 = null;
StringBuffer valueXmlString = new StringBuffer();
StringBuffer retString = new StringBuffer();
String errCode = "";
String sql = "";
String columnValue = "";
String childNodeName = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr = 0;
int n = 0;
int currentFormNo = 0;
String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
System.out.println("userId ::-"+userId);
try
{
conn = getConnection();
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
System.out.println("[SQLChangeEJB] [itemChanged] :currentFormNo ....." +currentFormNo);
//valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString = new StringBuffer("<?xml version=\"1.0\" encoding='"+genericUtility.getValueFromXTRA_PARAMS( xtraParams, "charEnc" )+"'?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
valueXmlString.append("<Detail>");
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
int childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equals(currentColumn))
{
if (childNode.getFirstChild() != null)
{
columnValue=childNode.getFirstChild().getNodeValue().trim();
}
}
ctr++;
}
while(ctr < childNodeListLength && !childNodeName.equals(currentColumn));
if (currentColumn.trim().equals("itm_default"))
{
if(columnValue != null)
{
try
{
String applCurrDate = getCurrdateAppFormat();
String empCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
valueXmlString.append("<tran_date protect=\"1\">").append(applCurrDate).append("</tran_date>");
valueXmlString.append("<emp_code__merge>").append(empCode).append("</emp_code__merge>");
String empFName = "";
String empMName = "";
String empLName = "";
String empDesc = "";
if(columnValue != null)
{
try
{
sql = "SELECT EMP_FNAME,EMP_MNAME,EMP_LNAME FROM EMPLOYEE WHERE EMP_CODE = '"+empCode.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
empFName = rs.getString(1);
empMName = rs.getString(2);
empLName = rs.getString(3);
}
empDesc = empFName+" "+empMName+" "+empLName;
System.out.println("Employee Code ::- "+columnValue);
System.out.println("Employee First Name ::- "+empFName);
System.out.println("Employee Middle Name ::- "+empMName);
System.out.println("Employee Last Name ::- "+empLName);
valueXmlString.append("<employee_emp_fname_1>").append(empFName).append("</employee_emp_fname_1>");
valueXmlString.append("<employee_emp_lname_1>").append(empLName).append("</employee_emp_lname_1>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}
else if (currentColumn.trim().equals("itm_defaultedit"))
{
String custName = "";
if(columnValue != null)
{
try
{
sql = "SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE = '"+columnValue.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
custName = rs.getString(1);
}
System.out.println("Customer Code ::- "+columnValue);
System.out.println("Customer Name ::- "+custName);
valueXmlString.append("<customer_cust_name>").append(custName).append("</customer_cust_name>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//else if
else if (currentColumn.trim().equals("req_id"))
{
String custName = null;
String custCode = null;
String reqDate = null;
if(columnValue != null)
{
try
{
sql = "SELECT A.CUST_CODE, B.CUST_NAME, A.REQ_DATE FROM SER_REQUEST A, CUSTOMER B WHERE A.CUST_CODE = B.CUST_CODE AND A.REQ_ID = '"+columnValue.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
custCode = rs.getString(1);
custName = rs.getString(2);
reqDate = rs.getString(3);
}
System.out.println("Customer Code ::- "+columnValue);
System.out.println("Customer Name ::- "+custName);
valueXmlString.append("<cust_code protect=\"1\">").append(custCode).append("</cust_code>");
valueXmlString.append("<customer_cust_name>").append(custName).append("</customer_cust_name>");
reqDate = genericUtility.getValidDateString(reqDate, genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
valueXmlString.append("<req_date protect=\"1\">").append(reqDate).append("</req_date>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//else if
else if (currentColumn.trim().equals("cust_code"))
{
String custName = "";
if(columnValue != null)
{
try
{
sql = "SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE = '"+columnValue.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
custName = rs.getString(1);
}
System.out.println("Customer Code ::- "+columnValue);
System.out.println("Customer Name ::- "+custName);
valueXmlString.append("<customer_cust_name>").append(custName).append("</customer_cust_name>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//else if
else if (currentColumn.trim().equals("emp_code__given"))
{
String empFName = "";
String empMName = "";
String empLName = "";
String empDesc = "";
if(columnValue != null)
{
try
{
sql = "SELECT EMP_FNAME,EMP_MNAME,EMP_LNAME FROM EMPLOYEE WHERE EMP_CODE = '"+columnValue.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
empFName = rs.getString(1);
empMName = rs.getString(2);
empLName = rs.getString(3);
}
empDesc = empFName+" "+empMName+" "+empLName;
System.out.println("Employee Code ::- "+columnValue);
System.out.println("Employee First Name ::- "+empFName);
System.out.println("Employee Middle Name ::- "+empMName);
System.out.println("Employee Last Name ::- "+empLName);
valueXmlString.append("<employee_emp_fname>").append(empFName).append("</employee_emp_fname>");
valueXmlString.append("<employee_emp_lname>").append(empLName).append("</employee_emp_lname>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//else if
else if (currentColumn.trim().equals("emp_code__merge"))
{
String empFName = "";
String empMName = "";
String empLName = "";
String empDesc = "";
if(columnValue != null)
{
try
{
sql = "SELECT EMP_FNAME,EMP_MNAME,EMP_LNAME FROM EMPLOYEE WHERE EMP_CODE = '"+columnValue.trim()+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
System.out.println("SQL....."+sql);
if (rs.next())
{
empFName = rs.getString(1);
empMName = rs.getString(2);
empLName = rs.getString(3);
}
empDesc = empFName+" "+empMName+" "+empLName;
System.out.println("Employee Code ::- "+columnValue);
System.out.println("Employee First Name ::- "+empFName);
System.out.println("Employee Middle Name ::- "+empMName);
System.out.println("Employee Last Name ::- "+empLName);
valueXmlString.append("<employee_emp_fname_1>").append(empFName).append("</employee_emp_fname_1>");
valueXmlString.append("<employee_emp_lname_1>").append(empLName).append("</employee_emp_lname_1>");
}//try
catch(Exception e)
{
System.out.println("Exception :[SQLChangeEJB][itemChanged::case 1::order_type] :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//if
}//else if
valueXmlString.append("</Detail>");
break;
}//Switch
valueXmlString.append("</Root>");
}//try
catch(Exception e)
{
System.out.println("Exception ::"+e.getMessage());
}
finally
{
try
{
conn.close();
conn = null;
}
catch(Exception s){}
}
return valueXmlString.toString();
}//itemChanged()
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = null;
System.out.println("Entering into validations ...................");
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : PayableOpeningsEJB : wfValData(String xmlString) : ==>\n"+e.getMessage());
}
return (errString);
}
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String errString = "";
String errCode = "";
String sql = "";
String userId = "";
String custCode = "";
String empCodeGiven = "";
String empCodeMerge = "";
String childNodeName = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr,currentFormNo=0;
int childNodeListLength;
try
{
conn = getConnection();
stmt = conn.createStatement();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
System.out.println("userId = "+userId);
System.out.println("xtraParams = "+xtraParams);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
parentNodeList = dom.getElementsByTagName("Detail" + currentFormNo);
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
switch (currentFormNo)
{
case 1:
{
if (childNodeName.equals("cust_code"))
{
System.out.println("childNodeName 1. : " + childNodeName);
custCode = genericUtility.getColumnValue("cust_code",dom);
System.out.println("childNode.getFirstChild() 1. : " + childNode.getFirstChild());
if (childNode.getFirstChild() == null)
{
errCode = "VECUST2";
errString = getErrorString("cust_code",errCode,userId);
break;
}
else if(custCode != null && custCode.trim().length()>0)
{
sql = "SELECT COUNT(1) AS COUNT FROM CUSTOMER WHERE CUST_CODE = '"+custCode.trim()+"'";
rs = stmt.executeQuery(sql);
System.out.println("SQL......"+sql);
if (rs.next())
{
int cnt = rs.getInt("COUNT");
if (cnt == 0)
{
errCode = "VMCUSTCDX";
errString = getErrorString("cust_code",errCode,userId);
break;
}
}
}//else
}//if
if (childNodeName.equals("itm_ver"))
{
System.out.println("childNodeName 1. : " + childNodeName);
custCode = genericUtility.getColumnValue("itm_ver",dom);
System.out.println("childNode.getFirstChild() 1. : " + childNode.getFirstChild());
if (childNode.getFirstChild() == null)
{
errCode = "VTITMVER";
errString = getErrorString("itm_ver",errCode,userId);
break;
}
}//if
else if (childNodeName.equals("emp_code__given"))
{
System.out.println("childNodeName 1. : " + childNodeName);
empCodeGiven = genericUtility.getColumnValue("emp_code__given",dom);
System.out.println("childNode.getFirstChild() 1. : " + childNode.getFirstChild());
if (empCodeGiven == null || empCodeGiven.trim().length() == 0)
{
errCode = "VTEMPNOEX";
errString = getErrorString("emp_code__given",errCode,userId);
break;
}
else if(empCodeGiven != null && empCodeGiven.trim().length()>0)
{
sql = "SELECT COUNT(1) AS COUNT FROM EMPLOYEE WHERE EMP_CODE = '"+empCodeGiven.trim()+"'";
rs = stmt.executeQuery(sql);
System.out.println("SQL......"+sql);
if (rs.next())
{
int cnt = rs.getInt("COUNT");
if (cnt == 0)
{
errCode = "VMEMPCD1";
errString = getErrorString("emp_code__given",errCode,userId);
break;
}
}
}//else
}//if
else if (childNodeName.equals("emp_code__merge"))
{
System.out.println("childNodeName 1. : " + childNodeName);
empCodeMerge = genericUtility.getColumnValue("emp_code__merge",dom);
System.out.println("childNode.getFirstChild() 1. : " + childNode.getFirstChild());
if (empCodeMerge == null || empCodeMerge.trim().length() == 0)
{
errCode = "VTEMPNOEX";
errString = getErrorString("emp_code__merge",errCode,userId);
break;
}
else if(empCodeMerge != null && empCodeMerge.trim().length()>0)
{
sql = "SELECT COUNT(1) AS COUNT FROM EMPLOYEE WHERE EMP_CODE = '"+empCodeMerge.trim()+"'";
rs = stmt.executeQuery(sql);
System.out.println("SQL......"+sql);
if (rs.next())
{
int cnt = rs.getInt("COUNT");
if (cnt == 0)
{
errCode = "VMEMPCD1";
errString = getErrorString("emp_code__merge",errCode,userId);
break;
}
}
}//else
}//else if
else if(childNodeName.equals("req_id"))
{
if(childNode.getFirstChild() == null)
{
errCode = "INREQ12";
errString = getErrorString("req_id",errCode,userId);
break;
}
}
else if(childNodeName.equals("req_date"))
{
System.out.println("Inside Request date ...");
if(childNode.getFirstChild() == null)
{
errCode = "INREQ13";
errString = getErrorString("req_date",errCode,userId);
break;
}
}
}//case1
break;
}//switch
}//for
}//try
catch(Exception e)
{
System.out.println("Exception ::"+e);
e.printStackTrace();
}
finally
{
try
{
System.out.println("Closing Connection.....");
conn.close();
conn = null;
}catch(Exception se){}
}
System.out.println("ErrString ::"+errString);
return errString;
}//wfValData
private String getCurrdateAppFormat()
{
String currAppdate ="";
java.sql.Timestamp currDate = null;
try
{
Object date = null;
currDate =new java.sql.Timestamp(System.currentTimeMillis()) ;
System.out.println(genericUtility.getDBDateFormat());
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = sdf.parse(currDate.toString());
currDate = java.sql.Timestamp.valueOf(sdf.format(date).toString() + " 00:00:00.0");
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
}
catch(Exception e)
{
System.out.println("Exception in :::calcFrsBal"+e.getMessage());
}
return (currAppdate);
}
}//class
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface SQLChangeLocal extends ValidatorLocal//, EJBObject
{
public String wfValData() throws RemoteException,ITMException;
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() 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;
}
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.ejb.*;
import ibase.webitm.utility.ITMException;
public interface SQLChangeRemote extends ValidatorRemote//, EJBObject
{
public String wfValData() throws RemoteException,ITMException;
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() 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;
}
package ibase.webitm.ejb.sys;
import java.sql.*;
import java.util.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.*;
import ibase.webitm.utility.GenericUtility;
public class SysCommon
{
GenericUtility genericUtility = GenericUtility.getInstance();
public static String nfCheckPeriod(String modCode, java.sql.Timestamp tranDate , String siteCode, Connection conn) throws Exception
{
String errCode = "";
String prdCode= "";
String stat = "";
String sql = "";
java.sql.Timestamp procDate = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
String fldPart = null;
GenericUtility genericUtility = new ibase.webitm.utility.GenericUtility();//.getInstance();
try
{
if ("DIS".equals(modCode.toUpperCase()))
{
fldPart = "IC";
}
else
{
fldPart = modCode;
}
if("ADM".equals(modCode.toUpperCase()) || "FIN".equals(modCode.toUpperCase()) || "PUR".equals(modCode.toUpperCase())|| "SAL".equals(modCode.toUpperCase())|| "MFG".equals(modCode.toUpperCase())|| "IC".equals(modCode.toUpperCase())|| "DIS".equals(modCode.toUpperCase()) )
{
sql = "SELECT CODE FROM PERIOD WHERE ? BETWEEN FR_DATE AND TO_DATE";
System.out.println( "sql in nbCheckPeriod:" + sql );
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDate);
rs = pstmt.executeQuery();
if(rs.next())
{
prdCode = rs.getString(1);
}
else
{
errCode = "VTPRD1";
}
rs.close();
pstmt.close();
rs = null;
pstmt = null;
if (errCode.length() == 0)
{
sql = "SELECT STAT_" + fldPart + ",PROC_DATE FROM PERIOD_STAT WHERE SITE_CODE = '" + siteCode + "' AND PRD_CODE = '" + prdCode + "'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
stat = rs.getString(1);
procDate = rs.getTimestamp(2);
if (stat.equals("N"))
{
errCode = "VTPRD" + fldPart;
}
else if (procDate.compareTo(tranDate) > 0 )
{
errCode = "VTPRDT" + fldPart;
}
}
rs.close();
pstmt.close();
rs = null;
pstmt = null;
}
}
}
catch (Exception e)
{
System.out.println("Exception :SysCommon :nfCheckPeriod:" + e.getMessage() + ":");
throw e;
}
return errCode;
}
public static void CheckValidity() throws Exception
{
//ibase.webitm.ejb.sys.GenValBean gvb= new ibase.webitm.ejb.sys.GenValBean();
//gvb.CheckCredential();
}
}//class
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import ibase.utility.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class SysGenPassword extends ValidatorEJB implements SysGenPasswordLocal , SysGenPasswordRemote // SessionBean
{
/*public void ejbCreate() throws RemoteException, CreateException
{
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
*/
public String preSaveForm()throws RemoteException,ITMException
{
return "";
}
public String preSaveForm(String xmlString1,String domId,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException
{
Document dom = null;
String flag="PRE";
try
{
if (xmlString1 != null && xmlString1.trim().length() > 0)
{
dom = GenericUtility.getInstance().parseString(xmlString1);
executepreSaveForm(xmlString1,domId,objContext,editFlag,xtraParams,flag,conn);
}
}
catch(Exception e)
{
System.out.println("Exception :SysGenPassword ::" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return "";
}
public String postSaveRec(String xmlString1, String domId, String objContext, String editFlag, String xtraParams, Connection conn) throws RemoteException, ITMException
{
Document dom = null;
String saveRec = "",flag="POST";
try
{
if (xmlString1 != null && xmlString1.trim().length() > 0)
{
dom = GenericUtility.getInstance().parseString(xmlString1);
executepreSaveForm(xmlString1,domId,objContext,editFlag,xtraParams,flag,conn);
}
}
catch(Exception e)
{
System.out.println("Exception :WoPostSaveEJB :postSaveRec(): " + e.getMessage()+ ":");
e.printStackTrace();
throw new ITMException(e);
}
return saveRec;
}
private String executepreSaveForm(String xmlString1, String domID,String objContext,String editFlag, String xtraParams,String flag, Connection conn)throws RemoteException,ITMException
{
System.out.println("flag : " + flag);
System.out.println("editFlag : " + editFlag);
GenericUtility genericUtility = GenericUtility.getInstance();
String finalStr = "";
Document dom = null;
StringBuffer valueXmlString = new StringBuffer();
String childNodeValue = null,currentColumn ="";
String columnValue = "",xmlStringComp ="",acctLock ="";
String userId="", errCode = "",resultString = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql ="",formatCode ="",refSer ="",tranIdCol ="",eventContext ="";
String refId ="",objName ="",genPassWord ="",winName ="";
int lineNo =0, k=0;
int ctr=0,currentFormNo =0,childNodeListLength =0,cnt =0;
StringBuffer commInfo = new StringBuffer();
String sendTo ="";
String sendCC ="",acctLockPrev ="";
String userType ="",code ="";
try
{
userId = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
dom = parseString(xmlString1);
objName = "user";
winName = "w_user";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
for(int i=0; i<childNodeList.getLength(); i++)
{
childNode = childNodeList.item(i);
childNodeName = childNode.getNodeName();
if(childNode.getNodeName().equalsIgnoreCase("acct_lock"))
{
if (childNode.getFirstChild() != null)
{
acctLock = childNode.getFirstChild().getNodeValue();
//System.out.println("Node Value1 : " + childNode.getFirstChild().getNodeValue());
}
}
if(childNode.getNodeName().equalsIgnoreCase("user_type"))
{
if (childNode.getFirstChild() != null)
{
userType = childNode.getFirstChild().getNodeValue();
//System.out.println("Node Value1 : " + childNode.getFirstChild().getNodeValue());
}
}
if(childNode.getNodeName().equalsIgnoreCase("code"))
{
if (childNode.getFirstChild() != null)
{
code = childNode.getFirstChild().getNodeValue();
//System.out.println("Node Value1 : " + childNode.getFirstChild().getNodeValue());
}
}
}
sql="select acct_lock from users where code = '"+code+"' ";
//System.out.println("[SysGenPasswordEJB] SQL..................."+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
acctLockPrev = rs.getString("acct_lock");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(("E".equalsIgnoreCase(editFlag.trim()) && "N".equalsIgnoreCase(acctLock.trim()) && "Y".equalsIgnoreCase(acctLockPrev.trim())) || (("A".equalsIgnoreCase(editFlag.trim()) && "POST".equalsIgnoreCase(flag.trim()))))
{
if("A".equalsIgnoreCase(editFlag))
{
eventContext = "new_password";
}
else
{
eventContext = "acct_unlock";
}
sql="SELECT comm_format FROM system_events WHERE obj_name = '"+objName+"' "
+ " and event_context = '"+eventContext+"' ";
//System.out.println("[SysGenPasswordEJB] SQL..................."+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
formatCode = rs.getString("comm_format");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql="SELECT ref_ser, tran_id_col FROM transetup WHERE tran_window = '"+winName+"' ";
//System.out.println("[SysGenPasswordEJB] SQL..................."+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
refSer = rs.getString("ref_ser");
tranIdCol = rs.getString("tran_id_col");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(refSer == null ) refSer =" ";
if(tranIdCol == null ) tranIdCol =" ";
if((refId == null) || refId.trim().length() == 0)
{
refId = "newrefno";
}
PassWordGenerator passWordGenerator = new PassWordGenerator();
genPassWord = passWordGenerator.password(userId);
passWordGenerator = null;
valueXmlString.append("<pass_wd>").append("<![CDATA[" + genPassWord + "]]>").append("</pass_wd>");
commInfo.append("<ROOT><TRANS_INFO>");
commInfo.append("<OBJ_NAME><![CDATA[" + objName + "]]></OBJ_NAME>");
commInfo.append("<REF_SER><![CDATA[" + refSer + "]]></REF_SER>");
commInfo.append("<REF_ID><![CDATA[" + refId + "]]></REF_ID>");
commInfo.append("<LINE_NO><![CDATA[" + lineNo + "]]></LINE_NO>");
commInfo.append("<XSL_FILE_NAME></XSL_FILE_NAME></TRANS_INFO>");
commInfo.append("<MAIL><EMAIL_TYPE>page</EMAIL_TYPE><ENTITY_CODE>BASE</ENTITY_CODE>");
commInfo.append("<ENTITY_TYPE>"+userType+"</ENTITY_TYPE>");
commInfo.append("<TO_ADD>"+sendTo+"</TO_ADD>");
commInfo.append("<CC_ADD>"+sendCC+"</CC_ADD>");
commInfo.append("<FORMAT_CODE>"+formatCode+"</FORMAT_CODE>");
commInfo.append("<ATTACHMENT><BODY></BODY><LOCATION></LOCATION></ATTACHMENT>");
if("E".equalsIgnoreCase(editFlag))
{
xmlStringComp =xmlString1.substring(0,xmlString1.indexOf("<pass_wd>"));
xmlStringComp =xmlStringComp + xmlString1.substring(xmlString1.indexOf("</pass_wd>")+10,xmlString1.indexOf("</Detail1>"));
xmlStringComp = xmlStringComp + valueXmlString.toString() + xmlString1.substring(xmlString1.indexOf("</Detail1>"));
}
else
{
xmlStringComp =xmlString1.substring(0,xmlString1.indexOf("<pass_wd/>"));
xmlStringComp =xmlStringComp + xmlString1.substring(xmlString1.indexOf("<pass_wd/>")+10,xmlString1.indexOf("</Detail1>"));
xmlStringComp = xmlStringComp + valueXmlString.toString() + xmlString1.substring(xmlString1.indexOf("</Detail1>"));
}
//System.out.println("[SysGenPasswordEJB] xmlStringComp..................."+xmlStringComp);
commInfo.append("</MAIL><XML_DATA>"+xmlStringComp+"</XML_DATA>");
commInfo.append("</ROOT>");
//System.out.println("[SysGenPasswordEJB] commInfo..................."+commInfo);
EMail email = new EMail();
email.sendMail(commInfo.toString(), "ITM");
email = null;
if(errCode.trim().length() == 0 || errCode == null )
{
errCode = "<Root><Message>Success</Message></Root>";
sql= "update users set pass_wd ='"+genPassWord+"' where code = '"+code+"' " ;
//System.out.println("[SysGenPasswordEJB] SQL..................."+sql);
pstmt = conn.prepareStatement(sql);
int upd = pstmt.executeUpdate();
if(upd > 0)
{
System.out.println("pass word updated...................");
}
pstmt.close();
pstmt = null;
}
}
}
catch (RemoteException e1) {
e1.printStackTrace();
}
catch (ITMException e1) {
e1.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
return errCode;
}
}
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import java.sql.Connection;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface SysGenPasswordLocal extends ValidatorLocal//, EJBObject
{
public String preSaveForm()throws RemoteException,ITMException;
public String preSaveForm(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
public String postSaveRec(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import ibase.webitm.ejb.*;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import java.sql.Connection;
import ibase.webitm.utility.ITMException;
public interface SysGenPasswordRemote extends ValidatorRemote//, EJBObject
{
public String preSaveForm()throws RemoteException,ITMException;
public String preSaveForm(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
public String postSaveRec(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
}
\ No newline at end of file
package ibase.webitm.ejb.sys;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.lang.*;
import javax.ejb.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import javax.naming.InitialContext;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.utility.CommonConstants;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.TransIDGenerator;
import org.xml.sax.InputSource;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class UserRightsPrc extends ProcessEJB implements UserRightsPrcLocal , UserRightsPrcRemote // SessionBean
{
GenericUtility genericUtility = GenericUtility.getInstance();
CommonConstants commonConstants = new CommonConstants();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
Connection conn = null;
HashMap userRightsMap = null;
HashMap winNameMap = null;
HashMap menuNameMap = null;
String profileId = null;
String processStr = null;
/*public void ejbCreate() throws RemoteException, CreateException
{
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}*/
public String process() throws RemoteException,ITMException
{
return "";
}
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
String rtrStr = "";
Document headerDom = null;
Document detailDom = null;
try
{
System.out.println("xmlString ["+xmlString+"]");
System.out.println("xmlString2 ["+xmlString2+"]");
System.out.println("windowName ["+windowName+"]");
System.out.println("xtraParams ["+xtraParams+"]");
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, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :UserRightsEJB :getData(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
throw new ITMException(e);
}
return rtrStr;
}
public String getData(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer retTabSepStrBuff = new StringBuffer();
String userId = null;
Object date = null;
String sql = "";
String errCode = "";
String errString = "";
String resultString = "";
//String profileId =null;
double quantity = 0.0,pendingQty = 0.0;
int count = 0;
try
{
if(conn == null)
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
}
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"userId");
profileId = genericUtility.getColumnValue("profile_id", headerDom);
System.out.println("profileId ::- "+ profileId);
////////////////
//If profile Id is blank or doesnt exist in the User_Rights table then prompt error
//String profileSql = " select count(*) " +
// " from user_rights " +
// " where profile_id = '" + profileId + "' " ;
String profileSql = " select count(1) " +
" from gencodes " +
" where fld_name = 'PROFILE_ID' and fld_value = '" + profileId + "' " ;
int profileCount = 0;
System.out.println("ProfileSql :: " + profileSql);
PreparedStatement pProfileStmt = null;
ResultSet profileRs = null;
pProfileStmt = conn.prepareStatement(profileSql);
profileRs = pProfileStmt.executeQuery();
if(profileRs.next())
{
profileCount = profileRs.getInt(1);
System.out.println("Profile Count = " + profileCount);
}
profileRs.close();
profileRs = null;
pProfileStmt.close();
pProfileStmt = null;
///////////////
if(profileCount == 0)
{
errString = itmDBAccessEJB.getErrorString("","PNOTEXIST","","",conn);
return errString;
}
}
catch(Exception e)
{
}
userRightsMap = new HashMap();
winNameMap = new HashMap();
menuNameMap = new HashMap();
String sqlStr = " SELECT ITM2MENU.APPLICATION, " +
" ITM2MENU.LEVEL_1, " +
" ITM2MENU.LEVEL_2, " +
" ITM2MENU.LEVEL_3, " +
" ITM2MENU.LEVEL_4, " +
" ITM2MENU.LEVEL_5, " +
" ITM2MENU.WIN_NAME, " +
" ITM2MENU.DESCR, " +
" (SELECT USER_RIGHTS.RIGHTS FROM USER_RIGHTS " +
" WHERE USER_RIGHTS.PROFILE_ID = '" + profileId + "' " +
" AND USER_RIGHTS.APPLICATION = ITM2MENU.APPLICATION " +
" AND USER_RIGHTS.MENU_ROW = ITM2MENU.LEVEL_1 " +
" AND USER_RIGHTS.MENU_COL = ITM2MENU.LEVEL_2 " +
" AND USER_RIGHTS.MENU_SUBCOL = ITM2MENU.LEVEL_3 " +
" AND USER_RIGHTS.LEVEL_4 = ITM2MENU.LEVEL_4 " +
" AND USER_RIGHTS.LEVEL_5 = ITM2MENU.LEVEL_5 " +
" ) AS RIGHTS " +
" FROM ITM2MENU " +
" ORDER BY ITM2MENU.APPLICATION, ITM2MENU.LEVEL_1, ITM2MENU.LEVEL_2, ITM2MENU.LEVEL_3, ITM2MENU.LEVEL_4, ITM2MENU.LEVEL_5 ";
/*
" SELECT ITM2MENU.APPLICATION, "+
" ITM2MENU.LEVEL_1, "+
" ITM2MENU.LEVEL_2, "+
" ITM2MENU.LEVEL_3, "+
" ITM2MENU.LEVEL_4, "+
" ITM2MENU.LEVEL_5, "+
" ITM2MENU.WIN_NAME, "+
" ITM2MENU.DESCR, "+
" USER_RIGHTS.RIGHTS "+
" FROM ITM2MENU "+
" LEFT OUTER JOIN USER_RIGHTS ON "+
" ITM2MENU.APPLICATION = USER_RIGHTS.APPLICATION "+
" AND ITM2MENU.LEVEL_1 = USER_RIGHTS.MENU_ROW "+
" AND ITM2MENU.LEVEL_2 = USER_RIGHTS.MENU_COL "+
" AND ITM2MENU.LEVEL_3 = USER_RIGHTS.MENU_SUBCOL "+
" AND ITM2MENU.LEVEL_4 = USER_RIGHTS.LEVEL_4 "+
" AND ITM2MENU.LEVEL_5 = USER_RIGHTS.LEVEL_5 "+
" WHERE (USER_RIGHTS.PROFILE_ID = '" + profileId + "'" +
" OR USER_RIGHTS.PROFILE_ID is null )" +
" ORDER BY ITM2MENU.APPLICATION, ITM2MENU.LEVEL_1, ITM2MENU.LEVEL_2, ITM2MENU.LEVEL_3 ";
*/
try
{
pstmt = conn.prepareStatement(sqlStr);
System.out.println("The getData sql is:-"+ sqlStr);
rs = pstmt.executeQuery();
while (rs.next())
{
String tApplication = null;
String key = null;
String tWinName = null;
String tMenuName = null;
tApplication = rs.getString(1);
if(tApplication != null)
key = tApplication + ":" + rs.getInt(2) + ":" + rs.getInt(3) + ":" + rs.getInt(4)
+ ":" + rs.getInt(5) + ":" + rs.getInt(6);
//APPLICATION
retTabSepStrBuff.append(tApplication==null?"":rs.getString(1)).append("\t");
//LEVEL_1
retTabSepStrBuff.append(rs.getInt(2)).append("\t");
//LEVEL_2
retTabSepStrBuff.append(rs.getInt(3)).append("\t");
//LEVEL_3
retTabSepStrBuff.append(rs.getInt(4)).append("\t");
//LEVEL_4
retTabSepStrBuff.append(rs.getInt(5)).append("\t");
//LEVEL_5
retTabSepStrBuff.append(rs.getInt(6)).append("\t");
//DESCR
tMenuName = rs.getString(8);
retTabSepStrBuff.append(rs.getString(8)==null?"":rs.getString(8)).append("\t");
//RIGHTS
retTabSepStrBuff.append(rs.getString(9)==null?"":rs.getString(9)).append("\t");
//WIN_NAME
tWinName = rs.getString(7);
retTabSepStrBuff.append(rs.getString(7)==null?"":rs.getString(7)).append("\t");
retTabSepStrBuff.append(" ").append("\t");
retTabSepStrBuff.append("\n");
System.out.println("Key getdata function ["+key+"]");
System.out.println("rights in function ["+ rs.getString(9) +"]");
userRightsMap.put(key, rs.getString(9));
if(tWinName != null && tWinName.trim().length() > 2)
winNameMap.put(key, tWinName.trim().substring(2, tWinName.trim().length()));
menuNameMap.put(key, tMenuName);
}//while
}//try
catch (SQLException e)
{
System.out.println("SQLException ::" + sqlStr + e.getMessage() + ":");
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception []::" + ex.getMessage());
ex.printStackTrace();
}
finally
{
try
{
rs.close();
rs = null;
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
catch(Exception e){}
}
resultString = retTabSepStrBuff.toString();
return resultString;
}//getData()
//process()
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
String retStr = "";
Document detailDom = null;
Document headerDom = null;
System.out.println("xmlString2-->"+ xmlString2);
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
System.out.println("xmlString ["+xmlString+"]");
System.out.println("xmlString2 ["+xmlString2+"]");
System.out.println("windowName ["+windowName+"]");
System.out.println("xtraParams ["+xtraParams+"]");
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, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :UserRightsEJB :process(String xmlString, String xmlString2, String windowName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
processStr = null;
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pInsertStmt = null;
PreparedStatement pUpdateStmt = null;
PreparedStatement pDeleteStmt = null;
Statement stmt = null;
ResultSet rs = null;
java.sql.Timestamp orderDate = new java.sql.Timestamp(System.currentTimeMillis());
java.sql.Timestamp udfDate = null;
ArrayList relArray = new ArrayList();
String returnString = "";
//Declaring fields of the table User_Rights
String profileId = null;
String application = null;
String level1 = null, level2 = null, level3 = null, level4 = null, level5 = null;
String menuName = null;
String rights = null;
String accFilt = null;
String defFilt = null;
String objName = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = "";
boolean bDetailFound = false;
int parentNodeListLength = 0;
int childNodeListLength = 0;
String delSql = "";
profileId = genericUtility.getColumnValue("profile_id", headerDom);
System.out.println("profileId..............."+profileId);
String batchInesertSql = "INSERT INTO USER_RIGHTS ( PROFILE_ID, APPLICATION, MENU_ROW, MENU_COL, MENU_SUBCOL, LEVEL_4, LEVEL_5, MENU_NAME, RIGHTS, OBJ_NAME)"
+ " VALUES ( '" + profileId + "' , ?, ?, ?, ?, ?, ?, ?, ?,? )";
System.out.println("Insert Sql :: " + batchInesertSql);
String batchUpdateSql = "UPDATE USER_RIGHTS SET " +
" RIGHTS = ?, " +
" OBJ_NAME = ? " +
" WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String batchDeleteSql = " DELETE FROM USER_RIGHTS " +
" WHERE PROFILE_ID = '" + profileId + "' " +
" AND APPLICATION = ? " +
" AND MENU_ROW = ? " +
" AND MENU_COL = ? " +
" AND MENU_SUBCOL = ? " +
" AND LEVEL_4 = ? " +
" AND LEVEL_5 = ? ";
String searchKey = null;
int operation = 0;
try
{
if(conn == null)
{
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
pInsertStmt = conn.prepareStatement(batchInesertSql);
pUpdateStmt = conn.prepareStatement(batchUpdateSql);
pDeleteStmt = conn.prepareStatement(batchDeleteSql);
}
parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
System.out.println("ParentNodeListLength....::- "+parentNodeListLength);
for (int selectedRow = 0; selectedRow < parentNodeListLength; selectedRow++)
{
operation = 0;
parentNode = parentNodeList.item(selectedRow);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("ChildNodeListLength.........:-"+ childNodeListLength);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
if (childNodeName.equals("application"))
{
if (childNode.getFirstChild() != null) // ****************
{
application = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("APPLICATION:::::["+ application+"]");
}
}
if (childNodeName.equals("level_1"))
{
if (childNode.getFirstChild() != null) // ****************
{
level1 = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("level1:::::"+ level1);
}
}
if (childNodeName.equals("level_2"))
{
if (childNode.getFirstChild() != null) // ****************
{
level2 = (childNode.getFirstChild().getNodeValue()).trim();
}
System.out.println("level2:::::"+ level2);
}
if (childNodeName.equals("level_3"))
{
if (childNode.getFirstChild() != null) // ****************
{
level3 = (childNode.getFirstChild().getNodeValue()).trim();
}
System.out.println("level3:::::"+ level3);
}
if (childNodeName.equals("level_4"))
{
if (childNode.getFirstChild() != null) // ****************
{
level4 = (childNode.getFirstChild().getNodeValue()).trim();
}
System.out.println("level_4:::::"+ level4);
}
if (childNodeName.equals("level_5"))
{
if (childNode.getFirstChild() != null) // ****************
{
if (childNode.getFirstChild() != null) // ****************
{
level5 = (childNode.getFirstChild().getNodeValue()).trim();
}
}
System.out.println("level_5:::::" + level5);
}
if (childNodeName.equals("descr"))
{
if (childNode.getFirstChild() != null) // ****************
{
menuName = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("menu_name:::"+ menuName);
}
}
if (childNodeName.equals("rights"))
{
if (childNode.getFirstChild() != null) // ****************
{
rights = (childNode.getFirstChild().getNodeValue()).trim();
System.out.println("rights::::"+ rights);
}
else
rights = null;
}
}
searchKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
//
//get all submenu if found
ArrayList subMenuList = null;
subMenuList = getAllSubMenu(application, Integer.parseInt(level1), Integer.parseInt(level2), Integer.parseInt(level3), Integer.parseInt(level4), Integer.parseInt(level5), conn);
System.out.println("SubMenu List :: " + subMenuList.toString());
//
//operation = searchUserRight(searchKey, rights);
if(subMenuList != null)
{
for(int index = 0; index < subMenuList.size(); index++)
{
String searchStr = null;
searchStr = (String)subMenuList.get(index);
objName = "";
objName = (String)winNameMap.get(searchStr);
//Get parameters from searchStr
StringTokenizer subMenuToken = new StringTokenizer(searchStr, ":");
if(subMenuToken.hasMoreTokens())
application = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level1 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level2 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level3 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level4 = subMenuToken.nextToken();
if(subMenuToken.hasMoreTokens())
level5 = subMenuToken.nextToken();
menuName = (String)menuNameMap.get(searchStr);
System.out.println("SerarchStr = " + searchStr + " :: " + application + " : " + level1 + " : " + level2 + " : " + level3 + " : " + level4 + " : " + level5);
//
operation = searchUserRight(searchStr, rights);
System.out.println("Operation ["+ operation +"]");
/*
1 - insert
2 - update
3 - delete
*/
if(operation == 1 && rights.trim().length() > 0){
//pInsertStmt.setString(1, profileId);
pInsertStmt.setString(1, application);
pInsertStmt.setInt(2, Integer.parseInt(level1));
pInsertStmt.setInt(3, Integer.parseInt(level2));
pInsertStmt.setInt(4, Integer.parseInt(level3));
pInsertStmt.setInt(5, Integer.parseInt(level4));
pInsertStmt.setInt(6, Integer.parseInt(level5));
pInsertStmt.setString(7, menuName);
pInsertStmt.setString(8, rights.trim());
pInsertStmt.setString(9, objName);
pInsertStmt.addBatch();
}
else if(operation == 2){
pUpdateStmt.setString(1, rights.trim());
//pUpdateStmt.setString(2, profileId);
pUpdateStmt.setString(2, objName);
pUpdateStmt.setString(3, application);
pUpdateStmt.setInt(4, Integer.parseInt(level1));
pUpdateStmt.setInt(5, Integer.parseInt(level2));
pUpdateStmt.setInt(6, Integer.parseInt(level3));
pUpdateStmt.setInt(7, Integer.parseInt(level4));
pUpdateStmt.setInt(8, Integer.parseInt(level5));
pUpdateStmt.addBatch();
}
else if(operation == 3){
//pDeleteStmt.setString(1, profileId);
pDeleteStmt.setString(1, application);
pDeleteStmt.setInt(2, Integer.parseInt(level1));
pDeleteStmt.setInt(3, Integer.parseInt(level2));
pDeleteStmt.setInt(4, Integer.parseInt(level3));
pDeleteStmt.setInt(5, Integer.parseInt(level4));
pDeleteStmt.setInt(6, Integer.parseInt(level5));
pDeleteStmt.addBatch();
}
}//End of subMenuList iteration for loop
}//End of if subMenuList is not null
}//outer for
System.out.println("Before Delete Batch");
pInsertStmt.executeBatch();
System.out.println("After Insert Batch" );
System.out.println("Before Update Batch");
pUpdateStmt.executeBatch();
System.out.println("After Update Batch = ");
System.out.println("Before Delete Batch");
pDeleteStmt.executeBatch();
System.out.println("After Delete Batch = ");
conn.commit();
System.out.println("After Commit");
}
catch(BatchUpdateException be)
{
be.printStackTrace();
returnString = be.getMessage();
System.out.println("BatchUpdateException :RunMRPPrcEJB: CreatePlanDemand(ADPElement)" + returnString);
System.out.println("Detail Exception : " + be.getNextException());
}
catch (SQLException ex)
{
returnString = ex.getMessage();
try{conn.rollback();
}catch(Exception e){}
ex.printStackTrace();
}
catch (Exception e)
{
returnString = e.getMessage();
try{
conn.rollback();
}catch(Exception ec){}
e.printStackTrace();
}
finally
{
try
{
userRightsMap = null;
winNameMap = null;
menuNameMap = null;
profileId = null;
pInsertStmt.close();
pInsertStmt = null;
pUpdateStmt.close();
pUpdateStmt = null;
pDeleteStmt.close();
pDeleteStmt = null;
conn.close();
conn = null;
}catch(Exception e){}
//return returnString;
}
if (returnString == null || returnString.trim().length() == 0)
{
System.out.println("errString is null************** ");
returnString="VTCOMPL";
returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
return returnString;
}
else
{
System.out.println("errString is not null ***************");
returnString="VTPRCERR";
returnString = itmDBAccessEJB.getErrorString("",returnString,"","",conn);
return returnString;
}
}//process()
/* 1 - insert
2- update
3-delete
Searches HashMap for availability of rights for searchKey
if Not Found and rights is not null then
return 1
else if Found and rights is not null then
return 2
else if Found and rights = null
return 3
*/
int searchUserRight(String searchKey, String rights)
{
System.out.println("searchKey in function ["+searchKey+"]");
System.out.println("rights in function ["+rights+"]");
String foundRights = null;
int operation = -1;
foundRights = (String) userRightsMap.get(searchKey);
System.out.println("Found rights in function ["+foundRights+"]");
if(foundRights == null && rights != null)
operation = 1;
else if(foundRights != null && rights != null)
operation = 2;
else if(foundRights != null && rights == null)
operation = 3;
return operation;
}
private ArrayList getAllSubMenu(String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
throws SQLException
{
String tApplication = null;
int tLevel1 = 0;
int tLevel2 = 0;
int tLevel3 = 0;
int tLevel4 = 0;
int tLevel5 = 0;
String tMenuName = null;
String gotUserRights = null;
String getSubMenuSql = " SELECT APPLICATION, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4, LEVEL_5, WIN_NAME, DESCR FROM ITM2MENU " +
" where APPLICATION = '" + application + "' " +
" and ( " + level1 + " = 0 or " +
" (" + level1 + " <> 0 and (LEVEL_1 = " + level1 + " AND LEVEL_2 > 0))) " +
" and ( " + level2 + " = 0 or " +
" (" + level2 + " <> 0 and (LEVEL_2 = " + level2 + " AND LEVEL_3 > 0))) " +
" and ( " + level3 + " = 0 or " +
" ( " + level3 + " <> 0 and (LEVEL_3 = " + level3 + " AND LEVEL_4 > 0))) " +
" and ( " + level4 + " = 0 or " +
" ( " + level4 + " <> 0 and (LEVEL_4 = " + level4 + " AND LEVEL_5 > 0))) " +
" and WIN_NAME <> '-' " ;
System.out.println("Get All Sub Menu SQL :: " + getSubMenuSql);
String parentKey = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
ArrayList subMenuList = new ArrayList();
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = conn.prepareStatement(getSubMenuSql);
rs = pstmt.executeQuery();
while(rs.next())
{
tApplication = rs.getString(1);
tLevel1 = rs.getInt(2);
tLevel2 = rs.getInt(3);
tLevel3 = rs.getInt(4);
tLevel4 = rs.getInt(5);
tLevel5 = rs.getInt(6);
String tWinName = null;
tWinName = rs.getString(7);
String tKey = null;
tKey = tApplication + ":" + tLevel1 + ":" + tLevel2 + ":" + tLevel3 + ":" + tLevel4 + ":" + tLevel5;
System.out.println("tKey :: " + tKey);
subMenuList.add(tKey);
tMenuName = rs.getString(8);
if(!menuNameMap.containsKey(tKey))
menuNameMap.put(tKey, tMenuName);
winNameMap.put(tKey, tWinName.trim().substring(2, tWinName.trim().length()));
gotUserRights = (String) userRightsMap.get(tKey);
if(gotUserRights == null || gotUserRights.trim().length() == 0){
gotUserRights = getUserRights(profileId, tApplication, tLevel1, tLevel2, tLevel3, tLevel4, tLevel5, conn);
if(gotUserRights != null && gotUserRights.trim().length() > 0)
userRightsMap.put(tKey, gotUserRights);
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(subMenuList.size() == 0)
subMenuList.add(parentKey);
return subMenuList;
}
private String getUserRights(String profileId, String application, int level1, int level2, int level3, int level4, int level5, Connection conn)
throws SQLException
{
String userRightsSql = " select RIGHTS " +
" from user_rights " +
" where profile_id = '" + profileId + "' " +
" and APPLICATION = '" + application + "' " +
" and MENU_ROW = " + level1 +
" and MENU_COL = " + level2 +
" and MENU_SUBCOL = " +level3 +
" and LEVEL_4 = " + level4 +
" and LEVEL_5 = " + level5;
String rights = null;
System.out.println("userRightsSql :: " + userRightsSql);
String key = application + ":" + level1 + ":" + level2 + ":" + level3 + ":" + level4 + ":" + level5;
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = conn.prepareStatement(userRightsSql);
rs = pstmt.executeQuery();
if(rs.next())
{
rights = rs.getString(1);
System.out.println("Key = " + key + " : Rights = " + rights);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
return rights;
}
}//class
package ibase.webitm.ejb.sys;
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 UserRightsPrcLocal extends ibase.webitm.ejb.ProcessLocal//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ProcessRemote;
public interface UserRightsPrcRemote extends ibase.webitm.ejb.ProcessRemote//, EJBObject
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.sys;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
public class UtilMethods {
public UtilMethods(){
}
public static UtilMethods getInstance()
{
return new UtilMethods();
}
public java.sql.Timestamp RelativeDate(java.sql.Timestamp baseDate, int noOfDays)
{
Calendar cal = Calendar.getInstance();
cal.setTime(baseDate);
cal.add(Calendar.DATE, noOfDays);
Date newDate = cal.getTime();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
return java.sql.Timestamp.valueOf(sdt.format(newDate) + " 00:00:00.000");
}
public Date RelativeDate(Date baseDate, int noOfDays)
{
Calendar cal = Calendar.getInstance();
cal.setTime(baseDate);
cal.add(Calendar.DATE, noOfDays);
Date newDate = cal.getTime();
return newDate;
}
public Date AddMonths(Date baseDate, int noOfMonths)
{
Calendar cal = Calendar.getInstance();
cal.setTime(baseDate);
cal.add(Calendar.MONTH, noOfMonths);
java.util.Date newDate = cal.getTime();
return newDate;
}
public java.sql.Timestamp AddMonths(java.sql.Timestamp baseDate, int noOfMonths)
{
Calendar cal = Calendar.getInstance();
cal.setTime(baseDate);
cal.add(Calendar.MONTH, noOfMonths);
java.util.Date newDate = cal.getTime();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
return java.sql.Timestamp.valueOf(sdt.format(newDate) + " 00:00:00.000");
}
public long DaysAfter(java.sql.Timestamp date1, java.sql.Timestamp date2)
{
// 18-04-2007 manoharan to find the elapsed days
// between 2 dates (timestamp).
// Return positive days if first argument date1 is earlier date
// and second argument date2 is a later date
// other wise returns negative days
Calendar calen = Calendar.getInstance();
Calendar calen1 = Calendar.getInstance();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
long totDays = 0;
date1 = java.sql.Timestamp.valueOf(sdt.format(date1) + " 00:00:00.000");
calen.setTime(date1);
date2 = java.sql.Timestamp.valueOf(sdt.format(date2) + " 00:00:00.000");
calen1.setTime(date2);
totDays = (calen.getTime().getTime() - calen1.getTime().getTime()) / (24 * 3600 * 1000);
return totDays;
}
public String getReqDecString(double actVal, int prec)
{
String fmtStr = "############0";
String strValue = null;
if (prec > 0)
{
fmtStr = fmtStr + "." + "000000000".substring(0, prec);
}
DecimalFormat decFormat = new DecimalFormat(fmtStr);
return decFormat.format(actVal);
}
public int MonthsBetween(java.sql.Timestamp date1, java.sql.Timestamp date2)
{
// 18-04-2007 manoharan to find the elapsed months
// between 2 dates (timestamp).
Calendar calen = Calendar.getInstance();
Calendar calen1 = Calendar.getInstance();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
long totDays = 0;
int startMonth = 0, endMonth = 0, startDay = 0;
int totMonths = 0;
java.sql.Timestamp tmpDate = null;
date1 = java.sql.Timestamp.valueOf(sdt.format(date1) + " 00:00:00.000");
date2 = java.sql.Timestamp.valueOf(sdt.format(date2) + " 00:00:00.000");
if (date2.compareTo(date1) < 0)
{
tmpDate = date2;
date2 = date1;
date1 = tmpDate;
}
calen.setTime(date1);
calen1.setTime(date2);
startDay = calen.get(Calendar.DAY_OF_MONTH);
startMonth = calen.get(Calendar.MONTH) + 1;
endMonth = calen1.get(Calendar.MONTH) + 1;
System.out.println("start month before" + startMonth);
if (startDay > 15)
{
startMonth++;
if ( startMonth > 12)
{
startMonth = 1;
}
}
if (startMonth > endMonth)
{
totMonths = 12 - startMonth + 1 + endMonth;
}
else
{
totMonths = endMonth - startMonth + 1;
}
return totMonths ;
}
public double ElapsedTimeHHMM(java.sql.Timestamp date1, java.sql.Timestamp date2)
{
// 19/01/2009 manoharan to find the elapsed time
// between 2 dates (timestamp). in the format hh.mm
// Return positive hours/minutes if first argument date1 is earlier date
// and second argument date2 is a later date
// other wise returns negative hours/minutes
Calendar calen = Calendar.getInstance();
Calendar calen1 = Calendar.getInstance();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd kk:mm");
double totHHMM = 0;
long totalTime = 0,amills = 0, bmills = 0;
java.sql.Timestamp tmpDate;
int multiplier = 1;
if (date2.compareTo(date1) < 0)
{
tmpDate = date2;
date2 = date1;
date1 = tmpDate;
multiplier = -1;
}
date1 = java.sql.Timestamp.valueOf(sdt.format(date1) + ":00.000");
calen.setTime(date1);
date2 = java.sql.Timestamp.valueOf(sdt.format(date2) + ":00.000");
calen1.setTime(date2);
bmills = calen.getTimeInMillis();
amills = calen1.getTimeInMillis();
totalTime = amills - bmills;
//System.out.println("Total Time Spend :: "+totalTime+" Milliseconds");
int totSecs = (int)(((double)1/1000)*(totalTime));
int totalHrs = (int)(totSecs / 3600);
int totlMts = (int)(((totSecs - ( totalHrs * 3600))/ 60));
totSecs = (int) ( totSecs - (( totalHrs * 3600) + (totlMts * 60)) );
//System.out.println("Tot Hours : " + totalHrs);
//System.out.println("tot Minutes : " + totlMts);
totHHMM = (double) Double.parseDouble( Integer.toString(totalHrs).trim() + "." + Integer.toString(totlMts).trim() );
totHHMM = totHHMM * multiplier ;
return totHHMM;
}
}
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