Browse Source

changes in register page

master
yoganandhan 10 months ago
parent
commit
2b5293f9a4
  1. 2
      src/main/java/com/gcc/crslogs/controller/ApiController.java
  2. 327
      src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java
  3. 1531
      src/main/resources/templates/modules/crslogspages/birthloginpage.html
  4. 9
      src/main/resources/templates/modules/crslogspages/death.html
  5. 1531
      src/main/resources/templates/modules/crslogspages/deathloginpage.html

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

@ -258,7 +258,7 @@ public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String,
if (dod == null || dod.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
error.put("message", "dod and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}

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

@ -31,24 +31,20 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Service
public class BirthAndDeathDetailsService {
@Autowired
@Autowired
private final RestTemplate restTemplate;
@Autowired
@Autowired
private JdbcTemplate jdbcTemplate;
public BirthAndDeathDetailsService(RestTemplateBuilder builder) {
public BirthAndDeathDetailsService(RestTemplateBuilder builder) {
this.restTemplate = builder.build();
}
// using for live
//using for live
public Map<String, Object> fetchBirthCertificate(String dob, String sex, String regno, String childName, String fatherName, String motherName) throws Exception {
public Map<String, Object> fetchBirthCertificate(String dob, String sex, String regno, String childName,
String fatherName, String motherName) throws Exception {
Map<String, String> params = new LinkedHashMap(); // keep order
params.put("regno", regno != null ? regno : "");
params.put("sex", sex);
@ -61,10 +57,11 @@ public class BirthAndDeathDetailsService {
String serviceInput = mapper.writeValueAsString(params);
// Final raw URL — NOT encoded
String BirthCertificateapiUrl = "https://chennaicorporation.gov.in/gcc/Api/BirthCertificate_json.jsp?serviceinput=" + serviceInput;
String BirthCertificateapiUrl = "https://chennaicorporation.gov.in/gcc/Api/BirthCertificate_json.jsp?serviceinput="
+ serviceInput;
//System.out.println("⏩ Raw JSON: " + serviceInput);
//System.out.println("🌐 FINAL RAW URL: " + BirthCertificateapiUrl);
// System.out.println("⏩ Raw JSON: " + serviceInput);
// System.out.println("🌐 FINAL RAW URL: " + BirthCertificateapiUrl);
HttpHeaders headers = new HttpHeaders();
headers.set("User-Agent", "Mozilla/5.0");
@ -72,128 +69,125 @@ public class BirthAndDeathDetailsService {
HttpEntity<String> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(BirthCertificateapiUrl, HttpMethod.GET, entity, String.class);
ResponseEntity<String> response = restTemplate.exchange(BirthCertificateapiUrl, HttpMethod.GET, entity,
String.class);
String rawJson = response.getBody();
String cleanJson = sanitizeJsonResponse(rawJson);
// System.out.println("✅ API Raw Response: " + cleanJson);
//System.out.println("✅ API Raw Response: " + cleanJson);
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {});
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {
});
}
// to created our external api from restservices
public Map<String, Object> fetchLocalBirthCertificate(
String dob, String fatherName, String motherName, String childName, String sex) throws Exception {
// to created our external api from restservices
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb";
public Map<String, Object> fetchLocalBirthCertificate(
String dob, String fatherName, String motherName, String childName, String sex) throws Exception {
// String apiUrl =
// "http://localhost:8077/gccrestservices/api/birth-certificate/by-detailsnewforWeb";
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb";
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dob); // yyyy-MM-dd
params.add("gender", sex);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dob); // yyyy-MM-dd
params.add("gender", sex);
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (childName != null && !childName.trim().isEmpty()) {
params.add("child_name", childName.trim().toUpperCase());
}
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (childName != null && !childName.trim().isEmpty()) {
params.add("child_name", childName.trim().toUpperCase());
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {
});
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
// ✅ Only keep records that actually have a PDF link
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
// ✅ Only keep records that actually have a PDF link
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
result.put("certificate_details", filtered);
}
result.put("certificate_details", filtered);
return result;
}
return result;
}
// to created our external api from restservices
public Map<String, Object> fetchLocalDeathCertificate(
String dod, String fatherName, String motherName, String personName, String sex) throws Exception {
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/death-certificate/by-detailsnewforWeb";
// String apiUrl =
// "http://localhost:8077/gccrestservices/api/death-certificate/by-detailsnewforWeb";
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dod); // yyyy-MM-dd
params.add("gender", sex);
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (personName != null && !personName.trim().isEmpty()) {
params.add("person_name", personName.trim().toUpperCase());
}
// to created our external api from restservices
public Map<String, Object> fetchLocalDeathCertificate(
String dod, String fatherName, String motherName, String personName, String sex) throws Exception {
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/death-certificate/by-detailsnewforWeb";
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("incident_date", dod); // yyyy-MM-dd
params.add("gender", sex);
// 🔹 Pass optional values if provided (converted to UPPERCASE, DB expects this)
if (fatherName != null && !fatherName.trim().isEmpty()) {
params.add("father_name", fatherName.trim().toUpperCase());
}
if (motherName != null && !motherName.trim().isEmpty()) {
params.add("mother_name", motherName.trim().toUpperCase());
}
if (personName != null && !personName.trim().isEmpty()) {
params.add("person_name", personName.trim().toUpperCase());
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {
});
// ✅ Only keep records that actually have a PDF link
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
//✅ Only keep records that actually have a PDF link
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
result.put("certificate_details", filtered);
}
result.put("certificate_details", filtered);
return result;
}
return result;
}
// using in live
//using in live
public Map<String, Object> fetchDeathCertificate(String dod, String sex, String regno, String personName, String fatherName, String motherName) throws Exception {
public Map<String, Object> fetchDeathCertificate(String dod, String sex, String regno, String personName,
String fatherName, String motherName) throws Exception {
@SuppressWarnings("rawtypes")
Map<String, String> params = new LinkedHashMap(); // keep order
Map<String, String> params = new LinkedHashMap(); // keep order
params.put("regno", regno != null ? regno : "");
params.put("sex", sex);
params.put("dod", dod);
@ -205,10 +199,11 @@ public class BirthAndDeathDetailsService {
String serviceInput = mapper.writeValueAsString(params);
// Final raw URL — NOT encoded
String DeathCertificateapiUrl = "https://chennaicorporation.gov.in/gcc/Api/DeathCertificate_json.jsp?serviceinput=" + serviceInput;
String DeathCertificateapiUrl = "https://chennaicorporation.gov.in/gcc/Api/DeathCertificate_json.jsp?serviceinput="
+ serviceInput;
//System.out.println("⏩ Raw JSON: " + serviceInput);
//System.out.println("🌐 FINAL RAW URL: " + DeathCertificateapiUrl);
// System.out.println("⏩ Raw JSON: " + serviceInput);
// System.out.println("🌐 FINAL RAW URL: " + DeathCertificateapiUrl);
HttpHeaders headers = new HttpHeaders();
headers.set("User-Agent", "Mozilla/5.0");
@ -216,86 +211,76 @@ public class BirthAndDeathDetailsService {
HttpEntity<String> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(DeathCertificateapiUrl, HttpMethod.GET, entity, String.class);
ResponseEntity<String> response = restTemplate.exchange(DeathCertificateapiUrl, HttpMethod.GET, entity,
String.class);
//System.out.println("✅ API Raw Response: " + response.getBody());
// System.out.println("✅ API Raw Response: " + response.getBody());
String rawJson = response.getBody();
String cleanJson = sanitizeJsonResponse(rawJson);
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {});
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {
});
}
private String sanitizeJsonResponse(String rawJson) {
if (rawJson == null)
return "";
// Remove quote before parenthesis (fixes: "NAME" : "ABC "(LATE)")
String fixed = rawJson.replaceAll("\"\\s*\\(([^)]*)\\)\"", " ($1)\"");
// Remove parenthesis and content outside of quotes (fixes: ... "ABC" (LATE) ...
// → ... "ABC" ...)
fixed = fixed.replaceAll("\"\\s*\\([^)]*\\)", "\"");
return fixed
.replace("\\", "\\\\") // Escape backslashes
.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters
.replaceAll("\t", "") // Remove tab characters
.replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
.replaceAll("\r", "") // Remove carriage return
.replaceAll("\n", "") // Remove newlines
.replaceAll(",\\s*\\[", "[") // Remove comma before array start
.replaceAll("\\[\\s*,", "[") // Remove comma after array start
.replaceAll(",\\s*\\]", "]") // Remove trailing comma in array
.replaceAll("\"\"\"", "\"\"") // fix triple quotes
.replaceAll("\"{3,}", "\"") // collapse 3+ quotes to 1
.replaceAll(":(\\s*)\"{2,}\"", ":\"\""); // handle `:"""` to `:""`
}
@Transactional
public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) {
Map<String, Object> result = new HashMap();
String sql = "INSERT INTO users (user_name, user_address, user_mobile) VALUES (?, ?, ?)";
try {
jdbcTemplate.update(sql, user_name, user_address, user_mobile);
result.put("message", "New User Saved Sucessfully");
result.put("data", "Success");
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
result.put("message", "Error");
result.put("Error", "Failed to save new user: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
}
}
public boolean isUserRegistered(String mobile) {
String sql = "SELECT COUNT(*) FROM users WHERE user_mobile = ?";
Integer count = jdbcTemplate.queryForObject(sql, new Object[] { mobile }, Integer.class);
return count != null && count > 0;
}
public ResponseEntity<?> saveCertificateLogs(String regNo, String eventDate, String url, String service,
int userid) {
String sql = "Insert into certificate_logs (regno, event_date, english_url, service, user_id) VALUES (?, ?, ?, ?, ?)";
Integer count = jdbcTemplate.update(sql, regNo, eventDate, url, service, userid);
return count != null && count > 0 ? ResponseEntity.ok(count) : ResponseEntity.notFound().build();
}
private String sanitizeJsonResponse(String rawJson) {
if (rawJson == null) return "";
// Remove quote before parenthesis (fixes: "NAME" : "ABC "(LATE)")
String fixed = rawJson.replaceAll("\"\\s*\\(([^)]*)\\)\"", " ($1)\"");
// Remove parenthesis and content outside of quotes (fixes: ... "ABC" (LATE) ... → ... "ABC" ...)
fixed = fixed.replaceAll("\"\\s*\\([^)]*\\)", "\"");
return fixed
.replace("\\", "\\\\") // Escape backslashes
.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters
.replaceAll("\t", "") // Remove tab characters
.replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits
.replaceAll("\r", "") // Remove carriage return
.replaceAll("\n", "") // Remove newlines
.replaceAll(",\\s*\\[", "[") // Remove comma before array start
.replaceAll("\\[\\s*,", "[") // Remove comma after array start
.replaceAll(",\\s*\\]", "]") // Remove trailing comma in array
.replaceAll("\"\"\"", "\"\"") // fix triple quotes
.replaceAll("\"{3,}", "\"") // collapse 3+ quotes to 1
.replaceAll(":(\\s*)\"{2,}\"", ":\"\""); // handle `:"""` to `:""`
}
@Transactional
public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) {
Map<String, Object> result = new HashMap();
String sql = "INSERT INTO users (user_name, user_address, user_mobile) VALUES (?, ?, ?)";
try {
jdbcTemplate.update(sql, user_name, user_address, user_mobile);
result.put("message", "New User Saved Sucessfully");
result.put("data", "Success");
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
result.put("message", "Error");
result.put("Error", "Failed to save new user: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
}
}
public boolean isUserRegistered(String mobile) {
String sql = "SELECT COUNT(*) FROM users WHERE user_mobile = ?";
Integer count = jdbcTemplate.queryForObject(sql, new Object[]{mobile}, Integer.class);
return count != null && count > 0;
}
public ResponseEntity<?> saveCertificateLogs(String regNo, String eventDate, String url, String service, int userid) {
String sql = "Insert into certificate_logs (regno, event_date, english_url, service, user_id) VALUES (?, ?, ?, ?, ?)";
Integer count = jdbcTemplate.update(sql, regNo, eventDate, url, service, userid);
return count != null && count > 0 ? ResponseEntity.ok(count) : ResponseEntity.notFound().build();
}
public Map<String,Object> getUserDetails(String mobNo) {
String sql = "Select * from users where user_mobile = ?";
return jdbcTemplate.queryForMap(sql, mobNo);
}
public Map<String, Object> getUserDetails(String mobNo) {
String sql = "Select * from users where user_mobile = ?";
return jdbcTemplate.queryForMap(sql, mobNo);
}
}

1531
src/main/resources/templates/modules/crslogspages/birthloginpage.html
File diff suppressed because it is too large
View File

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

@ -704,7 +704,7 @@ $(document).ready(function () {
document.addEventListener("DOMContentLoaded", function () {
const today = new Date().toISOString().split("T")[0]; // yyyy-mm-dd format
document.getElementById("dateofbirth").setAttribute("max", today);
//document.getElementById("dateofbirth").setAttribute("max", today);
document.getElementById("dateofdeath").setAttribute("max", today);
});
@ -848,7 +848,7 @@ function validateCaptcha(type) {
document.addEventListener("DOMContentLoaded", function () {
generateCaptcha("birth");
// generateCaptcha("birth");
generateCaptcha("death");
});
@ -1010,7 +1010,7 @@ if (!validateCaptcha('death')) {
const formattedDod = dod.split("-").reverse().join("/"); // Convert yyyy-MM-dd to dd/MM/yyyy
// console.log("dod:", formattedDod);
//console.log("dod:", formattedDod);
$('#pageLoader').show();
const payload = {
@ -1029,10 +1029,11 @@ $.ajax({
contentType: 'application/json',
data: JSON.stringify(payload),
success: function (response) {
$('#pageLoader').hide();
if (response && response.certificate_details && response.certificate_details.length > 0) {
let html = '<table id="deathDataTable" class="table table-bordered"><thead><tr>' +
let html = '<table id="deathDataTable" class="table table-bordered table-striped"><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>';

1531
src/main/resources/templates/modules/crslogspages/deathloginpage.html
File diff suppressed because it is too large
View File

Loading…
Cancel
Save