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
target/
.classpath
.project
.settings/

10
pom.xml
View File

@@ -28,6 +28,16 @@
<artifactId>ojdbc8</artifactId>
<version>23.5.0.24.07</version>
</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>
<build>

View File

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

View File

@@ -113,13 +113,12 @@ public class SSHProtocol {
System.out.println("DB Connected..");
}
ps =
connection.prepareStatement(
ps = connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ 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();
while (rs.next()) {
@@ -167,8 +166,7 @@ public class SSHProtocol {
}
if (errCount == 0) {
statement2 = connection.createStatement();
rs2 =
statement2.executeQuery(
rs2 = statement2.executeQuery(
"update "
+ this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
@@ -258,13 +256,12 @@ public class SSHProtocol {
System.out.println("DB Connected..");
}
ps =
connection.prepareStatement(
ps = connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ 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();
while (rs.next()) {
@@ -312,8 +309,7 @@ public class SSHProtocol {
}
if (errCount == 0) {
statement2 = connection.createStatement();
rs2 =
statement2.executeQuery(
rs2 = statement2.executeQuery(
"update "
+ this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
@@ -359,6 +355,7 @@ public class SSHProtocol {
public void fetchFileSSHUcb(String remote_report_pattern) {
try {
String local_folder_path_bkp = "/home/ec2-user/RUPAYKCCFILES/reportFiles_bkp/";
System.out.println("Going to FETCH files from remote Server");
JSch jsch = new JSch();
System.out.println(
@@ -368,7 +365,7 @@ public class SSHProtocol {
+ this.hostUcb
+ ":"
+ 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);
Properties config = new Properties();
@@ -397,13 +394,14 @@ public class SSHProtocol {
continue;
}
System.out.println("Found folder: " + entry.getFilename());
System.out.println("cd: " + rootPath + "/" + entry.getFilename());
sftpChannel.cd(rootPath + "/" + entry.getFilename());
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) {
if (!(new File(this.local_folder_path_bkp + "/" + subDirFiles.getFilename()))
.exists()) {
if (!(new File(local_folder_path_bkp + "/" + subDirFiles.getFilename())).exists()) {
sftpChannel.get(
subDirFiles.getFilename(), this.local_fileName + subDirFiles.getFilename());
System.out.println(
@@ -423,6 +421,7 @@ public class SSHProtocol {
e.printStackTrace();
}
}
public void fetchFileSSHNabard(String remote_report_pattern) {
try {
System.out.println("Going to FETCH files from remote Server");