From cbaee03e06d59cbd17862cbbf9b826ad7a59f189 Mon Sep 17 00:00:00 2001 From: asif Date: Tue, 5 Aug 2025 12:26:35 +0530 Subject: [PATCH] added purulia and Mughberia to Nabard bank list --- .../java/com/methods/RequestResponse.java | 1245 ++++++++--------- 1 file changed, 620 insertions(+), 625 deletions(-) diff --git a/src/main/java/com/methods/RequestResponse.java b/src/main/java/com/methods/RequestResponse.java index 0562829..256e32a 100644 --- a/src/main/java/com/methods/RequestResponse.java +++ b/src/main/java/com/methods/RequestResponse.java @@ -28,663 +28,658 @@ 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 Properties prop = new Properties(); - static Logger log = Logger.getLogger(Scheduler.class.getName()); + static Connection connection = null; + static ResultSet rs = null; + static Statement statement = null; + public static Properties prop = new Properties(); + static Logger log = Logger.getLogger(Scheduler.class.getName()); - public static ArrayList get_response(String jsonInputString, String date) - throws IOException { - int responseCode = -1; - String reverseTrandate = ""; - InputStream input1 = null; - String apiURL = null; - try { - String bc = new JSONObject(jsonInputString).getString("bankcode"); - input1 = Scheduler.class.getClass().getResourceAsStream("/Properties.properties"); - - prop.load(input1); - if(bc.equals("0005") || bc.equals("0021")) { - apiURL = prop.getProperty("APIURL_NABARD"); - } else { - apiURL = prop.getProperty("APIURL_UCB"); - } - } catch (IOException ex) { - - log.error(String.valueOf(ex.getMessage()) + " error in request response class line no 67"); - } catch(Exception e) { - log.error(e.getMessage()); - e.printStackTrace(); - } finally { - - if (input1 != null) { + public static ArrayList get_response(String jsonInputString, String date) + throws IOException { + int responseCode = -1; + String reverseTrandate = ""; + InputStream input1 = null; + String apiURL = null; try { - input1.close(); - } catch (IOException e) { - log.error(e.getMessage()); - } + String bc = new JSONObject(jsonInputString).getString("bankcode"); + input1 = Scheduler.class.getClass().getResourceAsStream("/Properties.properties"); - } else { + prop.load(input1); + if (bc.equals("0005") || bc.equals("0021") || bc.equals("0016") || bc.equals("0018")) { + apiURL = prop.getProperty("APIURL_NABARD"); + } else { + apiURL = prop.getProperty("APIURL_UCB"); + } + } catch (IOException ex) { - log.error( - "Either no properties file found or error in properties file path in request response" - + " class"); - } - } - - log.info("Req MSG : " + jsonInputString); - - ArrayList data = new ArrayList<>(); - URL url = null; - - try { - url = new URL(apiURL); - } catch (MalformedURLException e1) { - - log.error(String.valueOf(e1.getMessage()) + " error in request response class on line no 96"); - } - 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) { - - log.error( - String.valueOf(e2.getMessage()) + " error in request response class on line no 110"); - } - - Exception exception1 = null, exception2 = null; - try { - OutputStream os = con.getOutputStream(); - try { - byte[] input = jsonInputString.getBytes("utf-8"); - os.write(input, 0, input.length); - } finally { - if (os != null) os.close(); - } - } finally { - exception2 = null; - if (exception1 == null) { - exception1 = exception2; - } else if (exception1 != exception2) { - exception1.addSuppressed(exception2); - } - } - - log.info("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) { - - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 139"); - } - try { - in.close(); - } catch (IOException e1) { - - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 145"); - } - - try { - response.append("}"); - - if (response.toString().contains("No data found")) { - - JSONObject json = new JSONObject(response.toString()); - JSONObject errorobj = new JSONObject(json.get("result").toString()); - - String bankcode = errorobj.getString("bankcode"); - String reason = errorobj.getString("reason"); - String errordategetfromjson = errorobj.getString("trandate"); - SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); - Date date2 = formatter1.parse(errordategetfromjson); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - String errordate = dateFormat.format(date2); - - try { - ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); + log.error(String.valueOf(ex.getMessage()) + " error in request response class line no 67"); } catch (Exception e) { + log.error(e.getMessage()); + e.printStackTrace(); + } finally { - log.info("Unable to add error log into ipks database"); + if (input1 != null) { + try { + input1.close(); + } catch (IOException e) { + log.error(e.getMessage()); + } + + } else { + + log.error( + "Either no properties file found or error in properties file path in request response" + + " class"); + } + } + + log.info("Req MSG : " + jsonInputString); + + ArrayList data = new ArrayList<>(); + URL url = null; + + try { + url = new URL(apiURL); + } catch (MalformedURLException e1) { + + log.error(String.valueOf(e1.getMessage()) + " error in request response class on line no 96"); + } + 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) { + + log.error( + String.valueOf(e2.getMessage()) + " error in request response class on line no 110"); + } + + Exception exception1 = null, exception2 = null; + try { + OutputStream os = con.getOutputStream(); + try { + byte[] input = jsonInputString.getBytes("utf-8"); + os.write(input, 0, input.length); + } finally { + if (os != null) + os.close(); + } + } finally { + exception2 = null; + if (exception1 == null) { + exception1 = exception2; + } else if (exception1 != exception2) { + exception1.addSuppressed(exception2); + } + } + + log.info("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) { + + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 139"); + } + try { + in.close(); + } catch (IOException e1) { + + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 145"); } try { - ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); - } catch (Exception e) { + response.append("}"); - log.info("Unable to add error log into API database"); + if (response.toString().contains("No data found")) { + + JSONObject json = new JSONObject(response.toString()); + JSONObject errorobj = new JSONObject(json.get("result").toString()); + + String bankcode = errorobj.getString("bankcode"); + String reason = errorobj.getString("reason"); + String errordategetfromjson = errorobj.getString("trandate"); + SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); + Date date2 = formatter1.parse(errordategetfromjson); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + String errordate = dateFormat.format(date2); + + try { + ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into ipks database"); + } + + try { + ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into API database"); + } + + } else if (response.toString().contains("Unable to fetch data")) { + + JSONObject json = new JSONObject(response.toString()); + JSONObject errorobj = new JSONObject(json.get("result").toString()); + + String bankcode = errorobj.getString("bankcode"); + String reason = errorobj.getString("reason"); + String errordategetfromjson = errorobj.getString("trandate"); + SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); + Date date2 = formatter1.parse(errordategetfromjson); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + String errordate = dateFormat.format(date2); + + try { + ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into ipks database"); + } + + try { + ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into API database"); + } + } else if (response.toString().contains("SERVER UNAVAILABLE")) { + + JSONObject json = new JSONObject(response.toString()); + JSONObject errorobj = new JSONObject(json.get("result").toString()); + + String bankcode = errorobj.getString("bankcode"); + String reason = errorobj.getString("reason"); + String errordategetfromjson = errorobj.getString("trandate"); + SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); + Date date2 = formatter1.parse(errordategetfromjson); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + String errordate = dateFormat.format(date2); + + try { + ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into ipks database"); + } + + try { + ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); + } catch (Exception e) { + + log.info("Unable to add error log into API database"); + } + } else { + + System.out.println(response.toString()); + 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.setBankcode(dataD.get("bankcode").toString().trim()); + + String Trandate = dataD.get("trandate").toString().trim(); + SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); + Date date1 = formatter1.parse(Trandate); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + reverseTrandate = dateFormat.format(date1); + + databean.setTrandate(reverseTrandate); + + databean.setNarration(dataD.get("narration").toString().trim()); + databean.setTrnamt(dataD.get("trnamt").toString().trim()); + + databean.setJrnl(dataD.getString("jrnl").toString().trim()); + databean.setAcctno(dataD.getString("acctno").toString().trim()); + databean.setRemarks(dataD.getString("remarks").toString().trim()); + + data.add(databean); + } + + try { + setDatainAPIDatabase(data, reverseTrandate); + } catch (Exception e) { + + String bankcode = "", reason = e.getMessage(); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + String errordate = dateFormat.format(new Date()); + + try { + ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "API"); + } catch (Exception e2) { + + log.info("Unable to add error log into API database"); + } + } + + try { + setDatainDatabase(data, reverseTrandate); + } catch (Exception e) { + + String bankcode = ""; + String reason = e.getMessage(); + DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); + String errordate = dateFormat.format(new Date()); + + try { + ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "IPKS"); + } catch (Exception e1) { + + log.info("Unable to add error log into ipks database"); + } + } + } + + } catch (Exception e3) { + + log.error( + String.valueOf(e3.getMessage()) + " error in request response class on line no 235"); } - } else if (response.toString().contains("Unable to fetch data")) { + return data; + } - JSONObject json = new JSONObject(response.toString()); - JSONObject errorobj = new JSONObject(json.get("result").toString()); + public static ArrayList getRequestBody() { + Date date = new Date(); - String bankcode = errorobj.getString("bankcode"); - String reason = errorobj.getString("reason"); - String errordategetfromjson = errorobj.getString("trandate"); - SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); - Date date2 = formatter1.parse(errordategetfromjson); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - String errordate = dateFormat.format(date2); + DateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + + Calendar cal = Calendar.getInstance(); + String dateToday = sdf.format(cal.getTime()); + + log.info("Date :" + dateToday); + + String url = null; + String bankCode = null; + ArrayList 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(8); + bankCode = rs.getString(6); + String finUrl = url.replaceAll("dt", dateToday); + finUrl = finUrl.replaceAll("bcode", bankCode); + + finUrl = finUrl.replaceAll("tnty", "dbtl"); + finalUrl.add(finUrl); + } + + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 367"); + } finally { + + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 374"); + } + } + return finalUrl; + } + + public static ArrayList getRequestBodyForPreviousDay() { + Date date = new Date(); + + DateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + cal.add(6, -1); + + String dateToPreviousday = sdf.format(cal.getTime()); + + log.info("Date :" + dateToPreviousday); + + String url = null; + String bankCode = null; + ArrayList 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(8); + bankCode = rs.getString(6); + String finUrl = url.replaceAll("dt", dateToPreviousday); + finUrl = finUrl.replaceAll("bcode", bankCode); + finUrl = finUrl.replaceAll("tnty", "dbtl"); + System.out.println(finUrl); + finalUrl.add(finUrl); + } + + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 376"); + } finally { + + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 383"); + } + } + return finalUrl; + } + + public static void setDatainDatabase(ArrayList data, String date) { + Connection connection = null; + ResultSet rs = null; + Statement st = null; + String query = null; + PreparedStatement statement = null; + ArrayList combination = new ArrayList<>(); try { - ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); - } catch (Exception e) { + try { + connection = Util.getDBConnection(); + st = connection.createStatement(); - log.info("Unable to add error log into ipks database"); + rs = st.executeQuery( + "select l.bankcode,l.jrnl_id,l.tran_date from ach_api_log l where l.tran_date='" + + date + + "'"); + + while (rs.next()) { + String comb = String.valueOf(rs.getString(1)) + "|" + rs.getString(2) + "|" + rs.getString(3); + + combination.add(comb); + } + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 402"); + } + + Iterator iter = data.iterator(); + Statement st2 = connection.createStatement(); + while (iter.hasNext()) { + DataBean d = iter.next(); + + if (combination.contains( + String.valueOf(d.getBankcode()) + "|" + d.getJrnl() + "|" + d.getTrandate()) + || d.getJrnl() == null + || d.getJrnl().equalsIgnoreCase("")) { + log.info( + "RECORD ALREADY PRESENT IPKS for " + + d.getBankcode() + + "|" + + d.getJrnl() + + "|" + + d.getTrandate()); + + continue; + } + query = "insert into ach_api_log(narration,status,bankcode,jrnl_id, tran_date, cbs_acct," + + " tran_amt,TXNIND) values ('" + + d.getNarration() + + "','" + + d.getRemarks() + + "','" + + d.getBankcode() + + "','" + + d.getJrnl() + + "','" + + d.getTrandate() + + "','" + + d.getAcctno() + + "',"; + query = String.valueOf(query) + + "abs(" + + d.getTrnamt() + + "),(case when to_number(" + + d.getTrnamt() + + ") < 0 then 'DR' else 'CR' end))"; + log.info("SQL Statement :" + query); + System.out.println(query); + + st2.addBatch(query); + log.info("Added to DB Insert Batch"); + } + + st2.executeBatch(); + log.info("Insert to DB Completed"); + log.info("Posting Txns in IPKS"); + + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 451"); + } finally { + + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 358"); + } } + } + + public static void ErrorStoreInDaatabaseIPKS( + String bankcode, String error_msg, String errordate, String Error_at) { + Connection connection = null; + + Statement st = null; + String query = null; try { - ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); + connection = Util.getDBConnection(); + st = connection.createStatement(); + + query = "insert into neft_rtgs_dbtl_api_error_log" + + " (bank_code,proc_date,proc_time,api_type,error_msg,error_at) values('" + + bankcode + + "','" + + errordate + + "',to_date(to_char(SYSTIMESTAMP," + + " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),'Dbtl','" + + error_msg + + "','" + + Error_at + + "')"; + + st = connection.createStatement(); + int updatecount = st.executeUpdate(query); + + try { + CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); + cs.execute(); + + log.info("Posting Completed, Check log."); + + } catch (Exception e) { + + log.error(String.valueOf(e.getMessage()) + " error in procedure"); + } + } catch (Exception e) { + log.error(String.valueOf(e.getMessage()) + " error in request response class on line no 484"); + } finally { - log.info("Unable to add error log into API database"); + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 91 "); + } } - } else if (response.toString().contains("SERVER UNAVAILABLE")) { + } - JSONObject json = new JSONObject(response.toString()); - JSONObject errorobj = new JSONObject(json.get("result").toString()); + public static void ErrorStoreInDaatabaseAPI( + String bankcode, String error_msg, String errordate, String Error_at) { + Connection connection = null; - String bankcode = errorobj.getString("bankcode"); - String reason = errorobj.getString("reason"); - String errordategetfromjson = errorobj.getString("trandate"); - SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); - Date date2 = formatter1.parse(errordategetfromjson); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - String errordate = dateFormat.format(date2); + Statement st = null; + String query = null; try { - ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "CEDGE"); - } catch (Exception e) { + connection = Util.getDBConnectionforAPI(); + st = connection.createStatement(); - log.info("Unable to add error log into ipks database"); + query = "insert into neft_rtgs_dbtl_api_error_log" + + " (bank_code,proc_date,proc_time,api_type,error_msg,error_at) values('" + + bankcode + + "','" + + errordate + + "',to_date(to_char(SYSTIMESTAMP," + + " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),'Dbtl','" + + error_msg + + "','" + + Error_at + + "')"; + + st = connection.createStatement(); + int updatecount = st.executeUpdate(query); + + try { + CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); + cs.execute(); + + log.info("Posting Completed, Check log."); + + } catch (Exception e) { + + log.error(String.valueOf(e.getMessage()) + " error in procedure"); + } + + } catch (Exception e) { + log.error(String.valueOf(e.getMessage()) + " error in request response class on line no 519"); + } finally { + + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 527 "); + } } + } + + public static void setDatainAPIDatabase(ArrayList data, String date) { + Connection connection = null; + ResultSet rs = null; + Statement st = null; + String query = null; + PreparedStatement statement = null; + ArrayList combination1 = new ArrayList<>(); try { - ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "CEDGE"); - } catch (Exception e) { + try { + connection = Util.getDBConnectionforAPI(); + st = connection.createStatement(); - log.info("Unable to add error log into API database"); + rs = st.executeQuery( + "select l.bankcode,l.jrnl_id,l.tran_date from ach_api_log l where l.tran_date='" + + date + + "'"); + + while (rs.next()) { + String comb = String.valueOf(rs.getString(1)) + "|" + rs.getString(2) + "|" + rs.getString(3); + + combination1.add(comb); + } + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 559"); + } + + Iterator iter = data.iterator(); + Statement st2 = connection.createStatement(); + while (iter.hasNext()) { + DataBean d = iter.next(); + + if (combination1.contains( + String.valueOf(d.getBankcode()) + "|" + d.getJrnl() + "|" + d.getTrandate()) + || d.getJrnl() == null + || d.getJrnl().equalsIgnoreCase("")) { + log.info( + "RECORD ALREADY PRESENT API for " + + d.getBankcode() + + "|" + + d.getJrnl() + + "|" + + d.getTrandate()); + + continue; + } + query = "insert into ach_api_log(narration,status,bankcode,jrnl_id, tran_date, cbs_acct," + + " tran_amt,TXNIND) values ('" + + d.getNarration() + + "','" + + d.getRemarks() + + "','" + + d.getBankcode() + + "','" + + d.getJrnl() + + "','" + + d.getTrandate() + + "','" + + d.getAcctno() + + "',"; + query = String.valueOf(query) + + "abs(" + + d.getTrnamt() + + "),(case when to_number(" + + d.getTrnamt() + + ") < 0 then 'DR' else 'CR' end))"; + log.info("SQL Statement :" + query); + System.out.println("SQL Statement :" + query); + st2.addBatch(query); + log.info("Added to DB Insert Batch"); + } + + st2.executeBatch(); + log.info("Insert to DB Completed"); + log.info("Posting Txns in IPKS"); + + CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); + cs.execute(); + + log.info("Posting Completed, Check log."); + + } catch (Exception ex) { + log.error( + String.valueOf(ex.getMessage()) + " error in request response class on line no 594"); + } finally { + + try { + if (connection != null) + connection.close(); + } catch (SQLException e1) { + log.error( + String.valueOf(e1.getMessage()) + " error in request response class on line no 601 "); + } } - } else { - - System.out.println(response.toString()); - 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.setBankcode(dataD.get("bankcode").toString().trim()); - - String Trandate = dataD.get("trandate").toString().trim(); - SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); - Date date1 = formatter1.parse(Trandate); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - reverseTrandate = dateFormat.format(date1); - - databean.setTrandate(reverseTrandate); - - databean.setNarration(dataD.get("narration").toString().trim()); - databean.setTrnamt(dataD.get("trnamt").toString().trim()); - - databean.setJrnl(dataD.getString("jrnl").toString().trim()); - databean.setAcctno(dataD.getString("acctno").toString().trim()); - databean.setRemarks(dataD.getString("remarks").toString().trim()); - - data.add(databean); - } - - try { - setDatainAPIDatabase(data, reverseTrandate); - } catch (Exception e) { - - String bankcode = "", reason = e.getMessage(); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - String errordate = dateFormat.format(new Date()); - - try { - ErrorStoreInDaatabaseAPI(bankcode, reason, errordate, "API"); - } catch (Exception e2) { - - log.info("Unable to add error log into API database"); - } - } - - try { - setDatainDatabase(data, reverseTrandate); - } catch (Exception e) { - - String bankcode = ""; - String reason = e.getMessage(); - DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy"); - String errordate = dateFormat.format(new Date()); - - try { - ErrorStoreInDaatabaseIPKS(bankcode, reason, errordate, "IPKS"); - } catch (Exception e1) { - - log.info("Unable to add error log into ipks database"); - } - } - } - - } catch (Exception e3) { - - log.error( - String.valueOf(e3.getMessage()) + " error in request response class on line no 235"); } - - return data; - } - - public static ArrayList getRequestBody() { - Date date = new Date(); - - DateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - - Calendar cal = Calendar.getInstance(); - String dateToday = sdf.format(cal.getTime()); - - log.info("Date :" + dateToday); - - String url = null; - String bankCode = null; - ArrayList 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(8); - bankCode = rs.getString(6); - String finUrl = url.replaceAll("dt", dateToday); - finUrl = finUrl.replaceAll("bcode", bankCode); - - finUrl = finUrl.replaceAll("tnty", "dbtl"); - finalUrl.add(finUrl); - } - - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 367"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 374"); - } - } - return finalUrl; - } - - public static ArrayList getRequestBodyForPreviousDay() { - Date date = new Date(); - - DateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - cal.add(6, -1); - - String dateToPreviousday = sdf.format(cal.getTime()); - - log.info("Date :" + dateToPreviousday); - - String url = null; - String bankCode = null; - ArrayList 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(8); - bankCode = rs.getString(6); - String finUrl = url.replaceAll("dt", dateToPreviousday); - finUrl = finUrl.replaceAll("bcode", bankCode); - finUrl = finUrl.replaceAll("tnty", "dbtl"); - System.out.println(finUrl); - finalUrl.add(finUrl); - } - - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 376"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 383"); - } - } - return finalUrl; - } - - public static void setDatainDatabase(ArrayList data, String date) { - Connection connection = null; - ResultSet rs = null; - Statement st = null; - String query = null; - PreparedStatement statement = null; - ArrayList combination = new ArrayList<>(); - - try { - try { - connection = Util.getDBConnection(); - st = connection.createStatement(); - - rs = - st.executeQuery( - "select l.bankcode,l.jrnl_id,l.tran_date from ach_api_log l where l.tran_date='" - + date - + "'"); - - while (rs.next()) { - String comb = - String.valueOf(rs.getString(1)) + "|" + rs.getString(2) + "|" + rs.getString(3); - - combination.add(comb); - } - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 402"); - } - - Iterator iter = data.iterator(); - Statement st2 = connection.createStatement(); - while (iter.hasNext()) { - DataBean d = iter.next(); - - if (combination.contains( - String.valueOf(d.getBankcode()) + "|" + d.getJrnl() + "|" + d.getTrandate()) - || d.getJrnl() == null - || d.getJrnl().equalsIgnoreCase("")) { - log.info( - "RECORD ALREADY PRESENT IPKS for " - + d.getBankcode() - + "|" - + d.getJrnl() - + "|" - + d.getTrandate()); - - continue; - } - query = - "insert into ach_api_log(narration,status,bankcode,jrnl_id, tran_date, cbs_acct," - + " tran_amt,TXNIND) values ('" - + d.getNarration() - + "','" - + d.getRemarks() - + "','" - + d.getBankcode() - + "','" - + d.getJrnl() - + "','" - + d.getTrandate() - + "','" - + d.getAcctno() - + "',"; - query = - String.valueOf(query) - + "abs(" - + d.getTrnamt() - + "),(case when to_number(" - + d.getTrnamt() - + ") < 0 then 'DR' else 'CR' end))"; - log.info("SQL Statement :" + query); - System.out.println(query); - - st2.addBatch(query); - log.info("Added to DB Insert Batch"); - } - - st2.executeBatch(); - log.info("Insert to DB Completed"); - log.info("Posting Txns in IPKS"); - - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 451"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 358"); - } - } - } - - public static void ErrorStoreInDaatabaseIPKS( - String bankcode, String error_msg, String errordate, String Error_at) { - Connection connection = null; - - Statement st = null; - String query = null; - - try { - connection = Util.getDBConnection(); - st = connection.createStatement(); - - query = - "insert into neft_rtgs_dbtl_api_error_log" - + " (bank_code,proc_date,proc_time,api_type,error_msg,error_at) values('" - + bankcode - + "','" - + errordate - + "',to_date(to_char(SYSTIMESTAMP," - + " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),'Dbtl','" - + error_msg - + "','" - + Error_at - + "')"; - - st = connection.createStatement(); - int updatecount = st.executeUpdate(query); - - try { - CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); - cs.execute(); - - log.info("Posting Completed, Check log."); - - } catch (Exception e) { - - log.error(String.valueOf(e.getMessage()) + " error in procedure"); - } - - } catch (Exception e) { - log.error(String.valueOf(e.getMessage()) + " error in request response class on line no 484"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 91 "); - } - } - } - - public static void ErrorStoreInDaatabaseAPI( - String bankcode, String error_msg, String errordate, String Error_at) { - Connection connection = null; - - Statement st = null; - String query = null; - - try { - connection = Util.getDBConnectionforAPI(); - st = connection.createStatement(); - - query = - "insert into neft_rtgs_dbtl_api_error_log" - + " (bank_code,proc_date,proc_time,api_type,error_msg,error_at) values('" - + bankcode - + "','" - + errordate - + "',to_date(to_char(SYSTIMESTAMP," - + " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),'Dbtl','" - + error_msg - + "','" - + Error_at - + "')"; - - st = connection.createStatement(); - int updatecount = st.executeUpdate(query); - - try { - CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); - cs.execute(); - - log.info("Posting Completed, Check log."); - - } catch (Exception e) { - - log.error(String.valueOf(e.getMessage()) + " error in procedure"); - } - - } catch (Exception e) { - log.error(String.valueOf(e.getMessage()) + " error in request response class on line no 519"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 527 "); - } - } - } - - public static void setDatainAPIDatabase(ArrayList data, String date) { - Connection connection = null; - ResultSet rs = null; - Statement st = null; - String query = null; - PreparedStatement statement = null; - ArrayList combination1 = new ArrayList<>(); - - try { - try { - connection = Util.getDBConnectionforAPI(); - st = connection.createStatement(); - - rs = - st.executeQuery( - "select l.bankcode,l.jrnl_id,l.tran_date from ach_api_log l where l.tran_date='" - + date - + "'"); - - while (rs.next()) { - String comb = - String.valueOf(rs.getString(1)) + "|" + rs.getString(2) + "|" + rs.getString(3); - - combination1.add(comb); - } - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 559"); - } - - Iterator iter = data.iterator(); - Statement st2 = connection.createStatement(); - while (iter.hasNext()) { - DataBean d = iter.next(); - - if (combination1.contains( - String.valueOf(d.getBankcode()) + "|" + d.getJrnl() + "|" + d.getTrandate()) - || d.getJrnl() == null - || d.getJrnl().equalsIgnoreCase("")) { - log.info( - "RECORD ALREADY PRESENT API for " - + d.getBankcode() - + "|" - + d.getJrnl() - + "|" - + d.getTrandate()); - - continue; - } - query = - "insert into ach_api_log(narration,status,bankcode,jrnl_id, tran_date, cbs_acct," - + " tran_amt,TXNIND) values ('" - + d.getNarration() - + "','" - + d.getRemarks() - + "','" - + d.getBankcode() - + "','" - + d.getJrnl() - + "','" - + d.getTrandate() - + "','" - + d.getAcctno() - + "',"; - query = - String.valueOf(query) - + "abs(" - + d.getTrnamt() - + "),(case when to_number(" - + d.getTrnamt() - + ") < 0 then 'DR' else 'CR' end))"; - log.info("SQL Statement :" + query); - System.out.println("SQL Statement :" + query); - st2.addBatch(query); - log.info("Added to DB Insert Batch"); - } - - st2.executeBatch(); - log.info("Insert to DB Completed"); - log.info("Posting Txns in IPKS"); - - CallableStatement cs = connection.prepareCall("{call ach_api_txn_post}"); - cs.execute(); - - log.info("Posting Completed, Check log."); - - } catch (Exception ex) { - log.error( - String.valueOf(ex.getMessage()) + " error in request response class on line no 594"); - } finally { - - try { - if (connection != null) connection.close(); - } catch (SQLException e1) { - log.error( - String.valueOf(e1.getMessage()) + " error in request response class on line no 601 "); - } - } - } }