| Line 628... |
Line 628... |
| 628 |
}
|
628 |
}
|
| 629 |
|
629 |
|
| 630 |
@RequestMapping(value = "/admin/policy/certificate", method = RequestMethod.GET)
|
630 |
@RequestMapping(value = "/admin/policy/certificate", method = RequestMethod.GET)
|
| 631 |
public ResponseEntity<byte[]> downloadPolicyCertificate(HttpServletRequest request,
|
631 |
public ResponseEntity<byte[]> downloadPolicyCertificate(HttpServletRequest request,
|
| 632 |
@RequestParam(required = false) String policyNumber,
|
632 |
@RequestParam(required = false) String policyNumber,
|
| - |
|
633 |
@RequestParam(required = false) String policyNo,
|
| - |
|
634 |
@RequestParam(required = false) String proposalNumber,
|
| 633 |
@RequestParam(required = false) String proposalNumber) throws Exception {
|
635 |
@RequestParam(required = false) String proposalNo) throws Exception {
|
| 634 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
636 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 635 |
if (!roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
637 |
if (!roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 636 |
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
638 |
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
| 637 |
}
|
639 |
}
|
| 638 |
|
640 |
|
| - |
|
641 |
// Accept either spelling, either kind — whichever is provided gets sent
|
| 639 |
if ((policyNumber == null || policyNumber.isEmpty())
|
642 |
// straight to ICICI's certificate API.
|
| 640 |
&& (proposalNumber == null || proposalNumber.isEmpty())) {
|
643 |
String policy = firstNonBlank(policyNumber, policyNo, proposalNumber, proposalNo);
|
| - |
|
644 |
if (policy == null) {
|
| 641 |
return ResponseEntity.badRequest().build();
|
645 |
return ResponseEntity.badRequest().build();
|
| 642 |
}
|
646 |
}
|
| 643 |
|
647 |
|
| 644 |
// If policyNumber wasn't given, resolve it from proposalNumber first.
|
- |
|
| 645 |
if (policyNumber == null || policyNumber.isEmpty()) {
|
- |
|
| 646 |
policyNumber = iciciLombardService.recoverPolicyNumberByProposalNumber(proposalNumber);
|
- |
|
| 647 |
}
|
- |
|
| 648 |
|
- |
|
| 649 |
String filePath = iciciLombardService.fetchPolicyCertificateByPolicyNumber(policyNumber);
|
648 |
String filePath = iciciLombardService.fetchPolicyCertificateByPolicyNumber(policy);
|
| 650 |
byte[] pdfBytes = Files.readAllBytes(new File(filePath).toPath());
|
649 |
byte[] pdfBytes = Files.readAllBytes(new File(filePath).toPath());
|
| 651 |
|
650 |
|
| 652 |
String safeName = "policy-" + policyNumber.replace("/", "-") + ".pdf";
|
651 |
String safeName = "policy-" + policy.replace("/", "-") + ".pdf";
|
| 653 |
HttpHeaders headers = new HttpHeaders();
|
652 |
HttpHeaders headers = new HttpHeaders();
|
| 654 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
653 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 655 |
headers.setContentDispositionFormData("inline", safeName);
|
654 |
headers.setContentDispositionFormData("inline", safeName);
|
| 656 |
headers.setContentLength(pdfBytes.length);
|
655 |
headers.setContentLength(pdfBytes.length);
|
| 657 |
return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK);
|
656 |
return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK);
|
| 658 |
}
|
657 |
}
|
| 659 |
|
658 |
|
| - |
|
659 |
private String firstNonBlank(String... values) {
|
| - |
|
660 |
for (String v : values) {
|
| - |
|
661 |
if (v != null && !v.isEmpty()) return v;
|
| - |
|
662 |
}
|
| - |
|
663 |
return null;
|
| - |
|
664 |
}
|
| - |
|
665 |
|
| 660 |
|
666 |
|
| 661 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
667 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 662 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
668 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
| 663 |
Model model) throws ProfitMandiBusinessException {
|
669 |
Model model) throws ProfitMandiBusinessException {
|
| 664 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
670 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|