Commit 68e9bc59 authored by agaikwad's avatar agaikwad

Request_id-F15GWIN001

New Scheduler BankPIF Process


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@99185 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 0715a247
package ibase.webitm.ejb.fin.adv;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.fin.BankReconPrcLocal;
import ibase.webitm.ejb.fin.BankReconPrcRemote;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Properties;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@SuppressWarnings( { "unused" })
public class BankPiFprc implements Schedule // extends ProcessEJB implements
// BankPiFprcLocal,BankPiFprcRemote{
{
E12GenericUtility genericUtility = new E12GenericUtility();
FileOutputStream fos1 = null;
public String schedule(String scheduleParamXML) throws Exception,
ITMException {
ibase.utility.UserInfoBean userInfo = null;
String loginSiteCode = "", siteCode = "";
try {
Document dom = null;
String xtraParams = "", siteList = "";
int childNodeListLength = 0;
String childNodeName = null;
String voucher_date = "", sysDate = "";
String xmlString = "", xmlString2 = "", winName = "w_bankpif";
NodeList parentNodeList = null, childNodeList = null;
Node parentNode = null, childNode = null;
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility
.getDBDateFormat());
Node currDetail = null;
int noOfParam = 0;
System.out
.println("scheduleParamXML>>>>[" + scheduleParamXML + "]");
userInfo = new ibase.utility.UserInfoBean(scheduleParamXML);
loginSiteCode = userInfo.getSiteCode();
System.out.println("Log in Site code>>>>" + loginSiteCode + "]");
xtraParams = "loginEmpCode=" + userInfo.getEmpCode()
+ "~~loginCode=" + userInfo.getLoginCode() + "~~termId="
+ userInfo.getRemoteHost() + "~~loginSiteCode="
+ loginSiteCode;
dom = genericUtility.parseString(scheduleParamXML);
NodeList paramList = dom.getElementsByTagName("SCHEDULE");
noOfParam = paramList.getLength();
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println(" CshildNodeListLength >>>>:-["
+ childNodeListLength + "]");
process(xmlString, xmlString2, winName, xtraParams);
} catch (Exception e) {
System.out
.println("Exception :BankPiFprc :schedule :Exception :==>\n"
+ e.getMessage());
e.printStackTrace();
throw new ITMException(e);
} finally {
try {
if (fos1 != null) {
fos1.close();
fos1 = null;
}
} catch (Exception e) {
System.out.println("Exception >>>." + e.getMessage());
}
}
return "";
}
/*
* public String process() throws RemoteException,ITMException { return "";
* }
*/
// process()
public String process(String xmlString, String xmlString2,
String windowName, String xtraParams) throws RemoteException,
ITMException {
System.out.println("xmlString:::::::::::" + xmlString);
System.out.println("xmlString:::::::::::" + xmlString2);
String xtraParam = "";
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 :BankReconPrcEJB :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 {
System.out.println("@@@@@@@@@@@@@@@@@@@@ inside BankPifRtgsprc@@@@@@@@@@@@@@@");
Connection conn = null;
GenericUtility genericUtility = GenericUtility.getInstance();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
String activity_code = "", activity_descr = "", combocode = "", combodescr = "", floor = "", floor_descr = "", configunit = "", configunit_descr = "";
ConnDriver connDriver = null;
String tranId = "", userId = "", loginEmpCode = "", chgTerm = "";
String errString = "";
String errCode = "";
ValidatorEJB validatorEJB = null;
ITMDBAccessEJB itmDBAccessEJB = null;
boolean isError = false;
double tempAMt = 0;
double totAmt1 = 0;
String orgAmt = "";
DistCommon disCommon = null;
String forcedFlag = "";
ReceiptAdvConf Conf = null;
File csvFile = null;
File destFile = null;
File filePath=null;
itmDBAccessEJB = new ITMDBAccessEJB();
validatorEJB = new ValidatorEJB();
connDriver = new ConnDriver();
String confirm = "";
ArrayList al = new ArrayList();
String row;
String fileName;
int sheetNo = 0;
int cnt = 0;
int successcnt =0;
double Value=0;
Conf = new ReceiptAdvConf();
String InsNo = "";
String totAmt = "";
String batchNo = "";
String totalAmt = "";
PreparedStatement psmt = null;
Document dom1 = null;
String xmlParseStr = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String description="",shDescr="",message="",Error="", fileName1 ="";
int parentNodeListLength=0;
int detField1=0;
String retString="";
try {
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
conn.setAutoCommit(false);
filePath = new File(CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default" + File.separator+"deploy"+File.separator+"updatexls");//String to file
System.out.println(":::::::file Path" + filePath);
File[] files = filePath.listFiles();
for(File file : files)
{
if(file.isFile())
{
fileName1 = file.getName();
if(fileName1.endsWith(".xls") || fileName1.endsWith(".XLS"))//xls
{
System.out.println("FileName:::"+fileName1);
al = readExcelFile(file.getAbsolutePath(), sheetNo);
System.out.println("call read excel File" + al.size());
File Writefile = new File( CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default"+ File.separator+"deploy"+File.separator+"updatexls"+File.separator+"Bank.txt");
if(Writefile.createNewFile())
{
System.out.println(Writefile+" File Created");
}else
System.out.println("File "+Writefile+" already exists");
FileWriter fw = new FileWriter(Writefile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
for (int i = 1; i < al.size(); i++)
{
row = al.get(i).toString();
row = row.replace("[", "");
row = row.replace("]", "");
String col[] = row.split(",");
batchNo = col[2].trim();
InsNo = col[11].trim();
totAmt = col[13].trim();
System.out.println("Batch Number is " + batchNo);
if(batchNo.contains("."))
{
Value= Double.parseDouble(batchNo);
batchNo = BigDecimal.valueOf(Value).toPlainString();
System.out.println("Batch Number is"+batchNo);
}
System.out.println("Total Amount is" + totAmt);
System.out.println("Instrument Number is" + InsNo);
int Amt = Integer.parseInt(totAmt.substring(totAmt.indexOf(".") + 1, totAmt.length()));
System.out.println("Amt" + Amt);
if (!(Amt > 0))
{
totAmt = totAmt.substring(0, totAmt.indexOf("."));
}
System.out.println("Amt" + totAmt);
totAmt = totAmt != null && totAmt.trim().length() > 0 ? totAmt.trim() : "0";
totalAmt = getReqDecimal(totAmt);
System.out.println("Total AMount:"+totalAmt);
if(InsNo.contains("."))
{
int insNO = Integer.parseInt(InsNo.substring(InsNo.indexOf(".") + 1, InsNo.length()));
System.out.println("Instrument" + insNO);
if (!(insNO > 0))
{
InsNo = InsNo.substring(0, InsNo.indexOf("."));
}
}
System.out.println("Instrument Number" + InsNo);
sql = "select count(1) from receipt where ref_no = ? and net_amt= ? and entry_batch_no = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, InsNo);
pstmt.setString(2, totalAmt);
pstmt.setString(3, batchNo);
rs = pstmt.executeQuery();
if (rs.next()) {
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (cnt > 0)
{
System.out.println("@@ Count>0");
sql = "select tran_id,confirmed from receipt where ref_no = ? and net_amt=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, InsNo);
pstmt.setString(2, totalAmt);
rs = pstmt.executeQuery();
if (rs.next())
{
tranId = rs.getString(1);
confirm = rs.getString("confirmed") == null ? "N" : rs.getString("confirmed");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (confirm != null && confirm.equalsIgnoreCase("N"))
{
errString = Conf.confirm(tranId, xtraParams, forcedFlag);
if (errString == null || errString.trim().length() == 0)
{
System.out.println("Enter confirm COndition");
System.out.println("The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is Sucessfully Confirmed");
String content = "The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is Sucessfully Confirmed";
bw.write(content);
bw.newLine();
System.out.println("Write confirmed");
successcnt++;
System.out.println("Sucess Count Y is:"+successcnt);
}
else
{
dom1 = parseString(errString);
System.out.println("dom1>>>>>: "+dom1);
parentNodeList = dom1.getElementsByTagName("error");
parentNodeListLength = parentNodeList.getLength();
for (int lineCount = 0; lineCount < parentNodeListLength; lineCount++)
{
parentNode = parentNodeList.item(lineCount);
childNodeList = parentNode.getChildNodes();
for (detField1 = 0; detField1 < childNodeList.getLength(); detField1++)
{
childNode = childNodeList.item(detField1);
if ( childNode != null && childNode.getFirstChild() != null &&
childNode.getNodeName().equalsIgnoreCase("message") )
{
message = (childNode.getFirstChild().getNodeValue().trim());
System.out.println(">>>message : "+message);
}
else if ( childNode != null && childNode.getFirstChild() != null &&
childNode.getNodeName().equalsIgnoreCase("description") )
{
description = (childNode.getFirstChild().getNodeValue().trim());
System.out.println(">>>Description : "+description);
}
}
retString=""+message+":"+description+"";
System.out.println("After Parsing Return String>>>>"+retString);
}
System.out.println("The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + ":"+retString + " is Unconfirmed");
String content = "The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo +" :"+retString + " is Unconfirmed";
bw.write(content);
System.out.println("Write Unconfirmed");
bw.newLine();
}
}
else
{
System.out.println("Enter in else Already confirm COndition");
System.out.println("The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is Already Sucessfully Confirmed");
String content = "The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is Already Sucessfully Confirmed";
bw.write(content);
bw.newLine();
System.out.println("Write Already confirmed");
successcnt++;
System.out.println("Sucess COunt Y is:"+successcnt);
}
System.out.println("Complete Process");
}
else
{
System.out.println("The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is not Present in Statement");
String content = "The Record of Receipt tran_id : "+ tranId + " and Reference Number : " + InsNo + " and Amount : " + totalAmt + " and Slip Number : " + batchNo + " is not Present in Statement";
bw.write(content);
bw.newLine();
System.out.println("Write Already confirmed");
}
}
bw.close();
fw.close();
System.out.println("List size is"+al.size());
System.out.println("Counter size is"+successcnt);
if(al.size() - 1 == successcnt)
{
destFile = new File( CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default"
+ File.separator+"deploy"+File.separator+"BankStatement");
boolean success = csvFile.renameTo(new File(destFile, csvFile.getName()));
if (success) {
System.out.println("File was successfully moved.\n");
} else {
System.out.println("File was not successfully moved.\n");
}
}
}
}
}
} catch (Exception e) {
System.out.println("Exception: confirm method ..> "
+ e.getMessage());
isError = true;
errCode = "VTTRNNCNF"; // exception so cannot confirm
errString = itmDBAccessEJB.getErrorString("", errCode, userId);
throw new ITMException(e);
} finally {
if (conn != null) {
try {
if (isError) {
conn.rollback();
System.out.println("confirm: Connection Rollback");
} else {
conn.commit();
System.out.println("confirm: Connection Commit");
}
conn.close();
conn = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
return errString;
}
private static Document parseString(String xsdString)throws Exception
{
Document dom = null;
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
OutputStreamWriter errorWriter = new OutputStreamWriter(System.err, "UTF-8");
ByteArrayInputStream baos = new ByteArrayInputStream(xsdString.getBytes());
dom = db.parse(baos);
}
catch (Exception e)
{
System.out.println("Error :" +e);
}
return dom;
}
public ArrayList readExcelFile(String fileName, int sheetNo) {
System.out.println("----in readExcelFile1 method CNT..................");
String value = null;
int headerRowCnt = -1, detailRowCnt = -1;
ArrayList cellArrayLisstHolder = new ArrayList();
try {
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(sheetNo);
Sheet sheet = myWorkBook.getSheetAt(sheetNo);
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() != Cell.CELL_TYPE_BLANK) {
if (cell.getCellType() != Cell.CELL_TYPE_STRING
|| cell.getStringCellValue().length() > 0) {
if (sheetNo == 1)
headerRowCnt++;
else if (sheetNo == 2)
detailRowCnt++;
break;
}
}
}
}
for (Row row : mySheet) {
ArrayList cellStoreArrayList = new ArrayList();
for (int cn = 0; cn < row.getLastCellNum(); cn++) {
Cell cell = row.getCell(cn, Row.CREATE_NULL_AS_BLANK);
value = cell.toString();
if (value.contains(",")) {
value = value.replace(",", "");
}
cellStoreArrayList.add(value);
}
cellArrayLisstHolder.add(cellStoreArrayList);
}
} catch (Exception e) {
e.printStackTrace();
}
return cellArrayLisstHolder;
}
public String getReqDecimal(String chqAmt)
{
DecimalFormat df = new DecimalFormat("000000");
int num= Integer.parseInt(chqAmt);
String refAmt = df.format(num);
System.out.println("@@@@@"+refAmt);
return refAmt;
}
@Override
public String schedule(HashMap arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
package ibase.webitm.ejb.fin.adv;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.fin.BankReconPrcLocal;
import ibase.webitm.ejb.fin.BankReconPrcRemote;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Properties;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@SuppressWarnings( { "unused" })
public class BankPifRtgsprc implements Schedule // extends ProcessEJB implements
// BankPiFprcLocal,BankPiFprcRemote{
{
E12GenericUtility genericUtility = new E12GenericUtility();
FileOutputStream fos1 = null;
public String schedule(String scheduleParamXML) throws Exception,
ITMException {
ibase.utility.UserInfoBean userInfo = null;
String loginSiteCode = "", siteCode = "";
try {
Document dom = null;
String xtraParams = "", siteList = "";
int childNodeListLength = 0;
String childNodeName = null;
String voucher_date = "", sysDate = "";
String xmlString = "", xmlString2 = "", winName = "w_bankpif";
NodeList parentNodeList = null, childNodeList = null;
Node parentNode = null, childNode = null;
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility
.getDBDateFormat());
Node currDetail = null;
int noOfParam = 0;
System.out
.println("scheduleParamXML>>>>[" + scheduleParamXML + "]");
userInfo = new ibase.utility.UserInfoBean(scheduleParamXML);
loginSiteCode = userInfo.getSiteCode();
// System.out.println("@V@ IntializingLog "+
// intializingLog("Chnl_Ptr_VouchConf_log"));
System.out.println("Log in Site code>>>>" + loginSiteCode + "]");
xtraParams = "loginEmpCode=" + userInfo.getEmpCode()+ "~~loginCode=" + userInfo.getLoginCode() + "~~termId="
+ userInfo.getRemoteHost() + "~~loginSiteCode="
+ loginSiteCode;
dom = genericUtility.parseString(scheduleParamXML);
NodeList paramList = dom.getElementsByTagName("SCHEDULE");
noOfParam = paramList.getLength();
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println(" CshildNodeListLength >>>>:-["
+ childNodeListLength + "]");
processRtgs(xmlString, xmlString2, winName, xtraParams);
} catch (Exception e) {
System.out
.println("Exception :BankPiFprc :schedule :Exception :==>\n"
+ e.getMessage());
e.printStackTrace();
throw new ITMException(e);
} finally {
try {
if (fos1 != null) {
fos1.close();
fos1 = null;
}
} catch (Exception e) {
System.out.println("Exception >>>." + e.getMessage());
}
}
return "";
}
/*
* public String process() throws RemoteException,ITMException { return "";
* }
*/
// process()
public String processRtgs(String xmlString, String xmlString2,
String windowName, String xtraParams) throws RemoteException,
ITMException {
System.out.println("xmlString:::::::::::" + xmlString);
System.out.println("xmlString:::::::::::" + xmlString2);
String xtraParam = "";
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 :BankPifRtgsprc :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 {
System.out.println("@@@@@@@@@@@@@@@@@@@@ inside BankPifRtgsprc@@@@@@@@@@@@@@@");
Connection conn = null;
GenericUtility genericUtility = GenericUtility.getInstance();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
ConnDriver connDriver = null;
String tranId = "", userId = "", loginEmpCode = "", chgTerm = "";
String errString = "";
String errCode = "";
ValidatorEJB validatorEJB = null;
ITMDBAccessEJB itmDBAccessEJB = null;
boolean isError = false;
double tempAMt = 0;
double totAmt1 = 0;
double InsNo1 = 0;
String orgAmt = "";
DistCommon disCommon = null;
String forcedFlag = "";
ReceiptAdvConf Conf = null;
File csvFile = null;
File destFile = null;
File file=null;
itmDBAccessEJB = new ITMDBAccessEJB();
validatorEJB = new ValidatorEJB();
connDriver = new ConnDriver();
String confirm = "";
ArrayList al = new ArrayList();
String row;
String fileName;
int sheetNo = 0;
int cnt = 0;
int successcnt = 0;
Conf = new ReceiptAdvConf();
String refdate = "";
String refno = "";
String custcode = "";
String totAmt = "";
PreparedStatement psmt = null;
Document dom1 = null;
String xmlParseStr = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String description = "", shDescr = "", message = "", Error = "";
int parentNodeListLength = 0;
int detField1 = 0;
try {
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
conn.setAutoCommit(false);
csvFile = new File( CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default"
+ File.separator+"deploy"+File.separator+"updatexls"+File.separator+"RtgsAttachment.xls");
System.out.println(":::::::file Path" + csvFile);
al = readExcelFile(csvFile, sheetNo);
System.out.println("call read excel File" + al.size());
//File file = new File("/home/base/tmp/Rtgs.txt");
file = new File( CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default"
+ File.separator+"deploy"+File.separator+"updatexls"+File.separator+"Rtgs.txt");
if(file.createNewFile())
{
System.out.println(file+" File Created");
}else
System.out.println("File "+file+" already exists");
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
String retString = "";
for (int i = 1; i < al.size(); i++)
{
row = al.get(i).toString();
row = row.replace("[", "");
row = row.replace("]", "");
String col[] = row.split(",");
// cust_code,ref_no,ref_date,net_amt
custcode = col[2].trim();
refno = col[6].trim();
refdate = col[7].trim();
totAmt = col[8].trim();
int Amt = Integer.parseInt(totAmt.substring(totAmt.indexOf(".") + 1, totAmt.length()));
System.out.println("Amt" + Amt);
if (!(Amt > 0)) {
totAmt = totAmt.substring(0, totAmt.indexOf("."));
}
System.out.println("Amount" + totAmt);
// cust_code,ref_date,ref_no,chq_amt
sql = "select count(1) from receipt where cust_code = ? and ref_no=? and ref_date = ? and chq_amt =? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custcode);
pstmt.setString(2, refno);
pstmt.setString(3, refdate);
pstmt.setString(4, totAmt);
rs = pstmt.executeQuery();
if (rs.next()) {
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (cnt > 0)
{
System.out.println("@@ Count>0");
sql = "select tran_id,confirmed from receipt where cust_code = ? and ref_no=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custcode);
pstmt.setString(2, refno);
rs = pstmt.executeQuery();
if (rs.next()) {
tranId = rs.getString(1);
confirm = rs.getString("confirmed") == null ? "N" : rs.getString("confirmed");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (confirm != null && confirm.equalsIgnoreCase("N"))
{
errString = Conf.confirm(tranId, xtraParams, forcedFlag);
if (errString == null || errString.trim().length() == 0)
{
System.out.println("Enter confirm COndition");
System.out.println("The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is Sucessfully Confirmed");
String content = "The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is Sucessfully Confirmed";
bw.write(content);
bw.newLine();
System.out.println("Write confirmed");
successcnt++;
System.out.println("Sucess Count Y is:"+ successcnt);
} else
{
dom1 = parseString(errString);
System.out.println("dom1>>>>>: " + dom1);
parentNodeList = dom1.getElementsByTagName("error");
parentNodeListLength = parentNodeList.getLength();
for (int lineCount = 0; lineCount < parentNodeListLength; lineCount++)
{
parentNode = parentNodeList.item(lineCount);
childNodeList = parentNode.getChildNodes();
for (detField1 = 0; detField1 < childNodeList.getLength(); detField1++)
{
childNode = childNodeList.item(detField1);
if (childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("message"))
{
message = (childNode.getFirstChild().getNodeValue().trim());
System.out.println(">>>message : "+ message);
}
else if (childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("description"))
{
description = (childNode.getFirstChild().getNodeValue().trim());
System.out.println(">>>Description : "+ description);
}
}
retString = "" + message + ":" + description + "";
System.out.println("After Parsing Return String>>>>"+ retString);
}
System.out.println("The Record of tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + ":" + retString + " is Unconfirmed");
String content = "The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + ":"+ retString +" is Unconfirmed";
bw.write(content);
System.out.println("Write Unconfirmed");
bw.newLine();
}
}
else
{
System.out.println("Enter in else Already confirm COndition");
System.out.println("The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is Already Sucessfully Confirmed");
String content = "The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is Already Sucessfully Confirmed";
bw.write(content);
bw.newLine();
System.out.println("Write Already confirmed");
successcnt++;
System.out.println("Sucess COunt Y is:" + successcnt);
}
System.out.println("Complete Process");
} else {
System.out.println("The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is not Present in Statement");
String content = "The Record of Receipt tran_id : "+ tranId+"Customer Code :"+ custcode+ " and Reference Number : " + refno + " and Reference Date : : " + refdate + " and Cheque Amount : " + totAmt + " is not Present in Statement";
bw.write(content);
bw.newLine();
System.out.println("Write Already confirmed");
}
}
bw.close();
fw.close();
System.out.println("List size is" + al.size());
System.out.println("Counter size is" + successcnt);
if (al.size()-1 == successcnt)
{
System.out.println("In List size is" + al.size());
destFile = new File( CommonConstants.JBOSSHOME + File.separator+"server"+File.separator+"default"
+ File.separator+"deploy"+File.separator+"RtgsStatement");
boolean success = csvFile.renameTo(new File(destFile, csvFile.getName()));
if (success)
{
System.out.println("File was successfully moved.\n");
} else
{
System.out.println("File was not successfully moved.\n");
}
}
} catch (Exception e)
{
System.out.println("Exception: confirm method ..> "+ e.getMessage());
isError = true;
errCode = "VTTRNNCNF"; // exception so cannot confirm
errString = itmDBAccessEJB.getErrorString("", errCode, userId);
throw new ITMException(e);
}
finally
{
if (conn != null)
{
try {
if (isError)
{
conn.rollback();
System.out.println("confirm: Connection Rollback");
} else
{
conn.commit();
System.out.println("confirm: Connection Commit");
}
conn.close();
conn = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
return errString;
}
private static Document parseString(String xsdString) throws Exception {
Document dom = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
OutputStreamWriter errorWriter = new OutputStreamWriter(System.err,
"UTF-8");
ByteArrayInputStream baos = new ByteArrayInputStream(xsdString
.getBytes());
dom = db.parse(baos);
} catch (Exception e) {
System.out.println("Error :" + e);
}
return dom;
}
public ArrayList readExcelFile(File fileName, int sheetNo) {
System.out
.println("----in readExcelFile1 method CNT..................");
String value = null;
int headerRowCnt = -1, detailRowCnt = -1;
ArrayList cellArrayLisstHolder = new ArrayList();
try {
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(sheetNo);
Sheet sheet = myWorkBook.getSheetAt(sheetNo);
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() != Cell.CELL_TYPE_BLANK) {
if (cell.getCellType() != Cell.CELL_TYPE_STRING
|| cell.getStringCellValue().length() > 0) {
if (sheetNo == 1)
headerRowCnt++;
else if (sheetNo == 2)
detailRowCnt++;
break;
}
}
}
}
for (Row row : mySheet) {
ArrayList cellStoreArrayList = new ArrayList();
for (int cn = 0; cn < row.getLastCellNum(); cn++) {
Cell cell = row.getCell(cn, Row.CREATE_NULL_AS_BLANK);
value = cell.toString();
if (value.contains(",")) {
value = value.replace(",", "");
}
cellStoreArrayList.add(value);
}
cellArrayLisstHolder.add(cellStoreArrayList);
}
} catch (Exception e) {
e.printStackTrace();
}
return cellArrayLisstHolder;
}
/*
* public String getReqDecimal(String chqAmt) { DecimalFormat df = new
* DecimalFormat("000000"); //int num= Integer.parseInt(chqAmt); String
* refAmt = df.format(chqAmt); System.out.println("@@@@@"+refAmt); return
* refAmt; }
*/
@Override
public String schedule(HashMap arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
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