deompiled and formatted code

This commit is contained in:
2025-08-20 14:32:12 +05:30
commit f2594db8f2
3 changed files with 335 additions and 0 deletions

15
config.properties Normal file
View File

@@ -0,0 +1,15 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.
DB_URL=jdbc:oracle:thin:@ipksprod3.c7q7defafeea.ap-south-1.rds.amazonaws.com:1521:IPKS
#DB_URL=jdbc:oracle:thin:@testforipks.c7q7defafeea.ap-south-1.rds.amazonaws.com:1521:IPKS
DB_USER=pacs_db
DB_PASS=pacs_db
DB_SCHEMA=pacs_db
SLEEP_TIME_MINS=30
#DB_USER=ipks_test
#DB_PASS=ipks_test
#DB_SCHEMA=ipks_test
IN_FOLDER_PATH=/home/ec2-user/PRODFILES/reportFiles/
#BACKUP_FOLDER_PATH=/home/ec2-user/FILES/reportFiles/
#IN_FOLDER_PATH=C:\\D\\test - Copy\\remotefiles\\
#BACKUP_FOLDER_PATH=C:\\Users\\1242938\\Desktop\\test\\remotefiles\\

174
loadreportfile/Main.java Normal file
View File

@@ -0,0 +1,174 @@
package loadreportfile;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import loadreportfile.dao.ReportFileProcessing;
public class Main {
public static void main(String[] args) throws InterruptedException {
String dbUrl = "";
String dbUsr = "";
String dbPass = "";
String dbSchema = "";
String inpFolderPath = "";
long sleep = 5L;
BufferedReader br = null;
String line = "";
String accNo = "";
String cbsAccNo = "";
String cbsCIF = "";
String outMsg = "";
List<String> accntdetailsList = new ArrayList<>();
ReportFileProcessing dao = new ReportFileProcessing();
try {
InputStream input = Main.class.getClassLoader().getResourceAsStream("config.properties");
Properties prop = new Properties();
if (input == null) {
System.out.println("Sorry, unable to find config.properties");
return;
}
prop.load(input);
dbUrl = prop.getProperty("DB_URL");
dbUsr = prop.getProperty("DB_USER");
dbPass = prop.getProperty("DB_PASS");
dbSchema = prop.getProperty("DB_SCHEMA");
inpFolderPath = prop.getProperty("IN_FOLDER_PATH");
sleep = Long.parseLong(prop.getProperty("SLEEP_TIME_MINS"));
} catch (Exception e) {
e.printStackTrace();
}
File folder = new File(inpFolderPath);
File unzipFolder = new File(inpFolderPath + "unzipped");
File processedFolder = new File(inpFolderPath + "processed_bkp");
if (!unzipFolder.exists()) {
unzipFolder.mkdir();
}
if (!processedFolder.exists()) {
processedFolder.mkdir();
}
while (true) {
String unzipFolderPath = unzipFolder.getAbsolutePath();
File[] gzFileList = folder.listFiles();
byte[] buffer = new byte[1024];
try {
for (File file : gzFileList) {
System.out.println("Current File name: " + file.getName());
if (file.isFile()) {
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file.getAbsoluteFile()));
FileOutputStream out = new FileOutputStream(
unzipFolderPath + File.separator + file.getName().replace(".gz", ""));
int len;
while ((len = gzis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
gzis.close();
out.close();
file.renameTo(new File(processedFolder.getAbsoluteFile() + File.separator + file.getName()));
System.out.println("Done");
}
}
} catch (Exception e) {
e.printStackTrace();
}
File[] listOfFiles = unzipFolder.listFiles();
try {
for (File file2 : listOfFiles) {
if (file2.isFile()) {
accntdetailsList.clear();
System.out.println(file2.getName());
br = new BufferedReader(new FileReader(file2.getAbsoluteFile()));
String fileName = file2.getName();
while ((line = br.readLine()) != null) {
if (!line.isEmpty() && line.length() == 146) {
accNo = line.substring(129);
cbsAccNo = line.substring(75, 88);
cbsCIF = line.substring(95, 108);
cbsAccNo = cbsAccNo.replace("-", "");
cbsAccNo = cbsAccNo.replace(" ", "");
cbsCIF = cbsCIF.replace("-", "");
cbsCIF = cbsCIF.replace(" ", "");
if (cbsAccNo.length() != 0 && accNo.length() != 0) {
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
}
}
if (!line.isEmpty() && line.length() == 129) {
accNo = line.substring(112);
cbsAccNo = line.substring(74, 89);
cbsCIF = line.substring(94, 109);
cbsAccNo = cbsAccNo.replace("-", "");
cbsAccNo = cbsAccNo.replace(" ", "");
cbsCIF = cbsCIF.replace("-", "");
cbsCIF = cbsCIF.replace(" ", "");
if (cbsAccNo.length() != 0 && accNo.length() != 0) {
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
}
}
if (!line.isEmpty() && line.length() > 112 && line.length() != 129
&& line.length() != 146) {
accNo = "E";
cbsAccNo = line.substring(74, 89);
cbsCIF = line.substring(94, 109);
cbsAccNo = cbsAccNo.replace("-", "");
cbsAccNo = cbsAccNo.replace(" ", "");
cbsCIF = cbsCIF.replace("-", "");
cbsCIF = cbsCIF.replace(" ", "");
if (cbsAccNo.length() != 0 && cbsCIF.length() != 0) {
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
}
}
}
if (accntdetailsList.size() > 0)
outMsg = dao.insertBulkAccMap(accntdetailsList, "", "", dbUrl, dbUsr, dbPass, dbSchema,
fileName);
System.out.println(outMsg);
}
file2.delete();
}
System.out.println("___________________________________________________");
TimeUnit.MINUTES.sleep(sleep);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("___________________________________________________");
TimeUnit.MINUTES.sleep(sleep);
}
}
}
}

View File

@@ -0,0 +1,146 @@
package loadreportfile.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
public class ReportFileProcessing {
public String insertBulkAccMap(List<String> accntdetailsList, String pacsId, String tellerId, String dbUrl,
String dbUsr, String dbPass, String dbSchema, String fileName) {
Connection con = null;
PreparedStatement ps = null;
int i = 0;
String[] accNo = null;
CallableStatement proc = null;
CallableStatement procall = null;
String outMsg = "";
String res = "";
System.out.println("File list: " + fileName);
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(dbUrl, dbUsr, dbPass);
con.setAutoCommit(false);
try {
while (i <= accntdetailsList.size() - 1) {
accNo = ((String) accntdetailsList.get(i)).split("\\:");
String acn1 = accNo[0];
String acn2 = accNo[1];
String acn3 = accNo[2];
ps = con.prepareStatement("insert into " + dbSchema
+ ".bulk_acct_map (pacs_id, key_1, cbs_acct, teller_id, map_dt, map_tym, status, id_typ, id_no, bank_cif, mark_type) values (?,?,?,?,(select system_date from system_date),to_char(SYSTIMESTAMP, 'DD-MON-RRHH12:MI:SS'),'PENDING','','',?,'')");
ps.setString(1, pacsId);
ps.setString(2, accNo[0]);
ps.setString(3, accNo[1]);
ps.setString(4, tellerId);
ps.setString(5, accNo[2]);
ps.executeQuery();
con.commit();
ps.close();
i++;
}
} catch (SQLException ex) {
ex.printStackTrace();
try {
if (ps != null) {
ps.close();
}
} catch (SQLException ep) {
ex.printStackTrace();
} catch (Exception e) {
ex.printStackTrace();
}
String msg = "SQL error in inserting bulk_acct_map";
try {
procall = con.prepareCall("{ call operations2.cbs_to_ipks(?,?,?) }");
procall.setString(1, fileName);
procall.setString(2, msg);
procall.registerOutParameter(3, 12);
procall.executeUpdate();
res = procall.getString(3);
System.out.println(res);
System.out.println("proc executed");
con.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (procall != null) {
procall.close();
}
} catch (SQLException ep) {
ep.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return msg;
}
try {
proc = con.prepareCall("{ call " + dbSchema + ".operations1.BULK_ACCT_MAPPING_auto(?,?,?,?) }");
proc.setString(1, pacsId);
proc.setString(2, tellerId);
proc.registerOutParameter(3, 12);
proc.registerOutParameter(4, 2);
proc.executeUpdate();
System.out.println("Procedure executed");
outMsg = proc.getString(3);
con.commit();
} catch (SQLException ex) {
ex.printStackTrace();
try {
if (ps != null) {
ps.close();
}
if (proc != null) {
proc.close();
}
} catch (SQLException ep) {
ex.printStackTrace();
} catch (Exception e) {
ex.printStackTrace();
}
return "Procedure error in bulk account mapping";
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (proc != null) {
proc.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return outMsg;
}
}