Commit 1c988fc5 authored by sgadve's avatar sgadve

-Convert the Arrears delete form business logic WSR to JB,Adding two component...

-Convert the Arrears delete form business logic WSR to JB,Adding two component ArrearsDeleteIc and ArrearsDeletePrc and respected sql.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@205121 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 85beb241
/**
* Added by saiprasad G. for the validation and itemchange
*/
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.ejb.CommonDBAccessEJB;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
public class ArrearsDeleteIC extends ValidatorEJB
{
E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("Inside the validation");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = "";
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
System.out.println("ErrString :" + errString);
}
catch(Exception e)
{
System.out.println("Exception : ArrearsDeleteIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("Returning from ArrearsDeleteIC wfValData");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
NodeList parentNodeList = null;NodeList childNodeList = null;
Node parentNode = null;Node childNode = null;
String childNodeName = null;
Connection conn = null;
int currentFormNo=0,childNodeListLength ,ctr=0 , columnCtr=0 , cnt=0;
String errCode = "", userId = "" , prdCodeTo = "", prdCodeAcc = "" ,errString ="" , errorType = "";
String prdCodeFr = "";
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
try
{
conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("userId:- " + userId);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
System.out.println("current Form No:"+currentFormNo);
}
switch(currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
int parentNodeListLen = parentNodeList.getLength();
System.out.println("Number of node in parentNodeListLen : "+parentNodeListLen);
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("prd_code__fr"))
{
prdCodeFr = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__fr", dom));
if(E12GenericUtility.checkNull(prdCodeFr).length() <= 0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
columnCtr =getColumnValue("period", "code", prdCodeFr, conn);
if(columnCtr==0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
else if (childNodeName.equalsIgnoreCase("prd_code__to"))
{
prdCodeTo = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__to", dom));
if(E12GenericUtility.checkNull(prdCodeTo).length() <= 0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else if(E12GenericUtility.checkNull(prdCodeTo).length() > 0)
{
columnCtr =getColumnValue("period", "code", prdCodeTo , conn );
int prdCodeFrInt =0,prdCOdeToInt=0;
if(columnCtr==0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
try
{
if(prdCodeFr!=null)
{
prdCodeFrInt = Integer.parseInt(prdCodeFr);
}
if(prdCodeTo!=null)
{
prdCOdeToInt = Integer.parseInt(prdCodeTo);
}
if(prdCodeFrInt > prdCOdeToInt)
{
errCode = "VMPRD2";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
catch(NumberFormatException e)
{
System.out.println(e);
}
}
}
}
else if (childNodeName.equalsIgnoreCase("prd_code__acc"))
{
prdCodeAcc = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__acc", dom));
System.out.println("Period Code From:"+prdCodeAcc);
if(E12GenericUtility.checkNull(prdCodeAcc).length() <= 0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else if(E12GenericUtility.checkNull(prdCodeAcc).length() > 0)
{
columnCtr = getColumnValue("period", "code", prdCodeAcc , conn );
if(columnCtr==0)
{
errCode = "VMPRD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
int errListSize = errList.size();
cnt =0;
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
System.out.println("Inside errList >"+errList);
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String)errList.get(cnt);
System.out.println("errCode :"+errCode);
int pos = errCode.indexOf("~");
System.out.println("pos :"+pos);
if(pos>-1)
{
errCode=errCode.substring(0,pos);
}
System.out.println("error code is :"+errCode);
errFldName = (String)errFields.get(cnt);
System.out.println(" cnt [" + cnt + "] errCode [" + errCode + "] errFldName [" + errFldName + "]");
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
System.out.println("errorType :"+errorType);
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") +
8, errString.indexOf("<trace>"));
bifurErrString = bifurErrString +
errString.substring(errString.indexOf("</trace>") +
8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
if(conn!=null)
{
conn.close();
conn = null;
}
break;
}
}
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
finally
{
try
{
if(conn!=null)
{
conn.close();
conn = null;
}
}catch(Exception e)
{
System.out.println("Excpetion closing"+e);
}
}
System.out.println("ErrString ::[ "+errStringXml.toString()+" ]");
return errStringXml.toString();
}
public String itemChanged(String xmlString, String xmlStringHdr, String xmlStringAll, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null, domHdr = null, domAll = null;
String valueXmlString = "";
try {
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlStringHdr != null && xmlStringHdr.trim().length() > 0)
{
domHdr = genericUtility.parseString(xmlStringHdr);
}
if (xmlStringAll != null && xmlStringAll.trim().length() > 0)
{
domAll = genericUtility.parseString(xmlStringAll);
}
valueXmlString = itemChanged(dom, domHdr, domAll, objContext, currentColumn, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception [" + this.getClass().getSimpleName() + "] : [itemChanged(S)] " + e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
System.out.println("itemchanged on the ArrearsDelete");
String loginEmpCode = "",loginSiteCode="";
int currentFormNo = 0;
StringBuffer valueXmlString = new StringBuffer();
try
{
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
loginEmpCode = getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
loginSiteCode = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
System.out.println("currentColumn:::::" + currentColumn);
valueXmlString = new StringBuffer("<?xml version=\"1.0\" encoding=''?>\r\n<Root>\r\n<header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</header>\r\n");
switch (currentFormNo)
{
case 1:
{
valueXmlString.append("<Detail1>\r\n");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
valueXmlString.append( "<site_code__fr><![CDATA[" ).append(loginSiteCode).append( "]]></site_code__fr>\r\n" );
valueXmlString.append( "<site_code__to><![CDATA[" ).append(loginSiteCode).append( "]]></site_code__to>\r\n" );
}
valueXmlString.append("</Detail1>\r\n");
}
valueXmlString.append("</Root>\r\n");
}
}
catch (Exception e)
{
System.out.println("Exception in EJB["+this.getClass().getSimpleName()+"]:[" + e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("Itemchange ::==== ["+valueXmlString.toString()+"]");
return valueXmlString.toString();
}
private String errorType(Connection conn, String errorCode) throws ITMException
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
if (rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return msgType;
}
public int getColumnValue(String tableName ,String columnName , String columnValue , Connection con)
{
String sql = "";
int count=0;
PreparedStatement pStmt = null;
ResultSet rs = null;
try
{
sql ="select count(*) from "+tableName+" where "+columnName+"="+"'"+columnValue+"'";
pStmt = con.prepareStatement(sql);
rs =pStmt.executeQuery();
while(rs.next())
{
count =rs.getInt(1);
System.out.println("Gettting the data:"+count);
}
if(rs!=null)
{
rs.close();
rs=null;
}
if(pStmt!=null)
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{
System.out.println("Exception in getColumnValue"+e);
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if(pStmt!=null)
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{
System.out.println("Exception e"+e);
}
}
return count;
}
}
/**
* Added by saiprasad G.
* For process the data migrate from WSR to JB
*/
package ibase.webitm.ejb.adm.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.w3c.dom.Document;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
public class ArrearsDeletePrc extends ProcessEJB
{
E12GenericUtility genericUtility=new E12GenericUtility();
public String process(String xmlString,String xmlString1,String objContext,String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null;
Document headerDom = null;
String retStr = "";
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom" + xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString1);
System.out.println("detailDom" + xmlString1);
}
retStr = process(headerDom, detailDom, objContext, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception:ArrearsDeletePrc:process"+e);
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String objContext, String xtraParams)throws RemoteException, ITMException
{
String retStr="";
Connection con=null;
try
{
if(con==null)
{
con = getConnection();
con.setAutoCommit(false);
}
retStr=processData(headerDom, detailDom, objContext, xtraParams, con);
}
catch(Exception e)
{
System.out.println("Exception e1"+e);
}
finally
{
try
{
con.close();
con=null;
}
catch(Exception e)
{
System.out.println("Exception e1"+e);
}
}
return retStr;
}
public String processData(Document headerDom , Document detailDom,String objContext ,String xtraParams , Connection con )
{
String prdCodeAcct = "", prdCodeFr = "",prdCodeTo="" ,empCodeFr="",empCodeTo ="";
String siteCodeFr = "", siteCodeTo = "", prcGrpFr = "", prcGrpTo = "";
String prdCode = "",empCode="",siteCodePay="",prcGrp="",prdAccountCode="" , errorString = "";
PreparedStatement pStmt = null;
ResultSet rs = null;
int count;
String userId ="";
boolean isSuccess = false;
StringBuilder sql = new StringBuilder();
try
{
userId=genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("userId:- " + userId);
empCodeFr = E12GenericUtility.checkNull(genericUtility.getColumnValue("emp_code__fr", headerDom));
empCodeTo = E12GenericUtility.checkNull(genericUtility.getColumnValue("emp_code__to", headerDom));
siteCodeFr = E12GenericUtility.checkNull(genericUtility.getColumnValue("site_code__fr", headerDom));
siteCodeTo = E12GenericUtility.checkNull(genericUtility.getColumnValue("site_code__to", headerDom));
prdCodeFr = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__fr", headerDom));
prdCodeTo = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__to", headerDom));
prcGrpFr = E12GenericUtility.checkNull(genericUtility.getColumnValue("proc_group__fr", headerDom));
prcGrpTo = E12GenericUtility.checkNull(genericUtility.getColumnValue("proc_group__to", headerDom));
prdCodeAcct = E12GenericUtility.checkNull(genericUtility.getColumnValue("prd_code__acc", headerDom));
if(empCodeFr.length() <= 0)
{
empCodeFr = "0000";
}
if(empCodeTo.length() <= 0)
{
empCodeTo = "ZZZ";
}
if(siteCodeFr.length() <= 0)
{
siteCodeFr = "000";
}
if(siteCodeTo.length() <= 0)
{
siteCodeTo = "ZZZ";
}
if(prcGrpFr.length() <= 0)
{
prcGrpFr = "000";
}
if(prcGrpTo.length() <= 0)
{
prcGrpTo = "ZZZ";
}
sql.append("SELECT ARREARS.PRD_CODE,ARREARS.EMP_CODE,ARREARS.SITE_CODE__PAY,EMPLOYEE.PROC_GROUP,ARREARS.PRD_CODE__ACC FROM ARREARS,EMPLOYEE");
sql.append(" WHERE ( ARREARS.EMP_CODE = EMPLOYEE.EMP_CODE ) AND ( ( ARREARS.PRD_CODE >= ? ) ");
sql.append(" AND ( ARREARS.PRD_CODE <= ? ) AND ( ARREARS.EMP_CODE >= ? ) AND");
sql.append("(ARREARS.EMP_CODE <= ?) AND ( ARREARS.SITE_CODE__PAY >= ?) AND (ARREARS.SITE_CODE__PAY <= ?) AND (EMPLOYEE.PROC_GROUP >= ?) AND ");
sql.append("( EMPLOYEE.PROC_GROUP <= ?) AND ( ARREARS.PRD_CODE__ACC = ? ) AND ( ARREARS.VOUCHER_NO IS NULL ))");
pStmt = con.prepareStatement(sql.toString());
pStmt.setString(1, prdCodeFr);
pStmt.setString(2, prdCodeTo);
pStmt.setString(3, empCodeFr);
pStmt.setString(4, empCodeTo);
pStmt.setString(5, siteCodeFr);
pStmt.setString(6, siteCodeTo);
pStmt.setString(7, prcGrpFr);
pStmt.setString(8, prcGrpTo);
pStmt.setString(9, prdCodeAcct);
rs = pStmt.executeQuery();
while(rs.next())
{
prdCode = rs.getString("PRD_CODE");
empCode = rs.getString("EMP_CODE");
siteCodePay = rs.getString("SITE_CODE__PAY");
prcGrp = rs.getString("PROC_GROUP");
//prdAccountCode = rs.getString("PRD_CODE__ACC");
System.out.println("###Sai:"+prdCode+"\t"+empCode+"\t"+siteCodePay+"\t"+prcGrp+"\t"+prdAccountCode);
String deleteSql="DELETE FROM ARREARS WHERE PRD_CODE=? AND EMP_CODE=? AND PRD_CODE__ACC=?";
PreparedStatement pStmt1 = con.prepareStatement(deleteSql);
pStmt1.setString(1, prdCode);
pStmt1.setString(2, empCode);
pStmt1.setString(3, prdCodeAcct);
count= pStmt1.executeUpdate();
System.out.println("Data deleted:"+count);
if(count>0)
{
isSuccess = true;
con.commit();
}
else
{
con.rollback();
}
if(pStmt1!=null)
{
pStmt1.close();
pStmt1 = null;
}
}
if(rs!=null)
{
rs.close();
rs= null;
}
if(pStmt!=null)
{
pStmt.close();
pStmt = null;
}
if(isSuccess)
{
errorString = genericUtility.getErrorString("", "PROCSUCC", userId);
}
}
catch(Exception e)
{
System.out.println("Exception in processData1:"+e);
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(pStmt!=null)
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{
System.out.println("Excption in processData2:"+e);
}
}
return errorString;
}
}
----------Arrear deletion [START]-------------------------------------------------------------
update system_events set comp_name='ibase.webitm.ejb.adm.ArrearsDeleteIC',comp_type='JB' where obj_name='arrears_deletion'and event_code='post_item_change';
update system_events set service_code='poic_default_ejb' where obj_name='arrears_deletion' and event_code='post_item_change';
update system_events set comp_name='ibase.webitm.ejb.adm.ArrearsDeleteIC',comp_type='JB' , service_code='prv_default_ejb' where obj_name='arrears_deletion'and event_code='pre_validate';
Insert into SYSTEM_EVENT_SERVICES (SERVICE_CODE,SERVICE_DESCR,SERVICE_URI,SERVICE_PROVIDER,METHOD_NAME,RETURN_VALUE,RETURN_TYPE,RETURN_DESCR,RETURN_XFRM,CHG_DATE,CHG_USER,CHG_TERM,SERVICE_NAMESPACE,RES_ELEM,SOAP_ACTION) values ('prc_default_ejb','Action To process','http://localhost:9090/axis/services/ProcessService','Base Information','process','String','S',null,null,sysdate,'BASE','BASE',null,null,null);
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',1,'COMPONENT_TYPE','I','Component Type','S',null,sysdate,'BASE','BASE','JB');
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',2,'COMPONENT_NAME','I','Component Name','S',null,sysdate,'BASE','BASE','');
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',3,'XML_DATA_1','I','XML data of form no 1','S',null,sysdate,'BASE','BASE',null);
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',4,'XML_DATA__ALL','I','XML data of form no 1','S',null,sysdate,'BASE','BASE',null);
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',5,'OBJ_CONTEXT','I','Object Context','S',null,sysdate,'BASE','BASE','');
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_default_ejb',6,'XTRA_PARAMS','I','Extra Arguments','S',null,sysdate,'BASE','BASE',null);
update system_events set service_code='prc_default_ejb' where obj_name='arrears_deletion' and event_code='process';
update system_events set comp_name='ibase.webitm.ejb.adm.adv.ArrearsDeletePrc',comp_type='JB' where service_code='prc_default_ejb' and obj_name='arrears_deletion';
----------Arrear deletion [END]---------------------------------------------------------
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