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; package ibase.webitm.ejb.sys;
import ibase.webitm.utility.*; import ibase.webitm.utility.*;
import ibase.webitm.ejb.*; import ibase.webitm.ejb.*;
import ibase.webitm.bean.*; import ibase.webitm.bean.*;
import ibase.utility.CommonConstants; import ibase.utility.CommonConstants;
import ibase.system.config.*; import ibase.system.config.*;
import ibase.utility.UserInfoBean; import ibase.utility.UserInfoBean;
import ibase.scheduler.utility.interfaces.Schedule; import ibase.scheduler.utility.interfaces.Schedule;
import java.util.*;
import java.rmi.*; import java.util.*;
import javax.ejb.*; import java.rmi.*;
import javax.rmi.*; import javax.ejb.*;
import java.io.File; import javax.rmi.*;
import java.io.FileWriter; import java.io.File;
import java.io.*; import java.io.FileWriter;
import java.lang.String; import java.io.*;
import java.lang.String;
import org.apache.log4j.*; import javax.mail.*;
import org.w3c.dom.*; import javax.mail.internet.*;
import javax.activation.*;
public class DownloadCSVBatchBean implements Schedule import java.sql.*;
{
protected ibase.utility.UserInfoBean userInfo = null; import org.apache.log4j.*;
import org.w3c.dom.*;
public void downloadTransaction( String objName, String downloadLoc, String entityCode, String entityType, String siteCodeDnld, String custCodeDnld ) throws RemoteException, ITMException
{ public class DownloadCSVBatchBean implements Schedule
//String entityType = null; {
//String entityCode = null; protected ibase.utility.UserInfoBean userInfo = null;
String templUpld = null;
String templTypeUpld = null; public void downloadTransaction( String objName, String downloadLoc, String entityCode,
String templDnld = null; String entityType, String siteCodeDnld, String custCodeDnld ) throws RemoteException, ITMException
String templTypeDnld = null; {
String objEximpFmt = null; String templUpld = null;
String templTypeUpld = null;
TranXmlData client = null; String templDnld = null;
String dnldFileName = null; String templTypeDnld = null;
String xmlToCsvStr = null; String objEximpFmt = null;
HashMap tranFileMip = new HashMap(); TranXmlData client = null;
// 11/09/09 manoharan DI89SUN223 String dnldFileName = null;
HashMap tranSeqMap = new HashMap(); String xmlToCsvStr = null;
// end 11/09/09 manoharan
HashMap tranFileMip = new HashMap();
String tranId = null; HashMap emailHash = new HashMap();
String custCode = null;
String uniformCode = null; String tranId = null;
String dt = null; String custCode = null;
String prvCustCode = null; String emailAddr = null;
String previousDay = null; String uniformCode = null;
int recCounter = 0; String dt = null;
String trfCycle = null;
String fileName = null; String trfType = null;
String previousDay = null;
boolean isTemplateExist = false; String filePath = null;
String retString = null;
siteCodeDnld = ( siteCodeDnld != null && siteCodeDnld.equalsIgnoreCase( "null" ) ) ? "" : siteCodeDnld.trim(); String subject = null;
custCodeDnld = ( custCodeDnld != null && custCodeDnld.equalsIgnoreCase( "null" ) ) ? "" : custCodeDnld.trim(); String text = null;
java.sql.Timestamp fromDate = null;
//entityCode = userInfo.getEntityCode(); java.sql.Timestamp toDate = null;
//entityType = userInfo.getUserType();
boolean isTemplateExist = false;
//entityType = "E";
//entityCode = "E03498"; siteCodeDnld = ( siteCodeDnld != null && siteCodeDnld.equalsIgnoreCase( "null" ) ) ?
String sql = null; "" : siteCodeDnld.trim();
//objName = "invoice"; custCodeDnld = ( custCodeDnld != null && custCodeDnld.equalsIgnoreCase( "null" ) ) ?
//downloadLoc = "G:\\rcp\\JBoss-2.4.4\\DOWNLOAD\\daily"; "" : custCodeDnld.trim();
sql = " select OBJ_NAME, TEMPL_UPLD, TEMPL_TYPE_UPLD, TEMPL_DNLD, TEMPL_TYPE_DNLD" String sql = null;
+" from OBJECT_EXIM_FMT "
+" where OBJ_NAME = '" + objName + "'" //System.out.println( "downloadLoc:: " + downloadLoc );
+" and OBJ_CONTEXT = '" + entityType.trim() + "-" + entityCode.trim() + "'";
//System.out.println( "SQL :: " + sql ); sql = " SELECT OBJ_NAME, TEMPL_UPLD, TEMPL_TYPE_UPLD, TEMPL_DNLD, TEMPL_TYPE_DNLD"
java.sql.Connection conn = null; +" FROM OBJECT_EXIM_FMT "
java.sql.PreparedStatement pstmt = null; +" WHERE OBJ_NAME = '" + objName + "'"
java.sql.ResultSet rs = null; +" AND OBJ_CONTEXT = '" + entityType.trim() + "-" + entityCode.trim() + "'";
// 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.Connection conn = null;
java.sql.Timestamp tranDate = null; java.sql.PreparedStatement pstmt = null;
// end 11/09/09 manoharan to store and get the sequence (file suffix) in invoice table java.sql.ResultSet rs = null;
ConnDriver connDriver = new ConnDriver(); java.sql.PreparedStatement pstmtSeq = null;
try java.sql.PreparedStatement pstmtSeq2 = null;
{ java.sql.ResultSet rsSeq = null;
conn = connDriver.getConnectDB( "DriverITM" ); java.sql.Timestamp tranDate = null;
conn.setAutoCommit( false );
pstmt = conn.prepareStatement( sql ); ConnDriver connDriver = new ConnDriver();
rs = pstmt.executeQuery(); try
if( rs.next() ) {
{ conn = connDriver.getConnectDB( "DriverITM" );
objName = rs.getString( "OBJ_NAME" ); conn.setAutoCommit( false );
templUpld = rs.getString( "TEMPL_UPLD" );
templTypeUpld = rs.getString( "TEMPL_TYPE_UPLD" ); pstmt = conn.prepareStatement( sql );
templDnld = rs.getString( "TEMPL_DNLD" ); rs = pstmt.executeQuery();
templTypeDnld = rs.getString( "TEMPL_TYPE_DNLD" ); if( rs.next() )
{
isTemplateExist = true; objName = rs.getString( "OBJ_NAME" );
} templUpld = rs.getString( "TEMPL_UPLD" );
System.out.println( " isTemplateExist :: [" + isTemplateExist + "]" ); templTypeUpld = rs.getString( "TEMPL_TYPE_UPLD" );
System.out.println( " objName :: [" + objName + "]" ); templDnld = rs.getString( "TEMPL_DNLD" );
System.out.println( " templUpld :: [" + templUpld + "]" ); templTypeDnld = rs.getString( "TEMPL_TYPE_DNLD" );
System.out.println( " templTypeUpld :: [" + templTypeUpld + "]" );
System.out.println( " templDnld :: [" + templDnld + "]" ); isTemplateExist = true;
System.out.println( " templTypeDnld :: [" + templTypeDnld + "]" ); }
rs.close(); /*System.out.println( " isTemplateExist :: [" + isTemplateExist + "]" );
rs = null; System.out.println( " objName :: [" + objName + "]" );
pstmt.close(); System.out.println( " templUpld :: [" + templUpld + "]" );
pstmt = null; System.out.println( " templTypeUpld :: [" + templTypeUpld + "]" );
}catch( Exception ex ) System.out.println( " templDnld :: [" + templDnld + "]" );
{ System.out.println( " templTypeDnld :: [" + templTypeDnld + "]" );
ex.printStackTrace(); */
} rs.close();
if( isTemplateExist ) rs = null;
{ pstmt.close();
GenericUtility genericUtility = GenericUtility.getInstance(); pstmt = null;
}catch( Exception ex )
String xlsFileName = null; {
String csvData = null; ex.printStackTrace();
String templFileName = null; }
templFileName = CommonConstants.JBOSSHOME; if( isTemplateExist )
fileName = CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD" + File.separator + objName; {
//ibase.webitm.utility.XML2XLSCustomXfm xlsConverter = new ibase.webitm.utility.XML2XLSCustomXfm(); GenericUtility genericUtility = GenericUtility.getInstance();
//System.out.println( " templDnld :: " + CommonConstants.JBOSSHOME + File.separator + "DWNLOAD" + File.separator + "template" + File.separator + templDnld );
//System.out.println( " fileName :: " + fileName ); String xlsFileName = null;
try String csvData = null;
{ String templFileName = null;
if( templTypeDnld.equalsIgnoreCase( "C" ) ) templFileName = CommonConstants.JBOSSHOME;
{
ibase.webitm.utility.XML2CSVCustomConverter csvConverter = null;
csvConverter = new ibase.webitm.utility.XML2CSVCustomConverter(); try
{
if( objName.equalsIgnoreCase( "INVOICE" ) ) if( templTypeDnld.equalsIgnoreCase( "C" ) )
{ {
String str = null;
client = new TranXmlData();
if( objName.equalsIgnoreCase( "INVOICE" ) )
// 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'"); String str = null;
// 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. //start - select all the undownloaded invoice, if found,
sql = "SELECT iv.INVOICE_ID TRAN_ID, iv.CUST_CODE, cu.UNIFORM_CODE, " //then download for each.
+" to_char( iv.tran_date, 'ddmmyyyy' ) dt , iv.tran_date tran_date" sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, "
+" FROM INVOICE iv, CUSTOMER cu, site_customer sc " +" CU.EMAIL_ADDR EMAIL_ADDR, CU.UNIFORM_CODE UNIFORM_CODE, "
+" WHERE iv.cust_code = cu.cust_code( + ) " +" TO_CHAR( IV.TRAN_DATE, 'DDMM' ) DT, IV.TRAN_DATE TRAN_DATE, "
+" and iv.site_code = sc.site_code " +" SC.INV_TRF_TYPE INV_TRF_TYPE, SC.INV_TRF_CYCLE INV_TRF_CYCLE "
+" and iv.cust_code = sc.cust_code " +" FROM INVOICE IV, CUSTOMER CU, SITE_CUSTOMER SC "
+" and sc.download_YN = 'Y' " +" WHERE IV.CUST_CODE__BIL = CU.CUST_CODE( + ) "
+" and ( iv.download_flag is null or iv.download_flag = 'N' ) "; +" AND IV.SITE_CODE = SC.SITE_CODE "
if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0 && custCodeDnld != null && custCodeDnld.trim().length() > 0 ) +" AND IV.CUST_CODE__BIL = SC.CUST_CODE "
{ +" AND ( IV.DOWNLOAD_FLAG IS NULL OR IV.DOWNLOAD_FLAG = 'N' ) ";
sql = sql + " and iv.site_code = '" + siteCodeDnld + "' and iv.cust_code = '" + custCodeDnld + "' ";
} if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0
sql = sql + " order by iv.cust_code "; && custCodeDnld != null && custCodeDnld.trim().length() > 0 )
pstmt = conn.prepareStatement( sql ); {
rs = pstmt.executeQuery(); sql = sql + " AND IV.SITE_CODE = ? "
+" AND IV.CUST_CODE = ? ";
prvCustCode = null; }
recCounter = 0; sql = sql + " ORDER BY IV.TRAN_DATE ASC ";
while( rs.next() )
{ pstmt = conn.prepareStatement( sql );
pstmt.setString(1, siteCodeDnld);
tranId = rs.getString( "TRAN_ID" ); pstmt.setString(2, custCodeDnld);
custCode = rs.getString( "CUST_CODE" ); rs = pstmt.executeQuery();
uniformCode = rs.getString( "UNIFORM_CODE" );
dt = rs.getString( "dt" ); while( rs.next() )
tranDate = rs.getTimestamp( "tran_date" ); {
if( custCode.equalsIgnoreCase( prvCustCode ) && dt.equalsIgnoreCase( previousDay ) ) tranFileMip = new HashMap();
{ emailHash = new HashMap();
recCounter++; retString = null;
} tranId = rs.getString( "TRAN_ID" );
else custCode = rs.getString( "CUST_CODE" );
{ emailAddr = rs.getString( "EMAIL_ADDR" );
// 11/09/09 DI89SUN223 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day uniformCode = rs.getString( "UNIFORM_CODE" );
//recCounter = 1; dt = rs.getString( "DT" );
pstmtSeq.setString(1,custCode); tranDate = rs.getTimestamp( "TRAN_DATE" );
pstmtSeq.setTimestamp(2,tranDate); trfType = rs.getString( "INV_TRF_TYPE" );
rsSeq = pstmtSeq.executeQuery(); trfCycle = rs.getString( "INV_TRF_CYCLE" );
if( rsSeq.next() )
{ // 29/03/10 sachin---to store file in new format as IDDMM<invoice id>.CSV
recCounter = rsSeq.getInt("download_file_seq"); dnldFileName = "I"+ dt + tranId;
}
rsSeq.close(); tranFileMip.put( "tranId", tranId );
rsSeq = null; tranFileMip.put( "dnldFileName", dnldFileName );
//if (recCounter == 0 ) tranFileMip.put( "templDnld", templDnld );
//{
recCounter++;// = 1; filePath = downloadLoc + File.separator + dnldFileName + ".csv";
//}
// end 11/09/09 manoharan to store the sequence number (file suffix) in invoice table and increment for the same day if(emailAddr!=null && !emailAddr.equalsIgnoreCase(" "))
} {
dnldFileName = ( uniformCode == null ? "" : uniformCode.trim() ) + "_" + dt + "_" + ( new java.text.DecimalFormat( "000" ) ).format( recCounter ); emailHash.put("TO_ADDR", emailAddr);
prvCustCode = custCode; }
previousDay = dt; else
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 emailHash.put("TO_ADDR", "");
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
} subject = "Invoice in CSV format for Invoice No." +tranId;
text = "Dear Sir/Madam,\n Please find the attached CSV file for Invoice "
rs.close(); +" No. "+tranId;
rs = null;
pstmt.close(); emailHash.put("SUBJECT", subject);
pstmt = null; emailHash.put("TEXT", text);
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same
pstmtSeq.close(); // 06/04/10 SY90SUN012 sachin to select the peroid against
pstmtSeq = null; //the tran date from period table
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same
pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD "
//end - select all the undownloaded invoice, if found, then download for each. +" WHERE ? BETWEEN FR_DATE AND TO_DATE ");
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same pstmtSeq.setTimestamp(1, tranDate);
//pstmt = conn.prepareStatement( "update invoice set download_flag = 'Y' where invoice_id = ?" ); rsSeq = pstmtSeq.executeQuery();
pstmt = conn.prepareStatement( "update invoice set download_flag = 'Y', download_file_seq = ? where invoice_id = ?" ); while( rsSeq.next() )
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same {
fromDate = rsSeq.getTimestamp( "FR_DATE" );
Iterator tranItr = tranFileMip.keySet().iterator(); toDate = rsSeq.getTimestamp( "TO_DATE" );
}
while( tranItr.hasNext() ) rsSeq.close();
{ rsSeq = null;
try pstmtSeq.close();
{ pstmtSeq = null;
tranId = ( String ) tranItr.next(); // end 06/04/10 SY90SUN012 sachin to select the peroid
dnldFileName = ( String )tranFileMip.get( tranId ); //against the tran date from period table
xmlToCsvStr = client.getTranXml( "invoice", if("E".equalsIgnoreCase(trfType))
java.sql.Timestamp.valueOf( "2008-11-01 00:00:00" ), {
java.sql.Timestamp.valueOf( "2008-11-01 00:00:00" ), downloadLoc = CommonConstants.JBOSSHOME + File.separator
tranId, tranId, conn ); + "server" + File.separator + "default" + File.separator
+ "tmp";
csvData = csvConverter.convert( xmlToCsvStr, }
CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD"
+ File.separator + "template" if(trfCycle != null && trfCycle.equalsIgnoreCase( "O" ))
+ File.separator + templDnld + ".xml", {
null pstmtSeq = conn.prepareStatement( " SELECT IV.INV_EXP_DATE "
); +" FROM INVOICE IV, SITE_CUSTOMER SC "
FileWriter fw = new FileWriter( downloadLoc + File.separator + dnldFileName + ".csv" ); +" WHERE IV.CUST_CODE__BIL = SC.CUST_CODE "
+" AND IV.SITE_CODE = SC.SITE_CODE AND IV.INV_EXP_DATE IS NOT NULL "
fw.write( csvData ); +" AND IV.TRAN_DATE BETWEEN ? AND ? ");
fw.close(); pstmtSeq.setTimestamp(1, fromDate);
fw = null; pstmtSeq.setTimestamp(2, toDate);
//Changed by Rupali [update the Download_flag after each invoice files downloading].Start rsSeq = pstmtSeq.executeQuery();
//pstmt.addBatch(); if( rsSeq.next() )
// 11/09/09 DI89SUN223 manoharan to store the sequence (file suffix) in invoice table and increment the same {
recCounter = (( Integer )tranSeqMap.get( tranId )).intValue(); pstmtSeq2 = conn.prepareStatement( "UPDATE INVOICE SET "
// end 11/09/09 manoharan to store the sequence (file suffix) in invoice table and increment the same +" DOWNLOAD_FLAG = 'Y' WHERE INVOICE_ID = ? " );
pstmt.setInt( 1, recCounter ); pstmtSeq2.setString( 1, tranId );
pstmt.setString( 2, tranId ); int rowCnt = pstmtSeq2.executeUpdate();
int rowCnt = pstmt.executeUpdate(); if(rowCnt >= 1){
if(rowCnt >= 1){ conn.commit();
conn.commit(); }
} else{
else{ conn.rollback();
conn.rollback(); }
} pstmtSeq2.close();
}catch( Exception ex ) pstmtSeq2 = null;
{ }
//ignore this exception as if one file throws exception next file should download. else
} {
//Changed by Rupali [update the Download_flag after each invoice files downloading].End download(tranFileMip, downloadLoc);
} if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
//Changed by Rupali [update the Download_flag after each invoice files downloading].Start trfType.equalsIgnoreCase( "E" )))
//pstmt.executeBatch(); {
pstmt.close();
pstmt = null; filePath = downloadLoc + File.separator + dnldFileName
/* + ".csv";
try{ emailHash.put("FILEPATH", filePath);
conn.commit(); retString = sendMail(emailHash, conn);
}catch( Exception ex ){} if(trfType.equalsIgnoreCase( "E" ))
*/ {
//Changed by Rupali [update the Download_flag after each invoice files downloading].End deleteFile(filePath);
} }
else }
{ }
/* rsSeq.close();
csvData = csvConverter.convert( xmlDataDnld, rsSeq = null;
CommonConstants.JBOSSHOME + File.separator + "DOWNLOAD" pstmtSeq.close();
+ File.separator + "template" pstmtSeq = null;
+ File.separator + templDnld + ".xml", }
null
); else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" ))
*/ {
} download(tranFileMip, downloadLoc);
}
} if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
catch( Exception pte ) trfType.equalsIgnoreCase( "E" )))
{ {
try{ filePath = downloadLoc + File.separator + dnldFileName
conn.rollback(); + ".csv";
}catch( Exception ex ){} emailHash.put("FILEPATH", filePath);
pte.printStackTrace(); retString = sendMail(emailHash, conn);
} if(trfType.equalsIgnoreCase( "E" ))
} {
} deleteFile(filePath);
}
public String schedule( HashMap map )throws RemoteException, ITMException }
{
return ""; }
} //Changed by Sachin [update the Download_flag and INV_EXP_DATE after
public String schedule( String scheduleParamXML )throws RemoteException, ITMException //each invoice files downloading]
{
String userInfoList = null; if(retString!=null && !retString.equalsIgnoreCase("ERROR"))
String isIntractive = null; {
String objName = null; pstmtSeq = conn.prepareStatement( "UPDATE INVOICE SET "
String downloadLoc = null; +" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE "
+" WHERE INVOICE_ID = ? " );
ArrayList paramListArr = new ArrayList();
pstmtSeq.setString( 1, tranId );
try int rowCnt = pstmtSeq.executeUpdate();
{ if(rowCnt >= 1){
//APPLICATION_CONTEXT = CommonConstants.UPLOAD_LOC + File.separator + "webapps" + File.separator + "ibase" + File.separator ; conn.commit();
//System.out.println(" scheduleParamXML [" + scheduleParamXML + "]"); }
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML ); else{
NodeList paramList = userInfoDom.getElementsByTagName( "ACTUALPARAMETER" ); conn.rollback();
// }
int noOfParam = paramList.getLength(); pstmtSeq.close();
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ ) pstmtSeq = null;
{ }
paramListArr.add( ( String )( paramList.item( paramCnt ).getFirstChild().getNodeValue() ) ); }
} //Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading].end
//for( int i = 0 ; i < paramListArr.size(); i++ )
//{ //end - select all the undownloaded invoice, if found, then download for each.
// System.out.println( "My param :: " + (String)paramListArr.get( i ) );
//} }
// else
{
/* /*
System.out.println(" RootNode [ " + rootNode+ " ] "); csvData = csvConverter.convert( xmlDataDnld,
NodeList propNodeList = rootNode.getChildNodes(); CommonConstants.JBOSSHOME + File.separator
System.out.println(" propNodeList [ " + propNodeList+ " ] "); + "DOWNLOAD" + File.separator + "template"
int noOfProps = propNodeList.getLength(); + File.separator + templDnld + ".xml",
for( int propCtr = 0; propCtr < noOfProps; propCtr++ ) null
{ );
Node propNode = propNodeList.item( propCtr ); */
System.out.println(" propNode [" +propNode+"]"); }
if( propNode != null && propNode.getFirstChild() != null ) }
{ }
String propName = propNode.getNodeName(); catch( Exception pte )
System.out.println(" propName [" +propName+"]"); {
if ( "UserInfoStr".equalsIgnoreCase( propName ) ) try{
{ conn.rollback();
userInfoList = propNode.getFirstChild().getNodeValue(); conn.close();
System.out.println(" userInfoList [" + userInfoList + "]"); conn = null;
} }catch( Exception ex ){}
else if ( "downloadLoc".equalsIgnoreCase( propName ) ) pte.printStackTrace();
{ }
downloadLoc = propNode.getFirstChild().getNodeValue();
System.out.println(" isIntractive [" + isIntractive + "]"); }
} }
else if ( "objName".equalsIgnoreCase( propName ) )
{ public void deleteFile( String filePath)throws RemoteException, ITMException
objName = propNode.getFirstChild().getNodeValue(); {
System.out.println(" objName [" + objName + "]"); try
} {
else if ( "entityCode".equalsIgnoreCase( propName ) ) // Construct a File object for the file to be deleted.
{ File target = new File(filePath);
entityCode = propNode.getFirstChild().getNodeValue();
System.out.println(" entityCode [" + entityCode + "]"); if (!target.exists()) {
} System.err.println("File " + filePath
else if ( "entityType".equalsIgnoreCase( propName ) ) + " not present to begin with!");
{ return;
entityType = propNode.getFirstChild().getNodeValue(); }
System.out.println(" entityType [" + entityType + "]");
} // delete tmp file:
} if (target.delete())
} System.err.println("** Deleted " + filePath + " **");
*/ else
//downloadTransaction( objName, downloadLoc, entityCode, entityType, null ); System.err.println("Failed to delete " + filePath);
/* }
List and order of arguments : catch (SecurityException e)
1. location, {
2. Entity Code System.err.println("Unable to delete " + filePath + "("
3. Entity Type + e.getMessage() + ")");
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) public void download( HashMap map, String downloadLoc)throws RemoteException, ITMException
{ {
//System.out.println("DownloadCSVBatchEJB :==>Schedule"); java.sql.Connection conn = null;
e.printStackTrace(); java.sql.PreparedStatement pstmt = null;
} java.sql.ResultSet rs = null;
String tranId = null;
return ""; 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