|
|
@ -31,12 +31,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
@Service |
|
|
@Service |
|
|
public class BirthAndDeathDetailsService { |
|
|
public class BirthAndDeathDetailsService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private final RestTemplate restTemplate; |
|
|
private final RestTemplate restTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private JdbcTemplate jdbcTemplate; |
|
|
private JdbcTemplate jdbcTemplate; |
|
|
|
|
|
|
|
|
@ -44,11 +41,10 @@ public class BirthAndDeathDetailsService { |
|
|
this.restTemplate = builder.build(); |
|
|
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 |
|
|
Map<String, String> params = new LinkedHashMap(); // keep order |
|
|
params.put("regno", regno != null ? regno : ""); |
|
|
params.put("regno", regno != null ? regno : ""); |
|
|
params.put("sex", sex); |
|
|
params.put("sex", sex); |
|
|
@ -61,7 +57,8 @@ public class BirthAndDeathDetailsService { |
|
|
String serviceInput = mapper.writeValueAsString(params); |
|
|
String serviceInput = mapper.writeValueAsString(params); |
|
|
|
|
|
|
|
|
// Final raw URL — NOT encoded |
|
|
// 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("⏩ Raw JSON: " + serviceInput); |
|
|
// System.out.println("🌐 FINAL RAW URL: " + BirthCertificateapiUrl); |
|
|
// System.out.println("🌐 FINAL RAW URL: " + BirthCertificateapiUrl); |
|
|
@ -72,19 +69,18 @@ public class BirthAndDeathDetailsService { |
|
|
HttpEntity<String> entity = new HttpEntity<>(headers); |
|
|
HttpEntity<String> entity = new HttpEntity<>(headers); |
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
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 rawJson = response.getBody(); |
|
|
String cleanJson = sanitizeJsonResponse(rawJson); |
|
|
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 |
|
|
// to created our external api from restservices |
|
|
|
|
|
|
|
|
public Map<String, Object> fetchLocalBirthCertificate( |
|
|
public Map<String, Object> fetchLocalBirthCertificate( |
|
|
@ -92,6 +88,9 @@ public class BirthAndDeathDetailsService { |
|
|
|
|
|
|
|
|
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb"; |
|
|
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/birth-certificate/by-detailsnewforWeb"; |
|
|
|
|
|
|
|
|
|
|
|
// String apiUrl = |
|
|
|
|
|
// "http://localhost:8077/gccrestservices/api/birth-certificate/by-detailsnewforWeb"; |
|
|
|
|
|
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
|
|
params.add("incident_date", dob); // yyyy-MM-dd |
|
|
params.add("incident_date", dob); // yyyy-MM-dd |
|
|
params.add("gender", sex); |
|
|
params.add("gender", sex); |
|
|
@ -116,7 +115,8 @@ 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")) { |
|
|
@ -132,12 +132,6 @@ public class BirthAndDeathDetailsService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// to created our external api from restservices |
|
|
// to created our external api from restservices |
|
|
|
|
|
|
|
|
public Map<String, Object> fetchLocalDeathCertificate( |
|
|
public Map<String, Object> fetchLocalDeathCertificate( |
|
|
@ -145,6 +139,9 @@ public class BirthAndDeathDetailsService { |
|
|
|
|
|
|
|
|
String apiUrl = "https://gccservices.chennaicorporation.gov.in/gccrestservices/api/death-certificate/by-detailsnewforWeb"; |
|
|
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<>(); |
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
|
|
params.add("incident_date", dod); // yyyy-MM-dd |
|
|
params.add("incident_date", dod); // yyyy-MM-dd |
|
|
params.add("gender", sex); |
|
|
params.add("gender", sex); |
|
|
@ -169,7 +166,8 @@ 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"); |
|
|
@ -184,14 +182,10 @@ public class BirthAndDeathDetailsService { |
|
|
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") |
|
|
@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("regno", regno != null ? regno : ""); |
|
|
@ -205,7 +199,8 @@ public class BirthAndDeathDetailsService { |
|
|
String serviceInput = mapper.writeValueAsString(params); |
|
|
String serviceInput = mapper.writeValueAsString(params); |
|
|
|
|
|
|
|
|
// Final raw URL — NOT encoded |
|
|
// 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("⏩ Raw JSON: " + serviceInput); |
|
|
// System.out.println("🌐 FINAL RAW URL: " + DeathCertificateapiUrl); |
|
|
// System.out.println("🌐 FINAL RAW URL: " + DeathCertificateapiUrl); |
|
|
@ -216,26 +211,26 @@ public class BirthAndDeathDetailsService { |
|
|
HttpEntity<String> entity = new HttpEntity<>(headers); |
|
|
HttpEntity<String> entity = new HttpEntity<>(headers); |
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
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 rawJson = response.getBody(); |
|
|
String cleanJson = sanitizeJsonResponse(rawJson); |
|
|
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) { |
|
|
private String sanitizeJsonResponse(String rawJson) { |
|
|
if (rawJson == null) return ""; |
|
|
|
|
|
|
|
|
if (rawJson == null) |
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
|
// Remove quote before parenthesis (fixes: "NAME" : "ABC "(LATE)") |
|
|
// Remove quote before parenthesis (fixes: "NAME" : "ABC "(LATE)") |
|
|
String fixed = rawJson.replaceAll("\"\\s*\\(([^)]*)\\)\"", " ($1)\""); |
|
|
String fixed = rawJson.replaceAll("\"\\s*\\(([^)]*)\\)\"", " ($1)\""); |
|
|
|
|
|
|
|
|
// Remove parenthesis and content outside of quotes (fixes: ... "ABC" (LATE) ... → ... "ABC" ...) |
|
|
|
|
|
|
|
|
// Remove parenthesis and content outside of quotes (fixes: ... "ABC" (LATE) ... |
|
|
|
|
|
// → ... "ABC" ...) |
|
|
fixed = fixed.replaceAll("\"\\s*\\([^)]*\\)", "\""); |
|
|
fixed = fixed.replaceAll("\"\\s*\\([^)]*\\)", "\""); |
|
|
|
|
|
|
|
|
return fixed |
|
|
return fixed |
|
|
@ -253,10 +248,6 @@ public class BirthAndDeathDetailsService { |
|
|
.replaceAll(":(\\s*)\"{2,}\"", ":\"\""); // handle `:"""` to `:""` |
|
|
.replaceAll(":(\\s*)\"{2,}\"", ":\"\""); // handle `:"""` to `:""` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
@Transactional |
|
|
public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) { |
|
|
public ResponseEntity<?> saveNewUser(String user_name, String user_address, String user_mobile) { |
|
|
Map<String, Object> result = new HashMap(); |
|
|
Map<String, Object> result = new HashMap(); |
|
|
@ -274,18 +265,14 @@ public class BirthAndDeathDetailsService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isUserRegistered(String mobile) { |
|
|
public boolean isUserRegistered(String mobile) { |
|
|
String sql = "SELECT COUNT(*) FROM users WHERE user_mobile = ?"; |
|
|
String sql = "SELECT COUNT(*) FROM users WHERE user_mobile = ?"; |
|
|
Integer count = jdbcTemplate.queryForObject(sql, new Object[] { mobile }, Integer.class); |
|
|
Integer count = jdbcTemplate.queryForObject(sql, new Object[] { mobile }, Integer.class); |
|
|
return count != null && count > 0; |
|
|
return count != null && count > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ResponseEntity<?> saveCertificateLogs(String regNo, String eventDate, String url, String service, int userid) { |
|
|
|
|
|
|
|
|
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 (?, ?, ?, ?, ?)"; |
|
|
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); |
|
|
Integer count = jdbcTemplate.update(sql, regNo, eventDate, url, service, userid); |
|
|
return count != null && count > 0 ? ResponseEntity.ok(count) : ResponseEntity.notFound().build(); |
|
|
return count != null && count > 0 ? ResponseEntity.ok(count) : ResponseEntity.notFound().build(); |
|
|
@ -296,6 +283,4 @@ public class BirthAndDeathDetailsService { |
|
|
return jdbcTemplate.queryForMap(sql, mobNo); |
|
|
return jdbcTemplate.queryForMap(sql, mobNo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |