Replace CustomerExtrenalInfo.jsp

parent d037a259
......@@ -6,36 +6,44 @@
<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
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/registration/verification";
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");
......@@ -49,8 +57,8 @@
}
in.close();
infoResponse = apiResponse.toString();
BaseLogger.log("3", null, null, "API Response: " + infoResponse);
panVerificationResponse = apiResponse.toString();
BaseLogger.log("3", null, null, "API Response for PAN Verification: " + panVerificationResponse);
// Store the API response in the database
Connection connection = null;
......@@ -58,10 +66,11 @@
try {
ConnDriver connDriver = new ConnDriver();
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.setString(1, custCode);
pstmt.setString(2, infoResponse);
pstmt.setString(2, "Pan Verification");
pstmt.setString(3, panVerificationResponse);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
......@@ -82,21 +91,36 @@
}
}
} 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>
<%-- 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>
<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>
......@@ -105,9 +129,8 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) {
</tr>
</thead>
<tbody>
<%-- Parse JSON response using JavaScript --%>
<script>
var jsonData = <%=infoResponse.replaceAll("\"", "\\\"")%>;
var jsonData = <%=panVerificationResponse.replaceAll("\"", "\\\"")%>;
function createTableFromJson(data, parentElement) {
for (var key in data) {
......@@ -137,8 +160,9 @@ if (infoResponse != null || !infoResponse.trim().isEmpty()) {
</script>
</tbody>
</table>
<% } else { %>
<p>No data available.</p>
<% } 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