Subversion Repositories SmartDukaan

Rev

Rev 37630 | Rev 37660 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37630 Rev 37632
Line 493... Line 493...
493
    }
493
    }
494
 
494
 
495
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
495
    @RequestMapping(value = "/validateLoiOtp", method = RequestMethod.PUT)
496
    public ResponseEntity<?> validateLoiAcceptanceOtp(HttpServletRequest request, @RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
496
    public ResponseEntity<?> validateLoiAcceptanceOtp(HttpServletRequest request, @RequestParam int loiId, @RequestParam String provideOtp, Model model) throws Exception {
497
        LoiForm loiForm = loiFormRepository.selectById(loiId);
497
        LoiForm loiForm = loiFormRepository.selectById(loiId);
-
 
498
        if (loiForm.getLoiSignOtp() != null && loiForm.getLoiDoc() > 0) {
-
 
499
            throw new ProfitMandiBusinessException("LOI already signed", loiId, "This LOI is already signed and saved. Refresh the Pending LOI list.");
-
 
500
        }
498
        String mobile = String.valueOf(loiForm.getMobile());
501
        String mobile = String.valueOf(loiForm.getMobile());
499
        Otp otp = otpRepository.selectAllByMobileWithTime(mobile).get(0);
502
        List<Otp> otps = otpRepository.selectAllByMobileWithTime(mobile);
-
 
503
        if (otps.isEmpty()) {
-
 
504
            throw new ProfitMandiBusinessException("No OTP", mobile, "No OTP was sent to " + mobile + " in the last 24 hours. Click Send OTP first.");
-
 
505
        }
500
        OTPResponse otpResponse = otpProcessor.validateOtp(otp.getId(), mobile, provideOtp);
506
        OTPResponse otpResponse = otpProcessor.validateOtp(otps.get(0).getId(), mobile, provideOtp);
501
        Map<String, Object> response = new HashMap<>();
507
        Map<String, Object> response = new HashMap<>();
502
        if (otpResponse.isResult()) {
508
        if (otpResponse.isResult()) {
503
            loiForm.setLoiSignOtp(provideOtp);
509
            loiForm.setLoiSignOtp(provideOtp);
504
            loiForm.setLoiSignedOn(LocalDateTime.now());
510
            loiForm.setLoiSignedOn(LocalDateTime.now());
505
 
511
 
Line 543... Line 549...
543
            response.put("generatedAt", audit.getCreatedAt());
549
            response.put("generatedAt", audit.getCreatedAt());
544
            response.put("loiId", loiId);
550
            response.put("loiId", loiId);
545
            loiAuditTrailRepository.persist(audit);
551
            loiAuditTrailRepository.persist(audit);
546
 
552
 
547
        } else {
553
        } else {
-
 
554
            // "OTP expired" also covers an OTP that was already used - e.g. re-entering the code after
-
 
555
            // the signed PDF failed to save. Say so instead of calling it wrong.
548
            throw new ProfitMandiBusinessException("Wrong OTP", "", "Your given Otp ->" + provideOtp + " is wrong , please check OTP and try again");
556
            throw new ProfitMandiBusinessException("Wrong OTP", "", "OTP " + provideOtp + " not accepted (" + otpResponse.getMessage()
-
 
557
                    + "). An OTP works only once - if it was already entered, click Send OTP to get a new one.");
549
        }
558
        }
550
        return responseSender.ok(response);
559
        return responseSender.ok(response);
551
    }
560
    }
552
 
561
 
553
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
562
    @RequestMapping(value = "/saveLoiDoc", method = RequestMethod.POST)
554
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
563
    public String saveLoiDoc(@RequestParam int loiId, @RequestParam int loiDocId, Model model) throws Exception {
555
        LOGGER.info("loi_docId-" + loiDocId);
564
        LOGGER.info("loi_docId-" + loiDocId);
556
        LoiForm loiForm = loiFormRepository.selectById(loiId);
565
        LoiForm loiForm = loiFormRepository.selectById(loiId);
557
        if (loiDocId > 0) {
566
        if (loiDocId > 0) {
-
 
567
            if (loiForm.getLoiSignOtp() == null) {
-
 
568
                throw new ProfitMandiBusinessException("LOI OTP not verified", loiId, "Partner OTP is not verified for this LOI. Click Send OTP and Confirm Sign again.");
-
 
569
            }
-
 
570
            if (loiForm.getLoiDoc() > 0) {
-
 
571
                // Retry of a save that already went through: don't mail the partner or complete the LOI twice.
-
 
572
                LOGGER.info("Signed LOI already saved for loiId {} (doc {}), ignoring doc {}", loiId, loiForm.getLoiDoc(), loiDocId);
-
 
573
                model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
574
                return "response";
-
 
575
            }
558
            loiForm.setLoiDoc(loiDocId);
576
            loiForm.setLoiDoc(loiDocId);
559
            loiFormService.sendSignedLoiPdfToPartner(loiForm);
577
            loiFormService.sendSignedLoiPdfToPartner(loiForm);
560
            loiFormService.checkLoiDetailsCompletion(loiForm);
578
            loiFormService.checkLoiDetailsCompletion(loiForm);
561
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
579
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
562
        } else {
580
        } else {