-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBfhlQualifierApplication.java
More file actions
70 lines (53 loc) · 3.09 KB
/
BfhlQualifierApplication.java
File metadata and controls
70 lines (53 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.exam.bfhl;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
public class BfhlQualifierApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(BfhlQualifierApplication.class, args);
}
@Override
public void run(String... args) {
System.out.println("Starting application and executing webhook task...");
RestTemplate restTemplate = new RestTemplate();
String generateWebhookUrl = "https://bfhldevapigw.healthrx.co.in/hiring/generateWebhook/JAVA";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Map<String, String> requestBody = new HashMap<>();
requestBody.put("name", "John Doe");
requestBody.put("regNo", "REG12347");
requestBody.put("email", "john@example.com");
HttpEntity<Map<String, String>> request = new HttpEntity<>(requestBody, headers);
try {
ResponseEntity<Map> response = restTemplate.postForEntity(generateWebhookUrl, request, Map.class);
System.out.println("Generate Webhook Response: " + response.getBody());
if (response.getBody() != null) {
String webhook = (String) response.getBody().get("webhook");
String accessToken = (String) response.getBody().get("accessToken");
if (webhook == null) {
webhook = "https://bfhldevapigw.healthrx.co.in/hiring/testWebhook/JAVA"; // Fallback
}
String sqlQuery = "SELECT p.AMOUNT AS SALARY, CONCAT(e.FIRST_NAME, ' ', e.LAST_NAME) AS NAME, TIMESTAMPDIFF(YEAR, e.DOB, CURDATE()) AS AGE, d.DEPARTMENT_NAME FROM PAYMENTS p JOIN EMPLOYEE e ON p.EMP_ID = e.EMP_ID JOIN DEPARTMENT d ON e.DEPARTMENT = d.DEPARTMENT_ID WHERE DAY(p.PAYMENT_TIME) != 1 ORDER BY p.AMOUNT DESC LIMIT 1;";
HttpHeaders submitHeaders = new HttpHeaders();
submitHeaders.setContentType(MediaType.APPLICATION_JSON);
submitHeaders.set("Authorization", accessToken);
Map<String, String> submitBody = new HashMap<>();
submitBody.put("finalQuery", sqlQuery);
HttpEntity<Map<String, String>> submitRequest = new HttpEntity<>(submitBody, submitHeaders);
System.out.println("Submitting to: " + webhook);
ResponseEntity<String> submitResponse = restTemplate.postForEntity(webhook, submitRequest, String.class);
System.out.println("Submit Response: " + submitResponse.getBody());
}
} catch (Exception e) {
System.err.println("API execution failed: " + e.getMessage());
}
}
}