Commit 50502aac authored by nshinde's avatar nshinde

Added By Manoj dtd 05/11/2012 implement abstract method


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@92142 ce508802-f39f-4f6c-b175-0d175dae99d5
parent c68a4ccc
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 dnldFileNameServer = null;
String dnldFileNameEmail = null;
String downloadLocEmail = null;
String xmlToCsvStr = null;
HashMap emailHash = new HashMap();
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 siteCode = null;
String emailAddr = null;
String uniformCode = null;
String dt = null;
String dty = null;
String trfCycle = null;
String prvCustCode = null;
String previousDay = null;
String trfType = null;
String filePath = null;
String retString = null;
String subject = null;
int recCounter = 0;
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.ResultSet rsSeq2 = 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;
try
{
if( templTypeDnld.equalsIgnoreCase( "C" ) )
{
if( objName.equalsIgnoreCase( "INVOICE" ) )
{
//start - select all the undownloaded invoice, if found,
//then download for each.
sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, "
+" IV.SITE_CODE SITE_CODE, CU.EMAIL_ADDR EMAIL_ADDR, "
+" CU.UNIFORM_CODE UNIFORM_CODE, "
+" TO_CHAR( IV.TRAN_DATE, 'DDMMYYYY' ) DTY, "
+" 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 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 = ? "
+" AND IV.CUST_CODE = ? ";
}
sql = sql + " ORDER BY IV.CUST_CODE, IV.TRAN_DATE, IV.INVOICE_ID ASC ";
pstmt = conn.prepareStatement( sql );
if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0
&& custCodeDnld != null && custCodeDnld.trim().length() > 0 )
{
pstmt.setString(1, siteCodeDnld);
pstmt.setString(2, custCodeDnld);
}
rs = pstmt.executeQuery();
prvCustCode = null;
recCounter = 0;
while( rs.next() )
{
tranFileMip = new HashMap();
emailHash = new HashMap();
retString = null;
tranId = rs.getString( "TRAN_ID" );
custCode = rs.getString( "CUST_CODE" );
siteCode = rs.getString( "SITE_CODE" );
emailAddr = rs.getString( "EMAIL_ADDR" );
uniformCode = rs.getString( "UNIFORM_CODE" );
dt = rs.getString( "DT" );
dty = rs.getString( "DTY" );
tranDate = rs.getTimestamp( "TRAN_DATE" );
trfType = rs.getString( "INV_TRF_TYPE" );
trfCycle = rs.getString( "INV_TRF_CYCLE" );
System.out.println("tranDate =="+tranDate);
System.out.println("custCode =="+custCode);
System.out.println("prvCustCode =="+prvCustCode);
System.out.println("dt =="+dt);
System.out.println("previousDay =="+previousDay);
// 11/09/09 manoharan DI89SUN223 to store the sequence number
//(file suffix) in invoice table and increment for the same day
pstmtSeq2 = conn.prepareStatement("SELECT NVL(MAX(CASE WHEN DOWNLOAD_FILE_SEQ "
+" IS NULL THEN 0 ELSE DOWNLOAD_FILE_SEQ END),0) 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
tranFileMip.put( "tranId", tranId );
tranFileMip.put( "templDnld", templDnld );
// 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email start
if(!("S".equalsIgnoreCase(trfType)))
{
dnldFileNameEmail = "I"+ dt + tranId.trim();
tranFileMip.put( "dnldFileName", dnldFileNameEmail );
downloadLocEmail = CommonConstants.JBOSSHOME + File.separator
+ "server" + File.separator + "default" + File.separator
+ "tmp";
filePath = downloadLocEmail + File.separator + dnldFileNameEmail
+ ".csv";
System.out.println(filePath);
subject = "Invoice in CSV format for Invoice No." +tranId;
text = "Dear Sir/Madam,\n Please find the attached CSV file "
+" for Invoice No. "+tranId;
if(emailAddr == null && emailAddr.equalsIgnoreCase(" "))
{
emailAddr = "";
}
emailHash.put("TO_ADDR", emailAddr);
emailHash.put("SUBJECT", subject);
emailHash.put("TEXT", text);
emailHash.put("FILEPATH", filePath);
}
// 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email end
// 06/04/10 SY90SUN012 -sachin to select the peroid against
//the tran date from period table start
pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD "
+" WHERE ? BETWEEN FR_DATE AND TO_DATE ");
pstmtSeq.setTimestamp(1, tranDate);
rsSeq = pstmtSeq.executeQuery();
if( 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 end
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 ? "
+" AND IV.SITE_CODE = ? "
+" AND IV.CUST_CODE = ? "
+" AND IV.DOWNLOAD_FLAG = 'Y' " );
pstmtSeq.setTimestamp(1, fromDate);
pstmtSeq.setTimestamp(2, toDate);
pstmtSeq.setString(3, siteCode);
pstmtSeq.setString(4, custCode);
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
updateFlag(tranId, conn);
System.out.println("Inside Once -- already downloaded ");
}
else
{
if(!("S".equalsIgnoreCase(trfType)))
{
download(tranFileMip, downloadLocEmail);
retString = sendMail(emailHash, conn);
deleteFile(filePath);
}
if(!("E".equalsIgnoreCase(trfType)))
{
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;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dty + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
}
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
}
else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" ))
{
if(!("S".equalsIgnoreCase(trfType)))
{
download(tranFileMip, downloadLocEmail);
retString = sendMail(emailHash, conn);
deleteFile(filePath);
}
if(!("E".equalsIgnoreCase(trfType)))
{
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;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dty + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
}
}
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading]
if(retString!=null && !retString.equalsIgnoreCase("ERROR"))
{
sql = "UPDATE INVOICE SET "
+" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE ";
if(!("E".equalsIgnoreCase(trfType)))
{
sql += ", DOWNLOAD_FILE_SEQ = "+recCounter;
}
sql +=" WHERE INVOICE_ID = ? ";
pstmtSeq = conn.prepareStatement(sql);
pstmtSeq.setString( 1, tranId );
int rowCnt = pstmtSeq.executeUpdate();
System.out.println("Successfully updated =="+rowCnt);
if(rowCnt >= 1)
{
conn.commit();
}
else
{
conn.rollback();
}
pstmtSeq.close();
pstmtSeq = null;
}
pstmtSeq2.close();
pstmtSeq2 = 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.
}
}
}
catch( Exception pte )
{
try{
conn.rollback();
conn.close();
conn = null;
}catch( Exception ex ){}
pte.printStackTrace();
}
}
}
public void updateFlag(String tranId, Connection conn)throws RemoteException, ITMException
{
java.sql.PreparedStatement pstmtSeq2 = null;
try
{
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;
}
catch (Exception e)
{
System.out.println("Unable to updateFlag (" + e.getMessage() + ")");
}
}
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;
System.out.println("Inside download ");
}
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 = "";
String cc = "";
boolean debug = false;
String subject = "",text = "";
String xmlDataFilePath = "";
java.sql.PreparedStatement pstmtSeq = null;
java.sql.ResultSet rsSeq = null;
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);
// 28/04/10 Sachin---Start to check CC address is present
pstmtSeq = conn.prepareStatement( "SELECT VAR_VALUE FROM DISPARM "
+" WHERE PRD_CODE='999999' AND VAR_NAME = 'INV_MAIL_CC' " );
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
cc = rsSeq.getString( "VAR_VALUE" );
System.out.println("cc =="+ cc);
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
if(cc != null && cc.trim().length() > 0){
InternetAddress[] ccAddress = {new InternetAddress(cc)};
msg.setRecipients(Message.RecipientType.CC, ccAddress);
}
// 28/04/10 Sachin---End to check CC address is present
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 "";
}
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;
//Added By Manoj dtd 05/11/2012 implement abstract method
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
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 dnldFileNameServer = null;
String dnldFileNameEmail = null;
String downloadLocEmail = null;
String xmlToCsvStr = null;
HashMap emailHash = new HashMap();
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 siteCode = null;
String emailAddr = null;
String uniformCode = null;
String dt = null;
String dty = null;
String trfCycle = null;
String prvCustCode = null;
String previousDay = null;
String trfType = null;
String filePath = null;
String retString = null;
String subject = null;
int recCounter = 0;
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.ResultSet rsSeq2 = 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;
try
{
if( templTypeDnld.equalsIgnoreCase( "C" ) )
{
if( objName.equalsIgnoreCase( "INVOICE" ) )
{
//start - select all the undownloaded invoice, if found,
//then download for each.
sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, "
+" IV.SITE_CODE SITE_CODE, CU.EMAIL_ADDR EMAIL_ADDR, "
+" CU.UNIFORM_CODE UNIFORM_CODE, "
+" TO_CHAR( IV.TRAN_DATE, 'DDMMYYYY' ) DTY, "
+" 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 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 = ? "
+" AND IV.CUST_CODE = ? ";
}
sql = sql + " ORDER BY IV.CUST_CODE, IV.TRAN_DATE, IV.INVOICE_ID ASC ";
pstmt = conn.prepareStatement( sql );
if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0
&& custCodeDnld != null && custCodeDnld.trim().length() > 0 )
{
pstmt.setString(1, siteCodeDnld);
pstmt.setString(2, custCodeDnld);
}
rs = pstmt.executeQuery();
prvCustCode = null;
recCounter = 0;
while( rs.next() )
{
tranFileMip = new HashMap();
emailHash = new HashMap();
retString = null;
tranId = rs.getString( "TRAN_ID" );
custCode = rs.getString( "CUST_CODE" );
siteCode = rs.getString( "SITE_CODE" );
emailAddr = rs.getString( "EMAIL_ADDR" );
uniformCode = rs.getString( "UNIFORM_CODE" );
dt = rs.getString( "DT" );
dty = rs.getString( "DTY" );
tranDate = rs.getTimestamp( "TRAN_DATE" );
trfType = rs.getString( "INV_TRF_TYPE" );
trfCycle = rs.getString( "INV_TRF_CYCLE" );
System.out.println("tranDate =="+tranDate);
System.out.println("custCode =="+custCode);
System.out.println("prvCustCode =="+prvCustCode);
System.out.println("dt =="+dt);
System.out.println("previousDay =="+previousDay);
// 11/09/09 manoharan DI89SUN223 to store the sequence number
//(file suffix) in invoice table and increment for the same day
pstmtSeq2 = conn.prepareStatement("SELECT NVL(MAX(CASE WHEN DOWNLOAD_FILE_SEQ "
+" IS NULL THEN 0 ELSE DOWNLOAD_FILE_SEQ END),0) 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
tranFileMip.put( "tranId", tranId );
tranFileMip.put( "templDnld", templDnld );
// 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email start
if(!("S".equalsIgnoreCase(trfType)))
{
dnldFileNameEmail = "I"+ dt + tranId.trim();
tranFileMip.put( "dnldFileName", dnldFileNameEmail );
downloadLocEmail = CommonConstants.JBOSSHOME + File.separator
+ "server" + File.separator + "default" + File.separator
+ "tmp";
filePath = downloadLocEmail + File.separator + dnldFileNameEmail
+ ".csv";
System.out.println(filePath);
subject = "Invoice in CSV format for Invoice No." +tranId;
text = "Dear Sir/Madam,\n Please find the attached CSV file "
+" for Invoice No. "+tranId;
if(emailAddr == null && emailAddr.equalsIgnoreCase(" "))
{
emailAddr = "";
}
emailHash.put("TO_ADDR", emailAddr);
emailHash.put("SUBJECT", subject);
emailHash.put("TEXT", text);
emailHash.put("FILEPATH", filePath);
}
// 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email end
// 06/04/10 SY90SUN012 -sachin to select the peroid against
//the tran date from period table start
pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD "
+" WHERE ? BETWEEN FR_DATE AND TO_DATE ");
pstmtSeq.setTimestamp(1, tranDate);
rsSeq = pstmtSeq.executeQuery();
if( 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 end
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 ? "
+" AND IV.SITE_CODE = ? "
+" AND IV.CUST_CODE = ? "
+" AND IV.DOWNLOAD_FLAG = 'Y' " );
pstmtSeq.setTimestamp(1, fromDate);
pstmtSeq.setTimestamp(2, toDate);
pstmtSeq.setString(3, siteCode);
pstmtSeq.setString(4, custCode);
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
updateFlag(tranId, conn);
System.out.println("Inside Once -- already downloaded ");
}
else
{
if(!("S".equalsIgnoreCase(trfType)))
{
download(tranFileMip, downloadLocEmail);
retString = sendMail(emailHash, conn);
deleteFile(filePath);
}
if(!("E".equalsIgnoreCase(trfType)))
{
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;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dty + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
}
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
}
else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" ))
{
if(!("S".equalsIgnoreCase(trfType)))
{
download(tranFileMip, downloadLocEmail);
retString = sendMail(emailHash, conn);
deleteFile(filePath);
}
if(!("E".equalsIgnoreCase(trfType)))
{
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;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dty + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
}
}
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading]
if(retString!=null && !retString.equalsIgnoreCase("ERROR"))
{
sql = "UPDATE INVOICE SET "
+" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE ";
if(!("E".equalsIgnoreCase(trfType)))
{
sql += ", DOWNLOAD_FILE_SEQ = "+recCounter;
}
sql +=" WHERE INVOICE_ID = ? ";
pstmtSeq = conn.prepareStatement(sql);
pstmtSeq.setString( 1, tranId );
int rowCnt = pstmtSeq.executeUpdate();
System.out.println("Successfully updated =="+rowCnt);
if(rowCnt >= 1)
{
conn.commit();
}
else
{
conn.rollback();
}
pstmtSeq.close();
pstmtSeq = null;
}
pstmtSeq2.close();
pstmtSeq2 = 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.
}
}
}
catch( Exception pte )
{
try{
conn.rollback();
conn.close();
conn = null;
}catch( Exception ex ){}
pte.printStackTrace();
}
}
}
public void updateFlag(String tranId, Connection conn)throws RemoteException, ITMException
{
java.sql.PreparedStatement pstmtSeq2 = null;
try
{
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;
}
catch (Exception e)
{
System.out.println("Unable to updateFlag (" + e.getMessage() + ")");
}
}
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;
System.out.println("Inside download ");
}
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 = "";
String cc = "";
boolean debug = false;
String subject = "",text = "";
String xmlDataFilePath = "";
java.sql.PreparedStatement pstmtSeq = null;
java.sql.ResultSet rsSeq = null;
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);
// 28/04/10 Sachin---Start to check CC address is present
pstmtSeq = conn.prepareStatement( "SELECT VAR_VALUE FROM DISPARM "
+" WHERE PRD_CODE='999999' AND VAR_NAME = 'INV_MAIL_CC' " );
rsSeq = pstmtSeq.executeQuery();
if( rsSeq.next() )
{
cc = rsSeq.getString( "VAR_VALUE" );
System.out.println("cc =="+ cc);
}
rsSeq.close();
rsSeq = null;
pstmtSeq.close();
pstmtSeq = null;
if(cc != null && cc.trim().length() > 0){
InternetAddress[] ccAddress = {new InternetAddress(cc)};
msg.setRecipients(Message.RecipientType.CC, ccAddress);
}
// 28/04/10 Sachin---End to check CC address is present
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 "";
}
}
\ No newline at end of file
/*******************************************
Title ExpiryProcess
Developed Date 3/9/2009
Modified By Ashwin on 05-Aug-10
// For Getting Processing Sites from Schedulers ActualParameter Instead of DISPARM
********************************************/
package ibase.webitm.ejb.sys;
import java.util.*;
import java.sql.*;
import ibase.system.config.ConnDriver;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import ibase.utility.CommonConstants;
import java.util.*;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.GenericUtility ;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.Date;
import java.text.SimpleDateFormat;
//import org.apache.commons.logging.LogFactory;
public class ExpiryProcess implements Schedule
{
ibase.utility.GenericUtility genericUtility = new ibase.utility.GenericUtility();
Object[] aobj = new Object[4];
public String schedule( HashMap map )throws RemoteException, ITMException
{
return "";
}
public String schedule( String scheduleParamXML )throws RemoteException, ITMException
{
System.out.println("\n\n\n\n\n ::::::::::::::::::: ExpiryProcess :::::::::::::::::::::::");
PreparedStatement pstmt = null ;
ResultSet rs = null ;
Connection conn=null;
String sql="";
String userInfoList = null;
String isIntractive = null;
String objName = null;
String varValue = "",varvalue2 = "",varvalue1="";
String addlValue =null;
//String addlValue = "";
Timestamp frDate = null ,currDate=null,addlValueTm =null,currAppTime = null;//addlValue = null;
SimpleDateFormat currAppdate = null;
String lsFromdateStr ="",siteCode = "",retString="",xtraParams="",despid = "",drnoteDateStr = "";
Date lsFromdateDt = null,dateValue = null;
String freshDescr="";
String locCode="" ,expLoc = "",nearExpLoc = "" ;
StringBuffer filterString = new StringBuffer();
StringBuffer fltrArg = null;
StringTokenizer stringTokenizer = null;
String varName = "";
double timdifferance = 0.00;
try
{
if( conn == null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
}
System.out.println(" scheduleParamXML [" + scheduleParamXML + "]");
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML );
NodeList paramList = userInfoDom.getElementsByTagName( "SCHEDULE" );
Node currDetail = null ;
int noOfParam = paramList.getLength();
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ )
{
currDetail = paramList.item(paramCnt);
siteCode = currDetail.getAttributes().getNamedItem("id").getNodeValue();
}
//----- Changes Start By Ashwin On 05-Aug-10 - Begin
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
String DisparmSites = "";
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = userInfoDom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
DisparmSites=childNode.getFirstChild().getNodeValue();
}
}
}
System.out.println("\n\n :::: Disparm Sites["+DisparmSites+"]");
//----- Changes End By Ashwin On 05-Aug-10 - End
// code to be migrate
java.sql.Timestamp drnoteDate = new java.sql.Timestamp( System.currentTimeMillis() );
drnoteDateStr = genericUtility.getValidDateString(drnoteDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
sql="select var_value,descr "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'ALLOC_FGLOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
locCode = rs.getString("var_value") == null?"":rs.getString("var_value");
freshDescr = rs.getString("descr") == null?"":rs.getString("descr") ;
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
sql="select var_value "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'NEAREXP_LOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
nearExpLoc = rs.getString("var_value")==null?"":rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
sql="select var_value "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'EXP_LOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
expLoc = rs.getString("var_value")==null?"":rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
// end of code
//sql = "select site_code from site " ;
//-- Commented By Ashwin On 05-Aug-10 - Begin
// So as to get Sites from scheduler ActualParameter Instead of DISPLARM
/*sql = " SELECT VAR_VALUE FROM DISPARM WHERE PRD_CODE='999999' AND VAR_NAME = 'AUTONEARCHARGESITE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
varName = rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
stringTokenizer = new StringTokenizer(varName ,",");
*/
//Changes Done by Ashwin On 05-Aug-10 - End
stringTokenizer = new StringTokenizer(DisparmSites ,",");
while(stringTokenizer.hasMoreElements())
{
filterString.append(stringTokenizer.nextToken()).append("\t");
filterString.append(drnoteDateStr).append("\t");
filterString.append("00").append("\t");
filterString.append("ZZ").append("\t");
//filterString.append("").append("\t");// changes for nearexpiry and expiry
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(nearExpLoc).append("\t"); // nearexpiery to nearexppiery
fltrArg.append(nearExpLoc).append("\t");
fltrArg.append("E").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(locCode).append("\t"); //fresh to fresh using nearExpieryLocation
fltrArg.append(locCode).append("\t");
fltrArg.append("N").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(locCode).append("\t"); //fresh to fresh using ExpieryLocaltion
fltrArg.append(locCode).append("\t");
fltrArg.append("E").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
filterString.setLength(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
} // end of schedule
public String callNvo( String filterData, String objName, String serviceCode, Connection conn ) throws ITMException
{
String methodName = "";
String retString = "";
String serviceURI = "";
String actionURI = "";
String selectSql = "" , selectSqlSec = "" ;
String businessObj = "",xtraParams = "";
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
//businessObj = "nvo_bo_finance_charge_calc";
selectSql = "SELECT comp_name FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND service_code = ? ";
System.out.println("\nselectSql :: "+selectSql);
pstmt = conn.prepareStatement(selectSql);
pstmt.setString(1,objName);
pstmt.setString(2,serviceCode);
rs = pstmt.executeQuery();
//stmt = conn.createStatement();
//rs = stmt.executeQuery(selectSql);
if ( rs.next() )
{
businessObj = rs.getString( "comp_name" );
}
System.out.println("businessObj :: "+businessObj);
rs.close();
pstmt.close();
rs = null;
pstmt = null;
selectSqlSec = "SELECT SERVICE_URI, METHOD_NAME FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
System.out.println("\nselectSql :: "+selectSqlSec);
pstmt = conn.prepareStatement(selectSqlSec);
pstmt.setString(1,serviceCode);
rs = pstmt.executeQuery();
//rs = stmt.executeQuery(selectSql);
if ( rs.next() )
{
serviceURI = rs.getString( "SERVICE_URI" );
methodName = rs.getString( "METHOD_NAME" );
}
actionURI = "http://NvoServiceurl.org/"+methodName;
System.out.println("\n actionURI :: "+actionURI);
Service service = new Service();
Call call = ( Call )service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[4];
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tab_xml_data_1"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "dummy"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(businessObj);
aobj[1] = new String(filterData);
aobj[2] = new String( "" );
aobj[3] = new String( xtraParams );// passed blank as It can not be created from scheduler
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke( aobj );
System.out.println("Return value [" + retString +"]");
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if (pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{ e.printStackTrace();}
}
return retString ;
}
/*******************************************
Title ExpiryProcess
Developed Date 3/9/2009
Modified By Ashwin on 05-Aug-10
// For Getting Processing Sites from Schedulers ActualParameter Instead of DISPARM
********************************************/
package ibase.webitm.ejb.sys;
import java.util.*;
import java.sql.*;
import ibase.system.config.ConnDriver;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import ibase.utility.CommonConstants;
import java.util.*;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.GenericUtility ;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.Date;
import java.text.SimpleDateFormat;
//import org.apache.commons.logging.LogFactory;
public class ExpiryProcess implements Schedule
{
ibase.utility.GenericUtility genericUtility = new ibase.utility.GenericUtility();
Object[] aobj = new Object[4];
//Added By Manoj dtd 05/11/2012 implement abstract method
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule( HashMap map )throws RemoteException, ITMException
{
return "";
}
public String schedule( String scheduleParamXML )throws RemoteException, ITMException
{
System.out.println("\n\n\n\n\n ::::::::::::::::::: ExpiryProcess :::::::::::::::::::::::");
PreparedStatement pstmt = null ;
ResultSet rs = null ;
Connection conn=null;
String sql="";
String userInfoList = null;
String isIntractive = null;
String objName = null;
String varValue = "",varvalue2 = "",varvalue1="";
String addlValue =null;
//String addlValue = "";
Timestamp frDate = null ,currDate=null,addlValueTm =null,currAppTime = null;//addlValue = null;
SimpleDateFormat currAppdate = null;
String lsFromdateStr ="",siteCode = "",retString="",xtraParams="",despid = "",drnoteDateStr = "";
Date lsFromdateDt = null,dateValue = null;
String freshDescr="";
String locCode="" ,expLoc = "",nearExpLoc = "" ;
StringBuffer filterString = new StringBuffer();
StringBuffer fltrArg = null;
StringTokenizer stringTokenizer = null;
String varName = "";
double timdifferance = 0.00;
try
{
if( conn == null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
}
System.out.println(" scheduleParamXML [" + scheduleParamXML + "]");
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML );
NodeList paramList = userInfoDom.getElementsByTagName( "SCHEDULE" );
Node currDetail = null ;
int noOfParam = paramList.getLength();
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ )
{
currDetail = paramList.item(paramCnt);
siteCode = currDetail.getAttributes().getNamedItem("id").getNodeValue();
}
//----- Changes Start By Ashwin On 05-Aug-10 - Begin
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
String DisparmSites = "";
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = userInfoDom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
DisparmSites=childNode.getFirstChild().getNodeValue();
}
}
}
System.out.println("\n\n :::: Disparm Sites["+DisparmSites+"]");
//----- Changes End By Ashwin On 05-Aug-10 - End
// code to be migrate
java.sql.Timestamp drnoteDate = new java.sql.Timestamp( System.currentTimeMillis() );
drnoteDateStr = genericUtility.getValidDateString(drnoteDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
sql="select var_value,descr "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'ALLOC_FGLOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
locCode = rs.getString("var_value") == null?"":rs.getString("var_value");
freshDescr = rs.getString("descr") == null?"":rs.getString("descr") ;
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
sql="select var_value "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'NEAREXP_LOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
nearExpLoc = rs.getString("var_value")==null?"":rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
sql="select var_value "
+"from disparm "
+ "where prd_code = '999999' "
+ "and var_name = 'EXP_LOC' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
expLoc = rs.getString("var_value")==null?"":rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
// end of code
//sql = "select site_code from site " ;
//-- Commented By Ashwin On 05-Aug-10 - Begin
// So as to get Sites from scheduler ActualParameter Instead of DISPLARM
/*sql = " SELECT VAR_VALUE FROM DISPARM WHERE PRD_CODE='999999' AND VAR_NAME = 'AUTONEARCHARGESITE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
varName = rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
stringTokenizer = new StringTokenizer(varName ,",");
*/
//Changes Done by Ashwin On 05-Aug-10 - End
stringTokenizer = new StringTokenizer(DisparmSites ,",");
while(stringTokenizer.hasMoreElements())
{
filterString.append(stringTokenizer.nextToken()).append("\t");
filterString.append(drnoteDateStr).append("\t");
filterString.append("00").append("\t");
filterString.append("ZZ").append("\t");
//filterString.append("").append("\t");// changes for nearexpiry and expiry
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(nearExpLoc).append("\t"); // nearexpiery to nearexppiery
fltrArg.append(nearExpLoc).append("\t");
fltrArg.append("E").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(locCode).append("\t"); //fresh to fresh using nearExpieryLocation
fltrArg.append(locCode).append("\t");
fltrArg.append("N").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
fltrArg = new StringBuffer( filterString.toString() );
fltrArg.append(locCode).append("\t"); //fresh to fresh using ExpieryLocaltion
fltrArg.append(locCode).append("\t");
fltrArg.append("E").append("\t");
fltrArg.append("\n");
retString = callNvo( fltrArg.toString(), "near_expiry", "pr_default_1", conn );
filterString.setLength(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
} // end of schedule
public String callNvo( String filterData, String objName, String serviceCode, Connection conn ) throws ITMException
{
String methodName = "";
String retString = "";
String serviceURI = "";
String actionURI = "";
String selectSql = "" , selectSqlSec = "" ;
String businessObj = "",xtraParams = "";
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
//businessObj = "nvo_bo_finance_charge_calc";
selectSql = "SELECT comp_name FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND service_code = ? ";
System.out.println("\nselectSql :: "+selectSql);
pstmt = conn.prepareStatement(selectSql);
pstmt.setString(1,objName);
pstmt.setString(2,serviceCode);
rs = pstmt.executeQuery();
//stmt = conn.createStatement();
//rs = stmt.executeQuery(selectSql);
if ( rs.next() )
{
businessObj = rs.getString( "comp_name" );
}
System.out.println("businessObj :: "+businessObj);
rs.close();
pstmt.close();
rs = null;
pstmt = null;
selectSqlSec = "SELECT SERVICE_URI, METHOD_NAME FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
System.out.println("\nselectSql :: "+selectSqlSec);
pstmt = conn.prepareStatement(selectSqlSec);
pstmt.setString(1,serviceCode);
rs = pstmt.executeQuery();
//rs = stmt.executeQuery(selectSql);
if ( rs.next() )
{
serviceURI = rs.getString( "SERVICE_URI" );
methodName = rs.getString( "METHOD_NAME" );
}
actionURI = "http://NvoServiceurl.org/"+methodName;
System.out.println("\n actionURI :: "+actionURI);
Service service = new Service();
Call call = ( Call )service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[4];
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tab_xml_data_1"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "dummy"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(businessObj);
aobj[1] = new String(filterData);
aobj[2] = new String( "" );
aobj[3] = new String( xtraParams );// passed blank as It can not be created from scheduler
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke( aobj );
System.out.println("Return value [" + retString +"]");
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if (pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{ e.printStackTrace();}
}
return retString ;
}
}
\ No newline at end of file
/*******************************************
Developed Date 3/9/2009
Modified By Ashwin on 05-Aug-10
// For Getting Processing Sites from Scheduler's ActualParameter Instead of FINPARM
********************************************/
package ibase.webitm.ejb.sys;
import java.util.*;
import java.sql.*;
import ibase.system.config.ConnDriver;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import ibase.utility.CommonConstants;
import java.util.*;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.GenericUtility ;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.Date;
import java.text.SimpleDateFormat;
//import org.apache.commons.logging.LogFactory;
public class FinChargeCalcPrc implements Schedule
{
ibase.utility.GenericUtility genericUtility = new ibase.utility.GenericUtility();
public String schedule( HashMap map )throws RemoteException, ITMException
{
return "";
}
public String schedule( String scheduleParamXML )throws RemoteException, ITMException
{
System.out.println("\n\n::::: FinChargeCalcPrc ::::::::: ");
System.out.println("\n\n::::: INside scheduleParamXML [" + scheduleParamXML + "]");
PreparedStatement pstmt = null ;
ResultSet rs = null ;
Connection conn=null;
String sql="";
String userInfoList = null;
String isIntractive = null;
String objName = null;
String downloadLoc = null;
String varValue = "",varvalue2 = "",varvalue1="",drnoteDateStr = "";
//String addlValue =null;
//String addlValue = "";
Timestamp frDate = null ,currDate=null,addlValueTm =null;//addlValue = null;
SimpleDateFormat currAppdate = null;
String lsFromdateStr ="",siteCode = "",retString="",despid = "",addlValueMinFin="",varValueMinFin="",addlValueStr="",frDateStr = "";
Timestamp lsFromdateDt = null,dateValue = null,addlValue=null;
ArrayList paramListArr = new ArrayList();
double timdifferance = 0.00;
StringBuffer filterString = null;
filterString = new StringBuffer();
StringTokenizer stringTokenizer = null;
String varName = "";
String chgUse = "";
try
{
if( conn == null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
}
System.out.println(" scheduleParamXML [" + scheduleParamXML + "]");
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML );
//----- Changes Start By Ashwin 31/07/10 - Begin
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
String finSites = "";
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = userInfoDom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
finSites=childNode.getFirstChild().getNodeValue();
}
}
}
System.out.println("\n\n :::: finSites["+finSites+"]");
//----- Changes End By Ashwin 31/07/10 - End
NodeList paramList = userInfoDom.getElementsByTagName( "SCHEDULE" );
Node currDetail = null ;
int noOfParam = paramList.getLength();
//System.out.println("noOfParam>>>>>"+noOfParam);
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ )
{
currDetail = paramList.item(paramCnt);
siteCode = currDetail.getAttributes().getNamedItem("id").getNodeValue();
}
//start code 08/10/09
chgUse = userInfoDom.getElementsByTagName( "loginCode" ).item(0).getFirstChild().getNodeValue();
//System.out.println("loginCodeBase>>>"+loginCodeBase);
//end code 08/10/09
// code to be migrate for itmdefault
java.sql.Timestamp drnoteDate = new java.sql.Timestamp( System.currentTimeMillis() );
drnoteDateStr = genericUtility.getValidDateString(drnoteDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
//System.out.println("drnoteDate>>>"+drnoteDate);
sql="select var_value, addl_value "
+" from finparm "
+" where var_name='FIN_CHARGE_DATE' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
varValue = rs.getString("var_value")==null?"":rs.getString("var_value");
addlValueStr = rs.getString("addl_value") ;
}
System.out.println(">>>>>>>>>>>>value>>>>>>>" + varValue);
System.out.println(">>>>>>>>>>>>addlValue>>>>>>>" + addlValueStr);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
if(varValue==null || varValue.trim().length()==0)
{
varValue = "P";
}
if( "P".equalsIgnoreCase( varValue ) && addlValueStr != null )
{
// 12/09/09 manoharan first change to db date format
//addlValueStr = genericUtility.getValidDateString(addlValue.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
frDateStr = addlValueStr ; //genericUtility.getValidDateString(addlValueStr.toString(), genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
// end 12/09/09 manoharan first change to db date format
//frDate = java.sql.Timestamp.valueOf(frDateStr + " 00:00:00");
System.out.println("frDateStr>>>>>>>>"+frDateStr);
}else if( "U".equalsIgnoreCase( varValue ) )
{
frDate =null;
}
else if( "F".equalsIgnoreCase( varValue ) )
{
sql=" select fr_date from acctprd where code = ( select acct_prd from parameter )" ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
frDate = rs.getTimestamp("fr_date");
}
//System.out.println("frDate>>>>>>>>"+frDate);
frDateStr = genericUtility.getValidDateString(frDate.toString(),genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
//System.out.println("frDateStr>>>>>>>>"+frDateStr);
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select var_value, addl_value from finparm "
+" where prd_code = '999999' and var_name ='FINCHG_START_DATE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varvalue1 = rs.getString("var_value");
varvalue2 = rs.getString("addl_value");
}
//System.out.println("varvalue1>>>>>>>>"+varvalue1);
//System.out.println("varvalue2>>>>>>>>"+varvalue2);
rs.close();
rs=null;
pstmt.close();
pstmt=null;
/*if(varvalue2 == null || varvalue2.trim().length()== 0 )
{
lsFromdateStr = varvalue1 ;
}
else
{
lsFromdateStr = varvalue1 + varvalue2 ;
}*/
//lsFromdateStr = genericUtility.getValidDateString(lsFromdateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
//lsFromdateDt = java.sql.Timestamp.valueOf(lsFromdateStr + " 00:00:00");
/*if ( !"NULLFOUND".equalsIgnoreCase( lsFromdateStr ) && (lsFromdateStr.trim().length() > 0))
{
frDateStr = genericUtility.getValidDateString(frDate.toString(),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
//frDate = java.sql.Timestamp.valueOf(frDateStr + " 00:00:00");
timdifferance = genericUtility.timeDiff(frDate,lsFromdateDt);
if(timdifferance <0)
{
frDateStr = lsFromdateStr ;
}
}*/
if ( varvalue2 !=null &&(varvalue2.trim().length() > 0) )
{
//System.out.println("varvalue2.toString()>>>>>>>>"+varvalue2.toString());
java.sql.Timestamp lsFromdateDate = Timestamp.valueOf(genericUtility.getValidDateString(varvalue2, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
java.sql.Timestamp frDatedate = Timestamp.valueOf(genericUtility.getValidDateString(frDateStr.toString(), genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
if(frDatedate.compareTo (lsFromdateDate) < 0 )
{
frDateStr = lsFromdateStr ;
frDateStr = genericUtility.getValidDateString(frDateStr.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
System.out.println("frDateStr>>>>>>>>"+frDateStr);
}
}
}
sql=" select var_value "
+ "from finparm "
+ " where var_name='TRANTYPE_FINCHRGCALC' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varValue = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
}
rs.close();
rs=null;
pstmt.close();
pstmt = null;
sql=" select var_value,addl_value "
+ "from finparm "
+ " where var_name='MIN_FINCHG_AR' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varValueMinFin = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
addlValueMinFin = rs.getString("addl_value")==null?"":rs.getString("addl_value").trim();
}
//System.out.println("varValueMinFin>>>>>>>>"+varValueMinFin);
//System.out.println("addlValueMinFin>>>>>>>>"+addlValueMinFin);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
sql=" select var_value ,addl_value "
+ "from finparm "
+ " where var_name='ACCT_AR_FINCHG_AR' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varvalue1 = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
varvalue2 = rs.getString("addl_value")==null?"":rs.getString("addl_value").trim();
}
//System.out.println("varvalue1>>>>>>>>"+varvalue1);
//System.out.println("varvalue2>>>>>>>>"+varvalue2);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
// end of code
//sql = "select site_code from site " ;
//sql= "select * from disAUTONEARCHARGESITE
String xtraParams = getXtraParams( userInfoDom , siteCode , conn );
System.out.println("xtraParams...\n"+xtraParams);
/*Changes Done By ashwin on 31/07/10 - Begin
sql = " SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE='999999' AND VAR_NAME='AUTOFINCHARGESITE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
varName = rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
stringTokenizer = new StringTokenizer(varName ,",");*/
//Changes Done By ashwin on31/07/10 - End
//So as to get Sites from scheduler ActualParameter Instead of FINPARM
stringTokenizer = new StringTokenizer(finSites ,",");
//Changes Done By ashwin on 7/31/2010
while(stringTokenizer.hasMoreElements())
{
filterString.append(stringTokenizer.nextToken()).append("\t");
filterString.append(frDateStr).append("\t");
filterString.append(drnoteDateStr).append("\t");
filterString.append(varValueMinFin + addlValueMinFin).append("\t");
filterString.append(drnoteDate).append("\t");
filterString.append(varvalue1).append("\t");
filterString.append(varvalue1).append("\t");
filterString.append("0").append("\t");
filterString.append("Z").append("\t");
filterString.append("Y").append("\t");
filterString.append("Y").append("\t");
filterString.append(varValue ).append("\t");
filterString.append("0").append("\t");
filterString.append("\n");
System.out.println("frDateStr>>>2>>>>>"+frDateStr);
System.out.println("Data sent ["+filterString.toString() + "]");
// added chgUse in callNvo() on 08/10/09 for xtrapram
retString = callNvo( filterString.toString(), "finance_charge_calc", "pr_default_1",xtraParams, conn );
// end
filterString.setLength(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
} // end of schedule
public String callNvo( String filterData, String objName, String serviceCode,String xtraParams , Connection conn ) throws ITMException
{
String methodName = "";
String retString = "";
String serviceURI = "";
String actionURI = "";
String selectSql = "";
String businessObj = "";
PreparedStatement pStmt = null;
ResultSet rs = null;
try
{
//businessObj = "nvo_bo_finance_charge_calc";
selectSql = "SELECT comp_name FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND service_code = ? ";
//System.out.println("\nselectSql :: "+selectSql);
pStmt = conn.prepareStatement(selectSql);
pStmt.setString(1,objName);
pStmt.setString(2,serviceCode);
rs = pStmt.executeQuery();
if ( rs.next() )
{
businessObj = rs.getString( "comp_name" );
}
System.out.println("\n businessObj :: ["+businessObj+"]");
rs.close();
rs=null;
pStmt.close();
pStmt = null;
selectSql = "SELECT SERVICE_URI, METHOD_NAME FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
System.out.println("\nselectSql :: "+selectSql);
pStmt = conn.prepareStatement(selectSql);
pStmt.setString(1,serviceCode);
rs = pStmt.executeQuery();
if ( rs.next() )
{
serviceURI = rs.getString( "SERVICE_URI" );
methodName = rs.getString( "METHOD_NAME" );
}
rs.close();
rs=null;
pStmt.close();
pStmt = null;
System.out.println("\n serviceURI :: ["+serviceURI+"]");
System.out.println("\n methodName :: ["+methodName+"]");
actionURI = "http://NvoServiceurl.org/"+methodName;
System.out.println("\n actionURI :: ["+actionURI+"]");
Service service = new Service();
Call call = ( Call )service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[4];
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tab_xml_data_1"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "dummy"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(businessObj);
aobj[1] = new String(filterData);
aobj[2] = new String( "" );
aobj[3] = new String( xtraParams );// passed blank as It can not be created from scheduler
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke( aobj );
System.out.println("Return value [" + retString +"]"); // leave this
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(pStmt != null )
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{e.printStackTrace();}
}
return retString ;
}
private Timestamp getCurrdateAppFormat()
{
String s = "";
Timestamp timestamp = null;
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
java.util.Date date = null;
timestamp = new Timestamp(System.currentTimeMillis());
//System.out.println(genericUtility.getDBDateFormat());
SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = simpledateformat.parse(timestamp.toString());
timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
//System.out.println("timestamp is ==>"+timestamp);
}
catch(Exception exception)
{
System.out.println("Exception in getCurrdateAppFormat " + exception.getMessage());
}
return timestamp;
}
private String getXtraParams(Document userInfoDom ,String siteCode , Connection conn )throws Exception
{
StringBuffer xtraParamsBuff = new StringBuffer();
PreparedStatement pstmt =null;
ResultSet rs = null;
String XTRA_PARAMS_SEPARATOR = "~~";
String loginCode="",loginEmpCode="",loginSiteCode="",entityCode="",profileId="",userType="";
String runMode="",chgTerm="",chgUser="",remoteHost="",sql="", charEnc="";
loginCode = userInfoDom.getElementsByTagName( "loginCode" ).item(0).getFirstChild().getNodeValue();
charEnc = userInfoDom.getElementsByTagName( "charEnc" ).item(0).getFirstChild().getNodeValue();
remoteHost = userInfoDom.getElementsByTagName( "remoteHost" ).item(0).getFirstChild().getNodeValue();
sql="select emp_code,entity_code,profile_id,user_type,chg_term,chg_user from users where code = ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,loginCode);
//pstmt.setString(2,siteCode);
//pstmt.setString(3,itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
loginEmpCode = rs.getString("emp_code")==null?"":rs.getString("emp_code");
entityCode = rs.getString("entity_code")==null?"":rs.getString("entity_code");
profileId = rs.getString("PROFILE_ID")==null?"":rs.getString("PROFILE_ID");
userType = rs.getString("USER_TYPE")==null?"":rs.getString("USER_TYPE");
chgTerm = rs.getString("CHG_TERM")==null?"":rs.getString("CHG_TERM");
chgUser = rs.getString("CHG_USER")==null?"":rs.getString("CHG_USER");
}
pstmt.close();
pstmt=null;
rs.close();
rs=null;
xtraParamsBuff.append("loginCode=" + loginCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginEmpCode=" + loginEmpCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginSiteCode=" + siteCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("entityCode=" + entityCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("profileId=" + profileId);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("userType=" + userType);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("runMode=I");
//xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_lang=" + this.user_lang);
//xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_country=" + this.user_country);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("charEnc=" +charEnc );
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("termId="+remoteHost);
// changes by madhup 10/02/07
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("chgTerm=" + chgTerm);
return xtraParamsBuff.toString();
}
/*******************************************
Developed Date 3/9/2009
Modified By Ashwin on 05-Aug-10
// For Getting Processing Sites from Scheduler's ActualParameter Instead of FINPARM
********************************************/
package ibase.webitm.ejb.sys;
import java.util.*;
import java.sql.*;
import ibase.system.config.ConnDriver;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import ibase.utility.CommonConstants;
import java.util.*;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.GenericUtility ;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.Date;
import java.text.SimpleDateFormat;
//import org.apache.commons.logging.LogFactory;
public class FinChargeCalcPrc implements Schedule
{
ibase.utility.GenericUtility genericUtility = new ibase.utility.GenericUtility();
//Added By Manoj dtd 05/11/2012 implement abstract method
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule( HashMap map )throws RemoteException, ITMException
{
return "";
}
public String schedule( String scheduleParamXML )throws RemoteException, ITMException
{
System.out.println("\n\n::::: FinChargeCalcPrc ::::::::: ");
System.out.println("\n\n::::: INside scheduleParamXML [" + scheduleParamXML + "]");
PreparedStatement pstmt = null ;
ResultSet rs = null ;
Connection conn=null;
String sql="";
String userInfoList = null;
String isIntractive = null;
String objName = null;
String downloadLoc = null;
String varValue = "",varvalue2 = "",varvalue1="",drnoteDateStr = "";
//String addlValue =null;
//String addlValue = "";
Timestamp frDate = null ,currDate=null,addlValueTm =null;//addlValue = null;
SimpleDateFormat currAppdate = null;
String lsFromdateStr ="",siteCode = "",retString="",despid = "",addlValueMinFin="",varValueMinFin="",addlValueStr="",frDateStr = "";
Timestamp lsFromdateDt = null,dateValue = null,addlValue=null;
ArrayList paramListArr = new ArrayList();
double timdifferance = 0.00;
StringBuffer filterString = null;
filterString = new StringBuffer();
StringTokenizer stringTokenizer = null;
String varName = "";
String chgUse = "";
try
{
if( conn == null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
}
System.out.println(" scheduleParamXML [" + scheduleParamXML + "]");
Document userInfoDom = new ibase.utility.GenericUtility().parseString( scheduleParamXML );
//----- Changes Start By Ashwin 31/07/10 - Begin
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
String finSites = "";
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = userInfoDom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
finSites=childNode.getFirstChild().getNodeValue();
}
}
}
System.out.println("\n\n :::: finSites["+finSites+"]");
//----- Changes End By Ashwin 31/07/10 - End
NodeList paramList = userInfoDom.getElementsByTagName( "SCHEDULE" );
Node currDetail = null ;
int noOfParam = paramList.getLength();
//System.out.println("noOfParam>>>>>"+noOfParam);
for( int paramCnt = 0; paramCnt < noOfParam ; paramCnt++ )
{
currDetail = paramList.item(paramCnt);
siteCode = currDetail.getAttributes().getNamedItem("id").getNodeValue();
}
//start code 08/10/09
chgUse = userInfoDom.getElementsByTagName( "loginCode" ).item(0).getFirstChild().getNodeValue();
//System.out.println("loginCodeBase>>>"+loginCodeBase);
//end code 08/10/09
// code to be migrate for itmdefault
java.sql.Timestamp drnoteDate = new java.sql.Timestamp( System.currentTimeMillis() );
drnoteDateStr = genericUtility.getValidDateString(drnoteDate.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
//System.out.println("drnoteDate>>>"+drnoteDate);
sql="select var_value, addl_value "
+" from finparm "
+" where var_name='FIN_CHARGE_DATE' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement( sql );
rs = pstmt.executeQuery();
if( rs.next() )
{
varValue = rs.getString("var_value")==null?"":rs.getString("var_value");
addlValueStr = rs.getString("addl_value") ;
}
System.out.println(">>>>>>>>>>>>value>>>>>>>" + varValue);
System.out.println(">>>>>>>>>>>>addlValue>>>>>>>" + addlValueStr);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
if(varValue==null || varValue.trim().length()==0)
{
varValue = "P";
}
if( "P".equalsIgnoreCase( varValue ) && addlValueStr != null )
{
// 12/09/09 manoharan first change to db date format
//addlValueStr = genericUtility.getValidDateString(addlValue.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
frDateStr = addlValueStr ; //genericUtility.getValidDateString(addlValueStr.toString(), genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
// end 12/09/09 manoharan first change to db date format
//frDate = java.sql.Timestamp.valueOf(frDateStr + " 00:00:00");
System.out.println("frDateStr>>>>>>>>"+frDateStr);
}else if( "U".equalsIgnoreCase( varValue ) )
{
frDate =null;
}
else if( "F".equalsIgnoreCase( varValue ) )
{
sql=" select fr_date from acctprd where code = ( select acct_prd from parameter )" ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
frDate = rs.getTimestamp("fr_date");
}
//System.out.println("frDate>>>>>>>>"+frDate);
frDateStr = genericUtility.getValidDateString(frDate.toString(),genericUtility.getDBDateFormat(), genericUtility.getApplDateFormat());
//System.out.println("frDateStr>>>>>>>>"+frDateStr);
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select var_value, addl_value from finparm "
+" where prd_code = '999999' and var_name ='FINCHG_START_DATE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varvalue1 = rs.getString("var_value");
varvalue2 = rs.getString("addl_value");
}
//System.out.println("varvalue1>>>>>>>>"+varvalue1);
//System.out.println("varvalue2>>>>>>>>"+varvalue2);
rs.close();
rs=null;
pstmt.close();
pstmt=null;
/*if(varvalue2 == null || varvalue2.trim().length()== 0 )
{
lsFromdateStr = varvalue1 ;
}
else
{
lsFromdateStr = varvalue1 + varvalue2 ;
}*/
//lsFromdateStr = genericUtility.getValidDateString(lsFromdateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
//lsFromdateDt = java.sql.Timestamp.valueOf(lsFromdateStr + " 00:00:00");
/*if ( !"NULLFOUND".equalsIgnoreCase( lsFromdateStr ) && (lsFromdateStr.trim().length() > 0))
{
frDateStr = genericUtility.getValidDateString(frDate.toString(),genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat());
//frDate = java.sql.Timestamp.valueOf(frDateStr + " 00:00:00");
timdifferance = genericUtility.timeDiff(frDate,lsFromdateDt);
if(timdifferance <0)
{
frDateStr = lsFromdateStr ;
}
}*/
if ( varvalue2 !=null &&(varvalue2.trim().length() > 0) )
{
//System.out.println("varvalue2.toString()>>>>>>>>"+varvalue2.toString());
java.sql.Timestamp lsFromdateDate = Timestamp.valueOf(genericUtility.getValidDateString(varvalue2, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
java.sql.Timestamp frDatedate = Timestamp.valueOf(genericUtility.getValidDateString(frDateStr.toString(), genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
if(frDatedate.compareTo (lsFromdateDate) < 0 )
{
frDateStr = lsFromdateStr ;
frDateStr = genericUtility.getValidDateString(frDateStr.toString(),genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
System.out.println("frDateStr>>>>>>>>"+frDateStr);
}
}
}
sql=" select var_value "
+ "from finparm "
+ " where var_name='TRANTYPE_FINCHRGCALC' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varValue = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
}
rs.close();
rs=null;
pstmt.close();
pstmt = null;
sql=" select var_value,addl_value "
+ "from finparm "
+ " where var_name='MIN_FINCHG_AR' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varValueMinFin = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
addlValueMinFin = rs.getString("addl_value")==null?"":rs.getString("addl_value").trim();
}
//System.out.println("varValueMinFin>>>>>>>>"+varValueMinFin);
//System.out.println("addlValueMinFin>>>>>>>>"+addlValueMinFin);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
sql=" select var_value ,addl_value "
+ "from finparm "
+ " where var_name='ACCT_AR_FINCHG_AR' "
+" and prd_code='999999' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() )
{
varvalue1 = rs.getString("var_value")==null?"":rs.getString("var_value").trim();
varvalue2 = rs.getString("addl_value")==null?"":rs.getString("addl_value").trim();
}
//System.out.println("varvalue1>>>>>>>>"+varvalue1);
//System.out.println("varvalue2>>>>>>>>"+varvalue2);
rs.close();
rs=null;
pstmt.close();
pstmt = null;
// end of code
//sql = "select site_code from site " ;
//sql= "select * from disAUTONEARCHARGESITE
String xtraParams = getXtraParams( userInfoDom , siteCode , conn );
System.out.println("xtraParams...\n"+xtraParams);
/*Changes Done By ashwin on 31/07/10 - Begin
sql = " SELECT VAR_VALUE FROM FINPARM WHERE PRD_CODE='999999' AND VAR_NAME='AUTOFINCHARGESITE' " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
varName = rs.getString("var_value");
}
rs.close();
pstmt.close();
rs=null;
pstmt = null;
stringTokenizer = new StringTokenizer(varName ,",");*/
//Changes Done By ashwin on31/07/10 - End
//So as to get Sites from scheduler ActualParameter Instead of FINPARM
stringTokenizer = new StringTokenizer(finSites ,",");
//Changes Done By ashwin on 7/31/2010
while(stringTokenizer.hasMoreElements())
{
filterString.append(stringTokenizer.nextToken()).append("\t");
filterString.append(frDateStr).append("\t");
filterString.append(drnoteDateStr).append("\t");
filterString.append(varValueMinFin + addlValueMinFin).append("\t");
filterString.append(drnoteDate).append("\t");
filterString.append(varvalue1).append("\t");
filterString.append(varvalue1).append("\t");
filterString.append("0").append("\t");
filterString.append("Z").append("\t");
filterString.append("Y").append("\t");
filterString.append("Y").append("\t");
filterString.append(varValue ).append("\t");
filterString.append("0").append("\t");
filterString.append("\n");
System.out.println("frDateStr>>>2>>>>>"+frDateStr);
System.out.println("Data sent ["+filterString.toString() + "]");
// added chgUse in callNvo() on 08/10/09 for xtrapram
retString = callNvo( filterString.toString(), "finance_charge_calc", "pr_default_1",xtraParams, conn );
// end
filterString.setLength(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
} // end of schedule
public String callNvo( String filterData, String objName, String serviceCode,String xtraParams , Connection conn ) throws ITMException
{
String methodName = "";
String retString = "";
String serviceURI = "";
String actionURI = "";
String selectSql = "";
String businessObj = "";
PreparedStatement pStmt = null;
ResultSet rs = null;
try
{
//businessObj = "nvo_bo_finance_charge_calc";
selectSql = "SELECT comp_name FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND service_code = ? ";
//System.out.println("\nselectSql :: "+selectSql);
pStmt = conn.prepareStatement(selectSql);
pStmt.setString(1,objName);
pStmt.setString(2,serviceCode);
rs = pStmt.executeQuery();
if ( rs.next() )
{
businessObj = rs.getString( "comp_name" );
}
System.out.println("\n businessObj :: ["+businessObj+"]");
rs.close();
rs=null;
pStmt.close();
pStmt = null;
selectSql = "SELECT SERVICE_URI, METHOD_NAME FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
System.out.println("\nselectSql :: "+selectSql);
pStmt = conn.prepareStatement(selectSql);
pStmt.setString(1,serviceCode);
rs = pStmt.executeQuery();
if ( rs.next() )
{
serviceURI = rs.getString( "SERVICE_URI" );
methodName = rs.getString( "METHOD_NAME" );
}
rs.close();
rs=null;
pStmt.close();
pStmt = null;
System.out.println("\n serviceURI :: ["+serviceURI+"]");
System.out.println("\n methodName :: ["+methodName+"]");
actionURI = "http://NvoServiceurl.org/"+methodName;
System.out.println("\n actionURI :: ["+actionURI+"]");
Service service = new Service();
Call call = ( Call )service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[4];
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tab_xml_data_1"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "dummy"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(businessObj);
aobj[1] = new String(filterData);
aobj[2] = new String( "" );
aobj[3] = new String( xtraParams );// passed blank as It can not be created from scheduler
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke( aobj );
System.out.println("Return value [" + retString +"]"); // leave this
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(pStmt != null )
{
pStmt.close();
pStmt = null;
}
}
catch(Exception e)
{e.printStackTrace();}
}
return retString ;
}
private Timestamp getCurrdateAppFormat()
{
String s = "";
Timestamp timestamp = null;
GenericUtility genericUtility = GenericUtility.getInstance();
try
{
java.util.Date date = null;
timestamp = new Timestamp(System.currentTimeMillis());
//System.out.println(genericUtility.getDBDateFormat());
SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
date = simpledateformat.parse(timestamp.toString());
timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
//System.out.println("timestamp is ==>"+timestamp);
}
catch(Exception exception)
{
System.out.println("Exception in getCurrdateAppFormat " + exception.getMessage());
}
return timestamp;
}
private String getXtraParams(Document userInfoDom ,String siteCode , Connection conn )throws Exception
{
StringBuffer xtraParamsBuff = new StringBuffer();
PreparedStatement pstmt =null;
ResultSet rs = null;
String XTRA_PARAMS_SEPARATOR = "~~";
String loginCode="",loginEmpCode="",loginSiteCode="",entityCode="",profileId="",userType="";
String runMode="",chgTerm="",chgUser="",remoteHost="",sql="", charEnc="";
loginCode = userInfoDom.getElementsByTagName( "loginCode" ).item(0).getFirstChild().getNodeValue();
charEnc = userInfoDom.getElementsByTagName( "charEnc" ).item(0).getFirstChild().getNodeValue();
remoteHost = userInfoDom.getElementsByTagName( "remoteHost" ).item(0).getFirstChild().getNodeValue();
sql="select emp_code,entity_code,profile_id,user_type,chg_term,chg_user from users where code = ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,loginCode);
//pstmt.setString(2,siteCode);
//pstmt.setString(3,itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
loginEmpCode = rs.getString("emp_code")==null?"":rs.getString("emp_code");
entityCode = rs.getString("entity_code")==null?"":rs.getString("entity_code");
profileId = rs.getString("PROFILE_ID")==null?"":rs.getString("PROFILE_ID");
userType = rs.getString("USER_TYPE")==null?"":rs.getString("USER_TYPE");
chgTerm = rs.getString("CHG_TERM")==null?"":rs.getString("CHG_TERM");
chgUser = rs.getString("CHG_USER")==null?"":rs.getString("CHG_USER");
}
pstmt.close();
pstmt=null;
rs.close();
rs=null;
xtraParamsBuff.append("loginCode=" + loginCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginEmpCode=" + loginEmpCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginSiteCode=" + siteCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("entityCode=" + entityCode);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("profileId=" + profileId);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("userType=" + userType);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("runMode=I");
//xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_lang=" + this.user_lang);
//xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_country=" + this.user_country);
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("charEnc=" +charEnc );
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("termId="+remoteHost);
// changes by madhup 10/02/07
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("chgTerm=" + chgTerm);
return xtraParamsBuff.toString();
}
}
\ No newline at end of file
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