Browse Source

changes in error handling from front end done

master
yoganandhan 1 year ago
parent
commit
e08dd8f536
  1. 51
      src/main/java/com/gcc/crslogs/controller/ApiController.java
  2. 1
      src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java
  3. 231
      src/main/resources/templates/modules/crslogspages/birth.html
  4. 245
      src/main/resources/templates/modules/crslogspages/death.html

51
src/main/java/com/gcc/crslogs/controller/ApiController.java

@ -7,11 +7,12 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -174,7 +176,11 @@ public class ApiController {
// try { // try {
// Map<String, Object> result = birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname, fathername, mothername); // Map<String, Object> result = birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname, fathername, mothername);
// return ResponseEntity.ok(result); // return ResponseEntity.ok(result);
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// Map<String, Object> error = new HashMap<>(); // Map<String, Object> error = new HashMap<>();
// error.put("status", false); // error.put("status", false);
@ -212,14 +218,34 @@ public ResponseEntity<?> fetchBirthCertificateSecurely(@RequestBody Map<String,
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Map<String, Object> error = new HashMap<>(); Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching birth record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false); error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error); return ResponseEntity.status(500).body(error);
} }
} }
}
// from external api restapiservices
// from external api restapiservices death certificate
@PostMapping("/death-details") @PostMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String, String> params) { public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String, String> params) {
@ -247,10 +273,27 @@ public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String,
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Map<String, Object> error = new HashMap<>(); Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching death record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false); error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error); return ResponseEntity.status(500).body(error);
} }
}
} }

1
src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java

@ -170,7 +170,6 @@ public class BirthAndDeathDetailsService {
String rawJson = response.getBody(); String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {}); Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
// ✅ Only keep records that actually have a PDF link // ✅ Only keep records that actually have a PDF link
// if (result.containsKey("certificate_details")) { // if (result.containsKey("certificate_details")) {
// List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details"); // List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");

231
src/main/resources/templates/modules/crslogspages/birth.html

@ -591,98 +591,11 @@ body {
</div> </div>
<!-- Death certificate card -->
<div class="card" id="death-card" style="display: none;">
<div class="card-header bg-dark text-white">
<h5>Death Certificate:-</h5>
</div>
<div class="card-body" >
<h6>
<strong>Death Certificate Details :-</strong>
</h6>
<hr />
<div class="container mt-5">
<!-- Row 1:Register No and Name -->
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="registerno">Enter Register Number </label> <input type="text"
class="form-control"
placeholder="Enter Register number">
</div>
<div class="col-md-5">
<label class="form-label" for="name">Person Name </label> <input type="text"
class="form-control" placeholder="Enter Person Name here" id="personname" oninput="this.value = this.value.replace(/[^a-zA-Z\s]/g, '')">
</div>
</div>
<!-- Row 2: D.O.B and Gender -->
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="name">Date of Death<span
class="text-danger">*</span></label> <input type="DATE"
class="form-control" placeholder="Select Date"
id="dateofdeath" onclick="this.showPicker()" required>
</div>
<div class="col-md-5"> <label class="form-label d-block">Gender <span class="text-danger">*</span></label>
<div class="d-flex align-items-center gap-3">
<div class="form-check form-check-inline mb-0">
<input class="form-check-input" type="radio" name="deathgender" id="deathGenderMale" value="Male" required> <label class="form-check-label" for="deathGenderMale">Male</label> </div>
<div class="form-check form-check-inline mb-0"> <input class="form-check-input" type="radio" name="deathgender" id="deathGenderFemale" value="Female" required> <label class="form-check-label" for="deathGenderFemale">Female</label> </div>
<div class="form-check form-check-inline mb-0"> <input class="form-check-input" type="radio" name="deathgender" id="deathGenderTrans" value="Transgender" required> <label class="form-check-label" for="deathGenderTrans">Transgender</label>
</div> </div> </div>
</div>
<!-- Row 3: Parents Details -->
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="name">Name of Father</label> <input type="text"
class="form-control" placeholder="Enter the Father Name"
id="deathfathername">
</div>
<div class="col-md-5">
<label class="form-label" for="name">Name of Mother</label> <input type="text"
class="form-control" placeholder="Enter the Mother Name"
id="deathmothername">
</div>
<div class="col-md-5 mt-3">
<label for="death-captcha-input">Enter Captcha <span class="text-danger">*</span></label>
<div class="d-flex align-items-center">
<div id="death-captcha" class="captcha-box mr-2" style="width: 140px; text-align: center; user-select: none;"></div>
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="generateCaptcha('death')">↻</button>
</div>
<input type="text" id="death-captcha-input" class="form-control mt-2"
placeholder="Enter Captcha"
onpaste="return false" oncopy="return false" oncut="return false" />
</div>
</div>
</div>
<div class="text-center ">
<button type="button" class="btn btn-success" onclick="fetchDeathData()">Submit</button>
<!-- <button type="button" class="btn btn-secondary" onclick="goBack()">Back</button> -->
</div>
</div> </div>
</div>
</div>
<br> <br>
@ -703,9 +616,6 @@ body {
</div> </div>
</div> </div>
<!-- Bootstrap Modal --> <!-- Bootstrap Modal -->
@ -725,28 +635,7 @@ body {
</div> </div>
</div> </div>
<!-- Bootstrap Modal -->
<div class="modal fade" id="deathModal" tabindex="-1" aria-labelledby="deathModalLabel" data-bs-backdrop="static" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deathModalLabel">Death Certificate Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">&times;</button>
</div>
<div class="modal-body" id="deathModalBody">
<!-- Table will be injected here -->
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
@ -1204,128 +1093,12 @@ function fetchBirthData() {
if (xhr.responseJSON && xhr.responseJSON.message) { if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message; message = xhr.responseJSON.message;
} }
alert("Error: " + message);
alert(message);
} }
}); });
} }
// this function only using in live
function fetchDeathData() {
const dod = document.getElementById('dateofdeath').value;
const gender = document.querySelector('input[name="deathgender"]:checked')?.value;
const captchaInput = document.getElementById('death-captcha-input');
// console.log("gender:", gender);
// Validate Date of Birth
if (!dod) {
Swal.fire({
icon: 'warning',
title: 'Missing Date of Birth',
text: 'Please enter your Date of Birth.'
});
return;
}
// Validate Gender
if (!gender) {
Swal.fire({
icon: 'warning',
title: 'Missing Gender Selection',
text: 'Please select a gender.'
});
return;
}
if (!validateCaptcha('death')) {
//captchaInput.classList.add('is-invalid');
//captchaInput.focus();
return;
} else {
captchaInput.classList.remove('is-invalid');
}
const formattedDod = dod.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
// console.log("dod:", formattedDod);
$('#pageLoader').show();
$.ajax({
url: '/crs/api/death-details',
method: 'GET',
data: {
dod: formattedDod,
sex: gender.charAt(0).toUpperCase()
},
success: function (response) {
$('#pageLoader').hide();
if (response && response.DEATH && response.DEATH.length > 0) {
let html = '<table id="deathDataTable" class="table table-bordered"><thead><tr>' +
'<th>S.No</th><th>Reg No</th><th>Person Name</th>' +
'<th>Father Name</th><th>Mother Name</th><th>DOD</th><th>Certificate Link</th></tr></thead><tbody>';
response.DEATH.forEach((row ,index) => {
html += `<tr>
<td>${index + 1}</td>
<td>${row.REGNO}</td>
<td>${row.DEATHPERSONNAME}</td>
<td>${row.FATHERNAME}</td>
<td>${row.MOTHERNAME}</td>
<td>${row.DOD}</td>
<td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
onclick="saveCertificateLog('${row.REGNO}', '${row.DOD}', '${row.ENGLISHURL}', 'Death')">View</a>` : 'N/A'}</td> </tr>`;
});
html += '</tbody></table>';
$('#deathModalBody').html(html);
// Delay initialization to ensure DOM is ready
setTimeout(() => {
$('#deathDataTable').DataTable({
responsive: true,
pagingType: "full_numbers", // Buttons for pagination
language: {
search: "🔍 Search: ",
emptyTable: "No records found",
paginate: {
previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
}
},
columnDefs: [
{ orderable: false, targets: 0 } // Disable sorting on S.No
]
});
}, 100);
} else {
$('#deathModalBody').html('<p class="text-danger">No deathrecords found.</p>');
}
const modal = new bootstrap.Modal(document.getElementById('deathModal'));
modal.show();
},
error: function (xhr) {
$('#pageLoader').hide();
let message = "Something went wrong.";
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
alert("Error: " + message);
}
});
}
function saveCertificateLog(regNo, eventDate, url, service){ function saveCertificateLog(regNo, eventDate, url, service){
$.ajax({ $.ajax({
url: '/crs/api/saveCertificateLogs', url: '/crs/api/saveCertificateLogs',

245
src/main/resources/templates/modules/crslogspages/death.html

@ -500,98 +500,7 @@ body {
<!-- Header End--> <!-- Header End-->
<main class="container mt-4" > <main class="container mt-4" >
<div class="container mt-5">
<!-- <div class="card" id="birth-card" style="display: block;">
<div class="card-header bg-dark text-white">
<h5>Birth Certificate:-</h5>
</div>
<div class="card-body">
<h6>
<strong>Birth Certificate Details :-</strong>
</h6>
<hr />
<div class="container mt-5">
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="phoneNumber">Enter Register Number </label> <input type="text"
id="regno" class="form-control"
placeholder="Enter Register number">
</div>
<div class="col-md-5">
<label class="form-label" for="name">Child Name </label> <input type="text"
class="form-control" placeholder="Enter Child Name here" id="childname" oninput="this.value = this.value.replace(/[^a-zA-Z\s]/g, '')">
</div>
</div>
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="name">Date of Birth<span
class="text-danger">*</span></label> <input type="DATE"
class="form-control" placeholder="Enter Door Number"
id="dateofbirth" onclick="this.showPicker()" required>
</div>
<div class="col-md-5"> <label class="form-label d-block">Gender <span class="text-danger">*</span></label>
<div class="d-flex align-items-center gap-3">
<div class="form-check form-check-inline mb-0">
<input class="form-check-input" type="radio" name="gender" id="birthGenderMale" value="Male" required> <label class="form-check-label" for="birthGenderMale">Male</label> </div>
<div class="form-check form-check-inline mb-0"> <input class="form-check-input" type="radio" name="gender" id="birthGenderFemale" value="Female" required> <label class="form-check-label" for="birthGenderFemale">Female</label> </div>
<div class="form-check form-check-inline mb-0"> <input class="form-check-input" type="radio" name="gender" id="birthGenderTrans" value="Transgender" required> <label class="form-check-label" for="birthGenderTrans">Transgender</label> </div> </div> </div>
</div>
<div class="row mb-3">
<div class="col-md-5">
<label class="form-label" for="name">Name of Father</label> <input type="text"
class="form-control" placeholder="Enter the Father Name"
id="fathername">
</div>
<div class="col-md-5">
<label class="form-label" for="name">Name of Mother</span></label> <input type="text"
class="form-control" placeholder="Enter the Mother Name"
id="mothername">
</div>
<div class="col-md-5 mt-3">
<label for="birth-captcha-input">Enter Captcha <span class="text-danger">*</span></label>
<div class="d-flex align-items-center">
<div id="birth-captcha" class="captcha-box mr-2" style="width: 140px; text-align: center; user-select: none;"></div>
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="generateCaptcha('birth')">↻</button>
</div>
<input type="text" id="birth-captcha-input" class="form-control mt-2"
placeholder="Enter Captcha"
onpaste="return false" oncopy="return false" oncut="return false" />
</div>
</div>
</div>
<div class="text-center ">
<button type="button" class="btn btn-success" onclick="fetchBirthData()">Submit</button>
</div> -->
</div>
</div>
<!-- Death certificate card -->
<!-- Death certificate card -->
<div class="card" id="death-card"> <div class="card" id="death-card">
<div class="card-header bg-dark text-white"> <div class="card-header bg-dark text-white">
@ -702,30 +611,6 @@ body {
wait...</p> wait...</p>
</div> </div>
</div> </div>
<!-- Bootstrap Modal -->
<div class="modal fade" id="birthModal" tabindex="-1" aria-labelledby="birthModalLabel" data-bs-backdrop="static" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="birthModalLabel">Birth Certificate Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">&times;</button>
</div>
<div class="modal-body" id="birthModalBody">
<!-- Table will be injected here -->
</div>
</div>
</div>
</div>
@ -969,132 +854,6 @@ document.addEventListener("DOMContentLoaded", function () {
function fetchBirthData() {
const dob = document.getElementById('dateofbirth').value;
const gender = document.querySelector('input[name="gender"]:checked')?.value;
const captchaInput = document.getElementById('birth-captcha-input');
//console.log("gender:", gender);
// Validate Date of Birth
if (!dob) {
Swal.fire({
icon: 'warning',
title: 'Missing Date of Birth',
text: 'Please enter your Date of Birth.'
});
return;
}
// Validate Gender
if (!gender) {
Swal.fire({
icon: 'warning',
title: 'Missing Gender Selection',
text: 'Please select a gender.'
});
return;
}
// CAPTCHA validation first
// Validate CAPTCHA
if (!validateCaptcha('birth')) {
//captchaInput.classList.add('is-invalid');
//captchaInput.focus();
return;
} else {
captchaInput.classList.remove('is-invalid');
}
const formattedDob = dob.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
//console.log("dob:", formattedDob);
$('#pageLoader').show();
$.ajax({
url: '/crs/api/birth-details',
method: 'GET',
data: {
dob: formattedDob,
sex: gender.charAt(0).toUpperCase()
},
success: function (response) {
$('#pageLoader').hide();
if (response && response.BIRTH && response.BIRTH.length > 0) {
console.log("birthdetails:",response);
let html = `
<table id="birthDataTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Reg No</th>
<th>Child Name</th>
<th>Father</th>
<th>Mother</th>
<th>DOB</th>
<th>Certificate Link</th>
</tr>
</thead>
<tbody>`;
response.BIRTH.forEach((row, index) => {
html += `<tr>
<td>${index + 1}</td>
<td>${row.REGNO}</td>
<td>${row.CHILDNAME}</td>
<td>${row.FATHERNAME}</td>
<td>${row.MOTHERNAME}</td>
<td>${row.DOB}</td>
<td>${row.ENGLISHURL ? `<a href="${row.ENGLISHURL}" target="_blank"
onclick="saveCertificateLog('${row.REGNO}', '${row.DOB}', '${row.ENGLISHURL}', 'Birth')">View</a>` : 'N/A'}</td>
</tr>`;
});
html += `</tbody></table>`;
$('#birthModalBody').html(html);
setTimeout(() => {
$('#birthDataTable').DataTable({
responsive: true,
pagingType: "full_numbers", // Buttons for pagination
language: {
search: "🔍 Search: ",
emptyTable: "No records found",
paginate: {
previous: "<button class='btn btn-outline-primary btn-sm'>Previous</button>",
next: "<button class='btn btn-outline-primary btn-sm'>Next</button>"
}
},
columnDefs: [
{ orderable: false, targets: 0 } // Disable sorting on S.No
]
});
}, 100);
}
else {
$('#birthModalBody').html('<p class="text-danger">No birth records found.</p>');
}
const modal = new bootstrap.Modal(document.getElementById('birthModal'));
modal.show();
},
error: function (xhr) {
$('#pageLoader').hide();
let message = "Something went wrong.";
if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message;
}
alert("Error: " + message);
}
});
}
// using fetchdeathdata function in live // using fetchdeathdata function in live
// function fetchDeathData() { // function fetchDeathData() {
@ -1324,7 +1083,7 @@ $.ajax({
if (xhr.responseJSON && xhr.responseJSON.message) { if (xhr.responseJSON && xhr.responseJSON.message) {
message = xhr.responseJSON.message; message = xhr.responseJSON.message;
} }
alert("Error: " + message);
alert(message);
} }
}); });

Loading…
Cancel
Save