Commit 374d3e99 authored by vkadam's avatar vkadam

Scheduler to confirm voucher created by Channel Partner [F15FSUN004]


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98562 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4aa8dd2a
package ibase.webitm.ejb.fin;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
public class ConfVouchChPartnerSch implements Schedule
{
GenericUtility genericUtility = GenericUtility.getInstance();
FileOutputStream fos1 = null;
Calendar calendar = Calendar.getInstance();
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
String startDateStr = null;
@Override
public String schedule(String scheduleParamXML)throws Exception,ITMException
{
ibase.utility.UserInfoBean userInfo = null;
String loginSiteCode="",siteCode="";
try
{
Document dom = null;
String xtraParams = "",siteList="";
Node currDetail = null ;
int noOfParam=0;
System.out.println("@V@ scheduleParamXML["+scheduleParamXML+"]");
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
loginSiteCode = userInfo.getSiteCode();
System.out.println("@V@ IntializingLog "+ intializingLog("Chnl_Ptr_VouchConf_log"));
System.out.println("@V@ Log in Site code"+loginSiteCode+"]");
xtraParams = "loginEmpCode="+userInfo.getEmpCode()+"~~loginCode="+userInfo.getLoginCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode;
voucherConfirm(xtraParams);
}
catch (Exception e)
{
System.out.println("@V@ Exception :SplitSchedularSOrder :schedule :Exception :==>\n"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(fos1!=null)
{
fos1.close();
fos1=null;
}
}
catch(Exception e)
{
System.out.println( "@V@ Exception"+e.getMessage());
}
}
return "";
}
private String intializingLog(String fileName)
{
String log="intializingLog_Failed";
String strToWrite = "";
String currTime = null;
try{
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility.getDBDateFormat());
try
{
currTime = sdf1.format(new Timestamp(System.currentTimeMillis())).toString();
currTime = currTime.replaceAll("-","");
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
fileName = fileName+currTime+calendar.get(Calendar.HOUR)+""+calendar.get(Calendar.MINUTE)+".txt";
fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"EDI"+File.separator+fileName);
}
catch(Exception e)
{
System.out.println("@V@ Exception:-"+e.getMessage());
e.printStackTrace();
}
startDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
startDateStr = sdf1.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
fos1.write(("Fetching Records Started At " + startDateStr +"\r\n").getBytes());
}
catch(Exception e)
{
System.out.println("@V@ Exception2 :-"+e.getMessage());
e.printStackTrace();
}
log ="intializingLog_Successesfull";
return log;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
return input;
}
public void voucherConfirm(String xtraParams) throws ITMException
{
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pstmt=null;
ResultSet rs=null;
String sql="";
String tranId="",retString="";
try
{
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
sql="SELECT DISTINCT A.TRAN_ID FROM VOUCHER A,VOUCHRCP B,PORCP C,SUPPLIER D"
+ " WHERE A.TRAN_ID=B.TRAN_ID AND B.PRCP_ID=C.TRAN_ID"
+ " AND A.SUPP_CODE=D.SUPP_CODE"
+ " AND A.SITE_CODE IN (select site_code from site where site_code__cons LIKE '%__600')"
+ " AND A.SITE_CODE NOT IN(SELECT case when var_value is null then ' ' else var_value END"
+ " from finparm where var_name='DEFT_EXC_SITE_PORCPV' and prd_code='999999')"
+ " AND CASE WHEN A.CONFIRMED IS NULL THEN 'N' ELSE A.CONFIRMED END='N'"
+ " AND( ( C.reciept_type ='F' and C.tran_ser='P-RCP' ) or ( C.ret_opt ='C' and C.tran_ser='P-RET') )"
+ " AND D.CHANNEL_PARTNER='Y'";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next())
{
tranId=rs.getString("tran_id");
System.out.println("@V@ Voucher TranId :- ["+tranId+"]");
fos1.write(("Purchase Voucher Tran Id is:: [" + tranId +"]\r\n").getBytes());
retString=confirmTran("voucher",tranId,xtraParams,"",conn);
System.out.println("@V@ Voucher TranId :-["+tranId+" confirm return string :- ["+retString+"]");
fos1.write(("Status is:: [" + retString +"]\r\n").getBytes());
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if(rs!=null)
{
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pstmt!=null)
{
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
rs=null;
pstmt=null;
conn=null;
}
}
public String confirmTran(String businessObj,String tranId,String xtraParams,String forceFlag,Connection conn) throws ITMException
{
String methodName = "";
String compName = "";
String retString = "";
String serviceCode = "";
String serviceURI = "";
String actionURI = "";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
System.out.println("@V@ OBJ_NAME :- ["+businessObj+"]");
System.out.println("@V@ Voucher TranId at confirm :- ["+tranId+"]");
sql = "SELECT SERVICE_CODE,COMP_NAME FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND EVENT_CODE = 'pre_confirm' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,businessObj);
rs = pstmt.executeQuery();
if ( rs.next() )
{
serviceCode = rs.getString("SERVICE_CODE");
compName = rs.getString("COMP_NAME");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
System.out.println("@V@ ServiceCode :- ["+serviceCode+"] CompName :- ["+compName+"]");
sql = "SELECT SERVICE_URI,METHOD_NAME FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,serviceCode);
rs = pstmt.executeQuery();
if ( rs.next() )
{
methodName= rs.getString("METHOD_NAME");
serviceURI = rs.getString("SERVICE_URI");
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
actionURI = "http://NvoServiceurl.org/" + methodName;
System.out.println("@V@ ServiceURI :- ["+serviceURI+"] MethodName :- ["+methodName+"]");
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", "tran_id"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName("http://NvoServiceurl.org", "forced_flag"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(compName);
aobj[1] = new String(tranId);
aobj[2] = new String(xtraParams);
aobj[3] = new String("");
System.out.println("@V@ Call.setReturnType(XMLType.XSD_STRING) executed");
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke(aobj);
System.out.println("@V@ Confirm Complete Return string :- ["+retString+"]");
if(retString!=null && !retString.contains("VTSUCC1"))
{
conn.rollback();
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try{
if (pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
System.out.println("@V@ Exception inCalling confirmed");
e.printStackTrace();
try{
conn.rollback();
}catch (Exception s)
{
System.out.println("@V@ Unable to rollback");
s.printStackTrace();
}
throw new ITMException(e);
}
}
return retString;
}
@Override
public String schedule(HashMap arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
//@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment