Commit 65407b2a authored by ssalve's avatar ssalve

Sarita: Source code for Receipt Dishonour on 14 MAY 2018

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@184866 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 212f6733
//Receipt Dishonour Request ID : F17LGTP001
package ibase.webitm.ejb.fin.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.w3c.dom.Document;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.request.HttpRequest;
import ibase.system.config.AppConnectParm;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ITMDBAccessLocal;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.ITMException;
@Stateless
public class RcpDishnrPushData extends ActionHandlerEJB implements RcpDishnrPushDataLocal,RcpDishnrPushDataRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
FinCommon Fcommon = new FinCommon();
public String confirm(String tranId,String xtraParams, String forcedFlag) throws ITMException
{
System.out.println("Post Confirm gets called ........... [sarita]");
String retString = "";
Connection conn = null;
Document dom = null;
try
{
System.out.println("tranId ["+tranId+"] \n xtraParams ["+xtraParams+"] \n forcedFlag["+forcedFlag+"]");
conn = getConnection();
retString = rcpDishnrPush( tranId, xtraParams, forcedFlag, conn );
}
catch(Exception exception)
{
//retString = "ERROR";
exception.printStackTrace();
System.out.println("Exception in [RcpDishnrPushData] " + exception.getMessage());
throw new ITMException(exception);
}
{
if(conn != null)
{
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
conn = null;
}
}
return retString;
}
public String rcpDishnrPush(String tranId, String xtraParams, String forcedFlag, Connection conn) throws RemoteException,ITMException
{
System.out.println("rcpDishnrPush Confirm called........");
String errString = "",errorXML = "" ;
String reasonCode = "";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String chequeAmt="", acctCode="", receiptNo="", remark="",rctRemarks = "", callStatus = "", authToken = "",responseJsonStr = "";
String errMsg = "";
double chqAmount = 0.0;
String paymentNumber = "",customerAccountNumber="", varValue = "";
String loginCode = "";
JSONObject dataObj = new JSONObject();
AppConnectParm appConnect = null;
InitialContext initialCtx = null;
ITMDBAccessLocal itmDBAccess = null;
FinCommon finCommon = null;
int reasListLen = 0;
ArrayList<String> reasVarValues = null;
String isConfirmed = "";
String syncStatus = "",errStringMsg="";
int updCount = 0;
try
{
System.out.println("********************** Inside confirm method of [RcpDishnrConf] class ***************************");
appConnect = new AppConnectParm();
initialCtx = new InitialContext(appConnect.getProperty());
itmDBAccess = (ITMDBAccessLocal)initialCtx.lookup("ibase/ITMDBAccessEJB/local");
finCommon = new FinCommon();
loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
sql = "select receipt_no, remarks ,reas_code ,confirmed, sync_status from rcpdishnr where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if(rs.next())
{
receiptNo = checkNull(rs.getString("receipt_no"));
remark = checkNull(rs.getString("remarks"));
reasonCode = checkNull(rs.getString("reas_code"));
isConfirmed = checkNull(rs.getString("confirmed"));
syncStatus = checkNull(rs.getString("sync_status"));
System.out.println("Receipt Number :["+receiptNo+"] ; Remark :["+remark+"] ; reasonCode :["+reasonCode+"]confirmed--["+isConfirmed+"]syncStatus--["+syncStatus+"]");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
varValue = finCommon.getFinparams("999999", "RCDISHNR_NOSYNC_REAS", conn);
reasVarValues = new ArrayList<>(Arrays.asList(varValue.trim().split(",") ));
System.out.println("reasVarValues---["+reasVarValues+"]");
if("NULLFOUND".equalsIgnoreCase(varValue))
{
//Variable not defined in finparams
errString = itmDBAccess.getErrorString( "", "VTNOTDEF" , loginCode);
return errString;
}
else if(!isConfirmed.equalsIgnoreCase("Y") || ("Y").equalsIgnoreCase(syncStatus) || reasVarValues.contains(reasonCode.trim()))
{
// Do not proceed further in case of transaction not confirmed or already integrated or not to be integrated
errString = itmDBAccess.getErrorString( "", "NOTTOSYNC" , loginCode);
return errString;
}
sql = "select chq_amt , remarks from receipt where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, receiptNo);
rs = pstmt.executeQuery();
if(rs.next())
{
chqAmount = rs.getDouble("chq_amt");
rctRemarks = rs.getString("remarks");
System.out.println("Cheque Amount :["+chqAmount+"] ; Receipt Remarks :["+rctRemarks+"]");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
chequeAmt = String.valueOf(chqAmount);
if(rctRemarks.indexOf(",") != -1)
{
String getStrArr[] = rctRemarks.split(",");
paymentNumber = getStrArr[0];
customerAccountNumber = getStrArr[1];
System.out.println("paymentNumber is :["+paymentNumber+"] \t customerAccountNumber is :["+customerAccountNumber+"]");
}
else
{
paymentNumber = rctRemarks;
System.out.println("paymentNumber is :["+paymentNumber+"] \t customerAccountNumber is :["+customerAccountNumber+"]");
}
dataObj.put("paymentNumber",paymentNumber);
dataObj.put("basePrice",chequeAmt);
dataObj.put("remarks",remark);
dataObj.put("customerAccountNumber",customerAccountNumber);
System.out.println("11111111112"+dataObj.toString());
authToken = doAuthantication(conn);
if(authToken != null && authToken.trim().length() >0)
{
errString = pushData(authToken, dataObj ,conn);
System.out.println("Final errString is ["+errString+"]");
//Commented and added by sarita on 10MAY2018 [Start]
/*if (errString == null || errString.trim().length() == 0)
{
errString = "SUCCESS";
}
else
{
errString = "FAILED";
}
if("SUCCESS".equalsIgnoreCase(errString))
{
sql = "update rcpdishnr set sync_status = 'Y' where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
updCount = pstmt.executeUpdate();
System.out.println("Update in rcpdishnr ----["+ updCount +"]");if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}*/
if(errString.contains("success"))
{
System.out.println("1");
errStringMsg = "SUCCESS";
}
else
{
System.out.println("2");
errStringMsg = "FAILED";
}
if("SUCCESS".equalsIgnoreCase(errStringMsg))
{
sql = "update rcpdishnr set sync_status = 'Y' where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
updCount = pstmt.executeUpdate();
System.out.println("Update in rcpdishnr ----["+ updCount +"]");if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
errString = getError(errString, "VTSUCCESS",conn);
return errString;
}
else
{
errString = getError(errString, "VTFAILURE",conn);
System.out.println("errString ::: ["+errString+"]");
return errString;
}
}
//Commented and added by sarita on 10MAY2018 [End]
else
{
System.out.println("Already Authenticated!!!");
errString = itmDBAccess.getErrorString( "", "VTALRDAUTH" , loginCode);
return errString;
}
}
catch(Exception e)
{
System.out.println("Error in method confirm() "+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)
{
System.out.println("Exception--["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
}
//return errString;
}
private String doAuthantication(Connection conn) throws ITMException
{
String APPLICATION_JSON = "application/json";
String authToken = "" , retString = "";
AppConnectParm appConnect = null;
InitialContext initialCtx = null;
ITMDBAccessLocal itmDBAccess = null;
FinCommon finCommon = null;
String retCode = "";
try
{
System.out.println("******************** Inside callWebService1() Method ************************");
appConnect = new AppConnectParm();
initialCtx = new InitialContext(appConnect.getProperty());
itmDBAccess = (ITMDBAccessLocal)initialCtx.lookup("ibase/ITMDBAccessEJB/local");
finCommon = new FinCommon();
//String url = "http://uatmso.gtpl.net:18080/MSOIntegration/customer/login";
String url = finCommon.getFinparams("999999", "RCPDISHNR_PUSH_URL1", conn);
System.out.println("URL For [doAuthantication()]" +url);
JSONObject authTokenReqObj = new JSONObject();
authTokenReqObj.put("username", "mukesht"); authTokenReqObj.put("password", "admin"); authTokenReqObj.put("sId", 1);
HttpRequest extServiceReq = Unirest.post(url)
.header("Content-Type", APPLICATION_JSON)
.body(new JsonNode(authTokenReqObj.toString()))
.getHttpRequest();
System.out.println("URL IS ::["+extServiceReq.getUrl()+"]" + "\n"+ "HEADER IS ::["+extServiceReq.getHeaders()+"]" + "\n" + "BODY IS ::["+IOUtils.toString(extServiceReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> extServiceResp = extServiceReq.asJson();
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", extServiceResp.getStatus(), extServiceResp.getBody()));
if(extServiceResp.getStatus() == 200)
{
JSONObject jsonObject = extServiceResp.getBody().getObject(); System.out.println("object []" + new JsonNode(jsonObject.toString()));
if (jsonObject.has("data"))
{
JSONObject param1 = jsonObject.getJSONObject("data");
System.out.println("param1" + param1.toString());
if(param1.has("token"))
{
authToken = param1.getString("token");
System.out.println("Authentication Token Is ::"+authToken);
retString = authToken;
}
else
{
System.out.println("Response Data Not Found!!!!!!");
if(param1.has("code"))
{
retCode = param1.getString("code");
retString = itmDBAccess.getErrorString( "", "VTCODE"+retCode , "");
return retString;
}
}
}
else
{
System.out.println("Response Data Not Found!!!!!!");
retString = itmDBAccess.getErrorString( "", "VTNODATA" , "");
return retString;
}
}
else
{
System.out.println("Getting Error While Connection!!!!!");
retString = itmDBAccess.getErrorString( "", "VTNOCONN" , "");
return retString;
}
}
catch(Exception e)
{
System.out.println("Error In Method[doAuthantication ::]" +e);
e.printStackTrace();
throw new ITMException(e);
}
return retString.toString();
}
private String pushData(String authToken, JSONObject dataObj ,Connection conn) throws ITMException
{
String APPLICATION_JSON = "application/json";
String authUrl = "";
String retString = "";
AppConnectParm appConnect = null;
InitialContext initialCtx = null;
ITMDBAccessLocal itmDBAccess = null;
String errMsg = "";
String responseString = "";
FinCommon finCommon = null;
try
{
System.out.println("******************** Inside pushData Method ************************");
appConnect = new AppConnectParm();
initialCtx = new InitialContext(appConnect.getProperty());
itmDBAccess = (ITMDBAccessLocal)initialCtx.lookup("ibase/ITMDBAccessEJB/local");
finCommon = new FinCommon();
//authUrl = " http://uatmso.gtpl.net:18080/MSOIntegration/customer/paymentReversalERP";
authUrl = finCommon.getFinparams("999999", "RCPDISHNR_PUSH_URL2", conn);
System.out.println("URL For [callWebService2()]" +authUrl);
HttpRequest extServiceReqcall = Unirest.post(authUrl)
.header("Content-Type", APPLICATION_JSON)
// .header("token",authToken)//Added by sarita on 09MAY2018
.header("Authorization",authToken)
.body(new JsonNode(dataObj.toString()))
.getHttpRequest();
System.out.println("authUrl IS ::["+extServiceReqcall.getUrl()+"]"+ "\n" + "uthUrl HEADER IS ::["+extServiceReqcall.getHeaders()+"]" + "\n" +"authUrl BODY IS ::["+IOUtils.toString(extServiceReqcall.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> extServiceRespcall = extServiceReqcall.asJson();
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", extServiceRespcall.getStatus(), extServiceRespcall.getBody()));
if(extServiceRespcall.getStatus() == 200)
{
JSONObject jsonObject = extServiceRespcall.getBody().getObject();
//System.out.println("object []" + new JsonNode(jsonObject.toString()));
//Added by sarita on 09MAY2018 [start]
responseString = jsonObject.toString();
errMsg = "\n Message : "+jsonObject.getString("message")+" \n Return code : "+jsonObject.getInt("code") + "\n Status :" +jsonObject.getString("status");
System.out.println("responseString is :["+responseString+"] \t errMsg :["+errMsg+"]");
retString = errMsg;
return retString;
//Added by sarita on 09MAY2018 [end]
}
else
{
System.out.println("Getting Error While Connection!!!!!");
retString = itmDBAccess.getErrorString( "", "VTNOCONN" , "");
return retString;
}
}
catch(Exception e)
{
System.out.println("Error In pushData ::]" +e);
e.printStackTrace();
throw new ITMException(e);
}
//return retString;
}
private String checkNull(String input)
{
if (input==null)
{
input="";
}
return input.trim();
}
//Added by sarita on 09MAY2018 [start]
private String getError(String errMsg, String Code, Connection conn) throws ITMException, Exception
{
String mainStr ="";
try
{
String errString = "";
errString = new ITMDBAccessEJB().getErrorString("",Code,"","",conn);
System.out.println("Origional ErrorString is =====> <"+errString+">");
String begPart = errString.substring(0,errString.indexOf("</description>"));
String endDesc = errString.substring(errString.indexOf("</description>"),errString.length());
System.out.println("begPart ["+begPart+"] \t endDesc ["+endDesc+"]");
mainStr = checkNull(begPart) + errMsg + checkNull(endDesc);
System.out.println("mainStr:::::::::::::::::: "+mainStr);
//begPart = null;
//mainStr = errString;
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return mainStr;
}
//Added by sarita on 09MAY2018 [end]
}
/**
* @author : Wasim Ansari
* Date : 05-JUN-2015
* Migration: W16IBAS005
*/
package ibase.webitm.ejb.fin.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import javax.ejb.Local;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ActionHandlerLocal;
import ibase.webitm.utility.ITMException;
@Local
public interface RcpDishnrPushDataLocal extends ActionHandlerLocal
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException ,ITMException;
public String rcpDishnrPush(String tranId, String xtraParams, String forcedFlag, Connection conn ) throws RemoteException,ITMException;
}
/**
* @author : Wasim Ansari
* Date : 05-JUN-2015
* Migration: W16IBAS005
*/
package ibase.webitm.ejb.fin.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import javax.ejb.Remote;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ActionHandlerRemote;
import ibase.webitm.utility.ITMException;
@Remote
public interface RcpDishnrPushDataRemote extends ActionHandlerRemote
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException ,ITMException;
public String rcpDishnrPush(String tranId, String xtraParams, String forcedFlag, Connection conn ) throws RemoteException,ITMException;
}
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