Commit 0c5f23a8 authored by sakale's avatar sakale

SY90SUN012 The email with attachment feature has been provided to send invoices in CSV format


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@91261 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 15f3e60d
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();
// 11/09/09 manoharan DI89SUN223
HashMap tranSeqMap = new HashMap();
// end 11/09/09 manoharan
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;
// 11/09/09 manoharan to store and get the sequence (file suffix) in invoice table
java.sql.PreparedStatement pstmtSeq = null;
java.sql.ResultSet rsSeq = null;
java.sql.Timestamp tranDate = null;
// end 11/09/09 manoharan to store and get the sequence (file suffix) in invoice table
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;
}
System.out.println( " isTemplateExist :: [" + isTemplateExist + "]" );
System.out.println( " objName :: [" + objName + "]" );
System.out.println( " templUpld :: [" + templUpld + "]" );
System.out.println( " templTypeUpld :: [" + templTypeUpld + "]" );
System.out.println( " templDnld :: [" + templDnld + "]" );
System.out.println( " templTypeDnld :: [" + templTypeDnld + "]" );
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();
// 11/09/09 manoharan DI89SUN223 to store the sequence number (file suffix) in invoice table and increment for the same day
pstmtSeq = conn.prepareStatement("SELECT MAX(case when download_file_seq is null then 0 else download_file_seq end) as download_file_seq FROM INVOICE WHERE CUST_CODE = ? AND TRAN_DATE = ? AND download_flag = 'Y'");
// end 11/09/09 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day
//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 , iv.tran_date tran_date"
+" 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" );
tranDate = rs.getTimestamp( "tran_date" );
if( custCode.equalsIgnoreCase( prvCustCode ) && dt.equalsIgnoreCase( previousDay ) )
{
recCounter++;
}
else
{
// 11/09/09 DI89SUN223 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day
//recCounter = 1;
pstmtSeq.setString(1,custCode);
pstmtSeq.setTimestamp(2,tranDate);
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
recCounter = rsSeq.getInt("download_file_seq");
}
rsSeq.close();
rsSeq = null;
//if (recCounter == 0 )
//{
recCounter++;// = 1;
//}
// end 11/09/09 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day
}
dnldFileName = ( uniformCode == null ? "" : uniformCode.trim() ) + "_" + dt + "_" + ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
tranFileMip.put( tranId, dnldFileName );
// 11/09/09 DI89SUN223 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day
tranSeqMap.put(tranId, new Integer(recCounter));
// end 11/09/09 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same
pstmtSeq.close();
pstmtSeq = null;
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same
//end - select all the undownloaded invoice, if found, then download for each.
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same
//pstmt = conn.prepareStatement( "update invoice set download_flag = 'Y' where invoice_id = ?" );
pstmt = conn.prepareStatement( "update invoice set download_flag = 'Y', download_file_seq = ? where invoice_id = ?" );
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same
Iterator tranItr = tranFileMip.keySet().iterator();
while( tranItr.hasNext() )
{
try
{
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;
//Changed by Rupali [update the Download_flag after each invoice files downloading].Start
//pstmt.addBatch();
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same
recCounter = (( Integer )tranSeqMap.get( tranId )).intValue();
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same
pstmt.setInt( 1, recCounter );
pstmt.setString( 2, tranId );
int rowCnt = pstmt.executeUpdate();
if(rowCnt >= 1){
conn.commit();
}
else{
conn.rollback();
}
}catch( Exception ex )
{
//ignore this exception as if one file throws exception next file should download.
}
//Changed by Rupali [update the Download_flag after each invoice files downloading].End
}
//Changed by Rupali [update the Download_flag after each invoice files downloading].Start
//pstmt.executeBatch();
pstmt.close();
pstmt = null;
/*
try{
conn.commit();
}catch( Exception ex ){}
*/
//Changed by Rupali [update the Download_flag after each invoice files downloading].End
}
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 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 javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.sql.*;
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 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();
HashMap emailHash = new HashMap();
String tranId = null;
String custCode = null;
String emailAddr = null;
String uniformCode = null;
String dt = null;
String trfCycle = null;
String trfType = null;
String previousDay = null;
String filePath = null;
String retString = null;
String subject = null;
String text = null;
java.sql.Timestamp fromDate = null;
java.sql.Timestamp toDate = null;
boolean isTemplateExist = false;
siteCodeDnld = ( siteCodeDnld != null && siteCodeDnld.equalsIgnoreCase( "null" ) ) ?
"" : siteCodeDnld.trim();
custCodeDnld = ( custCodeDnld != null && custCodeDnld.equalsIgnoreCase( "null" ) ) ?
"" : custCodeDnld.trim();
String sql = null;
//System.out.println( "downloadLoc:: " + downloadLoc );
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() + "'";
java.sql.Connection conn = null;
java.sql.PreparedStatement pstmt = null;
java.sql.ResultSet rs = null;
java.sql.PreparedStatement pstmtSeq = null;
java.sql.PreparedStatement pstmtSeq2 = null;
java.sql.ResultSet rsSeq = null;
java.sql.Timestamp tranDate = 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;
}
/*System.out.println( " isTemplateExist :: [" + isTemplateExist + "]" );
System.out.println( " objName :: [" + objName + "]" );
System.out.println( " templUpld :: [" + templUpld + "]" );
System.out.println( " templTypeUpld :: [" + templTypeUpld + "]" );
System.out.println( " templDnld :: [" + templDnld + "]" );
System.out.println( " templTypeDnld :: [" + templTypeDnld + "]" );
*/
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;
try
{
if( templTypeDnld.equalsIgnoreCase( "C" ) )
{
if( objName.equalsIgnoreCase( "INVOICE" ) )
{
String str = null;
//start - select all the undownloaded invoice, if found,
//then download for each.
sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, "
+" CU.EMAIL_ADDR EMAIL_ADDR, CU.UNIFORM_CODE UNIFORM_CODE, "
+" TO_CHAR( IV.TRAN_DATE, 'DDMM' ) DT, IV.TRAN_DATE TRAN_DATE, "
+" SC.INV_TRF_TYPE INV_TRF_TYPE, SC.INV_TRF_CYCLE INV_TRF_CYCLE "
+" FROM INVOICE IV, CUSTOMER CU, SITE_CUSTOMER SC "
+" WHERE IV.CUST_CODE__BIL = CU.CUST_CODE( + ) "
+" AND IV.SITE_CODE = SC.SITE_CODE "
+" AND IV.CUST_CODE__BIL = SC.CUST_CODE "
+" 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 = ? "
+" AND IV.CUST_CODE = ? ";
}
sql = sql + " ORDER BY IV.TRAN_DATE ASC ";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, siteCodeDnld);
pstmt.setString(2, custCodeDnld);
rs = pstmt.executeQuery();
while( rs.next() )
{
tranFileMip = new HashMap();
emailHash = new HashMap();
retString = null;
tranId = rs.getString( "TRAN_ID" );
custCode = rs.getString( "CUST_CODE" );
emailAddr = rs.getString( "EMAIL_ADDR" );
uniformCode = rs.getString( "UNIFORM_CODE" );
dt = rs.getString( "DT" );
tranDate = rs.getTimestamp( "TRAN_DATE" );
trfType = rs.getString( "INV_TRF_TYPE" );
trfCycle = rs.getString( "INV_TRF_CYCLE" );
// 29/03/10 sachin---to store file in new format as IDDMM<invoice id>.CSV
dnldFileName = "I"+ dt + tranId;
tranFileMip.put( "tranId", tranId );
tranFileMip.put( "dnldFileName", dnldFileName );
tranFileMip.put( "templDnld", templDnld );
filePath = downloadLoc + File.separator + dnldFileName + ".csv";
if(emailAddr!=null && !emailAddr.equalsIgnoreCase(" "))
{
emailHash.put("TO_ADDR", emailAddr);
}
else
{
emailHash.put("TO_ADDR", "");
}
subject = "Invoice in CSV format for Invoice No." +tranId;
text = "Dear Sir/Madam,\n Please find the attached CSV file for Invoice "
+" No. "+tranId;
emailHash.put("SUBJECT", subject);
emailHash.put("TEXT", text);
// 06/04/10 SY90SUN012 sachin to select the peroid against
//the tran date from period table
pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD "
+" WHERE ? BETWEEN FR_DATE AND TO_DATE ");
pstmtSeq.setTimestamp(1, tranDate);
rsSeq = pstmtSeq.executeQuery();
while( rsSeq.next() )
{
fromDate = rsSeq.getTimestamp( "FR_DATE" );
toDate = rsSeq.getTimestamp( "TO_DATE" );
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
// end 06/04/10 SY90SUN012 sachin to select the peroid
//against the tran date from period table
if("E".equalsIgnoreCase(trfType))
{
downloadLoc = CommonConstants.JBOSSHOME + File.separator
+ "server" + File.separator + "default" + File.separator
+ "tmp";
}
if(trfCycle != null && trfCycle.equalsIgnoreCase( "O" ))
{
pstmtSeq = conn.prepareStatement( " SELECT IV.INV_EXP_DATE "
+" FROM INVOICE IV, SITE_CUSTOMER SC "
+" WHERE IV.CUST_CODE__BIL = SC.CUST_CODE "
+" AND IV.SITE_CODE = SC.SITE_CODE AND IV.INV_EXP_DATE IS NOT NULL "
+" AND IV.TRAN_DATE BETWEEN ? AND ? ");
pstmtSeq.setTimestamp(1, fromDate);
pstmtSeq.setTimestamp(2, toDate);
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
pstmtSeq2 = conn.prepareStatement( "UPDATE INVOICE SET "
+" DOWNLOAD_FLAG = 'Y' WHERE INVOICE_ID = ? " );
pstmtSeq2.setString( 1, tranId );
int rowCnt = pstmtSeq2.executeUpdate();
if(rowCnt >= 1){
conn.commit();
}
else{
conn.rollback();
}
pstmtSeq2.close();
pstmtSeq2 = null;
}
else
{
download(tranFileMip, downloadLoc);
if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
trfType.equalsIgnoreCase( "E" )))
{
filePath = downloadLoc + File.separator + dnldFileName
+ ".csv";
emailHash.put("FILEPATH", filePath);
retString = sendMail(emailHash, conn);
if(trfType.equalsIgnoreCase( "E" ))
{
deleteFile(filePath);
}
}
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
}
else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" ))
{
download(tranFileMip, downloadLoc);
if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
trfType.equalsIgnoreCase( "E" )))
{
filePath = downloadLoc + File.separator + dnldFileName
+ ".csv";
emailHash.put("FILEPATH", filePath);
retString = sendMail(emailHash, conn);
if(trfType.equalsIgnoreCase( "E" ))
{
deleteFile(filePath);
}
}
}
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading]
if(retString!=null && !retString.equalsIgnoreCase("ERROR"))
{
pstmtSeq = conn.prepareStatement( "UPDATE INVOICE SET "
+" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE "
+" WHERE INVOICE_ID = ? " );
pstmtSeq.setString( 1, tranId );
int rowCnt = pstmtSeq.executeUpdate();
if(rowCnt >= 1){
conn.commit();
}
else{
conn.rollback();
}
pstmtSeq.close();
pstmtSeq = null;
}
}
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading].end
//end - select all the undownloaded invoice, if found, then download for each.
}
else
{
/*
csvData = csvConverter.convert( xmlDataDnld,
CommonConstants.JBOSSHOME + File.separator
+ "DOWNLOAD" + File.separator + "template"
+ File.separator + templDnld + ".xml",
null
);
*/
}
}
}
catch( Exception pte )
{
try{
conn.rollback();
conn.close();
conn = null;
}catch( Exception ex ){}
pte.printStackTrace();
}
}
}
public void deleteFile( String filePath)throws RemoteException, ITMException
{
try
{
// Construct a File object for the file to be deleted.
File target = new File(filePath);
if (!target.exists()) {
System.err.println("File " + filePath
+ " not present to begin with!");
return;
}
// delete tmp file:
if (target.delete())
System.err.println("** Deleted " + filePath + " **");
else
System.err.println("Failed to delete " + filePath);
}
catch (SecurityException e)
{
System.err.println("Unable to delete " + filePath + "("
+ e.getMessage() + ")");
}
}
public void download( HashMap map, String downloadLoc)throws RemoteException, ITMException
{
java.sql.Connection conn = null;
java.sql.PreparedStatement pstmt = null;
java.sql.ResultSet rs = null;
String tranId = null;
String dnldFileName = null;
String xmlToCsvStr = null;
String templDnld = null;
String csvData = null;
TranXmlData client = null;
ibase.webitm.utility.XML2CSVCustomConverter csvConverter = null;
csvConverter = new ibase.webitm.utility.XML2CSVCustomConverter();
ConnDriver connDriver = new ConnDriver();
client = new TranXmlData();
if( map.size() > 0 )
{
try
{
conn = connDriver.getConnectDB( "DriverITM" );
conn.setAutoCommit( false );
connDriver = null;
tranId = ( String )map.get( "tranId" );
dnldFileName = ( String )map.get( "dnldFileName" );
templDnld = ( String )map.get( "templDnld" );
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;
conn.close();
conn = null;
}
catch( Exception ex )
{
//ignore this exception as if one file throws exception next file should download.
}
}
}
public String sendMail(HashMap hMap, Connection conn)throws Exception
{
String retString = "";
String to = "";
String from = "";
boolean debug = false;
String subject = "",text = "";
String xmlDataFilePath = "";
try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", CommonConstants.SMTPHOST);
Authenticator auth = null;
Session session= Session.getDefaultInstance(props,auth);
session.setDebug(debug);
MimeMessage msg = new MimeMessage(session);
MimeBodyPart mbp1 = new MimeBodyPart();
MimeBodyPart mbp2 = new MimeBodyPart();
Multipart mp = new MimeMultipart();
from = CommonConstants.MAILFROM;
to = (String)hMap.get("TO_ADDR");
subject = (String)hMap.get("SUBJECT");
text = (String)hMap.get("TEXT");
xmlDataFilePath = (String)hMap.get("FILEPATH");
InternetAddress[] address = {new InternetAddress(to)};
mbp1.setText(text);
mp.addBodyPart(mbp1);
// 30/03/10 Sachin---this part is added to send file as attachment.
if( xmlDataFilePath != null )
{
File createdFileObj = null;
createdFileObj = new File(xmlDataFilePath);
mbp2 = new MimeBodyPart();
DataSource source = new FileDataSource(createdFileObj);
mbp2.setDataHandler(new DataHandler(source));
mbp2.setFileName((createdFileObj.toString()).substring((createdFileObj.toString()).lastIndexOf("\\")+1, createdFileObj.toString().length()));
}
// 30/03/10 Sachin---end of part send file as attachment.
mp.addBodyPart(mbp2);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(from));
msg.setContent(mp);
msg.setSentDate(new java.util.Date());
if(msg.getRecipients(Message.RecipientType.TO) != null )
{
System.out.println("sending mail ...........");
Transport.send(msg);
}
}
catch (MessagingException mex)
{
retString = "ERROR";
System.out.println("SendEMail:MessagingException:\n");
mex.printStackTrace();
}
catch (Exception e)
{
retString = "ERROR";
System.out.println("SendEMail:MessagingException:\n");
e.printStackTrace();
}
return retString;
}
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 "";
}
}
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