cleaned up, formatted and made the project runnable after decompilation. Also added logic for NABARD and UCB servers bifurgation
This commit is contained in:
commit
6cf38d7890
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dependency-reduced-pom.xml
|
||||||
|
target/
|
64
pom.xml
Normal file
64
pom.xml
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.main</groupId>
|
||||||
|
<artifactId>SweepInterface_API</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<exec.mainClass>com.main.ResponseMain</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20180130</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.oracle.database.jdbc</groupId>
|
||||||
|
<artifactId>ojdbc8</artifactId>
|
||||||
|
<version>23.5.0.24.07</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- not using Maven Compiler Plugin as it is not necessay -->
|
||||||
|
<!-- <plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>1.8</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin> -->
|
||||||
|
|
||||||
|
<!-- Maven Shade plugin to build fat or uber jar -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.main.ResponseMain</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
104
src/main/java/com/bean/DataBean.java
Normal file
104
src/main/java/com/bean/DataBean.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package com.bean;
|
||||||
|
|
||||||
|
public class DataBean {
|
||||||
|
private String mobNum;
|
||||||
|
private String mcnNum;
|
||||||
|
private String timestamp;
|
||||||
|
private String jrnlId;
|
||||||
|
private String acctNo;
|
||||||
|
private String txnAmt;
|
||||||
|
private String txnInd;
|
||||||
|
private String narration;
|
||||||
|
private String txnCode;
|
||||||
|
private String bankcode;
|
||||||
|
|
||||||
|
public String getBankcode() {
|
||||||
|
return this.bankcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBankcode(String bankcode) {
|
||||||
|
this.bankcode = bankcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJrnlId() {
|
||||||
|
return this.jrnlId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJrnlId(String jrnlId) {
|
||||||
|
this.jrnlId = jrnlId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAcctNo() {
|
||||||
|
return this.acctNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAcctNo(String acctNo) {
|
||||||
|
this.acctNo = acctNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTxnAmt() {
|
||||||
|
return this.txnAmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTxnAmt(String txnAmt) {
|
||||||
|
this.txnAmt = txnAmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTxnInd() {
|
||||||
|
return this.txnInd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTxnInd(String txnInd) {
|
||||||
|
this.txnInd = txnInd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNarration() {
|
||||||
|
return this.narration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNarration(String narration) {
|
||||||
|
this.narration = narration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTxnCode() {
|
||||||
|
return this.txnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTxnCode(String txnCode) {
|
||||||
|
this.txnCode = txnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMobNum() {
|
||||||
|
return this.mobNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMobNum(String mobNum) {
|
||||||
|
this.mobNum = mobNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMcnNum() {
|
||||||
|
return this.mcnNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMcnNum(String mcnNum) {
|
||||||
|
this.mcnNum = mcnNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimestamp() {
|
||||||
|
return this.timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(String timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "DataBean [mobNum="
|
||||||
|
+ this.mobNum
|
||||||
|
+ ", mcnNum="
|
||||||
|
+ this.mcnNum
|
||||||
|
+ ", timestamp="
|
||||||
|
+ this.timestamp
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/com/main/ResponseMain.java
Normal file
13
src/main/java/com/main/ResponseMain.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.main;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class ResponseMain {
|
||||||
|
static ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
service.scheduleAtFixedRate(new Scheduler(), 0L, 2L, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
}
|
44
src/main/java/com/main/Scheduler.java
Normal file
44
src/main/java/com/main/Scheduler.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package com.main;
|
||||||
|
|
||||||
|
import com.methods.RequestResponse;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class Scheduler implements Runnable {
|
||||||
|
public static Properties prop = new Properties();
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
|
||||||
|
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
cal.add(6, -1);
|
||||||
|
|
||||||
|
String dateToday = sdf.format(cal.getTime());
|
||||||
|
|
||||||
|
System.out.println("Scheduled Run Begins in...." + new Date());
|
||||||
|
try {
|
||||||
|
ArrayList<String> urlList = RequestResponse.getUrl();
|
||||||
|
for (int i = 0; i < urlList.size(); i++) {
|
||||||
|
System.out.println("Iterating for Next Bank API");
|
||||||
|
|
||||||
|
try {
|
||||||
|
RequestResponse.get_response(urlList.get(i), dateToday);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("End of Scheduled Run");
|
||||||
|
}
|
||||||
|
}
|
285
src/main/java/com/methods/RequestResponse.java
Normal file
285
src/main/java/com/methods/RequestResponse.java
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
package com.methods;
|
||||||
|
|
||||||
|
import com.bean.DataBean;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public class RequestResponse {
|
||||||
|
static Connection connection = null;
|
||||||
|
static ResultSet rs = null;
|
||||||
|
static Statement statement = null;
|
||||||
|
|
||||||
|
public static ArrayList<DataBean> get_response(String jsonInputString, String date)
|
||||||
|
throws IOException {
|
||||||
|
// String urlFromDatabase = "https://IPKS.cedgenetbanking.in/IPKSTRAN";
|
||||||
|
String urlFromDatabase = "";
|
||||||
|
String bc = new JSONObject(jsonInputString).getString("bankcode");
|
||||||
|
if(bc.equals("0005") || bc.equals("0021")) {
|
||||||
|
urlFromDatabase = "https://NABARDIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||||
|
} else {
|
||||||
|
urlFromDatabase = "https://UCBIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Req MSG : " + jsonInputString);
|
||||||
|
ArrayList<DataBean> data = new ArrayList<>();
|
||||||
|
URL url = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL(urlFromDatabase);
|
||||||
|
} catch (MalformedURLException e1) {
|
||||||
|
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
try {
|
||||||
|
con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||||
|
con.setRequestProperty("Accept", "application/json");
|
||||||
|
con.setDoOutput(true);
|
||||||
|
|
||||||
|
} catch (IOException e2) {
|
||||||
|
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (OutputStream os = con.getOutputStream()) {
|
||||||
|
byte[] input = jsonInputString.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int responseCode = 0;
|
||||||
|
try {
|
||||||
|
responseCode = con.getResponseCode();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("Response Code : " + responseCode);
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
|
||||||
|
StringBuffer response = new StringBuffer();
|
||||||
|
response.append("{\"result\":");
|
||||||
|
try {
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.append("}");
|
||||||
|
|
||||||
|
if (response.toString().contains("No data found")) {
|
||||||
|
System.out.println("No Transactions found");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject(response.toString());
|
||||||
|
JSONArray dataArray = new JSONArray(json.get("result").toString());
|
||||||
|
|
||||||
|
for (int i = 0; i < dataArray.length(); i++) {
|
||||||
|
String JSonData = dataArray.get(i).toString();
|
||||||
|
DataBean databean = new DataBean();
|
||||||
|
|
||||||
|
JSONObject dataD = new JSONObject(JSonData);
|
||||||
|
|
||||||
|
databean.setAcctNo(dataD.get("acctno").toString());
|
||||||
|
databean.setBankcode(dataD.get("bankcode").toString());
|
||||||
|
databean.setTxnCode(dataD.get("trancode").toString());
|
||||||
|
databean.setTxnAmt(dataD.get("trnamt").toString());
|
||||||
|
databean.setNarration(dataD.get("narration").toString());
|
||||||
|
databean.setJrnlId(dataD.get("jrnl").toString());
|
||||||
|
databean.setTimestamp(date);
|
||||||
|
|
||||||
|
if (Double.parseDouble(dataD.get("trnamt").toString()) > 0.0D) {
|
||||||
|
databean.setTxnInd("CR");
|
||||||
|
} else if (Double.parseDouble(dataD.get("trnamt").toString()) < 0.0D) {
|
||||||
|
databean.setTxnInd("DR");
|
||||||
|
} else {
|
||||||
|
databean.setTxnInd("NA");
|
||||||
|
}
|
||||||
|
data.add(databean);
|
||||||
|
}
|
||||||
|
|
||||||
|
setDatainDatabase(data, date);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e3) {
|
||||||
|
|
||||||
|
e3.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> getUrl() {
|
||||||
|
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
|
||||||
|
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(new Date());
|
||||||
|
cal.add(6, -1);
|
||||||
|
|
||||||
|
String dateToday = sdf.format(cal.getTime());
|
||||||
|
|
||||||
|
System.out.println("Date :" + dateToday);
|
||||||
|
String url = null;
|
||||||
|
String bankCode = null;
|
||||||
|
ArrayList<String> finalUrl = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
connection = Util.getDBConnection();
|
||||||
|
|
||||||
|
statement = connection.createStatement();
|
||||||
|
rs =
|
||||||
|
statement.executeQuery(
|
||||||
|
"select * from rupay_kcc_api_map where status='Y' and API_TYPE='TXN'");
|
||||||
|
while (rs.next()) {
|
||||||
|
url = rs.getString(7);
|
||||||
|
bankCode = rs.getString(6);
|
||||||
|
String finUrl = url.replaceAll("dt", dateToday);
|
||||||
|
finUrl = finUrl.replaceAll("bcode", bankCode);
|
||||||
|
finalUrl.add(finUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (connection != null) connection.close();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return finalUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDatainDatabase(ArrayList<DataBean> data, String date) {
|
||||||
|
Connection connection = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Statement st = null;
|
||||||
|
String query = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
|
||||||
|
ArrayList<String> combination = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
connection = Util.getDBConnection();
|
||||||
|
st = connection.createStatement();
|
||||||
|
rs =
|
||||||
|
st.executeQuery(
|
||||||
|
"select l.bankcode,l.jrnl_id,l.txn_date from sweep_api_log l where l.txn_date='"
|
||||||
|
+ date
|
||||||
|
+ "'");
|
||||||
|
while (rs.next()) {
|
||||||
|
String comb = rs.getString(1) + "|" + rs.getString(2) + "|" + rs.getString(3);
|
||||||
|
|
||||||
|
combination.add(comb);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("No record found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<DataBean> iter = data.iterator();
|
||||||
|
Statement st2 = connection.createStatement();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
DataBean d = iter.next();
|
||||||
|
|
||||||
|
if (d.getTxnCode().equalsIgnoreCase("001057")) {
|
||||||
|
|
||||||
|
if (combination.contains(d.getBankcode() + "|" + d.getJrnlId() + "|" + d.getTimestamp())
|
||||||
|
|| d.getJrnlId() == null
|
||||||
|
|| d.getJrnlId().equalsIgnoreCase("")) {
|
||||||
|
System.out.println(
|
||||||
|
"RECORD ALREADY PRESENT FOR "
|
||||||
|
+ d.getBankcode()
|
||||||
|
+ "|"
|
||||||
|
+ d.getJrnlId()
|
||||||
|
+ "|"
|
||||||
|
+ d.getTimestamp());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
query =
|
||||||
|
"insert into sweep_api_log (bankcode, cbsacctno, txncode, txnamt, txnind, narration,"
|
||||||
|
+ " jrnl_id, txn_date, post_flag, success_flag, errorlog) values ('"
|
||||||
|
+ d.getBankcode()
|
||||||
|
+ "','"
|
||||||
|
+ d.getAcctNo()
|
||||||
|
+ "','"
|
||||||
|
+ d.getTxnCode()
|
||||||
|
+ "',abs("
|
||||||
|
+ d.getTxnAmt()
|
||||||
|
+ "),'";
|
||||||
|
query =
|
||||||
|
query
|
||||||
|
+ d.getTxnInd()
|
||||||
|
+ "','"
|
||||||
|
+ d.getNarration()
|
||||||
|
+ "','"
|
||||||
|
+ d.getJrnlId()
|
||||||
|
+ "','"
|
||||||
|
+ d.getTimestamp()
|
||||||
|
+ "','N','N',"
|
||||||
|
+ null
|
||||||
|
+ ")";
|
||||||
|
System.out.println("SQL Statement :" + query);
|
||||||
|
|
||||||
|
st2.addBatch(query);
|
||||||
|
System.out.println("Added to DB Insert Batch");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Txncode:" + d.getTxnCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
st2.executeBatch();
|
||||||
|
System.out.println("Insert to DB Completed");
|
||||||
|
System.out.println("Posting Txns in IPKS");
|
||||||
|
|
||||||
|
CallableStatement cs = connection.prepareCall("{call sweep_api_txn_post}");
|
||||||
|
cs.execute();
|
||||||
|
System.out.println("Posting Completed, Check log.");
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (connection != null) connection.close();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/main/java/com/methods/Util.java
Normal file
23
src/main/java/com/methods/Util.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.methods;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static Connection getDBConnection() {
|
||||||
|
Connection dbConnection = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("oracle.jdbc.driver.OracleDriver");
|
||||||
|
|
||||||
|
dbConnection =
|
||||||
|
DriverManager.getConnection(
|
||||||
|
"jdbc:oracle:thin:@ipksapi.c7q7defafeea.ap-south-1.rds.amazonaws.com:1521:ipksapi",
|
||||||
|
"api_db",
|
||||||
|
"api_db");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return dbConnection;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user