added logic to contact different servers for NABARD and UCB banks

This commit is contained in:
2025-08-09 22:24:42 +05:30
parent cc6eaf5852
commit d1850fd72f
4 changed files with 631 additions and 615 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,5 @@
dependency-reduced-pom.xml dependency-reduced-pom.xml
target/ target/
.classpath
.project
.settings/

10
pom.xml
View File

@@ -28,6 +28,16 @@
<artifactId>ojdbc8</artifactId> <artifactId>ojdbc8</artifactId>
<version>23.5.0.24.07</version> <version>23.5.0.24.07</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -1,12 +1,16 @@
package com.Main; package com.Main;
import com.fetchFile.FetchReportFile;
import com.sendFile.protocol.SSH.SSHProtocol;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.fetchFile.FetchReportFile; import org.slf4j.Logger;
import com.sendFile.protocol.SSH.SSHProtocol; import org.slf4j.LoggerFactory;
public class Main { public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) { public static void main(String[] args) {
String user = ""; String user = "";
String password = ""; String password = "";
@@ -35,7 +39,7 @@ public class Main {
InputStream input = Main.class.getClassLoader().getResourceAsStream("config.properties"); InputStream input = Main.class.getClassLoader().getResourceAsStream("config.properties");
Properties prop = new Properties(); Properties prop = new Properties();
if (input == null) { if (input == null) {
System.out.println("Sorry, unable to find config.properties"); logger.error("Sorry, unable to find config.properties");
return; return;
} }
prop.load(input); prop.load(input);
@@ -61,29 +65,29 @@ public class Main {
dbPass = prop.getProperty("DB_PASS"); dbPass = prop.getProperty("DB_PASS");
dbSchema = prop.getProperty("DB_SCHEMA"); dbSchema = prop.getProperty("DB_SCHEMA");
System.out.println("Config Properties read:"); logger.info("Config Properties read:");
System.out.println( logger.info(
"REMOTE_HOST_UCB: " "REMOTE_HOST_UCB: {}"
+ hostUcb + "\nREMOTE_HOST_NABARD: {}"
+ "\nREMOTE_HOST_NABARD: " + "\nREMOTE_USER: {}"
+ hostNabard + "\nREMOTE_PASS: {}"
+ "\nREMOTE_USER: " + "\nREMOTE_PORT: {}"
+ user + "\nREMOTE_FILE_PATH: {}"
+ "\nREMOTE_PASS: " + "\nSLEEP_TIME: {}"
+ password + "\nLOCAL_FOLDER_PATH: {}"
+ "\nREMOTE_PORT: " + "\nTRANSFER_PROTOCOL: {}",
+ port hostUcb,
+ "\nREMOTE_FILE_PATH: " hostNabard,
+ remote_file_path user,
+ "\nSLEEP_TIME: " password,
+ sleep port,
+ "\nLOCAL_FOLDER_PATH: " remote_file_path,
+ local_folder_path sleep,
+ "\nTRANSFER_PROTOCOL: " local_folder_path,
+ transfer_protocol); transfer_protocol);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("Error reading config file", e);
} }
SSHProtocol send = SSHProtocol send =
@@ -136,32 +140,32 @@ public class Main {
try { try {
while (true) { while (true) {
System.out.println("___________________________________________________"); logger.info("___________________________________________________");
try { try {
send.sendFileSSHUcb(); send.sendFileSSHUcb();
send.sendFileSSHNabard(); send.sendFileSSHNabard();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("Error sending file", e);
} }
try { try {
fetch.fetchFiles(); fetch.fetchFiles();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("Error fetching report file", e);
} }
try { try {
fetchFailed.fetchFiles(); fetchFailed.fetchFiles();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error("Error fetching failed file", e);
} }
System.out.println("Sleeping for:" + sleep + " Minutes"); logger.info("Sleeping for: {} Minutes", sleep);
System.out.println("___________________________________________________"); logger.info("___________________________________________________");
TimeUnit.MINUTES.sleep(sleep); TimeUnit.MINUTES.sleep(sleep);
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println(e); logger.error("An unexpected error occurred in the main loop", e);
return; return;
} }
} }

View File

@@ -113,13 +113,12 @@ public class SSHProtocol {
System.out.println("DB Connected.."); System.out.println("DB Connected..");
} }
ps = ps = connection.prepareStatement(
connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from " "select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema + this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '" + ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ dateToday + dateToday
+ "' and k.remarks = 'FILE GENERATED' AND k.bnk_code NOT IN ('0005', '0021')"); + "' and k.remarks = 'FILE GENERATED' AND k.bnk_code NOT IN ('0005', '0021', '0016', '0018', '0001', '0004', '0007')");
rs = ps.executeQuery(); rs = ps.executeQuery();
while (rs.next()) { while (rs.next()) {
@@ -167,8 +166,7 @@ public class SSHProtocol {
} }
if (errCount == 0) { if (errCount == 0) {
statement2 = connection.createStatement(); statement2 = connection.createStatement();
rs2 = rs2 = statement2.executeQuery(
statement2.executeQuery(
"update " "update "
+ this.dbSchema + this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE" + ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
@@ -258,13 +256,12 @@ public class SSHProtocol {
System.out.println("DB Connected.."); System.out.println("DB Connected..");
} }
ps = ps = connection.prepareStatement(
connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from " "select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema + this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '" + ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ dateToday + dateToday
+ "' and k.remarks = 'FILE GENERATED' AND k.bnk_code IN ('0005', '0021')"); + "' and k.remarks = 'FILE GENERATED' AND k.bnk_code IN ('0005', '0021', '0016', '0018', '0001', '0004', '0007')");
rs = ps.executeQuery(); rs = ps.executeQuery();
while (rs.next()) { while (rs.next()) {
@@ -312,8 +309,7 @@ public class SSHProtocol {
} }
if (errCount == 0) { if (errCount == 0) {
statement2 = connection.createStatement(); statement2 = connection.createStatement();
rs2 = rs2 = statement2.executeQuery(
statement2.executeQuery(
"update " "update "
+ this.dbSchema + this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE" + ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
@@ -359,6 +355,7 @@ public class SSHProtocol {
public void fetchFileSSHUcb(String remote_report_pattern) { public void fetchFileSSHUcb(String remote_report_pattern) {
try { try {
String local_folder_path_bkp = "/home/ec2-user/RUPAYKCCFILES/reportFiles_bkp/";
System.out.println("Going to FETCH files from remote Server"); System.out.println("Going to FETCH files from remote Server");
JSch jsch = new JSch(); JSch jsch = new JSch();
System.out.println( System.out.println(
@@ -368,7 +365,7 @@ public class SSHProtocol {
+ this.hostUcb + this.hostUcb
+ ":" + ":"
+ this.port); + this.port);
Session session = jsch.getSession(this.user, this.hostNabard, this.port); Session session = jsch.getSession(this.user, this.hostUcb, this.port);
session.setPassword(this.password); session.setPassword(this.password);
Properties config = new Properties(); Properties config = new Properties();
@@ -397,13 +394,14 @@ public class SSHProtocol {
continue; continue;
} }
System.out.println("Found folder: " + entry.getFilename()); System.out.println("Found folder: " + entry.getFilename());
System.out.println("cd: " + rootPath + "/" + entry.getFilename()); System.out.println("cd: " + rootPath + "/" + entry.getFilename());
sftpChannel.cd(rootPath + "/" + entry.getFilename());
System.out.println(sftpChannel.pwd()); System.out.println(sftpChannel.pwd());
Vector<ChannelSftp.LsEntry> subDirFileList = sftpChannel.ls(remote_report_pattern); sftpChannel.cd(rootPath + "/" + entry.getFilename());
Vector<ChannelSftp.LsEntry> subDirFileList = sftpChannel
.ls(sftpChannel.pwd() + "/" + remote_report_pattern);
for (ChannelSftp.LsEntry subDirFiles : subDirFileList) { for (ChannelSftp.LsEntry subDirFiles : subDirFileList) {
if (!(new File(this.local_folder_path_bkp + "/" + subDirFiles.getFilename())) if (!(new File(local_folder_path_bkp + "/" + subDirFiles.getFilename())).exists()) {
.exists()) {
sftpChannel.get( sftpChannel.get(
subDirFiles.getFilename(), this.local_fileName + subDirFiles.getFilename()); subDirFiles.getFilename(), this.local_fileName + subDirFiles.getFilename());
System.out.println( System.out.println(
@@ -423,6 +421,7 @@ public class SSHProtocol {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void fetchFileSSHNabard(String remote_report_pattern) { public void fetchFileSSHNabard(String remote_report_pattern) {
try { try {
System.out.println("Going to FETCH files from remote Server"); System.out.println("Going to FETCH files from remote Server");