Replace CustomerExtrenalInfo.jsp

parent d037a259
......@@ -6,139 +6,163 @@
<head>
<meta charset="UTF-8">
<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>
<body>
<%
BaseLogger.log("3", null, null, "Customer Exterranl Info ");
BaseLogger.log("3", null, null, "Customer External Info ");
System.out.println("...@@@@@@@ In CustExtInfo.jsp @@@@@@@@...");
String custCode = request.getParameter("CUST_CODE");
String selectedOption = request.getParameter("idType");
BaseLogger.log("3", null, null, "CustCode [" + custCode + "]");
BaseLogger.log("3", null, null, "Selected Option [" + selectedOption + "]");
UserInfoBean userInfo = (UserInfoBean) session.getAttribute("USER_INFO");
DBAccessEJB dbAccess = new DBAccessEJB();
String infoResponse = null;
BaseLogger.log("3", null, null, "infoResponse1 :: "+infoResponse);
// Check if custCode is present in the database
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 (custCODE != null) {
BaseLogger.log("3", null, null, "Inside if block..");
// If custCode is present, get the INFO_RESPONSE from database
infoResponse = dbAccess.getDBColumnValue("CUST_EXT_INFO", "INFO_RESPONSE", "CUST_CODE = '" + custCode + "'", userInfo.getTransDB());
BaseLogger.log("3", null, null, "infoResponse ::===> [" + infoResponse + "]");
} else {
BaseLogger.log("3", null, null, "Inside else block..");
// If custCode is not present, call the API and store the response in database
try {
String apiUrl = "https://sandboxapi.atlas.vayana.com/AtlasApi/v1.0/aadhaar/udyam/registration/verification";
URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer apiResponse = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
apiResponse.append(inputLine);
}
in.close();
infoResponse = apiResponse.toString();
BaseLogger.log("3", null, null, "API Response: " + infoResponse);
// Store the API response in the database
Connection connection = null;
PreparedStatement pstmt = null;
try {
ConnDriver connDriver = new ConnDriver();
connection = connDriver.getConnectDB(userInfo.getTransDB());
String insertQuery = "INSERT INTO CUST_EXT_INFO (CUST_CODE, INFO_RESPONSE) VALUES (?, ?)";
pstmt = connection.prepareStatement(insertQuery);
pstmt.setString(1, custCode);
pstmt.setString(2, infoResponse);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
String panNumber = null;
String panVerificationResponse = null;
if ("pan".equals(selectedOption)) {
panNumber = dbAccess.getDBColumnValue("CUSTOMER", "PAN_NO", "CUST_CODE = '" + custCode + "'", userInfo.getTransDB());
if (panNumber != null && !panNumber.isEmpty()) {
panVerificationResponse = dbAccess.getDBColumnValue("CUST_EXT_INFO", "INFO_RESPONSE", "CUST_CODE = '" + custCode + "' AND INFO_TYPE = 'Pan Verification'", userInfo.getTransDB());
if (panVerificationResponse == null) {
// Call the API if panVerificationResponse is null
try {
String apiUrl = "https://sandboxapi.atlas.vayana.com/AtlasApi/v1.0/aadhaar/udyam/verification";
URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer apiResponse = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
apiResponse.append(inputLine);
}
}
if (connection != null) {
in.close();
panVerificationResponse = apiResponse.toString();
BaseLogger.log("3", null, null, "API Response for PAN Verification: " + panVerificationResponse);
// Store the API response in the database
Connection connection = null;
PreparedStatement pstmt = null;
try {
connection.close();
ConnDriver connDriver = new ConnDriver();
connection = connDriver.getConnectDB(userInfo.getTransDB());
String insertQuery = "INSERT INTO CUST_EXT_INFO (CUST_CODE, INFO_TYPE, INFO_RESPONSE) VALUES (?, ?, ?)";
pstmt = connection.prepareStatement(insertQuery);
pstmt.setString(1, custCode);
pstmt.setString(2, "Pan Verification");
pstmt.setString(3, panVerificationResponse);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
out.println("Error calling API for PAN Verification: " + e.getMessage());
}
}
} catch (Exception e) {
out.println("Error calling API: " + e.getMessage());
}
}
%>
<h1>Customer External Information</h1>
<%-- Check if infoResponse is not null and parse JSON --%>
<%
BaseLogger.log("3", null, null, "infoResponse2 :: "+infoResponse);
if (infoResponse != null || !infoResponse.trim().isEmpty()) {
BaseLogger.log("3", null, null, "Inside the If Block :: " + infoResponse);
%>
<h2>JSON Data </h2>
<table id="jsonData">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<%-- Parse JSON response using JavaScript --%>
<script>
var jsonData = <%=infoResponse.replaceAll("\"", "\\\"")%>;
function createTableFromJson(data, parentElement) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
var value = data[key];
var row = parentElement.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = key;
if (typeof value === 'object' && value !== null) {
cell2.innerHTML = "";
var nestedTable = document.createElement("table");
var nestedBody = document.createElement("tbody");
nestedTable.appendChild(nestedBody);
createTableFromJson(value, nestedBody);
cell2.appendChild(nestedTable);
} else {
cell2.innerHTML = value;
<form id="detailsForm" method="post" action="">
<label for="idType">Choose an ID type:</label>
<select id="idType" name="idType" onchange="updateInputBox()">
<option value="pan" <%= "pan".equals(selectedOption) ? "selected" : "" %>>Pan</option>
<option value="aadharno" <%= "aadharno".equals(selectedOption) ? "selected" : "" %>>Aadharno</option>
<option value="udyogno" <%= "udyogno".equals(selectedOption) ? "selected" : "" %>>Udyog no</option>
</select>
<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">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<script>
var jsonData = <%=panVerificationResponse.replaceAll("\"", "\\\"")%>;
function createTableFromJson(data, parentElement) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
var value = data[key];
var row = parentElement.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = key;
if (typeof value === 'object' && value !== null) {
cell2.innerHTML = "";
var nestedTable = document.createElement("table");
var nestedBody = document.createElement("tbody");
nestedTable.appendChild(nestedBody);
createTableFromJson(value, nestedBody);
cell2.appendChild(nestedTable);
} else {
cell2.innerHTML = value;
}
}
}
}
}
var tableBody = document.getElementById("jsonData").getElementsByTagName('tbody')[0];
createTableFromJson(JSON.parse(jsonData), tableBody);
</script>
</tbody>
</table>
<% } else { %>
<p>No data available.</p>
var tableBody = document.getElementById("jsonData").getElementsByTagName('tbody')[0];
createTableFromJson(JSON.parse(jsonData), tableBody);
</script>
</tbody>
</table>
<% } else { %>
<p>No Pan Verification response found for the given customer code.</p>
<% } %>
<% } %>
</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