diff --git a/src/main/java/com/gcc/crslogs/controller/ApiController.java b/src/main/java/com/gcc/crslogs/controller/ApiController.java index 36f6e97..208f730 100644 --- a/src/main/java/com/gcc/crslogs/controller/ApiController.java +++ b/src/main/java/com/gcc/crslogs/controller/ApiController.java @@ -258,7 +258,7 @@ public ResponseEntity fetchDeathCertificateSecurely(@RequestBody Map 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); } diff --git a/src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java b/src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java index aeb2073..56ca299 100644 --- a/src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java +++ b/src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java @@ -30,25 +30,21 @@ 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 - - public Map fetchBirthCertificate(String dob, String sex, String regno, String childName, String fatherName, String motherName) throws Exception { + + // using for live + + public Map fetchBirthCertificate(String dob, String sex, String regno, String childName, + String fatherName, String motherName) throws Exception { Map 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 entity = new HttpEntity<>(headers); RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.exchange(BirthCertificateapiUrl, HttpMethod.GET, entity, String.class); - + ResponseEntity 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>() {}); + return mapper.readValue(cleanJson, new TypeReference>() { + }); } - - -// to created our external api from restservices - - public Map 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 fetchLocalBirthCertificate( + String dob, String fatherName, String motherName, String childName, String sex) throws Exception { - MultiValueMap params = new LinkedMultiValueMap<>(); - params.add("incident_date", dob); // yyyy-MM-dd - params.add("gender", sex); + String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb"; - // 🔹 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()); - } + // String apiUrl = + // "http://localhost:8077/gccrestservices/api/birth-certificate/by-detailsnewforWeb"; - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("incident_date", dob); // yyyy-MM-dd + params.add("gender", sex); - HttpEntity> entity = new HttpEntity<>(params, headers); + // 🔹 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()); + } - ResponseEntity response = restTemplate.postForEntity(apiUrl, entity, String.class); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - String rawJson = response.getBody(); - ObjectMapper mapper = new ObjectMapper(); - Map result = mapper.readValue(rawJson, new TypeReference>() {}); + HttpEntity> entity = new HttpEntity<>(params, headers); - // ✅ Only keep records that actually have a PDF link - if (result.containsKey("certificate_details")) { - List> details = (List>) result.get("certificate_details"); + ResponseEntity response = restTemplate.postForEntity(apiUrl, entity, String.class); - List> filtered = details.stream() - .filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty()) - .toList(); + String rawJson = response.getBody(); + ObjectMapper mapper = new ObjectMapper(); + Map result = mapper.readValue(rawJson, new TypeReference>() { + }); - result.put("certificate_details", filtered); - } - - return result; -} + // ✅ Only keep records that actually have a PDF link + if (result.containsKey("certificate_details")) { + List> details = (List>) result.get("certificate_details"); + List> filtered = details.stream() + .filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty()) + .toList(); + result.put("certificate_details", filtered); + } + return result; + } + // to created our external api from restservices + public Map 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"; -// to created our external api from restservices - - public Map fetchLocalDeathCertificate( - String dod, String fatherName, String motherName, String personName, String sex) throws Exception { + // String apiUrl = + // "http://localhost:8077/gccrestservices/api/death-certificate/by-detailsnewforWeb"; - String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/death-certificate/by-detailsnewforWeb"; + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("incident_date", dod); // yyyy-MM-dd + params.add("gender", sex); - MultiValueMap 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()); + } - // 🔹 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> entity = new HttpEntity<>(params, headers); - HttpEntity> entity = new HttpEntity<>(params, headers); + ResponseEntity response = restTemplate.postForEntity(apiUrl, entity, String.class); - ResponseEntity response = restTemplate.postForEntity(apiUrl, entity, String.class); + String rawJson = response.getBody(); + ObjectMapper mapper = new ObjectMapper(); + Map result = mapper.readValue(rawJson, new TypeReference>() { + }); + // ✅ Only keep records that actually have a PDF link + if (result.containsKey("certificate_details")) { + List> details = (List>) result.get("certificate_details"); - String rawJson = response.getBody(); - ObjectMapper mapper = new ObjectMapper(); - Map result = mapper.readValue(rawJson, new TypeReference>() {}); - //✅ Only keep records that actually have a PDF link - if (result.containsKey("certificate_details")) { - List> details = (List>) result.get("certificate_details"); + List> filtered = details.stream() + .filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty()) + .toList(); - List> 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 fetchDeathCertificate(String dod, String sex, String regno, String personName, String fatherName, String motherName) throws Exception { + public Map fetchDeathCertificate(String dod, String sex, String regno, String personName, + String fatherName, String motherName) throws Exception { @SuppressWarnings("rawtypes") - Map params = new LinkedHashMap(); // keep order + Map 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 entity = new HttpEntity<>(headers); RestTemplate restTemplate = new RestTemplate(); - ResponseEntity response = restTemplate.exchange(DeathCertificateapiUrl, HttpMethod.GET, entity, String.class); + ResponseEntity 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>() {}); + return mapper.readValue(cleanJson, new TypeReference>() { + }); } + 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 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 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 getUserDetails(String mobNo) { - String sql = "Select * from users where user_mobile = ?"; - return jdbcTemplate.queryForMap(sql, mobNo); - } - - + public Map getUserDetails(String mobNo) { + String sql = "Select * from users where user_mobile = ?"; + return jdbcTemplate.queryForMap(sql, mobNo); + } } diff --git a/src/main/resources/templates/modules/crslogspages/birthloginpage.html b/src/main/resources/templates/modules/crslogspages/birthloginpage.html index 7183351..eec0bc2 100644 --- a/src/main/resources/templates/modules/crslogspages/birthloginpage.html +++ b/src/main/resources/templates/modules/crslogspages/birthloginpage.html @@ -1,826 +1,828 @@ + - - -GCC - Birth And Death - - - - - - - - - - + + + GCC - Birth And Death + + + + + + + + + + + - -
-
- - - - -
- GREATER CHENNAI - CORPORATION -
- - - - - -
- - - -
- - - -
- - - -
- - - - - -