|
|
@ -5,11 +5,15 @@ import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
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.HttpServerErrorException; |
|
|
|
|
|
import org.springframework.web.client.ResourceAccessException; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
import in.gov.chennaicorporation.gccoffice.configuration.AppConfig; |
|
|
import in.gov.chennaicorporation.gccoffice.configuration.AppConfig; |
|
|
@ -143,14 +147,134 @@ public class ShelterInspectionController { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/questions") |
|
|
@GetMapping("/questions") |
|
|
public ResponseEntity<?> getquestionsDetails(@RequestParam("cid") String cid){ |
|
|
|
|
|
String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid; |
|
|
|
|
|
return restTemplate.getForEntity(apiUrl, String.class); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ResponseEntity<?> getquestionsDetails( |
|
|
|
|
|
@RequestParam("cid") String cid) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
String apiUrl = |
|
|
|
|
|
appConfig.shelterurl + "/questions?cid=" + cid; |
|
|
|
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"API URL for night inspection questions: " + apiUrl |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<Object> response = |
|
|
|
|
|
restTemplate.getForEntity( |
|
|
|
|
|
apiUrl, |
|
|
|
|
|
Object.class |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity |
|
|
|
|
|
.status(response.getStatusCode()) |
|
|
|
|
|
.body(response.getBody()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (HttpClientErrorException e) { |
|
|
|
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"Question API Client Error: " + |
|
|
|
|
|
e.getStatusCode() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity |
|
|
|
|
|
.status(e.getStatusCode()) |
|
|
|
|
|
.body(e.getResponseBodyAsString()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (HttpServerErrorException e) { |
|
|
|
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"Question API Server Error: " + |
|
|
|
|
|
e.getStatusCode() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity |
|
|
|
|
|
.status(e.getStatusCode()) |
|
|
|
|
|
.body(e.getResponseBodyAsString()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (ResourceAccessException e) { |
|
|
|
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"Question API Connection Error: " + |
|
|
|
|
|
e.getMessage() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity |
|
|
|
|
|
.status(HttpStatus.BAD_GATEWAY) |
|
|
|
|
|
.body( |
|
|
|
|
|
Map.of( |
|
|
|
|
|
"status", false, |
|
|
|
|
|
"message", |
|
|
|
|
|
"Unable to connect to Question Master API." |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"Question API Exception" |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity |
|
|
|
|
|
.status(HttpStatus.INTERNAL_SERVER_ERROR) |
|
|
|
|
|
.body( |
|
|
|
|
|
Map.of( |
|
|
|
|
|
"status", false, |
|
|
|
|
|
"message", |
|
|
|
|
|
"Unable to load question details." |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @GetMapping("/questions") |
|
|
|
|
|
// public ResponseEntity<?> getquestionsDetails(@RequestParam("cid") String cid) { |
|
|
|
|
|
// |
|
|
|
|
|
// try { |
|
|
|
|
|
// |
|
|
|
|
|
// String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid; |
|
|
|
|
|
// |
|
|
|
|
|
// System.out.println("apiUrl for night inspection questions:" +apiUrl); |
|
|
|
|
|
// |
|
|
|
|
|
// ResponseEntity<String> response = |
|
|
|
|
|
// restTemplate.getForEntity(apiUrl, String.class); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity |
|
|
|
|
|
// .status(response.getStatusCode()) |
|
|
|
|
|
// .body(response.getBody()); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (HttpClientErrorException e) { |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity |
|
|
|
|
|
// .status(e.getStatusCode()) |
|
|
|
|
|
// .body(e.getResponseBodyAsString()); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (HttpServerErrorException e) { |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity |
|
|
|
|
|
// .status(e.getStatusCode()) |
|
|
|
|
|
// .body(e.getResponseBodyAsString()); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (ResourceAccessException e) { |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity |
|
|
|
|
|
// .status(HttpStatus.BAD_GATEWAY) |
|
|
|
|
|
// .body("Unable to connect to Question Master API."); |
|
|
|
|
|
// |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// |
|
|
|
|
|
// System.out.println("apiUrl for night inspection questions Exception....."); |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// |
|
|
|
|
|
// return ResponseEntity |
|
|
|
|
|
// .status(HttpStatus.INTERNAL_SERVER_ERROR) |
|
|
|
|
|
// .body("Unable to load question details."); |
|
|
|
|
|
// |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
// @GetMapping("/questions") |
|
|
// @GetMapping("/questions") |
|
|
// public ResponseEntity<?> getQuestions(@RequestParam String cid) { |
|
|
// public ResponseEntity<?> getQuestions(@RequestParam String cid) { |
|
|
|