Replace CustomerExtrenalInfo.jsp

parent d037a259
...@@ -6,36 +6,44 @@ ...@@ -6,36 +6,44 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Customer External Information</title> <title>Customer External Information</title>
<script>
function updateInputBox() {
var selectedOption = document.getElementById("idType").value;
document.getElementById("selectedIdType").value = selectedOption;
}
function getDetails() {
document.getElementById("detailsForm").submit();
}
</script>
</head> </head>
<body> <body>
<% <%
BaseLogger.log("3", null, null, "Customer Exterranl Info "); BaseLogger.log("3", null, null, "Customer External Info ");
System.out.println("...@@@@@@@ In CustExtInfo.jsp @@@@@@@@..."); System.out.println("...@@@@@@@ In CustExtInfo.jsp @@@@@@@@...");
String custCode = request.getParameter("CUST_CODE"); String custCode = request.getParameter("CUST_CODE");
String selectedOption = request.getParameter("idType");
BaseLogger.log("3", null, null, "CustCode [" + custCode + "]"); BaseLogger.log("3", null, null, "CustCode [" + custCode + "]");
BaseLogger.log("3", null, null, "Selected Option [" + selectedOption + "]");
UserInfoBean userInfo = (UserInfoBean) session.getAttribute("USER_INFO"); UserInfoBean userInfo = (UserInfoBean) session.getAttribute("USER_INFO");
DBAccessEJB dbAccess = new DBAccessEJB(); DBAccessEJB dbAccess = new DBAccessEJB();
String infoResponse = null; String infoResponse = null;
BaseLogger.log("3", null, null, "infoResponse1 :: "+infoResponse); String panNumber = null;
// Check if custCode is present in the database String panVerificationResponse = null;
String custCODE = dbAccess.getDBColumnValue("CUST_EXT_INFO", "CUST_CODE", "CUST_CODE = '" + custCode + "'", userInfo.getTransDB());
BaseLogger.log("3", null, null, "CustCode present in CUST_EXT_INFO Table [" + custCODE + "]"); if ("pan".equals(selectedOption)) {
panNumber = dbAccess.getDBColumnValue("CUSTOMER", "PAN_NO", "CUST_CODE = '" + custCode + "'", userInfo.getTransDB());
if (custCODE != null) {
BaseLogger.log("3", null, null, "Inside if block.."); if (panNumber != null && !panNumber.isEmpty()) {
// If custCode is present, get the INFO_RESPONSE from database panVerificationResponse = dbAccess.getDBColumnValue("CUST_EXT_INFO", "INFO_RESPONSE", "CUST_CODE = '" + custCode + "' AND INFO_TYPE = 'Pan Verification'", userInfo.getTransDB());
infoResponse = dbAccess.getDBColumnValue("CUST_EXT_INFO", "INFO_RESPONSE", "CUST_CODE = '" + custCode + "'", userInfo.getTransDB());
BaseLogger.log("3", null, null, "infoResponse ::===> [" + infoResponse + "]"); if (panVerificationResponse == null) {
} else { // Call the API if panVerificationResponse is null
BaseLogger.log("3", null, null, "Inside else block..");
// If custCode is not present, call the API and store the response in database
try { try {
String apiUrl = "https://sandboxapi.atlas.vayana.com/AtlasApi/v1.0/aadhaar/udyam/registration/verification"; String apiUrl = "https://sandboxapi.atlas.vayana.com/AtlasApi/v1.0/aadhaar/udyam/verification";
URL url = new URL(apiUrl); URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
...@@ -49,8 +57,8 @@ ...@@ -49,8 +57,8 @@
} }
in.close(); in.close();
infoResponse = apiResponse.toString(); panVerificationResponse = apiResponse.toString();
BaseLogger.log("3", null, null, "API Response: " + infoResponse); BaseLogger.log("3", null, null, "API Response for PAN Verification: " + panVerificationResponse);
// Store the API response in the database // Store the API response in the database
Connection connection = null; Connection connection = null;
...@@ -58,10 +66,11 @@ ...@@ -58,10 +66,11 @@
try { try {
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
connection = connDriver.getConnectDB(userInfo.getTransDB()); connection = connDriver.getConnectDB(userInfo.getTransDB());
String insertQuery = "INSERT INTO CUST_EXT_INFO (CUST_CODE, INFO_RESPONSE) VALUES (?, ?)"; String insertQuery = "INSERT INTO CUST_EXT_INFO (CUST_CODE, INFO_TYPE, INFO_RESPONSE) VALUES (?, ?, ?)";
pstmt = connection.prepareStatement(insertQuery); pstmt = connection.prepareStatement(insertQuery);
pstmt.setString(1, custCode); pstmt.setString(1, custCode);
pstmt.setString(2, infoResponse); pstmt.setString(2, "Pan Verification");
pstmt.setString(3, panVerificationResponse);
pstmt.executeUpdate(); pstmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -82,21 +91,36 @@ ...@@ -82,21 +91,36 @@
} }
} }
} catch (Exception e) { } catch (Exception e) {
out.println("Error calling API: " + e.getMessage()); out.println("Error calling API for PAN Verification: " + e.getMessage());
}
}
} }
} }
%> %>
<h1>Customer External Information</h1> <h1>Customer External Information</h1>
<%-- Check if infoResponse is not null and parse JSON --%> <form id="detailsForm" method="post" action="">
<% <label for="idType">Choose an ID type:</label>
BaseLogger.log("3", null, null, "infoResponse2 :: "+infoResponse); <select id="idType" name="idType" onchange="updateInputBox()">
if (infoResponse != null || !infoResponse.trim().isEmpty()) { <option value="pan" <%= "pan".equals(selectedOption) ? "selected" : "" %>>Pan</option>
BaseLogger.log("3", null, null, "Inside the If Block :: " + infoResponse); <option value="aadharno" <%= "aadharno".equals(selectedOption) ? "selected" : "" %>>Aadharno</option>
<option value="udyogno" <%= "udyogno".equals(selectedOption) ? "selected" : "" %>>Udyog no</option>
%> </select>
<h2>JSON Data </h2> <input type="hidden" name="CUST_CODE" value="<%= custCode %>">
<br><br>
<label for="selectedIdType">Selected ID Type:</label>
<input type="text" id="selectedIdType" name="selectedIdType" readonly value="<%= selectedOption != null ? selectedOption : "" %>">
<br><br>
<button type="button" onclick="getDetails()">Get Details</button>
</form>
<% if ("pan".equals(selectedOption)) { %>
<h2>PAN Number</h2>
<p><%= panNumber != null ? panNumber : "No PAN number found for the given customer code." %></p>
<% if (panVerificationResponse != null && !panVerificationResponse.isEmpty()) { %>
<h2>Pan Verification Info Response</h2>
<table id="jsonData"> <table id="jsonData">
<thead> <thead>
<tr> <tr>
...@@ -105,9 +129,8 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) { ...@@ -105,9 +129,8 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<%-- Parse JSON response using JavaScript --%>
<script> <script>
var jsonData = <%=infoResponse.replaceAll("\"", "\\\"")%>; var jsonData = <%=panVerificationResponse.replaceAll("\"", "\\\"")%>;
function createTableFromJson(data, parentElement) { function createTableFromJson(data, parentElement) {
for (var key in data) { for (var key in data) {
...@@ -137,8 +160,9 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) { ...@@ -137,8 +160,9 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) {
</script> </script>
</tbody> </tbody>
</table> </table>
<% } else { %> <% } else { %>
<p>No data available.</p> <p>No Pan Verification response found for the given customer code.</p>
<% } %>
<% } %> <% } %>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment