resolve bulkfile issue
This commit is contained in:
@@ -7,6 +7,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -53,122 +54,181 @@ public class Main {
|
|||||||
|
|
||||||
File folder = new File(inpFolderPath);
|
File folder = new File(inpFolderPath);
|
||||||
|
|
||||||
File unzipFolder = new File(inpFolderPath + "unzipped");
|
File unzipFolder = new File(inpFolderPath + "unzipped");
|
||||||
File processedFolder = new File(inpFolderPath + "processed_bkp");
|
File processedFolder = new File(inpFolderPath + "processed_bkp");
|
||||||
|
|
||||||
if (!unzipFolder.exists()) {
|
if (!unzipFolder.exists()) {
|
||||||
unzipFolder.mkdir();
|
unzipFolder.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!processedFolder.exists()) {
|
if (!processedFolder.exists()) {
|
||||||
processedFolder.mkdir();
|
processedFolder.mkdir();
|
||||||
}
|
}
|
||||||
|
while (true) {
|
||||||
|
String unzipFolderPath = unzipFolder.getAbsolutePath();
|
||||||
|
File[] gzFileList = folder.listFiles();
|
||||||
|
|
||||||
while (true) {
|
try {
|
||||||
String unzipFolderPath = unzipFolder.getAbsolutePath();
|
for (File file : gzFileList) {
|
||||||
File[] gzFileList = folder.listFiles();
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
|
|
||||||
try {
|
if (file.isFile()) {
|
||||||
for (File file : gzFileList) {
|
System.out.println("Current File name: " + file.getName());
|
||||||
System.out.println("Current File name: " + file.getName());
|
if (file.getName().endsWith(".gz")) {
|
||||||
if (file.isFile()) {
|
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file.getAbsoluteFile()));
|
||||||
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file.getAbsoluteFile()));
|
FileOutputStream out = new FileOutputStream(
|
||||||
FileOutputStream out = new FileOutputStream(
|
unzipFolderPath + File.separator + file.getName().replace(".gz", ""));
|
||||||
unzipFolderPath + File.separator + file.getName().replace(".gz", ""));
|
byte[] buffer = new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = gzis.read(buffer)) > 0) {
|
while ((len = gzis.read(buffer)) > 0) {
|
||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
gzis.close();
|
gzis.close();
|
||||||
out.close();
|
out.close();
|
||||||
|
} else {
|
||||||
|
File destFile = new File(unzipFolderPath + File.separator + file.getName());
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
FileOutputStream fos = new FileOutputStream(destFile);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = fis.read(buffer)) > 0) {
|
||||||
|
fos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
|
||||||
file.renameTo(new File(processedFolder.getAbsoluteFile() + File.separator + file.getName()));
|
file.renameTo(new File(processedFolder.getAbsoluteFile() + File.separator + file.getName()));
|
||||||
|
|
||||||
System.out.println("Done");
|
System.out.println("Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] listOfFiles = unzipFolder.listFiles();
|
File[] listOfFiles = unzipFolder.listFiles();
|
||||||
|
// ✅ Allowed codes
|
||||||
|
String[] allowedCodes = { "00002" };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (File file2 : listOfFiles) {
|
for (File file2 : listOfFiles) {
|
||||||
if (file2.isFile()) {
|
if (file2.isFile()) {
|
||||||
accntdetailsList.clear();
|
accntdetailsList.clear();
|
||||||
System.out.println(file2.getName());
|
String fileName = file2.getName();
|
||||||
br = new BufferedReader(new FileReader(file2.getAbsoluteFile()));
|
System.out.println(fileName);
|
||||||
String fileName = file2.getName();
|
// ✅ Split by underscore and extract second part EX- BLK_00014_20082025*
|
||||||
|
String[] parts = fileName.split("_");
|
||||||
|
String code = (parts.length > 1) ? parts[1] : "";
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
// ✅ Check if code is in allowedCodes
|
||||||
|
boolean match = Arrays.asList(allowedCodes).contains(code);
|
||||||
|
if (!match) {
|
||||||
|
br = new BufferedReader(new FileReader(file2.getAbsoluteFile()));
|
||||||
|
|
||||||
if (!line.isEmpty() && line.length() == 146) {
|
while ((line = br.readLine()) != null) {
|
||||||
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) {
|
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(" ", "");
|
||||||
|
|
||||||
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
if (cbsAccNo.length() != 0 && accNo.length() != 0) {
|
||||||
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!line.isEmpty() && line.length() == 129) {
|
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
accNo = line.substring(112);
|
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
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) {
|
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(" ", "");
|
||||||
|
|
||||||
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
if (cbsAccNo.length() != 0 && accNo.length() != 0) {
|
||||||
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!line.isEmpty() && line.length() > 112 && line.length() != 129
|
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
&& line.length() != 146) {
|
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
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) {
|
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(" ", "");
|
||||||
|
|
||||||
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
if (cbsAccNo.length() != 0 && cbsCIF.length() != 0) {
|
||||||
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accntdetailsList.size() > 0)
|
accntdetailsList.add(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
outMsg = dao.insertBulkAccMap(accntdetailsList, "", "", dbUrl, dbUsr, dbPass, dbSchema,
|
System.out.println(accNo + ":" + cbsAccNo + ":" + cbsCIF);
|
||||||
fileName);
|
}
|
||||||
System.out.println(outMsg);
|
}
|
||||||
}
|
}
|
||||||
file2.delete();
|
} else {
|
||||||
}
|
br = new BufferedReader(new FileReader(file2.getAbsoluteFile()));
|
||||||
System.out.println("___________________________________________________");
|
while ((line = br.readLine()) != null) {
|
||||||
TimeUnit.MINUTES.sleep(sleep);
|
|
||||||
} catch (Exception ex) {
|
if (!line.isEmpty() && line.length() == 118) {
|
||||||
ex.printStackTrace();
|
accNo = line.substring(102);
|
||||||
System.out.println("___________________________________________________");
|
cbsAccNo = line.substring(62, 75);
|
||||||
TimeUnit.MINUTES.sleep(sleep);
|
cbsCIF = line.substring(84, 97);
|
||||||
}
|
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() != 118) {
|
||||||
|
System.out.println(line);
|
||||||
|
accNo = "E";
|
||||||
|
cbsAccNo = line.substring(62, 75);
|
||||||
|
cbsCIF = line.substring(84, 97);
|
||||||
|
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();
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
System.out.println("___________________________________________________");
|
||||||
|
TimeUnit.MINUTES.sleep(sleep);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.out.println("___________________________________________________");
|
||||||
|
TimeUnit.MINUTES.sleep(sleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user